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()
806 if (ncm->notify->driver_data) { in ncm_set_alt()
808 usb_ep_disable(ncm->notify); in ncm_set_alt()
811 if (!(ncm->notify->desc)) { in ncm_set_alt()
813 if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) in ncm_set_alt()
816 usb_ep_enable(ncm->notify); in ncm_set_alt()
817 ncm->notify->driver_data = ncm; in ncm_set_alt()
820 } else if (intf == ncm->data_id) { in ncm_set_alt()
824 if (ncm->port.in_ep->driver_data) { in ncm_set_alt()
826 ncm->timer_stopping = true; in ncm_set_alt()
827 ncm->netdev = NULL; in ncm_set_alt()
828 gether_disconnect(&ncm->port); in ncm_set_alt()
829 ncm_reset_values(ncm); in ncm_set_alt()
839 if (!ncm->port.in_ep->desc || in ncm_set_alt()
840 !ncm->port.out_ep->desc) { in ncm_set_alt()
843 ncm->port.in_ep) || in ncm_set_alt()
845 ncm->port.out_ep)) { in ncm_set_alt()
846 ncm->port.in_ep->desc = NULL; in ncm_set_alt()
847 ncm->port.out_ep->desc = NULL; in ncm_set_alt()
856 ncm->port.is_zlp_ok = !( in ncm_set_alt()
859 ncm->port.cdc_filter = DEFAULT_FILTER; in ncm_set_alt()
861 net = gether_connect(&ncm->port); in ncm_set_alt()
864 ncm->netdev = net; in ncm_set_alt()
865 ncm->timer_stopping = false; in ncm_set_alt()
868 spin_lock(&ncm->lock); in ncm_set_alt()
869 ncm_notify(ncm); in ncm_set_alt()
870 spin_unlock(&ncm->lock); in ncm_set_alt()
885 struct f_ncm *ncm = func_to_ncm(f); in ncm_get_alt() local
887 if (intf == ncm->ctrl_id) in ncm_get_alt()
889 return ncm->port.in_ep->driver_data ? 1 : 0; in ncm_get_alt()
892 static struct sk_buff *package_for_tx(struct f_ncm *ncm) in package_for_tx() argument
900 const struct ndp_parser_opts *opts = ncm->parser_opts; in package_for_tx()
905 hrtimer_try_to_cancel(&ncm->task_timer); in package_for_tx()
907 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) - in package_for_tx()
908 ncm->skb_tx_data->len; in package_for_tx()
909 ndp_index = ncm->skb_tx_data->len + ndp_pad; in package_for_tx()
910 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len; in package_for_tx()
913 ntb_iter = (void *) ncm->skb_tx_data->data; in package_for_tx()
921 (ncm->ndp_dgram_count * dgram_idx_len); in package_for_tx()
922 ncm->ndp_dgram_count = 0; in package_for_tx()
924 ntb_iter = (void *) ncm->skb_tx_ndp->data; in package_for_tx()
929 swap(skb2, ncm->skb_tx_data); in package_for_tx()
930 if (ncm->skb_tx_data) { in package_for_tx()
931 dev_kfree_skb_any(ncm->skb_tx_data); in package_for_tx()
932 ncm->skb_tx_data = NULL; in package_for_tx()
940 ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len); in package_for_tx()
941 memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); in package_for_tx()
942 dev_kfree_skb_any(ncm->skb_tx_ndp); in package_for_tx()
943 ncm->skb_tx_ndp = NULL; in package_for_tx()
955 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_wrap_ntb() local
962 unsigned max_size = ncm->port.fixed_in_len; in ncm_wrap_ntb()
963 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_wrap_ntb()
969 if (!skb && !ncm->skb_tx_data) in ncm_wrap_ntb()
974 if (ncm->is_crc) { in ncm_wrap_ntb()
990 if (ncm->skb_tx_data in ncm_wrap_ntb()
991 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE in ncm_wrap_ntb()
992 || (ncm->skb_tx_data->len + in ncm_wrap_ntb()
994 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len)) in ncm_wrap_ntb()
996 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1001 if (!ncm->skb_tx_data) { in ncm_wrap_ntb()
1007 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC); in ncm_wrap_ntb()
1008 if (!ncm->skb_tx_data) in ncm_wrap_ntb()
1011 ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len); in ncm_wrap_ntb()
1023 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size in ncm_wrap_ntb()
1027 if (!ncm->skb_tx_ndp) in ncm_wrap_ntb()
1029 ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, in ncm_wrap_ntb()
1033 put_unaligned_le32(ncm->ndp_sign, ntb_ndp); in ncm_wrap_ntb()
1037 ncm->ndp_dgram_count = 1; in ncm_wrap_ntb()
1043 hrtimer_start(&ncm->task_timer, in ncm_wrap_ntb()
1048 ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, dgram_idx_len); in ncm_wrap_ntb()
1051 ncb_len = ncm->skb_tx_data->len; in ncm_wrap_ntb()
1059 ncm->ndp_dgram_count++; in ncm_wrap_ntb()
1062 ntb_data = (void *) skb_put(ncm->skb_tx_data, dgram_pad); in ncm_wrap_ntb()
1064 ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len); in ncm_wrap_ntb()
1069 } else if (ncm->skb_tx_data && ncm->timer_force_tx) { in ncm_wrap_ntb()
1071 skb2 = package_for_tx(ncm); in ncm_wrap_ntb()
1079 ncm->netdev->stats.tx_dropped++; in ncm_wrap_ntb()
1083 if (ncm->skb_tx_data) in ncm_wrap_ntb()
1084 dev_kfree_skb_any(ncm->skb_tx_data); in ncm_wrap_ntb()
1085 if (ncm->skb_tx_ndp) in ncm_wrap_ntb()
1086 dev_kfree_skb_any(ncm->skb_tx_ndp); in ncm_wrap_ntb()
1096 struct f_ncm *ncm = (void *)data; in ncm_tx_tasklet() local
1098 if (ncm->timer_stopping) in ncm_tx_tasklet()
1102 if (ncm->skb_tx_data) { in ncm_tx_tasklet()
1103 ncm->timer_force_tx = true; in ncm_tx_tasklet()
1111 ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev); in ncm_tx_tasklet()
1113 ncm->timer_force_tx = false; in ncm_tx_tasklet()
1123 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); in ncm_tx_timeout() local
1124 tasklet_schedule(&ncm->tx_tasklet); in ncm_tx_timeout()
1132 struct f_ncm *ncm = func_to_ncm(&port->func); in ncm_unwrap_ntb() local
1141 const struct ndp_parser_opts *opts = ncm->parser_opts; in ncm_unwrap_ntb()
1142 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; in ncm_unwrap_ntb()
1182 if (get_unaligned_le32(tmp) != ncm->ndp_sign) { in ncm_unwrap_ntb()
1221 if (ncm->is_crc) { in ncm_unwrap_ntb()
1244 skb2 = netdev_alloc_skb_ip_align(ncm->netdev, in ncm_unwrap_ntb()
1275 struct f_ncm *ncm = func_to_ncm(f); in ncm_disable() local
1280 if (ncm->port.in_ep->driver_data) { in ncm_disable()
1281 ncm->timer_stopping = true; in ncm_disable()
1282 ncm->netdev = NULL; in ncm_disable()
1283 gether_disconnect(&ncm->port); in ncm_disable()
1286 if (ncm->notify->driver_data) { in ncm_disable()
1287 usb_ep_disable(ncm->notify); in ncm_disable()
1288 ncm->notify->driver_data = NULL; in ncm_disable()
1289 ncm->notify->desc = NULL; in ncm_disable()
1315 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_open() local
1317 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_open()
1319 spin_lock(&ncm->lock); in ncm_open()
1320 ncm->is_open = true; in ncm_open()
1321 ncm_notify(ncm); in ncm_open()
1322 spin_unlock(&ncm->lock); in ncm_open()
1327 struct f_ncm *ncm = func_to_ncm(&geth->func); in ncm_close() local
1329 DBG(ncm->port.func.config->cdev, "%s\n", __func__); in ncm_close()
1331 spin_lock(&ncm->lock); in ncm_close()
1332 ncm->is_open = false; in ncm_close()
1333 ncm_notify(ncm); in ncm_close()
1334 spin_unlock(&ncm->lock); in ncm_close()
1344 struct f_ncm *ncm = func_to_ncm(f); in ncm_bind() local
1384 ncm->ctrl_id = status; in ncm_bind()
1393 ncm->data_id = status; in ncm_bind()
1405 ncm->port.in_ep = ep; in ncm_bind()
1411 ncm->port.out_ep = ep; in ncm_bind()
1417 ncm->notify = ep; in ncm_bind()
1423 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); in ncm_bind()
1424 if (!ncm->notify_req) in ncm_bind()
1426 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL); in ncm_bind()
1427 if (!ncm->notify_req->buf) in ncm_bind()
1429 ncm->notify_req->context = ncm; in ncm_bind()
1430 ncm->notify_req->complete = ncm_notify_complete; in ncm_bind()
1453 ncm->port.open = ncm_open; in ncm_bind()
1454 ncm->port.close = ncm_close; in ncm_bind()
1456 tasklet_init(&ncm->tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm); in ncm_bind()
1457 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ncm_bind()
1458 ncm->task_timer.function = ncm_tx_timeout; in ncm_bind()
1462 ncm->port.in_ep->name, ncm->port.out_ep->name, in ncm_bind()
1463 ncm->notify->name); in ncm_bind()
1467 if (ncm->notify_req) { in ncm_bind()
1468 kfree(ncm->notify_req->buf); in ncm_bind()
1469 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_bind()
1473 if (ncm->notify) in ncm_bind()
1474 ncm->notify->driver_data = NULL; in ncm_bind()
1475 if (ncm->port.out_ep) in ncm_bind()
1476 ncm->port.out_ep->driver_data = NULL; in ncm_bind()
1477 if (ncm->port.in_ep) in ncm_bind()
1478 ncm->port.in_ep->driver_data = NULL; in ncm_bind()
1492 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1495 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1498 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1501 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1504 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1555 struct f_ncm *ncm; in ncm_free() local
1558 ncm = func_to_ncm(f); in ncm_free()
1560 kfree(ncm); in ncm_free()
1568 struct f_ncm *ncm = func_to_ncm(f); in ncm_unbind() local
1572 hrtimer_cancel(&ncm->task_timer); in ncm_unbind()
1573 tasklet_kill(&ncm->tx_tasklet); in ncm_unbind()
1578 kfree(ncm->notify_req->buf); in ncm_unbind()
1579 usb_ep_free_request(ncm->notify, ncm->notify_req); in ncm_unbind()
1584 struct f_ncm *ncm; in ncm_alloc() local
1589 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); in ncm_alloc()
1590 if (!ncm) in ncm_alloc()
1598 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, in ncm_alloc()
1599 sizeof(ncm->ethaddr)); in ncm_alloc()
1601 kfree(ncm); in ncm_alloc()
1605 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; in ncm_alloc()
1607 spin_lock_init(&ncm->lock); in ncm_alloc()
1608 ncm_reset_values(ncm); in ncm_alloc()
1609 ncm->port.ioport = netdev_priv(opts->net); in ncm_alloc()
1611 ncm->port.is_fixed = true; in ncm_alloc()
1612 ncm->port.supports_multi_frame = true; in ncm_alloc()
1614 ncm->port.func.name = "cdc_network"; in ncm_alloc()
1616 ncm->port.func.bind = ncm_bind; in ncm_alloc()
1617 ncm->port.func.unbind = ncm_unbind; in ncm_alloc()
1618 ncm->port.func.set_alt = ncm_set_alt; in ncm_alloc()
1619 ncm->port.func.get_alt = ncm_get_alt; in ncm_alloc()
1620 ncm->port.func.setup = ncm_setup; in ncm_alloc()
1621 ncm->port.func.disable = ncm_disable; in ncm_alloc()
1622 ncm->port.func.free_func = ncm_free; in ncm_alloc()
1624 ncm->port.wrap = ncm_wrap_ntb; in ncm_alloc()
1625 ncm->port.unwrap = ncm_unwrap_ntb; in ncm_alloc()
1627 return &ncm->port.func; in ncm_alloc()
1630 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);