usbnet.c 34 KB

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