iwl-tx.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  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 = dma_alloc_coherent(&priv->pci_dev->dev, size, &ptr->dma,
  61. GFP_KERNEL);
  62. if (!ptr->addr)
  63. return -ENOMEM;
  64. ptr->size = size;
  65. return 0;
  66. }
  67. static inline void iwl_free_dma_ptr(struct iwl_priv *priv,
  68. struct iwl_dma_ptr *ptr)
  69. {
  70. if (unlikely(!ptr->addr))
  71. return;
  72. dma_free_coherent(&priv->pci_dev->dev, ptr->size, ptr->addr, ptr->dma);
  73. memset(ptr, 0, sizeof(*ptr));
  74. }
  75. /**
  76. * iwl_txq_update_write_ptr - Send new write index to hardware
  77. */
  78. void iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  79. {
  80. u32 reg = 0;
  81. int txq_id = txq->q.id;
  82. if (txq->need_update == 0)
  83. return;
  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;
  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. }
  106. EXPORT_SYMBOL(iwl_txq_update_write_ptr);
  107. void iwl_free_tfds_in_queue(struct iwl_priv *priv,
  108. int sta_id, int tid, int freed)
  109. {
  110. if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  111. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  112. else {
  113. IWL_ERR(priv, "free more than tfds_in_queue (%u:%d)\n",
  114. priv->stations[sta_id].tid[tid].tfds_in_queue,
  115. freed);
  116. priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
  117. }
  118. }
  119. EXPORT_SYMBOL(iwl_free_tfds_in_queue);
  120. /**
  121. * iwl_tx_queue_free - Deallocate DMA queue.
  122. * @txq: Transmit queue to deallocate.
  123. *
  124. * Empty queue by removing and destroying all BD's.
  125. * Free all buffers.
  126. * 0-fill, but do not free "txq" descriptor structure.
  127. */
  128. void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id)
  129. {
  130. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  131. struct iwl_queue *q = &txq->q;
  132. struct device *dev = &priv->pci_dev->dev;
  133. int i;
  134. if (q->n_bd == 0)
  135. return;
  136. /* first, empty all BD's */
  137. for (; q->write_ptr != q->read_ptr;
  138. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
  139. priv->cfg->ops->lib->txq_free_tfd(priv, txq);
  140. /* De-alloc array of command/tx buffers */
  141. for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
  142. kfree(txq->cmd[i]);
  143. /* De-alloc circular buffer of TFDs */
  144. if (txq->q.n_bd)
  145. dma_free_coherent(dev, priv->hw_params.tfd_size *
  146. txq->q.n_bd, txq->tfds, txq->q.dma_addr);
  147. /* De-alloc array of per-TFD driver data */
  148. kfree(txq->txb);
  149. txq->txb = NULL;
  150. /* deallocate arrays */
  151. kfree(txq->cmd);
  152. kfree(txq->meta);
  153. txq->cmd = NULL;
  154. txq->meta = NULL;
  155. /* 0-fill queue descriptor structure */
  156. memset(txq, 0, sizeof(*txq));
  157. }
  158. EXPORT_SYMBOL(iwl_tx_queue_free);
  159. /**
  160. * iwl_cmd_queue_free - Deallocate DMA queue.
  161. * @txq: Transmit queue to deallocate.
  162. *
  163. * Empty queue by removing and destroying all BD's.
  164. * Free all buffers.
  165. * 0-fill, but do not free "txq" descriptor structure.
  166. */
  167. void iwl_cmd_queue_free(struct iwl_priv *priv)
  168. {
  169. struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  170. struct iwl_queue *q = &txq->q;
  171. struct device *dev = &priv->pci_dev->dev;
  172. int i;
  173. if (q->n_bd == 0)
  174. return;
  175. /* De-alloc array of command/tx buffers */
  176. for (i = 0; i <= TFD_CMD_SLOTS; i++)
  177. kfree(txq->cmd[i]);
  178. /* De-alloc circular buffer of TFDs */
  179. if (txq->q.n_bd)
  180. dma_free_coherent(dev, priv->hw_params.tfd_size * txq->q.n_bd,
  181. txq->tfds, txq->q.dma_addr);
  182. /* deallocate arrays */
  183. kfree(txq->cmd);
  184. kfree(txq->meta);
  185. txq->cmd = NULL;
  186. txq->meta = NULL;
  187. /* 0-fill queue descriptor structure */
  188. memset(txq, 0, sizeof(*txq));
  189. }
  190. EXPORT_SYMBOL(iwl_cmd_queue_free);
  191. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  192. * DMA services
  193. *
  194. * Theory of operation
  195. *
  196. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  197. * of buffer descriptors, each of which points to one or more data buffers for
  198. * the device to read from or fill. Driver and device exchange status of each
  199. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  200. * entries in each circular buffer, to protect against confusing empty and full
  201. * queue states.
  202. *
  203. * The device reads or writes the data in the queues via the device's several
  204. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  205. *
  206. * For Tx queue, there are low mark and high mark limits. If, after queuing
  207. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  208. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  209. * Tx queue resumed.
  210. *
  211. * See more detailed info in iwl-4965-hw.h.
  212. ***************************************************/
  213. int iwl_queue_space(const struct iwl_queue *q)
  214. {
  215. int s = q->read_ptr - q->write_ptr;
  216. if (q->read_ptr > q->write_ptr)
  217. s -= q->n_bd;
  218. if (s <= 0)
  219. s += q->n_window;
  220. /* keep some reserve to not confuse empty and full situations */
  221. s -= 2;
  222. if (s < 0)
  223. s = 0;
  224. return s;
  225. }
  226. EXPORT_SYMBOL(iwl_queue_space);
  227. /**
  228. * iwl_queue_init - Initialize queue's high/low-water and read/write indexes
  229. */
  230. static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
  231. int count, int slots_num, u32 id)
  232. {
  233. q->n_bd = count;
  234. q->n_window = slots_num;
  235. q->id = id;
  236. /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
  237. * and iwl_queue_dec_wrap are broken. */
  238. BUG_ON(!is_power_of_2(count));
  239. /* slots_num must be power-of-two size, otherwise
  240. * get_cmd_index is broken. */
  241. BUG_ON(!is_power_of_2(slots_num));
  242. q->low_mark = q->n_window / 4;
  243. if (q->low_mark < 4)
  244. q->low_mark = 4;
  245. q->high_mark = q->n_window / 8;
  246. if (q->high_mark < 2)
  247. q->high_mark = 2;
  248. q->write_ptr = q->read_ptr = 0;
  249. return 0;
  250. }
  251. /**
  252. * iwl_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  253. */
  254. static int iwl_tx_queue_alloc(struct iwl_priv *priv,
  255. struct iwl_tx_queue *txq, u32 id)
  256. {
  257. struct device *dev = &priv->pci_dev->dev;
  258. size_t tfd_sz = priv->hw_params.tfd_size * TFD_QUEUE_SIZE_MAX;
  259. /* Driver private data, only for Tx (not command) queues,
  260. * not shared with device. */
  261. if (id != IWL_CMD_QUEUE_NUM) {
  262. txq->txb = kmalloc(sizeof(txq->txb[0]) *
  263. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  264. if (!txq->txb) {
  265. IWL_ERR(priv, "kmalloc for auxiliary BD "
  266. "structures failed\n");
  267. goto error;
  268. }
  269. } else {
  270. txq->txb = NULL;
  271. }
  272. /* Circular buffer of transmit frame descriptors (TFDs),
  273. * shared with device */
  274. txq->tfds = dma_alloc_coherent(dev, tfd_sz, &txq->q.dma_addr,
  275. GFP_KERNEL);
  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_CMD_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. spin_lock_irqsave(&priv->lock, flags);
  638. if (iwl_is_rfkill(priv)) {
  639. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  640. goto drop_unlock;
  641. }
  642. fc = hdr->frame_control;
  643. #ifdef CONFIG_IWLWIFI_DEBUG
  644. if (ieee80211_is_auth(fc))
  645. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  646. else if (ieee80211_is_assoc_req(fc))
  647. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  648. else if (ieee80211_is_reassoc_req(fc))
  649. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  650. #endif
  651. hdr_len = ieee80211_hdrlen(fc);
  652. /* Find (or create) index into station table for destination station */
  653. if (info->flags & IEEE80211_TX_CTL_INJECTED)
  654. sta_id = priv->hw_params.bcast_sta_id;
  655. else
  656. sta_id = iwl_get_sta_id(priv, hdr);
  657. if (sta_id == IWL_INVALID_STATION) {
  658. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  659. hdr->addr1);
  660. goto drop_unlock;
  661. }
  662. IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
  663. if (sta)
  664. sta_priv = (void *)sta->drv_priv;
  665. if (sta_priv && sta_id != priv->hw_params.bcast_sta_id &&
  666. sta_priv->asleep) {
  667. WARN_ON(!(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE));
  668. /*
  669. * This sends an asynchronous command to the device,
  670. * but we can rely on it being processed before the
  671. * next frame is processed -- and the next frame to
  672. * this station is the one that will consume this
  673. * counter.
  674. * For now set the counter to just 1 since we do not
  675. * support uAPSD yet.
  676. */
  677. iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
  678. }
  679. txq_id = skb_get_queue_mapping(skb);
  680. if (ieee80211_is_data_qos(fc)) {
  681. qc = ieee80211_get_qos_ctl(hdr);
  682. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  683. if (unlikely(tid >= MAX_TID_COUNT))
  684. goto drop_unlock;
  685. seq_number = priv->stations[sta_id].tid[tid].seq_number;
  686. seq_number &= IEEE80211_SCTL_SEQ;
  687. hdr->seq_ctrl = hdr->seq_ctrl &
  688. cpu_to_le16(IEEE80211_SCTL_FRAG);
  689. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  690. seq_number += 0x10;
  691. /* aggregation is on for this <sta,tid> */
  692. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  693. priv->stations[sta_id].tid[tid].agg.state == IWL_AGG_ON) {
  694. txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
  695. }
  696. }
  697. txq = &priv->txq[txq_id];
  698. swq_id = txq->swq_id;
  699. q = &txq->q;
  700. if (unlikely(iwl_queue_space(q) < q->high_mark))
  701. goto drop_unlock;
  702. if (ieee80211_is_data_qos(fc))
  703. priv->stations[sta_id].tid[tid].tfds_in_queue++;
  704. /* Set up driver data for this TFD */
  705. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  706. txq->txb[q->write_ptr].skb[0] = skb;
  707. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  708. out_cmd = txq->cmd[q->write_ptr];
  709. out_meta = &txq->meta[q->write_ptr];
  710. tx_cmd = &out_cmd->cmd.tx;
  711. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  712. memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd));
  713. /*
  714. * Set up the Tx-command (not MAC!) header.
  715. * Store the chosen Tx queue and TFD index within the sequence field;
  716. * after Tx, uCode's Tx response will return this value so driver can
  717. * locate the frame within the tx queue and do post-tx processing.
  718. */
  719. out_cmd->hdr.cmd = REPLY_TX;
  720. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  721. INDEX_TO_SEQ(q->write_ptr)));
  722. /* Copy MAC header from skb into command buffer */
  723. memcpy(tx_cmd->hdr, hdr, hdr_len);
  724. /* Total # bytes to be transmitted */
  725. len = (u16)skb->len;
  726. tx_cmd->len = cpu_to_le16(len);
  727. if (info->control.hw_key)
  728. iwl_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
  729. /* TODO need this for burst mode later on */
  730. iwl_tx_cmd_build_basic(priv, tx_cmd, info, hdr, sta_id);
  731. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  732. /* set is_hcca to 0; it probably will never be implemented */
  733. iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, 0);
  734. iwl_update_stats(priv, true, fc, len);
  735. /*
  736. * Use the first empty entry in this queue's command buffer array
  737. * to contain the Tx command and MAC header concatenated together
  738. * (payload data will be in another buffer).
  739. * Size of this varies, due to varying MAC header length.
  740. * If end is not dword aligned, we'll have 2 extra bytes at the end
  741. * of the MAC header (device reads on dword boundaries).
  742. * We'll tell device about this padding later.
  743. */
  744. len = sizeof(struct iwl_tx_cmd) +
  745. sizeof(struct iwl_cmd_header) + hdr_len;
  746. len_org = len;
  747. firstlen = len = (len + 3) & ~3;
  748. if (len_org != len)
  749. len_org = 1;
  750. else
  751. len_org = 0;
  752. /* Tell NIC about any 2-byte padding after MAC header */
  753. if (len_org)
  754. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  755. /* Physical address of this Tx command's header (not MAC header!),
  756. * within command buffer array. */
  757. txcmd_phys = pci_map_single(priv->pci_dev,
  758. &out_cmd->hdr, len,
  759. PCI_DMA_BIDIRECTIONAL);
  760. pci_unmap_addr_set(out_meta, mapping, txcmd_phys);
  761. pci_unmap_len_set(out_meta, len, len);
  762. /* Add buffer containing Tx command and MAC(!) header to TFD's
  763. * first entry */
  764. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  765. txcmd_phys, len, 1, 0);
  766. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  767. txq->need_update = 1;
  768. if (qc)
  769. priv->stations[sta_id].tid[tid].seq_number = seq_number;
  770. } else {
  771. wait_write_ptr = 1;
  772. txq->need_update = 0;
  773. }
  774. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  775. * if any (802.11 null frames have no payload). */
  776. secondlen = len = skb->len - hdr_len;
  777. if (len) {
  778. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  779. len, PCI_DMA_TODEVICE);
  780. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  781. phys_addr, len,
  782. 0, 0);
  783. }
  784. scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
  785. offsetof(struct iwl_tx_cmd, scratch);
  786. len = sizeof(struct iwl_tx_cmd) +
  787. sizeof(struct iwl_cmd_header) + hdr_len;
  788. /* take back ownership of DMA buffer to enable update */
  789. pci_dma_sync_single_for_cpu(priv->pci_dev, txcmd_phys,
  790. len, PCI_DMA_BIDIRECTIONAL);
  791. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  792. tx_cmd->dram_msb_ptr = iwl_get_dma_hi_addr(scratch_phys);
  793. IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
  794. le16_to_cpu(out_cmd->hdr.sequence));
  795. IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd->tx_flags));
  796. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
  797. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
  798. /* Set up entry for this TFD in Tx byte-count array */
  799. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  800. priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq,
  801. le16_to_cpu(tx_cmd->len));
  802. pci_dma_sync_single_for_device(priv->pci_dev, txcmd_phys,
  803. len, PCI_DMA_BIDIRECTIONAL);
  804. trace_iwlwifi_dev_tx(priv,
  805. &((struct iwl_tfd *)txq->tfds)[txq->q.write_ptr],
  806. sizeof(struct iwl_tfd),
  807. &out_cmd->hdr, firstlen,
  808. skb->data + hdr_len, secondlen);
  809. /* Tell device the write index *just past* this latest filled TFD */
  810. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  811. iwl_txq_update_write_ptr(priv, txq);
  812. spin_unlock_irqrestore(&priv->lock, flags);
  813. /*
  814. * At this point the frame is "transmitted" successfully
  815. * and we will get a TX status notification eventually,
  816. * regardless of the value of ret. "ret" only indicates
  817. * whether or not we should update the write pointer.
  818. */
  819. /* avoid atomic ops if it isn't an associated client */
  820. if (sta_priv && sta_priv->client)
  821. atomic_inc(&sta_priv->pending_frames);
  822. if ((iwl_queue_space(q) < q->high_mark) && priv->mac80211_registered) {
  823. if (wait_write_ptr) {
  824. spin_lock_irqsave(&priv->lock, flags);
  825. txq->need_update = 1;
  826. iwl_txq_update_write_ptr(priv, txq);
  827. spin_unlock_irqrestore(&priv->lock, flags);
  828. } else {
  829. iwl_stop_queue(priv, txq->swq_id);
  830. }
  831. }
  832. return 0;
  833. drop_unlock:
  834. spin_unlock_irqrestore(&priv->lock, flags);
  835. return -1;
  836. }
  837. EXPORT_SYMBOL(iwl_tx_skb);
  838. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  839. /**
  840. * iwl_enqueue_hcmd - enqueue a uCode command
  841. * @priv: device private data point
  842. * @cmd: a point to the ucode command structure
  843. *
  844. * The function returns < 0 values to indicate the operation is
  845. * failed. On success, it turns the index (> 0) of command in the
  846. * command queue.
  847. */
  848. int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
  849. {
  850. struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  851. struct iwl_queue *q = &txq->q;
  852. struct iwl_device_cmd *out_cmd;
  853. struct iwl_cmd_meta *out_meta;
  854. dma_addr_t phys_addr;
  855. unsigned long flags;
  856. int len;
  857. u32 idx;
  858. u16 fix_size;
  859. cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
  860. fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  861. /* If any of the command structures end up being larger than
  862. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  863. * we will need to increase the size of the TFD entries
  864. * Also, check to see if command buffer should not exceed the size
  865. * of device_cmd and max_cmd_size. */
  866. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  867. !(cmd->flags & CMD_SIZE_HUGE));
  868. BUG_ON(fix_size > IWL_MAX_CMD_SIZE);
  869. if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) {
  870. IWL_WARN(priv, "Not sending command - %s KILL\n",
  871. iwl_is_rfkill(priv) ? "RF" : "CT");
  872. return -EIO;
  873. }
  874. if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
  875. IWL_ERR(priv, "No space in command queue\n");
  876. if (iwl_within_ct_kill_margin(priv))
  877. iwl_tt_enter_ct_kill(priv);
  878. else {
  879. IWL_ERR(priv, "Restarting adapter due to queue full\n");
  880. queue_work(priv->workqueue, &priv->restart);
  881. }
  882. return -ENOSPC;
  883. }
  884. spin_lock_irqsave(&priv->hcmd_lock, flags);
  885. idx = get_cmd_index(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE);
  886. out_cmd = txq->cmd[idx];
  887. out_meta = &txq->meta[idx];
  888. memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
  889. out_meta->flags = cmd->flags;
  890. if (cmd->flags & CMD_WANT_SKB)
  891. out_meta->source = cmd;
  892. if (cmd->flags & CMD_ASYNC)
  893. out_meta->callback = cmd->callback;
  894. out_cmd->hdr.cmd = cmd->id;
  895. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  896. /* At this point, the out_cmd now has all of the incoming cmd
  897. * information */
  898. out_cmd->hdr.flags = 0;
  899. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
  900. INDEX_TO_SEQ(q->write_ptr));
  901. if (cmd->flags & CMD_SIZE_HUGE)
  902. out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
  903. len = sizeof(struct iwl_device_cmd);
  904. if (idx == TFD_CMD_SLOTS)
  905. len = IWL_MAX_CMD_SIZE;
  906. #ifdef CONFIG_IWLWIFI_DEBUG
  907. switch (out_cmd->hdr.cmd) {
  908. case REPLY_TX_LINK_QUALITY_CMD:
  909. case SENSITIVITY_CMD:
  910. IWL_DEBUG_HC_DUMP(priv, "Sending command %s (#%x), seq: 0x%04X, "
  911. "%d bytes at %d[%d]:%d\n",
  912. get_cmd_string(out_cmd->hdr.cmd),
  913. out_cmd->hdr.cmd,
  914. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  915. q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  916. break;
  917. default:
  918. IWL_DEBUG_HC(priv, "Sending command %s (#%x), seq: 0x%04X, "
  919. "%d bytes at %d[%d]:%d\n",
  920. get_cmd_string(out_cmd->hdr.cmd),
  921. out_cmd->hdr.cmd,
  922. le16_to_cpu(out_cmd->hdr.sequence), fix_size,
  923. q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  924. }
  925. #endif
  926. txq->need_update = 1;
  927. if (priv->cfg->ops->lib->txq_update_byte_cnt_tbl)
  928. /* Set up entry in queue's byte count circular buffer */
  929. priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
  930. phys_addr = pci_map_single(priv->pci_dev, &out_cmd->hdr,
  931. fix_size, PCI_DMA_BIDIRECTIONAL);
  932. pci_unmap_addr_set(out_meta, mapping, phys_addr);
  933. pci_unmap_len_set(out_meta, len, fix_size);
  934. trace_iwlwifi_dev_hcmd(priv, &out_cmd->hdr, fix_size, cmd->flags);
  935. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  936. phys_addr, fix_size, 1,
  937. U32_PAD(cmd->len));
  938. /* Increment and update queue's write index */
  939. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  940. iwl_txq_update_write_ptr(priv, txq);
  941. spin_unlock_irqrestore(&priv->hcmd_lock, flags);
  942. return idx;
  943. }
  944. static void iwl_tx_status(struct iwl_priv *priv, struct sk_buff *skb)
  945. {
  946. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  947. struct ieee80211_sta *sta;
  948. struct iwl_station_priv *sta_priv;
  949. sta = ieee80211_find_sta(priv->vif, hdr->addr1);
  950. if (sta) {
  951. sta_priv = (void *)sta->drv_priv;
  952. /* avoid atomic ops if this isn't a client */
  953. if (sta_priv->client &&
  954. atomic_dec_return(&sta_priv->pending_frames) == 0)
  955. ieee80211_sta_block_awake(priv->hw, sta, false);
  956. }
  957. ieee80211_tx_status_irqsafe(priv->hw, skb);
  958. }
  959. int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
  960. {
  961. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  962. struct iwl_queue *q = &txq->q;
  963. struct iwl_tx_info *tx_info;
  964. int nfreed = 0;
  965. struct ieee80211_hdr *hdr;
  966. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  967. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  968. "is out of range [0-%d] %d %d.\n", txq_id,
  969. index, q->n_bd, q->write_ptr, q->read_ptr);
  970. return 0;
  971. }
  972. for (index = iwl_queue_inc_wrap(index, q->n_bd);
  973. q->read_ptr != index;
  974. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  975. tx_info = &txq->txb[txq->q.read_ptr];
  976. iwl_tx_status(priv, tx_info->skb[0]);
  977. hdr = (struct ieee80211_hdr *)tx_info->skb[0]->data;
  978. if (hdr && ieee80211_is_data_qos(hdr->frame_control))
  979. nfreed++;
  980. tx_info->skb[0] = NULL;
  981. if (priv->cfg->ops->lib->txq_inval_byte_cnt_tbl)
  982. priv->cfg->ops->lib->txq_inval_byte_cnt_tbl(priv, txq);
  983. priv->cfg->ops->lib->txq_free_tfd(priv, txq);
  984. }
  985. return nfreed;
  986. }
  987. EXPORT_SYMBOL(iwl_tx_queue_reclaim);
  988. /**
  989. * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
  990. *
  991. * When FW advances 'R' index, all entries between old and new 'R' index
  992. * need to be reclaimed. As result, some free space forms. If there is
  993. * enough free space (> low mark), wake the stack that feeds us.
  994. */
  995. static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id,
  996. int idx, int cmd_idx)
  997. {
  998. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  999. struct iwl_queue *q = &txq->q;
  1000. int nfreed = 0;
  1001. if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) {
  1002. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  1003. "is out of range [0-%d] %d %d.\n", txq_id,
  1004. idx, q->n_bd, q->write_ptr, q->read_ptr);
  1005. return;
  1006. }
  1007. for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  1008. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  1009. if (nfreed++ > 0) {
  1010. IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", idx,
  1011. q->write_ptr, q->read_ptr);
  1012. queue_work(priv->workqueue, &priv->restart);
  1013. }
  1014. }
  1015. }
  1016. /**
  1017. * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1018. * @rxb: Rx buffer to reclaim
  1019. *
  1020. * If an Rx buffer has an async callback associated with it the callback
  1021. * will be executed. The attached skb (if present) will only be freed
  1022. * if the callback returns 1
  1023. */
  1024. void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1025. {
  1026. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1027. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1028. int txq_id = SEQ_TO_QUEUE(sequence);
  1029. int index = SEQ_TO_INDEX(sequence);
  1030. int cmd_index;
  1031. bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  1032. struct iwl_device_cmd *cmd;
  1033. struct iwl_cmd_meta *meta;
  1034. /* If a Tx command is being handled and it isn't in the actual
  1035. * command queue then there a command routing bug has been introduced
  1036. * in the queue management code. */
  1037. if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
  1038. "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
  1039. txq_id, sequence,
  1040. priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
  1041. priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
  1042. iwl_print_hex_error(priv, pkt, 32);
  1043. return;
  1044. }
  1045. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1046. cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1047. meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index];
  1048. pci_unmap_single(priv->pci_dev,
  1049. pci_unmap_addr(meta, mapping),
  1050. pci_unmap_len(meta, len),
  1051. PCI_DMA_BIDIRECTIONAL);
  1052. /* Input error checking is done when commands are added to queue. */
  1053. if (meta->flags & CMD_WANT_SKB) {
  1054. meta->source->reply_page = (unsigned long)rxb_addr(rxb);
  1055. rxb->page = NULL;
  1056. } else if (meta->callback)
  1057. meta->callback(priv, cmd, pkt);
  1058. iwl_hcmd_queue_reclaim(priv, txq_id, index, cmd_index);
  1059. if (!(meta->flags & CMD_ASYNC)) {
  1060. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1061. IWL_DEBUG_INFO(priv, "Clearing HCMD_ACTIVE for command %s \n",
  1062. get_cmd_string(cmd->hdr.cmd));
  1063. wake_up_interruptible(&priv->wait_command_queue);
  1064. }
  1065. }
  1066. EXPORT_SYMBOL(iwl_tx_cmd_complete);
  1067. /*
  1068. * Find first available (lowest unused) Tx Queue, mark it "active".
  1069. * Called only when finding queue for aggregation.
  1070. * Should never return anything < 7, because they should already
  1071. * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
  1072. */
  1073. static int iwl_txq_ctx_activate_free(struct iwl_priv *priv)
  1074. {
  1075. int txq_id;
  1076. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
  1077. if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
  1078. return txq_id;
  1079. return -1;
  1080. }
  1081. int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
  1082. {
  1083. int sta_id;
  1084. int tx_fifo;
  1085. int txq_id;
  1086. int ret;
  1087. unsigned long flags;
  1088. struct iwl_tid_data *tid_data;
  1089. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  1090. tx_fifo = default_tid_to_tx_fifo[tid];
  1091. else
  1092. return -EINVAL;
  1093. IWL_WARN(priv, "%s on ra = %pM tid = %d\n",
  1094. __func__, ra, tid);
  1095. sta_id = iwl_find_station(priv, ra);
  1096. if (sta_id == IWL_INVALID_STATION) {
  1097. IWL_ERR(priv, "Start AGG on invalid station\n");
  1098. return -ENXIO;
  1099. }
  1100. if (unlikely(tid >= MAX_TID_COUNT))
  1101. return -EINVAL;
  1102. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
  1103. IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
  1104. return -ENXIO;
  1105. }
  1106. txq_id = iwl_txq_ctx_activate_free(priv);
  1107. if (txq_id == -1) {
  1108. IWL_ERR(priv, "No free aggregation queue available\n");
  1109. return -ENXIO;
  1110. }
  1111. spin_lock_irqsave(&priv->sta_lock, flags);
  1112. tid_data = &priv->stations[sta_id].tid[tid];
  1113. *ssn = SEQ_TO_SN(tid_data->seq_number);
  1114. tid_data->agg.txq_id = txq_id;
  1115. priv->txq[txq_id].swq_id = iwl_virtual_agg_queue_num(tx_fifo, txq_id);
  1116. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1117. ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,
  1118. sta_id, tid, *ssn);
  1119. if (ret)
  1120. return ret;
  1121. if (tid_data->tfds_in_queue == 0) {
  1122. IWL_DEBUG_HT(priv, "HW queue is empty\n");
  1123. tid_data->agg.state = IWL_AGG_ON;
  1124. ieee80211_start_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1125. } else {
  1126. IWL_DEBUG_HT(priv, "HW queue is NOT empty: %d packets in HW queue\n",
  1127. tid_data->tfds_in_queue);
  1128. tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
  1129. }
  1130. return ret;
  1131. }
  1132. EXPORT_SYMBOL(iwl_tx_agg_start);
  1133. int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
  1134. {
  1135. int tx_fifo_id, txq_id, sta_id, ssn = -1;
  1136. struct iwl_tid_data *tid_data;
  1137. int write_ptr, read_ptr;
  1138. unsigned long flags;
  1139. if (!ra) {
  1140. IWL_ERR(priv, "ra = NULL\n");
  1141. return -EINVAL;
  1142. }
  1143. if (unlikely(tid >= MAX_TID_COUNT))
  1144. return -EINVAL;
  1145. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  1146. tx_fifo_id = default_tid_to_tx_fifo[tid];
  1147. else
  1148. return -EINVAL;
  1149. sta_id = iwl_find_station(priv, ra);
  1150. if (sta_id == IWL_INVALID_STATION) {
  1151. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  1152. return -ENXIO;
  1153. }
  1154. if (priv->stations[sta_id].tid[tid].agg.state ==
  1155. IWL_EMPTYING_HW_QUEUE_ADDBA) {
  1156. IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
  1157. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1158. priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
  1159. return 0;
  1160. }
  1161. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
  1162. IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");
  1163. tid_data = &priv->stations[sta_id].tid[tid];
  1164. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  1165. txq_id = tid_data->agg.txq_id;
  1166. write_ptr = priv->txq[txq_id].q.write_ptr;
  1167. read_ptr = priv->txq[txq_id].q.read_ptr;
  1168. /* The queue is not empty */
  1169. if (write_ptr != read_ptr) {
  1170. IWL_DEBUG_HT(priv, "Stopping a non empty AGG HW QUEUE\n");
  1171. priv->stations[sta_id].tid[tid].agg.state =
  1172. IWL_EMPTYING_HW_QUEUE_DELBA;
  1173. return 0;
  1174. }
  1175. IWL_DEBUG_HT(priv, "HW queue is empty\n");
  1176. priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
  1177. spin_lock_irqsave(&priv->lock, flags);
  1178. /*
  1179. * the only reason this call can fail is queue number out of range,
  1180. * which can happen if uCode is reloaded and all the station
  1181. * information are lost. if it is outside the range, there is no need
  1182. * to deactivate the uCode queue, just return "success" to allow
  1183. * mac80211 to clean up it own data.
  1184. */
  1185. priv->cfg->ops->lib->txq_agg_disable(priv, txq_id, ssn,
  1186. tx_fifo_id);
  1187. spin_unlock_irqrestore(&priv->lock, flags);
  1188. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, ra, tid);
  1189. return 0;
  1190. }
  1191. EXPORT_SYMBOL(iwl_tx_agg_stop);
  1192. int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id)
  1193. {
  1194. struct iwl_queue *q = &priv->txq[txq_id].q;
  1195. u8 *addr = priv->stations[sta_id].sta.sta.addr;
  1196. struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
  1197. switch (priv->stations[sta_id].tid[tid].agg.state) {
  1198. case IWL_EMPTYING_HW_QUEUE_DELBA:
  1199. /* We are reclaiming the last packet of the */
  1200. /* aggregated HW queue */
  1201. if ((txq_id == tid_data->agg.txq_id) &&
  1202. (q->read_ptr == q->write_ptr)) {
  1203. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  1204. int tx_fifo = default_tid_to_tx_fifo[tid];
  1205. IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n");
  1206. priv->cfg->ops->lib->txq_agg_disable(priv, txq_id,
  1207. ssn, tx_fifo);
  1208. tid_data->agg.state = IWL_AGG_OFF;
  1209. ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, addr, tid);
  1210. }
  1211. break;
  1212. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  1213. /* We are reclaiming the last packet of the queue */
  1214. if (tid_data->tfds_in_queue == 0) {
  1215. IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n");
  1216. tid_data->agg.state = IWL_AGG_ON;
  1217. ieee80211_start_tx_ba_cb_irqsafe(priv->vif, addr, tid);
  1218. }
  1219. break;
  1220. }
  1221. return 0;
  1222. }
  1223. EXPORT_SYMBOL(iwl_txq_check_empty);
  1224. /**
  1225. * iwl_tx_status_reply_compressed_ba - Update tx status from block-ack
  1226. *
  1227. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  1228. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  1229. */
  1230. static int iwl_tx_status_reply_compressed_ba(struct iwl_priv *priv,
  1231. struct iwl_ht_agg *agg,
  1232. struct iwl_compressed_ba_resp *ba_resp)
  1233. {
  1234. int i, sh, ack;
  1235. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  1236. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  1237. u64 bitmap;
  1238. int successes = 0;
  1239. struct ieee80211_tx_info *info;
  1240. if (unlikely(!agg->wait_for_ba)) {
  1241. IWL_ERR(priv, "Received BA when not expected\n");
  1242. return -EINVAL;
  1243. }
  1244. /* Mark that the expected block-ack response arrived */
  1245. agg->wait_for_ba = 0;
  1246. IWL_DEBUG_TX_REPLY(priv, "BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
  1247. /* Calculate shift to align block-ack bits with our Tx window bits */
  1248. sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl >> 4);
  1249. if (sh < 0) /* tbw something is wrong with indices */
  1250. sh += 0x100;
  1251. /* don't use 64-bit values for now */
  1252. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  1253. if (agg->frame_count > (64 - sh)) {
  1254. IWL_DEBUG_TX_REPLY(priv, "more frames than bitmap size");
  1255. return -1;
  1256. }
  1257. /* check for success or failure according to the
  1258. * transmitted bitmap and block-ack bitmap */
  1259. bitmap &= agg->bitmap;
  1260. /* For each frame attempted in aggregation,
  1261. * update driver's record of tx frame's status. */
  1262. for (i = 0; i < agg->frame_count ; i++) {
  1263. ack = bitmap & (1ULL << i);
  1264. successes += !!ack;
  1265. IWL_DEBUG_TX_REPLY(priv, "%s ON i=%d idx=%d raw=%d\n",
  1266. ack ? "ACK" : "NACK", i, (agg->start_idx + i) & 0xff,
  1267. agg->start_idx + i);
  1268. }
  1269. info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
  1270. memset(&info->status, 0, sizeof(info->status));
  1271. info->flags |= IEEE80211_TX_STAT_ACK;
  1272. info->flags |= IEEE80211_TX_STAT_AMPDU;
  1273. info->status.ampdu_ack_map = successes;
  1274. info->status.ampdu_ack_len = agg->frame_count;
  1275. iwl_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
  1276. IWL_DEBUG_TX_REPLY(priv, "Bitmap %llx\n", (unsigned long long)bitmap);
  1277. return 0;
  1278. }
  1279. /**
  1280. * iwl_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  1281. *
  1282. * Handles block-acknowledge notification from device, which reports success
  1283. * of frames sent via aggregation.
  1284. */
  1285. void iwl_rx_reply_compressed_ba(struct iwl_priv *priv,
  1286. struct iwl_rx_mem_buffer *rxb)
  1287. {
  1288. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1289. struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  1290. struct iwl_tx_queue *txq = NULL;
  1291. struct iwl_ht_agg *agg;
  1292. int index;
  1293. int sta_id;
  1294. int tid;
  1295. /* "flow" corresponds to Tx queue */
  1296. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  1297. /* "ssn" is start of block-ack Tx window, corresponds to index
  1298. * (in Tx queue's circular buffer) of first TFD/frame in window */
  1299. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  1300. if (scd_flow >= priv->hw_params.max_txq_num) {
  1301. IWL_ERR(priv,
  1302. "BUG_ON scd_flow is bigger than number of queues\n");
  1303. return;
  1304. }
  1305. txq = &priv->txq[scd_flow];
  1306. sta_id = ba_resp->sta_id;
  1307. tid = ba_resp->tid;
  1308. agg = &priv->stations[sta_id].tid[tid].agg;
  1309. /* Find index just before block-ack window */
  1310. index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  1311. /* TODO: Need to get this copy more safely - now good for debug */
  1312. IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
  1313. "sta_id = %d\n",
  1314. agg->wait_for_ba,
  1315. (u8 *) &ba_resp->sta_addr_lo32,
  1316. ba_resp->sta_id);
  1317. IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
  1318. "%d, scd_ssn = %d\n",
  1319. ba_resp->tid,
  1320. ba_resp->seq_ctl,
  1321. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  1322. ba_resp->scd_flow,
  1323. ba_resp->scd_ssn);
  1324. IWL_DEBUG_TX_REPLY(priv, "DAT start_idx = %d, bitmap = 0x%llx \n",
  1325. agg->start_idx,
  1326. (unsigned long long)agg->bitmap);
  1327. /* Update driver's record of ACK vs. not for each frame in window */
  1328. iwl_tx_status_reply_compressed_ba(priv, agg, ba_resp);
  1329. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  1330. * block-ack window (we assume that they've been successfully
  1331. * transmitted ... if not, it's too late anyway). */
  1332. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  1333. /* calculate mac80211 ampdu sw queue to wake */
  1334. int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
  1335. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  1336. if ((iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  1337. priv->mac80211_registered &&
  1338. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA))
  1339. iwl_wake_queue(priv, txq->swq_id);
  1340. iwl_txq_check_empty(priv, sta_id, tid, scd_flow);
  1341. }
  1342. }
  1343. EXPORT_SYMBOL(iwl_rx_reply_compressed_ba);
  1344. #ifdef CONFIG_IWLWIFI_DEBUG
  1345. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1346. const char *iwl_get_tx_fail_reason(u32 status)
  1347. {
  1348. switch (status & TX_STATUS_MSK) {
  1349. case TX_STATUS_SUCCESS:
  1350. return "SUCCESS";
  1351. TX_STATUS_ENTRY(SHORT_LIMIT);
  1352. TX_STATUS_ENTRY(LONG_LIMIT);
  1353. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  1354. TX_STATUS_ENTRY(MGMNT_ABORT);
  1355. TX_STATUS_ENTRY(NEXT_FRAG);
  1356. TX_STATUS_ENTRY(LIFE_EXPIRE);
  1357. TX_STATUS_ENTRY(DEST_PS);
  1358. TX_STATUS_ENTRY(ABORTED);
  1359. TX_STATUS_ENTRY(BT_RETRY);
  1360. TX_STATUS_ENTRY(STA_INVALID);
  1361. TX_STATUS_ENTRY(FRAG_DROPPED);
  1362. TX_STATUS_ENTRY(TID_DISABLE);
  1363. TX_STATUS_ENTRY(FRAME_FLUSHED);
  1364. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  1365. TX_STATUS_ENTRY(TX_LOCKED);
  1366. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  1367. }
  1368. return "UNKNOWN";
  1369. }
  1370. EXPORT_SYMBOL(iwl_get_tx_fail_reason);
  1371. #endif /* CONFIG_IWLWIFI_DEBUG */