iwl-rx.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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/slab.h>
  31. #include <linux/sched.h>
  32. #include <net/mac80211.h>
  33. #include <asm/unaligned.h>
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h"
  36. #include "iwl-core.h"
  37. #include "iwl-sta.h"
  38. #include "iwl-io.h"
  39. #include "iwl-helpers.h"
  40. #include "iwl-agn-calib.h"
  41. #include "iwl-agn.h"
  42. /******************************************************************************
  43. *
  44. * RX path functions
  45. *
  46. ******************************************************************************/
  47. /*
  48. * Rx theory of operation
  49. *
  50. * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
  51. * each of which point to Receive Buffers to be filled by the NIC. These get
  52. * used not only for Rx frames, but for any command response or notification
  53. * from the NIC. The driver and NIC manage the Rx buffers by means
  54. * of indexes into the circular buffer.
  55. *
  56. * Rx Queue Indexes
  57. * The host/firmware share two index registers for managing the Rx buffers.
  58. *
  59. * The READ index maps to the first position that the firmware may be writing
  60. * to -- the driver can read up to (but not including) this position and get
  61. * good data.
  62. * The READ index is managed by the firmware once the card is enabled.
  63. *
  64. * The WRITE index maps to the last position the driver has read from -- the
  65. * position preceding WRITE is the last slot the firmware can place a packet.
  66. *
  67. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  68. * WRITE = READ.
  69. *
  70. * During initialization, the host sets up the READ queue position to the first
  71. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  72. *
  73. * When the firmware places a packet in a buffer, it will advance the READ index
  74. * and fire the RX interrupt. The driver can then query the READ index and
  75. * process as many packets as possible, moving the WRITE index forward as it
  76. * resets the Rx queue buffers with new memory.
  77. *
  78. * The management in the driver is as follows:
  79. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  80. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  81. * to replenish the iwl->rxq->rx_free.
  82. * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
  83. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  84. * 'processed' and 'read' driver indexes as well)
  85. * + A received packet is processed and handed to the kernel network stack,
  86. * detached from the iwl->rxq. The driver 'processed' index is updated.
  87. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  88. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  89. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  90. * were enough free buffers and RX_STALLED is set it is cleared.
  91. *
  92. *
  93. * Driver sequence:
  94. *
  95. * iwl_rx_queue_alloc() Allocates rx_free
  96. * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
  97. * iwl_rx_queue_restock
  98. * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
  99. * queue, updates firmware pointers, and updates
  100. * the WRITE index. If insufficient rx_free buffers
  101. * are available, schedules iwl_rx_replenish
  102. *
  103. * -- enable interrupts --
  104. * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
  105. * READ INDEX, detaching the SKB from the pool.
  106. * Moves the packet buffer from queue to rx_used.
  107. * Calls iwl_rx_queue_restock to refill any empty
  108. * slots.
  109. * ...
  110. *
  111. */
  112. /**
  113. * iwl_rx_queue_space - Return number of free slots available in queue.
  114. */
  115. int iwl_rx_queue_space(const struct iwl_rx_queue *q)
  116. {
  117. int s = q->read - q->write;
  118. if (s <= 0)
  119. s += RX_QUEUE_SIZE;
  120. /* keep some buffer to not confuse full and empty queue */
  121. s -= 2;
  122. if (s < 0)
  123. s = 0;
  124. return s;
  125. }
  126. /**
  127. * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  128. */
  129. void iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
  130. {
  131. unsigned long flags;
  132. u32 rx_wrt_ptr_reg = priv->hw_params.rx_wrt_ptr_reg;
  133. u32 reg;
  134. spin_lock_irqsave(&q->lock, flags);
  135. if (q->need_update == 0)
  136. goto exit_unlock;
  137. if (priv->cfg->base_params->shadow_reg_enable) {
  138. /* shadow register enabled */
  139. /* Device expects a multiple of 8 */
  140. q->write_actual = (q->write & ~0x7);
  141. iwl_write32(priv, rx_wrt_ptr_reg, q->write_actual);
  142. } else {
  143. /* If power-saving is in use, make sure device is awake */
  144. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  145. reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
  146. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  147. IWL_DEBUG_INFO(priv,
  148. "Rx queue requesting wakeup,"
  149. " GP1 = 0x%x\n", reg);
  150. iwl_set_bit(priv, CSR_GP_CNTRL,
  151. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  152. goto exit_unlock;
  153. }
  154. q->write_actual = (q->write & ~0x7);
  155. iwl_write_direct32(priv, rx_wrt_ptr_reg,
  156. q->write_actual);
  157. /* Else device is assumed to be awake */
  158. } else {
  159. /* Device expects a multiple of 8 */
  160. q->write_actual = (q->write & ~0x7);
  161. iwl_write_direct32(priv, rx_wrt_ptr_reg,
  162. q->write_actual);
  163. }
  164. }
  165. q->need_update = 0;
  166. exit_unlock:
  167. spin_unlock_irqrestore(&q->lock, flags);
  168. }
  169. int iwl_rx_queue_alloc(struct iwl_priv *priv)
  170. {
  171. struct iwl_rx_queue *rxq = &priv->rxq;
  172. struct device *dev = &priv->pci_dev->dev;
  173. int i;
  174. spin_lock_init(&rxq->lock);
  175. INIT_LIST_HEAD(&rxq->rx_free);
  176. INIT_LIST_HEAD(&rxq->rx_used);
  177. /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
  178. rxq->bd = dma_alloc_coherent(dev, 4 * RX_QUEUE_SIZE, &rxq->bd_dma,
  179. GFP_KERNEL);
  180. if (!rxq->bd)
  181. goto err_bd;
  182. rxq->rb_stts = dma_alloc_coherent(dev, sizeof(struct iwl_rb_status),
  183. &rxq->rb_stts_dma, GFP_KERNEL);
  184. if (!rxq->rb_stts)
  185. goto err_rb;
  186. /* Fill the rx_used queue with _all_ of the Rx buffers */
  187. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  188. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  189. /* Set us so that we have processed and used all buffers, but have
  190. * not restocked the Rx queue with fresh buffers */
  191. rxq->read = rxq->write = 0;
  192. rxq->write_actual = 0;
  193. rxq->free_count = 0;
  194. rxq->need_update = 0;
  195. return 0;
  196. err_rb:
  197. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  198. rxq->bd_dma);
  199. err_bd:
  200. return -ENOMEM;
  201. }
  202. /******************************************************************************
  203. *
  204. * Generic RX handler implementations
  205. *
  206. ******************************************************************************/
  207. static void iwl_rx_reply_error(struct iwl_priv *priv,
  208. struct iwl_rx_mem_buffer *rxb)
  209. {
  210. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  211. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  212. "seq 0x%04X ser 0x%08X\n",
  213. le32_to_cpu(pkt->u.err_resp.error_type),
  214. get_cmd_string(pkt->u.err_resp.cmd_id),
  215. pkt->u.err_resp.cmd_id,
  216. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  217. le32_to_cpu(pkt->u.err_resp.error_info));
  218. }
  219. static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  220. {
  221. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  222. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  223. /*
  224. * MULTI-FIXME
  225. * See iwl_mac_channel_switch.
  226. */
  227. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  228. struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
  229. if (priv->switch_rxon.switch_in_progress) {
  230. if (!le32_to_cpu(csa->status) &&
  231. (csa->channel == priv->switch_rxon.channel)) {
  232. rxon->channel = csa->channel;
  233. ctx->staging.channel = csa->channel;
  234. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  235. le16_to_cpu(csa->channel));
  236. iwl_chswitch_done(priv, true);
  237. } else {
  238. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  239. le16_to_cpu(csa->channel));
  240. iwl_chswitch_done(priv, false);
  241. }
  242. }
  243. }
  244. static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
  245. struct iwl_rx_mem_buffer *rxb)
  246. {
  247. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  248. struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
  249. if (!report->state) {
  250. IWL_DEBUG_11H(priv,
  251. "Spectrum Measure Notification: Start\n");
  252. return;
  253. }
  254. memcpy(&priv->measure_report, report, sizeof(*report));
  255. priv->measurement_status |= MEASUREMENT_READY;
  256. }
  257. static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  258. struct iwl_rx_mem_buffer *rxb)
  259. {
  260. #ifdef CONFIG_IWLWIFI_DEBUG
  261. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  262. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  263. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  264. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  265. #endif
  266. }
  267. static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  268. struct iwl_rx_mem_buffer *rxb)
  269. {
  270. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  271. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  272. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  273. "notification for %s:\n", len,
  274. get_cmd_string(pkt->hdr.cmd));
  275. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  276. }
  277. static void iwl_rx_beacon_notif(struct iwl_priv *priv,
  278. struct iwl_rx_mem_buffer *rxb)
  279. {
  280. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  281. struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw;
  282. #ifdef CONFIG_IWLWIFI_DEBUG
  283. u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
  284. u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  285. IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
  286. "tsf:0x%.8x%.8x rate:%d\n",
  287. status & TX_STATUS_MSK,
  288. beacon->beacon_notify_hdr.failure_frame,
  289. le32_to_cpu(beacon->ibss_mgr_status),
  290. le32_to_cpu(beacon->high_tsf),
  291. le32_to_cpu(beacon->low_tsf), rate);
  292. #endif
  293. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  294. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  295. queue_work(priv->workqueue, &priv->beacon_update);
  296. }
  297. /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
  298. #define ACK_CNT_RATIO (50)
  299. #define BA_TIMEOUT_CNT (5)
  300. #define BA_TIMEOUT_MAX (16)
  301. /**
  302. * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
  303. *
  304. * When the ACK count ratio is low and aggregated BA timeout retries exceeding
  305. * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
  306. * operation state.
  307. */
  308. static bool iwl_good_ack_health(struct iwl_priv *priv,
  309. struct statistics_tx *cur)
  310. {
  311. int actual_delta, expected_delta, ba_timeout_delta;
  312. struct statistics_tx *old;
  313. if (priv->_agn.agg_tids_count)
  314. return true;
  315. old = &priv->statistics.tx;
  316. actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
  317. le32_to_cpu(old->actual_ack_cnt);
  318. expected_delta = le32_to_cpu(cur->expected_ack_cnt) -
  319. le32_to_cpu(old->expected_ack_cnt);
  320. /* Values should not be negative, but we do not trust the firmware */
  321. if (actual_delta <= 0 || expected_delta <= 0)
  322. return true;
  323. ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) -
  324. le32_to_cpu(old->agg.ba_timeout);
  325. if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO &&
  326. ba_timeout_delta > BA_TIMEOUT_CNT) {
  327. IWL_DEBUG_RADIO(priv, "deltas: actual %d expected %d ba_timeout %d\n",
  328. actual_delta, expected_delta, ba_timeout_delta);
  329. #ifdef CONFIG_IWLWIFI_DEBUGFS
  330. /*
  331. * This is ifdef'ed on DEBUGFS because otherwise the
  332. * statistics aren't available. If DEBUGFS is set but
  333. * DEBUG is not, these will just compile out.
  334. */
  335. IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n",
  336. priv->delta_stats.tx.rx_detected_cnt);
  337. IWL_DEBUG_RADIO(priv,
  338. "ack_or_ba_timeout_collision delta %d\n",
  339. priv->delta_stats.tx.ack_or_ba_timeout_collision);
  340. #endif
  341. if (ba_timeout_delta >= BA_TIMEOUT_MAX)
  342. return false;
  343. }
  344. return true;
  345. }
  346. /**
  347. * iwl_good_plcp_health - checks for plcp error.
  348. *
  349. * When the plcp error is exceeding the thresholds, reset the radio
  350. * to improve the throughput.
  351. */
  352. static bool iwl_good_plcp_health(struct iwl_priv *priv,
  353. struct statistics_rx_phy *cur_ofdm,
  354. struct statistics_rx_ht_phy *cur_ofdm_ht,
  355. unsigned int msecs)
  356. {
  357. int delta;
  358. int threshold = priv->cfg->base_params->plcp_delta_threshold;
  359. if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
  360. IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
  361. return true;
  362. }
  363. delta = le32_to_cpu(cur_ofdm->plcp_err) -
  364. le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
  365. le32_to_cpu(cur_ofdm_ht->plcp_err) -
  366. le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
  367. /* Can be negative if firmware reset statistics */
  368. if (delta <= 0)
  369. return true;
  370. if ((delta * 100 / msecs) > threshold) {
  371. IWL_DEBUG_RADIO(priv,
  372. "plcp health threshold %u delta %d msecs %u\n",
  373. threshold, delta, msecs);
  374. return false;
  375. }
  376. return true;
  377. }
  378. static void iwl_recover_from_statistics(struct iwl_priv *priv,
  379. struct statistics_rx_phy *cur_ofdm,
  380. struct statistics_rx_ht_phy *cur_ofdm_ht,
  381. struct statistics_tx *tx,
  382. unsigned long stamp)
  383. {
  384. const struct iwl_mod_params *mod_params = priv->cfg->mod_params;
  385. unsigned int msecs;
  386. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  387. return;
  388. msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
  389. /* Only gather statistics and update time stamp when not associated */
  390. if (!iwl_is_any_associated(priv))
  391. return;
  392. /* Do not check/recover when do not have enough statistics data */
  393. if (msecs < 99)
  394. return;
  395. if (mod_params->ack_check && !iwl_good_ack_health(priv, tx)) {
  396. IWL_ERR(priv, "low ack count detected, restart firmware\n");
  397. if (!iwl_force_reset(priv, IWL_FW_RESET, false))
  398. return;
  399. }
  400. if (mod_params->plcp_check &&
  401. !iwl_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
  402. iwl_force_reset(priv, IWL_RF_RESET, false);
  403. }
  404. /* Calculate noise level, based on measurements during network silence just
  405. * before arriving beacon. This measurement can be done only if we know
  406. * exactly when to expect beacons, therefore only when we're associated. */
  407. static void iwl_rx_calc_noise(struct iwl_priv *priv)
  408. {
  409. struct statistics_rx_non_phy *rx_info;
  410. int num_active_rx = 0;
  411. int total_silence = 0;
  412. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  413. int last_rx_noise;
  414. rx_info = &priv->statistics.rx_non_phy;
  415. bcn_silence_a =
  416. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  417. bcn_silence_b =
  418. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  419. bcn_silence_c =
  420. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  421. if (bcn_silence_a) {
  422. total_silence += bcn_silence_a;
  423. num_active_rx++;
  424. }
  425. if (bcn_silence_b) {
  426. total_silence += bcn_silence_b;
  427. num_active_rx++;
  428. }
  429. if (bcn_silence_c) {
  430. total_silence += bcn_silence_c;
  431. num_active_rx++;
  432. }
  433. /* Average among active antennas */
  434. if (num_active_rx)
  435. last_rx_noise = (total_silence / num_active_rx) - 107;
  436. else
  437. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  438. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  439. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  440. last_rx_noise);
  441. }
  442. #ifdef CONFIG_IWLWIFI_DEBUGFS
  443. /*
  444. * based on the assumption of all statistics counter are in DWORD
  445. * FIXME: This function is for debugging, do not deal with
  446. * the case of counters roll-over.
  447. */
  448. static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
  449. __le32 *max_delta, __le32 *accum, int size)
  450. {
  451. int i;
  452. for (i = 0;
  453. i < size / sizeof(__le32);
  454. i++, prev++, cur++, delta++, max_delta++, accum++) {
  455. if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
  456. *delta = cpu_to_le32(
  457. le32_to_cpu(*cur) - le32_to_cpu(*prev));
  458. le32_add_cpu(accum, le32_to_cpu(*delta));
  459. if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
  460. *max_delta = *delta;
  461. }
  462. }
  463. }
  464. static void
  465. iwl_accumulative_statistics(struct iwl_priv *priv,
  466. struct statistics_general_common *common,
  467. struct statistics_rx_non_phy *rx_non_phy,
  468. struct statistics_rx_phy *rx_ofdm,
  469. struct statistics_rx_ht_phy *rx_ofdm_ht,
  470. struct statistics_rx_phy *rx_cck,
  471. struct statistics_tx *tx,
  472. struct statistics_bt_activity *bt_activity)
  473. {
  474. #define ACCUM(_name) \
  475. accum_stats((__le32 *)&priv->statistics._name, \
  476. (__le32 *)_name, \
  477. (__le32 *)&priv->delta_stats._name, \
  478. (__le32 *)&priv->max_delta_stats._name, \
  479. (__le32 *)&priv->accum_stats._name, \
  480. sizeof(*_name));
  481. ACCUM(common);
  482. ACCUM(rx_non_phy);
  483. ACCUM(rx_ofdm);
  484. ACCUM(rx_ofdm_ht);
  485. ACCUM(rx_cck);
  486. ACCUM(tx);
  487. if (bt_activity)
  488. ACCUM(bt_activity);
  489. #undef ACCUM
  490. }
  491. #else
  492. static inline void
  493. iwl_accumulative_statistics(struct iwl_priv *priv,
  494. struct statistics_general_common *common,
  495. struct statistics_rx_non_phy *rx_non_phy,
  496. struct statistics_rx_phy *rx_ofdm,
  497. struct statistics_rx_ht_phy *rx_ofdm_ht,
  498. struct statistics_rx_phy *rx_cck,
  499. struct statistics_tx *tx,
  500. struct statistics_bt_activity *bt_activity)
  501. {
  502. }
  503. #endif
  504. static void iwl_rx_statistics(struct iwl_priv *priv,
  505. struct iwl_rx_mem_buffer *rxb)
  506. {
  507. unsigned long stamp = jiffies;
  508. const int reg_recalib_period = 60;
  509. int change;
  510. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  511. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  512. __le32 *flag;
  513. struct statistics_general_common *common;
  514. struct statistics_rx_non_phy *rx_non_phy;
  515. struct statistics_rx_phy *rx_ofdm;
  516. struct statistics_rx_ht_phy *rx_ofdm_ht;
  517. struct statistics_rx_phy *rx_cck;
  518. struct statistics_tx *tx;
  519. struct statistics_bt_activity *bt_activity;
  520. len -= sizeof(struct iwl_cmd_header); /* skip header */
  521. IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
  522. len);
  523. if (len == sizeof(struct iwl_bt_notif_statistics)) {
  524. struct iwl_bt_notif_statistics *stats;
  525. stats = &pkt->u.stats_bt;
  526. flag = &stats->flag;
  527. common = &stats->general.common;
  528. rx_non_phy = &stats->rx.general.common;
  529. rx_ofdm = &stats->rx.ofdm;
  530. rx_ofdm_ht = &stats->rx.ofdm_ht;
  531. rx_cck = &stats->rx.cck;
  532. tx = &stats->tx;
  533. bt_activity = &stats->general.activity;
  534. #ifdef CONFIG_IWLWIFI_DEBUGFS
  535. /* handle this exception directly */
  536. priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
  537. le32_add_cpu(&priv->statistics.accum_num_bt_kills,
  538. le32_to_cpu(stats->rx.general.num_bt_kills));
  539. #endif
  540. } else if (len == sizeof(struct iwl_notif_statistics)) {
  541. struct iwl_notif_statistics *stats;
  542. stats = &pkt->u.stats;
  543. flag = &stats->flag;
  544. common = &stats->general.common;
  545. rx_non_phy = &stats->rx.general;
  546. rx_ofdm = &stats->rx.ofdm;
  547. rx_ofdm_ht = &stats->rx.ofdm_ht;
  548. rx_cck = &stats->rx.cck;
  549. tx = &stats->tx;
  550. bt_activity = NULL;
  551. } else {
  552. WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
  553. len, sizeof(struct iwl_bt_notif_statistics),
  554. sizeof(struct iwl_notif_statistics));
  555. return;
  556. }
  557. change = common->temperature != priv->statistics.common.temperature ||
  558. (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  559. (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
  560. iwl_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
  561. rx_ofdm_ht, rx_cck, tx, bt_activity);
  562. iwl_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
  563. priv->statistics.flag = *flag;
  564. memcpy(&priv->statistics.common, common, sizeof(*common));
  565. memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
  566. memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
  567. memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
  568. memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
  569. memcpy(&priv->statistics.tx, tx, sizeof(*tx));
  570. #ifdef CONFIG_IWLWIFI_DEBUGFS
  571. if (bt_activity)
  572. memcpy(&priv->statistics.bt_activity, bt_activity,
  573. sizeof(*bt_activity));
  574. #endif
  575. priv->rx_statistics_jiffies = stamp;
  576. set_bit(STATUS_STATISTICS, &priv->status);
  577. /* Reschedule the statistics timer to occur in
  578. * reg_recalib_period seconds to ensure we get a
  579. * thermal update even if the uCode doesn't give
  580. * us one */
  581. mod_timer(&priv->statistics_periodic, jiffies +
  582. msecs_to_jiffies(reg_recalib_period * 1000));
  583. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  584. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  585. iwl_rx_calc_noise(priv);
  586. queue_work(priv->workqueue, &priv->run_time_calib_work);
  587. }
  588. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  589. priv->cfg->ops->lib->temp_ops.temperature(priv);
  590. }
  591. static void iwl_rx_reply_statistics(struct iwl_priv *priv,
  592. struct iwl_rx_mem_buffer *rxb)
  593. {
  594. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  595. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  596. #ifdef CONFIG_IWLWIFI_DEBUGFS
  597. memset(&priv->accum_stats, 0,
  598. sizeof(priv->accum_stats));
  599. memset(&priv->delta_stats, 0,
  600. sizeof(priv->delta_stats));
  601. memset(&priv->max_delta_stats, 0,
  602. sizeof(priv->max_delta_stats));
  603. #endif
  604. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  605. }
  606. iwl_rx_statistics(priv, rxb);
  607. }
  608. /* Handle notification from uCode that card's power state is changing
  609. * due to software, hardware, or critical temperature RFKILL */
  610. static void iwl_rx_card_state_notif(struct iwl_priv *priv,
  611. struct iwl_rx_mem_buffer *rxb)
  612. {
  613. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  614. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  615. unsigned long status = priv->status;
  616. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
  617. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  618. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  619. (flags & CT_CARD_DISABLED) ?
  620. "Reached" : "Not reached");
  621. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  622. CT_CARD_DISABLED)) {
  623. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  624. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  625. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  626. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  627. if (!(flags & RXON_CARD_DISABLED)) {
  628. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  629. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  630. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  631. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  632. }
  633. if (flags & CT_CARD_DISABLED)
  634. iwl_tt_enter_ct_kill(priv);
  635. }
  636. if (!(flags & CT_CARD_DISABLED))
  637. iwl_tt_exit_ct_kill(priv);
  638. if (flags & HW_CARD_DISABLED)
  639. set_bit(STATUS_RF_KILL_HW, &priv->status);
  640. else
  641. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  642. if (!(flags & RXON_CARD_DISABLED))
  643. iwl_scan_cancel(priv);
  644. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  645. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  646. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  647. test_bit(STATUS_RF_KILL_HW, &priv->status));
  648. else
  649. wake_up_interruptible(&priv->wait_command_queue);
  650. }
  651. static void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
  652. struct iwl_rx_mem_buffer *rxb)
  653. {
  654. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  655. struct iwl_missed_beacon_notif *missed_beacon;
  656. missed_beacon = &pkt->u.missed_beacon;
  657. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  658. priv->missed_beacon_threshold) {
  659. IWL_DEBUG_CALIB(priv,
  660. "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  661. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  662. le32_to_cpu(missed_beacon->total_missed_becons),
  663. le32_to_cpu(missed_beacon->num_recvd_beacons),
  664. le32_to_cpu(missed_beacon->num_expected_beacons));
  665. if (!test_bit(STATUS_SCANNING, &priv->status))
  666. iwl_init_sensitivity(priv);
  667. }
  668. }
  669. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  670. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  671. static void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
  672. struct iwl_rx_mem_buffer *rxb)
  673. {
  674. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  675. priv->_agn.last_phy_res_valid = true;
  676. memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
  677. sizeof(struct iwl_rx_phy_res));
  678. }
  679. /*
  680. * returns non-zero if packet should be dropped
  681. */
  682. static int iwl_set_decrypted_flag(struct iwl_priv *priv,
  683. struct ieee80211_hdr *hdr,
  684. u32 decrypt_res,
  685. struct ieee80211_rx_status *stats)
  686. {
  687. u16 fc = le16_to_cpu(hdr->frame_control);
  688. /*
  689. * All contexts have the same setting here due to it being
  690. * a module parameter, so OK to check any context.
  691. */
  692. if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
  693. RXON_FILTER_DIS_DECRYPT_MSK)
  694. return 0;
  695. if (!(fc & IEEE80211_FCTL_PROTECTED))
  696. return 0;
  697. IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
  698. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  699. case RX_RES_STATUS_SEC_TYPE_TKIP:
  700. /* The uCode has got a bad phase 1 Key, pushes the packet.
  701. * Decryption will be done in SW. */
  702. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  703. RX_RES_STATUS_BAD_KEY_TTAK)
  704. break;
  705. case RX_RES_STATUS_SEC_TYPE_WEP:
  706. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  707. RX_RES_STATUS_BAD_ICV_MIC) {
  708. /* bad ICV, the packet is destroyed since the
  709. * decryption is inplace, drop it */
  710. IWL_DEBUG_RX(priv, "Packet destroyed\n");
  711. return -1;
  712. }
  713. case RX_RES_STATUS_SEC_TYPE_CCMP:
  714. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  715. RX_RES_STATUS_DECRYPT_OK) {
  716. IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
  717. stats->flag |= RX_FLAG_DECRYPTED;
  718. }
  719. break;
  720. default:
  721. break;
  722. }
  723. return 0;
  724. }
  725. static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
  726. struct ieee80211_hdr *hdr,
  727. u16 len,
  728. u32 ampdu_status,
  729. struct iwl_rx_mem_buffer *rxb,
  730. struct ieee80211_rx_status *stats)
  731. {
  732. struct sk_buff *skb;
  733. __le16 fc = hdr->frame_control;
  734. struct iwl_rxon_context *ctx;
  735. /* We only process data packets if the interface is open */
  736. if (unlikely(!priv->is_open)) {
  737. IWL_DEBUG_DROP_LIMIT(priv,
  738. "Dropping packet while interface is not open.\n");
  739. return;
  740. }
  741. /* In case of HW accelerated crypto and bad decryption, drop */
  742. if (!priv->cfg->mod_params->sw_crypto &&
  743. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  744. return;
  745. skb = dev_alloc_skb(128);
  746. if (!skb) {
  747. IWL_ERR(priv, "dev_alloc_skb failed\n");
  748. return;
  749. }
  750. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  751. iwl_update_stats(priv, false, fc, len);
  752. /*
  753. * Wake any queues that were stopped due to a passive channel tx
  754. * failure. This can happen because the regulatory enforcement in
  755. * the device waits for a beacon before allowing transmission,
  756. * sometimes even after already having transmitted frames for the
  757. * association because the new RXON may reset the information.
  758. */
  759. if (unlikely(ieee80211_is_beacon(fc))) {
  760. for_each_context(priv, ctx) {
  761. if (!ctx->last_tx_rejected)
  762. continue;
  763. if (compare_ether_addr(hdr->addr3,
  764. ctx->active.bssid_addr))
  765. continue;
  766. ctx->last_tx_rejected = false;
  767. iwl_wake_any_queue(priv, ctx);
  768. }
  769. }
  770. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  771. ieee80211_rx(priv->hw, skb);
  772. rxb->page = NULL;
  773. }
  774. static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  775. {
  776. u32 decrypt_out = 0;
  777. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  778. RX_RES_STATUS_STATION_FOUND)
  779. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  780. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  781. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  782. /* packet was not encrypted */
  783. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  784. RX_RES_STATUS_SEC_TYPE_NONE)
  785. return decrypt_out;
  786. /* packet was encrypted with unknown alg */
  787. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  788. RX_RES_STATUS_SEC_TYPE_ERR)
  789. return decrypt_out;
  790. /* decryption was not done in HW */
  791. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  792. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  793. return decrypt_out;
  794. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  795. case RX_RES_STATUS_SEC_TYPE_CCMP:
  796. /* alg is CCM: check MIC only */
  797. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  798. /* Bad MIC */
  799. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  800. else
  801. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  802. break;
  803. case RX_RES_STATUS_SEC_TYPE_TKIP:
  804. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  805. /* Bad TTAK */
  806. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  807. break;
  808. }
  809. /* fall through if TTAK OK */
  810. default:
  811. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  812. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  813. else
  814. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  815. break;
  816. }
  817. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  818. decrypt_in, decrypt_out);
  819. return decrypt_out;
  820. }
  821. /* Called for REPLY_RX (legacy ABG frames), or
  822. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  823. static void iwl_rx_reply_rx(struct iwl_priv *priv,
  824. struct iwl_rx_mem_buffer *rxb)
  825. {
  826. struct ieee80211_hdr *header;
  827. struct ieee80211_rx_status rx_status;
  828. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  829. struct iwl_rx_phy_res *phy_res;
  830. __le32 rx_pkt_status;
  831. struct iwl_rx_mpdu_res_start *amsdu;
  832. u32 len;
  833. u32 ampdu_status;
  834. u32 rate_n_flags;
  835. /**
  836. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  837. * REPLY_RX: physical layer info is in this buffer
  838. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  839. * command and cached in priv->last_phy_res
  840. *
  841. * Here we set up local variables depending on which command is
  842. * received.
  843. */
  844. if (pkt->hdr.cmd == REPLY_RX) {
  845. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  846. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  847. + phy_res->cfg_phy_cnt);
  848. len = le16_to_cpu(phy_res->byte_count);
  849. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  850. phy_res->cfg_phy_cnt + len);
  851. ampdu_status = le32_to_cpu(rx_pkt_status);
  852. } else {
  853. if (!priv->_agn.last_phy_res_valid) {
  854. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  855. return;
  856. }
  857. phy_res = &priv->_agn.last_phy_res;
  858. amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
  859. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  860. len = le16_to_cpu(amsdu->byte_count);
  861. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  862. ampdu_status = iwl_translate_rx_status(priv,
  863. le32_to_cpu(rx_pkt_status));
  864. }
  865. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  866. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  867. phy_res->cfg_phy_cnt);
  868. return;
  869. }
  870. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  871. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  872. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  873. le32_to_cpu(rx_pkt_status));
  874. return;
  875. }
  876. /* This will be used in several places later */
  877. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  878. /* rx_status carries information about the packet to mac80211 */
  879. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  880. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  881. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  882. rx_status.freq =
  883. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  884. rx_status.band);
  885. rx_status.rate_idx =
  886. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  887. rx_status.flag = 0;
  888. /* TSF isn't reliable. In order to allow smooth user experience,
  889. * this W/A doesn't propagate it to the mac80211 */
  890. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
  891. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  892. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  893. rx_status.signal = priv->cfg->ops->utils->calc_rssi(priv, phy_res);
  894. iwl_dbg_log_rx_data_frame(priv, len, header);
  895. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  896. rx_status.signal, (unsigned long long)rx_status.mactime);
  897. /*
  898. * "antenna number"
  899. *
  900. * It seems that the antenna field in the phy flags value
  901. * is actually a bit field. This is undefined by radiotap,
  902. * it wants an actual antenna number but I always get "7"
  903. * for most legacy frames I receive indicating that the
  904. * same frame was received on all three RX chains.
  905. *
  906. * I think this field should be removed in favor of a
  907. * new 802.11n radiotap field "RX chains" that is defined
  908. * as a bitmask.
  909. */
  910. rx_status.antenna =
  911. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  912. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  913. /* set the preamble flag if appropriate */
  914. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  915. rx_status.flag |= RX_FLAG_SHORTPRE;
  916. /* Set up the HT phy flags */
  917. if (rate_n_flags & RATE_MCS_HT_MSK)
  918. rx_status.flag |= RX_FLAG_HT;
  919. if (rate_n_flags & RATE_MCS_HT40_MSK)
  920. rx_status.flag |= RX_FLAG_40MHZ;
  921. if (rate_n_flags & RATE_MCS_SGI_MSK)
  922. rx_status.flag |= RX_FLAG_SHORT_GI;
  923. iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  924. rxb, &rx_status);
  925. }
  926. /**
  927. * iwl_setup_rx_handlers - Initialize Rx handler callbacks
  928. *
  929. * Setup the RX handlers for each of the reply types sent from the uCode
  930. * to the host.
  931. */
  932. void iwl_setup_rx_handlers(struct iwl_priv *priv)
  933. {
  934. void (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
  935. handlers = priv->rx_handlers;
  936. handlers[REPLY_ERROR] = iwl_rx_reply_error;
  937. handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  938. handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif;
  939. handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  940. handlers[PM_DEBUG_STATISTIC_NOTIFIC] = iwl_rx_pm_debug_statistics_notif;
  941. handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
  942. /*
  943. * The same handler is used for both the REPLY to a discrete
  944. * statistics request from the host as well as for the periodic
  945. * statistics notifications (after received beacons) from the uCode.
  946. */
  947. handlers[REPLY_STATISTICS_CMD] = iwl_rx_reply_statistics;
  948. handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
  949. iwl_setup_rx_scan_handlers(priv);
  950. handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
  951. handlers[MISSED_BEACONS_NOTIFICATION] = iwl_rx_missed_beacon_notif;
  952. /* Rx handlers */
  953. handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
  954. handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
  955. /* block ack */
  956. handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
  957. /* Set up hardware specific Rx handlers */
  958. priv->cfg->ops->lib->rx_handler_setup(priv);
  959. }