iwl-tx.c 46 KB

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