iwl-rx.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/etherdevice.h>
  30. #include <net/mac80211.h>
  31. #include <asm/unaligned.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-calib.h"
  38. #include "iwl-helpers.h"
  39. /************************** RX-FUNCTIONS ****************************/
  40. /*
  41. * Rx theory of operation
  42. *
  43. * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
  44. * each of which point to Receive Buffers to be filled by the NIC. These get
  45. * used not only for Rx frames, but for any command response or notification
  46. * from the NIC. The driver and NIC manage the Rx buffers by means
  47. * of indexes into the circular buffer.
  48. *
  49. * Rx Queue Indexes
  50. * The host/firmware share two index registers for managing the Rx buffers.
  51. *
  52. * The READ index maps to the first position that the firmware may be writing
  53. * to -- the driver can read up to (but not including) this position and get
  54. * good data.
  55. * The READ index is managed by the firmware once the card is enabled.
  56. *
  57. * The WRITE index maps to the last position the driver has read from -- the
  58. * position preceding WRITE is the last slot the firmware can place a packet.
  59. *
  60. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  61. * WRITE = READ.
  62. *
  63. * During initialization, the host sets up the READ queue position to the first
  64. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  65. *
  66. * When the firmware places a packet in a buffer, it will advance the READ index
  67. * and fire the RX interrupt. The driver can then query the READ index and
  68. * process as many packets as possible, moving the WRITE index forward as it
  69. * resets the Rx queue buffers with new memory.
  70. *
  71. * The management in the driver is as follows:
  72. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  73. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  74. * to replenish the iwl->rxq->rx_free.
  75. * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
  76. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  77. * 'processed' and 'read' driver indexes as well)
  78. * + A received packet is processed and handed to the kernel network stack,
  79. * detached from the iwl->rxq. The driver 'processed' index is updated.
  80. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  81. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  82. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  83. * were enough free buffers and RX_STALLED is set it is cleared.
  84. *
  85. *
  86. * Driver sequence:
  87. *
  88. * iwl_rx_queue_alloc() Allocates rx_free
  89. * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
  90. * iwl_rx_queue_restock
  91. * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
  92. * queue, updates firmware pointers, and updates
  93. * the WRITE index. If insufficient rx_free buffers
  94. * are available, schedules iwl_rx_replenish
  95. *
  96. * -- enable interrupts --
  97. * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
  98. * READ INDEX, detaching the SKB from the pool.
  99. * Moves the packet buffer from queue to rx_used.
  100. * Calls iwl_rx_queue_restock to refill any empty
  101. * slots.
  102. * ...
  103. *
  104. */
  105. /**
  106. * iwl_rx_queue_space - Return number of free slots available in queue.
  107. */
  108. int iwl_rx_queue_space(const struct iwl_rx_queue *q)
  109. {
  110. int s = q->read - q->write;
  111. if (s <= 0)
  112. s += RX_QUEUE_SIZE;
  113. /* keep some buffer to not confuse full and empty queue */
  114. s -= 2;
  115. if (s < 0)
  116. s = 0;
  117. return s;
  118. }
  119. EXPORT_SYMBOL(iwl_rx_queue_space);
  120. /**
  121. * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  122. */
  123. int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
  124. {
  125. unsigned long flags;
  126. u32 rx_wrt_ptr_reg = priv->hw_params.rx_wrt_ptr_reg;
  127. u32 reg;
  128. int ret = 0;
  129. spin_lock_irqsave(&q->lock, flags);
  130. if (q->need_update == 0)
  131. goto exit_unlock;
  132. /* If power-saving is in use, make sure device is awake */
  133. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  134. reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
  135. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  136. iwl_set_bit(priv, CSR_GP_CNTRL,
  137. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  138. goto exit_unlock;
  139. }
  140. q->write_actual = (q->write & ~0x7);
  141. iwl_write_direct32(priv, rx_wrt_ptr_reg, q->write_actual);
  142. /* Else device is assumed to be awake */
  143. } else {
  144. /* Device expects a multiple of 8 */
  145. q->write_actual = (q->write & ~0x7);
  146. iwl_write_direct32(priv, rx_wrt_ptr_reg, q->write_actual);
  147. }
  148. q->need_update = 0;
  149. exit_unlock:
  150. spin_unlock_irqrestore(&q->lock, flags);
  151. return ret;
  152. }
  153. EXPORT_SYMBOL(iwl_rx_queue_update_write_ptr);
  154. /**
  155. * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  156. */
  157. static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv,
  158. dma_addr_t dma_addr)
  159. {
  160. return cpu_to_le32((u32)(dma_addr >> 8));
  161. }
  162. /**
  163. * iwl_rx_queue_restock - refill RX queue from pre-allocated pool
  164. *
  165. * If there are slots in the RX queue that need to be restocked,
  166. * and we have free pre-allocated buffers, fill the ranks as much
  167. * as we can, pulling from rx_free.
  168. *
  169. * This moves the 'write' index forward to catch up with 'processed', and
  170. * also updates the memory address in the firmware to reference the new
  171. * target buffer.
  172. */
  173. int iwl_rx_queue_restock(struct iwl_priv *priv)
  174. {
  175. struct iwl_rx_queue *rxq = &priv->rxq;
  176. struct list_head *element;
  177. struct iwl_rx_mem_buffer *rxb;
  178. unsigned long flags;
  179. int write;
  180. int ret = 0;
  181. spin_lock_irqsave(&rxq->lock, flags);
  182. write = rxq->write & ~0x7;
  183. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  184. /* Get next free Rx buffer, remove from free list */
  185. element = rxq->rx_free.next;
  186. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  187. list_del(element);
  188. /* Point to Rx buffer via next RBD in circular buffer */
  189. rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->aligned_dma_addr);
  190. rxq->queue[rxq->write] = rxb;
  191. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  192. rxq->free_count--;
  193. }
  194. spin_unlock_irqrestore(&rxq->lock, flags);
  195. /* If the pre-allocated buffer pool is dropping low, schedule to
  196. * refill it */
  197. if (rxq->free_count <= RX_LOW_WATERMARK)
  198. queue_work(priv->workqueue, &priv->rx_replenish);
  199. /* If we've added more space for the firmware to place data, tell it.
  200. * Increment device's write pointer in multiples of 8. */
  201. if (rxq->write_actual != (rxq->write & ~0x7)) {
  202. spin_lock_irqsave(&rxq->lock, flags);
  203. rxq->need_update = 1;
  204. spin_unlock_irqrestore(&rxq->lock, flags);
  205. ret = iwl_rx_queue_update_write_ptr(priv, rxq);
  206. }
  207. return ret;
  208. }
  209. EXPORT_SYMBOL(iwl_rx_queue_restock);
  210. /**
  211. * iwl_rx_replenish - Move all used packet from rx_used to rx_free
  212. *
  213. * When moving to rx_free an SKB is allocated for the slot.
  214. *
  215. * Also restock the Rx queue via iwl_rx_queue_restock.
  216. * This is called as a scheduled work item (except for during initialization)
  217. */
  218. void iwl_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  219. {
  220. struct iwl_rx_queue *rxq = &priv->rxq;
  221. struct list_head *element;
  222. struct iwl_rx_mem_buffer *rxb;
  223. struct sk_buff *skb;
  224. unsigned long flags;
  225. while (1) {
  226. spin_lock_irqsave(&rxq->lock, flags);
  227. if (list_empty(&rxq->rx_used)) {
  228. spin_unlock_irqrestore(&rxq->lock, flags);
  229. return;
  230. }
  231. spin_unlock_irqrestore(&rxq->lock, flags);
  232. /* Alloc a new receive buffer */
  233. skb = alloc_skb(priv->hw_params.rx_buf_size + 256,
  234. priority);
  235. if (!skb) {
  236. IWL_CRIT(priv, "Can not allocate SKB buffers\n");
  237. /* We don't reschedule replenish work here -- we will
  238. * call the restock method and if it still needs
  239. * more buffers it will schedule replenish */
  240. break;
  241. }
  242. spin_lock_irqsave(&rxq->lock, flags);
  243. if (list_empty(&rxq->rx_used)) {
  244. spin_unlock_irqrestore(&rxq->lock, flags);
  245. dev_kfree_skb_any(skb);
  246. return;
  247. }
  248. element = rxq->rx_used.next;
  249. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  250. list_del(element);
  251. spin_unlock_irqrestore(&rxq->lock, flags);
  252. rxb->skb = skb;
  253. /* Get physical address of RB/SKB */
  254. rxb->real_dma_addr = pci_map_single(
  255. priv->pci_dev,
  256. rxb->skb->data,
  257. priv->hw_params.rx_buf_size + 256,
  258. PCI_DMA_FROMDEVICE);
  259. /* dma address must be no more than 36 bits */
  260. BUG_ON(rxb->real_dma_addr & ~DMA_BIT_MASK(36));
  261. /* and also 256 byte aligned! */
  262. rxb->aligned_dma_addr = ALIGN(rxb->real_dma_addr, 256);
  263. skb_reserve(rxb->skb, rxb->aligned_dma_addr - rxb->real_dma_addr);
  264. spin_lock_irqsave(&rxq->lock, flags);
  265. list_add_tail(&rxb->list, &rxq->rx_free);
  266. rxq->free_count++;
  267. priv->alloc_rxb_skb++;
  268. spin_unlock_irqrestore(&rxq->lock, flags);
  269. }
  270. }
  271. void iwl_rx_replenish(struct iwl_priv *priv)
  272. {
  273. unsigned long flags;
  274. iwl_rx_allocate(priv, GFP_KERNEL);
  275. spin_lock_irqsave(&priv->lock, flags);
  276. iwl_rx_queue_restock(priv);
  277. spin_unlock_irqrestore(&priv->lock, flags);
  278. }
  279. EXPORT_SYMBOL(iwl_rx_replenish);
  280. void iwl_rx_replenish_now(struct iwl_priv *priv)
  281. {
  282. iwl_rx_allocate(priv, GFP_ATOMIC);
  283. iwl_rx_queue_restock(priv);
  284. }
  285. EXPORT_SYMBOL(iwl_rx_replenish_now);
  286. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  287. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  288. * This free routine walks the list of POOL entries and if SKB is set to
  289. * non NULL it is unmapped and freed
  290. */
  291. void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  292. {
  293. int i;
  294. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  295. if (rxq->pool[i].skb != NULL) {
  296. pci_unmap_single(priv->pci_dev,
  297. rxq->pool[i].real_dma_addr,
  298. priv->hw_params.rx_buf_size + 256,
  299. PCI_DMA_FROMDEVICE);
  300. dev_kfree_skb(rxq->pool[i].skb);
  301. }
  302. }
  303. pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  304. rxq->dma_addr);
  305. pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
  306. rxq->rb_stts, rxq->rb_stts_dma);
  307. rxq->bd = NULL;
  308. rxq->rb_stts = NULL;
  309. }
  310. EXPORT_SYMBOL(iwl_rx_queue_free);
  311. int iwl_rx_queue_alloc(struct iwl_priv *priv)
  312. {
  313. struct iwl_rx_queue *rxq = &priv->rxq;
  314. struct pci_dev *dev = priv->pci_dev;
  315. int i;
  316. spin_lock_init(&rxq->lock);
  317. INIT_LIST_HEAD(&rxq->rx_free);
  318. INIT_LIST_HEAD(&rxq->rx_used);
  319. /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
  320. rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
  321. if (!rxq->bd)
  322. goto err_bd;
  323. rxq->rb_stts = pci_alloc_consistent(dev, sizeof(struct iwl_rb_status),
  324. &rxq->rb_stts_dma);
  325. if (!rxq->rb_stts)
  326. goto err_rb;
  327. /* Fill the rx_used queue with _all_ of the Rx buffers */
  328. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  329. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  330. /* Set us so that we have processed and used all buffers, but have
  331. * not restocked the Rx queue with fresh buffers */
  332. rxq->read = rxq->write = 0;
  333. rxq->write_actual = 0;
  334. rxq->free_count = 0;
  335. rxq->need_update = 0;
  336. return 0;
  337. err_rb:
  338. pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  339. rxq->dma_addr);
  340. err_bd:
  341. return -ENOMEM;
  342. }
  343. EXPORT_SYMBOL(iwl_rx_queue_alloc);
  344. void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  345. {
  346. unsigned long flags;
  347. int i;
  348. spin_lock_irqsave(&rxq->lock, flags);
  349. INIT_LIST_HEAD(&rxq->rx_free);
  350. INIT_LIST_HEAD(&rxq->rx_used);
  351. /* Fill the rx_used queue with _all_ of the Rx buffers */
  352. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  353. /* In the reset function, these buffers may have been allocated
  354. * to an SKB, so we need to unmap and free potential storage */
  355. if (rxq->pool[i].skb != NULL) {
  356. pci_unmap_single(priv->pci_dev,
  357. rxq->pool[i].real_dma_addr,
  358. priv->hw_params.rx_buf_size + 256,
  359. PCI_DMA_FROMDEVICE);
  360. priv->alloc_rxb_skb--;
  361. dev_kfree_skb(rxq->pool[i].skb);
  362. rxq->pool[i].skb = NULL;
  363. }
  364. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  365. }
  366. /* Set us so that we have processed and used all buffers, but have
  367. * not restocked the Rx queue with fresh buffers */
  368. rxq->read = rxq->write = 0;
  369. rxq->write_actual = 0;
  370. rxq->free_count = 0;
  371. spin_unlock_irqrestore(&rxq->lock, flags);
  372. }
  373. int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  374. {
  375. u32 rb_size;
  376. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  377. u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT for all devices? */
  378. if (!priv->cfg->use_isr_legacy)
  379. rb_timeout = RX_RB_TIMEOUT;
  380. if (priv->cfg->mod_params->amsdu_size_8K)
  381. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  382. else
  383. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  384. /* Stop Rx DMA */
  385. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  386. /* Reset driver's Rx queue write index */
  387. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  388. /* Tell device where to find RBD circular buffer in DRAM */
  389. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  390. (u32)(rxq->dma_addr >> 8));
  391. /* Tell device where in DRAM to update its Rx status */
  392. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  393. rxq->rb_stts_dma >> 4);
  394. /* Enable Rx DMA
  395. * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
  396. * the credit mechanism in 5000 HW RX FIFO
  397. * Direct rx interrupts to hosts
  398. * Rx buffer size 4 or 8k
  399. * RB timeout 0x10
  400. * 256 RBDs
  401. */
  402. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  403. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  404. FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
  405. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  406. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  407. rb_size|
  408. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  409. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  410. iwl_write32(priv, CSR_INT_COALESCING, 0x40);
  411. return 0;
  412. }
  413. int iwl_rxq_stop(struct iwl_priv *priv)
  414. {
  415. /* stop Rx DMA */
  416. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  417. iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  418. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  419. return 0;
  420. }
  421. EXPORT_SYMBOL(iwl_rxq_stop);
  422. void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
  423. struct iwl_rx_mem_buffer *rxb)
  424. {
  425. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  426. struct iwl_missed_beacon_notif *missed_beacon;
  427. missed_beacon = &pkt->u.missed_beacon;
  428. if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
  429. IWL_DEBUG_CALIB(priv, "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  430. le32_to_cpu(missed_beacon->consequtive_missed_beacons),
  431. le32_to_cpu(missed_beacon->total_missed_becons),
  432. le32_to_cpu(missed_beacon->num_recvd_beacons),
  433. le32_to_cpu(missed_beacon->num_expected_beacons));
  434. if (!test_bit(STATUS_SCANNING, &priv->status))
  435. iwl_init_sensitivity(priv);
  436. }
  437. }
  438. EXPORT_SYMBOL(iwl_rx_missed_beacon_notif);
  439. /* Calculate noise level, based on measurements during network silence just
  440. * before arriving beacon. This measurement can be done only if we know
  441. * exactly when to expect beacons, therefore only when we're associated. */
  442. static void iwl_rx_calc_noise(struct iwl_priv *priv)
  443. {
  444. struct statistics_rx_non_phy *rx_info
  445. = &(priv->statistics.rx.general);
  446. int num_active_rx = 0;
  447. int total_silence = 0;
  448. int bcn_silence_a =
  449. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  450. int bcn_silence_b =
  451. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  452. int bcn_silence_c =
  453. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  454. if (bcn_silence_a) {
  455. total_silence += bcn_silence_a;
  456. num_active_rx++;
  457. }
  458. if (bcn_silence_b) {
  459. total_silence += bcn_silence_b;
  460. num_active_rx++;
  461. }
  462. if (bcn_silence_c) {
  463. total_silence += bcn_silence_c;
  464. num_active_rx++;
  465. }
  466. /* Average among active antennas */
  467. if (num_active_rx)
  468. priv->last_rx_noise = (total_silence / num_active_rx) - 107;
  469. else
  470. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  471. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  472. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  473. priv->last_rx_noise);
  474. }
  475. #define REG_RECALIB_PERIOD (60)
  476. void iwl_rx_statistics(struct iwl_priv *priv,
  477. struct iwl_rx_mem_buffer *rxb)
  478. {
  479. int change;
  480. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  481. IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
  482. (int)sizeof(priv->statistics),
  483. le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
  484. change = ((priv->statistics.general.temperature !=
  485. pkt->u.stats.general.temperature) ||
  486. ((priv->statistics.flag &
  487. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  488. (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  489. memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
  490. set_bit(STATUS_STATISTICS, &priv->status);
  491. /* Reschedule the statistics timer to occur in
  492. * REG_RECALIB_PERIOD seconds to ensure we get a
  493. * thermal update even if the uCode doesn't give
  494. * us one */
  495. mod_timer(&priv->statistics_periodic, jiffies +
  496. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  497. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  498. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  499. iwl_rx_calc_noise(priv);
  500. queue_work(priv->workqueue, &priv->run_time_calib_work);
  501. }
  502. iwl_leds_background(priv);
  503. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  504. priv->cfg->ops->lib->temp_ops.temperature(priv);
  505. }
  506. EXPORT_SYMBOL(iwl_rx_statistics);
  507. #define PERFECT_RSSI (-20) /* dBm */
  508. #define WORST_RSSI (-95) /* dBm */
  509. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  510. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  511. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  512. * about formulas used below. */
  513. static int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm)
  514. {
  515. int sig_qual;
  516. int degradation = PERFECT_RSSI - rssi_dbm;
  517. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  518. * as indicator; formula is (signal dbm - noise dbm).
  519. * SNR at or above 40 is a great signal (100%).
  520. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  521. * Weakest usable signal is usually 10 - 15 dB SNR. */
  522. if (noise_dbm) {
  523. if (rssi_dbm - noise_dbm >= 40)
  524. return 100;
  525. else if (rssi_dbm < noise_dbm)
  526. return 0;
  527. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  528. /* Else use just the signal level.
  529. * This formula is a least squares fit of data points collected and
  530. * compared with a reference system that had a percentage (%) display
  531. * for signal quality. */
  532. } else
  533. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  534. (15 * RSSI_RANGE + 62 * degradation)) /
  535. (RSSI_RANGE * RSSI_RANGE);
  536. if (sig_qual > 100)
  537. sig_qual = 100;
  538. else if (sig_qual < 1)
  539. sig_qual = 0;
  540. return sig_qual;
  541. }
  542. /* Calc max signal level (dBm) among 3 possible receivers */
  543. static inline int iwl_calc_rssi(struct iwl_priv *priv,
  544. struct iwl_rx_phy_res *rx_resp)
  545. {
  546. return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
  547. }
  548. #ifdef CONFIG_IWLWIFI_DEBUG
  549. /**
  550. * iwl_dbg_report_frame - dump frame to syslog during debug sessions
  551. *
  552. * You may hack this function to show different aspects of received frames,
  553. * including selective frame dumps.
  554. * group100 parameter selects whether to show 1 out of 100 good data frames.
  555. * All beacon and probe response frames are printed.
  556. */
  557. static void iwl_dbg_report_frame(struct iwl_priv *priv,
  558. struct iwl_rx_phy_res *phy_res, u16 length,
  559. struct ieee80211_hdr *header, int group100)
  560. {
  561. u32 to_us;
  562. u32 print_summary = 0;
  563. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  564. u32 hundred = 0;
  565. u32 dataframe = 0;
  566. __le16 fc;
  567. u16 seq_ctl;
  568. u16 channel;
  569. u16 phy_flags;
  570. u32 rate_n_flags;
  571. u32 tsf_low;
  572. int rssi;
  573. if (likely(!(iwl_get_debug_level(priv) & IWL_DL_RX)))
  574. return;
  575. /* MAC header */
  576. fc = header->frame_control;
  577. seq_ctl = le16_to_cpu(header->seq_ctrl);
  578. /* metadata */
  579. channel = le16_to_cpu(phy_res->channel);
  580. phy_flags = le16_to_cpu(phy_res->phy_flags);
  581. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  582. /* signal statistics */
  583. rssi = iwl_calc_rssi(priv, phy_res);
  584. tsf_low = le64_to_cpu(phy_res->timestamp) & 0x0ffffffff;
  585. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  586. /* if data frame is to us and all is good,
  587. * (optionally) print summary for only 1 out of every 100 */
  588. if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
  589. cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  590. dataframe = 1;
  591. if (!group100)
  592. print_summary = 1; /* print each frame */
  593. else if (priv->framecnt_to_us < 100) {
  594. priv->framecnt_to_us++;
  595. print_summary = 0;
  596. } else {
  597. priv->framecnt_to_us = 0;
  598. print_summary = 1;
  599. hundred = 1;
  600. }
  601. } else {
  602. /* print summary for all other frames */
  603. print_summary = 1;
  604. }
  605. if (print_summary) {
  606. char *title;
  607. int rate_idx;
  608. u32 bitrate;
  609. if (hundred)
  610. title = "100Frames";
  611. else if (ieee80211_has_retry(fc))
  612. title = "Retry";
  613. else if (ieee80211_is_assoc_resp(fc))
  614. title = "AscRsp";
  615. else if (ieee80211_is_reassoc_resp(fc))
  616. title = "RasRsp";
  617. else if (ieee80211_is_probe_resp(fc)) {
  618. title = "PrbRsp";
  619. print_dump = 1; /* dump frame contents */
  620. } else if (ieee80211_is_beacon(fc)) {
  621. title = "Beacon";
  622. print_dump = 1; /* dump frame contents */
  623. } else if (ieee80211_is_atim(fc))
  624. title = "ATIM";
  625. else if (ieee80211_is_auth(fc))
  626. title = "Auth";
  627. else if (ieee80211_is_deauth(fc))
  628. title = "DeAuth";
  629. else if (ieee80211_is_disassoc(fc))
  630. title = "DisAssoc";
  631. else
  632. title = "Frame";
  633. rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
  634. if (unlikely((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT))) {
  635. bitrate = 0;
  636. WARN_ON_ONCE(1);
  637. } else {
  638. bitrate = iwl_rates[rate_idx].ieee / 2;
  639. }
  640. /* print frame summary.
  641. * MAC addresses show just the last byte (for brevity),
  642. * but you can hack it to show more, if you'd like to. */
  643. if (dataframe)
  644. IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, "
  645. "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
  646. title, le16_to_cpu(fc), header->addr1[5],
  647. length, rssi, channel, bitrate);
  648. else {
  649. /* src/dst addresses assume managed mode */
  650. IWL_DEBUG_RX(priv, "%s: 0x%04x, dst=0x%02x, src=0x%02x, "
  651. "len=%u, rssi=%d, tim=%lu usec, "
  652. "phy=0x%02x, chnl=%d\n",
  653. title, le16_to_cpu(fc), header->addr1[5],
  654. header->addr3[5], length, rssi,
  655. tsf_low - priv->scan_start_tsf,
  656. phy_flags, channel);
  657. }
  658. }
  659. if (print_dump)
  660. iwl_print_hex_dump(priv, IWL_DL_RX, header, length);
  661. }
  662. #endif
  663. /*
  664. * returns non-zero if packet should be dropped
  665. */
  666. int iwl_set_decrypted_flag(struct iwl_priv *priv,
  667. struct ieee80211_hdr *hdr,
  668. u32 decrypt_res,
  669. struct ieee80211_rx_status *stats)
  670. {
  671. u16 fc = le16_to_cpu(hdr->frame_control);
  672. if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
  673. return 0;
  674. if (!(fc & IEEE80211_FCTL_PROTECTED))
  675. return 0;
  676. IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
  677. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  678. case RX_RES_STATUS_SEC_TYPE_TKIP:
  679. /* The uCode has got a bad phase 1 Key, pushes the packet.
  680. * Decryption will be done in SW. */
  681. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  682. RX_RES_STATUS_BAD_KEY_TTAK)
  683. break;
  684. case RX_RES_STATUS_SEC_TYPE_WEP:
  685. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  686. RX_RES_STATUS_BAD_ICV_MIC) {
  687. /* bad ICV, the packet is destroyed since the
  688. * decryption is inplace, drop it */
  689. IWL_DEBUG_RX(priv, "Packet destroyed\n");
  690. return -1;
  691. }
  692. case RX_RES_STATUS_SEC_TYPE_CCMP:
  693. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  694. RX_RES_STATUS_DECRYPT_OK) {
  695. IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
  696. stats->flag |= RX_FLAG_DECRYPTED;
  697. }
  698. break;
  699. default:
  700. break;
  701. }
  702. return 0;
  703. }
  704. EXPORT_SYMBOL(iwl_set_decrypted_flag);
  705. static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  706. {
  707. u32 decrypt_out = 0;
  708. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  709. RX_RES_STATUS_STATION_FOUND)
  710. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  711. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  712. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  713. /* packet was not encrypted */
  714. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  715. RX_RES_STATUS_SEC_TYPE_NONE)
  716. return decrypt_out;
  717. /* packet was encrypted with unknown alg */
  718. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  719. RX_RES_STATUS_SEC_TYPE_ERR)
  720. return decrypt_out;
  721. /* decryption was not done in HW */
  722. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  723. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  724. return decrypt_out;
  725. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  726. case RX_RES_STATUS_SEC_TYPE_CCMP:
  727. /* alg is CCM: check MIC only */
  728. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  729. /* Bad MIC */
  730. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  731. else
  732. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  733. break;
  734. case RX_RES_STATUS_SEC_TYPE_TKIP:
  735. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  736. /* Bad TTAK */
  737. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  738. break;
  739. }
  740. /* fall through if TTAK OK */
  741. default:
  742. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  743. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  744. else
  745. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  746. break;
  747. };
  748. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  749. decrypt_in, decrypt_out);
  750. return decrypt_out;
  751. }
  752. static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
  753. struct ieee80211_hdr *hdr,
  754. u16 len,
  755. u32 ampdu_status,
  756. struct iwl_rx_mem_buffer *rxb,
  757. struct ieee80211_rx_status *stats)
  758. {
  759. /* We only process data packets if the interface is open */
  760. if (unlikely(!priv->is_open)) {
  761. IWL_DEBUG_DROP_LIMIT(priv,
  762. "Dropping packet while interface is not open.\n");
  763. return;
  764. }
  765. /* In case of HW accelerated crypto and bad decryption, drop */
  766. if (!priv->cfg->mod_params->sw_crypto &&
  767. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  768. return;
  769. /* Resize SKB from mac header to end of packet */
  770. skb_reserve(rxb->skb, (void *)hdr - (void *)rxb->skb->data);
  771. skb_put(rxb->skb, len);
  772. iwl_update_stats(priv, false, hdr->frame_control, len);
  773. memcpy(IEEE80211_SKB_RXCB(rxb->skb), stats, sizeof(*stats));
  774. ieee80211_rx_irqsafe(priv->hw, rxb->skb);
  775. priv->alloc_rxb_skb--;
  776. rxb->skb = NULL;
  777. }
  778. /* This is necessary only for a number of statistics, see the caller. */
  779. static int iwl_is_network_packet(struct iwl_priv *priv,
  780. struct ieee80211_hdr *header)
  781. {
  782. /* Filter incoming packets to determine if they are targeted toward
  783. * this network, discarding packets coming from ourselves */
  784. switch (priv->iw_mode) {
  785. case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
  786. /* packets to our IBSS update information */
  787. return !compare_ether_addr(header->addr3, priv->bssid);
  788. case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
  789. /* packets to our IBSS update information */
  790. return !compare_ether_addr(header->addr2, priv->bssid);
  791. default:
  792. return 1;
  793. }
  794. }
  795. /* Called for REPLY_RX (legacy ABG frames), or
  796. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  797. void iwl_rx_reply_rx(struct iwl_priv *priv,
  798. struct iwl_rx_mem_buffer *rxb)
  799. {
  800. struct ieee80211_hdr *header;
  801. struct ieee80211_rx_status rx_status;
  802. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  803. struct iwl_rx_phy_res *phy_res;
  804. __le32 rx_pkt_status;
  805. struct iwl4965_rx_mpdu_res_start *amsdu;
  806. u32 len;
  807. u32 ampdu_status;
  808. u16 fc;
  809. u32 rate_n_flags;
  810. /**
  811. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  812. * REPLY_RX: physical layer info is in this buffer
  813. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  814. * command and cached in priv->last_phy_res
  815. *
  816. * Here we set up local variables depending on which command is
  817. * received.
  818. */
  819. if (pkt->hdr.cmd == REPLY_RX) {
  820. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  821. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  822. + phy_res->cfg_phy_cnt);
  823. len = le16_to_cpu(phy_res->byte_count);
  824. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  825. phy_res->cfg_phy_cnt + len);
  826. ampdu_status = le32_to_cpu(rx_pkt_status);
  827. } else {
  828. if (!priv->last_phy_res[0]) {
  829. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  830. return;
  831. }
  832. phy_res = (struct iwl_rx_phy_res *)&priv->last_phy_res[1];
  833. amsdu = (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  834. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  835. len = le16_to_cpu(amsdu->byte_count);
  836. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  837. ampdu_status = iwl_translate_rx_status(priv,
  838. le32_to_cpu(rx_pkt_status));
  839. }
  840. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  841. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  842. phy_res->cfg_phy_cnt);
  843. return;
  844. }
  845. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  846. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  847. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  848. le32_to_cpu(rx_pkt_status));
  849. return;
  850. }
  851. /* This will be used in several places later */
  852. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  853. /* rx_status carries information about the packet to mac80211 */
  854. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  855. rx_status.freq =
  856. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel));
  857. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  858. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  859. rx_status.rate_idx =
  860. iwl_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  861. rx_status.flag = 0;
  862. /* TSF isn't reliable. In order to allow smooth user experience,
  863. * this W/A doesn't propagate it to the mac80211 */
  864. /*rx_status.flag |= RX_FLAG_TSFT;*/
  865. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  866. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  867. rx_status.signal = iwl_calc_rssi(priv, phy_res);
  868. /* Meaningful noise values are available only from beacon statistics,
  869. * which are gathered only when associated, and indicate noise
  870. * only for the associated network channel ...
  871. * Ignore these noise values while scanning (other channels) */
  872. if (iwl_is_associated(priv) &&
  873. !test_bit(STATUS_SCANNING, &priv->status)) {
  874. rx_status.noise = priv->last_rx_noise;
  875. rx_status.qual = iwl_calc_sig_qual(rx_status.signal,
  876. rx_status.noise);
  877. } else {
  878. rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  879. rx_status.qual = iwl_calc_sig_qual(rx_status.signal, 0);
  880. }
  881. /* Reset beacon noise level if not associated. */
  882. if (!iwl_is_associated(priv))
  883. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  884. #ifdef CONFIG_IWLWIFI_DEBUG
  885. /* Set "1" to report good data frames in groups of 100 */
  886. if (unlikely(iwl_get_debug_level(priv) & IWL_DL_RX))
  887. iwl_dbg_report_frame(priv, phy_res, len, header, 1);
  888. #endif
  889. iwl_dbg_log_rx_data_frame(priv, len, header);
  890. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, noise %d, qual %d, TSF %llu\n",
  891. rx_status.signal, rx_status.noise, rx_status.qual,
  892. (unsigned long long)rx_status.mactime);
  893. /*
  894. * "antenna number"
  895. *
  896. * It seems that the antenna field in the phy flags value
  897. * is actually a bit field. This is undefined by radiotap,
  898. * it wants an actual antenna number but I always get "7"
  899. * for most legacy frames I receive indicating that the
  900. * same frame was received on all three RX chains.
  901. *
  902. * I think this field should be removed in favor of a
  903. * new 802.11n radiotap field "RX chains" that is defined
  904. * as a bitmask.
  905. */
  906. rx_status.antenna =
  907. le16_to_cpu(phy_res->phy_flags & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  908. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  909. /* set the preamble flag if appropriate */
  910. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  911. rx_status.flag |= RX_FLAG_SHORTPRE;
  912. /* Set up the HT phy flags */
  913. if (rate_n_flags & RATE_MCS_HT_MSK)
  914. rx_status.flag |= RX_FLAG_HT;
  915. if (rate_n_flags & RATE_MCS_HT40_MSK)
  916. rx_status.flag |= RX_FLAG_40MHZ;
  917. if (rate_n_flags & RATE_MCS_SGI_MSK)
  918. rx_status.flag |= RX_FLAG_SHORT_GI;
  919. if (iwl_is_network_packet(priv, header)) {
  920. priv->last_rx_rssi = rx_status.signal;
  921. priv->last_beacon_time = priv->ucode_beacon_time;
  922. priv->last_tsf = le64_to_cpu(phy_res->timestamp);
  923. }
  924. fc = le16_to_cpu(header->frame_control);
  925. switch (fc & IEEE80211_FCTL_FTYPE) {
  926. case IEEE80211_FTYPE_MGMT:
  927. case IEEE80211_FTYPE_DATA:
  928. if (priv->iw_mode == NL80211_IFTYPE_AP)
  929. iwl_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
  930. header->addr2);
  931. /* fall through */
  932. default:
  933. iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  934. rxb, &rx_status);
  935. break;
  936. }
  937. }
  938. EXPORT_SYMBOL(iwl_rx_reply_rx);
  939. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  940. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  941. void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
  942. struct iwl_rx_mem_buffer *rxb)
  943. {
  944. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  945. priv->last_phy_res[0] = 1;
  946. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  947. sizeof(struct iwl_rx_phy_res));
  948. }
  949. EXPORT_SYMBOL(iwl_rx_reply_rx_phy);