pio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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_savedstate |= 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. queue->nr_tx_packets++;
  408. B43legacy_WARN_ON(queue->nr_txfree >= B43legacy_PIO_MAXTXPACKETS);
  409. tasklet_schedule(&queue->txtask);
  410. return 0;
  411. }
  412. void b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev,
  413. const struct b43legacy_txstatus *status)
  414. {
  415. struct b43legacy_pioqueue *queue;
  416. struct b43legacy_pio_txpacket *packet;
  417. struct ieee80211_tx_info *info;
  418. int retry_limit;
  419. queue = parse_cookie(dev, status->cookie, &packet);
  420. B43legacy_WARN_ON(!queue);
  421. if (!packet->skb)
  422. return;
  423. queue->tx_devq_packets--;
  424. queue->tx_devq_used -= (packet->skb->len +
  425. sizeof(struct b43legacy_txhdr_fw3));
  426. info = IEEE80211_SKB_CB(packet->skb);
  427. /* preserve the confiured retry limit before clearing the status
  428. * The xmit function has overwritten the rc's value with the actual
  429. * retry limit done by the hardware */
  430. retry_limit = info->status.rates[0].count;
  431. ieee80211_tx_info_clear_status(info);
  432. if (status->acked)
  433. info->flags |= IEEE80211_TX_STAT_ACK;
  434. if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
  435. /*
  436. * If the short retries (RTS, not data frame) have exceeded
  437. * the limit, the hw will not have tried the selected rate,
  438. * but will have used the fallback rate instead.
  439. * Don't let the rate control count attempts for the selected
  440. * rate in this case, otherwise the statistics will be off.
  441. */
  442. info->status.rates[0].count = 0;
  443. info->status.rates[1].count = status->frame_count;
  444. } else {
  445. if (status->frame_count > retry_limit) {
  446. info->status.rates[0].count = retry_limit;
  447. info->status.rates[1].count = status->frame_count -
  448. retry_limit;
  449. } else {
  450. info->status.rates[0].count = status->frame_count;
  451. info->status.rates[1].idx = -1;
  452. }
  453. }
  454. ieee80211_tx_status_irqsafe(dev->wl->hw, packet->skb);
  455. packet->skb = NULL;
  456. free_txpacket(packet, 1);
  457. /* If there are packets on the txqueue, poke the tasklet
  458. * to transmit them.
  459. */
  460. if (!list_empty(&queue->txqueue))
  461. tasklet_schedule(&queue->txtask);
  462. }
  463. void b43legacy_pio_get_tx_stats(struct b43legacy_wldev *dev,
  464. struct ieee80211_tx_queue_stats *stats)
  465. {
  466. struct b43legacy_pio *pio = &dev->pio;
  467. struct b43legacy_pioqueue *queue;
  468. queue = pio->queue1;
  469. stats[0].len = B43legacy_PIO_MAXTXPACKETS - queue->nr_txfree;
  470. stats[0].limit = B43legacy_PIO_MAXTXPACKETS;
  471. stats[0].count = queue->nr_tx_packets;
  472. }
  473. static void pio_rx_error(struct b43legacy_pioqueue *queue,
  474. int clear_buffers,
  475. const char *error)
  476. {
  477. int i;
  478. b43legacyerr(queue->dev->wl, "PIO RX error: %s\n", error);
  479. b43legacy_pio_write(queue, B43legacy_PIO_RXCTL,
  480. B43legacy_PIO_RXCTL_READY);
  481. if (clear_buffers) {
  482. B43legacy_WARN_ON(queue->mmio_base != B43legacy_MMIO_PIO1_BASE);
  483. for (i = 0; i < 15; i++) {
  484. /* Dummy read. */
  485. b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  486. }
  487. }
  488. }
  489. void b43legacy_pio_rx(struct b43legacy_pioqueue *queue)
  490. {
  491. __le16 preamble[21] = { 0 };
  492. struct b43legacy_rxhdr_fw3 *rxhdr;
  493. u16 tmp;
  494. u16 len;
  495. u16 macstat;
  496. int i;
  497. int preamble_readwords;
  498. struct sk_buff *skb;
  499. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL);
  500. if (!(tmp & B43legacy_PIO_RXCTL_DATAAVAILABLE))
  501. return;
  502. b43legacy_pio_write(queue, B43legacy_PIO_RXCTL,
  503. B43legacy_PIO_RXCTL_DATAAVAILABLE);
  504. for (i = 0; i < 10; i++) {
  505. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXCTL);
  506. if (tmp & B43legacy_PIO_RXCTL_READY)
  507. goto data_ready;
  508. udelay(10);
  509. }
  510. b43legacydbg(queue->dev->wl, "PIO RX timed out\n");
  511. return;
  512. data_ready:
  513. len = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  514. if (unlikely(len > 0x700)) {
  515. pio_rx_error(queue, 0, "len > 0x700");
  516. return;
  517. }
  518. if (unlikely(len == 0 && queue->mmio_base !=
  519. B43legacy_MMIO_PIO4_BASE)) {
  520. pio_rx_error(queue, 0, "len == 0");
  521. return;
  522. }
  523. preamble[0] = cpu_to_le16(len);
  524. if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE)
  525. preamble_readwords = 14 / sizeof(u16);
  526. else
  527. preamble_readwords = 18 / sizeof(u16);
  528. for (i = 0; i < preamble_readwords; i++) {
  529. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  530. preamble[i + 1] = cpu_to_le16(tmp);
  531. }
  532. rxhdr = (struct b43legacy_rxhdr_fw3 *)preamble;
  533. macstat = le16_to_cpu(rxhdr->mac_status);
  534. if (macstat & B43legacy_RX_MAC_FCSERR) {
  535. pio_rx_error(queue,
  536. (queue->mmio_base == B43legacy_MMIO_PIO1_BASE),
  537. "Frame FCS error");
  538. return;
  539. }
  540. if (queue->mmio_base == B43legacy_MMIO_PIO4_BASE) {
  541. /* We received an xmit status. */
  542. struct b43legacy_hwtxstatus *hw;
  543. hw = (struct b43legacy_hwtxstatus *)(preamble + 1);
  544. b43legacy_handle_hwtxstatus(queue->dev, hw);
  545. return;
  546. }
  547. skb = dev_alloc_skb(len);
  548. if (unlikely(!skb)) {
  549. pio_rx_error(queue, 1, "OOM");
  550. return;
  551. }
  552. skb_put(skb, len);
  553. for (i = 0; i < len - 1; i += 2) {
  554. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  555. *((__le16 *)(skb->data + i)) = cpu_to_le16(tmp);
  556. }
  557. if (len % 2) {
  558. tmp = b43legacy_pio_read(queue, B43legacy_PIO_RXDATA);
  559. skb->data[len - 1] = (tmp & 0x00FF);
  560. }
  561. b43legacy_rx(queue->dev, skb, rxhdr);
  562. }
  563. void b43legacy_pio_tx_suspend(struct b43legacy_pioqueue *queue)
  564. {
  565. b43legacy_power_saving_ctl_bits(queue->dev, -1, 1);
  566. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  567. b43legacy_pio_read(queue, B43legacy_PIO_TXCTL)
  568. | B43legacy_PIO_TXCTL_SUSPEND);
  569. }
  570. void b43legacy_pio_tx_resume(struct b43legacy_pioqueue *queue)
  571. {
  572. b43legacy_pio_write(queue, B43legacy_PIO_TXCTL,
  573. b43legacy_pio_read(queue, B43legacy_PIO_TXCTL)
  574. & ~B43legacy_PIO_TXCTL_SUSPEND);
  575. b43legacy_power_saving_ctl_bits(queue->dev, -1, -1);
  576. tasklet_schedule(&queue->txtask);
  577. }
  578. void b43legacy_pio_freeze_txqueues(struct b43legacy_wldev *dev)
  579. {
  580. struct b43legacy_pio *pio;
  581. B43legacy_WARN_ON(!b43legacy_using_pio(dev));
  582. pio = &dev->pio;
  583. pio->queue0->tx_frozen = 1;
  584. pio->queue1->tx_frozen = 1;
  585. pio->queue2->tx_frozen = 1;
  586. pio->queue3->tx_frozen = 1;
  587. }
  588. void b43legacy_pio_thaw_txqueues(struct b43legacy_wldev *dev)
  589. {
  590. struct b43legacy_pio *pio;
  591. B43legacy_WARN_ON(!b43legacy_using_pio(dev));
  592. pio = &dev->pio;
  593. pio->queue0->tx_frozen = 0;
  594. pio->queue1->tx_frozen = 0;
  595. pio->queue2->tx_frozen = 0;
  596. pio->queue3->tx_frozen = 0;
  597. if (!list_empty(&pio->queue0->txqueue))
  598. tasklet_schedule(&pio->queue0->txtask);
  599. if (!list_empty(&pio->queue1->txqueue))
  600. tasklet_schedule(&pio->queue1->txtask);
  601. if (!list_empty(&pio->queue2->txqueue))
  602. tasklet_schedule(&pio->queue2->txtask);
  603. if (!list_empty(&pio->queue3->txqueue))
  604. tasklet_schedule(&pio->queue3->txtask);
  605. }