pio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. Broadcom B43legacy wireless driver
  3. PIO Transmission
  4. Copyright (c) 2005 Michael Buesch <mb@bu3sch.de>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "b43legacy.h"
  19. #include "pio.h"
  20. #include "main.h"
  21. #include "xmit.h"
  22. #include <linux/delay.h>
  23. static void tx_start(struct b43legacy_pioqueue *queue)
  24. {
  25. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  26. B43legacy_PIO_TXCTL_INIT);
  27. }
  28. static void tx_octet(struct b43legacy_pioqueue *queue,
  29. u8 octet)
  30. {
  31. if (queue->need_workarounds) {
  32. b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet);
  33. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  34. B43legacy_PIO_TXCTL_WRITELO);
  35. } else {
  36. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  37. B43legacy_PIO_TXCTL_WRITELO);
  38. b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, octet);
  39. }
  40. }
  41. static u16 tx_get_next_word(const u8 *txhdr,
  42. const u8 *packet,
  43. size_t txhdr_size,
  44. unsigned int *pos)
  45. {
  46. const u8 *source;
  47. unsigned int i = *pos;
  48. u16 ret;
  49. if (i < txhdr_size)
  50. source = txhdr;
  51. else {
  52. source = packet;
  53. i -= txhdr_size;
  54. }
  55. ret = le16_to_cpu(*((__le16 *)(source + i)));
  56. *pos += 2;
  57. return ret;
  58. }
  59. static void tx_data(struct b43legacy_pioqueue *queue,
  60. u8 *txhdr,
  61. const u8 *packet,
  62. unsigned int octets)
  63. {
  64. u16 data;
  65. unsigned int i = 0;
  66. if (queue->need_workarounds) {
  67. data = tx_get_next_word(txhdr, packet,
  68. sizeof(struct b43legacy_txhdr_fw3), &i);
  69. b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data);
  70. }
  71. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  72. B43legacy_PIO_TXCTL_WRITELO |
  73. B43legacy_PIO_TXCTL_WRITEHI);
  74. while (i < octets - 1) {
  75. data = tx_get_next_word(txhdr, packet,
  76. sizeof(struct b43legacy_txhdr_fw3), &i);
  77. b43legacy_pio_write(queue, B43legacy_PIO_TXDATA, data);
  78. }
  79. if (octets % 2)
  80. tx_octet(queue, packet[octets -
  81. sizeof(struct b43legacy_txhdr_fw3) - 1]);
  82. }
  83. static void tx_complete(struct b43legacy_pioqueue *queue,
  84. struct sk_buff *skb)
  85. {
  86. if (queue->need_workarounds) {
  87. b43legacy_pio_write(queue, B43legacy_PIO_TXDATA,
  88. skb->data[skb->len - 1]);
  89. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  90. B43legacy_PIO_TXCTL_WRITELO |
  91. B43legacy_PIO_TXCTL_COMPLETE);
  92. } else
  93. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  94. B43legacy_PIO_TXCTL_COMPLETE);
  95. }
  96. static u16 generate_cookie(struct b43legacy_pioqueue *queue,
  97. struct b43legacy_pio_txpacket *packet)
  98. {
  99. u16 cookie = 0x0000;
  100. int packetindex;
  101. /* We use the upper 4 bits for the PIO
  102. * controller ID and the lower 12 bits
  103. * for the packet index (in the cache).
  104. */
  105. switch (queue->mmio_base) {
  106. case B43legacy_MMIO_PIO1_BASE:
  107. break;
  108. case B43legacy_MMIO_PIO2_BASE:
  109. cookie = 0x1000;
  110. break;
  111. case B43legacy_MMIO_PIO3_BASE:
  112. cookie = 0x2000;
  113. break;
  114. case B43legacy_MMIO_PIO4_BASE:
  115. cookie = 0x3000;
  116. break;
  117. default:
  118. B43legacy_WARN_ON(1);
  119. }
  120. packetindex = pio_txpacket_getindex(packet);
  121. B43legacy_WARN_ON(!(((u16)packetindex & 0xF000) == 0x0000));
  122. cookie |= (u16)packetindex;
  123. return cookie;
  124. }
  125. static
  126. struct b43legacy_pioqueue *parse_cookie(struct b43legacy_wldev *dev,
  127. u16 cookie,
  128. struct b43legacy_pio_txpacket **packet)
  129. {
  130. struct b43legacy_pio *pio = &dev->pio;
  131. struct b43legacy_pioqueue *queue = NULL;
  132. int packetindex;
  133. switch (cookie & 0xF000) {
  134. case 0x0000:
  135. queue = pio->queue0;
  136. break;
  137. case 0x1000:
  138. queue = pio->queue1;
  139. break;
  140. case 0x2000:
  141. queue = pio->queue2;
  142. break;
  143. case 0x3000:
  144. queue = pio->queue3;
  145. break;
  146. default:
  147. B43legacy_WARN_ON(1);
  148. }
  149. packetindex = (cookie & 0x0FFF);
  150. B43legacy_WARN_ON(!(packetindex >= 0 && packetindex
  151. < B43legacy_PIO_MAXTXPACKETS));
  152. *packet = &(queue->tx_packets_cache[packetindex]);
  153. return queue;
  154. }
  155. union txhdr_union {
  156. struct b43legacy_txhdr_fw3 txhdr_fw3;
  157. };
  158. static int pio_tx_write_fragment(struct b43legacy_pioqueue *queue,
  159. struct sk_buff *skb,
  160. struct b43legacy_pio_txpacket *packet,
  161. size_t txhdr_size)
  162. {
  163. union txhdr_union txhdr_data;
  164. u8 *txhdr = NULL;
  165. unsigned int octets;
  166. int err;
  167. txhdr = (u8 *)(&txhdr_data.txhdr_fw3);
  168. B43legacy_WARN_ON(skb_shinfo(skb)->nr_frags != 0);
  169. err = b43legacy_generate_txhdr(queue->dev,
  170. txhdr, skb->data, skb->len,
  171. IEEE80211_SKB_CB(skb),
  172. generate_cookie(queue, packet));
  173. if (err)
  174. return err;
  175. tx_start(queue);
  176. octets = skb->len + txhdr_size;
  177. if (queue->need_workarounds)
  178. octets--;
  179. tx_data(queue, txhdr, (u8 *)skb->data, octets);
  180. tx_complete(queue, skb);
  181. return 0;
  182. }
  183. static void free_txpacket(struct b43legacy_pio_txpacket *packet,
  184. int irq_context)
  185. {
  186. struct b43legacy_pioqueue *queue = packet->queue;
  187. if (packet->skb) {
  188. if (irq_context)
  189. dev_kfree_skb_irq(packet->skb);
  190. else
  191. dev_kfree_skb(packet->skb);
  192. }
  193. list_move(&packet->list, &queue->txfree);
  194. queue->nr_txfree++;
  195. }
  196. static int pio_tx_packet(struct b43legacy_pio_txpacket *packet)
  197. {
  198. struct b43legacy_pioqueue *queue = packet->queue;
  199. struct sk_buff *skb = packet->skb;
  200. u16 octets;
  201. int err;
  202. octets = (u16)skb->len + sizeof(struct b43legacy_txhdr_fw3);
  203. if (queue->tx_devq_size < octets) {
  204. b43legacywarn(queue->dev->wl, "PIO queue too small. "
  205. "Dropping packet.\n");
  206. /* Drop it silently (return success) */
  207. free_txpacket(packet, 1);
  208. return 0;
  209. }
  210. B43legacy_WARN_ON(queue->tx_devq_packets >
  211. B43legacy_PIO_MAXTXDEVQPACKETS);
  212. B43legacy_WARN_ON(queue->tx_devq_used > queue->tx_devq_size);
  213. /* Check if there is sufficient free space on the device
  214. * TX queue. If not, return and let the TX tasklet
  215. * retry later.
  216. */
  217. if (queue->tx_devq_packets == B43legacy_PIO_MAXTXDEVQPACKETS)
  218. return -EBUSY;
  219. if (queue->tx_devq_used + octets > queue->tx_devq_size)
  220. return -EBUSY;
  221. /* Now poke the device. */
  222. err = pio_tx_write_fragment(queue, skb, packet,
  223. sizeof(struct b43legacy_txhdr_fw3));
  224. if (unlikely(err == -ENOKEY)) {
  225. /* Drop this packet, as we don't have the encryption key
  226. * anymore and must not transmit it unencrypted. */
  227. free_txpacket(packet, 1);
  228. return 0;
  229. }
  230. /* Account for the packet size.
  231. * (We must not overflow the device TX queue)
  232. */
  233. queue->tx_devq_packets++;
  234. queue->tx_devq_used += octets;
  235. /* Transmission started, everything ok, move the
  236. * packet to the txrunning list.
  237. */
  238. list_move_tail(&packet->list, &queue->txrunning);
  239. return 0;
  240. }
  241. static void tx_tasklet(unsigned long d)
  242. {
  243. struct b43legacy_pioqueue *queue = (struct b43legacy_pioqueue *)d;
  244. struct b43legacy_wldev *dev = queue->dev;
  245. unsigned long flags;
  246. struct b43legacy_pio_txpacket *packet, *tmp_packet;
  247. int err;
  248. u16 txctl;
  249. spin_lock_irqsave(&dev->wl->irq_lock, flags);
  250. if (queue->tx_frozen)
  251. goto out_unlock;
  252. txctl = b43legacy_pio_read(queue, B43legacy_PIO_TXCTL);
  253. if (txctl & B43legacy_PIO_TXCTL_SUSPEND)
  254. goto out_unlock;
  255. list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) {
  256. /* Try to transmit the packet. This can fail, if
  257. * the device queue is full. In case of failure, the
  258. * packet is left in the txqueue.
  259. * If transmission succeed, the packet is moved to txrunning.
  260. * If it is impossible to transmit the packet, it
  261. * is dropped.
  262. */
  263. err = pio_tx_packet(packet);
  264. if (err)
  265. break;
  266. }
  267. out_unlock:
  268. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  269. }
  270. static void setup_txqueues(struct b43legacy_pioqueue *queue)
  271. {
  272. struct b43legacy_pio_txpacket *packet;
  273. int i;
  274. queue->nr_txfree = B43legacy_PIO_MAXTXPACKETS;
  275. for (i = 0; i < B43legacy_PIO_MAXTXPACKETS; i++) {
  276. packet = &(queue->tx_packets_cache[i]);
  277. packet->queue = queue;
  278. INIT_LIST_HEAD(&packet->list);
  279. list_add(&packet->list, &queue->txfree);
  280. }
  281. }
  282. static
  283. struct b43legacy_pioqueue *b43legacy_setup_pioqueue(struct b43legacy_wldev *dev,
  284. u16 pio_mmio_base)
  285. {
  286. struct b43legacy_pioqueue *queue;
  287. u32 value;
  288. u16 qsize;
  289. queue = kzalloc(sizeof(*queue), GFP_KERNEL);
  290. if (!queue)
  291. goto out;
  292. queue->dev = dev;
  293. queue->mmio_base = pio_mmio_base;
  294. queue->need_workarounds = (dev->dev->id.revision < 3);
  295. INIT_LIST_HEAD(&queue->txfree);
  296. INIT_LIST_HEAD(&queue->txqueue);
  297. INIT_LIST_HEAD(&queue->txrunning);
  298. tasklet_init(&queue->txtask, tx_tasklet,
  299. (unsigned long)queue);
  300. value = b43legacy_read32(dev, B43legacy_MMIO_MACCTL);
  301. value &= ~B43legacy_MACCTL_BE;
  302. b43legacy_write32(dev, B43legacy_MMIO_MACCTL, value);
  303. qsize = b43legacy_read16(dev, queue->mmio_base
  304. + B43legacy_PIO_TXQBUFSIZE);
  305. if (qsize == 0) {
  306. b43legacyerr(dev->wl, "This card does not support PIO "
  307. "operation mode. Please use DMA mode "
  308. "(module parameter pio=0).\n");
  309. goto err_freequeue;
  310. }
  311. if (qsize <= B43legacy_PIO_TXQADJUST) {
  312. b43legacyerr(dev->wl, "PIO tx device-queue too small (%u)\n",
  313. qsize);
  314. goto err_freequeue;
  315. }
  316. qsize -= B43legacy_PIO_TXQADJUST;
  317. queue->tx_devq_size = qsize;
  318. setup_txqueues(queue);
  319. out:
  320. return queue;
  321. err_freequeue:
  322. kfree(queue);
  323. queue = NULL;
  324. goto out;
  325. }
  326. static void cancel_transfers(struct b43legacy_pioqueue *queue)
  327. {
  328. struct b43legacy_pio_txpacket *packet, *tmp_packet;
  329. tasklet_disable(&queue->txtask);
  330. list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list)
  331. free_txpacket(packet, 0);
  332. list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list)
  333. free_txpacket(packet, 0);
  334. }
  335. static void b43legacy_destroy_pioqueue(struct b43legacy_pioqueue *queue)
  336. {
  337. if (!queue)
  338. return;
  339. cancel_transfers(queue);
  340. kfree(queue);
  341. }
  342. void b43legacy_pio_free(struct b43legacy_wldev *dev)
  343. {
  344. struct b43legacy_pio *pio;
  345. if (!b43legacy_using_pio(dev))
  346. return;
  347. pio = &dev->pio;
  348. b43legacy_destroy_pioqueue(pio->queue3);
  349. pio->queue3 = NULL;
  350. b43legacy_destroy_pioqueue(pio->queue2);
  351. pio->queue2 = NULL;
  352. b43legacy_destroy_pioqueue(pio->queue1);
  353. pio->queue1 = NULL;
  354. b43legacy_destroy_pioqueue(pio->queue0);
  355. pio->queue0 = NULL;
  356. }
  357. int b43legacy_pio_init(struct b43legacy_wldev *dev)
  358. {
  359. struct b43legacy_pio *pio = &dev->pio;
  360. struct b43legacy_pioqueue *queue;
  361. int err = -ENOMEM;
  362. queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO1_BASE);
  363. if (!queue)
  364. goto out;
  365. pio->queue0 = queue;
  366. queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO2_BASE);
  367. if (!queue)
  368. goto err_destroy0;
  369. pio->queue1 = queue;
  370. queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO3_BASE);
  371. if (!queue)
  372. goto err_destroy1;
  373. pio->queue2 = queue;
  374. queue = b43legacy_setup_pioqueue(dev, B43legacy_MMIO_PIO4_BASE);
  375. if (!queue)
  376. goto err_destroy2;
  377. pio->queue3 = queue;
  378. if (dev->dev->id.revision < 3)
  379. dev->irq_mask |= B43legacy_IRQ_PIO_WORKAROUND;
  380. b43legacydbg(dev->wl, "PIO initialized\n");
  381. err = 0;
  382. out:
  383. return err;
  384. err_destroy2:
  385. b43legacy_destroy_pioqueue(pio->queue2);
  386. pio->queue2 = NULL;
  387. err_destroy1:
  388. b43legacy_destroy_pioqueue(pio->queue1);
  389. pio->queue1 = NULL;
  390. err_destroy0:
  391. b43legacy_destroy_pioqueue(pio->queue0);
  392. pio->queue0 = NULL;
  393. goto out;
  394. }
  395. int b43legacy_pio_tx(struct b43legacy_wldev *dev,
  396. struct sk_buff *skb)
  397. {
  398. struct b43legacy_pioqueue *queue = dev->pio.queue1;
  399. struct b43legacy_pio_txpacket *packet;
  400. B43legacy_WARN_ON(queue->tx_suspended);
  401. B43legacy_WARN_ON(list_empty(&queue->txfree));
  402. packet = list_entry(queue->txfree.next, struct b43legacy_pio_txpacket,
  403. list);
  404. packet->skb = skb;
  405. list_move_tail(&packet->list, &queue->txqueue);
  406. queue->nr_txfree--;
  407. B43legacy_WARN_ON(queue->nr_txfree >= B43legacy_PIO_MAXTXPACKETS);
  408. tasklet_schedule(&queue->txtask);
  409. return 0;
  410. }
  411. void b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev,
  412. const struct b43legacy_txstatus *status)
  413. {
  414. struct b43legacy_pioqueue *queue;
  415. struct b43legacy_pio_txpacket *packet;
  416. struct ieee80211_tx_info *info;
  417. int retry_limit;
  418. queue = parse_cookie(dev, status->cookie, &packet);
  419. B43legacy_WARN_ON(!queue);
  420. if (!packet->skb)
  421. return;
  422. queue->tx_devq_packets--;
  423. queue->tx_devq_used -= (packet->skb->len +
  424. sizeof(struct b43legacy_txhdr_fw3));
  425. info = IEEE80211_SKB_CB(packet->skb);
  426. /* preserve the confiured retry limit before clearing the status
  427. * The xmit function has overwritten the rc's value with the actual
  428. * retry limit done by the hardware */
  429. retry_limit = info->status.rates[0].count;
  430. ieee80211_tx_info_clear_status(info);
  431. if (status->acked)
  432. info->flags |= IEEE80211_TX_STAT_ACK;
  433. if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
  434. /*
  435. * If the short retries (RTS, not data frame) have exceeded
  436. * the limit, the hw will not have tried the selected rate,
  437. * but will have used the fallback rate instead.
  438. * Don't let the rate control count attempts for the selected
  439. * rate in this case, otherwise the statistics will be off.
  440. */
  441. info->status.rates[0].count = 0;
  442. info->status.rates[1].count = status->frame_count;
  443. } else {
  444. if (status->frame_count > retry_limit) {
  445. info->status.rates[0].count = retry_limit;
  446. info->status.rates[1].count = status->frame_count -
  447. retry_limit;
  448. } else {
  449. info->status.rates[0].count = status->frame_count;
  450. info->status.rates[1].idx = -1;
  451. }
  452. }
  453. ieee80211_tx_status_irqsafe(dev->wl->hw, packet->skb);
  454. packet->skb = NULL;
  455. free_txpacket(packet, 1);
  456. /* If there are packets on the txqueue, poke the tasklet
  457. * to transmit them.
  458. */
  459. if (!list_empty(&queue->txqueue))
  460. tasklet_schedule(&queue->txtask);
  461. }
  462. static void pio_rx_error(struct b43legacy_pioqueue *queue,
  463. int clear_buffers,
  464. const char *error)
  465. {
  466. int i;
  467. b43legacyerr(queue->dev->wl, "PIO RX error: %s\n", error);
  468. b43legacy_pio_write(queue, B43legacy_PIO_RXCTL,
  469. B43legacy_PIO_RXCTL_READY);
  470. if (clear_buffers) {
  471. B43legacy_WARN_ON(queue->mmio_base != B43legacy_MMIO_PIO1_BASE);
  472. for (i = 0; i < 15; i++) {
  473. /* Dummy read. */
  474. b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  475. }
  476. }
  477. }
  478. void b43legacy_pio_rx(struct b43legacy_pioqueue *queue)
  479. {
  480. __le16 preamble[21] = { 0 };
  481. struct b43legacy_rxhdr_fw3 *rxhdr;
  482. u16 tmp;
  483. u16 len;
  484. u16 macstat;
  485. int i;
  486. int preamble_readwords;
  487. struct sk_buff *skb;
  488. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL);
  489. if (!(tmp & B43legacy_PIO_RXCTL_DATAAVAILABLE))
  490. return;
  491. b43legacy_pio_write(queue, B43legacy_PIO_RXCTL,
  492. B43legacy_PIO_RXCTL_DATAAVAILABLE);
  493. for (i = 0; i < 10; i++) {
  494. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL);
  495. if (tmp & B43legacy_PIO_RXCTL_READY)
  496. goto data_ready;
  497. udelay(10);
  498. }
  499. b43legacydbg(queue->dev->wl, "PIO RX timed out\n");
  500. return;
  501. data_ready:
  502. len = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  503. if (unlikely(len > 0x700)) {
  504. pio_rx_error(queue, 0, "len > 0x700");
  505. return;
  506. }
  507. if (unlikely(len == 0 && queue->mmio_base !=
  508. B43legacy_MMIO_PIO4_BASE)) {
  509. pio_rx_error(queue, 0, "len == 0");
  510. return;
  511. }
  512. preamble[0] = cpu_to_le16(len);
  513. if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE)
  514. preamble_readwords = 14 / sizeof(u16);
  515. else
  516. preamble_readwords = 18 / sizeof(u16);
  517. for (i = 0; i < preamble_readwords; i++) {
  518. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  519. preamble[i + 1] = cpu_to_le16(tmp);
  520. }
  521. rxhdr = (struct b43legacy_rxhdr_fw3 *)preamble;
  522. macstat = le16_to_cpu(rxhdr->mac_status);
  523. if (macstat & B43legacy_RX_MAC_FCSERR) {
  524. pio_rx_error(queue,
  525. (queue->mmio_base == B43legacy_MMIO_PIO1_BASE),
  526. "Frame FCS error");
  527. return;
  528. }
  529. if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE) {
  530. /* We received an xmit status. */
  531. struct b43legacy_hwtxstatus *hw;
  532. hw = (struct b43legacy_hwtxstatus *)(preamble + 1);
  533. b43legacy_handle_hwtxstatus(queue->dev, hw);
  534. return;
  535. }
  536. skb = dev_alloc_skb(len);
  537. if (unlikely(!skb)) {
  538. pio_rx_error(queue, 1, "OOM");
  539. return;
  540. }
  541. skb_put(skb, len);
  542. for (i = 0; i < len - 1; i += 2) {
  543. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  544. *((__le16 *)(skb->data + i)) = cpu_to_le16(tmp);
  545. }
  546. if (len % 2) {
  547. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  548. skb->data[len - 1] = (tmp & 0x00FF);
  549. }
  550. b43legacy_rx(queue->dev, skb, rxhdr);
  551. }
  552. void b43legacy_pio_tx_suspend(struct b43legacy_pioqueue *queue)
  553. {
  554. b43legacy_power_saving_ctl_bits(queue->dev, -1, 1);
  555. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  556. b43legacy_pio_read(queue, B43legacy_PIO_TXCTL)
  557. | B43legacy_PIO_TXCTL_SUSPEND);
  558. }
  559. void b43legacy_pio_tx_resume(struct b43legacy_pioqueue *queue)
  560. {
  561. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  562. b43legacy_pio_read(queue, B43legacy_PIO_TXCTL)
  563. & ~B43legacy_PIO_TXCTL_SUSPEND);
  564. b43legacy_power_saving_ctl_bits(queue->dev, -1, -1);
  565. tasklet_schedule(&queue->txtask);
  566. }
  567. void b43legacy_pio_freeze_txqueues(struct b43legacy_wldev *dev)
  568. {
  569. struct b43legacy_pio *pio;
  570. B43legacy_WARN_ON(!b43legacy_using_pio(dev));
  571. pio = &dev->pio;
  572. pio->queue0->tx_frozen = 1;
  573. pio->queue1->tx_frozen = 1;
  574. pio->queue2->tx_frozen = 1;
  575. pio->queue3->tx_frozen = 1;
  576. }
  577. void b43legacy_pio_thaw_txqueues(struct b43legacy_wldev *dev)
  578. {
  579. struct b43legacy_pio *pio;
  580. B43legacy_WARN_ON(!b43legacy_using_pio(dev));
  581. pio = &dev->pio;
  582. pio->queue0->tx_frozen = 0;
  583. pio->queue1->tx_frozen = 0;
  584. pio->queue2->tx_frozen = 0;
  585. pio->queue3->tx_frozen = 0;
  586. if (!list_empty(&pio->queue0->txqueue))
  587. tasklet_schedule(&pio->queue0->txtask);
  588. if (!list_empty(&pio->queue1->txqueue))
  589. tasklet_schedule(&pio->queue1->txtask);
  590. if (!list_empty(&pio->queue2->txqueue))
  591. tasklet_schedule(&pio->queue2->txtask);
  592. if (!list_empty(&pio->queue3->txqueue))
  593. tasklet_schedule(&pio->queue3->txtask);
  594. }