Lines Matching refs:ncm
508 static inline void ncm_reset_values(struct f_ncm *ncm)
510 ncm->parser_opts = &ndp16_opts;
511 ncm->is_crc = false;
512 ncm->ndp_sign = ncm->parser_opts->ndp_sign;
513 ncm->port.cdc_filter = DEFAULT_FILTER;
515 /* doesn't make sense for ncm, fixed size used */
516 ncm->port.header_len = 0;
518 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
519 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE;
523 * Context: ncm->lock held
525 static void ncm_do_notify(struct f_ncm *ncm)
527 struct usb_request *req = ncm->notify_req;
529 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
534 if (atomic_read(&ncm->notify_count))
538 switch (ncm->notify_state) {
544 if (ncm->is_open)
552 ncm->is_open ? "true" : "false");
553 ncm->notify_state = NCM_NOTIFY_NONE;
568 ncm->notify_state = NCM_NOTIFY_CONNECT;
572 event->wIndex = cpu_to_le16(ncm->ctrl_id);
574 atomic_inc(&ncm->notify_count);
581 spin_unlock(&ncm->lock);
582 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC);
583 spin_lock(&ncm->lock);
585 atomic_dec(&ncm->notify_count);
591 * Context: ncm->lock held
593 static void ncm_notify(struct f_ncm *ncm)
605 ncm->notify_state = NCM_NOTIFY_SPEED;
606 ncm_do_notify(ncm);
611 struct f_ncm *ncm = req->context;
612 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
615 spin_lock(&ncm->lock);
620 atomic_dec(&ncm->notify_count);
624 atomic_set(&ncm->notify_count, 0);
625 ncm->notify_state = NCM_NOTIFY_NONE;
630 atomic_dec(&ncm->notify_count);
633 ncm_do_notify(ncm);
634 spin_unlock(&ncm->lock);
642 struct f_ncm *ncm = func_to_ncm(f);
658 ncm->port.fixed_in_len = in_size;
669 struct f_ncm *ncm = func_to_ncm(f);
688 if (w_length != 0 || w_index != ncm->ctrl_id)
696 ncm->port.cdc_filter = w_value;
712 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id)
723 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id)
725 put_unaligned_le32(ncm->port.fixed_in_len, req->buf);
728 ncm->port.fixed_in_len);
734 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id)
749 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
751 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001;
761 if (w_length != 0 || w_index != ncm->ctrl_id)
765 ncm->parser_opts = &ndp16_opts;
769 ncm->parser_opts = &ndp32_opts;
783 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
785 is_crc = ncm->is_crc ? 0x0001 : 0x0000;
795 if (w_length != 0 || w_index != ncm->ctrl_id)
799 ncm->is_crc = false;
803 ncm->is_crc = true;
813 /* and disabled in ncm descriptor: */
825 ncm->ndp_sign = ncm->parser_opts->ndp_sign |
826 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0);
830 DBG(cdev, "ncm req%02x.%02x v%04x i%04x l%d\n",
837 ERROR(cdev, "ncm req %02x.%02x response err %d\n",
849 struct f_ncm *ncm = func_to_ncm(f);
853 if (intf == ncm->ctrl_id) {
857 DBG(cdev, "reset ncm control %d\n", intf);
858 usb_ep_disable(ncm->notify);
860 if (!(ncm->notify->desc)) {
861 DBG(cdev, "init ncm ctrl %d\n", intf);
862 if (config_ep_by_speed(cdev->gadget, f, ncm->notify))
865 usb_ep_enable(ncm->notify);
868 } else if (intf == ncm->data_id) {
872 if (ncm->port.in_ep->enabled) {
873 DBG(cdev, "reset ncm\n");
874 ncm->netdev = NULL;
875 gether_disconnect(&ncm->port);
876 ncm_reset_values(ncm);
886 if (!ncm->port.in_ep->desc ||
887 !ncm->port.out_ep->desc) {
888 DBG(cdev, "init ncm\n");
890 ncm->port.in_ep) ||
892 ncm->port.out_ep)) {
893 ncm->port.in_ep->desc = NULL;
894 ncm->port.out_ep->desc = NULL;
903 ncm->port.is_zlp_ok =
905 ncm->port.cdc_filter = DEFAULT_FILTER;
906 DBG(cdev, "activate ncm\n");
907 net = gether_connect(&ncm->port);
910 ncm->netdev = net;
913 spin_lock(&ncm->lock);
914 ncm_notify(ncm);
915 spin_unlock(&ncm->lock);
930 struct f_ncm *ncm = func_to_ncm(f);
932 if (intf == ncm->ctrl_id)
934 return ncm->port.in_ep->enabled ? 1 : 0;
937 static struct sk_buff *package_for_tx(struct f_ncm *ncm)
945 const struct ndp_parser_opts *opts = ncm->parser_opts;
950 hrtimer_try_to_cancel(&ncm->task_timer);
952 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) -
953 ncm->skb_tx_data->len;
954 ndp_index = ncm->skb_tx_data->len + ndp_pad;
955 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len;
958 ntb_iter = (void *) ncm->skb_tx_data->data;
966 (ncm->ndp_dgram_count * dgram_idx_len);
967 ncm->ndp_dgram_count = 0;
969 ntb_iter = (void *) ncm->skb_tx_ndp->data;
974 swap(skb2, ncm->skb_tx_data);
975 if (ncm->skb_tx_data) {
976 dev_consume_skb_any(ncm->skb_tx_data);
977 ncm->skb_tx_data = NULL;
984 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len);
985 dev_consume_skb_any(ncm->skb_tx_ndp);
986 ncm->skb_tx_ndp = NULL;
997 struct f_ncm *ncm = func_to_ncm(&port->func);
1006 unsigned max_size = ncm->port.fixed_in_len;
1007 const struct ndp_parser_opts *opts = ncm->parser_opts;
1014 if (ncm->is_crc) {
1030 if (ncm->skb_tx_data
1031 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE
1032 || (ncm->skb_tx_data->len +
1034 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len))
1036 skb2 = package_for_tx(ncm);
1041 if (!ncm->skb_tx_data) {
1047 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC);
1048 if (!ncm->skb_tx_data)
1051 ncm->skb_tx_data->dev = ncm->netdev;
1052 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len);
1063 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size
1067 if (!ncm->skb_tx_ndp)
1070 ncm->skb_tx_ndp->dev = ncm->netdev;
1071 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size);
1074 put_unaligned_le32(ncm->ndp_sign, ntb_ndp);
1078 ncm->ndp_dgram_count = 1;
1083 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
1088 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
1090 ncb_len = ncm->skb_tx_data->len;
1098 ncm->ndp_dgram_count++;
1101 skb_put_zero(ncm->skb_tx_data, dgram_pad);
1102 skb_put_data(ncm->skb_tx_data, skb->data, skb->len);
1106 } else if (ncm->skb_tx_data) {
1111 skb2 = package_for_tx(ncm);
1119 ncm->netdev->stats.tx_dropped++;
1123 if (ncm->skb_tx_data)
1124 dev_kfree_skb_any(ncm->skb_tx_data);
1125 if (ncm->skb_tx_ndp)
1126 dev_kfree_skb_any(ncm->skb_tx_ndp);
1137 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
1138 struct net_device *netdev = READ_ONCE(ncm->netdev);
1158 struct f_ncm *ncm = func_to_ncm(&port->func);
1170 const struct ndp_parser_opts *opts = ncm->parser_opts;
1171 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
1224 if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
1277 if (ncm->is_crc) {
1307 skb2 = netdev_alloc_skb_ip_align(ncm->netdev,
1352 struct f_ncm *ncm = func_to_ncm(f);
1355 DBG(cdev, "ncm deactivated\n");
1357 if (ncm->port.in_ep->enabled) {
1358 ncm->netdev = NULL;
1359 gether_disconnect(&ncm->port);
1362 if (ncm->notify->enabled) {
1363 usb_ep_disable(ncm->notify);
1364 ncm->notify->desc = NULL;
1390 struct f_ncm *ncm = func_to_ncm(&geth->func);
1392 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1394 spin_lock(&ncm->lock);
1395 ncm->is_open = true;
1396 ncm_notify(ncm);
1397 spin_unlock(&ncm->lock);
1402 struct f_ncm *ncm = func_to_ncm(&geth->func);
1404 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1406 spin_lock(&ncm->lock);
1407 ncm->is_open = false;
1408 ncm_notify(ncm);
1409 spin_unlock(&ncm->lock);
1419 struct f_ncm *ncm = func_to_ncm(f);
1466 ncm->ctrl_id = status;
1479 ncm->data_id = status;
1491 ncm->port.in_ep = ep;
1496 ncm->port.out_ep = ep;
1501 ncm->notify = ep;
1506 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
1507 if (!ncm->notify_req)
1509 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL);
1510 if (!ncm->notify_req->buf)
1512 ncm->notify_req->context = ncm;
1513 ncm->notify_req->complete = ncm_notify_complete;
1541 ncm->port.open = ncm_open;
1542 ncm->port.close = ncm_close;
1544 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
1545 ncm->task_timer.function = ncm_tx_timeout;
1548 ncm->port.in_ep->name, ncm->port.out_ep->name,
1549 ncm->notify->name);
1556 if (ncm->notify_req) {
1557 kfree(ncm->notify_req->buf);
1558 usb_ep_free_request(ncm->notify, ncm->notify_req);
1573 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1576 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1579 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1582 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1585 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1637 names[0] = "ncm";
1654 struct f_ncm *ncm;
1657 ncm = func_to_ncm(f);
1659 kfree(ncm);
1667 struct f_ncm *ncm = func_to_ncm(f);
1669 DBG(c->cdev, "ncm unbind\n");
1671 hrtimer_cancel(&ncm->task_timer);
1679 if (atomic_read(&ncm->notify_count)) {
1680 usb_ep_dequeue(ncm->notify, ncm->notify_req);
1681 atomic_set(&ncm->notify_count, 0);
1684 kfree(ncm->notify_req->buf);
1685 usb_ep_free_request(ncm->notify, ncm->notify_req);
1690 struct f_ncm *ncm;
1695 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL);
1696 if (!ncm)
1704 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr,
1705 sizeof(ncm->ethaddr));
1707 kfree(ncm);
1711 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr;
1713 spin_lock_init(&ncm->lock);
1714 ncm_reset_values(ncm);
1715 ncm->port.ioport = netdev_priv(opts->net);
1717 ncm->port.is_fixed = true;
1718 ncm->port.supports_multi_frame = true;
1720 ncm->port.func.name = "cdc_network";
1722 ncm->port.func.bind = ncm_bind;
1723 ncm->port.func.unbind = ncm_unbind;
1724 ncm->port.func.set_alt = ncm_set_alt;
1725 ncm->port.func.get_alt = ncm_get_alt;
1726 ncm->port.func.setup = ncm_setup;
1727 ncm->port.func.disable = ncm_disable;
1728 ncm->port.func.free_func = ncm_free;
1730 ncm->port.wrap = ncm_wrap_ntb;
1731 ncm->port.unwrap = ncm_unwrap_ntb;
1733 return &ncm->port.func;
1736 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);