Lines Matching refs:ncm

521 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
523 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
524 ncm->is_crc = false; in ncm_reset_values()
525 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
526 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
529 ncm->port.header_len = 0; in ncm_reset_values()
531 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
532 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
538 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
540 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
542 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
547 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
551 switch (ncm->notify_state) { in ncm_do_notify()
557 if (ncm->is_open) in ncm_do_notify()
565 ncm->is_open ? "true" : "false"); in ncm_do_notify()
566 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
581 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
585 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
587 atomic_inc(&ncm->notify_count); in ncm_do_notify()
594 spin_unlock(&ncm->lock); in ncm_do_notify()
595 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
596 spin_lock(&ncm->lock); in ncm_do_notify()
598 atomic_dec(&ncm->notify_count); in ncm_do_notify()
606 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
618 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
619 ncm_do_notify(ncm); in ncm_notify()
624 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
625 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
628 spin_lock(&ncm->lock); in ncm_notify_complete()
633 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
637 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
638 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
643 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
646 ncm_do_notify(ncm); in ncm_notify_complete()
647 spin_unlock(&ncm->lock); in ncm_notify_complete()
655 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
671 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
682 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
701 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
709 ncm->port.cdc_filter = w_value; in ncm_setup()
725 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
736 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
738 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
741 ncm->port.fixed_in_len); in ncm_setup()
747 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
762 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
764 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
774 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
778 ncm->parser_opts = &ndp16_opts; in ncm_setup()
782 ncm->parser_opts = &ndp32_opts; in ncm_setup()
796 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
798 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
808 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
812 ncm->is_crc = false; in ncm_setup()
816 ncm->is_crc = true; in ncm_setup()
838 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
839 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
862 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
866 if (intf == ncm->ctrl_id) { in ncm_set_alt()
871 usb_ep_disable(ncm->notify); in ncm_set_alt()
873 if (!(ncm->notify->desc)) { in ncm_set_alt()
875 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
878 usb_ep_enable(ncm->notify); in ncm_set_alt()
881 } else if (intf == ncm->data_id) { in ncm_set_alt()
885 if (ncm->port.in_ep->enabled) { in ncm_set_alt()
887 ncm->netdev = NULL; in ncm_set_alt()
888 gether_disconnect(&ncm->port); in ncm_set_alt()
889 ncm_reset_values(ncm); in ncm_set_alt()
899 if (!ncm->port.in_ep->desc || in ncm_set_alt()
900 !ncm->port.out_ep->desc) { in ncm_set_alt()
903 ncm->port.in_ep) || in ncm_set_alt()
905 ncm->port.out_ep)) { in ncm_set_alt()
906 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
907 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
916 ncm->port.is_zlp_ok = in ncm_set_alt()
918 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
920 net = gether_connect(&ncm->port); in ncm_set_alt()
923 ncm->netdev = net; in ncm_set_alt()
926 spin_lock(&ncm->lock); in ncm_set_alt()
927 ncm_notify(ncm); in ncm_set_alt()
928 spin_unlock(&ncm->lock); in ncm_set_alt()
943 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
945 if (intf == ncm->ctrl_id) in ncm_get_alt()
947 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
950 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
958 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
963 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
965 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
966 ncm->skb_tx_data->len; in package_for_tx()
967 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
968 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
971 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
979 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
980 ncm->ndp_dgram_count = 0; in package_for_tx()
982 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
987 swap(skb2, ncm->skb_tx_data); in package_for_tx()
988 if (ncm->skb_tx_data) { in package_for_tx()
989 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
990 ncm->skb_tx_data = NULL; in package_for_tx()
997 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
998 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
999 ncm->skb_tx_ndp = NULL; in package_for_tx()
1010 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1019 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1020 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1027 if (ncm->is_crc) { in ncm_wrap_ntb()
1043 if (ncm->skb_tx_data in ncm_wrap_ntb()
1044 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1045 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1047 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1049 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1054 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1060 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1061 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1064 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1065 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1076 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1080 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1083 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1084 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1087 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1091 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1096 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1101 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1103 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1111 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1114 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1115 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1119 } else if (ncm->skb_tx_data) { in ncm_wrap_ntb()
1124 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1132 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1136 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1137 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1138 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1139 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1150 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1151 struct net_device *netdev = READ_ONCE(ncm->netdev); in ncm_tx_timeout()
1171 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()
1232 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1285 if (ncm->is_crc) { in ncm_unwrap_ntb()
1315 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1345 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1350 if (ncm->port.in_ep->enabled) { in ncm_disable()
1351 ncm->netdev = NULL; in ncm_disable()
1352 gether_disconnect(&ncm->port); in ncm_disable()
1355 if (ncm->notify->enabled) { in ncm_disable()
1356 usb_ep_disable(ncm->notify); in ncm_disable()
1357 ncm->notify->desc = NULL; in ncm_disable()
1383 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1385 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1387 spin_lock(&ncm->lock); in ncm_open()
1388 ncm->is_open = true; in ncm_open()
1389 ncm_notify(ncm); in ncm_open()
1390 spin_unlock(&ncm->lock); in ncm_open()
1395 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1397 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1399 spin_lock(&ncm->lock); in ncm_close()
1400 ncm->is_open = false; in ncm_close()
1401 ncm_notify(ncm); in ncm_close()
1402 spin_unlock(&ncm->lock); in ncm_close()
1412 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1464 ncm->ctrl_id = status; in ncm_bind()
1477 ncm->data_id = status; in ncm_bind()
1489 ncm->port.in_ep = ep; in ncm_bind()
1494 ncm->port.out_ep = ep; in ncm_bind()
1499 ncm->notify = ep; in ncm_bind()
1504 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1505 if (!ncm->notify_req) in ncm_bind()
1507 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1508 if (!ncm->notify_req->buf) in ncm_bind()
1510 ncm->notify_req->context = ncm; in ncm_bind()
1511 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1539 ncm->port.open = ncm_open; in ncm_bind()
1540 ncm->port.close = ncm_close; in ncm_bind()
1542 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1543 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);