Lines Matching refs:ncm

508 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
510 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
511 ncm->is_crc = false; in ncm_reset_values()
512 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
513 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
516 ncm->port.header_len = 0; in ncm_reset_values()
518 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
519 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
525 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
527 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
529 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
534 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
538 switch (ncm->notify_state) { in ncm_do_notify()
544 if (ncm->is_open) in ncm_do_notify()
552 ncm->is_open ? "true" : "false"); in ncm_do_notify()
553 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
568 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
572 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
574 atomic_inc(&ncm->notify_count); in ncm_do_notify()
581 spin_unlock(&ncm->lock); in ncm_do_notify()
582 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
583 spin_lock(&ncm->lock); in ncm_do_notify()
585 atomic_dec(&ncm->notify_count); in ncm_do_notify()
593 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
605 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
606 ncm_do_notify(ncm); in ncm_notify()
611 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
612 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
615 spin_lock(&ncm->lock); in ncm_notify_complete()
620 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
624 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
625 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
630 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
633 ncm_do_notify(ncm); in ncm_notify_complete()
634 spin_unlock(&ncm->lock); in ncm_notify_complete()
642 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
658 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
669 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
688 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
696 ncm->port.cdc_filter = w_value; in ncm_setup()
712 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
723 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
725 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
728 ncm->port.fixed_in_len); in ncm_setup()
734 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
749 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
751 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
761 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
765 ncm->parser_opts = &ndp16_opts; in ncm_setup()
769 ncm->parser_opts = &ndp32_opts; in ncm_setup()
783 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
785 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
795 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
799 ncm->is_crc = false; in ncm_setup()
803 ncm->is_crc = true; in ncm_setup()
825 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
826 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
849 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
853 if (intf == ncm->ctrl_id) { in ncm_set_alt()
858 usb_ep_disable(ncm->notify); in ncm_set_alt()
860 if (!(ncm->notify->desc)) { in ncm_set_alt()
862 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
865 usb_ep_enable(ncm->notify); in ncm_set_alt()
868 } else if (intf == ncm->data_id) { in ncm_set_alt()
872 if (ncm->netdev) { in ncm_set_alt()
874 ncm->netdev = NULL; in ncm_set_alt()
875 gether_disconnect(&ncm->port); in ncm_set_alt()
876 ncm_reset_values(ncm); in ncm_set_alt()
886 if (!ncm->port.in_ep->desc || in ncm_set_alt()
887 !ncm->port.out_ep->desc) { in ncm_set_alt()
890 ncm->port.in_ep) || in ncm_set_alt()
892 ncm->port.out_ep)) { in ncm_set_alt()
893 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
894 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
903 ncm->port.is_zlp_ok = in ncm_set_alt()
905 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
907 net = gether_connect(&ncm->port); in ncm_set_alt()
910 ncm->netdev = net; in ncm_set_alt()
913 spin_lock(&ncm->lock); in ncm_set_alt()
914 ncm_notify(ncm); in ncm_set_alt()
915 spin_unlock(&ncm->lock); in ncm_set_alt()
930 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
932 if (intf == ncm->ctrl_id) in ncm_get_alt()
934 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
937 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
945 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
950 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
952 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
953 ncm->skb_tx_data->len; in package_for_tx()
954 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
955 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
958 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
966 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
967 ncm->ndp_dgram_count = 0; in package_for_tx()
969 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
974 swap(skb2, ncm->skb_tx_data); in package_for_tx()
975 if (ncm->skb_tx_data) { in package_for_tx()
976 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
977 ncm->skb_tx_data = NULL; in package_for_tx()
984 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
985 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
986 ncm->skb_tx_ndp = NULL; in package_for_tx()
997 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1006 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1007 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1014 if (ncm->is_crc) { in ncm_wrap_ntb()
1030 if (ncm->skb_tx_data in ncm_wrap_ntb()
1031 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1032 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1034 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1036 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1041 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1047 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1048 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1051 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1052 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1063 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1067 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1070 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1071 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1074 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1078 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1083 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1088 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1090 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1098 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1101 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1102 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1106 } else if (ncm->skb_tx_data) { in ncm_wrap_ntb()
1111 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1119 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1123 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1124 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1125 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1126 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1137 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1138 struct net_device *netdev = READ_ONCE(ncm->netdev); in ncm_tx_timeout()
1158 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1170 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1171 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1224 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1277 if (ncm->is_crc) { in ncm_unwrap_ntb()
1307 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1352 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1357 if (ncm->netdev) { in ncm_disable()
1358 ncm->netdev = NULL; in ncm_disable()
1359 gether_disconnect(&ncm->port); in ncm_disable()
1362 if (ncm->notify->enabled) { in ncm_disable()
1363 usb_ep_disable(ncm->notify); in ncm_disable()
1364 ncm->notify->desc = NULL; in ncm_disable()
1390 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1392 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1394 spin_lock(&ncm->lock); in ncm_open()
1395 ncm->is_open = true; in ncm_open()
1396 ncm_notify(ncm); in ncm_open()
1397 spin_unlock(&ncm->lock); in ncm_open()
1402 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1404 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1406 spin_lock(&ncm->lock); in ncm_close()
1407 ncm->is_open = false; in ncm_close()
1408 ncm_notify(ncm); in ncm_close()
1409 spin_unlock(&ncm->lock); in ncm_close()
1419 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1466 ncm->ctrl_id = status; in ncm_bind()
1479 ncm->data_id = status; in ncm_bind()
1491 ncm->port.in_ep = ep; in ncm_bind()
1496 ncm->port.out_ep = ep; in ncm_bind()
1501 ncm->notify = ep; in ncm_bind()
1506 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1507 if (!ncm->notify_req) in ncm_bind()
1509 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1510 if (!ncm->notify_req->buf) in ncm_bind()
1512 ncm->notify_req->context = ncm; in ncm_bind()
1513 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1541 ncm->port.open = ncm_open; in ncm_bind()
1542 ncm->port.close = ncm_close; in ncm_bind()
1544 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1545 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1548 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1549 ncm->notify->name); in ncm_bind()
1556 if (ncm->notify_req) { in ncm_bind()
1557 kfree(ncm->notify_req->buf); in ncm_bind()
1558 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1573 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1576 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1579 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1582 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1585 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1654 struct f_ncm *ncm; in ncm_free() local
1657 ncm = func_to_ncm(f); in ncm_free()
1659 kfree(ncm); in ncm_free()
1667 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1671 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1679 if (atomic_read(&ncm->notify_count)) { in ncm_unbind()
1680 usb_ep_dequeue(ncm->notify, ncm->notify_req); in ncm_unbind()
1681 atomic_set(&ncm->notify_count, 0); in ncm_unbind()
1684 kfree(ncm->notify_req->buf); in ncm_unbind()
1685 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1690 struct f_ncm *ncm; in ncm_alloc() local
1695 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1696 if (!ncm) in ncm_alloc()
1704 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1705 sizeof(ncm->ethaddr)); in ncm_alloc()
1707 kfree(ncm); in ncm_alloc()
1711 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1713 spin_lock_init(&ncm->lock); in ncm_alloc()
1714 ncm_reset_values(ncm); in ncm_alloc()
1715 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1717 ncm->port.is_fixed = true; in ncm_alloc()
1718 ncm->port.supports_multi_frame = true; in ncm_alloc()
1720 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1722 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1723 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1724 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1725 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1726 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1727 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1728 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1730 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1731 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1733 return &ncm->port.func; in ncm_alloc()
1736 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);