Lines Matching +full:u +full:- +full:blox
4 * Copyright (C) ST-Ericsson 2010-2012
16 * of the GNU General Public License (GPL) Version 2 or the 2-clause
78 .sizeof_stat = sizeof(((struct cdc_ncm_ctx *)0)->m), \
101 return -EOPNOTSUPP; in cdc_ncm_get_sset_count()
110 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_get_ethtool_stats()
152 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_check_rx_max()
157 max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_RX, le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)); in cdc_ncm_check_rx_max()
161 dev_warn(&dev->intf->dev, "dwNtbInMaxSize=%u is too small. Using %u\n", in cdc_ncm_check_rx_max()
162 le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize), min); in cdc_ncm_check_rx_max()
168 dev_dbg(&dev->intf->dev, "rx_max must be in the [%u, %u] range\n", min, max); in cdc_ncm_check_rx_max()
175 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_check_tx_max()
179 if (ctx->is_ndp16) in cdc_ncm_check_tx_max()
180 min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth16); in cdc_ncm_check_tx_max()
182 min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth32); in cdc_ncm_check_tx_max()
184 if (le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) == 0) in cdc_ncm_check_tx_max()
187 max = clamp_t(u32, le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize), in cdc_ncm_check_tx_max()
196 dev_dbg(&dev->intf->dev, "tx_max must be in the [%u, %u] range\n", min, max); in cdc_ncm_check_tx_max()
205 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in min_tx_pkt_show()
207 return sprintf(buf, "%u\n", ctx->min_tx_pkt); in min_tx_pkt_show()
214 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in rx_max_show()
216 return sprintf(buf, "%u\n", ctx->rx_max); in rx_max_show()
223 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in tx_max_show()
225 return sprintf(buf, "%u\n", ctx->tx_max); in tx_max_show()
232 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in tx_timer_usecs_show()
234 return sprintf(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC); in tx_timer_usecs_show()
242 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in min_tx_pkt_store()
245 /* no need to restrict values - anything from 0 to infinity is OK */ in min_tx_pkt_store()
247 return -EINVAL; in min_tx_pkt_store()
249 ctx->min_tx_pkt = val; in min_tx_pkt_store()
258 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in rx_max_store()
262 return -EINVAL; in rx_max_store()
264 cdc_ncm_update_rxtx_max(dev, val, ctx->tx_max); in rx_max_store()
273 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in tx_max_store()
277 return -EINVAL; in tx_max_store()
279 cdc_ncm_update_rxtx_max(dev, ctx->rx_max, val); in tx_max_store()
288 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in tx_timer_usecs_store()
296 return -EINVAL; in tx_timer_usecs_store()
298 spin_lock_bh(&ctx->mtx); in tx_timer_usecs_store()
299 ctx->timer_interval = val * NSEC_PER_USEC; in tx_timer_usecs_store()
300 if (!ctx->timer_interval) in tx_timer_usecs_store()
301 ctx->tx_timer_pending = 0; in tx_timer_usecs_store()
302 spin_unlock_bh(&ctx->mtx); in tx_timer_usecs_store()
314 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in ndp_to_end_show()
316 return sprintf(buf, "%c\n", ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END ? 'Y' : 'N'); in ndp_to_end_show()
322 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in ndp_to_end_store()
326 return -EINVAL; in ndp_to_end_store()
329 if (enable == (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in ndp_to_end_store()
333 if (ctx->is_ndp16 && !ctx->delayed_ndp16) { in ndp_to_end_store()
334 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in ndp_to_end_store()
335 if (!ctx->delayed_ndp16) in ndp_to_end_store()
336 return -ENOMEM; in ndp_to_end_store()
338 if (!ctx->is_ndp16 && !ctx->delayed_ndp32) { in ndp_to_end_store()
339 ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in ndp_to_end_store()
340 if (!ctx->delayed_ndp32) in ndp_to_end_store()
341 return -ENOMEM; in ndp_to_end_store()
346 netif_tx_lock_bh(dev->net); in ndp_to_end_store()
347 usbnet_start_xmit(NULL, dev->net); in ndp_to_end_store()
348 spin_lock_bh(&ctx->mtx); in ndp_to_end_store()
350 ctx->drvflags |= CDC_NCM_FLAG_NDP_TO_END; in ndp_to_end_store()
352 ctx->drvflags &= ~CDC_NCM_FLAG_NDP_TO_END; in ndp_to_end_store()
353 spin_unlock_bh(&ctx->mtx); in ndp_to_end_store()
354 netif_tx_unlock_bh(dev->net); in ndp_to_end_store()
364 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; \
365 return sprintf(buf, format "\n", tocpu(ctx->ncm_parm.name)); \
370 NCM_PARM_ATTR(dwNtbInMaxSize, "%u", le32_to_cpu);
371 NCM_PARM_ATTR(wNdpInDivisor, "%u", le16_to_cpu);
372 NCM_PARM_ATTR(wNdpInPayloadRemainder, "%u", le16_to_cpu);
373 NCM_PARM_ATTR(wNdpInAlignment, "%u", le16_to_cpu);
374 NCM_PARM_ATTR(dwNtbOutMaxSize, "%u", le32_to_cpu);
375 NCM_PARM_ATTR(wNdpOutDivisor, "%u", le16_to_cpu);
376 NCM_PARM_ATTR(wNdpOutPayloadRemainder, "%u", le16_to_cpu);
377 NCM_PARM_ATTR(wNdpOutAlignment, "%u", le16_to_cpu);
378 NCM_PARM_ATTR(wNtbOutMaxDatagrams, "%u", le16_to_cpu);
407 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_update_rxtx_max()
408 u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; in cdc_ncm_update_rxtx_max()
414 if (val != ctx->rx_max) { in cdc_ncm_update_rxtx_max()
417 dev_info(&dev->intf->dev, "setting rx_max = %u\n", val); in cdc_ncm_update_rxtx_max()
424 dev_dbg(&dev->intf->dev, "Setting NTB Input Size failed\n"); in cdc_ncm_update_rxtx_max()
426 ctx->rx_max = val; in cdc_ncm_update_rxtx_max()
430 if (dev->rx_urb_size != ctx->rx_max) { in cdc_ncm_update_rxtx_max()
431 dev->rx_urb_size = ctx->rx_max; in cdc_ncm_update_rxtx_max()
432 if (netif_running(dev->net)) in cdc_ncm_update_rxtx_max()
437 if (val != ctx->tx_max) in cdc_ncm_update_rxtx_max()
438 dev_info(&dev->intf->dev, "setting tx_max = %u\n", val); in cdc_ncm_update_rxtx_max()
444 * We cannot use dev->maxpacket here because this is called from in cdc_ncm_update_rxtx_max()
445 * .bind which is called before usbnet sets up dev->maxpacket in cdc_ncm_update_rxtx_max()
447 if (val != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) && in cdc_ncm_update_rxtx_max()
448 val % usb_maxpacket(dev->udev, dev->out) == 0) in cdc_ncm_update_rxtx_max()
452 if (netif_running(dev->net) && val > ctx->tx_max) { in cdc_ncm_update_rxtx_max()
453 netif_tx_lock_bh(dev->net); in cdc_ncm_update_rxtx_max()
454 usbnet_start_xmit(NULL, dev->net); in cdc_ncm_update_rxtx_max()
456 if (ctx->tx_curr_skb) { in cdc_ncm_update_rxtx_max()
457 dev_kfree_skb_any(ctx->tx_curr_skb); in cdc_ncm_update_rxtx_max()
458 ctx->tx_curr_skb = NULL; in cdc_ncm_update_rxtx_max()
460 ctx->tx_max = val; in cdc_ncm_update_rxtx_max()
461 netif_tx_unlock_bh(dev->net); in cdc_ncm_update_rxtx_max()
463 ctx->tx_max = val; in cdc_ncm_update_rxtx_max()
466 dev->hard_mtu = ctx->tx_max; in cdc_ncm_update_rxtx_max()
472 ctx->min_tx_pkt = clamp_t(u16, ctx->tx_max - 3 * usb_maxpacket(dev->udev, dev->out), in cdc_ncm_update_rxtx_max()
473 CDC_NCM_MIN_TX_PKT, ctx->tx_max); in cdc_ncm_update_rxtx_max()
479 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_flags()
481 if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc) in cdc_ncm_flags()
482 return ctx->mbim_desc->bmNetworkCapabilities; in cdc_ncm_flags()
483 if (ctx->func_desc) in cdc_ncm_flags()
484 return ctx->func_desc->bmNetworkCapabilities; in cdc_ncm_flags()
490 if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting)) in cdc_ncm_eth_hlen()
497 if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting)) in cdc_ncm_min_dgram_size()
504 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_max_dgram_size()
506 if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc) in cdc_ncm_max_dgram_size()
507 return le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize); in cdc_ncm_max_dgram_size()
508 if (ctx->ether_desc) in cdc_ncm_max_dgram_size()
509 return le16_to_cpu(ctx->ether_desc->wMaxSegmentSize); in cdc_ncm_max_dgram_size()
513 /* initial one-time device setup. MUST be called with the data interface
518 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_init()
519 u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; in cdc_ncm_init()
525 0, iface_no, &ctx->ncm_parm, in cdc_ncm_init()
526 sizeof(ctx->ncm_parm)); in cdc_ncm_init()
528 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); in cdc_ncm_init()
534 dev_dbg(&dev->intf->dev, "Setting CRC mode off\n"); in cdc_ncm_init()
541 dev_err(&dev->intf->dev, "SET_CRC_MODE failed\n"); in cdc_ncm_init()
545 ctx->is_ndp16 = 1; in cdc_ncm_init()
552 if (le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported) & in cdc_ncm_init()
554 if (ctx->drvflags & CDC_NCM_FLAG_PREFER_NTB32) { in cdc_ncm_init()
555 ctx->is_ndp16 = 0; in cdc_ncm_init()
556 dev_dbg(&dev->intf->dev, "Setting NTB format to 32-bit\n"); in cdc_ncm_init()
563 ctx->is_ndp16 = 1; in cdc_ncm_init()
564 dev_dbg(&dev->intf->dev, "Setting NTB format to 16-bit\n"); in cdc_ncm_init()
572 ctx->is_ndp16 = 1; in cdc_ncm_init()
573 dev_err(&dev->intf->dev, "SET_NTB_FORMAT failed\n"); in cdc_ncm_init()
578 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize); in cdc_ncm_init()
579 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize); in cdc_ncm_init()
580 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder); in cdc_ncm_init()
581 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor); in cdc_ncm_init()
582 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment); in cdc_ncm_init()
584 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams); in cdc_ncm_init()
586 dev_dbg(&dev->intf->dev, in cdc_ncm_init()
587 …"dwNtbInMaxSize=%u dwNtbOutMaxSize=%u wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u wNdpOutAlignmen… in cdc_ncm_init()
588 ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus, in cdc_ncm_init()
589 ctx->tx_ndp_modulus, ctx->tx_max_datagrams, cdc_ncm_flags(dev)); in cdc_ncm_init()
592 if ((ctx->tx_max_datagrams == 0) || in cdc_ncm_init()
593 (ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX)) in cdc_ncm_init()
594 ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX; in cdc_ncm_init()
597 if (ctx->is_ndp16) in cdc_ncm_init()
598 …ctx->max_ndp_size = sizeof(struct usb_cdc_ncm_ndp16) + (ctx->tx_max_datagrams + 1) * sizeof(struct… in cdc_ncm_init()
600 …ctx->max_ndp_size = sizeof(struct usb_cdc_ncm_ndp32) + (ctx->tx_max_datagrams + 1) * sizeof(struct… in cdc_ncm_init()
603 ctx->timer_interval = CDC_NCM_TIMER_INTERVAL_USEC * NSEC_PER_USEC; in cdc_ncm_init()
611 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_set_dgram_size()
612 u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; in cdc_ncm_set_dgram_size()
618 ctx->max_datagram_size = clamp_t(u32, new_size, in cdc_ncm_set_dgram_size()
631 dev_dbg(&dev->intf->dev, "GET_MAX_DATAGRAM_SIZE failed\n"); in cdc_ncm_set_dgram_size()
635 if (le16_to_cpu(max_datagram_size) == ctx->max_datagram_size) in cdc_ncm_set_dgram_size()
638 max_datagram_size = cpu_to_le16(ctx->max_datagram_size); in cdc_ncm_set_dgram_size()
643 dev_dbg(&dev->intf->dev, "SET_MAX_DATAGRAM_SIZE failed\n"); in cdc_ncm_set_dgram_size()
647 dev->net->mtu = min_t(int, dev->net->mtu, ctx->max_datagram_size - cdc_ncm_eth_hlen(dev)); in cdc_ncm_set_dgram_size()
650 if (ctx->mbim_extended_desc) { in cdc_ncm_set_dgram_size()
651 mbim_mtu = le16_to_cpu(ctx->mbim_extended_desc->wMTU); in cdc_ncm_set_dgram_size()
652 if (mbim_mtu != 0 && mbim_mtu < dev->net->mtu) in cdc_ncm_set_dgram_size()
653 dev->net->mtu = mbim_mtu; in cdc_ncm_set_dgram_size()
659 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_fix_modulus()
664 * - power of two in cdc_ncm_fix_modulus()
665 * - not greater than the maximum transmit length in cdc_ncm_fix_modulus()
666 * - not less than four bytes in cdc_ncm_fix_modulus()
668 val = ctx->tx_ndp_modulus; in cdc_ncm_fix_modulus()
671 (val != ((-val) & val)) || (val >= ctx->tx_max)) { in cdc_ncm_fix_modulus()
672 dev_dbg(&dev->intf->dev, "Using default alignment: 4 bytes\n"); in cdc_ncm_fix_modulus()
673 ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE; in cdc_ncm_fix_modulus()
678 * - power of two in cdc_ncm_fix_modulus()
679 * - not greater than the maximum transmit length in cdc_ncm_fix_modulus()
680 * - not less than four bytes in cdc_ncm_fix_modulus()
682 val = ctx->tx_modulus; in cdc_ncm_fix_modulus()
685 (val != ((-val) & val)) || (val >= ctx->tx_max)) { in cdc_ncm_fix_modulus()
686 dev_dbg(&dev->intf->dev, "Using default transmit modulus: 4 bytes\n"); in cdc_ncm_fix_modulus()
687 ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE; in cdc_ncm_fix_modulus()
691 if (ctx->tx_remainder >= ctx->tx_modulus) { in cdc_ncm_fix_modulus()
692 dev_dbg(&dev->intf->dev, "Using default transmit remainder: 0 bytes\n"); in cdc_ncm_fix_modulus()
693 ctx->tx_remainder = 0; in cdc_ncm_fix_modulus()
696 /* adjust TX-remainder according to NCM specification. */ in cdc_ncm_fix_modulus()
697 ctx->tx_remainder = ((ctx->tx_remainder - cdc_ncm_eth_hlen(dev)) & in cdc_ncm_fix_modulus()
698 (ctx->tx_modulus - 1)); in cdc_ncm_fix_modulus()
703 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_setup()
710 le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)); in cdc_ncm_setup()
712 le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)); in cdc_ncm_setup()
731 for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) { in cdc_ncm_find_endpoints()
732 e = intf->cur_altsetting->endpoint + ep; in cdc_ncm_find_endpoints()
735 if (!usb_endpoint_maxp(&e->desc)) in cdc_ncm_find_endpoints()
738 switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { in cdc_ncm_find_endpoints()
740 if (usb_endpoint_dir_in(&e->desc)) { in cdc_ncm_find_endpoints()
741 if (!dev->status) in cdc_ncm_find_endpoints()
742 dev->status = e; in cdc_ncm_find_endpoints()
747 if (usb_endpoint_dir_in(&e->desc)) { in cdc_ncm_find_endpoints()
760 if (in && !dev->in) in cdc_ncm_find_endpoints()
761 dev->in = usb_rcvbulkpipe(dev->udev, in cdc_ncm_find_endpoints()
762 in->desc.bEndpointAddress & in cdc_ncm_find_endpoints()
764 if (out && !dev->out) in cdc_ncm_find_endpoints()
765 dev->out = usb_sndbulkpipe(dev->udev, in cdc_ncm_find_endpoints()
766 out->desc.bEndpointAddress & in cdc_ncm_find_endpoints()
775 if (ctx->tx_rem_skb != NULL) { in cdc_ncm_free()
776 dev_kfree_skb_any(ctx->tx_rem_skb); in cdc_ncm_free()
777 ctx->tx_rem_skb = NULL; in cdc_ncm_free()
780 if (ctx->tx_curr_skb != NULL) { in cdc_ncm_free()
781 dev_kfree_skb_any(ctx->tx_curr_skb); in cdc_ncm_free()
782 ctx->tx_curr_skb = NULL; in cdc_ncm_free()
785 if (ctx->is_ndp16) in cdc_ncm_free()
786 kfree(ctx->delayed_ndp16); in cdc_ncm_free()
788 kfree(ctx->delayed_ndp32); in cdc_ncm_free()
794 * - respect the negotiated maximum datagram size
795 * - avoid unwanted changes to rx and tx buffers
801 WRITE_ONCE(net->mtu, new_mtu); in cdc_ncm_change_mtu()
832 return -ENOMEM; in cdc_ncm_bind_common()
834 ctx->dev = dev; in cdc_ncm_bind_common()
836 hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in cdc_ncm_bind_common()
837 ctx->tx_timer.function = &cdc_ncm_tx_timer_cb; in cdc_ncm_bind_common()
838 tasklet_setup(&ctx->bh, cdc_ncm_txpath_bh); in cdc_ncm_bind_common()
839 atomic_set(&ctx->stop, 0); in cdc_ncm_bind_common()
840 spin_lock_init(&ctx->mtx); in cdc_ncm_bind_common()
843 dev->data[0] = (unsigned long)ctx; in cdc_ncm_bind_common()
846 ctx->control = intf; in cdc_ncm_bind_common()
850 buf = intf->cur_altsetting->extra; in cdc_ncm_bind_common()
851 len = intf->cur_altsetting->extralen; in cdc_ncm_bind_common()
857 ctx->data = usb_ifnum_to_if(dev->udev, in cdc_ncm_bind_common()
858 hdr.usb_cdc_union_desc->bSlaveInterface0); in cdc_ncm_bind_common()
859 ctx->ether_desc = hdr.usb_cdc_ether_desc; in cdc_ncm_bind_common()
860 ctx->func_desc = hdr.usb_cdc_ncm_desc; in cdc_ncm_bind_common()
861 ctx->mbim_desc = hdr.usb_cdc_mbim_desc; in cdc_ncm_bind_common()
862 ctx->mbim_extended_desc = hdr.usb_cdc_mbim_extended_desc; in cdc_ncm_bind_common()
865 if (!hdr.usb_cdc_union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) { in cdc_ncm_bind_common()
866 ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1); in cdc_ncm_bind_common()
867 dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD\n"); in cdc_ncm_bind_common()
871 if (!ctx->data) { in cdc_ncm_bind_common()
872 dev_err(&intf->dev, "CDC Union missing and no IAD found\n"); in cdc_ncm_bind_common()
875 if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) { in cdc_ncm_bind_common()
876 if (!ctx->mbim_desc) { in cdc_ncm_bind_common()
877 dev_err(&intf->dev, "MBIM functional descriptor missing\n"); in cdc_ncm_bind_common()
881 if (!ctx->ether_desc || !ctx->func_desc) { in cdc_ncm_bind_common()
882 dev_err(&intf->dev, "NCM or ECM functional descriptors missing\n"); in cdc_ncm_bind_common()
888 if (ctx->data != ctx->control) { in cdc_ncm_bind_common()
889 temp = usb_driver_claim_interface(driver, ctx->data, dev); in cdc_ncm_bind_common()
891 dev_err(&intf->dev, "failed to claim data intf\n"); in cdc_ncm_bind_common()
896 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; in cdc_ncm_bind_common()
898 /* Device-specific flags */ in cdc_ncm_bind_common()
899 ctx->drvflags = drvflags; in cdc_ncm_bind_common()
907 if (!(ctx->drvflags & CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE)) in cdc_ncm_bind_common()
908 usb_set_interface(dev->udev, iface_no, data_altsetting); in cdc_ncm_bind_common()
910 temp = usb_set_interface(dev->udev, iface_no, 0); in cdc_ncm_bind_common()
912 dev_dbg(&intf->dev, "set interface failed\n"); in cdc_ncm_bind_common()
928 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); in cdc_ncm_bind_common()
930 dev_dbg(&intf->dev, "set interface failed\n"); in cdc_ncm_bind_common()
934 cdc_ncm_find_endpoints(dev, ctx->data); in cdc_ncm_bind_common()
935 cdc_ncm_find_endpoints(dev, ctx->control); in cdc_ncm_bind_common()
936 if (!dev->in || !dev->out || in cdc_ncm_bind_common()
937 (!dev->status && dev->driver_info->flags & FLAG_LINK_INTR)) { in cdc_ncm_bind_common()
938 dev_dbg(&intf->dev, "failed to collect endpoints\n"); in cdc_ncm_bind_common()
942 usb_set_intfdata(ctx->control, dev); in cdc_ncm_bind_common()
944 if (ctx->ether_desc) { in cdc_ncm_bind_common()
945 temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); in cdc_ncm_bind_common()
947 dev_err(&intf->dev, "failed to get mac address\n"); in cdc_ncm_bind_common()
950 dev_info(&intf->dev, "MAC-Address: %pM\n", dev->net->dev_addr); in cdc_ncm_bind_common()
957 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_bind_common()
958 if (ctx->is_ndp16) { in cdc_ncm_bind_common()
959 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
960 if (!ctx->delayed_ndp16) in cdc_ncm_bind_common()
963 ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
964 if (!ctx->delayed_ndp32) in cdc_ncm_bind_common()
967 dev_info(&intf->dev, "NDP will be placed at end of frame for this device."); in cdc_ncm_bind_common()
971 dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; in cdc_ncm_bind_common()
974 dev->net->sysfs_groups[0] = &cdc_ncm_sysfs_attr_group; in cdc_ncm_bind_common()
977 dev->net->netdev_ops = &cdc_ncm_netdev_ops; in cdc_ncm_bind_common()
978 dev->net->max_mtu = cdc_ncm_max_dgram_size(dev) - cdc_ncm_eth_hlen(dev); in cdc_ncm_bind_common()
983 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_bind_common()
984 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_bind_common()
985 if (ctx->data != ctx->control) in cdc_ncm_bind_common()
986 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_bind_common()
988 cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); in cdc_ncm_bind_common()
989 dev->data[0] = 0; in cdc_ncm_bind_common()
990 dev_info(&intf->dev, "bind() failure\n"); in cdc_ncm_bind_common()
991 return -ENODEV; in cdc_ncm_bind_common()
997 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_unbind()
1003 atomic_set(&ctx->stop, 1); in cdc_ncm_unbind()
1005 hrtimer_cancel(&ctx->tx_timer); in cdc_ncm_unbind()
1007 tasklet_kill(&ctx->bh); in cdc_ncm_unbind()
1010 if (ctx->control == ctx->data) in cdc_ncm_unbind()
1011 ctx->data = NULL; in cdc_ncm_unbind()
1013 /* disconnect master --> disconnect slave */ in cdc_ncm_unbind()
1014 if (intf == ctx->control && ctx->data) { in cdc_ncm_unbind()
1015 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_unbind()
1016 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_unbind()
1017 ctx->data = NULL; in cdc_ncm_unbind()
1019 } else if (intf == ctx->data && ctx->control) { in cdc_ncm_unbind()
1020 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_unbind()
1021 usb_driver_release_interface(driver, ctx->control); in cdc_ncm_unbind()
1022 ctx->control = NULL; in cdc_ncm_unbind()
1052 if (intf->num_altsetting < 2) in cdc_ncm_select_altsetting()
1053 return intf->cur_altsetting->desc.bAlternateSetting; in cdc_ncm_select_altsetting()
1068 return -ENODEV; in cdc_ncm_bind()
1070 /* The NCM data altsetting is fixed, so we hard-coded it. in cdc_ncm_bind()
1079 size_t align = ALIGN(skb->len, modulus) - skb->len + remainder; in cdc_ncm_align_tail()
1081 if (skb->len + align > max) in cdc_ncm_align_tail()
1082 align = max - skb->len; in cdc_ncm_align_tail()
1093 struct usb_cdc_ncm_nth16 *nth16 = (void *)skb->data; in cdc_ncm_ndp16()
1094 size_t ndpoffset = le16_to_cpu(nth16->wNdpIndex); in cdc_ncm_ndp16()
1100 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp16()
1101 if (ctx->delayed_ndp16->dwSignature == sign) in cdc_ncm_ndp16()
1102 return ctx->delayed_ndp16; in cdc_ncm_ndp16()
1108 else if (ctx->delayed_ndp16->dwSignature) in cdc_ncm_ndp16()
1114 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset); in cdc_ncm_ndp16()
1115 if (ndp16->dwSignature == sign) in cdc_ncm_ndp16()
1117 ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex); in cdc_ncm_ndp16()
1121 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1122 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp16()
1125 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp16()
1130 ndp16->wNextNdpIndex = cpu_to_le16(skb->len); in cdc_ncm_ndp16()
1132 nth16->wNdpIndex = cpu_to_le16(skb->len); in cdc_ncm_ndp16()
1135 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1136 ndp16 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp16()
1138 ndp16 = ctx->delayed_ndp16; in cdc_ncm_ndp16()
1140 ndp16->dwSignature = sign; in cdc_ncm_ndp16()
1141 ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) + sizeof(struct usb_cdc_ncm_dpe16)); in cdc_ncm_ndp16()
1148 struct usb_cdc_ncm_nth32 *nth32 = (void *)skb->data; in cdc_ncm_ndp32()
1149 size_t ndpoffset = le32_to_cpu(nth32->dwNdpIndex); in cdc_ncm_ndp32()
1155 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp32()
1156 if (ctx->delayed_ndp32->dwSignature == sign) in cdc_ncm_ndp32()
1157 return ctx->delayed_ndp32; in cdc_ncm_ndp32()
1163 else if (ctx->delayed_ndp32->dwSignature) in cdc_ncm_ndp32()
1169 ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb->data + ndpoffset); in cdc_ncm_ndp32()
1170 if (ndp32->dwSignature == sign) in cdc_ncm_ndp32()
1172 ndpoffset = le32_to_cpu(ndp32->dwNextNdpIndex); in cdc_ncm_ndp32()
1176 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1177 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp32()
1180 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp32()
1185 ndp32->dwNextNdpIndex = cpu_to_le32(skb->len); in cdc_ncm_ndp32()
1187 nth32->dwNdpIndex = cpu_to_le32(skb->len); in cdc_ncm_ndp32()
1190 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1191 ndp32 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp32()
1193 ndp32 = ctx->delayed_ndp32; in cdc_ncm_ndp32()
1195 ndp32->dwSignature = sign; in cdc_ncm_ndp32()
1196 ndp32->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp32) + sizeof(struct usb_cdc_ncm_dpe32)); in cdc_ncm_ndp32()
1203 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_fill_tx_frame()
1218 /* When our NDP gets written in cdc_ncm_ndp(), then skb_out->len gets updated in cdc_ncm_fill_tx_frame()
1221 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) in cdc_ncm_fill_tx_frame()
1222 delayed_ndp_size = ctx->max_ndp_size + in cdc_ncm_fill_tx_frame()
1224 ctx->tx_ndp_modulus, in cdc_ncm_fill_tx_frame()
1225 ctx->tx_modulus + ctx->tx_remainder) - 1; in cdc_ncm_fill_tx_frame()
1231 swap(skb, ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1232 swap(sign, ctx->tx_rem_sign); in cdc_ncm_fill_tx_frame()
1238 skb_out = ctx->tx_curr_skb; in cdc_ncm_fill_tx_frame()
1242 if (ctx->tx_low_mem_val == 0) { in cdc_ncm_fill_tx_frame()
1243 ctx->tx_curr_size = ctx->tx_max; in cdc_ncm_fill_tx_frame()
1244 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1252 if (ctx->tx_curr_size == USB_CDC_NCM_NTB_MIN_OUT_SIZE) in cdc_ncm_fill_tx_frame()
1254 ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1, in cdc_ncm_fill_tx_frame()
1256 ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt; in cdc_ncm_fill_tx_frame()
1265 ctx->tx_curr_size = max(skb->len, in cdc_ncm_fill_tx_frame()
1268 ctx->tx_curr_size = USB_CDC_NCM_NTB_MIN_OUT_SIZE; in cdc_ncm_fill_tx_frame()
1269 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1274 ctx->tx_low_mem_val--; in cdc_ncm_fill_tx_frame()
1276 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1277 /* fill out the initial 16-bit NTB header */ in cdc_ncm_fill_tx_frame()
1279 nth.nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN); in cdc_ncm_fill_tx_frame()
1280 nth.nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16)); in cdc_ncm_fill_tx_frame()
1281 nth.nth16->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1283 /* fill out the initial 32-bit NTB header */ in cdc_ncm_fill_tx_frame()
1285 nth.nth32->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH32_SIGN); in cdc_ncm_fill_tx_frame()
1286 nth.nth32->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth32)); in cdc_ncm_fill_tx_frame()
1287 nth.nth32->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1291 ctx->tx_curr_frame_num = 0; in cdc_ncm_fill_tx_frame()
1294 ctx->tx_curr_frame_payload = 0; in cdc_ncm_fill_tx_frame()
1297 for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) { in cdc_ncm_fill_tx_frame()
1300 skb = ctx->tx_rem_skb; in cdc_ncm_fill_tx_frame()
1301 sign = ctx->tx_rem_sign; in cdc_ncm_fill_tx_frame()
1302 ctx->tx_rem_skb = NULL; in cdc_ncm_fill_tx_frame()
1310 if (ctx->is_ndp16) in cdc_ncm_fill_tx_frame()
1311 ndp.ndp16 = cdc_ncm_ndp16(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1313 ndp.ndp32 = cdc_ncm_ndp32(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1316 cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_curr_size); in cdc_ncm_fill_tx_frame()
1319 if ((ctx->is_ndp16 && !ndp.ndp16) || (!ctx->is_ndp16 && !ndp.ndp32) || in cdc_ncm_fill_tx_frame()
1320 skb_out->len + skb->len + delayed_ndp_size > ctx->tx_curr_size) { in cdc_ncm_fill_tx_frame()
1325 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1327 /* no room for skb - store for later */ in cdc_ncm_fill_tx_frame()
1328 if (ctx->tx_rem_skb != NULL) { in cdc_ncm_fill_tx_frame()
1329 dev_kfree_skb_any(ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1330 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1332 ctx->tx_rem_skb = skb; in cdc_ncm_fill_tx_frame()
1333 ctx->tx_rem_sign = sign; in cdc_ncm_fill_tx_frame()
1336 ctx->tx_reason_ntb_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1342 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1343 ndplen = le16_to_cpu(ndp.ndp16->wLength); in cdc_ncm_fill_tx_frame()
1344 index = (ndplen - sizeof(struct usb_cdc_ncm_ndp16)) / sizeof(struct usb_cdc_ncm_dpe16) - 1; in cdc_ncm_fill_tx_frame()
1347 ndp.ndp16->dpe16[index].wDatagramLength = cpu_to_le16(skb->len); in cdc_ncm_fill_tx_frame()
1348 ndp.ndp16->dpe16[index].wDatagramIndex = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1349 ndp.ndp16->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe16)); in cdc_ncm_fill_tx_frame()
1351 ndplen = le16_to_cpu(ndp.ndp32->wLength); in cdc_ncm_fill_tx_frame()
1352 index = (ndplen - sizeof(struct usb_cdc_ncm_ndp32)) / sizeof(struct usb_cdc_ncm_dpe32) - 1; in cdc_ncm_fill_tx_frame()
1354 ndp.ndp32->dpe32[index].dwDatagramLength = cpu_to_le32(skb->len); in cdc_ncm_fill_tx_frame()
1355 ndp.ndp32->dpe32[index].dwDatagramIndex = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1356 ndp.ndp32->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe32)); in cdc_ncm_fill_tx_frame()
1358 skb_put_data(skb_out, skb->data, skb->len); in cdc_ncm_fill_tx_frame()
1359 ctx->tx_curr_frame_payload += skb->len; /* count real tx payload data */ in cdc_ncm_fill_tx_frame()
1366 ctx->tx_reason_ndp_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1375 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1378 ctx->tx_curr_frame_num = n; in cdc_ncm_fill_tx_frame()
1383 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1386 } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0) && (ctx->timer_interval > 0)) { in cdc_ncm_fill_tx_frame()
1389 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1392 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT; in cdc_ncm_fill_tx_frame()
1396 if (n == ctx->tx_max_datagrams) in cdc_ncm_fill_tx_frame()
1397 ctx->tx_reason_max_datagram++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1403 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_fill_tx_frame()
1404 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1405 nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1406 cdc_ncm_align_tail(skb_out, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size - ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1407 nth.nth16->wNdpIndex = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1408 skb_put_data(skb_out, ctx->delayed_ndp16, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1410 /* Zero out delayed NDP - signature checking will naturally fail. */ in cdc_ncm_fill_tx_frame()
1411 ndp.ndp16 = memset(ctx->delayed_ndp16, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1413 nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1414 cdc_ncm_align_tail(skb_out, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size - ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1415 nth.nth32->dwNdpIndex = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1416 skb_put_data(skb_out, ctx->delayed_ndp32, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1418 ndp.ndp32 = memset(ctx->delayed_ndp32, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1422 /* If collected data size is less or equal ctx->min_tx_pkt in cdc_ncm_fill_tx_frame()
1431 if (!(dev->driver_info->flags & FLAG_SEND_ZLP) && in cdc_ncm_fill_tx_frame()
1432 skb_out->len > ctx->min_tx_pkt) { in cdc_ncm_fill_tx_frame()
1433 padding_count = ctx->tx_curr_size - skb_out->len; in cdc_ncm_fill_tx_frame()
1434 if (!WARN_ON(padding_count > ctx->tx_curr_size)) in cdc_ncm_fill_tx_frame()
1436 } else if (skb_out->len < ctx->tx_curr_size && in cdc_ncm_fill_tx_frame()
1437 (skb_out->len % dev->maxpacket) == 0) { in cdc_ncm_fill_tx_frame()
1442 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1443 nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1444 nth.nth16->wBlockLength = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1446 nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1447 nth.nth32->dwBlockLength = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1451 ctx->tx_curr_skb = NULL; in cdc_ncm_fill_tx_frame()
1454 ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload; in cdc_ncm_fill_tx_frame()
1455 ctx->tx_ntbs++; in cdc_ncm_fill_tx_frame()
1462 (long)ctx->tx_curr_frame_payload - skb_out->len); in cdc_ncm_fill_tx_frame()
1469 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1472 /* Start timer, if there is a remaining non-empty skb */ in cdc_ncm_fill_tx_frame()
1473 if (ctx->tx_curr_skb != NULL && n > 0) in cdc_ncm_fill_tx_frame()
1482 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop))) in cdc_ncm_tx_timeout_start()
1483 hrtimer_start(&ctx->tx_timer, in cdc_ncm_tx_timeout_start()
1484 ctx->timer_interval, in cdc_ncm_tx_timeout_start()
1493 if (!atomic_read(&ctx->stop)) in cdc_ncm_tx_timer_cb()
1494 tasklet_schedule(&ctx->bh); in cdc_ncm_tx_timer_cb()
1501 struct usbnet *dev = ctx->dev; in cdc_ncm_txpath_bh()
1503 spin_lock(&ctx->mtx); in cdc_ncm_txpath_bh()
1504 if (ctx->tx_timer_pending != 0) { in cdc_ncm_txpath_bh()
1505 ctx->tx_timer_pending--; in cdc_ncm_txpath_bh()
1507 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1508 } else if (dev->net != NULL) { in cdc_ncm_txpath_bh()
1509 ctx->tx_reason_timeout++; /* count reason for transmitting */ in cdc_ncm_txpath_bh()
1510 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1511 netif_tx_lock_bh(dev->net); in cdc_ncm_txpath_bh()
1512 usbnet_start_xmit(NULL, dev->net); in cdc_ncm_txpath_bh()
1513 netif_tx_unlock_bh(dev->net); in cdc_ncm_txpath_bh()
1515 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1523 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_tx_fixup()
1535 spin_lock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1537 if (ctx->is_ndp16) in cdc_ncm_tx_fixup()
1542 spin_unlock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1556 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_nth16()
1559 int ret = -EINVAL; in cdc_ncm_rx_verify_nth16()
1564 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) + in cdc_ncm_rx_verify_nth16()
1566 netif_dbg(dev, rx_err, dev->net, "frame too short\n"); in cdc_ncm_rx_verify_nth16()
1570 nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data; in cdc_ncm_rx_verify_nth16()
1572 if (nth16->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN)) { in cdc_ncm_rx_verify_nth16()
1573 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1575 le32_to_cpu(nth16->dwSignature)); in cdc_ncm_rx_verify_nth16()
1579 len = le16_to_cpu(nth16->wBlockLength); in cdc_ncm_rx_verify_nth16()
1580 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth16()
1581 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1582 "unsupported NTB block length %u/%u\n", len, in cdc_ncm_rx_verify_nth16()
1583 ctx->rx_max); in cdc_ncm_rx_verify_nth16()
1587 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) && in cdc_ncm_rx_verify_nth16()
1588 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) && in cdc_ncm_rx_verify_nth16()
1589 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) { in cdc_ncm_rx_verify_nth16()
1590 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1592 ctx->rx_seq, le16_to_cpu(nth16->wSequence)); in cdc_ncm_rx_verify_nth16()
1594 ctx->rx_seq = le16_to_cpu(nth16->wSequence); in cdc_ncm_rx_verify_nth16()
1596 ret = le16_to_cpu(nth16->wNdpIndex); in cdc_ncm_rx_verify_nth16()
1604 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_nth32()
1607 int ret = -EINVAL; in cdc_ncm_rx_verify_nth32()
1612 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth32) + in cdc_ncm_rx_verify_nth32()
1614 netif_dbg(dev, rx_err, dev->net, "frame too short\n"); in cdc_ncm_rx_verify_nth32()
1618 nth32 = (struct usb_cdc_ncm_nth32 *)skb_in->data; in cdc_ncm_rx_verify_nth32()
1620 if (nth32->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH32_SIGN)) { in cdc_ncm_rx_verify_nth32()
1621 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1623 le32_to_cpu(nth32->dwSignature)); in cdc_ncm_rx_verify_nth32()
1627 len = le32_to_cpu(nth32->dwBlockLength); in cdc_ncm_rx_verify_nth32()
1628 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth32()
1629 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1630 "unsupported NTB block length %u/%u\n", len, in cdc_ncm_rx_verify_nth32()
1631 ctx->rx_max); in cdc_ncm_rx_verify_nth32()
1635 if ((ctx->rx_seq + 1) != le16_to_cpu(nth32->wSequence) && in cdc_ncm_rx_verify_nth32()
1636 (ctx->rx_seq || le16_to_cpu(nth32->wSequence)) && in cdc_ncm_rx_verify_nth32()
1637 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth32->wSequence))) { in cdc_ncm_rx_verify_nth32()
1638 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1640 ctx->rx_seq, le16_to_cpu(nth32->wSequence)); in cdc_ncm_rx_verify_nth32()
1642 ctx->rx_seq = le16_to_cpu(nth32->wSequence); in cdc_ncm_rx_verify_nth32()
1644 ret = le32_to_cpu(nth32->dwNdpIndex); in cdc_ncm_rx_verify_nth32()
1653 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_ndp16()
1655 int ret = -EINVAL; in cdc_ncm_rx_verify_ndp16()
1657 if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) { in cdc_ncm_rx_verify_ndp16()
1658 netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n", in cdc_ncm_rx_verify_ndp16()
1662 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_verify_ndp16()
1664 if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { in cdc_ncm_rx_verify_ndp16()
1665 netif_dbg(dev, rx_err, dev->net, "invalid DPT16 length <%u>\n", in cdc_ncm_rx_verify_ndp16()
1666 le16_to_cpu(ndp16->wLength)); in cdc_ncm_rx_verify_ndp16()
1670 ret = ((le16_to_cpu(ndp16->wLength) - in cdc_ncm_rx_verify_ndp16()
1673 ret--; /* we process NDP entries except for the last one */ in cdc_ncm_rx_verify_ndp16()
1676 ret * (sizeof(struct usb_cdc_ncm_dpe16))) > skb_in->len) { in cdc_ncm_rx_verify_ndp16()
1677 netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret); in cdc_ncm_rx_verify_ndp16()
1678 ret = -EINVAL; in cdc_ncm_rx_verify_ndp16()
1689 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_ndp32()
1691 int ret = -EINVAL; in cdc_ncm_rx_verify_ndp32()
1693 if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp32)) > skb_in->len) { in cdc_ncm_rx_verify_ndp32()
1694 netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n", in cdc_ncm_rx_verify_ndp32()
1698 ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_verify_ndp32()
1700 if (le16_to_cpu(ndp32->wLength) < USB_CDC_NCM_NDP32_LENGTH_MIN) { in cdc_ncm_rx_verify_ndp32()
1701 netif_dbg(dev, rx_err, dev->net, "invalid DPT32 length <%u>\n", in cdc_ncm_rx_verify_ndp32()
1702 le16_to_cpu(ndp32->wLength)); in cdc_ncm_rx_verify_ndp32()
1706 ret = ((le16_to_cpu(ndp32->wLength) - in cdc_ncm_rx_verify_ndp32()
1709 ret--; /* we process NDP entries except for the last one */ in cdc_ncm_rx_verify_ndp32()
1712 ret * (sizeof(struct usb_cdc_ncm_dpe32))) > skb_in->len) { in cdc_ncm_rx_verify_ndp32()
1713 netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret); in cdc_ncm_rx_verify_ndp32()
1714 ret = -EINVAL; in cdc_ncm_rx_verify_ndp32()
1725 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_rx_fixup()
1743 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1752 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1757 ndp.ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_fixup()
1759 if (ndp.ndp16->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) { in cdc_ncm_rx_fixup()
1760 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1762 le32_to_cpu(ndp.ndp16->dwSignature)); in cdc_ncm_rx_fixup()
1765 dpe.dpe16 = ndp.ndp16->dpe16; in cdc_ncm_rx_fixup()
1771 ndp.ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_fixup()
1773 if (ndp.ndp32->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP32_NOCRC_SIGN)) { in cdc_ncm_rx_fixup()
1774 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1776 le32_to_cpu(ndp.ndp32->dwSignature)); in cdc_ncm_rx_fixup()
1779 dpe.dpe32 = ndp.ndp32->dpe32; in cdc_ncm_rx_fixup()
1783 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1784 offset = le16_to_cpu(dpe.dpe16->wDatagramIndex); in cdc_ncm_rx_fixup()
1785 len = le16_to_cpu(dpe.dpe16->wDatagramLength); in cdc_ncm_rx_fixup()
1787 offset = le32_to_cpu(dpe.dpe32->dwDatagramIndex); in cdc_ncm_rx_fixup()
1788 len = le32_to_cpu(dpe.dpe32->dwDatagramLength); in cdc_ncm_rx_fixup()
1801 /* sanity checking - watch out for integer wrap*/ in cdc_ncm_rx_fixup()
1802 if ((offset > skb_in->len) || (len > skb_in->len - offset) || in cdc_ncm_rx_fixup()
1803 (len > ctx->rx_max) || (len < ETH_HLEN)) { in cdc_ncm_rx_fixup()
1804 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1805 "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n", in cdc_ncm_rx_fixup()
1813 skb = netdev_alloc_skb_ip_align(dev->net, len); in cdc_ncm_rx_fixup()
1816 skb_put_data(skb, skb_in->data + offset, len); in cdc_ncm_rx_fixup()
1821 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1828 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1829 ndpoffset = le16_to_cpu(ndp.ndp16->wNextNdpIndex); in cdc_ncm_rx_fixup()
1831 ndpoffset = le32_to_cpu(ndp.ndp32->dwNextNdpIndex); in cdc_ncm_rx_fixup()
1833 if (ndpoffset && loopcount--) in cdc_ncm_rx_fixup()
1837 ctx->rx_overhead += skb_in->len - payload; in cdc_ncm_rx_fixup()
1838 ctx->rx_ntbs++; in cdc_ncm_rx_fixup()
1851 dev->rx_speed = le32_to_cpu(data->DLBitRRate); in cdc_ncm_speed_change()
1852 dev->tx_speed = le32_to_cpu(data->ULBitRate); in cdc_ncm_speed_change()
1859 if (urb->actual_length < sizeof(*event)) in cdc_ncm_status()
1862 /* test for split data in 8-byte chunks */ in cdc_ncm_status()
1863 if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { in cdc_ncm_status()
1865 (struct usb_cdc_speed_change *)urb->transfer_buffer); in cdc_ncm_status()
1869 event = urb->transfer_buffer; in cdc_ncm_status()
1871 switch (event->bNotificationType) { in cdc_ncm_status()
1881 if (netif_carrier_ok(dev->net) != !!event->wValue) in cdc_ncm_status()
1882 usbnet_link_change(dev, !!event->wValue, 0); in cdc_ncm_status()
1886 if (urb->actual_length < (sizeof(*event) + in cdc_ncm_status()
1888 set_bit(EVENT_STS_SPLIT, &dev->flags); in cdc_ncm_status()
1895 dev_dbg(&dev->udev->dev, in cdc_ncm_status()
1897 event->bNotificationType); in cdc_ncm_status()
2072 /* u-blox TOBY-L4 */
2089 /* Generic CDC-NCM devices */