iwl-tx.c 46 KB

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