tx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * WUSB Wire Adapter: WLP interface
  3. * Deal with TX (massaging data to transmit, handling it)
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * Transmission engine. Get an skb, create from that a WLP transmit
  24. * context, add a WLP TX header (which we keep prefilled in the
  25. * device's instance), fill out the target-specific fields and
  26. * fire it.
  27. *
  28. * ROADMAP:
  29. *
  30. * Entry points:
  31. *
  32. * i1480u_tx_release(): called by i1480u_disconnect() to release
  33. * pending tx contexts.
  34. *
  35. * i1480u_tx_cb(): callback for TX contexts (USB URBs)
  36. * i1480u_tx_destroy():
  37. *
  38. * i1480u_tx_timeout(): called for timeout handling from the
  39. * network stack.
  40. *
  41. * i1480u_hard_start_xmit(): called for transmitting an skb from
  42. * the network stack. Will interact with WLP
  43. * substack to verify and prepare frame.
  44. * i1480u_xmit_frame(): actual transmission on hardware
  45. *
  46. * i1480u_tx_create() Creates TX context
  47. * i1480u_tx_create_1() For packets in 1 fragment
  48. * i1480u_tx_create_n() For packets in >1 fragments
  49. *
  50. * TODO:
  51. *
  52. * - FIXME: rewrite using usb_sg_*(), add asynch support to
  53. * usb_sg_*(). It might not make too much sense as most of
  54. * the times the MTU will be smaller than one page...
  55. */
  56. #include "i1480u-wlp.h"
  57. enum {
  58. /* This is only for Next and Last TX packets */
  59. i1480u_MAX_PL_SIZE = i1480u_MAX_FRG_SIZE
  60. - sizeof(struct untd_hdr_rst),
  61. };
  62. /* Free resources allocated to a i1480u tx context. */
  63. static
  64. void i1480u_tx_free(struct i1480u_tx *wtx)
  65. {
  66. kfree(wtx->buf);
  67. if (wtx->skb)
  68. dev_kfree_skb_irq(wtx->skb);
  69. usb_free_urb(wtx->urb);
  70. kfree(wtx);
  71. }
  72. static
  73. void i1480u_tx_destroy(struct i1480u *i1480u, struct i1480u_tx *wtx)
  74. {
  75. unsigned long flags;
  76. spin_lock_irqsave(&i1480u->tx_list_lock, flags); /* not active any more */
  77. list_del(&wtx->list_node);
  78. i1480u_tx_free(wtx);
  79. spin_unlock_irqrestore(&i1480u->tx_list_lock, flags);
  80. }
  81. static
  82. void i1480u_tx_unlink_urbs(struct i1480u *i1480u)
  83. {
  84. unsigned long flags;
  85. struct i1480u_tx *wtx, *next;
  86. spin_lock_irqsave(&i1480u->tx_list_lock, flags);
  87. list_for_each_entry_safe(wtx, next, &i1480u->tx_list, list_node) {
  88. usb_unlink_urb(wtx->urb);
  89. }
  90. spin_unlock_irqrestore(&i1480u->tx_list_lock, flags);
  91. }
  92. /*
  93. * Callback for a completed tx USB URB.
  94. *
  95. * TODO:
  96. *
  97. * - FIXME: recover errors more gracefully
  98. * - FIXME: handle NAKs (I dont think they come here) for flow ctl
  99. */
  100. static
  101. void i1480u_tx_cb(struct urb *urb)
  102. {
  103. struct i1480u_tx *wtx = urb->context;
  104. struct i1480u *i1480u = wtx->i1480u;
  105. struct net_device *net_dev = i1480u->net_dev;
  106. struct device *dev = &i1480u->usb_iface->dev;
  107. unsigned long flags;
  108. switch (urb->status) {
  109. case 0:
  110. spin_lock_irqsave(&i1480u->lock, flags);
  111. net_dev->stats.tx_packets++;
  112. net_dev->stats.tx_bytes += urb->actual_length;
  113. spin_unlock_irqrestore(&i1480u->lock, flags);
  114. break;
  115. case -ECONNRESET: /* Not an error, but a controlled situation; */
  116. case -ENOENT: /* (we killed the URB)...so, no broadcast */
  117. dev_dbg(dev, "notif endp: reset/noent %d\n", urb->status);
  118. netif_stop_queue(net_dev);
  119. break;
  120. case -ESHUTDOWN: /* going away! */
  121. dev_dbg(dev, "notif endp: down %d\n", urb->status);
  122. netif_stop_queue(net_dev);
  123. break;
  124. default:
  125. dev_err(dev, "TX: unknown URB status %d\n", urb->status);
  126. if (edc_inc(&i1480u->tx_errors, EDC_MAX_ERRORS,
  127. EDC_ERROR_TIMEFRAME)) {
  128. dev_err(dev, "TX: max acceptable errors exceeded."
  129. "Reset device.\n");
  130. netif_stop_queue(net_dev);
  131. i1480u_tx_unlink_urbs(i1480u);
  132. wlp_reset_all(&i1480u->wlp);
  133. }
  134. break;
  135. }
  136. i1480u_tx_destroy(i1480u, wtx);
  137. if (atomic_dec_return(&i1480u->tx_inflight.count)
  138. <= i1480u->tx_inflight.threshold
  139. && netif_queue_stopped(net_dev)
  140. && i1480u->tx_inflight.threshold != 0) {
  141. netif_start_queue(net_dev);
  142. atomic_inc(&i1480u->tx_inflight.restart_count);
  143. }
  144. return;
  145. }
  146. /*
  147. * Given a buffer that doesn't fit in a single fragment, create an
  148. * scatter/gather structure for delivery to the USB pipe.
  149. *
  150. * Implements functionality of i1480u_tx_create().
  151. *
  152. * @wtx: tx descriptor
  153. * @skb: skb to send
  154. * @gfp_mask: gfp allocation mask
  155. * @returns: Pointer to @wtx if ok, NULL on error.
  156. *
  157. * Sorry, TOO LONG a function, but breaking it up is kind of hard
  158. *
  159. * This will break the buffer in chunks smaller than
  160. * i1480u_MAX_FRG_SIZE (including the header) and add proper headers
  161. * to each:
  162. *
  163. * 1st header \
  164. * i1480 tx header | fragment 1
  165. * fragment data /
  166. * nxt header \ fragment 2
  167. * fragment data /
  168. * ..
  169. * ..
  170. * last header \ fragment 3
  171. * last fragment data /
  172. *
  173. * This does not fill the i1480 TX header, it is left up to the
  174. * caller to do that; you can get it from @wtx->wlp_tx_hdr.
  175. *
  176. * This function consumes the skb unless there is an error.
  177. */
  178. static
  179. int i1480u_tx_create_n(struct i1480u_tx *wtx, struct sk_buff *skb,
  180. gfp_t gfp_mask)
  181. {
  182. int result;
  183. void *pl;
  184. size_t pl_size;
  185. void *pl_itr, *buf_itr;
  186. size_t pl_size_left, frgs, pl_size_1st, frg_pl_size = 0;
  187. struct untd_hdr_1st *untd_hdr_1st;
  188. struct wlp_tx_hdr *wlp_tx_hdr;
  189. struct untd_hdr_rst *untd_hdr_rst;
  190. wtx->skb = NULL;
  191. pl = skb->data;
  192. pl_itr = pl;
  193. pl_size = skb->len;
  194. pl_size_left = pl_size; /* payload size */
  195. /* First fragment; fits as much as i1480u_MAX_FRG_SIZE minus
  196. * the headers */
  197. pl_size_1st = i1480u_MAX_FRG_SIZE
  198. - sizeof(struct untd_hdr_1st) - sizeof(struct wlp_tx_hdr);
  199. BUG_ON(pl_size_1st > pl_size);
  200. pl_size_left -= pl_size_1st;
  201. /* The rest have an smaller header (no i1480 TX header). We
  202. * need to break up the payload in blocks smaller than
  203. * i1480u_MAX_PL_SIZE (payload excluding header). */
  204. frgs = (pl_size_left + i1480u_MAX_PL_SIZE - 1) / i1480u_MAX_PL_SIZE;
  205. /* Allocate space for the new buffer. In this new buffer we'll
  206. * place the headers followed by the data fragment, headers,
  207. * data fragments, etc..
  208. */
  209. result = -ENOMEM;
  210. wtx->buf_size = sizeof(*untd_hdr_1st)
  211. + sizeof(*wlp_tx_hdr)
  212. + frgs * sizeof(*untd_hdr_rst)
  213. + pl_size;
  214. wtx->buf = kmalloc(wtx->buf_size, gfp_mask);
  215. if (wtx->buf == NULL)
  216. goto error_buf_alloc;
  217. buf_itr = wtx->buf; /* We got the space, let's fill it up */
  218. /* Fill 1st fragment */
  219. untd_hdr_1st = buf_itr;
  220. buf_itr += sizeof(*untd_hdr_1st);
  221. untd_hdr_set_type(&untd_hdr_1st->hdr, i1480u_PKT_FRAG_1ST);
  222. untd_hdr_set_rx_tx(&untd_hdr_1st->hdr, 0);
  223. untd_hdr_1st->hdr.len = cpu_to_le16(pl_size + sizeof(*wlp_tx_hdr));
  224. untd_hdr_1st->fragment_len =
  225. cpu_to_le16(pl_size_1st + sizeof(*wlp_tx_hdr));
  226. memset(untd_hdr_1st->padding, 0, sizeof(untd_hdr_1st->padding));
  227. /* Set up i1480 header info */
  228. wlp_tx_hdr = wtx->wlp_tx_hdr = buf_itr;
  229. buf_itr += sizeof(*wlp_tx_hdr);
  230. /* Copy the first fragment */
  231. memcpy(buf_itr, pl_itr, pl_size_1st);
  232. pl_itr += pl_size_1st;
  233. buf_itr += pl_size_1st;
  234. /* Now do each remaining fragment */
  235. result = -EINVAL;
  236. while (pl_size_left > 0) {
  237. if (buf_itr + sizeof(*untd_hdr_rst) - wtx->buf
  238. > wtx->buf_size) {
  239. printk(KERN_ERR "BUG: no space for header\n");
  240. goto error_bug;
  241. }
  242. untd_hdr_rst = buf_itr;
  243. buf_itr += sizeof(*untd_hdr_rst);
  244. if (pl_size_left > i1480u_MAX_PL_SIZE) {
  245. frg_pl_size = i1480u_MAX_PL_SIZE;
  246. untd_hdr_set_type(&untd_hdr_rst->hdr, i1480u_PKT_FRAG_NXT);
  247. } else {
  248. frg_pl_size = pl_size_left;
  249. untd_hdr_set_type(&untd_hdr_rst->hdr, i1480u_PKT_FRAG_LST);
  250. }
  251. untd_hdr_set_rx_tx(&untd_hdr_rst->hdr, 0);
  252. untd_hdr_rst->hdr.len = cpu_to_le16(frg_pl_size);
  253. untd_hdr_rst->padding = 0;
  254. if (buf_itr + frg_pl_size - wtx->buf
  255. > wtx->buf_size) {
  256. printk(KERN_ERR "BUG: no space for payload\n");
  257. goto error_bug;
  258. }
  259. memcpy(buf_itr, pl_itr, frg_pl_size);
  260. buf_itr += frg_pl_size;
  261. pl_itr += frg_pl_size;
  262. pl_size_left -= frg_pl_size;
  263. }
  264. dev_kfree_skb_irq(skb);
  265. return 0;
  266. error_bug:
  267. printk(KERN_ERR
  268. "BUG: skb %u bytes\n"
  269. "BUG: frg_pl_size %zd i1480u_MAX_FRG_SIZE %u\n"
  270. "BUG: buf_itr %zu buf_size %zu pl_size_left %zu\n",
  271. skb->len,
  272. frg_pl_size, i1480u_MAX_FRG_SIZE,
  273. buf_itr - wtx->buf, wtx->buf_size, pl_size_left);
  274. kfree(wtx->buf);
  275. error_buf_alloc:
  276. return result;
  277. }
  278. /*
  279. * Given a buffer that fits in a single fragment, fill out a @wtx
  280. * struct for transmitting it down the USB pipe.
  281. *
  282. * Uses the fact that we have space reserved in front of the skbuff
  283. * for hardware headers :]
  284. *
  285. * This does not fill the i1480 TX header, it is left up to the
  286. * caller to do that; you can get it from @wtx->wlp_tx_hdr.
  287. *
  288. * @pl: pointer to payload data
  289. * @pl_size: size of the payuload
  290. *
  291. * This function does not consume the @skb.
  292. */
  293. static
  294. int i1480u_tx_create_1(struct i1480u_tx *wtx, struct sk_buff *skb,
  295. gfp_t gfp_mask)
  296. {
  297. struct untd_hdr_cmp *untd_hdr_cmp;
  298. struct wlp_tx_hdr *wlp_tx_hdr;
  299. wtx->buf = NULL;
  300. wtx->skb = skb;
  301. BUG_ON(skb_headroom(skb) < sizeof(*wlp_tx_hdr));
  302. wlp_tx_hdr = (void *) __skb_push(skb, sizeof(*wlp_tx_hdr));
  303. wtx->wlp_tx_hdr = wlp_tx_hdr;
  304. BUG_ON(skb_headroom(skb) < sizeof(*untd_hdr_cmp));
  305. untd_hdr_cmp = (void *) __skb_push(skb, sizeof(*untd_hdr_cmp));
  306. untd_hdr_set_type(&untd_hdr_cmp->hdr, i1480u_PKT_FRAG_CMP);
  307. untd_hdr_set_rx_tx(&untd_hdr_cmp->hdr, 0);
  308. untd_hdr_cmp->hdr.len = cpu_to_le16(skb->len - sizeof(*untd_hdr_cmp));
  309. untd_hdr_cmp->padding = 0;
  310. return 0;
  311. }
  312. /*
  313. * Given a skb to transmit, massage it to become palatable for the TX pipe
  314. *
  315. * This will break the buffer in chunks smaller than
  316. * i1480u_MAX_FRG_SIZE and add proper headers to each.
  317. *
  318. * 1st header \
  319. * i1480 tx header | fragment 1
  320. * fragment data /
  321. * nxt header \ fragment 2
  322. * fragment data /
  323. * ..
  324. * ..
  325. * last header \ fragment 3
  326. * last fragment data /
  327. *
  328. * Each fragment will be always smaller or equal to i1480u_MAX_FRG_SIZE.
  329. *
  330. * If the first fragment is smaller than i1480u_MAX_FRG_SIZE, then the
  331. * following is composed:
  332. *
  333. * complete header \
  334. * i1480 tx header | single fragment
  335. * packet data /
  336. *
  337. * We were going to use s/g support, but because the interface is
  338. * synch and at the end there is plenty of overhead to do it, it
  339. * didn't seem that worth for data that is going to be smaller than
  340. * one page.
  341. */
  342. static
  343. struct i1480u_tx *i1480u_tx_create(struct i1480u *i1480u,
  344. struct sk_buff *skb, gfp_t gfp_mask)
  345. {
  346. int result;
  347. struct usb_endpoint_descriptor *epd;
  348. int usb_pipe;
  349. unsigned long flags;
  350. struct i1480u_tx *wtx;
  351. const size_t pl_max_size =
  352. i1480u_MAX_FRG_SIZE - sizeof(struct untd_hdr_cmp)
  353. - sizeof(struct wlp_tx_hdr);
  354. wtx = kmalloc(sizeof(*wtx), gfp_mask);
  355. if (wtx == NULL)
  356. goto error_wtx_alloc;
  357. wtx->urb = usb_alloc_urb(0, gfp_mask);
  358. if (wtx->urb == NULL)
  359. goto error_urb_alloc;
  360. epd = &i1480u->usb_iface->cur_altsetting->endpoint[2].desc;
  361. usb_pipe = usb_sndbulkpipe(i1480u->usb_dev, epd->bEndpointAddress);
  362. /* Fits in a single complete packet or need to split? */
  363. if (skb->len > pl_max_size) {
  364. result = i1480u_tx_create_n(wtx, skb, gfp_mask);
  365. if (result < 0)
  366. goto error_create;
  367. usb_fill_bulk_urb(wtx->urb, i1480u->usb_dev, usb_pipe,
  368. wtx->buf, wtx->buf_size, i1480u_tx_cb, wtx);
  369. } else {
  370. result = i1480u_tx_create_1(wtx, skb, gfp_mask);
  371. if (result < 0)
  372. goto error_create;
  373. usb_fill_bulk_urb(wtx->urb, i1480u->usb_dev, usb_pipe,
  374. skb->data, skb->len, i1480u_tx_cb, wtx);
  375. }
  376. spin_lock_irqsave(&i1480u->tx_list_lock, flags);
  377. list_add(&wtx->list_node, &i1480u->tx_list);
  378. spin_unlock_irqrestore(&i1480u->tx_list_lock, flags);
  379. return wtx;
  380. error_create:
  381. kfree(wtx->urb);
  382. error_urb_alloc:
  383. kfree(wtx);
  384. error_wtx_alloc:
  385. return NULL;
  386. }
  387. /*
  388. * Actual fragmentation and transmission of frame
  389. *
  390. * @wlp: WLP substack data structure
  391. * @skb: To be transmitted
  392. * @dst: Device address of destination
  393. * @returns: 0 on success, <0 on failure
  394. *
  395. * This function can also be called directly (not just from
  396. * hard_start_xmit), so we also check here if the interface is up before
  397. * taking sending anything.
  398. */
  399. int i1480u_xmit_frame(struct wlp *wlp, struct sk_buff *skb,
  400. struct uwb_dev_addr *dst)
  401. {
  402. int result = -ENXIO;
  403. struct i1480u *i1480u = container_of(wlp, struct i1480u, wlp);
  404. struct device *dev = &i1480u->usb_iface->dev;
  405. struct net_device *net_dev = i1480u->net_dev;
  406. struct i1480u_tx *wtx;
  407. struct wlp_tx_hdr *wlp_tx_hdr;
  408. static unsigned char dev_bcast[2] = { 0xff, 0xff };
  409. BUG_ON(i1480u->wlp.rc == NULL);
  410. if ((net_dev->flags & IFF_UP) == 0)
  411. goto out;
  412. result = -EBUSY;
  413. if (atomic_read(&i1480u->tx_inflight.count) >= i1480u->tx_inflight.max) {
  414. netif_stop_queue(net_dev);
  415. goto error_max_inflight;
  416. }
  417. result = -ENOMEM;
  418. wtx = i1480u_tx_create(i1480u, skb, GFP_ATOMIC);
  419. if (unlikely(wtx == NULL)) {
  420. if (printk_ratelimit())
  421. dev_err(dev, "TX: no memory for WLP TX URB,"
  422. "dropping packet (in flight %d)\n",
  423. atomic_read(&i1480u->tx_inflight.count));
  424. netif_stop_queue(net_dev);
  425. goto error_wtx_alloc;
  426. }
  427. wtx->i1480u = i1480u;
  428. /* Fill out the i1480 header; @i1480u->def_tx_hdr read without
  429. * locking. We do so because they are kind of orthogonal to
  430. * each other (and thus not changed in an atomic batch).
  431. * The ETH header is right after the WLP TX header. */
  432. wlp_tx_hdr = wtx->wlp_tx_hdr;
  433. *wlp_tx_hdr = i1480u->options.def_tx_hdr;
  434. wlp_tx_hdr->dstaddr = *dst;
  435. if (!memcmp(&wlp_tx_hdr->dstaddr, dev_bcast, sizeof(dev_bcast))
  436. && (wlp_tx_hdr_delivery_id_type(wlp_tx_hdr) & WLP_DRP)) {
  437. /*Broadcast message directed to DRP host. Send as best effort
  438. * on PCA. */
  439. wlp_tx_hdr_set_delivery_id_type(wlp_tx_hdr, i1480u->options.pca_base_priority);
  440. }
  441. result = usb_submit_urb(wtx->urb, GFP_ATOMIC); /* Go baby */
  442. if (result < 0) {
  443. dev_err(dev, "TX: cannot submit URB: %d\n", result);
  444. /* We leave the freeing of skb to calling function */
  445. wtx->skb = NULL;
  446. goto error_tx_urb_submit;
  447. }
  448. atomic_inc(&i1480u->tx_inflight.count);
  449. net_dev->trans_start = jiffies;
  450. return result;
  451. error_tx_urb_submit:
  452. i1480u_tx_destroy(i1480u, wtx);
  453. error_wtx_alloc:
  454. error_max_inflight:
  455. out:
  456. return result;
  457. }
  458. /*
  459. * Transmit an skb Called when an skbuf has to be transmitted
  460. *
  461. * The skb is first passed to WLP substack to ensure this is a valid
  462. * frame. If valid the device address of destination will be filled and
  463. * the WLP header prepended to the skb. If this step fails we fake sending
  464. * the frame, if we return an error the network stack will just keep trying.
  465. *
  466. * Broadcast frames inside a WSS needs to be treated special as multicast is
  467. * not supported. A broadcast frame is sent as unicast to each member of the
  468. * WSS - this is done by the WLP substack when it finds a broadcast frame.
  469. * So, we test if the WLP substack took over the skb and only transmit it
  470. * if it has not (been taken over).
  471. *
  472. * @net_dev->xmit_lock is held
  473. */
  474. netdev_tx_t i1480u_hard_start_xmit(struct sk_buff *skb,
  475. struct net_device *net_dev)
  476. {
  477. int result;
  478. struct i1480u *i1480u = netdev_priv(net_dev);
  479. struct device *dev = &i1480u->usb_iface->dev;
  480. struct uwb_dev_addr dst;
  481. if ((net_dev->flags & IFF_UP) == 0)
  482. goto error;
  483. result = wlp_prepare_tx_frame(dev, &i1480u->wlp, skb, &dst);
  484. if (result < 0) {
  485. dev_err(dev, "WLP verification of TX frame failed (%d). "
  486. "Dropping packet.\n", result);
  487. goto error;
  488. } else if (result == 1) {
  489. /* trans_start time will be set when WLP actually transmits
  490. * the frame */
  491. goto out;
  492. }
  493. result = i1480u_xmit_frame(&i1480u->wlp, skb, &dst);
  494. if (result < 0) {
  495. dev_err(dev, "Frame TX failed (%d).\n", result);
  496. goto error;
  497. }
  498. return NETDEV_TX_OK;
  499. error:
  500. dev_kfree_skb_any(skb);
  501. net_dev->stats.tx_dropped++;
  502. out:
  503. return NETDEV_TX_OK;
  504. }
  505. /*
  506. * Called when a pkt transmission doesn't complete in a reasonable period
  507. * Device reset may sleep - do it outside of interrupt context (delayed)
  508. */
  509. void i1480u_tx_timeout(struct net_device *net_dev)
  510. {
  511. struct i1480u *i1480u = netdev_priv(net_dev);
  512. wlp_reset_all(&i1480u->wlp);
  513. }
  514. void i1480u_tx_release(struct i1480u *i1480u)
  515. {
  516. unsigned long flags;
  517. struct i1480u_tx *wtx, *next;
  518. int count = 0, empty;
  519. spin_lock_irqsave(&i1480u->tx_list_lock, flags);
  520. list_for_each_entry_safe(wtx, next, &i1480u->tx_list, list_node) {
  521. count++;
  522. usb_unlink_urb(wtx->urb);
  523. }
  524. spin_unlock_irqrestore(&i1480u->tx_list_lock, flags);
  525. count = count*10; /* i1480ut 200ms per unlinked urb (intervals of 20ms) */
  526. /*
  527. * We don't like this sollution too much (dirty as it is), but
  528. * it is cheaper than putting a refcount on each i1480u_tx and
  529. * i1480uting for all of them to go away...
  530. *
  531. * Called when no more packets can be added to tx_list
  532. * so can i1480ut for it to be empty.
  533. */
  534. while (1) {
  535. spin_lock_irqsave(&i1480u->tx_list_lock, flags);
  536. empty = list_empty(&i1480u->tx_list);
  537. spin_unlock_irqrestore(&i1480u->tx_list_lock, flags);
  538. if (empty)
  539. break;
  540. count--;
  541. BUG_ON(count == 0);
  542. msleep(20);
  543. }
  544. }