iwl-rx.c 34 KB

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