Lines Matching refs:ncm

529 static inline void ncm_reset_values(struct f_ncm *ncm)
531 ncm->parser_opts = &ndp16_opts;
532 ncm->is_crc = false;
533 ncm->ndp_sign = ncm->parser_opts->ndp_sign;
534 ncm->port.cdc_filter = DEFAULT_FILTER;
536 /* doesn't make sense for ncm, fixed size used */
537 ncm->port.header_len = 0;
539 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
540 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE;
544 * Context: ncm->lock held
546 static void ncm_do_notify(struct f_ncm *ncm)
548 struct usb_request *req = ncm->notify_req;
550 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
555 if (atomic_read(&ncm->notify_count))
559 switch (ncm->notify_state) {
565 if (ncm->is_open)
573 ncm->is_open ? "true" : "false");
574 ncm->notify_state = NCM_NOTIFY_NONE;
589 ncm->notify_state = NCM_NOTIFY_CONNECT;
593 event->wIndex = cpu_to_le16(ncm->ctrl_id);
595 atomic_inc(&ncm->notify_count);
602 spin_unlock(&ncm->lock);
603 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC);
604 spin_lock(&ncm->lock);
606 atomic_dec(&ncm->notify_count);
612 * Context: ncm->lock held
614 static void ncm_notify(struct f_ncm *ncm)
626 ncm->notify_state = NCM_NOTIFY_SPEED;
627 ncm_do_notify(ncm);
632 struct f_ncm *ncm = req->context;
633 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
636 spin_lock(&ncm->lock);
641 atomic_dec(&ncm->notify_count);
645 atomic_set(&ncm->notify_count, 0);
646 ncm->notify_state = NCM_NOTIFY_NONE;
651 atomic_dec(&ncm->notify_count);
654 ncm_do_notify(ncm);
655 spin_unlock(&ncm->lock);
663 struct f_ncm *ncm = func_to_ncm(f);
679 ncm->port.fixed_in_len = in_size;
690 struct f_ncm *ncm = func_to_ncm(f);
709 if (w_length != 0 || w_index != ncm->ctrl_id)
717 ncm->port.cdc_filter = w_value;
733 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id)
744 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id)
746 put_unaligned_le32(ncm->port.fixed_in_len, req->buf);
749 ncm->port.fixed_in_len);
755 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id)
770 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
772 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001;
782 if (w_length != 0 || w_index != ncm->ctrl_id)
786 ncm->parser_opts = &ndp16_opts;
790 ncm->parser_opts = &ndp32_opts;
804 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
806 is_crc = ncm->is_crc ? 0x0001 : 0x0000;
816 if (w_length != 0 || w_index != ncm->ctrl_id)
820 ncm->is_crc = false;
824 ncm->is_crc = true;
834 /* and disabled in ncm descriptor: */
846 ncm->ndp_sign = ncm->parser_opts->ndp_sign |
847 (ncm->is_crc ? NCM_NDP_HDR_CRC : 0);
851 DBG(cdev, "ncm req%02x.%02x v%04x i%04x l%d\n",
858 ERROR(cdev, "ncm req %02x.%02x response err %d\n",
870 struct f_ncm *ncm = func_to_ncm(f);
874 if (intf == ncm->ctrl_id) {
878 DBG(cdev, "reset ncm control %d\n", intf);
879 usb_ep_disable(ncm->notify);
881 if (!(ncm->notify->desc)) {
882 DBG(cdev, "init ncm ctrl %d\n", intf);
883 if (config_ep_by_speed(cdev->gadget, f, ncm->notify))
886 usb_ep_enable(ncm->notify);
889 } else if (intf == ncm->data_id) {
893 if (ncm->port.in_ep->enabled) {
894 DBG(cdev, "reset ncm\n");
895 ncm->timer_stopping = true;
896 ncm->netdev = NULL;
897 gether_disconnect(&ncm->port);
898 ncm_reset_values(ncm);
908 if (!ncm->port.in_ep->desc ||
909 !ncm->port.out_ep->desc) {
910 DBG(cdev, "init ncm\n");
912 ncm->port.in_ep) ||
914 ncm->port.out_ep)) {
915 ncm->port.in_ep->desc = NULL;
916 ncm->port.out_ep->desc = NULL;
925 ncm->port.is_zlp_ok =
927 ncm->port.cdc_filter = DEFAULT_FILTER;
928 DBG(cdev, "activate ncm\n");
929 net = gether_connect(&ncm->port);
932 ncm->netdev = net;
933 ncm->timer_stopping = false;
936 spin_lock(&ncm->lock);
937 ncm_notify(ncm);
938 spin_unlock(&ncm->lock);
953 struct f_ncm *ncm = func_to_ncm(f);
955 if (intf == ncm->ctrl_id)
957 return ncm->port.in_ep->enabled ? 1 : 0;
960 static struct sk_buff *package_for_tx(struct f_ncm *ncm)
968 const struct ndp_parser_opts *opts = ncm->parser_opts;
973 hrtimer_try_to_cancel(&ncm->task_timer);
975 ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) -
976 ncm->skb_tx_data->len;
977 ndp_index = ncm->skb_tx_data->len + ndp_pad;
978 new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len;
981 ntb_iter = (void *) ncm->skb_tx_data->data;
989 (ncm->ndp_dgram_count * dgram_idx_len);
990 ncm->ndp_dgram_count = 0;
992 ntb_iter = (void *) ncm->skb_tx_ndp->data;
997 swap(skb2, ncm->skb_tx_data);
998 if (ncm->skb_tx_data) {
999 dev_consume_skb_any(ncm->skb_tx_data);
1000 ncm->skb_tx_data = NULL;
1007 skb_put_data(skb2, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len);
1008 dev_consume_skb_any(ncm->skb_tx_ndp);
1009 ncm->skb_tx_ndp = NULL;
1020 struct f_ncm *ncm = func_to_ncm(&port->func);
1027 unsigned max_size = ncm->port.fixed_in_len;
1028 const struct ndp_parser_opts *opts = ncm->parser_opts;
1034 if (!skb && !ncm->skb_tx_data)
1039 if (ncm->is_crc) {
1055 if (ncm->skb_tx_data
1056 && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE
1057 || (ncm->skb_tx_data->len +
1059 ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len))
1061 skb2 = package_for_tx(ncm);
1066 if (!ncm->skb_tx_data) {
1072 ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC);
1073 if (!ncm->skb_tx_data)
1076 ncm->skb_tx_data->dev = ncm->netdev;
1077 ntb_data = skb_put_zero(ncm->skb_tx_data, ncb_len);
1088 ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size
1092 if (!ncm->skb_tx_ndp)
1095 ncm->skb_tx_ndp->dev = ncm->netdev;
1096 ntb_ndp = skb_put(ncm->skb_tx_ndp, opts->ndp_size);
1099 put_unaligned_le32(ncm->ndp_sign, ntb_ndp);
1103 ncm->ndp_dgram_count = 1;
1108 hrtimer_start(&ncm->task_timer, TX_TIMEOUT_NSECS,
1113 ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
1115 ncb_len = ncm->skb_tx_data->len;
1123 ncm->ndp_dgram_count++;
1126 skb_put_zero(ncm->skb_tx_data, dgram_pad);
1127 skb_put_data(ncm->skb_tx_data, skb->data, skb->len);
1131 } else if (ncm->skb_tx_data && ncm->timer_force_tx) {
1133 skb2 = package_for_tx(ncm);
1141 ncm->netdev->stats.tx_dropped++;
1145 if (ncm->skb_tx_data)
1146 dev_kfree_skb_any(ncm->skb_tx_data);
1147 if (ncm->skb_tx_ndp)
1148 dev_kfree_skb_any(ncm->skb_tx_ndp);
1159 struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
1162 if (!ncm->timer_stopping && ncm->skb_tx_data) {
1163 ncm->timer_force_tx = true;
1171 ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev);
1173 ncm->timer_force_tx = false;
1182 struct f_ncm *ncm = func_to_ncm(&port->func);
1194 const struct ndp_parser_opts *opts = ncm->parser_opts;
1195 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
1248 if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
1301 if (ncm->is_crc) {
1331 skb2 = netdev_alloc_skb_ip_align(ncm->netdev,
1368 struct f_ncm *ncm = func_to_ncm(f);
1371 DBG(cdev, "ncm deactivated\n");
1373 if (ncm->port.in_ep->enabled) {
1374 ncm->timer_stopping = true;
1375 ncm->netdev = NULL;
1376 gether_disconnect(&ncm->port);
1379 if (ncm->notify->enabled) {
1380 usb_ep_disable(ncm->notify);
1381 ncm->notify->desc = NULL;
1407 struct f_ncm *ncm = func_to_ncm(&geth->func);
1409 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1411 spin_lock(&ncm->lock);
1412 ncm->is_open = true;
1413 ncm_notify(ncm);
1414 spin_unlock(&ncm->lock);
1419 struct f_ncm *ncm = func_to_ncm(&geth->func);
1421 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1423 spin_lock(&ncm->lock);
1424 ncm->is_open = false;
1425 ncm_notify(ncm);
1426 spin_unlock(&ncm->lock);
1436 struct f_ncm *ncm = func_to_ncm(f);
1483 ncm->ctrl_id = status;
1496 ncm->data_id = status;
1508 ncm->port.in_ep = ep;
1513 ncm->port.out_ep = ep;
1518 ncm->notify = ep;
1523 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
1524 if (!ncm->notify_req)
1526 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL);
1527 if (!ncm->notify_req->buf)
1529 ncm->notify_req->context = ncm;
1530 ncm->notify_req->complete = ncm_notify_complete;
1558 ncm->port.open = ncm_open;
1559 ncm->port.close = ncm_close;
1561 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
1562 ncm->task_timer.function = ncm_tx_timeout;
1567 ncm->port.in_ep->name, ncm->port.out_ep->name,
1568 ncm->notify->name);
1575 if (ncm->notify_req) {
1576 kfree(ncm->notify_req->buf);
1577 usb_ep_free_request(ncm->notify, ncm->notify_req);
1592 USB_ETHERNET_CONFIGFS_ITEM(ncm);
1595 USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm);
1598 USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm);
1601 USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1604 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1656 names[0] = "ncm";
1673 struct f_ncm *ncm;
1676 ncm = func_to_ncm(f);
1678 kfree(ncm);
1686 struct f_ncm *ncm = func_to_ncm(f);
1688 DBG(c->cdev, "ncm unbind\n");
1690 hrtimer_cancel(&ncm->task_timer);
1698 if (atomic_read(&ncm->notify_count)) {
1699 usb_ep_dequeue(ncm->notify, ncm->notify_req);
1700 atomic_set(&ncm->notify_count, 0);
1703 kfree(ncm->notify_req->buf);
1704 usb_ep_free_request(ncm->notify, ncm->notify_req);
1709 struct f_ncm *ncm;
1714 ncm = kzalloc(sizeof(*ncm), GFP_KERNEL);
1715 if (!ncm)
1723 status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr,
1724 sizeof(ncm->ethaddr));
1726 kfree(ncm);
1730 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr;
1732 spin_lock_init(&ncm->lock);
1733 ncm_reset_values(ncm);
1734 ncm->port.ioport = netdev_priv(opts->net);
1736 ncm->port.is_fixed = true;
1737 ncm->port.supports_multi_frame = true;
1739 ncm->port.func.name = "cdc_network";
1741 ncm->port.func.bind = ncm_bind;
1742 ncm->port.func.unbind = ncm_unbind;
1743 ncm->port.func.set_alt = ncm_set_alt;
1744 ncm->port.func.get_alt = ncm_get_alt;
1745 ncm->port.func.setup = ncm_setup;
1746 ncm->port.func.disable = ncm_disable;
1747 ncm->port.func.free_func = ncm_free;
1749 ncm->port.wrap = ncm_wrap_ntb;
1750 ncm->port.unwrap = ncm_unwrap_ntb;
1752 return &ncm->port.func;
1755 DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc);