usbnet.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /*
  2. * USB Network driver infrastructure
  3. * Copyright (C) 2000-2005 by David Brownell
  4. * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. /*
  21. * This is a generic "USB networking" framework that works with several
  22. * kinds of full and high speed networking devices: host-to-host cables,
  23. * smart usb peripherals, and actual Ethernet adapters.
  24. *
  25. * These devices usually differ in terms of control protocols (if they
  26. * even have one!) and sometimes they define new framing to wrap or batch
  27. * Ethernet packets. Otherwise, they talk to USB pretty much the same,
  28. * so interface (un)binding, endpoint I/O queues, fault handling, and other
  29. * issues can usefully be addressed by this framework.
  30. */
  31. // #define DEBUG // error path messages, extra info
  32. // #define VERBOSE // more; success messages
  33. #include <linux/module.h>
  34. #include <linux/init.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/ethtool.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/mii.h>
  40. #include <linux/usb.h>
  41. #include "usbnet.h"
  42. #define DRIVER_VERSION "22-Aug-2005"
  43. /*-------------------------------------------------------------------------*/
  44. /*
  45. * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
  46. * Several dozen bytes of IPv4 data can fit in two such transactions.
  47. * One maximum size Ethernet packet takes twenty four of them.
  48. * For high speed, each frame comfortably fits almost 36 max size
  49. * Ethernet packets (so queues should be bigger).
  50. *
  51. * REVISIT qlens should be members of 'struct usbnet'; the goal is to
  52. * let the USB host controller be busy for 5msec or more before an irq
  53. * is required, under load. Jumbograms change the equation.
  54. */
  55. #define RX_MAX_QUEUE_MEMORY (60 * 1518)
  56. #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
  57. (RX_MAX_QUEUE_MEMORY/(dev)->rx_urb_size) : 4)
  58. #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
  59. (RX_MAX_QUEUE_MEMORY/(dev)->hard_mtu) : 4)
  60. // reawaken network queue this soon after stopping; else watchdog barks
  61. #define TX_TIMEOUT_JIFFIES (5*HZ)
  62. // throttle rx/tx briefly after some faults, so khubd might disconnect()
  63. // us (it polls at HZ/4 usually) before we report too many false errors.
  64. #define THROTTLE_JIFFIES (HZ/8)
  65. // between wakeups
  66. #define UNLINK_TIMEOUT_MS 3
  67. /*-------------------------------------------------------------------------*/
  68. // randomly generated ethernet address
  69. static u8 node_id [ETH_ALEN];
  70. static const char driver_name [] = "usbnet";
  71. /* use ethtool to change the level for any given device */
  72. static int msg_level = -1;
  73. module_param (msg_level, int, 0);
  74. MODULE_PARM_DESC (msg_level, "Override default message level");
  75. /*-------------------------------------------------------------------------*/
  76. /* handles CDC Ethernet and many other network "bulk data" interfaces */
  77. int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
  78. {
  79. int tmp;
  80. struct usb_host_interface *alt = NULL;
  81. struct usb_host_endpoint *in = NULL, *out = NULL;
  82. struct usb_host_endpoint *status = NULL;
  83. for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
  84. unsigned ep;
  85. in = out = status = NULL;
  86. alt = intf->altsetting + tmp;
  87. /* take the first altsetting with in-bulk + out-bulk;
  88. * remember any status endpoint, just in case;
  89. * ignore other endpoints and altsetttings.
  90. */
  91. for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
  92. struct usb_host_endpoint *e;
  93. int intr = 0;
  94. e = alt->endpoint + ep;
  95. switch (e->desc.bmAttributes) {
  96. case USB_ENDPOINT_XFER_INT:
  97. if (!usb_endpoint_dir_in(&e->desc))
  98. continue;
  99. intr = 1;
  100. /* FALLTHROUGH */
  101. case USB_ENDPOINT_XFER_BULK:
  102. break;
  103. default:
  104. continue;
  105. }
  106. if (usb_endpoint_dir_in(&e->desc)) {
  107. if (!intr && !in)
  108. in = e;
  109. else if (intr && !status)
  110. status = e;
  111. } else {
  112. if (!out)
  113. out = e;
  114. }
  115. }
  116. if (in && out)
  117. break;
  118. }
  119. if (!alt || !in || !out)
  120. return -EINVAL;
  121. if (alt->desc.bAlternateSetting != 0
  122. || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
  123. tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
  124. alt->desc.bAlternateSetting);
  125. if (tmp < 0)
  126. return tmp;
  127. }
  128. dev->in = usb_rcvbulkpipe (dev->udev,
  129. in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  130. dev->out = usb_sndbulkpipe (dev->udev,
  131. out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  132. dev->status = status;
  133. return 0;
  134. }
  135. EXPORT_SYMBOL_GPL(usbnet_get_endpoints);
  136. static void intr_complete (struct urb *urb);
  137. static int init_status (struct usbnet *dev, struct usb_interface *intf)
  138. {
  139. char *buf = NULL;
  140. unsigned pipe = 0;
  141. unsigned maxp;
  142. unsigned period;
  143. if (!dev->driver_info->status)
  144. return 0;
  145. pipe = usb_rcvintpipe (dev->udev,
  146. dev->status->desc.bEndpointAddress
  147. & USB_ENDPOINT_NUMBER_MASK);
  148. maxp = usb_maxpacket (dev->udev, pipe, 0);
  149. /* avoid 1 msec chatter: min 8 msec poll rate */
  150. period = max ((int) dev->status->desc.bInterval,
  151. (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
  152. buf = kmalloc (maxp, GFP_KERNEL);
  153. if (buf) {
  154. dev->interrupt = usb_alloc_urb (0, GFP_KERNEL);
  155. if (!dev->interrupt) {
  156. kfree (buf);
  157. return -ENOMEM;
  158. } else {
  159. usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
  160. buf, maxp, intr_complete, dev, period);
  161. dev_dbg(&intf->dev,
  162. "status ep%din, %d bytes period %d\n",
  163. usb_pipeendpoint(pipe), maxp, period);
  164. }
  165. }
  166. return 0;
  167. }
  168. /* Passes this packet up the stack, updating its accounting.
  169. * Some link protocols batch packets, so their rx_fixup paths
  170. * can return clones as well as just modify the original skb.
  171. */
  172. void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
  173. {
  174. int status;
  175. skb->dev = dev->net;
  176. skb->protocol = eth_type_trans (skb, dev->net);
  177. dev->stats.rx_packets++;
  178. dev->stats.rx_bytes += skb->len;
  179. if (netif_msg_rx_status (dev))
  180. devdbg (dev, "< rx, len %zu, type 0x%x",
  181. skb->len + sizeof (struct ethhdr), skb->protocol);
  182. memset (skb->cb, 0, sizeof (struct skb_data));
  183. status = netif_rx (skb);
  184. if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
  185. devdbg (dev, "netif_rx status %d", status);
  186. }
  187. EXPORT_SYMBOL_GPL(usbnet_skb_return);
  188. /*-------------------------------------------------------------------------
  189. *
  190. * Network Device Driver (peer link to "Host Device", from USB host)
  191. *
  192. *-------------------------------------------------------------------------*/
  193. static int usbnet_change_mtu (struct net_device *net, int new_mtu)
  194. {
  195. struct usbnet *dev = netdev_priv(net);
  196. int ll_mtu = new_mtu + net->hard_header_len;
  197. int old_hard_mtu = dev->hard_mtu;
  198. int old_rx_urb_size = dev->rx_urb_size;
  199. if (new_mtu <= 0)
  200. return -EINVAL;
  201. // no second zero-length packet read wanted after mtu-sized packets
  202. if ((ll_mtu % dev->maxpacket) == 0)
  203. return -EDOM;
  204. net->mtu = new_mtu;
  205. dev->hard_mtu = net->mtu + net->hard_header_len;
  206. if (dev->rx_urb_size == old_hard_mtu) {
  207. dev->rx_urb_size = dev->hard_mtu;
  208. if (dev->rx_urb_size > old_rx_urb_size)
  209. usbnet_unlink_rx_urbs(dev);
  210. }
  211. return 0;
  212. }
  213. /*-------------------------------------------------------------------------*/
  214. static struct net_device_stats *usbnet_get_stats (struct net_device *net)
  215. {
  216. struct usbnet *dev = netdev_priv(net);
  217. return &dev->stats;
  218. }
  219. /*-------------------------------------------------------------------------*/
  220. /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
  221. * completion callbacks. 2.5 should have fixed those bugs...
  222. */
  223. static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)
  224. {
  225. unsigned long flags;
  226. spin_lock_irqsave(&list->lock, flags);
  227. __skb_unlink(skb, list);
  228. spin_unlock(&list->lock);
  229. spin_lock(&dev->done.lock);
  230. __skb_queue_tail(&dev->done, skb);
  231. if (dev->done.qlen == 1)
  232. tasklet_schedule(&dev->bh);
  233. spin_unlock_irqrestore(&dev->done.lock, flags);
  234. }
  235. /* some work can't be done in tasklets, so we use keventd
  236. *
  237. * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
  238. * but tasklet_schedule() doesn't. hope the failure is rare.
  239. */
  240. void usbnet_defer_kevent (struct usbnet *dev, int work)
  241. {
  242. set_bit (work, &dev->flags);
  243. if (!schedule_work (&dev->kevent))
  244. deverr (dev, "kevent %d may have been dropped", work);
  245. else
  246. devdbg (dev, "kevent %d scheduled", work);
  247. }
  248. EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
  249. /*-------------------------------------------------------------------------*/
  250. static void rx_complete (struct urb *urb);
  251. static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
  252. {
  253. struct sk_buff *skb;
  254. struct skb_data *entry;
  255. int retval = 0;
  256. unsigned long lockflags;
  257. size_t size = dev->rx_urb_size;
  258. if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
  259. if (netif_msg_rx_err (dev))
  260. devdbg (dev, "no rx skb");
  261. usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
  262. usb_free_urb (urb);
  263. return;
  264. }
  265. skb_reserve (skb, NET_IP_ALIGN);
  266. entry = (struct skb_data *) skb->cb;
  267. entry->urb = urb;
  268. entry->dev = dev;
  269. entry->state = rx_start;
  270. entry->length = 0;
  271. usb_fill_bulk_urb (urb, dev->udev, dev->in,
  272. skb->data, size, rx_complete, skb);
  273. spin_lock_irqsave (&dev->rxq.lock, lockflags);
  274. if (netif_running (dev->net)
  275. && netif_device_present (dev->net)
  276. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  277. switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
  278. case -EPIPE:
  279. usbnet_defer_kevent (dev, EVENT_RX_HALT);
  280. break;
  281. case -ENOMEM:
  282. usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
  283. break;
  284. case -ENODEV:
  285. if (netif_msg_ifdown (dev))
  286. devdbg (dev, "device gone");
  287. netif_device_detach (dev->net);
  288. break;
  289. default:
  290. if (netif_msg_rx_err (dev))
  291. devdbg (dev, "rx submit, %d", retval);
  292. tasklet_schedule (&dev->bh);
  293. break;
  294. case 0:
  295. __skb_queue_tail (&dev->rxq, skb);
  296. }
  297. } else {
  298. if (netif_msg_ifdown (dev))
  299. devdbg (dev, "rx: stopped");
  300. retval = -ENOLINK;
  301. }
  302. spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
  303. if (retval) {
  304. dev_kfree_skb_any (skb);
  305. usb_free_urb (urb);
  306. }
  307. }
  308. /*-------------------------------------------------------------------------*/
  309. static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
  310. {
  311. if (dev->driver_info->rx_fixup
  312. && !dev->driver_info->rx_fixup (dev, skb))
  313. goto error;
  314. // else network stack removes extra byte if we forced a short packet
  315. if (skb->len)
  316. usbnet_skb_return (dev, skb);
  317. else {
  318. if (netif_msg_rx_err (dev))
  319. devdbg (dev, "drop");
  320. error:
  321. dev->stats.rx_errors++;
  322. skb_queue_tail (&dev->done, skb);
  323. }
  324. }
  325. /*-------------------------------------------------------------------------*/
  326. static void rx_complete (struct urb *urb)
  327. {
  328. struct sk_buff *skb = (struct sk_buff *) urb->context;
  329. struct skb_data *entry = (struct skb_data *) skb->cb;
  330. struct usbnet *dev = entry->dev;
  331. int urb_status = urb->status;
  332. skb_put (skb, urb->actual_length);
  333. entry->state = rx_done;
  334. entry->urb = NULL;
  335. switch (urb_status) {
  336. // success
  337. case 0:
  338. if (skb->len < dev->net->hard_header_len) {
  339. entry->state = rx_cleanup;
  340. dev->stats.rx_errors++;
  341. dev->stats.rx_length_errors++;
  342. if (netif_msg_rx_err (dev))
  343. devdbg (dev, "rx length %d", skb->len);
  344. }
  345. break;
  346. // stalls need manual reset. this is rare ... except that
  347. // when going through USB 2.0 TTs, unplug appears this way.
  348. // we avoid the highspeed version of the ETIMEOUT/EILSEQ
  349. // storm, recovering as needed.
  350. case -EPIPE:
  351. dev->stats.rx_errors++;
  352. usbnet_defer_kevent (dev, EVENT_RX_HALT);
  353. // FALLTHROUGH
  354. // software-driven interface shutdown
  355. case -ECONNRESET: // async unlink
  356. case -ESHUTDOWN: // hardware gone
  357. if (netif_msg_ifdown (dev))
  358. devdbg (dev, "rx shutdown, code %d", urb_status);
  359. goto block;
  360. // we get controller i/o faults during khubd disconnect() delays.
  361. // throttle down resubmits, to avoid log floods; just temporarily,
  362. // so we still recover when the fault isn't a khubd delay.
  363. case -EPROTO:
  364. case -ETIME:
  365. case -EILSEQ:
  366. dev->stats.rx_errors++;
  367. if (!timer_pending (&dev->delay)) {
  368. mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
  369. if (netif_msg_link (dev))
  370. devdbg (dev, "rx throttle %d", urb_status);
  371. }
  372. block:
  373. entry->state = rx_cleanup;
  374. entry->urb = urb;
  375. urb = NULL;
  376. break;
  377. // data overrun ... flush fifo?
  378. case -EOVERFLOW:
  379. dev->stats.rx_over_errors++;
  380. // FALLTHROUGH
  381. default:
  382. entry->state = rx_cleanup;
  383. dev->stats.rx_errors++;
  384. if (netif_msg_rx_err (dev))
  385. devdbg (dev, "rx status %d", urb_status);
  386. break;
  387. }
  388. defer_bh(dev, skb, &dev->rxq);
  389. if (urb) {
  390. if (netif_running (dev->net)
  391. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  392. rx_submit (dev, urb, GFP_ATOMIC);
  393. return;
  394. }
  395. usb_free_urb (urb);
  396. }
  397. if (netif_msg_rx_err (dev))
  398. devdbg (dev, "no read resubmitted");
  399. }
  400. static void intr_complete (struct urb *urb)
  401. {
  402. struct usbnet *dev = urb->context;
  403. int status = urb->status;
  404. switch (status) {
  405. /* success */
  406. case 0:
  407. dev->driver_info->status(dev, urb);
  408. break;
  409. /* software-driven interface shutdown */
  410. case -ENOENT: // urb killed
  411. case -ESHUTDOWN: // hardware gone
  412. if (netif_msg_ifdown (dev))
  413. devdbg (dev, "intr shutdown, code %d", status);
  414. return;
  415. /* NOTE: not throttling like RX/TX, since this endpoint
  416. * already polls infrequently
  417. */
  418. default:
  419. devdbg (dev, "intr status %d", status);
  420. break;
  421. }
  422. if (!netif_running (dev->net))
  423. return;
  424. memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
  425. status = usb_submit_urb (urb, GFP_ATOMIC);
  426. if (status != 0 && netif_msg_timer (dev))
  427. deverr(dev, "intr resubmit --> %d", status);
  428. }
  429. /*-------------------------------------------------------------------------*/
  430. // unlink pending rx/tx; completion handlers do all other cleanup
  431. static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
  432. {
  433. unsigned long flags;
  434. struct sk_buff *skb, *skbnext;
  435. int count = 0;
  436. spin_lock_irqsave (&q->lock, flags);
  437. for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
  438. struct skb_data *entry;
  439. struct urb *urb;
  440. int retval;
  441. entry = (struct skb_data *) skb->cb;
  442. urb = entry->urb;
  443. skbnext = skb->next;
  444. // during some PM-driven resume scenarios,
  445. // these (async) unlinks complete immediately
  446. retval = usb_unlink_urb (urb);
  447. if (retval != -EINPROGRESS && retval != 0)
  448. devdbg (dev, "unlink urb err, %d", retval);
  449. else
  450. count++;
  451. }
  452. spin_unlock_irqrestore (&q->lock, flags);
  453. return count;
  454. }
  455. // Flush all pending rx urbs
  456. // minidrivers may need to do this when the MTU changes
  457. void usbnet_unlink_rx_urbs(struct usbnet *dev)
  458. {
  459. if (netif_running(dev->net)) {
  460. (void) unlink_urbs (dev, &dev->rxq);
  461. tasklet_schedule(&dev->bh);
  462. }
  463. }
  464. EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
  465. /*-------------------------------------------------------------------------*/
  466. // precondition: never called in_interrupt
  467. static int usbnet_stop (struct net_device *net)
  468. {
  469. struct usbnet *dev = netdev_priv(net);
  470. int temp;
  471. DECLARE_WAIT_QUEUE_HEAD_ONSTACK (unlink_wakeup);
  472. DECLARE_WAITQUEUE (wait, current);
  473. netif_stop_queue (net);
  474. if (netif_msg_ifdown (dev))
  475. devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
  476. dev->stats.rx_packets, dev->stats.tx_packets,
  477. dev->stats.rx_errors, dev->stats.tx_errors
  478. );
  479. // ensure there are no more active urbs
  480. add_wait_queue (&unlink_wakeup, &wait);
  481. dev->wait = &unlink_wakeup;
  482. temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
  483. // maybe wait for deletions to finish.
  484. while (!skb_queue_empty(&dev->rxq) &&
  485. !skb_queue_empty(&dev->txq) &&
  486. !skb_queue_empty(&dev->done)) {
  487. msleep(UNLINK_TIMEOUT_MS);
  488. if (netif_msg_ifdown (dev))
  489. devdbg (dev, "waited for %d urb completions", temp);
  490. }
  491. dev->wait = NULL;
  492. remove_wait_queue (&unlink_wakeup, &wait);
  493. usb_kill_urb(dev->interrupt);
  494. /* deferred work (task, timer, softirq) must also stop.
  495. * can't flush_scheduled_work() until we drop rtnl (later),
  496. * else workers could deadlock; so make workers a NOP.
  497. */
  498. dev->flags = 0;
  499. del_timer_sync (&dev->delay);
  500. tasklet_kill (&dev->bh);
  501. return 0;
  502. }
  503. /*-------------------------------------------------------------------------*/
  504. // posts reads, and enables write queuing
  505. // precondition: never called in_interrupt
  506. static int usbnet_open (struct net_device *net)
  507. {
  508. struct usbnet *dev = netdev_priv(net);
  509. int retval = 0;
  510. struct driver_info *info = dev->driver_info;
  511. // put into "known safe" state
  512. if (info->reset && (retval = info->reset (dev)) < 0) {
  513. if (netif_msg_ifup (dev))
  514. devinfo (dev,
  515. "open reset fail (%d) usbnet usb-%s-%s, %s",
  516. retval,
  517. dev->udev->bus->bus_name, dev->udev->devpath,
  518. info->description);
  519. goto done;
  520. }
  521. // insist peer be connected
  522. if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
  523. if (netif_msg_ifup (dev))
  524. devdbg (dev, "can't open; %d", retval);
  525. goto done;
  526. }
  527. /* start any status interrupt transfer */
  528. if (dev->interrupt) {
  529. retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
  530. if (retval < 0) {
  531. if (netif_msg_ifup (dev))
  532. deverr (dev, "intr submit %d", retval);
  533. goto done;
  534. }
  535. }
  536. netif_start_queue (net);
  537. if (netif_msg_ifup (dev)) {
  538. char *framing;
  539. if (dev->driver_info->flags & FLAG_FRAMING_NC)
  540. framing = "NetChip";
  541. else if (dev->driver_info->flags & FLAG_FRAMING_GL)
  542. framing = "GeneSys";
  543. else if (dev->driver_info->flags & FLAG_FRAMING_Z)
  544. framing = "Zaurus";
  545. else if (dev->driver_info->flags & FLAG_FRAMING_RN)
  546. framing = "RNDIS";
  547. else if (dev->driver_info->flags & FLAG_FRAMING_AX)
  548. framing = "ASIX";
  549. else
  550. framing = "simple";
  551. devinfo (dev, "open: enable queueing "
  552. "(rx %d, tx %d) mtu %d %s framing",
  553. (int)RX_QLEN (dev), (int)TX_QLEN (dev), dev->net->mtu,
  554. framing);
  555. }
  556. // delay posting reads until we're fully open
  557. tasklet_schedule (&dev->bh);
  558. done:
  559. return retval;
  560. }
  561. /*-------------------------------------------------------------------------*/
  562. /* ethtool methods; minidrivers may need to add some more, but
  563. * they'll probably want to use this base set.
  564. */
  565. #if defined(CONFIG_MII) || defined(CONFIG_MII_MODULE)
  566. #define HAVE_MII
  567. int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd)
  568. {
  569. struct usbnet *dev = netdev_priv(net);
  570. if (!dev->mii.mdio_read)
  571. return -EOPNOTSUPP;
  572. return mii_ethtool_gset(&dev->mii, cmd);
  573. }
  574. EXPORT_SYMBOL_GPL(usbnet_get_settings);
  575. int usbnet_set_settings (struct net_device *net, struct ethtool_cmd *cmd)
  576. {
  577. struct usbnet *dev = netdev_priv(net);
  578. int retval;
  579. if (!dev->mii.mdio_write)
  580. return -EOPNOTSUPP;
  581. retval = mii_ethtool_sset(&dev->mii, cmd);
  582. /* link speed/duplex might have changed */
  583. if (dev->driver_info->link_reset)
  584. dev->driver_info->link_reset(dev);
  585. return retval;
  586. }
  587. EXPORT_SYMBOL_GPL(usbnet_set_settings);
  588. u32 usbnet_get_link (struct net_device *net)
  589. {
  590. struct usbnet *dev = netdev_priv(net);
  591. /* If a check_connect is defined, return its result */
  592. if (dev->driver_info->check_connect)
  593. return dev->driver_info->check_connect (dev) == 0;
  594. /* if the device has mii operations, use those */
  595. if (dev->mii.mdio_read)
  596. return mii_link_ok(&dev->mii);
  597. /* Otherwise, say we're up (to avoid breaking scripts) */
  598. return 1;
  599. }
  600. EXPORT_SYMBOL_GPL(usbnet_get_link);
  601. int usbnet_nway_reset(struct net_device *net)
  602. {
  603. struct usbnet *dev = netdev_priv(net);
  604. if (!dev->mii.mdio_write)
  605. return -EOPNOTSUPP;
  606. return mii_nway_restart(&dev->mii);
  607. }
  608. EXPORT_SYMBOL_GPL(usbnet_nway_reset);
  609. #endif /* HAVE_MII */
  610. void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
  611. {
  612. struct usbnet *dev = netdev_priv(net);
  613. /* REVISIT don't always return "usbnet" */
  614. strncpy (info->driver, driver_name, sizeof info->driver);
  615. strncpy (info->version, DRIVER_VERSION, sizeof info->version);
  616. strncpy (info->fw_version, dev->driver_info->description,
  617. sizeof info->fw_version);
  618. usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
  619. }
  620. EXPORT_SYMBOL_GPL(usbnet_get_drvinfo);
  621. u32 usbnet_get_msglevel (struct net_device *net)
  622. {
  623. struct usbnet *dev = netdev_priv(net);
  624. return dev->msg_enable;
  625. }
  626. EXPORT_SYMBOL_GPL(usbnet_get_msglevel);
  627. void usbnet_set_msglevel (struct net_device *net, u32 level)
  628. {
  629. struct usbnet *dev = netdev_priv(net);
  630. dev->msg_enable = level;
  631. }
  632. EXPORT_SYMBOL_GPL(usbnet_set_msglevel);
  633. /* drivers may override default ethtool_ops in their bind() routine */
  634. static struct ethtool_ops usbnet_ethtool_ops = {
  635. #ifdef HAVE_MII
  636. .get_settings = usbnet_get_settings,
  637. .set_settings = usbnet_set_settings,
  638. .get_link = usbnet_get_link,
  639. .nway_reset = usbnet_nway_reset,
  640. #endif
  641. .get_drvinfo = usbnet_get_drvinfo,
  642. .get_msglevel = usbnet_get_msglevel,
  643. .set_msglevel = usbnet_set_msglevel,
  644. };
  645. /*-------------------------------------------------------------------------*/
  646. /* work that cannot be done in interrupt context uses keventd.
  647. *
  648. * NOTE: with 2.5 we could do more of this using completion callbacks,
  649. * especially now that control transfers can be queued.
  650. */
  651. static void
  652. kevent (struct work_struct *work)
  653. {
  654. struct usbnet *dev =
  655. container_of(work, struct usbnet, kevent);
  656. int status;
  657. /* usb_clear_halt() needs a thread context */
  658. if (test_bit (EVENT_TX_HALT, &dev->flags)) {
  659. unlink_urbs (dev, &dev->txq);
  660. status = usb_clear_halt (dev->udev, dev->out);
  661. if (status < 0
  662. && status != -EPIPE
  663. && status != -ESHUTDOWN) {
  664. if (netif_msg_tx_err (dev))
  665. deverr (dev, "can't clear tx halt, status %d",
  666. status);
  667. } else {
  668. clear_bit (EVENT_TX_HALT, &dev->flags);
  669. if (status != -ESHUTDOWN)
  670. netif_wake_queue (dev->net);
  671. }
  672. }
  673. if (test_bit (EVENT_RX_HALT, &dev->flags)) {
  674. unlink_urbs (dev, &dev->rxq);
  675. status = usb_clear_halt (dev->udev, dev->in);
  676. if (status < 0
  677. && status != -EPIPE
  678. && status != -ESHUTDOWN) {
  679. if (netif_msg_rx_err (dev))
  680. deverr (dev, "can't clear rx halt, status %d",
  681. status);
  682. } else {
  683. clear_bit (EVENT_RX_HALT, &dev->flags);
  684. tasklet_schedule (&dev->bh);
  685. }
  686. }
  687. /* tasklet could resubmit itself forever if memory is tight */
  688. if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
  689. struct urb *urb = NULL;
  690. if (netif_running (dev->net))
  691. urb = usb_alloc_urb (0, GFP_KERNEL);
  692. else
  693. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  694. if (urb != NULL) {
  695. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  696. rx_submit (dev, urb, GFP_KERNEL);
  697. tasklet_schedule (&dev->bh);
  698. }
  699. }
  700. if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
  701. struct driver_info *info = dev->driver_info;
  702. int retval = 0;
  703. clear_bit (EVENT_LINK_RESET, &dev->flags);
  704. if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
  705. devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s",
  706. retval,
  707. dev->udev->bus->bus_name, dev->udev->devpath,
  708. info->description);
  709. }
  710. }
  711. if (dev->flags)
  712. devdbg (dev, "kevent done, flags = 0x%lx",
  713. dev->flags);
  714. }
  715. /*-------------------------------------------------------------------------*/
  716. static void tx_complete (struct urb *urb)
  717. {
  718. struct sk_buff *skb = (struct sk_buff *) urb->context;
  719. struct skb_data *entry = (struct skb_data *) skb->cb;
  720. struct usbnet *dev = entry->dev;
  721. if (urb->status == 0) {
  722. dev->stats.tx_packets++;
  723. dev->stats.tx_bytes += entry->length;
  724. } else {
  725. dev->stats.tx_errors++;
  726. switch (urb->status) {
  727. case -EPIPE:
  728. usbnet_defer_kevent (dev, EVENT_TX_HALT);
  729. break;
  730. /* software-driven interface shutdown */
  731. case -ECONNRESET: // async unlink
  732. case -ESHUTDOWN: // hardware gone
  733. break;
  734. // like rx, tx gets controller i/o faults during khubd delays
  735. // and so it uses the same throttling mechanism.
  736. case -EPROTO:
  737. case -ETIME:
  738. case -EILSEQ:
  739. if (!timer_pending (&dev->delay)) {
  740. mod_timer (&dev->delay,
  741. jiffies + THROTTLE_JIFFIES);
  742. if (netif_msg_link (dev))
  743. devdbg (dev, "tx throttle %d",
  744. urb->status);
  745. }
  746. netif_stop_queue (dev->net);
  747. break;
  748. default:
  749. if (netif_msg_tx_err (dev))
  750. devdbg (dev, "tx err %d", entry->urb->status);
  751. break;
  752. }
  753. }
  754. urb->dev = NULL;
  755. entry->state = tx_done;
  756. defer_bh(dev, skb, &dev->txq);
  757. }
  758. /*-------------------------------------------------------------------------*/
  759. static void usbnet_tx_timeout (struct net_device *net)
  760. {
  761. struct usbnet *dev = netdev_priv(net);
  762. unlink_urbs (dev, &dev->txq);
  763. tasklet_schedule (&dev->bh);
  764. // FIXME: device recovery -- reset?
  765. }
  766. /*-------------------------------------------------------------------------*/
  767. static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
  768. {
  769. struct usbnet *dev = netdev_priv(net);
  770. int length;
  771. int retval = NET_XMIT_SUCCESS;
  772. struct urb *urb = NULL;
  773. struct skb_data *entry;
  774. struct driver_info *info = dev->driver_info;
  775. unsigned long flags;
  776. // some devices want funky USB-level framing, for
  777. // win32 driver (usually) and/or hardware quirks
  778. if (info->tx_fixup) {
  779. skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
  780. if (!skb) {
  781. if (netif_msg_tx_err (dev))
  782. devdbg (dev, "can't tx_fixup skb");
  783. goto drop;
  784. }
  785. }
  786. length = skb->len;
  787. if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
  788. if (netif_msg_tx_err (dev))
  789. devdbg (dev, "no urb");
  790. goto drop;
  791. }
  792. entry = (struct skb_data *) skb->cb;
  793. entry->urb = urb;
  794. entry->dev = dev;
  795. entry->state = tx_start;
  796. entry->length = length;
  797. usb_fill_bulk_urb (urb, dev->udev, dev->out,
  798. skb->data, skb->len, tx_complete, skb);
  799. /* don't assume the hardware handles USB_ZERO_PACKET
  800. * NOTE: strictly conforming cdc-ether devices should expect
  801. * the ZLP here, but ignore the one-byte packet.
  802. *
  803. * FIXME zero that byte, if it doesn't require a new skb.
  804. */
  805. if ((length % dev->maxpacket) == 0)
  806. urb->transfer_buffer_length++;
  807. spin_lock_irqsave (&dev->txq.lock, flags);
  808. switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
  809. case -EPIPE:
  810. netif_stop_queue (net);
  811. usbnet_defer_kevent (dev, EVENT_TX_HALT);
  812. break;
  813. default:
  814. if (netif_msg_tx_err (dev))
  815. devdbg (dev, "tx: submit urb err %d", retval);
  816. break;
  817. case 0:
  818. net->trans_start = jiffies;
  819. __skb_queue_tail (&dev->txq, skb);
  820. if (dev->txq.qlen >= TX_QLEN (dev))
  821. netif_stop_queue (net);
  822. }
  823. spin_unlock_irqrestore (&dev->txq.lock, flags);
  824. if (retval) {
  825. if (netif_msg_tx_err (dev))
  826. devdbg (dev, "drop, code %d", retval);
  827. drop:
  828. retval = NET_XMIT_SUCCESS;
  829. dev->stats.tx_dropped++;
  830. if (skb)
  831. dev_kfree_skb_any (skb);
  832. usb_free_urb (urb);
  833. } else if (netif_msg_tx_queued (dev)) {
  834. devdbg (dev, "> tx, len %d, type 0x%x",
  835. length, skb->protocol);
  836. }
  837. return retval;
  838. }
  839. /*-------------------------------------------------------------------------*/
  840. // tasklet (work deferred from completions, in_irq) or timer
  841. static void usbnet_bh (unsigned long param)
  842. {
  843. struct usbnet *dev = (struct usbnet *) param;
  844. struct sk_buff *skb;
  845. struct skb_data *entry;
  846. while ((skb = skb_dequeue (&dev->done))) {
  847. entry = (struct skb_data *) skb->cb;
  848. switch (entry->state) {
  849. case rx_done:
  850. entry->state = rx_cleanup;
  851. rx_process (dev, skb);
  852. continue;
  853. case tx_done:
  854. case rx_cleanup:
  855. usb_free_urb (entry->urb);
  856. dev_kfree_skb (skb);
  857. continue;
  858. default:
  859. devdbg (dev, "bogus skb state %d", entry->state);
  860. }
  861. }
  862. // waiting for all pending urbs to complete?
  863. if (dev->wait) {
  864. if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
  865. wake_up (dev->wait);
  866. }
  867. // or are we maybe short a few urbs?
  868. } else if (netif_running (dev->net)
  869. && netif_device_present (dev->net)
  870. && !timer_pending (&dev->delay)
  871. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  872. int temp = dev->rxq.qlen;
  873. int qlen = RX_QLEN (dev);
  874. if (temp < qlen) {
  875. struct urb *urb;
  876. int i;
  877. // don't refill the queue all at once
  878. for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
  879. urb = usb_alloc_urb (0, GFP_ATOMIC);
  880. if (urb != NULL)
  881. rx_submit (dev, urb, GFP_ATOMIC);
  882. }
  883. if (temp != dev->rxq.qlen && netif_msg_link (dev))
  884. devdbg (dev, "rxqlen %d --> %d",
  885. temp, dev->rxq.qlen);
  886. if (dev->rxq.qlen < qlen)
  887. tasklet_schedule (&dev->bh);
  888. }
  889. if (dev->txq.qlen < TX_QLEN (dev))
  890. netif_wake_queue (dev->net);
  891. }
  892. }
  893. /*-------------------------------------------------------------------------
  894. *
  895. * USB Device Driver support
  896. *
  897. *-------------------------------------------------------------------------*/
  898. // precondition: never called in_interrupt
  899. void usbnet_disconnect (struct usb_interface *intf)
  900. {
  901. struct usbnet *dev;
  902. struct usb_device *xdev;
  903. struct net_device *net;
  904. dev = usb_get_intfdata(intf);
  905. usb_set_intfdata(intf, NULL);
  906. if (!dev)
  907. return;
  908. xdev = interface_to_usbdev (intf);
  909. if (netif_msg_probe (dev))
  910. devinfo (dev, "unregister '%s' usb-%s-%s, %s",
  911. intf->dev.driver->name,
  912. xdev->bus->bus_name, xdev->devpath,
  913. dev->driver_info->description);
  914. net = dev->net;
  915. unregister_netdev (net);
  916. /* we don't hold rtnl here ... */
  917. flush_scheduled_work ();
  918. if (dev->driver_info->unbind)
  919. dev->driver_info->unbind (dev, intf);
  920. free_netdev(net);
  921. usb_put_dev (xdev);
  922. }
  923. EXPORT_SYMBOL_GPL(usbnet_disconnect);
  924. /*-------------------------------------------------------------------------*/
  925. // precondition: never called in_interrupt
  926. int
  927. usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
  928. {
  929. struct usbnet *dev;
  930. struct net_device *net;
  931. struct usb_host_interface *interface;
  932. struct driver_info *info;
  933. struct usb_device *xdev;
  934. int status;
  935. info = (struct driver_info *) prod->driver_info;
  936. if (!info) {
  937. dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
  938. return -ENODEV;
  939. }
  940. xdev = interface_to_usbdev (udev);
  941. interface = udev->cur_altsetting;
  942. usb_get_dev (xdev);
  943. status = -ENOMEM;
  944. // set up our own records
  945. net = alloc_etherdev(sizeof(*dev));
  946. if (!net) {
  947. dbg ("can't kmalloc dev");
  948. goto out;
  949. }
  950. dev = netdev_priv(net);
  951. dev->udev = xdev;
  952. dev->driver_info = info;
  953. dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
  954. | NETIF_MSG_PROBE | NETIF_MSG_LINK);
  955. skb_queue_head_init (&dev->rxq);
  956. skb_queue_head_init (&dev->txq);
  957. skb_queue_head_init (&dev->done);
  958. dev->bh.func = usbnet_bh;
  959. dev->bh.data = (unsigned long) dev;
  960. INIT_WORK (&dev->kevent, kevent);
  961. dev->delay.function = usbnet_bh;
  962. dev->delay.data = (unsigned long) dev;
  963. init_timer (&dev->delay);
  964. mutex_init (&dev->phy_mutex);
  965. SET_MODULE_OWNER (net);
  966. dev->net = net;
  967. strcpy (net->name, "usb%d");
  968. memcpy (net->dev_addr, node_id, sizeof node_id);
  969. /* rx and tx sides can use different message sizes;
  970. * bind() should set rx_urb_size in that case.
  971. */
  972. dev->hard_mtu = net->mtu + net->hard_header_len;
  973. #if 0
  974. // dma_supported() is deeply broken on almost all architectures
  975. // possible with some EHCI controllers
  976. if (dma_supported (&udev->dev, DMA_64BIT_MASK))
  977. net->features |= NETIF_F_HIGHDMA;
  978. #endif
  979. net->change_mtu = usbnet_change_mtu;
  980. net->get_stats = usbnet_get_stats;
  981. net->hard_start_xmit = usbnet_start_xmit;
  982. net->open = usbnet_open;
  983. net->stop = usbnet_stop;
  984. net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
  985. net->tx_timeout = usbnet_tx_timeout;
  986. net->ethtool_ops = &usbnet_ethtool_ops;
  987. // allow device-specific bind/init procedures
  988. // NOTE net->name still not usable ...
  989. if (info->bind) {
  990. status = info->bind (dev, udev);
  991. if (status < 0)
  992. goto out1;
  993. // heuristic: "usb%d" for links we know are two-host,
  994. // else "eth%d" when there's reasonable doubt. userspace
  995. // can rename the link if it knows better.
  996. if ((dev->driver_info->flags & FLAG_ETHER) != 0
  997. && (net->dev_addr [0] & 0x02) == 0)
  998. strcpy (net->name, "eth%d");
  999. /* maybe the remote can't receive an Ethernet MTU */
  1000. if (net->mtu > (dev->hard_mtu - net->hard_header_len))
  1001. net->mtu = dev->hard_mtu - net->hard_header_len;
  1002. } else if (!info->in || !info->out)
  1003. status = usbnet_get_endpoints (dev, udev);
  1004. else {
  1005. dev->in = usb_rcvbulkpipe (xdev, info->in);
  1006. dev->out = usb_sndbulkpipe (xdev, info->out);
  1007. if (!(info->flags & FLAG_NO_SETINT))
  1008. status = usb_set_interface (xdev,
  1009. interface->desc.bInterfaceNumber,
  1010. interface->desc.bAlternateSetting);
  1011. else
  1012. status = 0;
  1013. }
  1014. if (status == 0 && dev->status)
  1015. status = init_status (dev, udev);
  1016. if (status < 0)
  1017. goto out3;
  1018. if (!dev->rx_urb_size)
  1019. dev->rx_urb_size = dev->hard_mtu;
  1020. dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
  1021. SET_NETDEV_DEV(net, &udev->dev);
  1022. status = register_netdev (net);
  1023. if (status)
  1024. goto out3;
  1025. if (netif_msg_probe (dev))
  1026. devinfo (dev, "register '%s' at usb-%s-%s, %s, "
  1027. "%02x:%02x:%02x:%02x:%02x:%02x",
  1028. udev->dev.driver->name,
  1029. xdev->bus->bus_name, xdev->devpath,
  1030. dev->driver_info->description,
  1031. net->dev_addr [0], net->dev_addr [1],
  1032. net->dev_addr [2], net->dev_addr [3],
  1033. net->dev_addr [4], net->dev_addr [5]);
  1034. // ok, it's ready to go.
  1035. usb_set_intfdata (udev, dev);
  1036. // start as if the link is up
  1037. netif_device_attach (net);
  1038. return 0;
  1039. out3:
  1040. if (info->unbind)
  1041. info->unbind (dev, udev);
  1042. out1:
  1043. free_netdev(net);
  1044. out:
  1045. usb_put_dev(xdev);
  1046. return status;
  1047. }
  1048. EXPORT_SYMBOL_GPL(usbnet_probe);
  1049. /*-------------------------------------------------------------------------*/
  1050. /* FIXME these suspend/resume methods assume non-CDC style
  1051. * devices, with only one interface.
  1052. */
  1053. int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
  1054. {
  1055. struct usbnet *dev = usb_get_intfdata(intf);
  1056. /* accelerate emptying of the rx and queues, to avoid
  1057. * having everything error out.
  1058. */
  1059. netif_device_detach (dev->net);
  1060. (void) unlink_urbs (dev, &dev->rxq);
  1061. (void) unlink_urbs (dev, &dev->txq);
  1062. return 0;
  1063. }
  1064. EXPORT_SYMBOL_GPL(usbnet_suspend);
  1065. int usbnet_resume (struct usb_interface *intf)
  1066. {
  1067. struct usbnet *dev = usb_get_intfdata(intf);
  1068. netif_device_attach (dev->net);
  1069. tasklet_schedule (&dev->bh);
  1070. return 0;
  1071. }
  1072. EXPORT_SYMBOL_GPL(usbnet_resume);
  1073. /*-------------------------------------------------------------------------*/
  1074. static int __init usbnet_init(void)
  1075. {
  1076. /* compiler should optimize this out */
  1077. BUILD_BUG_ON (sizeof (((struct sk_buff *)0)->cb)
  1078. < sizeof (struct skb_data));
  1079. random_ether_addr(node_id);
  1080. return 0;
  1081. }
  1082. module_init(usbnet_init);
  1083. static void __exit usbnet_exit(void)
  1084. {
  1085. }
  1086. module_exit(usbnet_exit);
  1087. MODULE_AUTHOR("David Brownell");
  1088. MODULE_DESCRIPTION("USB network driver framework");
  1089. MODULE_LICENSE("GPL");