iwl-tx.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/etherdevice.h>
  30. #include <linux/sched.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-sta.h"
  36. #include "iwl-io.h"
  37. #include "iwl-helpers.h"
  38. static const u16 default_tid_to_tx_fifo[] = {
  39. IWL_TX_FIFO_AC1,
  40. IWL_TX_FIFO_AC0,
  41. IWL_TX_FIFO_AC0,
  42. IWL_TX_FIFO_AC1,
  43. IWL_TX_FIFO_AC2,
  44. IWL_TX_FIFO_AC2,
  45. IWL_TX_FIFO_AC3,
  46. IWL_TX_FIFO_AC3,
  47. IWL_TX_FIFO_NONE,
  48. IWL_TX_FIFO_NONE,
  49. IWL_TX_FIFO_NONE,
  50. IWL_TX_FIFO_NONE,
  51. IWL_TX_FIFO_NONE,
  52. IWL_TX_FIFO_NONE,
  53. IWL_TX_FIFO_NONE,
  54. IWL_TX_FIFO_NONE,
  55. IWL_TX_FIFO_AC3
  56. };
  57. static inline int iwl_alloc_dma_ptr(struct iwl_priv *priv,
  58. struct iwl_dma_ptr *ptr, size_t size)
  59. {
  60. ptr->addr = pci_alloc_consistent(priv->pci_dev, size, &ptr->dma);
  61. if (!ptr->addr)
  62. return -ENOMEM;
  63. ptr->size = size;
  64. return 0;
  65. }
  66. static inline void iwl_free_dma_ptr(struct iwl_priv *priv,
  67. struct iwl_dma_ptr *ptr)
  68. {
  69. if (unlikely(!ptr->addr))
  70. return;
  71. pci_free_consistent(priv->pci_dev, ptr->size, ptr->addr, ptr->dma);
  72. memset(ptr, 0, sizeof(*ptr));
  73. }
  74. /**
  75. * iwl_txq_update_write_ptr - Send new write index to hardware
  76. */
  77. void iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  78. {
  79. u32 reg = 0;
  80. int txq_id = txq->q.id;
  81. if (txq->need_update == 0)
  82. return;
  83. /* if we're trying to save power */
  84. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  85. /* wake up nic if it's powered down ...
  86. * uCode will wake up, and interrupt us again, so next
  87. * time we'll skip this part. */
  88. reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
  89. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  90. IWL_DEBUG_INFO(priv, "Tx queue %d requesting wakeup, GP1 = 0x%x\n",
  91. txq_id, reg);
  92. iwl_set_bit(priv, CSR_GP_CNTRL,
  93. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  94. return;
  95. }
  96. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  97. txq->q.write_ptr | (txq_id << 8));
  98. /* else not in power-save mode, uCode will never sleep when we're
  99. * trying to tx (during RFKILL, we're not trying to tx). */
  100. } else
  101. iwl_write32(priv, HBUS_TARG_WRPTR,
  102. txq->q.write_ptr | (txq_id << 8));
  103. txq->need_update = 0;
  104. }
  105. EXPORT_SYMBOL(iwl_txq_update_write_ptr);
  106. /**
  107. * iwl_tx_queue_free - Deallocate DMA queue.
  108. * @txq: Transmit queue to deallocate.
  109. *
  110. * Empty queue by removing and destroying all BD's.
  111. * Free all buffers.
  112. * 0-fill, but do not free "txq" descriptor structure.
  113. */
  114. void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id)
  115. {
  116. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  117. struct iwl_queue *q = &txq->q;
  118. struct pci_dev *dev = priv->pci_dev;
  119. int i;
  120. if (q->n_bd == 0)
  121. return;
  122. /* first, empty all BD's */
  123. for (; q->write_ptr != q->read_ptr;
  124. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
  125. priv->cfg->ops->lib->txq_free_tfd(priv, txq);
  126. /* De-alloc array of command/tx buffers */
  127. for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
  128. kfree(txq->cmd[i]);
  129. /* De-alloc circular buffer of TFDs */
  130. if (txq->q.n_bd)
  131. pci_free_consistent(dev, priv->hw_params.tfd_size *
  132. txq->q.n_bd, txq->tfds, txq->q.dma_addr);
  133. /* De-alloc array of per-TFD driver data */
  134. kfree(txq->txb);
  135. txq->txb = NULL;
  136. /* deallocate arrays */
  137. kfree(txq->cmd);
  138. kfree(txq->meta);
  139. txq->cmd = NULL;
  140. txq->meta = NULL;
  141. /* 0-fill queue descriptor structure */
  142. memset(txq, 0, sizeof(*txq));
  143. }
  144. EXPORT_SYMBOL(iwl_tx_queue_free);
  145. /**
  146. * iwl_cmd_queue_free - Deallocate DMA queue.
  147. * @txq: Transmit queue to deallocate.
  148. *
  149. * Empty queue by removing and destroying all BD's.
  150. * Free all buffers.
  151. * 0-fill, but do not free "txq" descriptor structure.
  152. */
  153. void iwl_cmd_queue_free(struct iwl_priv *priv)
  154. {
  155. struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  156. struct iwl_queue *q = &txq->q;
  157. struct pci_dev *dev = priv->pci_dev;
  158. int i;
  159. if (q->n_bd == 0)
  160. return;
  161. /* De-alloc array of command/tx buffers */
  162. for (i = 0; i <= TFD_CMD_SLOTS; i++)
  163. kfree(txq->cmd[i]);
  164. /* De-alloc circular buffer of TFDs */
  165. if (txq->q.n_bd)
  166. pci_free_consistent(dev, priv->hw_params.tfd_size *
  167. txq->q.n_bd, txq->tfds, txq->q.dma_addr);
  168. /* deallocate arrays */
  169. kfree(txq->cmd);
  170. kfree(txq->meta);
  171. txq->cmd = NULL;
  172. txq->meta = NULL;
  173. /* 0-fill queue descriptor structure */
  174. memset(txq, 0, sizeof(*txq));
  175. }
  176. EXPORT_SYMBOL(iwl_cmd_queue_free);
  177. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  178. * DMA services
  179. *
  180. * Theory of operation
  181. *
  182. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  183. * of buffer descriptors, each of which points to one or more data buffers for
  184. * the device to read from or fill. Driver and device exchange status of each
  185. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  186. * entries in each circular buffer, to protect against confusing empty and full
  187. * queue states.
  188. *
  189. * The device reads or writes the data in the queues via the device's several
  190. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  191. *
  192. * For Tx queue, there are low mark and high mark limits. If, after queuing
  193. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  194. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  195. * Tx queue resumed.
  196. *
  197. * See more detailed info in iwl-4965-hw.h.
  198. ***************************************************/
  199. int iwl_queue_space(const struct iwl_queue *q)
  200. {
  201. int s = q->read_ptr - q->write_ptr;
  202. if (q->read_ptr > q->write_ptr)
  203. s -= q->n_bd;
  204. if (s <= 0)
  205. s += q->n_window;
  206. /* keep some reserve to not confuse empty and full situations */
  207. s -= 2;
  208. if (s < 0)
  209. s = 0;
  210. return s;
  211. }
  212. EXPORT_SYMBOL(iwl_queue_space);
  213. /**
  214. * iwl_queue_init - Initialize queue's high/low-water and read/write indexes
  215. */
  216. static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
  217. int count, int slots_num, u32 id)
  218. {
  219. q->n_bd = count;
  220. q->n_window = slots_num;
  221. q->id = id;
  222. /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
  223. * and iwl_queue_dec_wrap are broken. */
  224. BUG_ON(!is_power_of_2(count));
  225. /* slots_num must be power-of-two size, otherwise
  226. * get_cmd_index is broken. */
  227. BUG_ON(!is_power_of_2(slots_num));
  228. q->low_mark = q->n_window / 4;
  229. if (q->low_mark < 4)
  230. q->low_mark = 4;
  231. q->high_mark = q->n_window / 8;
  232. if (q->high_mark < 2)
  233. q->high_mark = 2;
  234. q->write_ptr = q->read_ptr = 0;
  235. return 0;
  236. }
  237. /**
  238. * iwl_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  239. */
  240. static int iwl_tx_queue_alloc(struct iwl_priv *priv,
  241. struct iwl_tx_queue *txq, u32 id)
  242. {
  243. struct pci_dev *dev = priv->pci_dev;
  244. size_t tfd_sz = priv->hw_params.tfd_size * TFD_QUEUE_SIZE_MAX;
  245. /* Driver private data, only for Tx (not command) queues,
  246. * not shared with device. */
  247. if (id != IWL_CMD_QUEUE_NUM) {
  248. txq->txb = kmalloc(sizeof(txq->txb[0]) *
  249. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  250. if (!txq->txb) {
  251. IWL_ERR(priv, "kmalloc for auxiliary BD "
  252. "structures failed\n");
  253. goto error;
  254. }
  255. } else {
  256. txq->txb = NULL;
  257. }
  258. /* Circular buffer of transmit frame descriptors (TFDs),
  259. * shared with device */
  260. txq->tfds = pci_alloc_consistent(dev, tfd_sz, &txq->q.dma_addr);
  261. if (!txq->tfds) {
  262. IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", tfd_sz);
  263. goto error;
  264. }
  265. txq->q.id = id;
  266. return 0;
  267. error:
  268. kfree(txq->txb);
  269. txq->txb = NULL;
  270. return -ENOMEM;
  271. }
  272. /**
  273. * iwl_tx_queue_init - Allocate and initialize one tx/cmd queue
  274. */
  275. int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
  276. int slots_num, u32 txq_id)
  277. {
  278. int i, len;
  279. int ret;
  280. int actual_slots = slots_num;
  281. /*
  282. * Alloc buffer array for commands (Tx or other types of commands).
  283. * For the command queue (#4), allocate command space + one big
  284. * command for scan, since scan command is very huge; the system will
  285. * not have two scans at the same time, so only one is needed.
  286. * For normal Tx queues (all other queues), no super-size command
  287. * space is needed.
  288. */
  289. if (txq_id == IWL_CMD_QUEUE_NUM)
  290. actual_slots++;
  291. txq->meta = kzalloc(sizeof(struct iwl_cmd_meta) * actual_slots,
  292. GFP_KERNEL);
  293. txq->cmd = kzalloc(sizeof(struct iwl_device_cmd *) * actual_slots,
  294. GFP_KERNEL);
  295. if (!txq->meta || !txq->cmd)
  296. goto out_free_arrays;
  297. len = sizeof(struct iwl_device_cmd);
  298. for (i = 0; i < actual_slots; i++) {
  299. /* only happens for cmd queue */
  300. if (i == slots_num)
  301. len += IWL_MAX_SCAN_SIZE;
  302. txq->cmd[i] = kmalloc(len, GFP_KERNEL);
  303. if (!txq->cmd[i])
  304. goto err;
  305. }
  306. /* Alloc driver data array and TFD circular buffer */
  307. ret = iwl_tx_queue_alloc(priv, txq, txq_id);
  308. if (ret)
  309. goto err;
  310. txq->need_update = 0;
  311. /*
  312. * Aggregation TX queues will get their ID when aggregation begins;
  313. * they overwrite the setting done here. The command FIFO doesn't
  314. * need an swq_id so don't set one to catch errors, all others can
  315. * be set up to the identity mapping.
  316. */
  317. if (txq_id != IWL_CMD_QUEUE_NUM)
  318. txq->swq_id = txq_id;
  319. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  320. * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
  321. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  322. /* Initialize queue's high/low-water marks, and head/tail indexes */
  323. iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  324. /* Tell device where to find queue */
  325. priv->cfg->ops->lib->txq_init(priv, txq);
  326. return 0;
  327. err:
  328. for (i = 0; i < actual_slots; i++)
  329. kfree(txq->cmd[i]);
  330. out_free_arrays:
  331. kfree(txq->meta);
  332. kfree(txq->cmd);
  333. return -ENOMEM;
  334. }
  335. EXPORT_SYMBOL(iwl_tx_queue_init);
  336. /**
  337. * iwl_hw_txq_ctx_free - Free TXQ Context
  338. *
  339. * Destroy all TX DMA queues and structures
  340. */
  341. void iwl_hw_txq_ctx_free(struct iwl_priv *priv)
  342. {
  343. int txq_id;
  344. /* Tx queues */
  345. if (priv->txq) {
  346. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num;
  347. txq_id++)
  348. if (txq_id == IWL_CMD_QUEUE_NUM)
  349. iwl_cmd_queue_free(priv);
  350. else
  351. iwl_tx_queue_free(priv, txq_id);
  352. }
  353. iwl_free_dma_ptr(priv, &priv->kw);
  354. iwl_free_dma_ptr(priv, &priv->scd_bc_tbls);
  355. /* free tx queue structure */
  356. iwl_free_txq_mem(priv);
  357. }
  358. EXPORT_SYMBOL(iwl_hw_txq_ctx_free);
  359. /**
  360. * iwl_txq_ctx_reset - Reset TX queue context
  361. * Destroys all DMA structures and initialize them again
  362. *
  363. * @param priv
  364. * @return error code
  365. */
  366. int iwl_txq_ctx_reset(struct iwl_priv *priv)
  367. {
  368. int ret = 0;
  369. int txq_id, slots_num;
  370. unsigned long flags;
  371. /* Free all tx/cmd queues and keep-warm buffer */
  372. iwl_hw_txq_ctx_free(priv);
  373. ret = iwl_alloc_dma_ptr(priv, &priv->scd_bc_tbls,
  374. priv->hw_params.scd_bc_tbls_size);
  375. if (ret) {
  376. IWL_ERR(priv, "Scheduler BC Table allocation failed\n");
  377. goto error_bc_tbls;
  378. }
  379. /* Alloc keep-warm buffer */
  380. ret = iwl_alloc_dma_ptr(priv, &priv->kw, IWL_KW_SIZE);
  381. if (ret) {
  382. IWL_ERR(priv, "Keep Warm allocation failed\n");
  383. goto error_kw;
  384. }
  385. /* allocate tx queue structure */
  386. ret = iwl_alloc_txq_mem(priv);
  387. if (ret)
  388. goto error;
  389. spin_lock_irqsave(&priv->lock, flags);
  390. /* Turn off all Tx DMA fifos */
  391. priv->cfg->ops->lib->txq_set_sched(priv, 0);
  392. /* Tell NIC where to find the "keep warm" buffer */
  393. iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG, priv->kw.dma >> 4);
  394. spin_unlock_irqrestore(&priv->lock, flags);
  395. /* Alloc and init all Tx queues, including the command queue (#4) */
  396. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
  397. slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
  398. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  399. ret = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
  400. txq_id);
  401. if (ret) {
  402. IWL_ERR(priv, "Tx %d queue init failed\n", txq_id);
  403. goto error;
  404. }
  405. }
  406. return ret;
  407. error:
  408. iwl_hw_txq_ctx_free(priv);
  409. iwl_free_dma_ptr(priv, &priv->kw);
  410. error_kw:
  411. iwl_free_dma_ptr(priv, &priv->scd_bc_tbls);
  412. error_bc_tbls:
  413. return ret;
  414. }
  415. /**
  416. * iwl_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
  417. */
  418. void iwl_txq_ctx_stop(struct iwl_priv *priv)
  419. {
  420. int ch;
  421. unsigned long flags;
  422. /* Turn off all Tx DMA fifos */
  423. spin_lock_irqsave(&priv->lock, flags);
  424. priv->cfg->ops->lib->txq_set_sched(priv, 0);
  425. /* Stop each Tx DMA channel, and wait for it to be idle */
  426. for (ch = 0; ch < priv->hw_params.dma_chnl_num; ch++) {
  427. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
  428. iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
  429. FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch),
  430. 1000);
  431. }
  432. spin_unlock_irqrestore(&priv->lock, flags);
  433. /* Deallocate memory for all Tx queues */
  434. iwl_hw_txq_ctx_free(priv);
  435. }
  436. EXPORT_SYMBOL(iwl_txq_ctx_stop);
  437. /*
  438. * handle build REPLY_TX command notification.
  439. */
  440. static void iwl_tx_cmd_build_basic(struct iwl_priv *priv,
  441. struct iwl_tx_cmd *tx_cmd,
  442. struct ieee80211_tx_info *info,
  443. struct ieee80211_hdr *hdr,
  444. u8 std_id)
  445. {
  446. __le16 fc = hdr->frame_control;
  447. __le32 tx_flags = tx_cmd->tx_flags;
  448. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  449. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  450. tx_flags |= TX_CMD_FLG_ACK_MSK;
  451. if (ieee80211_is_mgmt(fc))
  452. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  453. if (ieee80211_is_probe_resp(fc) &&
  454. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  455. tx_flags |= TX_CMD_FLG_TSF_MSK;
  456. } else {
  457. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  458. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  459. }
  460. if (ieee80211_is_back_req(fc))
  461. tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
  462. tx_cmd->sta_id = std_id;
  463. if (ieee80211_has_morefrags(fc))
  464. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  465. if (ieee80211_is_data_qos(fc)) {
  466. u8 *qc = ieee80211_get_qos_ctl(hdr);
  467. tx_cmd->tid_tspec = qc[0] & 0xf;
  468. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  469. } else {
  470. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  471. }
  472. priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags);
  473. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  474. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  475. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  476. if (ieee80211_is_mgmt(fc)) {
  477. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  478. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  479. else
  480. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  481. } else {
  482. tx_cmd->timeout.pm_frame_timeout = 0;
  483. }
  484. tx_cmd->driver_txop = 0;
  485. tx_cmd->tx_flags = tx_flags;
  486. tx_cmd->next_frame_len = 0;
  487. }
  488. #define RTS_HCCA_RETRY_LIMIT 3
  489. #define RTS_DFAULT_RETRY_LIMIT 60
  490. static void iwl_tx_cmd_build_rate(struct iwl_priv *priv,
  491. struct iwl_tx_cmd *tx_cmd,
  492. struct ieee80211_tx_info *info,
  493. __le16 fc, int is_hcca)
  494. {
  495. u32 rate_flags;
  496. int rate_idx;
  497. u8 rts_retry_limit;
  498. u8 data_retry_limit;
  499. u8 rate_plcp;
  500. /* Set retry limit on DATA packets and Probe Responses*/
  501. if (ieee80211_is_probe_resp(fc))
  502. data_retry_limit = 3;
  503. else
  504. data_retry_limit = IWL_DEFAULT_TX_RETRY;
  505. tx_cmd->data_retry_limit = data_retry_limit;
  506. /* Set retry limit on RTS packets */
  507. rts_retry_limit = (is_hcca) ? RTS_HCCA_RETRY_LIMIT :
  508. RTS_DFAULT_RETRY_LIMIT;
  509. if (data_retry_limit < rts_retry_limit)
  510. rts_retry_limit = data_retry_limit;
  511. tx_cmd->rts_retry_limit = rts_retry_limit;
  512. /* DATA packets will use the uCode station table for rate/antenna
  513. * selection */
  514. if (ieee80211_is_data(fc)) {
  515. tx_cmd->initial_rate_index = 0;
  516. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  517. return;
  518. }
  519. /**
  520. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  521. * not really a TX rate. Thus, we use the lowest supported rate for
  522. * this band. Also use the lowest supported rate if the stored rate
  523. * index is invalid.
  524. */
  525. rate_idx = info->control.rates[0].idx;
  526. if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
  527. (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
  528. rate_idx = rate_lowest_index(&priv->bands[info->band],
  529. info->control.sta);
  530. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  531. if (info->band == IEEE80211_BAND_5GHZ)
  532. rate_idx += IWL_FIRST_OFDM_RATE;
  533. /* Get PLCP rate for tx_cmd->rate_n_flags */
  534. rate_plcp = iwl_rates[rate_idx].plcp;
  535. /* Zero out flags for this packet */
  536. rate_flags = 0;
  537. /* Set CCK flag as needed */
  538. if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
  539. rate_flags |= RATE_MCS_CCK_MSK;
  540. /* Set up RTS and CTS flags for certain packets */
  541. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  542. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  543. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  544. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  545. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  546. if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
  547. tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  548. tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
  549. }
  550. break;
  551. default:
  552. break;
  553. }
  554. /* Set up antennas */
  555. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant);
  556. rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  557. /* Set the rate in the TX cmd */
  558. tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
  559. }
  560. static void iwl_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
  561. struct ieee80211_tx_info *info,
  562. struct iwl_tx_cmd *tx_cmd,
  563. struct sk_buff *skb_frag,
  564. int sta_id)
  565. {
  566. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  567. switch (keyconf->alg) {
  568. case ALG_CCMP:
  569. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  570. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  571. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  572. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  573. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  574. break;
  575. case ALG_TKIP:
  576. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  577. ieee80211_get_tkip_key(keyconf, skb_frag,
  578. IEEE80211_TKIP_P2_KEY, tx_cmd->key);
  579. IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
  580. break;
  581. case ALG_WEP:
  582. tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
  583. (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
  584. if (keyconf->keylen == WEP_KEY_LEN_128)
  585. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  586. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  587. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  588. "with key %d\n", keyconf->keyidx);
  589. break;
  590. default:
  591. IWL_ERR(priv, "Unknown encode alg %d\n", keyconf->alg);
  592. break;
  593. }
  594. }
  595. /*
  596. * start REPLY_TX command process
  597. */
  598. int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  599. {
  600. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  601. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  602. struct ieee80211_sta *sta = info->control.sta;
  603. struct iwl_station_priv *sta_priv = NULL;
  604. struct iwl_tx_queue *txq;
  605. struct iwl_queue *q;
  606. struct iwl_device_cmd *out_cmd;
  607. struct iwl_cmd_meta *out_meta;
  608. struct iwl_tx_cmd *tx_cmd;
  609. int swq_id, txq_id;
  610. dma_addr_t phys_addr;
  611. dma_addr_t txcmd_phys;
  612. dma_addr_t scratch_phys;
  613. u16 len, len_org, firstlen, secondlen;
  614. u16 seq_number = 0;
  615. __le16 fc;
  616. u8 hdr_len;
  617. u8 sta_id;
  618. u8 wait_write_ptr = 0;
  619. u8 tid = 0;
  620. u8 *qc = NULL;
  621. unsigned long flags;
  622. spin_lock_irqsave(&priv->lock, flags);
  623. if (iwl_is_rfkill(priv)) {
  624. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  625. goto drop_unlock;
  626. }
  627. fc = hdr->frame_control;
  628. #ifdef CONFIG_IWLWIFI_DEBUG
  629. if (ieee80211_is_auth(fc))
  630. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  631. else if (ieee80211_is_assoc_req(fc))
  632. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  633. else if (ieee80211_is_reassoc_req(fc))
  634. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  635. #endif
  636. /* drop all non-injected data frame if we are not associated */
  637. if (ieee80211_is_data(fc) &&
  638. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  639. (!iwl_is_associated(priv) ||
  640. ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) ||
  641. !priv->assoc_station_added)) {
  642. IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
  643. goto drop_unlock;
  644. }
  645. hdr_len = ieee80211_hdrlen(fc);
  646. /* Find (or create) index into station table for destination station */
  647. if (info->flags & IEEE80211_TX_CTL_INJECTED)
  648. sta_id = priv->hw_params.bcast_sta_id;
  649. else
  650. sta_id = iwl_get_sta_id(priv, hdr);
  651. if (sta_id == IWL_INVALID_STATION) {
  652. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  653. hdr->addr1);
  654. goto drop_unlock;
  655. }
  656. IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
  657. if (sta)
  658. sta_priv = (void *)sta->drv_priv;
  659. if (sta_priv && sta_id != priv->hw_params.bcast_sta_id &&
  660. sta_priv->asleep) {
  661. WARN_ON(!(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE));
  662. /*
  663. * This sends an asynchronous command to the device,
  664. * but we can rely on it being processed before the
  665. * next frame is processed -- and the next frame to
  666. * this station is the one that will consume this
  667. * counter.
  668. * For now set the counter to just 1 since we do not
  669. * support uAPSD yet.
  670. */
  671. iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
  672. }
  673. txq_id = skb_get_queue_mapping(skb);
  674. if (ieee80211_is_data_qos(fc)) {
  675. qc = ieee80211_get_qos_ctl(hdr);
  676. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  677. if (unlikely(tid >= MAX_TID_COUNT))
  678. goto drop_unlock;
  679. seq_number = priv->stations[sta_id].tid[tid].seq_number;
  680. seq_number &= IEEE80211_SCTL_SEQ;
  681. hdr->seq_ctrl = hdr->seq_ctrl &
  682. cpu_to_le16(IEEE80211_SCTL_FRAG);
  683. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  684. seq_number += 0x10;
  685. /* aggregation is on for this <sta,tid> */
  686. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  687. priv->stations[sta_id].tid[tid].agg.state == IWL_AGG_ON) {
  688. txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
  689. }
  690. }
  691. txq = &priv->txq[txq_id];
  692. swq_id = txq->swq_id;
  693. q = &txq->q;
  694. if (unlikely(iwl_queue_space(q) < q->high_mark))
  695. goto drop_unlock;
  696. if (ieee80211_is_data_qos(fc))
  697. priv->stations[sta_id].tid[tid].tfds_in_queue++;
  698. /* Set up driver data for this TFD */
  699. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  700. txq->txb[q->write_ptr].skb[0] = skb;
  701. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  702. out_cmd = txq->cmd[q->write_ptr];
  703. out_meta = &txq->meta[q->write_ptr];
  704. tx_cmd = &out_cmd->cmd.tx;
  705. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  706. memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd));
  707. /*
  708. * Set up the Tx-command (not MAC!) header.
  709. * Store the chosen Tx queue and TFD index within the sequence field;
  710. * after Tx, uCode's Tx response will return this value so driver can
  711. * locate the frame within the tx queue and do post-tx processing.
  712. */
  713. out_cmd->hdr.cmd = REPLY_TX;
  714. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  715. INDEX_TO_SEQ(q->write_ptr)));
  716. /* Copy MAC header from skb into command buffer */
  717. memcpy(tx_cmd->hdr, hdr, hdr_len);
  718. /* Total # bytes to be transmitted */
  719. len = (u16)skb->len;
  720. tx_cmd->len = cpu_to_le16(len);
  721. if (info->control.hw_key)
  722. iwl_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
  723. /* TODO need this for burst mode later on */
  724. iwl_tx_cmd_build_basic(priv, tx_cmd, info, hdr, sta_id);
  725. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  726. /* set is_hcca to 0; it probably will never be implemented */
  727. iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, 0);
  728. iwl_update_stats(priv, true, fc, len);
  729. /*
  730. * Use the first empty entry in this queue's command buffer array
  731. * to contain the Tx command and MAC header concatenated together
  732. * (payload data will be in another buffer).
  733. * Size of this varies, due to varying MAC header length.
  734. * If end is not dword aligned, we'll have 2 extra bytes at the end
  735. * of the MAC header (device reads on dword boundaries).
  736. * We'll tell device about this padding later.
  737. */
  738. len = sizeof(struct iwl_tx_cmd) +
  739. sizeof(struct iwl_cmd_header) + hdr_len;
  740. len_org = len;
  741. firstlen = len = (len + 3) & ~3;
  742. if (len_org != len)
  743. len_org = 1;
  744. else
  745. len_org = 0;
  746. /* Tell NIC about any 2-byte padding after MAC header */
  747. if (len_org)
  748. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  749. /* Physical address of this Tx command's header (not MAC header!),
  750. * within command buffer array. */
  751. txcmd_phys = pci_map_single(priv->pci_dev,
  752. &out_cmd->hdr, len,
  753. PCI_DMA_BIDIRECTIONAL);
  754. pci_unmap_addr_set(out_meta, mapping, txcmd_phys);
  755. pci_unmap_len_set(out_meta, len, len);
  756. /* Add buffer containing Tx command and MAC(!) header to TFD's
  757. * first entry */
  758. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  759. txcmd_phys, len, 1, 0);
  760. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  761. txq->need_update = 1;
  762. if (qc)
  763. priv->stations[sta_id].tid[tid].seq_number = seq_number;
  764. } else {
  765. wait_write_ptr = 1;
  766. txq->need_update = 0;
  767. }
  768. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  769. * if any (802.11 null frames have no payload). */
  770. secondlen = len = skb->len - hdr_len;
  771. if (len) {
  772. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  773. len, PCI_DMA_TODEVICE);
  774. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  775. phys_addr, len,
  776. 0, 0);
  777. }
  778. scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
  779. offsetof(struct iwl_tx_cmd, scratch);
  780. len = sizeof(struct iwl_tx_cmd) +
  781. sizeof(struct iwl_cmd_header) + hdr_len;
  782. /* take back ownership of DMA buffer to enable update */
  783. pci_dma_sync_single_for_cpu(priv->pci_dev, txcmd_phys,
  784. len, PCI_DMA_BIDIRECTIONAL);
  785. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  786. tx_cmd->dram_msb_ptr = iwl_get_dma_hi_addr(scratch_phys);
  787. IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
  788. le16_to_cpu(out_cmd->hdr.sequence));
  789. IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd->tx_flags));
  790. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
  791. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
  792. /* Set up entry for this TFD in Tx byte-count array */
  793. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  794. priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq,
  795. le16_to_cpu(tx_cmd->len));
  796. pci_dma_sync_single_for_device(priv->pci_dev, txcmd_phys,
  797. len, PCI_DMA_BIDIRECTIONAL);
  798. trace_iwlwifi_dev_tx(priv,
  799. &((struct iwl_tfd *)txq->tfds)[txq->q.write_ptr],
  800. sizeof(struct iwl_tfd),
  801. &out_cmd->hdr, firstlen,
  802. skb->data + hdr_len, secondlen);
  803. /* Tell device the write index *just past* this latest filled TFD */
  804. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  805. iwl_txq_update_write_ptr(priv, txq);
  806. spin_unlock_irqrestore(&priv->lock, flags);
  807. /*
  808. * At this point the frame is "transmitted" successfully
  809. * and we will get a TX status notification eventually,
  810. * regardless of the value of ret. "ret" only indicates
  811. * whether or not we should update the write pointer.
  812. */
  813. /* avoid atomic ops if it isn't an associated client */
  814. if (sta_priv && sta_priv->client)
  815. atomic_inc(&sta_priv->pending_frames);
  816. if ((iwl_queue_space(q) < q->high_mark) && priv->mac80211_registered) {
  817. if (wait_write_ptr) {
  818. spin_lock_irqsave(&priv->lock, flags);
  819. txq->need_update = 1;
  820. iwl_txq_update_write_ptr(priv, txq);
  821. spin_unlock_irqrestore(&priv->lock, flags);
  822. } else {
  823. iwl_stop_queue(priv, txq->swq_id);
  824. }
  825. }
  826. return 0;
  827. drop_unlock:
  828. spin_unlock_irqrestore(&priv->lock, flags);
  829. return -1;
  830. }
  831. EXPORT_SYMBOL(iwl_tx_skb);
  832. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  833. /**
  834. * iwl_enqueue_hcmd - enqueue a uCode command
  835. * @priv: device private data point
  836. * @cmd: a point to the ucode command structure
  837. *
  838. * The function returns < 0 values to indicate the operation is
  839. * failed. On success, it turns the index (> 0) of command in the
  840. * command queue.
  841. */
  842. int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  843. {
  844. struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  845. struct iwl_queue *q = &txq->q;
  846. struct iwl_device_cmd *out_cmd;
  847. struct iwl_cmd_meta *out_meta;
  848. dma_addr_t phys_addr;
  849. unsigned long flags;
  850. int len;
  851. u32 idx;
  852. u16 fix_size;
  853. cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
  854. fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  855. /* If any of the command structures end up being larger than
  856. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  857. * we will need to increase the size of the TFD entries */
  858. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  859. !(cmd->flags & CMD_SIZE_HUGE));
  860. if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) {
  861. IWL_WARN(priv, "Not sending command - %s KILL\n",
  862. iwl_is_rfkill(priv) ? "RF" : "CT");
  863. return -EIO;
  864. }
  865. if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
  866. IWL_ERR(priv, "No space in command queue\n");
  867. if (iwl_within_ct_kill_margin(priv))
  868. iwl_tt_enter_ct_kill(priv);
  869. else {
  870. IWL_ERR(priv, "Restarting adapter due to queue full\n");
  871. queue_work(priv->workqueue, &priv->restart);
  872. }
  873. return -ENOSPC;
  874. }
  875. spin_lock_irqsave(&priv->hcmd_lock, flags);
  876. idx = get_cmd_index(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE);
  877. out_cmd = txq->cmd[idx];
  878. out_meta = &txq->meta[idx];
  879. memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
  880. out_meta->flags = cmd->flags;
  881. if (cmd->flags & CMD_WANT_SKB)
  882. out_meta->source = cmd;
  883. if (cmd->flags & CMD_ASYNC)
  884. out_meta->callback = cmd->callback;
  885. out_cmd->hdr.cmd = cmd->id;
  886. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  887. /* At this point, the out_cmd now has all of the incoming cmd
  888. * information */
  889. out_cmd->hdr.flags = 0;
  890. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
  891. INDEX_TO_SEQ(q->write_ptr));
  892. if (cmd->flags & CMD_SIZE_HUGE)
  893. out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
  894. len = sizeof(struct iwl_device_cmd);
  895. len += (idx == TFD_CMD_SLOTS) ? IWL_MAX_SCAN_SIZE : 0;
  896. #ifdef CONFIG_IWLWIFI_DEBUG
  897. switch (out_cmd->hdr.cmd) {
  898. case REPLY_TX_LINK_QUALITY_CMD:
  899. case SENSITIVITY_CMD:
  900. IWL_DEBUG_HC_DUMP(priv, "Sending command %s (#%x), seq: 0x%04X, "
  901. "%d bytes at %d[%d]:%d\n",
  902. get_cmd_string(out_cmd->hdr.cmd),
  903. out_cmd->hdr.cmd,
  904. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  905. q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  906. break;
  907. default:
  908. IWL_DEBUG_HC(priv, "Sending command %s (#%x), seq: 0x%04X, "
  909. "%d bytes at %d[%d]:%d\n",
  910. get_cmd_string(out_cmd->hdr.cmd),
  911. out_cmd->hdr.cmd,
  912. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  913. q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  914. }
  915. #endif
  916. txq->need_update = 1;
  917. if (priv->cfg->ops->lib->txq_update_byte_cnt_tbl)
  918. /* Set up entry in queue's byte count circular buffer */
  919. priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
  920. phys_addr = pci_map_single(priv->pci_dev, &out_cmd->hdr,
  921. fix_size, PCI_DMA_BIDIRECTIONAL);
  922. pci_unmap_addr_set(out_meta, mapping, phys_addr);
  923. pci_unmap_len_set(out_meta, len, fix_size);
  924. trace_iwlwifi_dev_hcmd(priv, &out_cmd->hdr, fix_size, cmd->flags);
  925. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  926. phys_addr, fix_size, 1,
  927. U32_PAD(cmd->len));
  928. /* Increment and update queue's write index */
  929. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  930. iwl_txq_update_write_ptr(priv, txq);
  931. spin_unlock_irqrestore(&priv->hcmd_lock, flags);
  932. return idx;
  933. }
  934. static void iwl_tx_status(struct iwl_priv *priv, struct sk_buff *skb)
  935. {
  936. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  937. struct ieee80211_sta *sta;
  938. struct iwl_station_priv *sta_priv;
  939. sta = ieee80211_find_sta(priv->vif, hdr->addr1);
  940. if (sta) {
  941. sta_priv = (void *)sta->drv_priv;
  942. /* avoid atomic ops if this isn't a client */
  943. if (sta_priv->client &&
  944. atomic_dec_return(&sta_priv->pending_frames) == 0)
  945. ieee80211_sta_block_awake(priv->hw, sta, false);
  946. }
  947. ieee80211_tx_status_irqsafe(priv->hw, skb);
  948. }
  949. int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
  950. {
  951. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  952. struct iwl_queue *q = &txq->q;
  953. struct iwl_tx_info *tx_info;
  954. int nfreed = 0;
  955. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  956. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  957. "is out of range [0-%d] %d %d.\n", txq_id,
  958. index, q->n_bd, q->write_ptr, q->read_ptr);
  959. return 0;
  960. }
  961. for (index = iwl_queue_inc_wrap(index, q->n_bd);
  962. q->read_ptr != index;
  963. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  964. tx_info = &txq->txb[txq->q.read_ptr];
  965. iwl_tx_status(priv, tx_info->skb[0]);
  966. tx_info->skb[0] = NULL;
  967. if (priv->cfg->ops->lib->txq_inval_byte_cnt_tbl)
  968. priv->cfg->ops->lib->txq_inval_byte_cnt_tbl(priv, txq);
  969. priv->cfg->ops->lib->txq_free_tfd(priv, txq);
  970. nfreed++;
  971. }
  972. return nfreed;
  973. }
  974. EXPORT_SYMBOL(iwl_tx_queue_reclaim);
  975. /**
  976. * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
  977. *
  978. * When FW advances 'R' index, all entries between old and new 'R' index
  979. * need to be reclaimed. As result, some free space forms. If there is
  980. * enough free space (> low mark), wake the stack that feeds us.
  981. */
  982. static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id,
  983. int idx, int cmd_idx)
  984. {
  985. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  986. struct iwl_queue *q = &txq->q;
  987. int nfreed = 0;
  988. if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) {
  989. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  990. "is out of range [0-%d] %d %d.\n", txq_id,
  991. idx, q->n_bd, q->write_ptr, q->read_ptr);
  992. return;
  993. }
  994. for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  995. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  996. if (nfreed++ > 0) {
  997. IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", idx,
  998. q->write_ptr, q->read_ptr);
  999. queue_work(priv->workqueue, &priv->restart);
  1000. }
  1001. }
  1002. }
  1003. /**
  1004. * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1005. * @rxb: Rx buffer to reclaim
  1006. *
  1007. * If an Rx buffer has an async callback associated with it the callback
  1008. * will be executed. The attached skb (if present) will only be freed
  1009. * if the callback returns 1
  1010. */
  1011. void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1012. {
  1013. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1014. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1015. int txq_id = SEQ_TO_QUEUE(sequence);
  1016. int index = SEQ_TO_INDEX(sequence);
  1017. int cmd_index;
  1018. bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  1019. struct iwl_device_cmd *cmd;
  1020. struct iwl_cmd_meta *meta;
  1021. /* If a Tx command is being handled and it isn't in the actual
  1022. * command queue then there a command routing bug has been introduced
  1023. * in the queue management code. */
  1024. if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
  1025. "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
  1026. txq_id, sequence,
  1027. priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
  1028. priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
  1029. iwl_print_hex_error(priv, pkt, 32);
  1030. return;
  1031. }
  1032. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1033. cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1034. meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index];
  1035. pci_unmap_single(priv->pci_dev,
  1036. pci_unmap_addr(meta, mapping),
  1037. pci_unmap_len(meta, len),
  1038. PCI_DMA_BIDIRECTIONAL);
  1039. /* Input error checking is done when commands are added to queue. */
  1040. if (meta->flags & CMD_WANT_SKB) {
  1041. meta->source->reply_page = (unsigned long)rxb_addr(rxb);
  1042. rxb->page = NULL;
  1043. } else if (meta->callback)
  1044. meta->callback(priv, cmd, pkt);
  1045. iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index);
  1046. if (!(meta->flags & CMD_ASYNC)) {
  1047. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1048. wake_up_interruptible(&priv->wait_command_queue);
  1049. }
  1050. }
  1051. EXPORT_SYMBOL(iwl_tx_cmd_complete);
  1052. /*
  1053. * Find first available (lowest unused) Tx Queue, mark it "active".
  1054. * Called only when finding queue for aggregation.
  1055. * Should never return anything < 7, because they should already
  1056. * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
  1057. */
  1058. static int iwl_txq_ctx_activate_free(struct iwl_priv *priv)
  1059. {
  1060. int txq_id;
  1061. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
  1062. if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
  1063. return txq_id;
  1064. return -1;
  1065. }
  1066. int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
  1067. {
  1068. int sta_id;
  1069. int tx_fifo;
  1070. int txq_id;
  1071. int ret;
  1072. unsigned long flags;
  1073. struct iwl_tid_data *tid_data;
  1074. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  1075. tx_fifo = default_tid_to_tx_fifo[tid];
  1076. else
  1077. return -EINVAL;
  1078. IWL_WARN(priv, "%s on ra = %pM tid = %d\n",
  1079. __func__, ra, tid);
  1080. sta_id = iwl_find_station(priv, ra);
  1081. if (sta_id == IWL_INVALID_STATION) {
  1082. IWL_ERR(priv, "Start AGG on invalid station\n");
  1083. return -ENXIO;
  1084. }
  1085. if (unlikely(tid >= MAX_TID_COUNT))
  1086. return -EINVAL;
  1087. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
  1088. IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
  1089. return -ENXIO;
  1090. }
  1091. txq_id = iwl_txq_ctx_activate_free(priv);
  1092. if (txq_id == -1) {
  1093. IWL_ERR(priv, "No free aggregation queue available\n");
  1094. return -ENXIO;
  1095. }
  1096. spin_lock_irqsave(&priv->sta_lock, flags);
  1097. tid_data = &priv->stations[sta_id].tid[tid];
  1098. *ssn = SEQ_TO_SN(tid_data->seq_number);
  1099. tid_data->agg.txq_id = txq_id;
  1100. priv->txq[txq_id].swq_id = iwl_virtual_agg_queue_num(tx_fifo, txq_id);
  1101. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1102. ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,
  1103. sta_id, tid, *ssn);
  1104. if (ret)
  1105. return ret;
  1106. if (tid_data->tfds_in_queue == 0) {
  1107. IWL_DEBUG_HT(priv, "HW queue is empty\n");
  1108. tid_data->agg.state = IWL_AGG_ON;
  1109. ieee80211_start_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1110. } else {
  1111. IWL_DEBUG_HT(priv, "HW queue is NOT empty: %d packets in HW queue\n",
  1112. tid_data->tfds_in_queue);
  1113. tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
  1114. }
  1115. return ret;
  1116. }
  1117. EXPORT_SYMBOL(iwl_tx_agg_start);
  1118. int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
  1119. {
  1120. int tx_fifo_id, txq_id, sta_id, ssn = -1;
  1121. struct iwl_tid_data *tid_data;
  1122. int write_ptr, read_ptr;
  1123. unsigned long flags;
  1124. if (!ra) {
  1125. IWL_ERR(priv, "ra = NULL\n");
  1126. return -EINVAL;
  1127. }
  1128. if (unlikely(tid >= MAX_TID_COUNT))
  1129. return -EINVAL;
  1130. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  1131. tx_fifo_id = default_tid_to_tx_fifo[tid];
  1132. else
  1133. return -EINVAL;
  1134. sta_id = iwl_find_station(priv, ra);
  1135. if (sta_id == IWL_INVALID_STATION) {
  1136. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  1137. return -ENXIO;
  1138. }
  1139. if (priv->stations[sta_id].tid[tid].agg.state ==
  1140. IWL_EMPTYING_HW_QUEUE_ADDBA) {
  1141. IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
  1142. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1143. priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
  1144. return 0;
  1145. }
  1146. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
  1147. IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");
  1148. tid_data = &priv->stations[sta_id].tid[tid];
  1149. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  1150. txq_id = tid_data->agg.txq_id;
  1151. write_ptr = priv->txq[txq_id].q.write_ptr;
  1152. read_ptr = priv->txq[txq_id].q.read_ptr;
  1153. /* The queue is not empty */
  1154. if (write_ptr != read_ptr) {
  1155. IWL_DEBUG_HT(priv, "Stopping a non empty AGG HW QUEUE\n");
  1156. priv->stations[sta_id].tid[tid].agg.state =
  1157. IWL_EMPTYING_HW_QUEUE_DELBA;
  1158. return 0;
  1159. }
  1160. IWL_DEBUG_HT(priv, "HW queue is empty\n");
  1161. priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
  1162. spin_lock_irqsave(&priv->lock, flags);
  1163. /*
  1164. * the only reason this call can fail is queue number out of range,
  1165. * which can happen if uCode is reloaded and all the station
  1166. * information are lost. if it is outside the range, there is no need
  1167. * to deactivate the uCode queue, just return "success" to allow
  1168. * mac80211 to clean up it own data.
  1169. */
  1170. priv->cfg->ops->lib->txq_agg_disable(priv, txq_id, ssn,
  1171. tx_fifo_id);
  1172. spin_unlock_irqrestore(&priv->lock, flags);
  1173. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1174. return 0;
  1175. }
  1176. EXPORT_SYMBOL(iwl_tx_agg_stop);
  1177. int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id)
  1178. {
  1179. struct iwl_queue *q = &priv->txq[txq_id].q;
  1180. u8 *addr = priv->stations[sta_id].sta.sta.addr;
  1181. struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
  1182. switch (priv->stations[sta_id].tid[tid].agg.state) {
  1183. case IWL_EMPTYING_HW_QUEUE_DELBA:
  1184. /* We are reclaiming the last packet of the */
  1185. /* aggregated HW queue */
  1186. if ((txq_id == tid_data->agg.txq_id) &&
  1187. (q->read_ptr == q->write_ptr)) {
  1188. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  1189. int tx_fifo = default_tid_to_tx_fifo[tid];
  1190. IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n");
  1191. priv->cfg->ops->lib->txq_agg_disable(priv, txq_id,
  1192. ssn, tx_fifo);
  1193. tid_data->agg.state = IWL_AGG_OFF;
  1194. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, addr, tid);
  1195. }
  1196. break;
  1197. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  1198. /* We are reclaiming the last packet of the queue */
  1199. if (tid_data->tfds_in_queue == 0) {
  1200. IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n");
  1201. tid_data->agg.state = IWL_AGG_ON;
  1202. ieee80211_start_tx_ba_cb_irqsafe(priv->vif, addr, tid);
  1203. }
  1204. break;
  1205. }
  1206. return 0;
  1207. }
  1208. EXPORT_SYMBOL(iwl_txq_check_empty);
  1209. /**
  1210. * iwl_tx_status_reply_compressed_ba - Update tx status from block-ack
  1211. *
  1212. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  1213. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  1214. */
  1215. static int iwl_tx_status_reply_compressed_ba(struct iwl_priv *priv,
  1216. struct iwl_ht_agg *agg,
  1217. struct iwl_compressed_ba_resp *ba_resp)
  1218. {
  1219. int i, sh, ack;
  1220. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  1221. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  1222. u64 bitmap;
  1223. int successes = 0;
  1224. struct ieee80211_tx_info *info;
  1225. if (unlikely(!agg->wait_for_ba)) {
  1226. IWL_ERR(priv, "Received BA when not expected\n");
  1227. return -EINVAL;
  1228. }
  1229. /* Mark that the expected block-ack response arrived */
  1230. agg->wait_for_ba = 0;
  1231. IWL_DEBUG_TX_REPLY(priv, "BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
  1232. /* Calculate shift to align block-ack bits with our Tx window bits */
  1233. sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl >> 4);
  1234. if (sh < 0) /* tbw something is wrong with indices */
  1235. sh += 0x100;
  1236. /* don't use 64-bit values for now */
  1237. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  1238. if (agg->frame_count > (64 - sh)) {
  1239. IWL_DEBUG_TX_REPLY(priv, "more frames than bitmap size");
  1240. return -1;
  1241. }
  1242. /* check for success or failure according to the
  1243. * transmitted bitmap and block-ack bitmap */
  1244. bitmap &= agg->bitmap;
  1245. /* For each frame attempted in aggregation,
  1246. * update driver's record of tx frame's status. */
  1247. for (i = 0; i < agg->frame_count ; i++) {
  1248. ack = bitmap & (1ULL << i);
  1249. successes += !!ack;
  1250. IWL_DEBUG_TX_REPLY(priv, "%s ON i=%d idx=%d raw=%d\n",
  1251. ack ? "ACK" : "NACK", i, (agg->start_idx + i) & 0xff,
  1252. agg->start_idx + i);
  1253. }
  1254. info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
  1255. memset(&info->status, 0, sizeof(info->status));
  1256. info->flags |= IEEE80211_TX_STAT_ACK;
  1257. info->flags |= IEEE80211_TX_STAT_AMPDU;
  1258. info->status.ampdu_ack_map = successes;
  1259. info->status.ampdu_ack_len = agg->frame_count;
  1260. iwl_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
  1261. IWL_DEBUG_TX_REPLY(priv, "Bitmap %llx\n", (unsigned long long)bitmap);
  1262. return 0;
  1263. }
  1264. /**
  1265. * iwl_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  1266. *
  1267. * Handles block-acknowledge notification from device, which reports success
  1268. * of frames sent via aggregation.
  1269. */
  1270. void iwl_rx_reply_compressed_ba(struct iwl_priv *priv,
  1271. struct iwl_rx_mem_buffer *rxb)
  1272. {
  1273. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1274. struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  1275. struct iwl_tx_queue *txq = NULL;
  1276. struct iwl_ht_agg *agg;
  1277. int index;
  1278. int sta_id;
  1279. int tid;
  1280. /* "flow" corresponds to Tx queue */
  1281. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  1282. /* "ssn" is start of block-ack Tx window, corresponds to index
  1283. * (in Tx queue's circular buffer) of first TFD/frame in window */
  1284. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  1285. if (scd_flow >= priv->hw_params.max_txq_num) {
  1286. IWL_ERR(priv,
  1287. "BUG_ON scd_flow is bigger than number of queues\n");
  1288. return;
  1289. }
  1290. txq = &priv->txq[scd_flow];
  1291. sta_id = ba_resp->sta_id;
  1292. tid = ba_resp->tid;
  1293. agg = &priv->stations[sta_id].tid[tid].agg;
  1294. /* Find index just before block-ack window */
  1295. index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  1296. /* TODO: Need to get this copy more safely - now good for debug */
  1297. IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
  1298. "sta_id = %d\n",
  1299. agg->wait_for_ba,
  1300. (u8 *) &ba_resp->sta_addr_lo32,
  1301. ba_resp->sta_id);
  1302. IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
  1303. "%d, scd_ssn = %d\n",
  1304. ba_resp->tid,
  1305. ba_resp->seq_ctl,
  1306. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  1307. ba_resp->scd_flow,
  1308. ba_resp->scd_ssn);
  1309. IWL_DEBUG_TX_REPLY(priv, "DAT start_idx = %d, bitmap = 0x%llx \n",
  1310. agg->start_idx,
  1311. (unsigned long long)agg->bitmap);
  1312. /* Update driver's record of ACK vs. not for each frame in window */
  1313. iwl_tx_status_reply_compressed_ba(priv, agg, ba_resp);
  1314. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  1315. * block-ack window (we assume that they've been successfully
  1316. * transmitted ... if not, it's too late anyway). */
  1317. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  1318. /* calculate mac80211 ampdu sw queue to wake */
  1319. int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
  1320. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1321. if ((iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  1322. priv->mac80211_registered &&
  1323. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA))
  1324. iwl_wake_queue(priv, txq->swq_id);
  1325. iwl_txq_check_empty(priv, sta_id, tid, scd_flow);
  1326. }
  1327. }
  1328. EXPORT_SYMBOL(iwl_rx_reply_compressed_ba);
  1329. #ifdef CONFIG_IWLWIFI_DEBUG
  1330. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1331. const char *iwl_get_tx_fail_reason(u32 status)
  1332. {
  1333. switch (status & TX_STATUS_MSK) {
  1334. case TX_STATUS_SUCCESS:
  1335. return "SUCCESS";
  1336. TX_STATUS_ENTRY(SHORT_LIMIT);
  1337. TX_STATUS_ENTRY(LONG_LIMIT);
  1338. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  1339. TX_STATUS_ENTRY(MGMNT_ABORT);
  1340. TX_STATUS_ENTRY(NEXT_FRAG);
  1341. TX_STATUS_ENTRY(LIFE_EXPIRE);
  1342. TX_STATUS_ENTRY(DEST_PS);
  1343. TX_STATUS_ENTRY(ABORTED);
  1344. TX_STATUS_ENTRY(BT_RETRY);
  1345. TX_STATUS_ENTRY(STA_INVALID);
  1346. TX_STATUS_ENTRY(FRAG_DROPPED);
  1347. TX_STATUS_ENTRY(TID_DISABLE);
  1348. TX_STATUS_ENTRY(FRAME_FLUSHED);
  1349. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  1350. TX_STATUS_ENTRY(TX_LOCKED);
  1351. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  1352. }
  1353. return "UNKNOWN";
  1354. }
  1355. EXPORT_SYMBOL(iwl_get_tx_fail_reason);
  1356. #endif /* CONFIG_IWLWIFI_DEBUG */