Lines Matching refs:ctx
66 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
110 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_get_ethtool_stats() local
115 p = (char *)ctx + cdc_ncm_gstrings_stats[i].stat_offset; 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() local
157 max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_RX, le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)); in cdc_ncm_check_rx_max()
162 le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize), min); 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() local
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()
205 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in min_tx_pkt_show() local
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() local
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() local
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() local
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() local
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() local
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() local
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() local
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() local
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() local
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()
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()
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()
364 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; \
365 return sprintf(buf, format "\n", tocpu(ctx->ncm_parm.name)); \
407 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_update_rxtx_max() local
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()
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()
437 if (val != ctx->tx_max) in cdc_ncm_update_rxtx_max()
447 if (val != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) && in cdc_ncm_update_rxtx_max()
452 if (netif_running(dev->net) && val > ctx->tx_max) { 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()
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() local
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()
504 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_max_dgram_size() local
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()
518 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_init() local
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()
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()
563 ctx->is_ndp16 = 1; in cdc_ncm_init()
572 ctx->is_ndp16 = 1; 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()
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() local
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()
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()
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()
659 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_fix_modulus() local
668 val = ctx->tx_ndp_modulus; in cdc_ncm_fix_modulus()
671 (val != ((-val) & val)) || (val >= ctx->tx_max)) { in cdc_ncm_fix_modulus()
673 ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE; 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()
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()
693 ctx->tx_remainder = 0; 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() local
710 le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)); in cdc_ncm_setup()
712 le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)); in cdc_ncm_setup()
770 static void cdc_ncm_free(struct cdc_ncm_ctx *ctx) in cdc_ncm_free() argument
772 if (ctx == NULL) in cdc_ncm_free()
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()
790 kfree(ctx); in cdc_ncm_free()
822 struct cdc_ncm_ctx *ctx; in cdc_ncm_bind_common() local
830 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in cdc_ncm_bind_common()
831 if (!ctx) 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()
857 ctx->data = usb_ifnum_to_if(dev->udev, 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()
866 ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1); in cdc_ncm_bind_common()
871 if (!ctx->data) { in cdc_ncm_bind_common()
876 if (!ctx->mbim_desc) { in cdc_ncm_bind_common()
881 if (!ctx->ether_desc || !ctx->func_desc) { 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()
896 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; 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()
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()
941 usb_set_intfdata(ctx->control, dev); in cdc_ncm_bind_common()
943 if (ctx->ether_desc) { in cdc_ncm_bind_common()
944 temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); in cdc_ncm_bind_common()
956 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_bind_common()
957 if (ctx->is_ndp16) { in cdc_ncm_bind_common()
958 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
959 if (!ctx->delayed_ndp16) in cdc_ncm_bind_common()
962 ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); in cdc_ncm_bind_common()
963 if (!ctx->delayed_ndp32) in cdc_ncm_bind_common()
982 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_bind_common()
983 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_bind_common()
984 if (ctx->data != ctx->control) in cdc_ncm_bind_common()
985 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_bind_common()
996 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_unbind() local
999 if (ctx == NULL) in cdc_ncm_unbind()
1002 atomic_set(&ctx->stop, 1); in cdc_ncm_unbind()
1004 hrtimer_cancel(&ctx->tx_timer); in cdc_ncm_unbind()
1006 tasklet_kill(&ctx->bh); in cdc_ncm_unbind()
1009 if (ctx->control == ctx->data) in cdc_ncm_unbind()
1010 ctx->data = NULL; in cdc_ncm_unbind()
1013 if (intf == ctx->control && ctx->data) { in cdc_ncm_unbind()
1014 usb_set_intfdata(ctx->data, NULL); in cdc_ncm_unbind()
1015 usb_driver_release_interface(driver, ctx->data); in cdc_ncm_unbind()
1016 ctx->data = NULL; in cdc_ncm_unbind()
1018 } else if (intf == ctx->data && ctx->control) { in cdc_ncm_unbind()
1019 usb_set_intfdata(ctx->control, NULL); in cdc_ncm_unbind()
1020 usb_driver_release_interface(driver, ctx->control); in cdc_ncm_unbind()
1021 ctx->control = NULL; in cdc_ncm_unbind()
1025 cdc_ncm_free(ctx); in cdc_ncm_unbind()
1089 static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32… in cdc_ncm_ndp16() argument
1099 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp16()
1100 if (ctx->delayed_ndp16->dwSignature == sign) in cdc_ncm_ndp16()
1101 return ctx->delayed_ndp16; in cdc_ncm_ndp16()
1107 else if (ctx->delayed_ndp16->dwSignature) in cdc_ncm_ndp16()
1120 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1121 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp16()
1124 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp16()
1134 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp16()
1135 ndp16 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp16()
1137 ndp16 = ctx->delayed_ndp16; in cdc_ncm_ndp16()
1144 static struct usb_cdc_ncm_ndp32 *cdc_ncm_ndp32(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32… in cdc_ncm_ndp32() argument
1154 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_ndp32()
1155 if (ctx->delayed_ndp32->dwSignature == sign) in cdc_ncm_ndp32()
1156 return ctx->delayed_ndp32; in cdc_ncm_ndp32()
1162 else if (ctx->delayed_ndp32->dwSignature) in cdc_ncm_ndp32()
1175 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1176 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); in cdc_ncm_ndp32()
1179 if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) in cdc_ncm_ndp32()
1189 if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) in cdc_ncm_ndp32()
1190 ndp32 = skb_put_zero(skb, ctx->max_ndp_size); in cdc_ncm_ndp32()
1192 ndp32 = ctx->delayed_ndp32; in cdc_ncm_ndp32()
1202 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_fill_tx_frame() local
1220 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) in cdc_ncm_fill_tx_frame()
1221 delayed_ndp_size = ctx->max_ndp_size + in cdc_ncm_fill_tx_frame()
1223 ctx->tx_ndp_modulus, in cdc_ncm_fill_tx_frame()
1224 ctx->tx_modulus + ctx->tx_remainder) - 1; in cdc_ncm_fill_tx_frame()
1230 swap(skb, ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1231 swap(sign, ctx->tx_rem_sign); in cdc_ncm_fill_tx_frame()
1237 skb_out = ctx->tx_curr_skb; in cdc_ncm_fill_tx_frame()
1241 if (ctx->tx_low_mem_val == 0) { in cdc_ncm_fill_tx_frame()
1242 ctx->tx_curr_size = ctx->tx_max; in cdc_ncm_fill_tx_frame()
1243 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1251 if (ctx->tx_curr_size == USB_CDC_NCM_NTB_MIN_OUT_SIZE) in cdc_ncm_fill_tx_frame()
1253 ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1, in cdc_ncm_fill_tx_frame()
1255 ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt; in cdc_ncm_fill_tx_frame()
1264 ctx->tx_curr_size = max(skb->len, in cdc_ncm_fill_tx_frame()
1267 ctx->tx_curr_size = USB_CDC_NCM_NTB_MIN_OUT_SIZE; in cdc_ncm_fill_tx_frame()
1268 skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC); in cdc_ncm_fill_tx_frame()
1273 ctx->tx_low_mem_val--; in cdc_ncm_fill_tx_frame()
1275 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1280 nth.nth16->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1286 nth.nth32->wSequence = cpu_to_le16(ctx->tx_seq++); in cdc_ncm_fill_tx_frame()
1290 ctx->tx_curr_frame_num = 0; in cdc_ncm_fill_tx_frame()
1293 ctx->tx_curr_frame_payload = 0; in cdc_ncm_fill_tx_frame()
1296 for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) { in cdc_ncm_fill_tx_frame()
1299 skb = ctx->tx_rem_skb; in cdc_ncm_fill_tx_frame()
1300 sign = ctx->tx_rem_sign; in cdc_ncm_fill_tx_frame()
1301 ctx->tx_rem_skb = NULL; in cdc_ncm_fill_tx_frame()
1309 if (ctx->is_ndp16) in cdc_ncm_fill_tx_frame()
1310 ndp.ndp16 = cdc_ncm_ndp16(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1312 ndp.ndp32 = cdc_ncm_ndp32(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); in cdc_ncm_fill_tx_frame()
1315 cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_curr_size); in cdc_ncm_fill_tx_frame()
1318 if ((ctx->is_ndp16 && !ndp.ndp16) || (!ctx->is_ndp16 && !ndp.ndp32) || in cdc_ncm_fill_tx_frame()
1319 skb_out->len + skb->len + delayed_ndp_size > ctx->tx_curr_size) { in cdc_ncm_fill_tx_frame()
1327 if (ctx->tx_rem_skb != NULL) { in cdc_ncm_fill_tx_frame()
1328 dev_kfree_skb_any(ctx->tx_rem_skb); in cdc_ncm_fill_tx_frame()
1331 ctx->tx_rem_skb = skb; in cdc_ncm_fill_tx_frame()
1332 ctx->tx_rem_sign = sign; in cdc_ncm_fill_tx_frame()
1335 ctx->tx_reason_ntb_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1341 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1358 ctx->tx_curr_frame_payload += skb->len; /* count real tx payload data */ in cdc_ncm_fill_tx_frame()
1365 ctx->tx_reason_ndp_full++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1377 ctx->tx_curr_frame_num = n; in cdc_ncm_fill_tx_frame()
1382 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1385 } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0) && (ctx->timer_interval > 0)) { in cdc_ncm_fill_tx_frame()
1388 ctx->tx_curr_skb = skb_out; in cdc_ncm_fill_tx_frame()
1391 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT; in cdc_ncm_fill_tx_frame()
1395 if (n == ctx->tx_max_datagrams) in cdc_ncm_fill_tx_frame()
1396 ctx->tx_reason_max_datagram++; /* count reason for transmitting */ in cdc_ncm_fill_tx_frame()
1402 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { in cdc_ncm_fill_tx_frame()
1403 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1405 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 skb_put_data(skb_out, ctx->delayed_ndp16, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1410 ndp.ndp16 = memset(ctx->delayed_ndp16, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1413 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 skb_put_data(skb_out, ctx->delayed_ndp32, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1417 ndp.ndp32 = memset(ctx->delayed_ndp32, 0, ctx->max_ndp_size); in cdc_ncm_fill_tx_frame()
1431 skb_out->len > ctx->min_tx_pkt) { in cdc_ncm_fill_tx_frame()
1432 padding_count = ctx->tx_curr_size - skb_out->len; in cdc_ncm_fill_tx_frame()
1433 if (!WARN_ON(padding_count > ctx->tx_curr_size)) in cdc_ncm_fill_tx_frame()
1435 } else if (skb_out->len < ctx->tx_curr_size && in cdc_ncm_fill_tx_frame()
1441 if (ctx->is_ndp16) { in cdc_ncm_fill_tx_frame()
1450 ctx->tx_curr_skb = NULL; in cdc_ncm_fill_tx_frame()
1453 ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload; in cdc_ncm_fill_tx_frame()
1454 ctx->tx_ntbs++; in cdc_ncm_fill_tx_frame()
1461 (long)ctx->tx_curr_frame_payload - skb_out->len); in cdc_ncm_fill_tx_frame()
1472 if (ctx->tx_curr_skb != NULL && n > 0) in cdc_ncm_fill_tx_frame()
1473 cdc_ncm_tx_timeout_start(ctx); in cdc_ncm_fill_tx_frame()
1478 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx) in cdc_ncm_tx_timeout_start() argument
1481 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop))) in cdc_ncm_tx_timeout_start()
1482 hrtimer_start(&ctx->tx_timer, in cdc_ncm_tx_timeout_start()
1483 ctx->timer_interval, in cdc_ncm_tx_timeout_start()
1489 struct cdc_ncm_ctx *ctx = in cdc_ncm_tx_timer_cb() local
1492 if (!atomic_read(&ctx->stop)) in cdc_ncm_tx_timer_cb()
1493 tasklet_schedule(&ctx->bh); in cdc_ncm_tx_timer_cb()
1499 struct cdc_ncm_ctx *ctx = from_tasklet(ctx, t, bh); in cdc_ncm_txpath_bh() local
1500 struct usbnet *dev = ctx->dev; in cdc_ncm_txpath_bh()
1502 spin_lock(&ctx->mtx); in cdc_ncm_txpath_bh()
1503 if (ctx->tx_timer_pending != 0) { in cdc_ncm_txpath_bh()
1504 ctx->tx_timer_pending--; in cdc_ncm_txpath_bh()
1505 cdc_ncm_tx_timeout_start(ctx); in cdc_ncm_txpath_bh()
1506 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1508 ctx->tx_reason_timeout++; /* count reason for transmitting */ in cdc_ncm_txpath_bh()
1509 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1514 spin_unlock(&ctx->mtx); in cdc_ncm_txpath_bh()
1522 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_tx_fixup() local
1531 if (ctx == NULL) in cdc_ncm_tx_fixup()
1534 spin_lock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1536 if (ctx->is_ndp16) in cdc_ncm_tx_fixup()
1541 spin_unlock_bh(&ctx->mtx); in cdc_ncm_tx_fixup()
1553 int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in) in cdc_ncm_rx_verify_nth16() argument
1560 if (ctx == NULL) in cdc_ncm_rx_verify_nth16()
1579 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth16()
1582 ctx->rx_max); in cdc_ncm_rx_verify_nth16()
1586 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) && in cdc_ncm_rx_verify_nth16()
1587 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) && in cdc_ncm_rx_verify_nth16()
1588 !((ctx->rx_seq == 0xffff) && !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()
1593 ctx->rx_seq = le16_to_cpu(nth16->wSequence); in cdc_ncm_rx_verify_nth16()
1601 int cdc_ncm_rx_verify_nth32(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in) in cdc_ncm_rx_verify_nth32() argument
1608 if (ctx == NULL) in cdc_ncm_rx_verify_nth32()
1627 if (len > ctx->rx_max) { in cdc_ncm_rx_verify_nth32()
1630 ctx->rx_max); in cdc_ncm_rx_verify_nth32()
1634 if ((ctx->rx_seq + 1) != le16_to_cpu(nth32->wSequence) && in cdc_ncm_rx_verify_nth32()
1635 (ctx->rx_seq || le16_to_cpu(nth32->wSequence)) && in cdc_ncm_rx_verify_nth32()
1636 !((ctx->rx_seq == 0xffff) && !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()
1641 ctx->rx_seq = le16_to_cpu(nth32->wSequence); in cdc_ncm_rx_verify_nth32()
1724 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; in cdc_ncm_rx_fixup() local
1742 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1743 ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in); in cdc_ncm_rx_fixup()
1745 ndpoffset = cdc_ncm_rx_verify_nth32(ctx, skb_in); in cdc_ncm_rx_fixup()
1751 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1782 if (ctx->is_ndp16) { in cdc_ncm_rx_fixup()
1802 (len > ctx->rx_max) || (len < ETH_HLEN)) { in cdc_ncm_rx_fixup()
1820 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1827 if (ctx->is_ndp16) in cdc_ncm_rx_fixup()
1836 ctx->rx_overhead += skb_in->len - payload; in cdc_ncm_rx_fixup()
1837 ctx->rx_ntbs++; in cdc_ncm_rx_fixup()