Lines Matching refs:ncm

527 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
529 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
530 ncm->is_crc = false; in ncm_reset_values()
531 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
532 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
535 ncm->port.header_len = 0; in ncm_reset_values()
537 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
538 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
544 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
546 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
548 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
553 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
557 switch (ncm->notify_state) { in ncm_do_notify()
563 if (ncm->is_open) in ncm_do_notify()
571 ncm->is_open ? "true" : "false"); in ncm_do_notify()
572 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
587 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
591 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
593 atomic_inc(&ncm->notify_count); in ncm_do_notify()
600 spin_unlock(&ncm->lock); in ncm_do_notify()
601 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
602 spin_lock(&ncm->lock); in ncm_do_notify()
604 atomic_dec(&ncm->notify_count); in ncm_do_notify()
612 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
624 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
625 ncm_do_notify(ncm); in ncm_notify()
630 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
631 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
634 spin_lock(&ncm->lock); in ncm_notify_complete()
639 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
643 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
644 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
649 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
652 ncm_do_notify(ncm); in ncm_notify_complete()
653 spin_unlock(&ncm->lock); in ncm_notify_complete()
661 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
677 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
688 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
707 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
715 ncm->port.cdc_filter = w_value; in ncm_setup()
731 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
742 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
744 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
747 ncm->port.fixed_in_len); in ncm_setup()
753 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
768 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
770 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
780 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
784 ncm->parser_opts = &ndp16_opts; in ncm_setup()
788 ncm->parser_opts = &ndp32_opts; in ncm_setup()
802 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
804 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
814 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
818 ncm->is_crc = false; in ncm_setup()
822 ncm->is_crc = true; in ncm_setup()
844 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
845 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
868 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
872 if (intf == ncm->ctrl_id) { in ncm_set_alt()
877 usb_ep_disable(ncm->notify); in ncm_set_alt()
879 if (!(ncm->notify->desc)) { in ncm_set_alt()
881 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
884 usb_ep_enable(ncm->notify); in ncm_set_alt()
887 } else if (intf == ncm->data_id) { in ncm_set_alt()
891 if (ncm->port.in_ep->enabled) { in ncm_set_alt()
893 ncm->timer_stopping = true; in ncm_set_alt()
894 ncm->netdev = NULL; in ncm_set_alt()
895 gether_disconnect(&ncm->port); in ncm_set_alt()
896 ncm_reset_values(ncm); in ncm_set_alt()
906 if (!ncm->port.in_ep->desc || in ncm_set_alt()
907 !ncm->port.out_ep->desc) { in ncm_set_alt()
910 ncm->port.in_ep) || in ncm_set_alt()
912 ncm->port.out_ep)) { in ncm_set_alt()
913 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
914 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
923 ncm->port.is_zlp_ok = in ncm_set_alt()
925 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
927 net = gether_connect(&ncm->port); in ncm_set_alt()
930 ncm->netdev = net; in ncm_set_alt()
931 ncm->timer_stopping = false; in ncm_set_alt()
934 spin_lock(&ncm->lock); in ncm_set_alt()
935 ncm_notify(ncm); in ncm_set_alt()
936 spin_unlock(&ncm->lock); in ncm_set_alt()
951 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
953 if (intf == ncm->ctrl_id) in ncm_get_alt()
955 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
958 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
966 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
971 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
973 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
974 ncm->skb_tx_data->len; in package_for_tx()
975 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
976 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
979 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
987 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
988 ncm->ndp_dgram_count = 0; in package_for_tx()
990 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
995 swap(skb2, ncm->skb_tx_data); in package_for_tx()
996 if (ncm->skb_tx_data) { in package_for_tx()
997 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
998 ncm->skb_tx_data = NULL; in package_for_tx()
1005 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
1006 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
1007 ncm->skb_tx_ndp = NULL; in package_for_tx()
1018 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1025 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1026 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1032 if (!skb && !ncm->skb_tx_data) in ncm_wrap_ntb()
1037 if (ncm->is_crc) { in ncm_wrap_ntb()
1053 if (ncm->skb_tx_data in ncm_wrap_ntb()
1054 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1055 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1057 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1059 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1064 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1070 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1071 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1074 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1075 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1086 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1090 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1093 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1094 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1097 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1101 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1107 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1111 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1113 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1121 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1124 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1125 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1129 } else if (ncm->skb_tx_data && ncm->timer_force_tx) { in ncm_wrap_ntb()
1131 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1139 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1143 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1144 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1145 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1146 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1157 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1160 if (!ncm->timer_stopping && ncm->skb_tx_data) { in ncm_tx_timeout()
1161 ncm->timer_force_tx = true; in ncm_tx_timeout()
1169 ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev); in ncm_tx_timeout()
1171 ncm->timer_force_tx = false; in ncm_tx_timeout()
1180 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1191 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1192 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1241 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1294 if (ncm->is_crc) { in ncm_unwrap_ntb()
1324 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1354 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1359 if (ncm->port.in_ep->enabled) { in ncm_disable()
1360 ncm->timer_stopping = true; in ncm_disable()
1361 ncm->netdev = NULL; in ncm_disable()
1362 gether_disconnect(&ncm->port); in ncm_disable()
1365 if (ncm->notify->enabled) { in ncm_disable()
1366 usb_ep_disable(ncm->notify); in ncm_disable()
1367 ncm->notify->desc = NULL; in ncm_disable()
1393 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1395 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1397 spin_lock(&ncm->lock); in ncm_open()
1398 ncm->is_open = true; in ncm_open()
1399 ncm_notify(ncm); in ncm_open()
1400 spin_unlock(&ncm->lock); in ncm_open()
1405 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1407 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1409 spin_lock(&ncm->lock); in ncm_close()
1410 ncm->is_open = false; in ncm_close()
1411 ncm_notify(ncm); in ncm_close()
1412 spin_unlock(&ncm->lock); in ncm_close()
1422 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1474 ncm->ctrl_id = status; in ncm_bind()
1487 ncm->data_id = status; in ncm_bind()
1499 ncm->port.in_ep = ep; in ncm_bind()
1504 ncm->port.out_ep = ep; in ncm_bind()
1509 ncm->notify = ep; in ncm_bind()
1514 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1515 if (!ncm->notify_req) in ncm_bind()
1517 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1518 if (!ncm->notify_req->buf) in ncm_bind()
1520 ncm->notify_req->context = ncm; in ncm_bind()
1521 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1549 ncm->port.open = ncm_open; in ncm_bind()
1550 ncm->port.close = ncm_close; in ncm_bind()
1552 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1553 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1558 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1559 ncm->notify->name); in ncm_bind()
1566 if (ncm->notify_req) { in ncm_bind()
1567 kfree(ncm->notify_req->buf); in ncm_bind()
1568 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1583 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1586 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1589 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1592 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1595 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1664 struct f_ncm *ncm; in ncm_free() local
1667 ncm = func_to_ncm(f); in ncm_free()
1669 kfree(ncm); in ncm_free()
1677 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1681 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1689 if (atomic_read(&ncm->notify_count)) { in ncm_unbind()
1690 usb_ep_dequeue(ncm->notify, ncm->notify_req); in ncm_unbind()
1691 atomic_set(&ncm->notify_count, 0); in ncm_unbind()
1694 kfree(ncm->notify_req->buf); in ncm_unbind()
1695 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1700 struct f_ncm *ncm; in ncm_alloc() local
1705 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1706 if (!ncm) in ncm_alloc()
1714 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1715 sizeof(ncm->ethaddr)); in ncm_alloc()
1717 kfree(ncm); in ncm_alloc()
1721 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1723 spin_lock_init(&ncm->lock); in ncm_alloc()
1724 ncm_reset_values(ncm); in ncm_alloc()
1725 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1727 ncm->port.is_fixed = true; in ncm_alloc()
1728 ncm->port.supports_multi_frame = true; in ncm_alloc()
1730 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1732 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1733 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1734 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1735 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1736 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1737 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1738 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1740 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1741 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1743 return &ncm->port.func; in ncm_alloc()
1746 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);