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_setup(&ctx->tx_timer, &cdc_ncm_tx_timer_cb, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in cdc_ncm_bind_common()
837 tasklet_setup(&ctx->bh, cdc_ncm_txpath_bh); in cdc_ncm_bind_common()
838 atomic_set(&ctx->stop, 0); in cdc_ncm_bind_common()
839 spin_lock_init(&ctx->mtx); in cdc_ncm_bind_common()
842 dev->data[0] = (unsigned long)ctx; in cdc_ncm_bind_common()
845 ctx->control = intf; in cdc_ncm_bind_common()
849 buf = intf->cur_altsetting->extra; in cdc_ncm_bind_common()
850 len = intf->cur_altsetting->extralen; in cdc_ncm_bind_common()
856 ctx->data = usb_ifnum_to_if(dev->udev, in cdc_ncm_bind_common()
857 hdr.usb_cdc_union_desc->bSlaveInterface0); in cdc_ncm_bind_common()
858 ctx->ether_desc = hdr.usb_cdc_ether_desc; in cdc_ncm_bind_common()
859 ctx->func_desc = hdr.usb_cdc_ncm_desc; in cdc_ncm_bind_common()
860 ctx->mbim_desc = hdr.usb_cdc_mbim_desc; in cdc_ncm_bind_common()
861 ctx->mbim_extended_desc = hdr.usb_cdc_mbim_extended_desc; in cdc_ncm_bind_common()
864 if (!hdr.usb_cdc_union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) { in cdc_ncm_bind_common()
865 ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1); in cdc_ncm_bind_common()
866 dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD\n"); in cdc_ncm_bind_common()
870 if (!ctx->data) { in cdc_ncm_bind_common()
871 dev_err(&intf->dev, "CDC Union missing and no IAD found\n"); in cdc_ncm_bind_common()
874 if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) { in cdc_ncm_bind_common()
875 if (!ctx->mbim_desc) { in cdc_ncm_bind_common()
876 dev_err(&intf->dev, "MBIM functional descriptor missing\n"); in cdc_ncm_bind_common()
880 if (!ctx->ether_desc || !ctx->func_desc) { in cdc_ncm_bind_common()
881 dev_err(&intf->dev, "NCM or ECM functional descriptors missing\n"); in cdc_ncm_bind_common()
887 if (ctx->data != ctx->control) { in cdc_ncm_bind_common()
888 temp = usb_driver_claim_interface(driver, ctx->data, dev); in cdc_ncm_bind_common()
890 dev_err(&intf->dev, "failed to claim data intf\n"); in cdc_ncm_bind_common()
895 if (ctx->func_desc) in cdc_ncm_bind_common()
896 ctx->filtering_supported = !!(ctx->func_desc->bmNetworkCapabilities in cdc_ncm_bind_common()
899 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; in cdc_ncm_bind_common()
901 /* Device-specific flags */ in cdc_ncm_bind_common()
902 ctx->drvflags = drvflags; in cdc_ncm_bind_common()
910 if (!(ctx->drvflags & CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE)) in cdc_ncm_bind_common()
911 usb_set_interface(dev->udev, iface_no, data_altsetting); in cdc_ncm_bind_common()
913 temp = usb_set_interface(dev->udev, iface_no, 0); in cdc_ncm_bind_common()
915 dev_dbg(&intf->dev, "set interface failed\n"); in cdc_ncm_bind_common()
931 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); in cdc_ncm_bind_common()
933 dev_dbg(&intf->dev, "set interface failed\n"); in cdc_ncm_bind_common()
937 cdc_ncm_find_endpoints(dev, ctx->data); in cdc_ncm_bind_common()
938 cdc_ncm_find_endpoints(dev, ctx->control); in cdc_ncm_bind_common()
939 if (!dev->in || !dev->out || in cdc_ncm_bind_common()
940 (!dev->status && dev->driver_info->flags & FLAG_LINK_INTR)) { in cdc_ncm_bind_common()
941 dev_dbg(&intf->dev, "failed to collect endpoints\n"); in cdc_ncm_bind_common()
945 usb_set_intfdata(ctx->control, dev); in cdc_ncm_bind_common()
947 if (ctx->ether_desc) { in cdc_ncm_bind_common()
948 temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); in cdc_ncm_bind_common()
950 dev_err(&intf->dev, "failed to get mac address\n"); in cdc_ncm_bind_common()
953 dev_info(&intf->dev, "MAC-Address: %pM\n", dev->net->dev_addr); in cdc_ncm_bind_common()
960 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_bind_common()
961 if (ctx->is_ndp16) { in cdc_ncm_bind_common()
962 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
963 if (!ctx->delayed_ndp16) in cdc_ncm_bind_common()
966 ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
967 if (!ctx->delayed_ndp32) in cdc_ncm_bind_common()
970 dev_info(&intf->dev, "NDP will be placed at end of frame for this device."); in cdc_ncm_bind_common()
974 dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; in cdc_ncm_bind_common()
977 dev->net->sysfs_groups[0] = &cdc_ncm_sysfs_attr_group; in cdc_ncm_bind_common()
980 dev->net->netdev_ops = &cdc_ncm_netdev_ops; in cdc_ncm_bind_common()
981 dev->net->max_mtu = cdc_ncm_max_dgram_size(dev) - cdc_ncm_eth_hlen(dev); in cdc_ncm_bind_common()
986 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_bind_common()
987 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_bind_common()
988 if (ctx->data != ctx->control) in cdc_ncm_bind_common()
989 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_bind_common()
991 cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); in cdc_ncm_bind_common()
992 dev->data[0] = 0; in cdc_ncm_bind_common()
993 dev_info(&intf->dev, "bind() failure\n"); in cdc_ncm_bind_common()
994 return -ENODEV; in cdc_ncm_bind_common()
1000 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_unbind()
1006 atomic_set(&ctx->stop, 1); in cdc_ncm_unbind()
1008 hrtimer_cancel(&ctx->tx_timer); in cdc_ncm_unbind()
1010 tasklet_kill(&ctx->bh); in cdc_ncm_unbind()
1013 if (ctx->control == ctx->data) in cdc_ncm_unbind()
1014 ctx->data = NULL; in cdc_ncm_unbind()
1016 /* disconnect master --> disconnect slave */ in cdc_ncm_unbind()
1017 if (intf == ctx->control && ctx->data) { in cdc_ncm_unbind()
1018 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_unbind()
1019 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_unbind()
1020 ctx->data = NULL; in cdc_ncm_unbind()
1022 } else if (intf == ctx->data && ctx->control) { in cdc_ncm_unbind()
1023 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_unbind()
1024 usb_driver_release_interface(driver, ctx->control); in cdc_ncm_unbind()
1025 ctx->control = NULL; in cdc_ncm_unbind()
1055 if (intf->num_altsetting < 2) in cdc_ncm_select_altsetting()
1056 return intf->cur_altsetting->desc.bAlternateSetting; in cdc_ncm_select_altsetting()
1071 return -ENODEV; in cdc_ncm_bind()
1073 /* The NCM data altsetting is fixed, so we hard-coded it. in cdc_ncm_bind()
1082 size_t align = ALIGN(skb->len, modulus) - skb->len + remainder; in cdc_ncm_align_tail()
1084 if (skb->len + align > max) in cdc_ncm_align_tail()
1085 align = max - skb->len; in cdc_ncm_align_tail()
1096 struct usb_cdc_ncm_nth16 *nth16 = (void *)skb->data; in cdc_ncm_ndp16()
1097 size_t ndpoffset = le16_to_cpu(nth16->wNdpIndex); in cdc_ncm_ndp16()
1103 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp16()
1104 if (ctx->delayed_ndp16->dwSignature == sign) in cdc_ncm_ndp16()
1105 return ctx->delayed_ndp16; in cdc_ncm_ndp16()
1111 else if (ctx->delayed_ndp16->dwSignature) in cdc_ncm_ndp16()
1117 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset); in cdc_ncm_ndp16()
1118 if (ndp16->dwSignature == sign) in cdc_ncm_ndp16()
1120 ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex); in cdc_ncm_ndp16()
1124 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1125 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp16()
1128 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp16()
1133 ndp16->wNextNdpIndex = cpu_to_le16(skb->len); in cdc_ncm_ndp16()
1135 nth16->wNdpIndex = cpu_to_le16(skb->len); in cdc_ncm_ndp16()
1138 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1139 ndp16 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp16()
1141 ndp16 = ctx->delayed_ndp16; in cdc_ncm_ndp16()
1143 ndp16->dwSignature = sign; in cdc_ncm_ndp16()
1144 ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) + sizeof(struct usb_cdc_ncm_dpe16)); in cdc_ncm_ndp16()
1151 struct usb_cdc_ncm_nth32 *nth32 = (void *)skb->data; in cdc_ncm_ndp32()
1152 size_t ndpoffset = le32_to_cpu(nth32->dwNdpIndex); in cdc_ncm_ndp32()
1158 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp32()
1159 if (ctx->delayed_ndp32->dwSignature == sign) in cdc_ncm_ndp32()
1160 return ctx->delayed_ndp32; in cdc_ncm_ndp32()
1166 else if (ctx->delayed_ndp32->dwSignature) in cdc_ncm_ndp32()
1172 ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb->data + ndpoffset); in cdc_ncm_ndp32()
1173 if (ndp32->dwSignature == sign) in cdc_ncm_ndp32()
1175 ndpoffset = le32_to_cpu(ndp32->dwNextNdpIndex); in cdc_ncm_ndp32()
1179 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1180 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp32()
1183 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp32()
1188 ndp32->dwNextNdpIndex = cpu_to_le32(skb->len); in cdc_ncm_ndp32()
1190 nth32->dwNdpIndex = cpu_to_le32(skb->len); in cdc_ncm_ndp32()
1193 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1194 ndp32 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp32()
1196 ndp32 = ctx->delayed_ndp32; in cdc_ncm_ndp32()
1198 ndp32->dwSignature = sign; in cdc_ncm_ndp32()
1199 ndp32->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp32) + sizeof(struct usb_cdc_ncm_dpe32)); in cdc_ncm_ndp32()
1206 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_fill_tx_frame()
1221 /* When our NDP gets written in cdc_ncm_ndp(), then skb_out->len gets updated in cdc_ncm_fill_tx_frame()
1224 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) in cdc_ncm_fill_tx_frame()
1225 delayed_ndp_size = ctx->max_ndp_size + in cdc_ncm_fill_tx_frame()
1227 ctx->tx_ndp_modulus, in cdc_ncm_fill_tx_frame()
1228 ctx->tx_modulus + ctx->tx_remainder) - 1; in cdc_ncm_fill_tx_frame()
1234 swap(skb, ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1235 swap(sign, ctx->tx_rem_sign); in cdc_ncm_fill_tx_frame()
1241 skb_out = ctx->tx_curr_skb; in cdc_ncm_fill_tx_frame()
1245 if (ctx->tx_low_mem_val == 0) { in cdc_ncm_fill_tx_frame()
1246 ctx->tx_curr_size = ctx->tx_max; in cdc_ncm_fill_tx_frame()
1247 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1255 if (ctx->tx_curr_size == USB_CDC_NCM_NTB_MIN_OUT_SIZE) in cdc_ncm_fill_tx_frame()
1257 ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1, in cdc_ncm_fill_tx_frame()
1259 ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt; in cdc_ncm_fill_tx_frame()
1268 ctx->tx_curr_size = max(skb->len, in cdc_ncm_fill_tx_frame()
1271 ctx->tx_curr_size = USB_CDC_NCM_NTB_MIN_OUT_SIZE; in cdc_ncm_fill_tx_frame()
1272 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1277 ctx->tx_low_mem_val--; in cdc_ncm_fill_tx_frame()
1279 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1280 /* fill out the initial 16-bit NTB header */ in cdc_ncm_fill_tx_frame()
1282 nth.nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN); in cdc_ncm_fill_tx_frame()
1283 nth.nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16)); in cdc_ncm_fill_tx_frame()
1284 nth.nth16->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1286 /* fill out the initial 32-bit NTB header */ in cdc_ncm_fill_tx_frame()
1288 nth.nth32->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH32_SIGN); in cdc_ncm_fill_tx_frame()
1289 nth.nth32->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth32)); in cdc_ncm_fill_tx_frame()
1290 nth.nth32->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1294 ctx->tx_curr_frame_num = 0; in cdc_ncm_fill_tx_frame()
1297 ctx->tx_curr_frame_payload = 0; in cdc_ncm_fill_tx_frame()
1300 for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) { in cdc_ncm_fill_tx_frame()
1303 skb = ctx->tx_rem_skb; in cdc_ncm_fill_tx_frame()
1304 sign = ctx->tx_rem_sign; in cdc_ncm_fill_tx_frame()
1305 ctx->tx_rem_skb = NULL; in cdc_ncm_fill_tx_frame()
1313 if (ctx->is_ndp16) in cdc_ncm_fill_tx_frame()
1314 ndp.ndp16 = cdc_ncm_ndp16(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1316 ndp.ndp32 = cdc_ncm_ndp32(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1319 cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_curr_size); in cdc_ncm_fill_tx_frame()
1322 if ((ctx->is_ndp16 && !ndp.ndp16) || (!ctx->is_ndp16 && !ndp.ndp32) || in cdc_ncm_fill_tx_frame()
1323 skb_out->len + skb->len + delayed_ndp_size > ctx->tx_curr_size) { in cdc_ncm_fill_tx_frame()
1328 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1330 /* no room for skb - store for later */ in cdc_ncm_fill_tx_frame()
1331 if (ctx->tx_rem_skb != NULL) { in cdc_ncm_fill_tx_frame()
1332 dev_kfree_skb_any(ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1333 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1335 ctx->tx_rem_skb = skb; in cdc_ncm_fill_tx_frame()
1336 ctx->tx_rem_sign = sign; in cdc_ncm_fill_tx_frame()
1339 ctx->tx_reason_ntb_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1345 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1346 ndplen = le16_to_cpu(ndp.ndp16->wLength); in cdc_ncm_fill_tx_frame()
1347 index = (ndplen - sizeof(struct usb_cdc_ncm_ndp16)) / sizeof(struct usb_cdc_ncm_dpe16) - 1; in cdc_ncm_fill_tx_frame()
1350 ndp.ndp16->dpe16[index].wDatagramLength = cpu_to_le16(skb->len); in cdc_ncm_fill_tx_frame()
1351 ndp.ndp16->dpe16[index].wDatagramIndex = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1352 ndp.ndp16->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe16)); in cdc_ncm_fill_tx_frame()
1354 ndplen = le16_to_cpu(ndp.ndp32->wLength); in cdc_ncm_fill_tx_frame()
1355 index = (ndplen - sizeof(struct usb_cdc_ncm_ndp32)) / sizeof(struct usb_cdc_ncm_dpe32) - 1; in cdc_ncm_fill_tx_frame()
1357 ndp.ndp32->dpe32[index].dwDatagramLength = cpu_to_le32(skb->len); in cdc_ncm_fill_tx_frame()
1358 ndp.ndp32->dpe32[index].dwDatagramIndex = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1359 ndp.ndp32->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe32)); in cdc_ncm_fill_tx_frame()
1361 skb_put_data(skb_out, skb->data, skb->len); in cdc_ncm_fill_tx_frame()
1362 ctx->tx_curr_frame_payload += skb->len; /* count real tx payload data */ in cdc_ncm_fill_tx_frame()
1369 ctx->tx_reason_ndp_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1378 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1381 ctx->tx_curr_frame_num = n; in cdc_ncm_fill_tx_frame()
1386 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1389 } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0) && (ctx->timer_interval > 0)) { in cdc_ncm_fill_tx_frame()
1392 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1395 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT; in cdc_ncm_fill_tx_frame()
1399 if (n == ctx->tx_max_datagrams) in cdc_ncm_fill_tx_frame()
1400 ctx->tx_reason_max_datagram++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1406 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_fill_tx_frame()
1407 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1408 nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1409 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()
1410 nth.nth16->wNdpIndex = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1411 skb_put_data(skb_out, ctx->delayed_ndp16, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1413 /* Zero out delayed NDP - signature checking will naturally fail. */ in cdc_ncm_fill_tx_frame()
1414 ndp.ndp16 = memset(ctx->delayed_ndp16, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1416 nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1417 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()
1418 nth.nth32->dwNdpIndex = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1419 skb_put_data(skb_out, ctx->delayed_ndp32, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1421 ndp.ndp32 = memset(ctx->delayed_ndp32, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1425 /* If collected data size is less or equal ctx->min_tx_pkt in cdc_ncm_fill_tx_frame()
1434 if (!(dev->driver_info->flags & FLAG_SEND_ZLP) && in cdc_ncm_fill_tx_frame()
1435 skb_out->len > ctx->min_tx_pkt) { in cdc_ncm_fill_tx_frame()
1436 padding_count = ctx->tx_curr_size - skb_out->len; in cdc_ncm_fill_tx_frame()
1437 if (!WARN_ON(padding_count > ctx->tx_curr_size)) in cdc_ncm_fill_tx_frame()
1439 } else if (skb_out->len < ctx->tx_curr_size && in cdc_ncm_fill_tx_frame()
1440 (skb_out->len % dev->maxpacket) == 0) { in cdc_ncm_fill_tx_frame()
1445 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1446 nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1447 nth.nth16->wBlockLength = cpu_to_le16(skb_out->len); in cdc_ncm_fill_tx_frame()
1449 nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data; in cdc_ncm_fill_tx_frame()
1450 nth.nth32->dwBlockLength = cpu_to_le32(skb_out->len); in cdc_ncm_fill_tx_frame()
1454 ctx->tx_curr_skb = NULL; in cdc_ncm_fill_tx_frame()
1457 ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload; in cdc_ncm_fill_tx_frame()
1458 ctx->tx_ntbs++; in cdc_ncm_fill_tx_frame()
1465 (long)ctx->tx_curr_frame_payload - skb_out->len); in cdc_ncm_fill_tx_frame()
1472 dev->net->stats.tx_dropped++; in cdc_ncm_fill_tx_frame()
1475 /* Start timer, if there is a remaining non-empty skb */ in cdc_ncm_fill_tx_frame()
1476 if (ctx->tx_curr_skb != NULL && n > 0) in cdc_ncm_fill_tx_frame()
1485 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop))) in cdc_ncm_tx_timeout_start()
1486 hrtimer_start(&ctx->tx_timer, in cdc_ncm_tx_timeout_start()
1487 ctx->timer_interval, in cdc_ncm_tx_timeout_start()
1496 if (!atomic_read(&ctx->stop)) in cdc_ncm_tx_timer_cb()
1497 tasklet_schedule(&ctx->bh); in cdc_ncm_tx_timer_cb()
1504 struct usbnet *dev = ctx->dev; in cdc_ncm_txpath_bh()
1506 spin_lock(&ctx->mtx); in cdc_ncm_txpath_bh()
1507 if (ctx->tx_timer_pending != 0) { in cdc_ncm_txpath_bh()
1508 ctx->tx_timer_pending--; in cdc_ncm_txpath_bh()
1510 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1511 } else if (dev->net != NULL) { in cdc_ncm_txpath_bh()
1512 ctx->tx_reason_timeout++; /* count reason for transmitting */ in cdc_ncm_txpath_bh()
1513 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1514 netif_tx_lock_bh(dev->net); in cdc_ncm_txpath_bh()
1515 usbnet_start_xmit(NULL, dev->net); in cdc_ncm_txpath_bh()
1516 netif_tx_unlock_bh(dev->net); in cdc_ncm_txpath_bh()
1518 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1526 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_tx_fixup()
1538 spin_lock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1540 if (ctx->is_ndp16) in cdc_ncm_tx_fixup()
1545 spin_unlock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1559 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_nth16()
1562 int ret = -EINVAL; in cdc_ncm_rx_verify_nth16()
1567 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) + in cdc_ncm_rx_verify_nth16()
1569 netif_dbg(dev, rx_err, dev->net, "frame too short\n"); in cdc_ncm_rx_verify_nth16()
1573 nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data; in cdc_ncm_rx_verify_nth16()
1575 if (nth16->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN)) { in cdc_ncm_rx_verify_nth16()
1576 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1578 le32_to_cpu(nth16->dwSignature)); in cdc_ncm_rx_verify_nth16()
1582 len = le16_to_cpu(nth16->wBlockLength); in cdc_ncm_rx_verify_nth16()
1583 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth16()
1584 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1585 "unsupported NTB block length %u/%u\n", len, in cdc_ncm_rx_verify_nth16()
1586 ctx->rx_max); in cdc_ncm_rx_verify_nth16()
1590 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) && in cdc_ncm_rx_verify_nth16()
1591 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) && in cdc_ncm_rx_verify_nth16()
1592 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) { in cdc_ncm_rx_verify_nth16()
1593 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth16()
1595 ctx->rx_seq, le16_to_cpu(nth16->wSequence)); in cdc_ncm_rx_verify_nth16()
1597 ctx->rx_seq = le16_to_cpu(nth16->wSequence); in cdc_ncm_rx_verify_nth16()
1599 ret = le16_to_cpu(nth16->wNdpIndex); in cdc_ncm_rx_verify_nth16()
1607 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_nth32()
1610 int ret = -EINVAL; in cdc_ncm_rx_verify_nth32()
1615 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth32) + in cdc_ncm_rx_verify_nth32()
1617 netif_dbg(dev, rx_err, dev->net, "frame too short\n"); in cdc_ncm_rx_verify_nth32()
1621 nth32 = (struct usb_cdc_ncm_nth32 *)skb_in->data; in cdc_ncm_rx_verify_nth32()
1623 if (nth32->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH32_SIGN)) { in cdc_ncm_rx_verify_nth32()
1624 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1626 le32_to_cpu(nth32->dwSignature)); in cdc_ncm_rx_verify_nth32()
1630 len = le32_to_cpu(nth32->dwBlockLength); in cdc_ncm_rx_verify_nth32()
1631 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth32()
1632 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1633 "unsupported NTB block length %u/%u\n", len, in cdc_ncm_rx_verify_nth32()
1634 ctx->rx_max); in cdc_ncm_rx_verify_nth32()
1638 if ((ctx->rx_seq + 1) != le16_to_cpu(nth32->wSequence) && in cdc_ncm_rx_verify_nth32()
1639 (ctx->rx_seq || le16_to_cpu(nth32->wSequence)) && in cdc_ncm_rx_verify_nth32()
1640 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth32->wSequence))) { in cdc_ncm_rx_verify_nth32()
1641 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_verify_nth32()
1643 ctx->rx_seq, le16_to_cpu(nth32->wSequence)); in cdc_ncm_rx_verify_nth32()
1645 ctx->rx_seq = le16_to_cpu(nth32->wSequence); in cdc_ncm_rx_verify_nth32()
1647 ret = le32_to_cpu(nth32->dwNdpIndex); in cdc_ncm_rx_verify_nth32()
1656 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_ndp16()
1658 int ret = -EINVAL; in cdc_ncm_rx_verify_ndp16()
1660 if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) { in cdc_ncm_rx_verify_ndp16()
1661 netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n", in cdc_ncm_rx_verify_ndp16()
1665 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_verify_ndp16()
1667 if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { in cdc_ncm_rx_verify_ndp16()
1668 netif_dbg(dev, rx_err, dev->net, "invalid DPT16 length <%u>\n", in cdc_ncm_rx_verify_ndp16()
1669 le16_to_cpu(ndp16->wLength)); in cdc_ncm_rx_verify_ndp16()
1673 ret = ((le16_to_cpu(ndp16->wLength) - in cdc_ncm_rx_verify_ndp16()
1676 ret--; /* we process NDP entries except for the last one */ in cdc_ncm_rx_verify_ndp16()
1679 ret * (sizeof(struct usb_cdc_ncm_dpe16))) > skb_in->len) { in cdc_ncm_rx_verify_ndp16()
1680 netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret); in cdc_ncm_rx_verify_ndp16()
1681 ret = -EINVAL; in cdc_ncm_rx_verify_ndp16()
1692 struct usbnet *dev = netdev_priv(skb_in->dev); in cdc_ncm_rx_verify_ndp32()
1694 int ret = -EINVAL; in cdc_ncm_rx_verify_ndp32()
1696 if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp32)) > skb_in->len) { in cdc_ncm_rx_verify_ndp32()
1697 netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n", in cdc_ncm_rx_verify_ndp32()
1701 ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_verify_ndp32()
1703 if (le16_to_cpu(ndp32->wLength) < USB_CDC_NCM_NDP32_LENGTH_MIN) { in cdc_ncm_rx_verify_ndp32()
1704 netif_dbg(dev, rx_err, dev->net, "invalid DPT32 length <%u>\n", in cdc_ncm_rx_verify_ndp32()
1705 le16_to_cpu(ndp32->wLength)); in cdc_ncm_rx_verify_ndp32()
1709 ret = ((le16_to_cpu(ndp32->wLength) - in cdc_ncm_rx_verify_ndp32()
1712 ret--; /* we process NDP entries except for the last one */ in cdc_ncm_rx_verify_ndp32()
1715 ret * (sizeof(struct usb_cdc_ncm_dpe32))) > skb_in->len) { in cdc_ncm_rx_verify_ndp32()
1716 netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret); in cdc_ncm_rx_verify_ndp32()
1717 ret = -EINVAL; in cdc_ncm_rx_verify_ndp32()
1728 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_rx_fixup()
1746 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1755 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1760 ndp.ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_fixup()
1762 if (ndp.ndp16->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) { in cdc_ncm_rx_fixup()
1763 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1765 le32_to_cpu(ndp.ndp16->dwSignature)); in cdc_ncm_rx_fixup()
1768 dpe.dpe16 = ndp.ndp16->dpe16; in cdc_ncm_rx_fixup()
1774 ndp.ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset); in cdc_ncm_rx_fixup()
1776 if (ndp.ndp32->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP32_NOCRC_SIGN)) { in cdc_ncm_rx_fixup()
1777 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1779 le32_to_cpu(ndp.ndp32->dwSignature)); in cdc_ncm_rx_fixup()
1782 dpe.dpe32 = ndp.ndp32->dpe32; in cdc_ncm_rx_fixup()
1786 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1787 offset = le16_to_cpu(dpe.dpe16->wDatagramIndex); in cdc_ncm_rx_fixup()
1788 len = le16_to_cpu(dpe.dpe16->wDatagramLength); in cdc_ncm_rx_fixup()
1790 offset = le32_to_cpu(dpe.dpe32->dwDatagramIndex); in cdc_ncm_rx_fixup()
1791 len = le32_to_cpu(dpe.dpe32->dwDatagramLength); in cdc_ncm_rx_fixup()
1804 /* sanity checking - watch out for integer wrap*/ in cdc_ncm_rx_fixup()
1805 if ((offset > skb_in->len) || (len > skb_in->len - offset) || in cdc_ncm_rx_fixup()
1806 (len > ctx->rx_max) || (len < ETH_HLEN)) { in cdc_ncm_rx_fixup()
1807 netif_dbg(dev, rx_err, dev->net, in cdc_ncm_rx_fixup()
1808 "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n", in cdc_ncm_rx_fixup()
1816 skb = netdev_alloc_skb_ip_align(dev->net, len); in cdc_ncm_rx_fixup()
1819 skb_put_data(skb, skb_in->data + offset, len); in cdc_ncm_rx_fixup()
1824 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1831 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1832 ndpoffset = le16_to_cpu(ndp.ndp16->wNextNdpIndex); in cdc_ncm_rx_fixup()
1834 ndpoffset = le32_to_cpu(ndp.ndp32->dwNextNdpIndex); in cdc_ncm_rx_fixup()
1836 if (ndpoffset && loopcount--) in cdc_ncm_rx_fixup()
1840 ctx->rx_overhead += skb_in->len - payload; in cdc_ncm_rx_fixup()
1841 ctx->rx_ntbs++; in cdc_ncm_rx_fixup()
1854 dev->rx_speed = le32_to_cpu(data->DLBitRRate); in cdc_ncm_speed_change()
1855 dev->tx_speed = le32_to_cpu(data->ULBitRate); in cdc_ncm_speed_change()
1862 if (urb->actual_length < sizeof(*event)) in cdc_ncm_status()
1865 /* test for split data in 8-byte chunks */ in cdc_ncm_status()
1866 if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { in cdc_ncm_status()
1868 (struct usb_cdc_speed_change *)urb->transfer_buffer); in cdc_ncm_status()
1872 event = urb->transfer_buffer; in cdc_ncm_status()
1874 switch (event->bNotificationType) { in cdc_ncm_status()
1884 if (netif_carrier_ok(dev->net) != !!event->wValue) in cdc_ncm_status()
1885 usbnet_link_change(dev, !!event->wValue, 0); in cdc_ncm_status()
1889 if (urb->actual_length < (sizeof(*event) + in cdc_ncm_status()
1891 set_bit(EVENT_STS_SPLIT, &dev->flags); in cdc_ncm_status()
1898 dev_dbg(&dev->udev->dev, in cdc_ncm_status()
1900 event->bNotificationType); in cdc_ncm_status()
1907 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_update_filter()
1909 if (ctx->filtering_supported) in cdc_ncm_update_filter()
2083 /* u-blox TOBY-L4 */
2090 /* Intel modem (label from OEM reads Fibocom L850-GL) */
2107 /* Generic CDC-NCM devices */