Lines Matching refs:ncm

518 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
520 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
521 ncm->is_crc = false; in ncm_reset_values()
522 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
523 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
526 ncm->port.header_len = 0; in ncm_reset_values()
528 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
529 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
535 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
537 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
539 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
544 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
548 switch (ncm->notify_state) { in ncm_do_notify()
554 if (ncm->is_open) in ncm_do_notify()
562 str_true_false(ncm->is_open)); in ncm_do_notify()
563 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
578 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
582 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
584 atomic_inc(&ncm->notify_count); in ncm_do_notify()
591 spin_unlock(&ncm->lock); in ncm_do_notify()
592 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
593 spin_lock(&ncm->lock); in ncm_do_notify()
595 atomic_dec(&ncm->notify_count); in ncm_do_notify()
603 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
615 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
616 ncm_do_notify(ncm); in ncm_notify()
621 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
622 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
625 spin_lock(&ncm->lock); in ncm_notify_complete()
630 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
634 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
635 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
640 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
643 ncm_do_notify(ncm); in ncm_notify_complete()
644 spin_unlock(&ncm->lock); in ncm_notify_complete()
652 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
668 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
679 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
698 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
706 ncm->port.cdc_filter = w_value; in ncm_setup()
722 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
733 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
735 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
738 ncm->port.fixed_in_len); in ncm_setup()
744 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
759 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
761 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
771 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
775 ncm->parser_opts = &ndp16_opts; in ncm_setup()
779 ncm->parser_opts = &ndp32_opts; in ncm_setup()
793 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
795 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
805 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
809 ncm->is_crc = false; in ncm_setup()
813 ncm->is_crc = true; in ncm_setup()
835 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
836 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
859 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
863 if (intf == ncm->ctrl_id) { in ncm_set_alt()
868 usb_ep_disable(ncm->notify); in ncm_set_alt()
870 if (!(ncm->notify->desc)) { in ncm_set_alt()
872 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
875 usb_ep_enable(ncm->notify); in ncm_set_alt()
878 } else if (intf == ncm->data_id) { in ncm_set_alt()
882 if (ncm->netdev) { in ncm_set_alt()
884 ncm->netdev = NULL; in ncm_set_alt()
885 gether_disconnect(&ncm->port); in ncm_set_alt()
886 ncm_reset_values(ncm); in ncm_set_alt()
896 if (!ncm->port.in_ep->desc || in ncm_set_alt()
897 !ncm->port.out_ep->desc) { in ncm_set_alt()
900 ncm->port.in_ep) || in ncm_set_alt()
902 ncm->port.out_ep)) { in ncm_set_alt()
903 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
904 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
913 ncm->port.is_zlp_ok = in ncm_set_alt()
915 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
917 net = gether_connect(&ncm->port); in ncm_set_alt()
920 ncm->netdev = net; in ncm_set_alt()
923 spin_lock(&ncm->lock); in ncm_set_alt()
924 ncm_notify(ncm); in ncm_set_alt()
925 spin_unlock(&ncm->lock); in ncm_set_alt()
940 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
942 if (intf == ncm->ctrl_id) in ncm_get_alt()
944 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
947 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
955 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
960 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
962 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
963 ncm->skb_tx_data->len; in package_for_tx()
964 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
965 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
968 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
976 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
977 ncm->ndp_dgram_count = 0; in package_for_tx()
979 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
984 swap(skb2, ncm->skb_tx_data); in package_for_tx()
985 if (ncm->skb_tx_data) { in package_for_tx()
986 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
987 ncm->skb_tx_data = NULL; in package_for_tx()
994 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
995 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
996 ncm->skb_tx_ndp = NULL; in package_for_tx()
1007 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1016 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1017 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1024 if (ncm->is_crc) { in ncm_wrap_ntb()
1040 if (ncm->skb_tx_data in ncm_wrap_ntb()
1041 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1042 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1044 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1046 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1051 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1057 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1058 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1061 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1062 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1073 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1077 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1080 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1081 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1084 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1088 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1093 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1098 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1100 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1108 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1111 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1112 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1116 } else if (ncm->skb_tx_data) { in ncm_wrap_ntb()
1121 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1129 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1133 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1134 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1135 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1136 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1147 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1148 struct net_device *netdev = READ_ONCE(ncm->netdev); in ncm_tx_timeout()
1168 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1180 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1181 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1238 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1291 if (ncm->is_crc) { in ncm_unwrap_ntb()
1321 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1366 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1371 if (ncm->netdev) { in ncm_disable()
1372 ncm->netdev = NULL; in ncm_disable()
1373 gether_disconnect(&ncm->port); in ncm_disable()
1376 if (ncm->notify->enabled) { in ncm_disable()
1377 usb_ep_disable(ncm->notify); in ncm_disable()
1378 ncm->notify->desc = NULL; in ncm_disable()
1404 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1406 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1408 spin_lock(&ncm->lock); in ncm_open()
1409 ncm->is_open = true; in ncm_open()
1410 ncm_notify(ncm); in ncm_open()
1411 spin_unlock(&ncm->lock); in ncm_open()
1416 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1418 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1420 spin_lock(&ncm->lock); in ncm_close()
1421 ncm->is_open = false; in ncm_close()
1422 ncm_notify(ncm); in ncm_close()
1423 spin_unlock(&ncm->lock); in ncm_close()
1433 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1482 ncm->ctrl_id = status; in ncm_bind()
1495 ncm->data_id = status; in ncm_bind()
1509 ncm->port.in_ep = ep; in ncm_bind()
1514 ncm->port.out_ep = ep; in ncm_bind()
1519 ncm->notify = ep; in ncm_bind()
1524 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1525 if (!ncm->notify_req) in ncm_bind()
1527 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1528 if (!ncm->notify_req->buf) in ncm_bind()
1530 ncm->notify_req->context = ncm; in ncm_bind()
1531 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1559 ncm->port.open = ncm_open; in ncm_bind()
1560 ncm->port.close = ncm_close; in ncm_bind()
1562 hrtimer_setup(&ncm->task_timer, ncm_tx_timeout, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1565 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1566 ncm->notify->name); in ncm_bind()
1573 if (ncm->notify_req) { in ncm_bind()
1574 kfree(ncm->notify_req->buf); in ncm_bind()
1575 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1590 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1593 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1596 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1599 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1602 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1717 struct f_ncm *ncm; in ncm_free() local
1720 ncm = func_to_ncm(f); in ncm_free()
1722 kfree(ncm); in ncm_free()
1730 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1734 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1742 if (atomic_read(&ncm->notify_count)) { in ncm_unbind()
1743 usb_ep_dequeue(ncm->notify, ncm->notify_req); in ncm_unbind()
1744 atomic_set(&ncm->notify_count, 0); in ncm_unbind()
1747 kfree(ncm->notify_req->buf); in ncm_unbind()
1748 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1753 struct f_ncm *ncm; in ncm_alloc() local
1758 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1759 if (!ncm) in ncm_alloc()
1767 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1768 sizeof(ncm->ethaddr)); in ncm_alloc()
1770 kfree(ncm); in ncm_alloc()
1774 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1776 spin_lock_init(&ncm->lock); in ncm_alloc()
1777 ncm_reset_values(ncm); in ncm_alloc()
1778 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1780 ncm->port.is_fixed = true; in ncm_alloc()
1781 ncm->port.supports_multi_frame = true; in ncm_alloc()
1783 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1785 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1786 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1787 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1788 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1789 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1790 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1791 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1793 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1794 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1796 return &ncm->port.func; in ncm_alloc()
1799 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);