Lines Matching refs:ncm

458 static inline void ncm_reset_values(struct f_ncm *ncm)  in ncm_reset_values()  argument
460 ncm->parser_opts = &ndp16_opts; in ncm_reset_values()
461 ncm->is_crc = false; in ncm_reset_values()
462 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_reset_values()
465 ncm->port.header_len = 0; in ncm_reset_values()
467 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); in ncm_reset_values()
468 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE; in ncm_reset_values()
474 static void ncm_do_notify(struct f_ncm *ncm) in ncm_do_notify() argument
476 struct usb_request *req = ncm->notify_req; in ncm_do_notify()
478 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_do_notify()
487 switch (ncm->notify_state) { in ncm_do_notify()
493 if (ncm->is_open) in ncm_do_notify()
501 ncm->is_open ? "true" : "false"); in ncm_do_notify()
502 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_do_notify()
517 ncm->notify_state = NCM_NOTIFY_CONNECT; in ncm_do_notify()
521 event->wIndex = cpu_to_le16(ncm->ctrl_id); in ncm_do_notify()
523 ncm->notify_req = NULL; in ncm_do_notify()
529 spin_unlock(&ncm->lock); in ncm_do_notify()
530 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC); in ncm_do_notify()
531 spin_lock(&ncm->lock); in ncm_do_notify()
533 ncm->notify_req = req; in ncm_do_notify()
541 static void ncm_notify(struct f_ncm *ncm) in ncm_notify() argument
553 ncm->notify_state = NCM_NOTIFY_SPEED; in ncm_notify()
554 ncm_do_notify(ncm); in ncm_notify()
559 struct f_ncm *ncm = req->context; in ncm_notify_complete() local
560 struct usb_composite_dev *cdev = ncm->port.func.config->cdev; in ncm_notify_complete()
563 spin_lock(&ncm->lock); in ncm_notify_complete()
571 ncm->notify_state = NCM_NOTIFY_NONE; in ncm_notify_complete()
578 ncm->notify_req = req; in ncm_notify_complete()
579 ncm_do_notify(ncm); in ncm_notify_complete()
580 spin_unlock(&ncm->lock); in ncm_notify_complete()
588 struct f_ncm *ncm = func_to_ncm(f); in ncm_ep0out_complete() local
604 ncm->port.fixed_in_len = in_size; in ncm_ep0out_complete()
615 struct f_ncm *ncm = func_to_ncm(f); in ncm_setup() local
634 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
642 ncm->port.cdc_filter = w_value; in ncm_setup()
658 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
669 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
671 put_unaligned_le32(ncm->port.fixed_in_len, req->buf); in ncm_setup()
674 ncm->port.fixed_in_len); in ncm_setup()
680 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
695 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
697 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001; in ncm_setup()
707 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
711 ncm->parser_opts = &ndp16_opts; in ncm_setup()
715 ncm->parser_opts = &ndp32_opts; in ncm_setup()
729 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id) in ncm_setup()
731 is_crc = ncm->is_crc ? 0x0001 : 0x0000; in ncm_setup()
743 if (w_length != 0 || w_index != ncm->ctrl_id) in ncm_setup()
747 ncm->is_crc = false; in ncm_setup()
752 ncm->is_crc = true; in ncm_setup()
759 ncm->ndp_sign = ncm->parser_opts->ndp_sign | ndp_hdr_crc; in ncm_setup()
798 struct f_ncm *ncm = func_to_ncm(f); in ncm_set_alt() local
802 if (intf == ncm->ctrl_id) { in ncm_set_alt()
807 usb_ep_disable(ncm->notify); in ncm_set_alt()
809 if (!(ncm->notify->desc)) { in ncm_set_alt()
811 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
814 usb_ep_enable(ncm->notify); in ncm_set_alt()
817 } else if (intf == ncm->data_id) { in ncm_set_alt()
821 if (ncm->port.in_ep->enabled) { in ncm_set_alt()
823 ncm->timer_stopping = true; in ncm_set_alt()
824 ncm->netdev = NULL; in ncm_set_alt()
825 gether_disconnect(&ncm->port); in ncm_set_alt()
826 ncm_reset_values(ncm); in ncm_set_alt()
836 if (!ncm->port.in_ep->desc || in ncm_set_alt()
837 !ncm->port.out_ep->desc) { in ncm_set_alt()
840 ncm->port.in_ep) || in ncm_set_alt()
842 ncm->port.out_ep)) { in ncm_set_alt()
843 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
844 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
853 ncm->port.is_zlp_ok = in ncm_set_alt()
855 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
857 net = gether_connect(&ncm->port); in ncm_set_alt()
860 ncm->netdev = net; in ncm_set_alt()
861 ncm->timer_stopping = false; in ncm_set_alt()
864 spin_lock(&ncm->lock); in ncm_set_alt()
865 ncm_notify(ncm); in ncm_set_alt()
866 spin_unlock(&ncm->lock); in ncm_set_alt()
881 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
883 if (intf == ncm->ctrl_id) in ncm_get_alt()
885 return ncm->port.in_ep->enabled ? 1 : 0; in ncm_get_alt()
888 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
896 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
901 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
903 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
904 ncm->skb_tx_data->len; in package_for_tx()
905 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
906 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
909 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
917 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
918 ncm->ndp_dgram_count = 0; in package_for_tx()
920 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
925 swap(skb2, ncm->skb_tx_data); in package_for_tx()
926 if (ncm->skb_tx_data) { in package_for_tx()
927 dev_kfree_skb_any(ncm->skb_tx_data); in package_for_tx()
928 ncm->skb_tx_data = NULL; in package_for_tx()
936 ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len); in package_for_tx()
937 memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
938 dev_kfree_skb_any(ncm->skb_tx_ndp); in package_for_tx()
939 ncm->skb_tx_ndp = NULL; in package_for_tx()
951 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
958 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
959 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
965 if (!skb && !ncm->skb_tx_data) in ncm_wrap_ntb()
970 if (ncm->is_crc) { in ncm_wrap_ntb()
986 if (ncm->skb_tx_data in ncm_wrap_ntb()
987 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
988 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
990 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
992 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
997 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1003 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1004 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1007 ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1019 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1023 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1025 ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, in ncm_wrap_ntb()
1029 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1033 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1039 hrtimer_start(&ncm->task_timer, in ncm_wrap_ntb()
1044 ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1047 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1055 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1058 ntb_data = (void *) skb_put(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1060 ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len); in ncm_wrap_ntb()
1065 } else if (ncm->skb_tx_data && ncm->timer_force_tx) { in ncm_wrap_ntb()
1067 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1075 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1079 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1080 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1081 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1082 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1092 struct f_ncm *ncm = (void *)data; in ncm_tx_tasklet() local
1094 if (ncm->timer_stopping) in ncm_tx_tasklet()
1098 if (ncm->skb_tx_data) { in ncm_tx_tasklet()
1099 ncm->timer_force_tx = true; in ncm_tx_tasklet()
1107 ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev); in ncm_tx_tasklet()
1109 ncm->timer_force_tx = false; in ncm_tx_tasklet()
1119 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1120 tasklet_schedule(&ncm->tx_tasklet); in ncm_tx_timeout()
1128 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1137 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1138 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1178 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1217 if (ncm->is_crc) { in ncm_unwrap_ntb()
1240 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1271 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1276 if (ncm->port.in_ep->enabled) { in ncm_disable()
1277 ncm->timer_stopping = true; in ncm_disable()
1278 ncm->netdev = NULL; in ncm_disable()
1279 gether_disconnect(&ncm->port); in ncm_disable()
1282 if (ncm->notify->enabled) { in ncm_disable()
1283 usb_ep_disable(ncm->notify); in ncm_disable()
1284 ncm->notify->desc = NULL; in ncm_disable()
1310 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1312 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1314 spin_lock(&ncm->lock); in ncm_open()
1315 ncm->is_open = true; in ncm_open()
1316 ncm_notify(ncm); in ncm_open()
1317 spin_unlock(&ncm->lock); in ncm_open()
1322 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1324 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1326 spin_lock(&ncm->lock); in ncm_close()
1327 ncm->is_open = false; in ncm_close()
1328 ncm_notify(ncm); in ncm_close()
1329 spin_unlock(&ncm->lock); in ncm_close()
1339 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1379 ncm->ctrl_id = status; in ncm_bind()
1388 ncm->data_id = status; in ncm_bind()
1400 ncm->port.in_ep = ep; in ncm_bind()
1405 ncm->port.out_ep = ep; in ncm_bind()
1410 ncm->notify = ep; in ncm_bind()
1415 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1416 if (!ncm->notify_req) in ncm_bind()
1418 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1419 if (!ncm->notify_req->buf) in ncm_bind()
1421 ncm->notify_req->context = ncm; in ncm_bind()
1422 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1445 ncm->port.open = ncm_open; in ncm_bind()
1446 ncm->port.close = ncm_close; in ncm_bind()
1448 tasklet_init(&ncm->tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm); in ncm_bind()
1449 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ncm_bind()
1450 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1454 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1455 ncm->notify->name); in ncm_bind()
1459 if (ncm->notify_req) { in ncm_bind()
1460 kfree(ncm->notify_req->buf); in ncm_bind()
1461 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1476 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1479 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1482 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1485 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1488 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1539 struct f_ncm *ncm; in ncm_free() local
1542 ncm = func_to_ncm(f); in ncm_free()
1544 kfree(ncm); in ncm_free()
1552 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1556 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1557 tasklet_kill(&ncm->tx_tasklet); in ncm_unbind()
1562 kfree(ncm->notify_req->buf); in ncm_unbind()
1563 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1568 struct f_ncm *ncm; in ncm_alloc() local
1573 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1574 if (!ncm) in ncm_alloc()
1582 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1583 sizeof(ncm->ethaddr)); in ncm_alloc()
1585 kfree(ncm); in ncm_alloc()
1589 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1591 spin_lock_init(&ncm->lock); in ncm_alloc()
1592 ncm_reset_values(ncm); in ncm_alloc()
1593 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1595 ncm->port.is_fixed = true; in ncm_alloc()
1596 ncm->port.supports_multi_frame = true; in ncm_alloc()
1598 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1600 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1601 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1602 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1603 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1604 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1605 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1606 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1608 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1609 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1611 return &ncm->port.func; in ncm_alloc()
1614 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);