usbnet.c (3c69a99b62fde9de86a612ef1daaa07d95f0a773) | usbnet.c (efe3e6b5aeefaabed9ad5dcb3682b581bf34c187) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * USB Network driver infrastructure 4 * Copyright (C) 2000-2005 by David Brownell 5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 6 */ 7 8/* 9 * This is a generic "USB networking" framework that works with several 10 * kinds of full and high speed networking devices: host-to-host cables, 11 * smart usb peripherals, and actual Ethernet adapters. 12 * 13 * These devices usually differ in terms of control protocols (if they 14 * even have one!) and sometimes they define new framing to wrap or batch 15 * Ethernet packets. Otherwise, they talk to USB pretty much the same, 16 * so interface (un)binding, endpoint I/O queues, fault handling, and other 17 * issues can usefully be addressed by this framework. 18 */ 19 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * USB Network driver infrastructure 4 * Copyright (C) 2000-2005 by David Brownell 5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 6 */ 7 8/* 9 * This is a generic "USB networking" framework that works with several 10 * kinds of full and high speed networking devices: host-to-host cables, 11 * smart usb peripherals, and actual Ethernet adapters. 12 * 13 * These devices usually differ in terms of control protocols (if they 14 * even have one!) and sometimes they define new framing to wrap or batch 15 * Ethernet packets. Otherwise, they talk to USB pretty much the same, 16 * so interface (un)binding, endpoint I/O queues, fault handling, and other 17 * issues can usefully be addressed by this framework. 18 */ 19 |
20// #define DEBUG // error path messages, extra info 21// #define VERBOSE // more; success messages 22 | |
23#include <linux/module.h> 24#include <linux/init.h> 25#include <linux/netdevice.h> 26#include <linux/etherdevice.h> 27#include <linux/ctype.h> 28#include <linux/ethtool.h> 29#include <linux/workqueue.h> 30#include <linux/mii.h> --- 301 unchanged lines hidden (view full) --- 332 return; 333 } 334 335 /* only update if unset to allow minidriver rx_fixup override */ 336 if (skb->protocol == 0) 337 skb->protocol = eth_type_trans (skb, dev->net); 338 339 flags = u64_stats_update_begin_irqsave(&stats64->syncp); | 20#include <linux/module.h> 21#include <linux/init.h> 22#include <linux/netdevice.h> 23#include <linux/etherdevice.h> 24#include <linux/ctype.h> 25#include <linux/ethtool.h> 26#include <linux/workqueue.h> 27#include <linux/mii.h> --- 301 unchanged lines hidden (view full) --- 329 return; 330 } 331 332 /* only update if unset to allow minidriver rx_fixup override */ 333 if (skb->protocol == 0) 334 skb->protocol = eth_type_trans (skb, dev->net); 335 336 flags = u64_stats_update_begin_irqsave(&stats64->syncp); |
340 stats64->rx_packets++; 341 stats64->rx_bytes += skb->len; | 337 u64_stats_inc(&stats64->rx_packets); 338 u64_stats_add(&stats64->rx_bytes, skb->len); |
342 u64_stats_update_end_irqrestore(&stats64->syncp, flags); 343 344 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", 345 skb->len + sizeof (struct ethhdr), skb->protocol); 346 memset (skb->cb, 0, sizeof (struct skb_data)); 347 348 if (skb_defer_rx_timestamp(skb)) 349 return; --- 29 unchanged lines hidden (view full) --- 379 break; 380 default: 381insanity: 382 dev->rx_qlen = dev->tx_qlen = 4; 383 } 384} 385EXPORT_SYMBOL_GPL(usbnet_update_max_qlen); 386 | 339 u64_stats_update_end_irqrestore(&stats64->syncp, flags); 340 341 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", 342 skb->len + sizeof (struct ethhdr), skb->protocol); 343 memset (skb->cb, 0, sizeof (struct skb_data)); 344 345 if (skb_defer_rx_timestamp(skb)) 346 return; --- 29 unchanged lines hidden (view full) --- 376 break; 377 default: 378insanity: 379 dev->rx_qlen = dev->tx_qlen = 4; 380 } 381} 382EXPORT_SYMBOL_GPL(usbnet_update_max_qlen); 383 |
387 | 384 |
388/*------------------------------------------------------------------------- 389 * 390 * Network Device Driver (peer link to "Host Device", from USB host) 391 * 392 *-------------------------------------------------------------------------*/ 393 394int usbnet_change_mtu (struct net_device *net, int new_mtu) 395{ --- 448 unchanged lines hidden (view full) --- 844 usbnet_terminate_urbs(dev); 845 846 usbnet_status_stop(dev); 847 848 usbnet_purge_paused_rxq(dev); 849 850 mpn = !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags); 851 | 385/*------------------------------------------------------------------------- 386 * 387 * Network Device Driver (peer link to "Host Device", from USB host) 388 * 389 *-------------------------------------------------------------------------*/ 390 391int usbnet_change_mtu (struct net_device *net, int new_mtu) 392{ --- 448 unchanged lines hidden (view full) --- 841 usbnet_terminate_urbs(dev); 842 843 usbnet_status_stop(dev); 844 845 usbnet_purge_paused_rxq(dev); 846 847 mpn = !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags); 848 |
852 /* deferred work (task, timer, softirq) must also stop. 853 * can't flush_scheduled_work() until we drop rtnl (later), 854 * else workers could deadlock; so make workers a NOP. 855 */ | 849 /* deferred work (timer, softirq, task) must also stop */ |
856 dev->flags = 0; 857 del_timer_sync (&dev->delay); 858 tasklet_kill (&dev->bh); | 850 dev->flags = 0; 851 del_timer_sync (&dev->delay); 852 tasklet_kill (&dev->bh); |
853 cancel_work_sync(&dev->kevent); |
|
859 if (!pm) 860 usb_autopm_put_interface(dev->intf); 861 862 if (info->manage_power && mpn) 863 info->manage_power(dev, 0); 864 else 865 usb_autopm_put_interface(dev->intf); 866 --- 386 unchanged lines hidden (view full) --- 1253 struct skb_data *entry = (struct skb_data *) skb->cb; 1254 struct usbnet *dev = entry->dev; 1255 1256 if (urb->status == 0) { 1257 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); 1258 unsigned long flags; 1259 1260 flags = u64_stats_update_begin_irqsave(&stats64->syncp); | 854 if (!pm) 855 usb_autopm_put_interface(dev->intf); 856 857 if (info->manage_power && mpn) 858 info->manage_power(dev, 0); 859 else 860 usb_autopm_put_interface(dev->intf); 861 --- 386 unchanged lines hidden (view full) --- 1248 struct skb_data *entry = (struct skb_data *) skb->cb; 1249 struct usbnet *dev = entry->dev; 1250 1251 if (urb->status == 0) { 1252 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); 1253 unsigned long flags; 1254 1255 flags = u64_stats_update_begin_irqsave(&stats64->syncp); |
1261 stats64->tx_packets += entry->packets; 1262 stats64->tx_bytes += entry->length; | 1256 u64_stats_add(&stats64->tx_packets, entry->packets); 1257 u64_stats_add(&stats64->tx_bytes, entry->length); |
1263 u64_stats_update_end_irqrestore(&stats64->syncp, flags); 1264 } else { 1265 dev->net->stats.tx_errors++; 1266 1267 switch (urb->status) { 1268 case -EPIPE: 1269 usbnet_defer_kevent (dev, EVENT_TX_HALT); 1270 break; --- 343 unchanged lines hidden (view full) --- 1614 netif_info(dev, probe, dev->net, "unregister '%s' usb-%s-%s, %s\n", 1615 intf->dev.driver->name, 1616 xdev->bus->bus_name, xdev->devpath, 1617 dev->driver_info->description); 1618 1619 net = dev->net; 1620 unregister_netdev (net); 1621 | 1258 u64_stats_update_end_irqrestore(&stats64->syncp, flags); 1259 } else { 1260 dev->net->stats.tx_errors++; 1261 1262 switch (urb->status) { 1263 case -EPIPE: 1264 usbnet_defer_kevent (dev, EVENT_TX_HALT); 1265 break; --- 343 unchanged lines hidden (view full) --- 1609 netif_info(dev, probe, dev->net, "unregister '%s' usb-%s-%s, %s\n", 1610 intf->dev.driver->name, 1611 xdev->bus->bus_name, xdev->devpath, 1612 dev->driver_info->description); 1613 1614 net = dev->net; 1615 unregister_netdev (net); 1616 |
1622 cancel_work_sync(&dev->kevent); 1623 | |
1624 usb_scuttle_anchored_urbs(&dev->deferred); 1625 1626 if (dev->driver_info->unbind) 1627 dev->driver_info->unbind(dev, intf); 1628 1629 usb_kill_urb(dev->interrupt); 1630 usb_free_urb(dev->interrupt); 1631 kfree(dev->padding_pkt); --- 592 unchanged lines hidden --- | 1617 usb_scuttle_anchored_urbs(&dev->deferred); 1618 1619 if (dev->driver_info->unbind) 1620 dev->driver_info->unbind(dev, intf); 1621 1622 usb_kill_urb(dev->interrupt); 1623 usb_free_urb(dev->interrupt); 1624 kfree(dev->padding_pkt); --- 592 unchanged lines hidden --- |