usbnet.c 34 KB

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