Lines Matching +full:autosuspend +full:- +full:delay +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2000-2005 by David Brownell
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
10 * kinds of full and high speed networking devices: host-to-host cables,
34 /*-------------------------------------------------------------------------*/
37 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
48 #define RX_QLEN(dev) ((dev)->rx_qlen)
49 #define TX_QLEN(dev) ((dev)->tx_qlen)
62 /*-------------------------------------------------------------------------*/
68 static int msg_level = -1;
72 /*-------------------------------------------------------------------------*/
99 for (tmp = 0; tmp < intf->num_altsetting; tmp++) { in usbnet_get_endpoints()
103 alt = intf->altsetting + tmp; in usbnet_get_endpoints()
105 /* take the first altsetting with in-bulk + out-bulk; in usbnet_get_endpoints()
109 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { in usbnet_get_endpoints()
113 e = alt->endpoint + ep; in usbnet_get_endpoints()
116 if (!usb_endpoint_maxp(&e->desc)) in usbnet_get_endpoints()
119 switch (e->desc.bmAttributes) { in usbnet_get_endpoints()
121 if (!usb_endpoint_dir_in(&e->desc)) in usbnet_get_endpoints()
130 if (usb_endpoint_dir_in(&e->desc)) { in usbnet_get_endpoints()
144 return -EINVAL; in usbnet_get_endpoints()
146 if (alt->desc.bAlternateSetting != 0 || in usbnet_get_endpoints()
147 !(dev->driver_info->flags & FLAG_NO_SETINT)) { in usbnet_get_endpoints()
148 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber, in usbnet_get_endpoints()
149 alt->desc.bAlternateSetting); in usbnet_get_endpoints()
154 dev->in = usb_rcvbulkpipe (dev->udev, in usbnet_get_endpoints()
155 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); in usbnet_get_endpoints()
156 dev->out = usb_sndbulkpipe (dev->udev, in usbnet_get_endpoints()
157 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); in usbnet_get_endpoints()
158 dev->status = status; in usbnet_get_endpoints()
166 int tmp = -1, ret; in usbnet_get_ethernet_addr()
169 ret = usb_string(dev->udev, iMACAddress, buf, sizeof buf); in usbnet_get_ethernet_addr()
173 dev_dbg(&dev->udev->dev, in usbnet_get_ethernet_addr()
176 ret = -EINVAL; in usbnet_get_ethernet_addr()
179 eth_hw_addr_set(dev->net, addr); in usbnet_get_ethernet_addr()
186 struct usbnet *dev = urb->context; in intr_complete()
187 int status = urb->status; in intr_complete()
192 dev->driver_info->status(dev, urb); in intr_complete()
195 /* software-driven interface shutdown */ in intr_complete()
196 case -ENOENT: /* urb killed */ in intr_complete()
197 case -ESHUTDOWN: /* hardware gone */ in intr_complete()
198 netif_dbg(dev, ifdown, dev->net, in intr_complete()
206 netdev_dbg(dev->net, "intr status %d\n", status); in intr_complete()
212 netif_err(dev, timer, dev->net, in intr_complete()
213 "intr resubmit --> %d\n", status); in intr_complete()
223 if (!dev->driver_info->status) in init_status()
226 pipe = usb_rcvintpipe (dev->udev, in init_status()
227 dev->status->desc.bEndpointAddress in init_status()
229 maxp = usb_maxpacket(dev->udev, pipe); in init_status()
232 period = max ((int) dev->status->desc.bInterval, in init_status()
233 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3); in init_status()
237 dev->interrupt = usb_alloc_urb (0, GFP_KERNEL); in init_status()
238 if (!dev->interrupt) { in init_status()
240 return -ENOMEM; in init_status()
242 usb_fill_int_urb(dev->interrupt, dev->udev, pipe, in init_status()
244 dev->interrupt->transfer_flags |= URB_FREE_BUFFER; in init_status()
245 dev_dbg(&intf->dev, in init_status()
258 WARN_ON_ONCE(dev->interrupt == NULL); in usbnet_status_start()
259 if (dev->interrupt) { in usbnet_status_start()
260 mutex_lock(&dev->interrupt_mutex); in usbnet_status_start()
262 if (++dev->interrupt_count == 1) in usbnet_status_start()
263 ret = usb_submit_urb(dev->interrupt, mem_flags); in usbnet_status_start()
265 dev_dbg(&dev->udev->dev, "incremented interrupt URB count to %d\n", in usbnet_status_start()
266 dev->interrupt_count); in usbnet_status_start()
267 mutex_unlock(&dev->interrupt_mutex); in usbnet_status_start()
278 mutex_lock(&dev->interrupt_mutex); in __usbnet_status_start_force()
279 if (dev->interrupt_count) { in __usbnet_status_start_force()
280 ret = usb_submit_urb(dev->interrupt, mem_flags); in __usbnet_status_start_force()
281 dev_dbg(&dev->udev->dev, in __usbnet_status_start_force()
284 mutex_unlock(&dev->interrupt_mutex); in __usbnet_status_start_force()
291 if (dev->interrupt) { in usbnet_status_stop()
292 mutex_lock(&dev->interrupt_mutex); in usbnet_status_stop()
293 WARN_ON(dev->interrupt_count == 0); in usbnet_status_stop()
295 if (dev->interrupt_count && --dev->interrupt_count == 0) in usbnet_status_stop()
296 usb_kill_urb(dev->interrupt); in usbnet_status_stop()
298 dev_dbg(&dev->udev->dev, in usbnet_status_stop()
300 dev->interrupt_count); in usbnet_status_stop()
301 mutex_unlock(&dev->interrupt_mutex); in usbnet_status_stop()
309 if (dev->interrupt) { in __usbnet_status_stop_force()
310 mutex_lock(&dev->interrupt_mutex); in __usbnet_status_stop_force()
311 usb_kill_urb(dev->interrupt); in __usbnet_status_stop_force()
312 dev_dbg(&dev->udev->dev, "killed interrupt URB for suspend\n"); in __usbnet_status_stop_force()
313 mutex_unlock(&dev->interrupt_mutex); in __usbnet_status_stop_force()
323 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); in usbnet_skb_return()
327 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) { in usbnet_skb_return()
328 skb_queue_tail(&dev->rxq_pause, skb); in usbnet_skb_return()
333 if (skb->protocol == 0) in usbnet_skb_return()
334 skb->protocol = eth_type_trans (skb, dev->net); in usbnet_skb_return()
336 flags = u64_stats_update_begin_irqsave(&stats64->syncp); in usbnet_skb_return()
337 u64_stats_inc(&stats64->rx_packets); in usbnet_skb_return()
338 u64_stats_add(&stats64->rx_bytes, skb->len); in usbnet_skb_return()
339 u64_stats_update_end_irqrestore(&stats64->syncp, flags); in usbnet_skb_return()
341 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", in usbnet_skb_return()
342 skb->len + sizeof (struct ethhdr), skb->protocol); in usbnet_skb_return()
343 memset (skb->cb, 0, sizeof (struct skb_data)); in usbnet_skb_return()
350 netif_dbg(dev, rx_err, dev->net, in usbnet_skb_return()
358 enum usb_device_speed speed = dev->udev->speed; in usbnet_update_max_qlen()
360 if (!dev->rx_urb_size || !dev->hard_mtu) in usbnet_update_max_qlen()
364 dev->rx_qlen = MAX_QUEUE_MEMORY / dev->rx_urb_size; in usbnet_update_max_qlen()
365 dev->tx_qlen = MAX_QUEUE_MEMORY / dev->hard_mtu; in usbnet_update_max_qlen()
370 * Not take default 5ms qlen for super speed HC to in usbnet_update_max_qlen()
371 * save memory, and iperf tests show 2.5ms qlen can in usbnet_update_max_qlen()
374 dev->rx_qlen = 5 * MAX_QUEUE_MEMORY / dev->rx_urb_size; in usbnet_update_max_qlen()
375 dev->tx_qlen = 5 * MAX_QUEUE_MEMORY / dev->hard_mtu; in usbnet_update_max_qlen()
379 dev->rx_qlen = dev->tx_qlen = 4; in usbnet_update_max_qlen()
385 /*-------------------------------------------------------------------------
389 *-------------------------------------------------------------------------*/
394 int ll_mtu = new_mtu + net->hard_header_len; in usbnet_change_mtu()
395 int old_hard_mtu = dev->hard_mtu; in usbnet_change_mtu()
396 int old_rx_urb_size = dev->rx_urb_size; in usbnet_change_mtu()
398 // no second zero-length packet read wanted after mtu-sized packets in usbnet_change_mtu()
399 if ((ll_mtu % dev->maxpacket) == 0) in usbnet_change_mtu()
400 return -EDOM; in usbnet_change_mtu()
401 net->mtu = new_mtu; in usbnet_change_mtu()
403 dev->hard_mtu = net->mtu + net->hard_header_len; in usbnet_change_mtu()
404 if (dev->rx_urb_size == old_hard_mtu) { in usbnet_change_mtu()
405 dev->rx_urb_size = dev->hard_mtu; in usbnet_change_mtu()
406 if (dev->rx_urb_size > old_rx_urb_size) { in usbnet_change_mtu()
420 /* The caller must hold list->lock */
424 struct skb_data *entry = (struct skb_data *) newsk->cb; in __usbnet_queue_skb()
427 entry->state = state; in __usbnet_queue_skb()
430 /*-------------------------------------------------------------------------*/
441 struct skb_data *entry = (struct skb_data *) skb->cb; in defer_bh()
443 spin_lock_irqsave(&list->lock, flags); in defer_bh()
444 old_state = entry->state; in defer_bh()
445 entry->state = state; in defer_bh()
448 /* defer_bh() is never called with list == &dev->done. in defer_bh()
450 * dev->done.lock here with list->lock held. in defer_bh()
452 spin_lock_nested(&dev->done.lock, SINGLE_DEPTH_NESTING); in defer_bh()
454 __skb_queue_tail(&dev->done, skb); in defer_bh()
455 if (dev->done.qlen == 1) in defer_bh()
456 tasklet_schedule(&dev->bh); in defer_bh()
457 spin_unlock(&dev->done.lock); in defer_bh()
458 spin_unlock_irqrestore(&list->lock, flags); in defer_bh()
469 set_bit (work, &dev->flags); in usbnet_defer_kevent()
470 if (!schedule_work (&dev->kevent)) in usbnet_defer_kevent()
471 netdev_dbg(dev->net, "kevent %s may have been dropped\n", usbnet_event_names[work]); in usbnet_defer_kevent()
473 netdev_dbg(dev->net, "kevent %s scheduled\n", usbnet_event_names[work]); in usbnet_defer_kevent()
477 /*-------------------------------------------------------------------------*/
487 size_t size = dev->rx_urb_size; in rx_submit()
490 if (test_bit(EVENT_RX_KILL, &dev->flags)) { in rx_submit()
492 return -ENOLINK; in rx_submit()
495 if (test_bit(EVENT_NO_IP_ALIGN, &dev->flags)) in rx_submit()
496 skb = __netdev_alloc_skb(dev->net, size, flags); in rx_submit()
498 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags); in rx_submit()
500 netif_dbg(dev, rx_err, dev->net, "no rx skb\n"); in rx_submit()
503 return -ENOMEM; in rx_submit()
506 entry = (struct skb_data *) skb->cb; in rx_submit()
507 entry->urb = urb; in rx_submit()
508 entry->dev = dev; in rx_submit()
509 entry->length = 0; in rx_submit()
511 usb_fill_bulk_urb (urb, dev->udev, dev->in, in rx_submit()
512 skb->data, size, rx_complete, skb); in rx_submit()
514 spin_lock_irqsave (&dev->rxq.lock, lockflags); in rx_submit()
516 if (netif_running (dev->net) && in rx_submit()
517 netif_device_present (dev->net) && in rx_submit()
518 test_bit(EVENT_DEV_OPEN, &dev->flags) && in rx_submit()
519 !test_bit (EVENT_RX_HALT, &dev->flags) && in rx_submit()
520 !test_bit (EVENT_DEV_ASLEEP, &dev->flags)) { in rx_submit()
522 case -EPIPE: in rx_submit()
525 case -ENOMEM: in rx_submit()
528 case -ENODEV: in rx_submit()
529 netif_dbg(dev, ifdown, dev->net, "device gone\n"); in rx_submit()
530 netif_device_detach (dev->net); in rx_submit()
532 case -EHOSTUNREACH: in rx_submit()
533 retval = -ENOLINK; in rx_submit()
536 netif_dbg(dev, rx_err, dev->net, in rx_submit()
538 tasklet_schedule (&dev->bh); in rx_submit()
541 __usbnet_queue_skb(&dev->rxq, skb, rx_start); in rx_submit()
544 netif_dbg(dev, ifdown, dev->net, "rx: stopped\n"); in rx_submit()
545 retval = -ENOLINK; in rx_submit()
547 spin_unlock_irqrestore (&dev->rxq.lock, lockflags); in rx_submit()
556 /*-------------------------------------------------------------------------*/
560 if (dev->driver_info->rx_fixup && in rx_process()
561 !dev->driver_info->rx_fixup (dev, skb)) { in rx_process()
563 if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE)) in rx_process()
564 dev->net->stats.rx_errors++; in rx_process()
570 if (dev->driver_info->flags & FLAG_MULTI_PACKET) in rx_process()
573 if (skb->len < ETH_HLEN) { in rx_process()
574 dev->net->stats.rx_errors++; in rx_process()
575 dev->net->stats.rx_length_errors++; in rx_process()
576 netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len); in rx_process()
583 skb_queue_tail(&dev->done, skb); in rx_process()
586 /*-------------------------------------------------------------------------*/
590 struct sk_buff *skb = (struct sk_buff *) urb->context; in rx_complete()
591 struct skb_data *entry = (struct skb_data *) skb->cb; in rx_complete()
592 struct usbnet *dev = entry->dev; in rx_complete()
593 int urb_status = urb->status; in rx_complete()
596 skb_put (skb, urb->actual_length); in rx_complete()
598 entry->urb = NULL; in rx_complete()
610 case -EPIPE: in rx_complete()
611 dev->net->stats.rx_errors++; in rx_complete()
615 /* software-driven interface shutdown */ in rx_complete()
616 case -ECONNRESET: /* async unlink */ in rx_complete()
617 case -ESHUTDOWN: /* hardware gone */ in rx_complete()
618 netif_dbg(dev, ifdown, dev->net, in rx_complete()
624 * so we still recover when the fault isn't a hub_wq delay. in rx_complete()
626 case -EPROTO: in rx_complete()
627 case -ETIME: in rx_complete()
628 case -EILSEQ: in rx_complete()
629 dev->net->stats.rx_errors++; in rx_complete()
630 if (!timer_pending (&dev->delay)) { in rx_complete()
631 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES); in rx_complete()
632 netif_dbg(dev, link, dev->net, in rx_complete()
637 entry->urb = urb; in rx_complete()
642 case -EOVERFLOW: in rx_complete()
643 dev->net->stats.rx_over_errors++; in rx_complete()
648 dev->net->stats.rx_errors++; in rx_complete()
649 netif_dbg(dev, rx_err, dev->net, "rx status %d\n", urb_status); in rx_complete()
654 if (++dev->pkt_cnt > 30) { in rx_complete()
655 dev->pkt_cnt = 0; in rx_complete()
656 dev->pkt_err = 0; in rx_complete()
659 dev->pkt_err++; in rx_complete()
660 if (dev->pkt_err > 20) in rx_complete()
661 set_bit(EVENT_RX_KILL, &dev->flags); in rx_complete()
664 state = defer_bh(dev, skb, &dev->rxq, state); in rx_complete()
667 if (netif_running (dev->net) && in rx_complete()
668 !test_bit (EVENT_RX_HALT, &dev->flags) && in rx_complete()
671 usb_mark_last_busy(dev->udev); in rx_complete()
676 netif_dbg(dev, rx_err, dev->net, "no read resubmitted\n"); in rx_complete()
679 /*-------------------------------------------------------------------------*/
682 set_bit(EVENT_RX_PAUSED, &dev->flags); in usbnet_pause_rx()
684 netif_dbg(dev, rx_status, dev->net, "paused rx queue enabled\n"); in usbnet_pause_rx()
693 clear_bit(EVENT_RX_PAUSED, &dev->flags); in usbnet_resume_rx()
695 while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) { in usbnet_resume_rx()
700 tasklet_schedule(&dev->bh); in usbnet_resume_rx()
702 netif_dbg(dev, rx_status, dev->net, in usbnet_resume_rx()
709 skb_queue_purge(&dev->rxq_pause); in usbnet_purge_paused_rxq()
713 /*-------------------------------------------------------------------------*/
723 spin_lock_irqsave (&q->lock, flags); in unlink_urbs()
730 entry = (struct skb_data *) skb->cb; in unlink_urbs()
731 if (entry->state != unlink_start) in unlink_urbs()
736 entry->state = unlink_start; in unlink_urbs()
737 urb = entry->urb; in unlink_urbs()
742 * use-after-free problem inside usb_unlink_urb since in unlink_urbs()
747 spin_unlock_irqrestore(&q->lock, flags); in unlink_urbs()
748 // during some PM-driven resume scenarios, in unlink_urbs()
751 if (retval != -EINPROGRESS && retval != 0) in unlink_urbs()
752 netdev_dbg(dev->net, "unlink urb err, %d\n", retval); in unlink_urbs()
756 spin_lock_irqsave(&q->lock, flags); in unlink_urbs()
758 spin_unlock_irqrestore (&q->lock, flags); in unlink_urbs()
767 if (netif_running(dev->net)) { in usbnet_unlink_rx_urbs()
768 (void) unlink_urbs (dev, &dev->rxq); in usbnet_unlink_rx_urbs()
769 tasklet_schedule(&dev->bh); in usbnet_unlink_rx_urbs()
774 /*-------------------------------------------------------------------------*/
780 spin_lock_irqsave(&q->lock, flags); in wait_skb_queue_empty()
782 spin_unlock_irqrestore(&q->lock, flags); in wait_skb_queue_empty()
785 spin_lock_irqsave(&q->lock, flags); in wait_skb_queue_empty()
787 spin_unlock_irqrestore(&q->lock, flags); in wait_skb_queue_empty()
797 add_wait_queue(&dev->wait, &wait); in usbnet_terminate_urbs()
799 temp = unlink_urbs(dev, &dev->txq) + in usbnet_terminate_urbs()
800 unlink_urbs(dev, &dev->rxq); in usbnet_terminate_urbs()
803 wait_skb_queue_empty(&dev->rxq); in usbnet_terminate_urbs()
804 wait_skb_queue_empty(&dev->txq); in usbnet_terminate_urbs()
805 wait_skb_queue_empty(&dev->done); in usbnet_terminate_urbs()
806 netif_dbg(dev, ifdown, dev->net, in usbnet_terminate_urbs()
809 remove_wait_queue(&dev->wait, &wait); in usbnet_terminate_urbs()
815 const struct driver_info *info = dev->driver_info; in usbnet_stop()
818 clear_bit(EVENT_DEV_OPEN, &dev->flags); in usbnet_stop()
821 netif_info(dev, ifdown, dev->net, in usbnet_stop()
823 net->stats.rx_packets, net->stats.tx_packets, in usbnet_stop()
824 net->stats.rx_errors, net->stats.tx_errors); in usbnet_stop()
827 pm = usb_autopm_get_interface(dev->intf); in usbnet_stop()
830 if (info->stop) { in usbnet_stop()
831 retval = info->stop(dev); in usbnet_stop()
833 netif_info(dev, ifdown, dev->net, in usbnet_stop()
834 "stop fail (%d) usbnet usb-%s-%s, %s\n", in usbnet_stop()
836 dev->udev->bus->bus_name, dev->udev->devpath, in usbnet_stop()
837 info->description); in usbnet_stop()
840 if (!(info->flags & FLAG_AVOID_UNLINK_URBS)) in usbnet_stop()
847 mpn = !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags); in usbnet_stop()
850 dev->flags = 0; in usbnet_stop()
851 del_timer_sync (&dev->delay); in usbnet_stop()
852 tasklet_kill (&dev->bh); in usbnet_stop()
853 cancel_work_sync(&dev->kevent); in usbnet_stop()
855 usb_autopm_put_interface(dev->intf); in usbnet_stop()
857 if (info->manage_power && mpn) in usbnet_stop()
858 info->manage_power(dev, 0); in usbnet_stop()
860 usb_autopm_put_interface(dev->intf); in usbnet_stop()
866 /*-------------------------------------------------------------------------*/
876 const struct driver_info *info = dev->driver_info; in usbnet_open()
878 if ((retval = usb_autopm_get_interface(dev->intf)) < 0) { in usbnet_open()
879 netif_info(dev, ifup, dev->net, in usbnet_open()
880 "resumption fail (%d) usbnet usb-%s-%s, %s\n", in usbnet_open()
882 dev->udev->bus->bus_name, in usbnet_open()
883 dev->udev->devpath, in usbnet_open()
884 info->description); in usbnet_open()
889 if (info->reset && (retval = info->reset (dev)) < 0) { in usbnet_open()
890 netif_info(dev, ifup, dev->net, in usbnet_open()
891 "open reset fail (%d) usbnet usb-%s-%s, %s\n", in usbnet_open()
893 dev->udev->bus->bus_name, in usbnet_open()
894 dev->udev->devpath, in usbnet_open()
895 info->description); in usbnet_open()
903 if (info->check_connect && (retval = info->check_connect (dev)) < 0) { in usbnet_open()
904 netif_err(dev, ifup, dev->net, "can't open; %d\n", retval); in usbnet_open()
909 if (dev->interrupt) { in usbnet_open()
912 netif_err(dev, ifup, dev->net, in usbnet_open()
918 set_bit(EVENT_DEV_OPEN, &dev->flags); in usbnet_open()
920 netif_info(dev, ifup, dev->net, in usbnet_open()
923 dev->net->mtu, in usbnet_open()
924 (dev->driver_info->flags & FLAG_FRAMING_NC) ? "NetChip" : in usbnet_open()
925 (dev->driver_info->flags & FLAG_FRAMING_GL) ? "GeneSys" : in usbnet_open()
926 (dev->driver_info->flags & FLAG_FRAMING_Z) ? "Zaurus" : in usbnet_open()
927 (dev->driver_info->flags & FLAG_FRAMING_RN) ? "RNDIS" : in usbnet_open()
928 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" : in usbnet_open()
932 dev->pkt_cnt = 0; in usbnet_open()
933 dev->pkt_err = 0; in usbnet_open()
934 clear_bit(EVENT_RX_KILL, &dev->flags); in usbnet_open()
936 // delay posting reads until we're fully open in usbnet_open()
937 tasklet_schedule (&dev->bh); in usbnet_open()
938 if (info->manage_power) { in usbnet_open()
939 retval = info->manage_power(dev, 1); in usbnet_open()
942 set_bit(EVENT_NO_RUNTIME_PM, &dev->flags); in usbnet_open()
944 usb_autopm_put_interface(dev->intf); in usbnet_open()
949 usb_autopm_put_interface(dev->intf); in usbnet_open()
955 /*-------------------------------------------------------------------------*/
969 if (!dev->mii.mdio_read) in usbnet_get_link_ksettings_mii()
970 return -EOPNOTSUPP; in usbnet_get_link_ksettings_mii()
972 mii_ethtool_get_link_ksettings(&dev->mii, cmd); in usbnet_get_link_ksettings_mii()
988 if (dev->rx_speed != SPEED_UNSET) in usbnet_get_link_ksettings_internal()
989 cmd->base.speed = dev->rx_speed / 1000000; in usbnet_get_link_ksettings_internal()
990 else if (dev->tx_speed != SPEED_UNSET) in usbnet_get_link_ksettings_internal()
991 cmd->base.speed = dev->tx_speed / 1000000; in usbnet_get_link_ksettings_internal()
993 cmd->base.speed = SPEED_UNKNOWN; in usbnet_get_link_ksettings_internal()
1005 if (!dev->mii.mdio_write) in usbnet_set_link_ksettings_mii()
1006 return -EOPNOTSUPP; in usbnet_set_link_ksettings_mii()
1008 retval = mii_ethtool_set_link_ksettings(&dev->mii, cmd); in usbnet_set_link_ksettings_mii()
1011 if (dev->driver_info->link_reset) in usbnet_set_link_ksettings_mii()
1012 dev->driver_info->link_reset(dev); in usbnet_set_link_ksettings_mii()
1026 if (dev->driver_info->check_connect) in usbnet_get_link()
1027 return dev->driver_info->check_connect (dev) == 0; in usbnet_get_link()
1030 if (dev->mii.mdio_read) in usbnet_get_link()
1031 return mii_link_ok(&dev->mii); in usbnet_get_link()
1042 if (!dev->mii.mdio_write) in usbnet_nway_reset()
1043 return -EOPNOTSUPP; in usbnet_nway_reset()
1045 return mii_nway_restart(&dev->mii); in usbnet_nway_reset()
1053 strscpy(info->driver, dev->driver_name, sizeof(info->driver)); in usbnet_get_drvinfo()
1054 strscpy(info->fw_version, dev->driver_info->description, in usbnet_get_drvinfo()
1055 sizeof(info->fw_version)); in usbnet_get_drvinfo()
1056 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); in usbnet_get_drvinfo()
1064 return dev->msg_enable; in usbnet_get_msglevel()
1072 dev->msg_enable = level; in usbnet_set_msglevel()
1088 /*-------------------------------------------------------------------------*/
1092 if (!test_bit(EVENT_DEV_OPEN, &dev->flags)) in __handle_link_change()
1095 if (!netif_carrier_ok(dev->net)) { in __handle_link_change()
1097 unlink_urbs(dev, &dev->rxq); in __handle_link_change()
1105 tasklet_schedule(&dev->bh); in __handle_link_change()
1111 clear_bit(EVENT_LINK_CHANGE, &dev->flags); in __handle_link_change()
1124 if (dev->driver_info->set_rx_mode) in __handle_set_rx_mode()
1125 (dev->driver_info->set_rx_mode)(dev); in __handle_set_rx_mode()
1127 clear_bit(EVENT_SET_RX_MODE, &dev->flags); in __handle_set_rx_mode()
1143 if (test_bit (EVENT_TX_HALT, &dev->flags)) { in usbnet_deferred_kevent()
1144 unlink_urbs (dev, &dev->txq); in usbnet_deferred_kevent()
1145 status = usb_autopm_get_interface(dev->intf); in usbnet_deferred_kevent()
1148 status = usb_clear_halt (dev->udev, dev->out); in usbnet_deferred_kevent()
1149 usb_autopm_put_interface(dev->intf); in usbnet_deferred_kevent()
1151 status != -EPIPE && in usbnet_deferred_kevent()
1152 status != -ESHUTDOWN) { in usbnet_deferred_kevent()
1155 netdev_err(dev->net, "can't clear tx halt, status %d\n", in usbnet_deferred_kevent()
1158 clear_bit (EVENT_TX_HALT, &dev->flags); in usbnet_deferred_kevent()
1159 if (status != -ESHUTDOWN) in usbnet_deferred_kevent()
1160 netif_wake_queue (dev->net); in usbnet_deferred_kevent()
1163 if (test_bit (EVENT_RX_HALT, &dev->flags)) { in usbnet_deferred_kevent()
1164 unlink_urbs (dev, &dev->rxq); in usbnet_deferred_kevent()
1165 status = usb_autopm_get_interface(dev->intf); in usbnet_deferred_kevent()
1168 status = usb_clear_halt (dev->udev, dev->in); in usbnet_deferred_kevent()
1169 usb_autopm_put_interface(dev->intf); in usbnet_deferred_kevent()
1171 status != -EPIPE && in usbnet_deferred_kevent()
1172 status != -ESHUTDOWN) { in usbnet_deferred_kevent()
1175 netdev_err(dev->net, "can't clear rx halt, status %d\n", in usbnet_deferred_kevent()
1178 clear_bit (EVENT_RX_HALT, &dev->flags); in usbnet_deferred_kevent()
1179 tasklet_schedule (&dev->bh); in usbnet_deferred_kevent()
1184 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) { in usbnet_deferred_kevent()
1188 if (netif_running (dev->net)) in usbnet_deferred_kevent()
1191 clear_bit (EVENT_RX_MEMORY, &dev->flags); in usbnet_deferred_kevent()
1193 clear_bit (EVENT_RX_MEMORY, &dev->flags); in usbnet_deferred_kevent()
1194 status = usb_autopm_get_interface(dev->intf); in usbnet_deferred_kevent()
1199 if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK) in usbnet_deferred_kevent()
1201 usb_autopm_put_interface(dev->intf); in usbnet_deferred_kevent()
1204 tasklet_schedule (&dev->bh); in usbnet_deferred_kevent()
1208 if (test_bit (EVENT_LINK_RESET, &dev->flags)) { in usbnet_deferred_kevent()
1209 const struct driver_info *info = dev->driver_info; in usbnet_deferred_kevent()
1212 clear_bit (EVENT_LINK_RESET, &dev->flags); in usbnet_deferred_kevent()
1213 status = usb_autopm_get_interface(dev->intf); in usbnet_deferred_kevent()
1216 if(info->link_reset && (retval = info->link_reset(dev)) < 0) { in usbnet_deferred_kevent()
1217 usb_autopm_put_interface(dev->intf); in usbnet_deferred_kevent()
1219 netdev_info(dev->net, "link reset failed (%d) usbnet usb-%s-%s, %s\n", in usbnet_deferred_kevent()
1221 dev->udev->bus->bus_name, in usbnet_deferred_kevent()
1222 dev->udev->devpath, in usbnet_deferred_kevent()
1223 info->description); in usbnet_deferred_kevent()
1225 usb_autopm_put_interface(dev->intf); in usbnet_deferred_kevent()
1232 if (test_bit (EVENT_LINK_CHANGE, &dev->flags)) in usbnet_deferred_kevent()
1235 if (test_bit (EVENT_SET_RX_MODE, &dev->flags)) in usbnet_deferred_kevent()
1239 if (dev->flags) in usbnet_deferred_kevent()
1240 netdev_dbg(dev->net, "kevent done, flags = 0x%lx\n", dev->flags); in usbnet_deferred_kevent()
1243 /*-------------------------------------------------------------------------*/
1247 struct sk_buff *skb = (struct sk_buff *) urb->context; in tx_complete()
1248 struct skb_data *entry = (struct skb_data *) skb->cb; in tx_complete()
1249 struct usbnet *dev = entry->dev; in tx_complete()
1251 if (urb->status == 0) { in tx_complete()
1252 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); in tx_complete()
1255 flags = u64_stats_update_begin_irqsave(&stats64->syncp); in tx_complete()
1256 u64_stats_add(&stats64->tx_packets, entry->packets); in tx_complete()
1257 u64_stats_add(&stats64->tx_bytes, entry->length); in tx_complete()
1258 u64_stats_update_end_irqrestore(&stats64->syncp, flags); in tx_complete()
1260 dev->net->stats.tx_errors++; in tx_complete()
1262 switch (urb->status) { in tx_complete()
1263 case -EPIPE: in tx_complete()
1267 /* software-driven interface shutdown */ in tx_complete()
1268 case -ECONNRESET: // async unlink in tx_complete()
1269 case -ESHUTDOWN: // hardware gone in tx_complete()
1275 case -EPROTO: in tx_complete()
1276 case -ETIME: in tx_complete()
1277 case -EILSEQ: in tx_complete()
1278 usb_mark_last_busy(dev->udev); in tx_complete()
1279 if (!timer_pending (&dev->delay)) { in tx_complete()
1280 mod_timer (&dev->delay, in tx_complete()
1282 netif_dbg(dev, link, dev->net, in tx_complete()
1283 "tx throttle %d\n", urb->status); in tx_complete()
1285 netif_stop_queue (dev->net); in tx_complete()
1288 netif_dbg(dev, tx_err, dev->net, in tx_complete()
1289 "tx err %d\n", entry->urb->status); in tx_complete()
1294 usb_autopm_put_interface_async(dev->intf); in tx_complete()
1295 (void) defer_bh(dev, skb, &dev->txq, tx_done); in tx_complete()
1298 /*-------------------------------------------------------------------------*/
1304 unlink_urbs (dev, &dev->txq); in usbnet_tx_timeout()
1305 tasklet_schedule (&dev->bh); in usbnet_tx_timeout()
1310 if (dev->driver_info->recover) in usbnet_tx_timeout()
1311 (dev->driver_info->recover)(dev); in usbnet_tx_timeout()
1315 /*-------------------------------------------------------------------------*/
1322 num_sgs = skb_shinfo(skb)->nr_frags + 1; in build_dma_sg()
1327 urb->sg = kmalloc_array(num_sgs + 1, sizeof(struct scatterlist), in build_dma_sg()
1329 if (!urb->sg) in build_dma_sg()
1330 return -ENOMEM; in build_dma_sg()
1332 urb->num_sgs = num_sgs; in build_dma_sg()
1333 sg_init_table(urb->sg, urb->num_sgs + 1); in build_dma_sg()
1335 sg_set_buf(&urb->sg[s++], skb->data, skb_headlen(skb)); in build_dma_sg()
1338 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in build_dma_sg()
1339 skb_frag_t *f = &skb_shinfo(skb)->frags[i]; in build_dma_sg()
1342 sg_set_page(&urb->sg[i + s], skb_frag_page(f), skb_frag_size(f), in build_dma_sg()
1345 urb->transfer_buffer_length = total_len; in build_dma_sg()
1357 const struct driver_info *info = dev->driver_info; in usbnet_start_xmit()
1364 // some devices want funky USB-level framing, for in usbnet_start_xmit()
1366 if (info->tx_fixup) { in usbnet_start_xmit()
1367 skb = info->tx_fixup (dev, skb, GFP_ATOMIC); in usbnet_start_xmit()
1370 if (info->flags & FLAG_MULTI_PACKET) in usbnet_start_xmit()
1372 netif_dbg(dev, tx_err, dev->net, "can't tx_fixup skb\n"); in usbnet_start_xmit()
1378 netif_dbg(dev, tx_err, dev->net, "no urb\n"); in usbnet_start_xmit()
1382 entry = (struct skb_data *) skb->cb; in usbnet_start_xmit()
1383 entry->urb = urb; in usbnet_start_xmit()
1384 entry->dev = dev; in usbnet_start_xmit()
1386 usb_fill_bulk_urb (urb, dev->udev, dev->out, in usbnet_start_xmit()
1387 skb->data, skb->len, tx_complete, skb); in usbnet_start_xmit()
1388 if (dev->can_dma_sg) { in usbnet_start_xmit()
1392 length = urb->transfer_buffer_length; in usbnet_start_xmit()
1395 * NOTE: strictly conforming cdc-ether devices should expect in usbnet_start_xmit()
1396 * the ZLP here, but ignore the one-byte packet. in usbnet_start_xmit()
1401 if (length % dev->maxpacket == 0) { in usbnet_start_xmit()
1402 if (!(info->flags & FLAG_SEND_ZLP)) { in usbnet_start_xmit()
1403 if (!(info->flags & FLAG_MULTI_PACKET)) { in usbnet_start_xmit()
1405 if (skb_tailroom(skb) && !urb->num_sgs) { in usbnet_start_xmit()
1406 skb->data[skb->len] = 0; in usbnet_start_xmit()
1408 } else if (urb->num_sgs) in usbnet_start_xmit()
1409 sg_set_buf(&urb->sg[urb->num_sgs++], in usbnet_start_xmit()
1410 dev->padding_pkt, 1); in usbnet_start_xmit()
1413 urb->transfer_flags |= URB_ZERO_PACKET; in usbnet_start_xmit()
1415 urb->transfer_buffer_length = length; in usbnet_start_xmit()
1417 if (info->flags & FLAG_MULTI_PACKET) { in usbnet_start_xmit()
1422 entry->length += length; in usbnet_start_xmit()
1423 if (WARN_ON_ONCE(entry->length <= 0)) in usbnet_start_xmit()
1424 entry->length = length; in usbnet_start_xmit()
1429 spin_lock_irqsave(&dev->txq.lock, flags); in usbnet_start_xmit()
1430 retval = usb_autopm_get_interface_async(dev->intf); in usbnet_start_xmit()
1432 spin_unlock_irqrestore(&dev->txq.lock, flags); in usbnet_start_xmit()
1436 usb_autopm_put_interface_async(dev->intf); in usbnet_start_xmit()
1437 spin_unlock_irqrestore(&dev->txq.lock, flags); in usbnet_start_xmit()
1443 if (test_bit(EVENT_DEV_ASLEEP, &dev->flags)) { in usbnet_start_xmit()
1445 usb_anchor_urb(urb, &dev->deferred); in usbnet_start_xmit()
1449 spin_unlock_irqrestore(&dev->txq.lock, flags); in usbnet_start_xmit()
1450 netdev_dbg(dev->net, "Delaying transmission for resumption\n"); in usbnet_start_xmit()
1456 case -EPIPE: in usbnet_start_xmit()
1459 usb_autopm_put_interface_async(dev->intf); in usbnet_start_xmit()
1462 usb_autopm_put_interface_async(dev->intf); in usbnet_start_xmit()
1463 netif_dbg(dev, tx_err, dev->net, in usbnet_start_xmit()
1468 __usbnet_queue_skb(&dev->txq, skb, tx_start); in usbnet_start_xmit()
1469 if (dev->txq.qlen >= TX_QLEN (dev)) in usbnet_start_xmit()
1472 spin_unlock_irqrestore (&dev->txq.lock, flags); in usbnet_start_xmit()
1475 netif_dbg(dev, tx_err, dev->net, "drop, code %d\n", retval); in usbnet_start_xmit()
1477 dev->net->stats.tx_dropped++; in usbnet_start_xmit()
1482 kfree(urb->sg); in usbnet_start_xmit()
1486 netif_dbg(dev, tx_queued, dev->net, in usbnet_start_xmit()
1487 "> tx, len %u, type 0x%x\n", length, skb->protocol); in usbnet_start_xmit()
1502 for (i = 0; i < 10 && dev->rxq.qlen < RX_QLEN(dev); i++) { in rx_alloc_submit()
1509 ret = -ENOMEM; in rx_alloc_submit()
1517 /*-------------------------------------------------------------------------*/
1523 struct usbnet *dev = from_timer(dev, t, delay); in usbnet_bh()
1527 while ((skb = skb_dequeue (&dev->done))) { in usbnet_bh()
1528 entry = (struct skb_data *) skb->cb; in usbnet_bh()
1529 switch (entry->state) { in usbnet_bh()
1531 entry->state = rx_cleanup; in usbnet_bh()
1535 kfree(entry->urb->sg); in usbnet_bh()
1538 usb_free_urb (entry->urb); in usbnet_bh()
1542 netdev_dbg(dev->net, "bogus skb state %d\n", entry->state); in usbnet_bh()
1547 clear_bit(EVENT_RX_KILL, &dev->flags); in usbnet_bh()
1552 if (waitqueue_active(&dev->wait)) { in usbnet_bh()
1553 if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0) in usbnet_bh()
1554 wake_up_all(&dev->wait); in usbnet_bh()
1557 } else if (netif_running (dev->net) && in usbnet_bh()
1558 netif_device_present (dev->net) && in usbnet_bh()
1559 netif_carrier_ok(dev->net) && in usbnet_bh()
1560 !timer_pending(&dev->delay) && in usbnet_bh()
1561 !test_bit(EVENT_RX_PAUSED, &dev->flags) && in usbnet_bh()
1562 !test_bit(EVENT_RX_HALT, &dev->flags)) { in usbnet_bh()
1563 int temp = dev->rxq.qlen; in usbnet_bh()
1566 if (rx_alloc_submit(dev, GFP_ATOMIC) == -ENOLINK) in usbnet_bh()
1568 if (temp != dev->rxq.qlen) in usbnet_bh()
1569 netif_dbg(dev, link, dev->net, in usbnet_bh()
1570 "rxqlen %d --> %d\n", in usbnet_bh()
1571 temp, dev->rxq.qlen); in usbnet_bh()
1572 if (dev->rxq.qlen < RX_QLEN(dev)) in usbnet_bh()
1573 tasklet_schedule (&dev->bh); in usbnet_bh()
1575 if (dev->txq.qlen < TX_QLEN (dev)) in usbnet_bh()
1576 netif_wake_queue (dev->net); in usbnet_bh()
1584 usbnet_bh(&dev->delay); in usbnet_bh_tasklet()
1588 /*-------------------------------------------------------------------------
1592 *-------------------------------------------------------------------------*/
1610 netif_info(dev, probe, dev->net, "unregister '%s' usb-%s-%s, %s\n", in usbnet_disconnect()
1611 intf->dev.driver->name, in usbnet_disconnect()
1612 xdev->bus->bus_name, xdev->devpath, in usbnet_disconnect()
1613 dev->driver_info->description); in usbnet_disconnect()
1615 net = dev->net; in usbnet_disconnect()
1618 while ((urb = usb_get_from_anchor(&dev->deferred))) { in usbnet_disconnect()
1619 dev_kfree_skb(urb->context); in usbnet_disconnect()
1620 kfree(urb->sg); in usbnet_disconnect()
1624 if (dev->driver_info->unbind) in usbnet_disconnect()
1625 dev->driver_info->unbind(dev, intf); in usbnet_disconnect()
1627 usb_kill_urb(dev->interrupt); in usbnet_disconnect()
1628 usb_free_urb(dev->interrupt); in usbnet_disconnect()
1629 kfree(dev->padding_pkt); in usbnet_disconnect()
1631 free_percpu(net->tstats); in usbnet_disconnect()
1648 /*-------------------------------------------------------------------------*/
1670 struct usb_driver *driver = to_usb_driver(udev->dev.driver); in usbnet_probe()
1676 if (!driver->supports_autosuspend) { in usbnet_probe()
1677 driver->supports_autosuspend = 1; in usbnet_probe()
1678 pm_runtime_enable(&udev->dev); in usbnet_probe()
1681 name = udev->dev.driver->name; in usbnet_probe()
1682 info = (const struct driver_info *) prod->driver_info; in usbnet_probe()
1684 dev_dbg (&udev->dev, "blacklisted by %s\n", name); in usbnet_probe()
1685 return -ENODEV; in usbnet_probe()
1688 interface = udev->cur_altsetting; in usbnet_probe()
1690 status = -ENOMEM; in usbnet_probe()
1698 SET_NETDEV_DEV(net, &udev->dev); in usbnet_probe()
1701 dev->udev = xdev; in usbnet_probe()
1702 dev->intf = udev; in usbnet_probe()
1703 dev->driver_info = info; in usbnet_probe()
1704 dev->driver_name = name; in usbnet_probe()
1705 dev->rx_speed = SPEED_UNSET; in usbnet_probe()
1706 dev->tx_speed = SPEED_UNSET; in usbnet_probe()
1708 net->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); in usbnet_probe()
1709 if (!net->tstats) in usbnet_probe()
1712 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV in usbnet_probe()
1714 init_waitqueue_head(&dev->wait); in usbnet_probe()
1715 skb_queue_head_init (&dev->rxq); in usbnet_probe()
1716 skb_queue_head_init (&dev->txq); in usbnet_probe()
1717 skb_queue_head_init (&dev->done); in usbnet_probe()
1718 skb_queue_head_init(&dev->rxq_pause); in usbnet_probe()
1719 tasklet_setup(&dev->bh, usbnet_bh_tasklet); in usbnet_probe()
1720 INIT_WORK (&dev->kevent, usbnet_deferred_kevent); in usbnet_probe()
1721 init_usb_anchor(&dev->deferred); in usbnet_probe()
1722 timer_setup(&dev->delay, usbnet_bh, 0); in usbnet_probe()
1723 mutex_init (&dev->phy_mutex); in usbnet_probe()
1724 mutex_init(&dev->interrupt_mutex); in usbnet_probe()
1725 dev->interrupt_count = 0; in usbnet_probe()
1727 dev->net = net; in usbnet_probe()
1728 strscpy(net->name, "usb%d", sizeof(net->name)); in usbnet_probe()
1734 dev->hard_mtu = net->mtu + net->hard_header_len; in usbnet_probe()
1735 net->min_mtu = 0; in usbnet_probe()
1736 net->max_mtu = ETH_MAX_MTU; in usbnet_probe()
1738 net->netdev_ops = &usbnet_netdev_ops; in usbnet_probe()
1739 net->watchdog_timeo = TX_TIMEOUT_JIFFIES; in usbnet_probe()
1740 net->ethtool_ops = &usbnet_ethtool_ops; in usbnet_probe()
1742 // allow device-specific bind/init procedures in usbnet_probe()
1743 // NOTE net->name still not usable ... in usbnet_probe()
1744 if (info->bind) { in usbnet_probe()
1745 status = info->bind (dev, udev); in usbnet_probe()
1749 // heuristic: "usb%d" for links we know are two-host, in usbnet_probe()
1752 if ((dev->driver_info->flags & FLAG_ETHER) != 0 && in usbnet_probe()
1753 ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 || in usbnet_probe()
1754 (net->dev_addr [0] & 0x02) == 0)) in usbnet_probe()
1755 strscpy(net->name, "eth%d", sizeof(net->name)); in usbnet_probe()
1757 if ((dev->driver_info->flags & FLAG_WLAN) != 0) in usbnet_probe()
1758 strscpy(net->name, "wlan%d", sizeof(net->name)); in usbnet_probe()
1760 if ((dev->driver_info->flags & FLAG_WWAN) != 0) in usbnet_probe()
1761 strscpy(net->name, "wwan%d", sizeof(net->name)); in usbnet_probe()
1764 if ((dev->driver_info->flags & FLAG_NOARP) != 0) in usbnet_probe()
1765 net->flags |= IFF_NOARP; in usbnet_probe()
1768 if (net->mtu > (dev->hard_mtu - net->hard_header_len)) in usbnet_probe()
1769 net->mtu = dev->hard_mtu - net->hard_header_len; in usbnet_probe()
1770 } else if (!info->in || !info->out) in usbnet_probe()
1773 dev->in = usb_rcvbulkpipe (xdev, info->in); in usbnet_probe()
1774 dev->out = usb_sndbulkpipe (xdev, info->out); in usbnet_probe()
1775 if (!(info->flags & FLAG_NO_SETINT)) in usbnet_probe()
1777 interface->desc.bInterfaceNumber, in usbnet_probe()
1778 interface->desc.bAlternateSetting); in usbnet_probe()
1783 if (status >= 0 && dev->status) in usbnet_probe()
1788 if (!dev->rx_urb_size) in usbnet_probe()
1789 dev->rx_urb_size = dev->hard_mtu; in usbnet_probe()
1790 dev->maxpacket = usb_maxpacket(dev->udev, dev->out); in usbnet_probe()
1791 if (dev->maxpacket == 0) { in usbnet_probe()
1793 status = -ENODEV; in usbnet_probe()
1798 if (ether_addr_equal(net->dev_addr, node_id)) in usbnet_probe()
1799 net->addr_assign_type = NET_ADDR_RANDOM; in usbnet_probe()
1801 if ((dev->driver_info->flags & FLAG_WLAN) != 0) in usbnet_probe()
1803 if ((dev->driver_info->flags & FLAG_WWAN) != 0) in usbnet_probe()
1809 if (dev->can_dma_sg && !(info->flags & FLAG_SEND_ZLP) && in usbnet_probe()
1810 !(info->flags & FLAG_MULTI_PACKET)) { in usbnet_probe()
1811 dev->padding_pkt = kzalloc(1, GFP_KERNEL); in usbnet_probe()
1812 if (!dev->padding_pkt) { in usbnet_probe()
1813 status = -ENOMEM; in usbnet_probe()
1821 netif_info(dev, probe, dev->net, in usbnet_probe()
1822 "register '%s' at usb-%s-%s, %s, %pM\n", in usbnet_probe()
1823 udev->dev.driver->name, in usbnet_probe()
1824 xdev->bus->bus_name, xdev->devpath, in usbnet_probe()
1825 dev->driver_info->description, in usbnet_probe()
1826 net->dev_addr); in usbnet_probe()
1833 if (dev->driver_info->flags & FLAG_LINK_INTR) in usbnet_probe()
1839 kfree(dev->padding_pkt); in usbnet_probe()
1841 usb_free_urb(dev->interrupt); in usbnet_probe()
1843 if (info->unbind) in usbnet_probe()
1844 info->unbind (dev, udev); in usbnet_probe()
1851 cancel_work_sync(&dev->kevent); in usbnet_probe()
1852 del_timer_sync(&dev->delay); in usbnet_probe()
1853 free_percpu(net->tstats); in usbnet_probe()
1861 /*-------------------------------------------------------------------------*/
1872 if (!dev->suspend_count++) { in usbnet_suspend()
1873 spin_lock_irq(&dev->txq.lock); in usbnet_suspend()
1874 /* don't autosuspend while transmitting */ in usbnet_suspend()
1875 if (dev->txq.qlen && PMSG_IS_AUTO(message)) { in usbnet_suspend()
1876 dev->suspend_count--; in usbnet_suspend()
1877 spin_unlock_irq(&dev->txq.lock); in usbnet_suspend()
1878 return -EBUSY; in usbnet_suspend()
1880 set_bit(EVENT_DEV_ASLEEP, &dev->flags); in usbnet_suspend()
1881 spin_unlock_irq(&dev->txq.lock); in usbnet_suspend()
1887 netif_device_detach (dev->net); in usbnet_suspend()
1895 netif_device_attach (dev->net); in usbnet_suspend()
1908 if (!--dev->suspend_count) { in usbnet_resume()
1912 spin_lock_irq(&dev->txq.lock); in usbnet_resume()
1913 while ((res = usb_get_from_anchor(&dev->deferred))) { in usbnet_resume()
1915 skb = (struct sk_buff *)res->context; in usbnet_resume()
1919 kfree(res->sg); in usbnet_resume()
1921 usb_autopm_put_interface_async(dev->intf); in usbnet_resume()
1923 netif_trans_update(dev->net); in usbnet_resume()
1924 __skb_queue_tail(&dev->txq, skb); in usbnet_resume()
1929 clear_bit(EVENT_DEV_ASLEEP, &dev->flags); in usbnet_resume()
1930 spin_unlock_irq(&dev->txq.lock); in usbnet_resume()
1932 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { in usbnet_resume()
1936 if (netif_device_present(dev->net) && in usbnet_resume()
1937 !timer_pending(&dev->delay) && in usbnet_resume()
1938 !test_bit(EVENT_RX_HALT, &dev->flags)) in usbnet_resume()
1941 if (!(dev->txq.qlen >= TX_QLEN(dev))) in usbnet_resume()
1942 netif_tx_wake_all_queues(dev->net); in usbnet_resume()
1943 tasklet_schedule (&dev->bh); in usbnet_resume()
1947 if (test_and_clear_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags)) in usbnet_resume()
1961 if (!test_and_set_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags)) { in usbnet_device_suggests_idle()
1962 dev->intf->needs_remote_wakeup = 1; in usbnet_device_suggests_idle()
1963 usb_autopm_put_interface_async(dev->intf); in usbnet_device_suggests_idle()
1973 dev->intf->needs_remote_wakeup = on; in usbnet_manage_power()
1982 netif_carrier_on(dev->net); in usbnet_link_change()
1984 netif_carrier_off(dev->net); in usbnet_link_change()
1993 /*-------------------------------------------------------------------------*/
1998 int err = -ENOMEM; in __usbnet_read_cmd()
2000 netdev_dbg(dev->net, "usbnet_read_cmd cmd=0x%02x reqtype=%02x" in __usbnet_read_cmd()
2010 err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), in __usbnet_read_cmd()
2017 netdev_dbg(dev->net, in __usbnet_read_cmd()
2030 int err = -ENOMEM; in __usbnet_write_cmd()
2032 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" in __usbnet_write_cmd()
2043 err = -EINVAL; in __usbnet_write_cmd()
2048 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), in __usbnet_write_cmd()
2066 if (usb_autopm_get_interface(dev->intf) < 0) in usbnet_read_cmd()
2067 return -ENODEV; in usbnet_read_cmd()
2070 usb_autopm_put_interface(dev->intf); in usbnet_read_cmd()
2084 if (usb_autopm_get_interface(dev->intf) < 0) in usbnet_write_cmd()
2085 return -ENODEV; in usbnet_write_cmd()
2088 usb_autopm_put_interface(dev->intf); in usbnet_write_cmd()
2120 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; in usbnet_async_cmd_cb()
2121 int status = urb->status; in usbnet_async_cmd_cb()
2124 dev_dbg(&urb->dev->dev, "%s failed with %d", in usbnet_async_cmd_cb()
2140 int err = -ENOMEM; in usbnet_write_cmd_async()
2143 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" in usbnet_write_cmd_async()
2154 netdev_err(dev->net, "Error allocating buffer" in usbnet_write_cmd_async()
2164 req->bRequestType = reqtype; in usbnet_write_cmd_async()
2165 req->bRequest = cmd; in usbnet_write_cmd_async()
2166 req->wValue = cpu_to_le16(value); in usbnet_write_cmd_async()
2167 req->wIndex = cpu_to_le16(index); in usbnet_write_cmd_async()
2168 req->wLength = cpu_to_le16(size); in usbnet_write_cmd_async()
2170 usb_fill_control_urb(urb, dev->udev, in usbnet_write_cmd_async()
2171 usb_sndctrlpipe(dev->udev, 0), in usbnet_write_cmd_async()
2174 urb->transfer_flags |= URB_FREE_BUFFER; in usbnet_write_cmd_async()
2178 netdev_err(dev->net, "Error submitting the control" in usbnet_write_cmd_async()
2193 urb->transfer_flags = 0; in usbnet_write_cmd_async()
2201 /*-------------------------------------------------------------------------*/