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->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
532 ncm->port.header_len = 0; in ncm_reset_values()
534 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
535 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
541 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
543 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
545 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
554 switch (ncm->notify_state) { in ncm_do_notify()
560 if (ncm->is_open) in ncm_do_notify()
568 ncm->is_open ? "true" : "false"); in ncm_do_notify()
569 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
584 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
588 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
590 ncm->notify_req = NULL; in ncm_do_notify()
596 spin_unlock(&ncm->lock); in ncm_do_notify()
597 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
598 spin_lock(&ncm->lock); in ncm_do_notify()
600 ncm->notify_req = req; in ncm_do_notify()
608 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
620 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
621 ncm_do_notify(ncm); in ncm_notify()
626 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
627 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
630 spin_lock(&ncm->lock); in ncm_notify_complete()
638 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
645 ncm->notify_req = req; 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()
810 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
814 ncm->is_crc = false; in ncm_setup()
819 ncm->is_crc = true; in ncm_setup()
826 ncm->ndp_sign = ncm->parser_opts->ndp_sign | ndp_hdr_crc; in ncm_setup()
865 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
869 if (intf == ncm->ctrl_id) { in ncm_set_alt()
874 usb_ep_disable(ncm->notify); in ncm_set_alt()
876 if (!(ncm->notify->desc)) { in ncm_set_alt()
878 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
881 usb_ep_enable(ncm->notify); in ncm_set_alt()
884 } else if (intf == ncm->data_id) { in ncm_set_alt()
888 if (ncm->port.in_ep->enabled) { in ncm_set_alt()
890 ncm->timer_stopping = true; 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()
928 ncm->timer_stopping = false; in ncm_set_alt()
931 spin_lock(&ncm->lock); in ncm_set_alt()
932 ncm_notify(ncm); in ncm_set_alt()
933 spin_unlock(&ncm->lock); in ncm_set_alt()
948 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
950 if (intf == ncm->ctrl_id) in ncm_get_alt()
952 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
955 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
963 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
968 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
970 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
971 ncm->skb_tx_data->len; in package_for_tx()
972 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
973 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
976 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
984 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
985 ncm->ndp_dgram_count = 0; in package_for_tx()
987 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
992 swap(skb2, ncm->skb_tx_data); in package_for_tx()
993 if (ncm->skb_tx_data) { in package_for_tx()
994 dev_consume_skb_any(ncm->skb_tx_data); in package_for_tx()
995 ncm->skb_tx_data = NULL; in package_for_tx()
1002 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
1003 dev_consume_skb_any(ncm->skb_tx_ndp); in package_for_tx()
1004 ncm->skb_tx_ndp = NULL; in package_for_tx()
1015 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
1022 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
1023 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
1029 if (!skb && !ncm->skb_tx_data) in ncm_wrap_ntb()
1034 if (ncm->is_crc) { in ncm_wrap_ntb()
1050 if (ncm->skb_tx_data in ncm_wrap_ntb()
1051 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
1052 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
1054 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
1056 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1061 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1067 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1068 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1071 ncm->skb_tx_data->dev = ncm->netdev; in ncm_wrap_ntb()
1072 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1083 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1087 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1090 ncm->skb_tx_ndp->dev = ncm->netdev; in ncm_wrap_ntb()
1091 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size); in ncm_wrap_ntb()
1094 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1098 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1104 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS, in ncm_wrap_ntb()
1108 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1110 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1118 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1121 skb_put_zero(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1122 skb_put_data(ncm->skb_tx_data, skb->data, skb->len); in ncm_wrap_ntb()
1126 } else if (ncm->skb_tx_data && ncm->timer_force_tx) { 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
1157 if (!ncm->timer_stopping && ncm->skb_tx_data) { in ncm_tx_timeout()
1158 ncm->timer_force_tx = true; in ncm_tx_timeout()
1166 ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev); in ncm_tx_timeout()
1168 ncm->timer_force_tx = false; in ncm_tx_timeout()
1177 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()
1227 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1266 if (ncm->is_crc) { in ncm_unwrap_ntb()
1289 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1320 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1325 if (ncm->port.in_ep->enabled) { in ncm_disable()
1326 ncm->timer_stopping = true; in ncm_disable()
1327 ncm->netdev = NULL; in ncm_disable()
1328 gether_disconnect(&ncm->port); in ncm_disable()
1331 if (ncm->notify->enabled) { in ncm_disable()
1332 usb_ep_disable(ncm->notify); in ncm_disable()
1333 ncm->notify->desc = NULL; in ncm_disable()
1359 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1361 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1363 spin_lock(&ncm->lock); in ncm_open()
1364 ncm->is_open = true; in ncm_open()
1365 ncm_notify(ncm); in ncm_open()
1366 spin_unlock(&ncm->lock); in ncm_open()
1371 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1373 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1375 spin_lock(&ncm->lock); in ncm_close()
1376 ncm->is_open = false; in ncm_close()
1377 ncm_notify(ncm); in ncm_close()
1378 spin_unlock(&ncm->lock); in ncm_close()
1388 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1428 ncm->ctrl_id = status; in ncm_bind()
1437 ncm->data_id = status; in ncm_bind()
1449 ncm->port.in_ep = ep; in ncm_bind()
1454 ncm->port.out_ep = ep; in ncm_bind()
1459 ncm->notify = ep; in ncm_bind()
1464 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1465 if (!ncm->notify_req) in ncm_bind()
1467 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1468 if (!ncm->notify_req->buf) in ncm_bind()
1470 ncm->notify_req->context = ncm; in ncm_bind()
1471 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1499 ncm->port.open = ncm_open; in ncm_bind()
1500 ncm->port.close = ncm_close; in ncm_bind()
1502 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in ncm_bind()
1503 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1508 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1509 ncm->notify->name); in ncm_bind()
1513 if (ncm->notify_req) { in ncm_bind()
1514 kfree(ncm->notify_req->buf); in ncm_bind()
1515 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1530 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1533 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1536 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1539 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1542 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1593 struct f_ncm *ncm; in ncm_free() local
1596 ncm = func_to_ncm(f); in ncm_free()
1598 kfree(ncm); in ncm_free()
1606 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1610 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1615 kfree(ncm->notify_req->buf); in ncm_unbind()
1616 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1621 struct f_ncm *ncm; in ncm_alloc() local
1626 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1627 if (!ncm) in ncm_alloc()
1635 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1636 sizeof(ncm->ethaddr)); in ncm_alloc()
1638 kfree(ncm); in ncm_alloc()
1642 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1644 spin_lock_init(&ncm->lock); in ncm_alloc()
1645 ncm_reset_values(ncm); in ncm_alloc()
1646 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1648 ncm->port.is_fixed = true; in ncm_alloc()
1649 ncm->port.supports_multi_frame = true; in ncm_alloc()
1651 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1653 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1654 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1655 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1656 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1657 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1658 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1659 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1661 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1662 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1664 return &ncm->port.func; in ncm_alloc()
1667 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);