Lines Matching refs:ncm
520 static inline void ncm_reset_values(struct f_ncm *ncm) in ncm_reset_values() argument
522 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
523 ncm->is_crc = false; in ncm_reset_values()
524 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
525 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
528 ncm->port.header_len = 0; in ncm_reset_values()
530 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
531 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
537 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
539 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
541 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
546 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
550 switch (ncm->notify_state) { in ncm_do_notify()
556 if (ncm->is_open) in ncm_do_notify()
564 str_true_false(ncm->is_open)); in ncm_do_notify()
565 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
580 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
584 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
586 atomic_inc(&ncm->notify_count); in ncm_do_notify()
593 spin_unlock(&ncm->lock); in ncm_do_notify()
594 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
595 spin_lock(&ncm->lock); in ncm_do_notify()
597 atomic_dec(&ncm->notify_count); in ncm_do_notify()
605 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
617 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
618 ncm_do_notify(ncm); in ncm_notify()
623 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
624 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
627 spin_lock(&ncm->lock); in ncm_notify_complete()
632 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
636 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
637 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
642 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
645 ncm_do_notify(ncm); in ncm_notify_complete()
646 spin_unlock(&ncm->lock); in ncm_notify_complete()
654 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
670 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
681 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
700 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
708 ncm->port.cdc_filter = w_value; in ncm_setup()
724 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
735 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
737 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
740 ncm->port.fixed_in_len); in ncm_setup()
746 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
761 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
763 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
773 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
777 ncm->parser_opts = &ndp16_opts; in ncm_setup()
781 ncm->parser_opts = &ndp32_opts; in ncm_setup()
795 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
797 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
807 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
811 ncm->is_crc = false; in ncm_setup()
815 ncm->is_crc = true; in ncm_setup()
837 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
838 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
861 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
865 if (intf == ncm->ctrl_id) { in ncm_set_alt()
870 usb_ep_disable(ncm->notify); in ncm_set_alt()
872 if (!(ncm->notify->desc)) { in ncm_set_alt()
874 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
877 usb_ep_enable(ncm->notify); in ncm_set_alt()
880 } else if (intf == ncm->data_id) { in ncm_set_alt()
884 if (ncm->netdev) { in ncm_set_alt()
886 ncm->netdev = NULL; in ncm_set_alt()
887 gether_disconnect(&ncm->port); in ncm_set_alt()
888 ncm_reset_values(ncm); in ncm_set_alt()
898 if (!ncm->port.in_ep->desc || in ncm_set_alt()
899 !ncm->port.out_ep->desc) { in ncm_set_alt()
902 ncm->port.in_ep) || in ncm_set_alt()
904 ncm->port.out_ep)) { in ncm_set_alt()
905 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
906 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
915 ncm->port.is_zlp_ok = in ncm_set_alt()
917 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
919 net = gether_connect(&ncm->port); in ncm_set_alt()
922 ncm->netdev = net; in ncm_set_alt()
925 spin_lock(&ncm->lock); in ncm_set_alt()
926 ncm_notify(ncm); in ncm_set_alt()
927 spin_unlock(&ncm->lock); in ncm_set_alt()
942 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
944 if (intf == ncm->ctrl_id) in ncm_get_alt()
946 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
949 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
957 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
962 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
964 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
965 ncm->skb_tx_data->len; in package_for_tx()
966 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
967 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
970 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
978 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
979 ncm->ndp_dgram_count = 0; in package_for_tx()
981 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
986 swap(skb2, ncm->skb_tx_data); in package_for_tx()
987 if (ncm->skb_tx_data) { in package_for_tx()
988 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
989 ncm->skb_tx_data = NULL; in package_for_tx()
996 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
997 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
998 ncm->skb_tx_ndp = NULL; in package_for_tx()
1009 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1018 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1019 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1026 if (ncm->is_crc) { in ncm_wrap_ntb()
1042 if (ncm->skb_tx_data in ncm_wrap_ntb()
1043 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1044 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1046 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1048 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1053 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1059 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1060 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1063 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1064 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1075 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1079 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1082 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1083 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1086 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1090 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1095 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1100 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1102 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1110 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1113 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1114 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1118 } else if (ncm->skb_tx_data) { in ncm_wrap_ntb()
1123 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1131 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1135 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1136 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1137 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1138 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1149 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1150 struct net_device *netdev = READ_ONCE(ncm->netdev); in ncm_tx_timeout()
1170 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1182 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1183 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1240 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1293 if (ncm->is_crc) { in ncm_unwrap_ntb()
1323 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1368 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1373 if (ncm->netdev) { in ncm_disable()
1374 ncm->netdev = NULL; in ncm_disable()
1375 gether_disconnect(&ncm->port); in ncm_disable()
1378 if (ncm->notify->enabled) { in ncm_disable()
1379 usb_ep_disable(ncm->notify); in ncm_disable()
1380 ncm->notify->desc = NULL; in ncm_disable()
1406 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1408 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1410 spin_lock(&ncm->lock); in ncm_open()
1411 ncm->is_open = true; in ncm_open()
1412 ncm_notify(ncm); in ncm_open()
1413 spin_unlock(&ncm->lock); in ncm_open()
1418 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1420 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1422 spin_lock(&ncm->lock); in ncm_close()
1423 ncm->is_open = false; in ncm_close()
1424 ncm_notify(ncm); in ncm_close()
1425 spin_unlock(&ncm->lock); in ncm_close()
1435 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1470 ncm_string_defs[1].s = ncm->ethaddr; in ncm_bind()
1487 ncm->ctrl_id = status; in ncm_bind()
1496 ncm->data_id = status; in ncm_bind()
1508 ncm->port.in_ep = ep; in ncm_bind()
1513 ncm->port.out_ep = ep; in ncm_bind()
1518 ncm->notify = ep; in ncm_bind()
1527 request->context = ncm; in ncm_bind()
1556 ncm->port.open = ncm_open; in ncm_bind()
1557 ncm->port.close = ncm_close; in ncm_bind()
1559 hrtimer_setup(&ncm->task_timer, ncm_tx_timeout, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1567 ncm->notify_req = no_free_ptr(request); in ncm_bind()
1573 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1574 ncm->notify->name); in ncm_bind()
1585 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1588 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1591 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1594 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1597 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1712 struct f_ncm *ncm; in ncm_free() local
1715 ncm = func_to_ncm(f); in ncm_free()
1717 kfree(ncm); in ncm_free()
1725 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1732 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1740 if (atomic_read(&ncm->notify_count)) { in ncm_unbind()
1741 usb_ep_dequeue(ncm->notify, ncm->notify_req); in ncm_unbind()
1742 atomic_set(&ncm->notify_count, 0); in ncm_unbind()
1745 kfree(ncm->notify_req->buf); in ncm_unbind()
1746 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1755 struct f_ncm *ncm; in ncm_alloc() local
1760 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1761 if (!ncm) in ncm_alloc()
1769 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1770 sizeof(ncm->ethaddr)); in ncm_alloc()
1772 kfree(ncm); in ncm_alloc()
1777 spin_lock_init(&ncm->lock); in ncm_alloc()
1778 ncm_reset_values(ncm); in ncm_alloc()
1779 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1781 ncm->port.is_fixed = true; in ncm_alloc()
1782 ncm->port.supports_multi_frame = true; in ncm_alloc()
1784 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1786 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1787 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1788 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1789 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1790 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1791 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1792 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1794 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1795 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1797 return &ncm->port.func; in ncm_alloc()
1800 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);