Lines Matching refs:ctx

139 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
168 static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
176 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
178 err = usb_control_msg(ctx->udev,
179 usb_rcvctrlpipe(ctx->udev, 0),
183 0, iface_no, &ctx->ncm_parm,
184 sizeof(ctx->ncm_parm), 10000);
191 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
192 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
193 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
194 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
195 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
197 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
198 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
200 if (ctx->func_desc != NULL)
201 flags = ctx->func_desc->bmNetworkCapabilities;
208 ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus,
209 ctx->tx_ndp_modulus, ctx->tx_max_datagrams, flags);
212 if ((ctx->tx_max_datagrams == 0) ||
213 (ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX))
214 ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX;
217 if (ctx->rx_max < USB_CDC_NCM_NTB_MIN_IN_SIZE) {
220 ctx->rx_max = USB_CDC_NCM_NTB_MIN_IN_SIZE;
223 if (ctx->rx_max > CDC_NCM_NTB_MAX_SIZE_RX) {
226 ctx->rx_max = CDC_NCM_NTB_MAX_SIZE_RX;
230 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
241 err = usb_control_msg(ctx->udev,
242 usb_sndctrlpipe(ctx->udev, 0),
256 *dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
258 err = usb_control_msg(ctx->udev,
259 usb_sndctrlpipe(ctx->udev, 0),
272 if ((ctx->tx_max <
274 (ctx->tx_max > CDC_NCM_NTB_MAX_SIZE_TX)) {
277 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
286 val = ctx->tx_ndp_modulus;
289 (val != ((-val) & val)) || (val >= ctx->tx_max)) {
291 ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
300 val = ctx->tx_modulus;
303 (val != ((-val) & val)) || (val >= ctx->tx_max)) {
305 ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
309 if (ctx->tx_remainder >= ctx->tx_modulus) {
311 ctx->tx_remainder = 0;
315 ctx->tx_remainder = ((ctx->tx_remainder - ETH_HLEN) &
316 (ctx->tx_modulus - 1));
322 err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
334 err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
343 ctx->max_datagram_size = CDC_NCM_MIN_DATAGRAM_SIZE;
348 u16 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
357 err = usb_control_msg(ctx->udev, usb_rcvctrlpipe(ctx->udev, 0),
367 ctx->max_datagram_size =
370 if (ctx->max_datagram_size > eth_max_sz)
371 ctx->max_datagram_size = eth_max_sz;
373 if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE)
374 ctx->max_datagram_size =
377 if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE)
378 ctx->max_datagram_size =
382 if (ctx->max_datagram_size !=
384 err = usb_control_msg(ctx->udev,
385 usb_sndctrlpipe(ctx->udev, 0),
400 if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN))
401 ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN;
407 cdc_ncm_find_endpoints(struct cdc_ncm_ctx *ctx, struct usb_interface *intf)
418 if (ctx->status_ep == NULL)
419 ctx->status_ep = e;
425 if (ctx->in_ep == NULL)
426 ctx->in_ep = e;
428 if (ctx->out_ep == NULL)
429 ctx->out_ep = e;
439 static void cdc_ncm_free(struct cdc_ncm_ctx *ctx)
441 if (ctx == NULL)
444 if (ctx->tx_rem_skb != NULL) {
445 dev_kfree_skb_any(ctx->tx_rem_skb);
446 ctx->tx_rem_skb = NULL;
449 if (ctx->tx_curr_skb != NULL) {
450 dev_kfree_skb_any(ctx->tx_curr_skb);
451 ctx->tx_curr_skb = NULL;
454 kfree(ctx);
459 struct cdc_ncm_ctx *ctx;
466 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
467 if (ctx == NULL)
470 hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
471 ctx->tx_timer.function = &cdc_ncm_tx_timer_cb;
472 ctx->bh.data = (unsigned long)ctx;
473 ctx->bh.func = cdc_ncm_txpath_bh;
474 atomic_set(&ctx->stop, 0);
475 spin_lock_init(&ctx->mtx);
476 ctx->netdev = dev->net;
478 /* store ctx pointer in device data field */
479 dev->data[0] = (unsigned long)ctx;
486 ctx->udev = dev->udev;
487 ctx->intf = intf;
497 if (buf[0] < sizeof(*(ctx->union_desc)))
500 ctx->union_desc =
503 ctx->control = usb_ifnum_to_if(dev->udev,
504 ctx->union_desc->bMasterInterface0);
505 ctx->data = usb_ifnum_to_if(dev->udev,
506 ctx->union_desc->bSlaveInterface0);
510 if (buf[0] < sizeof(*(ctx->ether_desc)))
513 ctx->ether_desc =
516 le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
525 if (buf[0] < sizeof(*(ctx->func_desc)))
528 ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf;
542 if ((ctx->control == NULL) || (ctx->data == NULL) ||
543 (ctx->ether_desc == NULL) || (ctx->control != intf))
547 temp = usb_driver_claim_interface(driver, ctx->data, dev);
551 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber;
559 if (cdc_ncm_setup(ctx))
567 cdc_ncm_find_endpoints(ctx, ctx->data);
568 cdc_ncm_find_endpoints(ctx, ctx->control);
570 if ((ctx->in_ep == NULL) || (ctx->out_ep == NULL) ||
571 (ctx->status_ep == NULL))
576 usb_set_intfdata(ctx->data, dev);
577 usb_set_intfdata(ctx->control, dev);
578 usb_set_intfdata(ctx->intf, dev);
580 temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
587 ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
589 ctx->out_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
590 dev->status = ctx->status_ep;
591 dev->rx_urb_size = ctx->rx_max;
600 ctx->tx_speed = ctx->rx_speed = 0;
604 usb_set_intfdata(ctx->control, NULL);
605 usb_set_intfdata(ctx->data, NULL);
606 usb_driver_release_interface(driver, ctx->data);
616 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
619 if (ctx == NULL)
622 atomic_set(&ctx->stop, 1);
624 if (hrtimer_active(&ctx->tx_timer))
625 hrtimer_cancel(&ctx->tx_timer);
627 tasklet_kill(&ctx->bh);
630 if (intf == ctx->control && ctx->data) {
631 usb_set_intfdata(ctx->data, NULL);
632 usb_driver_release_interface(driver, ctx->data);
633 ctx->data = NULL;
635 } else if (intf == ctx->data && ctx->control) {
636 usb_set_intfdata(ctx->control, NULL);
637 usb_driver_release_interface(driver, ctx->control);
638 ctx->control = NULL;
641 usb_set_intfdata(ctx->intf, NULL);
642 cdc_ncm_free(ctx);
657 cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
668 swap(skb, ctx->tx_rem_skb);
681 if (ctx->tx_curr_skb != NULL) {
683 skb_out = ctx->tx_curr_skb;
684 offset = ctx->tx_curr_offset;
685 last_offset = ctx->tx_curr_last_offset;
686 n = ctx->tx_curr_frame_num;
690 skb_out = alloc_skb((ctx->tx_max + 1), GFP_ATOMIC);
694 ctx->netdev->stats.tx_dropped++;
701 ctx->tx_ndp_modulus) +
703 (ctx->tx_max_datagrams + 1) *
709 offset = ALIGN(offset, ctx->tx_modulus) + ctx->tx_remainder;
713 ctx->tx_curr_frame_num = 0;
716 for (; n < ctx->tx_max_datagrams; n++) {
718 if (offset >= ctx->tx_max) {
723 rem = ctx->tx_max - offset;
726 skb = ctx->tx_rem_skb;
727 ctx->tx_rem_skb = NULL;
739 ctx->netdev->stats.tx_dropped++;
742 if (ctx->tx_rem_skb != NULL) {
743 dev_kfree_skb_any(ctx->tx_rem_skb);
744 ctx->netdev->stats.tx_dropped++;
746 ctx->tx_rem_skb = skb;
755 ctx->tx_ncm.dpe16[n].wDatagramLength = cpu_to_le16(skb->len);
756 ctx->tx_ncm.dpe16[n].wDatagramIndex = cpu_to_le16(offset);
765 offset = ALIGN(offset, ctx->tx_modulus) + ctx->tx_remainder;
769 ctx->tx_max);
778 ctx->netdev->stats.tx_dropped++;
781 ctx->tx_curr_frame_num = n;
786 ctx->tx_curr_skb = skb_out;
787 ctx->tx_curr_offset = offset;
788 ctx->tx_curr_last_offset = last_offset;
791 } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0)) {
794 ctx->tx_curr_skb = skb_out;
795 ctx->tx_curr_offset = offset;
796 ctx->tx_curr_last_offset = last_offset;
799 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT;
808 if (last_offset > ctx->tx_max)
809 last_offset = ctx->tx_max;
821 offset = ctx->tx_max;
824 cdc_ncm_zero_fill(skb_out->data, last_offset, offset, ctx->tx_max);
829 if (((last_offset < ctx->tx_max) && ((last_offset %
830 le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0)) ||
831 (((last_offset == ctx->tx_max) && ((ctx->tx_max %
832 le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0)) &&
833 (ctx->tx_max < le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)))) {
841 ctx->tx_ncm.dpe16[n].wDatagramLength = 0;
842 ctx->tx_ncm.dpe16[n].wDatagramIndex = 0;
846 ctx->tx_ncm.nth16.dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN);
847 ctx->tx_ncm.nth16.wHeaderLength =
848 cpu_to_le16(sizeof(ctx->tx_ncm.nth16));
849 ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq);
850 ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset);
851 index = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus);
852 ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(index);
854 memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16));
855 ctx->tx_seq++;
858 ctx->tx_ncm.ndp16.dwSignature =
860 rem = sizeof(ctx->tx_ncm.ndp16) + ((ctx->tx_curr_frame_num + 1) *
862 ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem);
863 ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */
866 &(ctx->tx_ncm.ndp16),
867 sizeof(ctx->tx_ncm.ndp16));
869 memcpy(((u8 *)skb_out->data) + index + sizeof(ctx->tx_ncm.ndp16),
870 &(ctx->tx_ncm.dpe16),
871 (ctx->tx_curr_frame_num + 1) *
878 ctx->tx_curr_skb = NULL;
879 ctx->netdev->stats.tx_packets += ctx->tx_curr_frame_num;
884 if (ctx->tx_curr_skb != NULL)
885 cdc_ncm_tx_timeout_start(ctx);
889 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
892 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop)))
893 hrtimer_start(&ctx->tx_timer,
900 struct cdc_ncm_ctx *ctx =
903 if (!atomic_read(&ctx->stop))
904 tasklet_schedule(&ctx->bh);
910 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)param;
912 spin_lock_bh(&ctx->mtx);
913 if (ctx->tx_timer_pending != 0) {
914 ctx->tx_timer_pending--;
915 cdc_ncm_tx_timeout_start(ctx);
916 spin_unlock_bh(&ctx->mtx);
917 } else if (ctx->netdev != NULL) {
918 spin_unlock_bh(&ctx->mtx);
919 netif_tx_lock_bh(ctx->netdev);
920 usbnet_start_xmit(NULL, ctx->netdev);
921 netif_tx_unlock_bh(ctx->netdev);
929 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
938 if (ctx == NULL)
941 spin_lock_bh(&ctx->mtx);
942 skb_out = cdc_ncm_fill_tx_frame(ctx, skb);
943 spin_unlock_bh(&ctx->mtx);
956 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
965 if (ctx == NULL)
983 if (len > ctx->rx_max) {
985 ctx->rx_max);
989 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) &&
990 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) &&
991 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) {
993 ctx->rx_seq, le16_to_cpu(nth16->wSequence));
995 ctx->rx_seq = le16_to_cpu(nth16->wSequence);
1049 (len > ctx->rx_max) || (len < ETH_HLEN)) {
1073 cdc_ncm_speed_change(struct cdc_ncm_ctx *ctx,
1083 if ((tx_speed != ctx->tx_speed) || (rx_speed != ctx->rx_speed)) {
1084 ctx->tx_speed = tx_speed;
1085 ctx->rx_speed = rx_speed;
1091 ctx->netdev->name,
1098 ctx->netdev->name,
1107 struct cdc_ncm_ctx *ctx;
1110 ctx = (struct cdc_ncm_ctx *)dev->data[0];
1117 cdc_ncm_speed_change(ctx,
1131 ctx->connected = event->wValue;
1135 ctx->netdev->name, ctx->connected ? "" : "dis");
1137 if (ctx->connected)
1141 ctx->tx_speed = ctx->rx_speed = 0;
1150 cdc_ncm_speed_change(ctx,
1163 struct cdc_ncm_ctx *ctx;
1165 ctx = (struct cdc_ncm_ctx *)dev->data[0];
1166 if (ctx == NULL)
1169 return !ctx->connected;