Lines Matching refs:ncm

525 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
527 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
528 ncm->is_crc = false; in ncm_reset_values()
529 ncm->ndp_sign = ncm->parser_opts->ndp_sign; in ncm_reset_values()
530 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
533 ncm->port.header_len = 0; in ncm_reset_values()
535 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
536 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
542 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
544 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
546 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
551 if (atomic_read(&ncm->notify_count)) in ncm_do_notify()
555 switch (ncm->notify_state) { in ncm_do_notify()
561 if (ncm->is_open) in ncm_do_notify()
569 ncm->is_open ? "true" : "false"); in ncm_do_notify()
570 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
585 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
589 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
591 atomic_inc(&ncm->notify_count); in ncm_do_notify()
598 spin_unlock(&ncm->lock); in ncm_do_notify()
599 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
600 spin_lock(&ncm->lock); in ncm_do_notify()
602 atomic_dec(&ncm->notify_count); in ncm_do_notify()
610 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
622 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
623 ncm_do_notify(ncm); in ncm_notify()
628 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
629 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
632 spin_lock(&ncm->lock); in ncm_notify_complete()
637 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
641 atomic_set(&ncm->notify_count, 0); in ncm_notify_complete()
642 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
647 atomic_dec(&ncm->notify_count); in ncm_notify_complete()
650 ncm_do_notify(ncm); in ncm_notify_complete()
651 spin_unlock(&ncm->lock); in ncm_notify_complete()
659 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
675 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
686 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
705 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
713 ncm->port.cdc_filter = w_value; in ncm_setup()
729 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
740 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
742 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
745 ncm->port.fixed_in_len); in ncm_setup()
751 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
766 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
768 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
778 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
782 ncm->parser_opts = &ndp16_opts; in ncm_setup()
786 ncm->parser_opts = &ndp32_opts; in ncm_setup()
800 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
802 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
812 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
816 ncm->is_crc = false; in ncm_setup()
820 ncm->is_crc = true; in ncm_setup()
842 ncm->ndp_sign = ncm->parser_opts->ndp_sign | in ncm_setup()
843 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); in ncm_setup()
866 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
870 if (intf == ncm->ctrl_id) { in ncm_set_alt()
875 usb_ep_disable(ncm->notify); in ncm_set_alt()
877 if (!(ncm->notify->desc)) { in ncm_set_alt()
879 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
882 usb_ep_enable(ncm->notify); in ncm_set_alt()
885 } else if (intf == ncm->data_id) { in ncm_set_alt()
889 if (ncm->port.in_ep->enabled) { in ncm_set_alt()
891 ncm->netdev = NULL; in ncm_set_alt()
892 gether_disconnect(&ncm->port); in ncm_set_alt()
893 ncm_reset_values(ncm); in ncm_set_alt()
903 if (!ncm->port.in_ep->desc || in ncm_set_alt()
904 !ncm->port.out_ep->desc) { in ncm_set_alt()
907 ncm->port.in_ep) || in ncm_set_alt()
909 ncm->port.out_ep)) { in ncm_set_alt()
910 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
911 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
920 ncm->port.is_zlp_ok = in ncm_set_alt()
922 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
924 net = gether_connect(&ncm->port); in ncm_set_alt()
927 ncm->netdev = net; in ncm_set_alt()
930 spin_lock(&ncm->lock); in ncm_set_alt()
931 ncm_notify(ncm); in ncm_set_alt()
932 spin_unlock(&ncm->lock); in ncm_set_alt()
947 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
949 if (intf == ncm->ctrl_id) in ncm_get_alt()
951 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
954 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
962 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
967 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
969 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
970 ncm->skb_tx_data->len; in package_for_tx()
971 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
972 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
975 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
983 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
984 ncm->ndp_dgram_count = 0; in package_for_tx()
986 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
991 swap(skb2, ncm->skb_tx_data); in package_for_tx()
992 if (ncm->skb_tx_data) { in package_for_tx()
993 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
994 ncm->skb_tx_data = NULL; in package_for_tx()
1001 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
1002 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
1003 ncm->skb_tx_ndp = NULL; in package_for_tx()
1014 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1023 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1024 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1031 if (ncm->is_crc) { in ncm_wrap_ntb()
1047 if (ncm->skb_tx_data in ncm_wrap_ntb()
1048 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1049 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1051 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1053 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1058 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1064 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1065 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1068 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1069 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1080 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1084 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1087 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1088 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1091 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1095 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1100 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1105 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1107 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1115 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1118 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1119 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1123 } else if (ncm->skb_tx_data) { in ncm_wrap_ntb()
1128 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1136 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1140 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1141 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1142 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1143 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1154 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1155 struct net_device *netdev = READ_ONCE(ncm->netdev); in ncm_tx_timeout()
1175 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1186 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1187 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1236 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1289 if (ncm->is_crc) { in ncm_unwrap_ntb()
1319 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1349 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1354 if (ncm->port.in_ep->enabled) { in ncm_disable()
1355 ncm->netdev = NULL; in ncm_disable()
1356 gether_disconnect(&ncm->port); in ncm_disable()
1359 if (ncm->notify->enabled) { in ncm_disable()
1360 usb_ep_disable(ncm->notify); in ncm_disable()
1361 ncm->notify->desc = NULL; in ncm_disable()
1387 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1389 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1391 spin_lock(&ncm->lock); in ncm_open()
1392 ncm->is_open = true; in ncm_open()
1393 ncm_notify(ncm); in ncm_open()
1394 spin_unlock(&ncm->lock); in ncm_open()
1399 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1401 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1403 spin_lock(&ncm->lock); in ncm_close()
1404 ncm->is_open = false; in ncm_close()
1405 ncm_notify(ncm); in ncm_close()
1406 spin_unlock(&ncm->lock); in ncm_close()
1416 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1468 ncm->ctrl_id = status; in ncm_bind()
1481 ncm->data_id = status; in ncm_bind()
1493 ncm->port.in_ep = ep; in ncm_bind()
1498 ncm->port.out_ep = ep; in ncm_bind()
1503 ncm->notify = ep; in ncm_bind()
1508 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1509 if (!ncm->notify_req) in ncm_bind()
1511 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1512 if (!ncm->notify_req->buf) in ncm_bind()
1514 ncm->notify_req->context = ncm; in ncm_bind()
1515 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1543 ncm->port.open = ncm_open; in ncm_bind()
1544 ncm->port.close = ncm_close; in ncm_bind()
1546 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1547 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1552 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1553 ncm->notify->name); in ncm_bind()
1560 if (ncm->notify_req) { in ncm_bind()
1561 kfree(ncm->notify_req->buf); in ncm_bind()
1562 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1577 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1580 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1583 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1586 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1589 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1658 struct f_ncm *ncm; in ncm_free() local
1661 ncm = func_to_ncm(f); in ncm_free()
1663 kfree(ncm); in ncm_free()
1671 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1675 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1683 if (atomic_read(&ncm->notify_count)) { in ncm_unbind()
1684 usb_ep_dequeue(ncm->notify, ncm->notify_req); in ncm_unbind()
1685 atomic_set(&ncm->notify_count, 0); in ncm_unbind()
1688 kfree(ncm->notify_req->buf); in ncm_unbind()
1689 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1694 struct f_ncm *ncm; in ncm_alloc() local
1699 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1700 if (!ncm) in ncm_alloc()
1708 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1709 sizeof(ncm->ethaddr)); in ncm_alloc()
1711 kfree(ncm); in ncm_alloc()
1715 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1717 spin_lock_init(&ncm->lock); in ncm_alloc()
1718 ncm_reset_values(ncm); in ncm_alloc()
1719 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1721 ncm->port.is_fixed = true; in ncm_alloc()
1722 ncm->port.supports_multi_frame = true; in ncm_alloc()
1724 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1726 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1727 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1728 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1729 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1730 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1731 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1732 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1734 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1735 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1737 return &ncm->port.func; in ncm_alloc()
1740 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);