iwl-rx.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. #include "iwl-shared.h"
  43. const char *get_cmd_string(u8 cmd)
  44. {
  45. switch (cmd) {
  46. IWL_CMD(REPLY_ALIVE);
  47. IWL_CMD(REPLY_ERROR);
  48. IWL_CMD(REPLY_ECHO);
  49. IWL_CMD(REPLY_RXON);
  50. IWL_CMD(REPLY_RXON_ASSOC);
  51. IWL_CMD(REPLY_QOS_PARAM);
  52. IWL_CMD(REPLY_RXON_TIMING);
  53. IWL_CMD(REPLY_ADD_STA);
  54. IWL_CMD(REPLY_REMOVE_STA);
  55. IWL_CMD(REPLY_REMOVE_ALL_STA);
  56. IWL_CMD(REPLY_TXFIFO_FLUSH);
  57. IWL_CMD(REPLY_WEPKEY);
  58. IWL_CMD(REPLY_TX);
  59. IWL_CMD(REPLY_LEDS_CMD);
  60. IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
  61. IWL_CMD(COEX_PRIORITY_TABLE_CMD);
  62. IWL_CMD(COEX_MEDIUM_NOTIFICATION);
  63. IWL_CMD(COEX_EVENT_CMD);
  64. IWL_CMD(REPLY_QUIET_CMD);
  65. IWL_CMD(REPLY_CHANNEL_SWITCH);
  66. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  67. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  68. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  69. IWL_CMD(POWER_TABLE_CMD);
  70. IWL_CMD(PM_SLEEP_NOTIFICATION);
  71. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  72. IWL_CMD(REPLY_SCAN_CMD);
  73. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  74. IWL_CMD(SCAN_START_NOTIFICATION);
  75. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  76. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  77. IWL_CMD(BEACON_NOTIFICATION);
  78. IWL_CMD(REPLY_TX_BEACON);
  79. IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
  80. IWL_CMD(QUIET_NOTIFICATION);
  81. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  82. IWL_CMD(MEASURE_ABORT_NOTIFICATION);
  83. IWL_CMD(REPLY_BT_CONFIG);
  84. IWL_CMD(REPLY_STATISTICS_CMD);
  85. IWL_CMD(STATISTICS_NOTIFICATION);
  86. IWL_CMD(REPLY_CARD_STATE_CMD);
  87. IWL_CMD(CARD_STATE_NOTIFICATION);
  88. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  89. IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
  90. IWL_CMD(SENSITIVITY_CMD);
  91. IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
  92. IWL_CMD(REPLY_RX_PHY_CMD);
  93. IWL_CMD(REPLY_RX_MPDU_CMD);
  94. IWL_CMD(REPLY_RX);
  95. IWL_CMD(REPLY_COMPRESSED_BA);
  96. IWL_CMD(CALIBRATION_CFG_CMD);
  97. IWL_CMD(CALIBRATION_RES_NOTIFICATION);
  98. IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION);
  99. IWL_CMD(REPLY_TX_POWER_DBM_CMD);
  100. IWL_CMD(TEMPERATURE_NOTIFICATION);
  101. IWL_CMD(TX_ANT_CONFIGURATION_CMD);
  102. IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF);
  103. IWL_CMD(REPLY_BT_COEX_PRIO_TABLE);
  104. IWL_CMD(REPLY_BT_COEX_PROT_ENV);
  105. IWL_CMD(REPLY_WIPAN_PARAMS);
  106. IWL_CMD(REPLY_WIPAN_RXON);
  107. IWL_CMD(REPLY_WIPAN_RXON_TIMING);
  108. IWL_CMD(REPLY_WIPAN_RXON_ASSOC);
  109. IWL_CMD(REPLY_WIPAN_QOS_PARAM);
  110. IWL_CMD(REPLY_WIPAN_WEPKEY);
  111. IWL_CMD(REPLY_WIPAN_P2P_CHANNEL_SWITCH);
  112. IWL_CMD(REPLY_WIPAN_NOA_NOTIFICATION);
  113. IWL_CMD(REPLY_WIPAN_DEACTIVATION_COMPLETE);
  114. IWL_CMD(REPLY_WOWLAN_PATTERNS);
  115. IWL_CMD(REPLY_WOWLAN_WAKEUP_FILTER);
  116. IWL_CMD(REPLY_WOWLAN_TSC_RSC_PARAMS);
  117. IWL_CMD(REPLY_WOWLAN_TKIP_PARAMS);
  118. IWL_CMD(REPLY_WOWLAN_KEK_KCK_MATERIAL);
  119. IWL_CMD(REPLY_WOWLAN_GET_STATUS);
  120. default:
  121. return "UNKNOWN";
  122. }
  123. }
  124. /******************************************************************************
  125. *
  126. * Generic RX handler implementations
  127. *
  128. ******************************************************************************/
  129. static int iwl_rx_reply_error(struct iwl_priv *priv,
  130. struct iwl_rx_mem_buffer *rxb,
  131. struct iwl_device_cmd *cmd)
  132. {
  133. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  134. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  135. "seq 0x%04X ser 0x%08X\n",
  136. le32_to_cpu(pkt->u.err_resp.error_type),
  137. get_cmd_string(pkt->u.err_resp.cmd_id),
  138. pkt->u.err_resp.cmd_id,
  139. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  140. le32_to_cpu(pkt->u.err_resp.error_info));
  141. return 0;
  142. }
  143. static int iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
  144. struct iwl_device_cmd *cmd)
  145. {
  146. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  147. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  148. /*
  149. * MULTI-FIXME
  150. * See iwlagn_mac_channel_switch.
  151. */
  152. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  153. struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
  154. if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
  155. return 0;
  156. if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
  157. rxon->channel = csa->channel;
  158. ctx->staging.channel = csa->channel;
  159. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  160. le16_to_cpu(csa->channel));
  161. iwl_chswitch_done(priv, true);
  162. } else {
  163. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  164. le16_to_cpu(csa->channel));
  165. iwl_chswitch_done(priv, false);
  166. }
  167. return 0;
  168. }
  169. static int iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
  170. struct iwl_rx_mem_buffer *rxb,
  171. struct iwl_device_cmd *cmd)
  172. {
  173. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  174. struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
  175. if (!report->state) {
  176. IWL_DEBUG_11H(priv,
  177. "Spectrum Measure Notification: Start\n");
  178. return 0;
  179. }
  180. memcpy(&priv->measure_report, report, sizeof(*report));
  181. priv->measurement_status |= MEASUREMENT_READY;
  182. return 0;
  183. }
  184. static int iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  185. struct iwl_rx_mem_buffer *rxb,
  186. struct iwl_device_cmd *cmd)
  187. {
  188. #ifdef CONFIG_IWLWIFI_DEBUG
  189. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  190. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  191. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  192. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  193. #endif
  194. return 0;
  195. }
  196. static int iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  197. struct iwl_rx_mem_buffer *rxb,
  198. struct iwl_device_cmd *cmd)
  199. {
  200. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  201. u32 __maybe_unused len =
  202. le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  203. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  204. "notification for %s:\n", len,
  205. get_cmd_string(pkt->hdr.cmd));
  206. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  207. return 0;
  208. }
  209. static int iwl_rx_beacon_notif(struct iwl_priv *priv,
  210. struct iwl_rx_mem_buffer *rxb,
  211. struct iwl_device_cmd *cmd)
  212. {
  213. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  214. struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw;
  215. #ifdef CONFIG_IWLWIFI_DEBUG
  216. u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
  217. u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  218. IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
  219. "tsf:0x%.8x%.8x rate:%d\n",
  220. status & TX_STATUS_MSK,
  221. beacon->beacon_notify_hdr.failure_frame,
  222. le32_to_cpu(beacon->ibss_mgr_status),
  223. le32_to_cpu(beacon->high_tsf),
  224. le32_to_cpu(beacon->low_tsf), rate);
  225. #endif
  226. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  227. return 0;
  228. }
  229. /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
  230. #define ACK_CNT_RATIO (50)
  231. #define BA_TIMEOUT_CNT (5)
  232. #define BA_TIMEOUT_MAX (16)
  233. /**
  234. * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
  235. *
  236. * When the ACK count ratio is low and aggregated BA timeout retries exceeding
  237. * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
  238. * operation state.
  239. */
  240. static bool iwl_good_ack_health(struct iwl_priv *priv,
  241. struct statistics_tx *cur)
  242. {
  243. int actual_delta, expected_delta, ba_timeout_delta;
  244. struct statistics_tx *old;
  245. if (priv->agg_tids_count)
  246. return true;
  247. old = &priv->statistics.tx;
  248. actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
  249. le32_to_cpu(old->actual_ack_cnt);
  250. expected_delta = le32_to_cpu(cur->expected_ack_cnt) -
  251. le32_to_cpu(old->expected_ack_cnt);
  252. /* Values should not be negative, but we do not trust the firmware */
  253. if (actual_delta <= 0 || expected_delta <= 0)
  254. return true;
  255. ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) -
  256. le32_to_cpu(old->agg.ba_timeout);
  257. if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO &&
  258. ba_timeout_delta > BA_TIMEOUT_CNT) {
  259. IWL_DEBUG_RADIO(priv, "deltas: actual %d expected %d ba_timeout %d\n",
  260. actual_delta, expected_delta, ba_timeout_delta);
  261. #ifdef CONFIG_IWLWIFI_DEBUGFS
  262. /*
  263. * This is ifdef'ed on DEBUGFS because otherwise the
  264. * statistics aren't available. If DEBUGFS is set but
  265. * DEBUG is not, these will just compile out.
  266. */
  267. IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n",
  268. priv->delta_stats.tx.rx_detected_cnt);
  269. IWL_DEBUG_RADIO(priv,
  270. "ack_or_ba_timeout_collision delta %d\n",
  271. priv->delta_stats.tx.ack_or_ba_timeout_collision);
  272. #endif
  273. if (ba_timeout_delta >= BA_TIMEOUT_MAX)
  274. return false;
  275. }
  276. return true;
  277. }
  278. /**
  279. * iwl_good_plcp_health - checks for plcp error.
  280. *
  281. * When the plcp error is exceeding the thresholds, reset the radio
  282. * to improve the throughput.
  283. */
  284. static bool iwl_good_plcp_health(struct iwl_priv *priv,
  285. struct statistics_rx_phy *cur_ofdm,
  286. struct statistics_rx_ht_phy *cur_ofdm_ht,
  287. unsigned int msecs)
  288. {
  289. int delta;
  290. int threshold = priv->cfg->base_params->plcp_delta_threshold;
  291. if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
  292. IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
  293. return true;
  294. }
  295. delta = le32_to_cpu(cur_ofdm->plcp_err) -
  296. le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
  297. le32_to_cpu(cur_ofdm_ht->plcp_err) -
  298. le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
  299. /* Can be negative if firmware reset statistics */
  300. if (delta <= 0)
  301. return true;
  302. if ((delta * 100 / msecs) > threshold) {
  303. IWL_DEBUG_RADIO(priv,
  304. "plcp health threshold %u delta %d msecs %u\n",
  305. threshold, delta, msecs);
  306. return false;
  307. }
  308. return true;
  309. }
  310. static void iwl_recover_from_statistics(struct iwl_priv *priv,
  311. struct statistics_rx_phy *cur_ofdm,
  312. struct statistics_rx_ht_phy *cur_ofdm_ht,
  313. struct statistics_tx *tx,
  314. unsigned long stamp)
  315. {
  316. unsigned int msecs;
  317. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  318. return;
  319. msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
  320. /* Only gather statistics and update time stamp when not associated */
  321. if (!iwl_is_any_associated(priv))
  322. return;
  323. /* Do not check/recover when do not have enough statistics data */
  324. if (msecs < 99)
  325. return;
  326. if (iwlagn_mod_params.ack_check && !iwl_good_ack_health(priv, tx)) {
  327. IWL_ERR(priv, "low ack count detected, restart firmware\n");
  328. if (!iwl_force_reset(priv, IWL_FW_RESET, false))
  329. return;
  330. }
  331. if (iwlagn_mod_params.plcp_check &&
  332. !iwl_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
  333. iwl_force_reset(priv, IWL_RF_RESET, false);
  334. }
  335. /* Calculate noise level, based on measurements during network silence just
  336. * before arriving beacon. This measurement can be done only if we know
  337. * exactly when to expect beacons, therefore only when we're associated. */
  338. static void iwl_rx_calc_noise(struct iwl_priv *priv)
  339. {
  340. struct statistics_rx_non_phy *rx_info;
  341. int num_active_rx = 0;
  342. int total_silence = 0;
  343. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  344. int last_rx_noise;
  345. rx_info = &priv->statistics.rx_non_phy;
  346. bcn_silence_a =
  347. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  348. bcn_silence_b =
  349. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  350. bcn_silence_c =
  351. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  352. if (bcn_silence_a) {
  353. total_silence += bcn_silence_a;
  354. num_active_rx++;
  355. }
  356. if (bcn_silence_b) {
  357. total_silence += bcn_silence_b;
  358. num_active_rx++;
  359. }
  360. if (bcn_silence_c) {
  361. total_silence += bcn_silence_c;
  362. num_active_rx++;
  363. }
  364. /* Average among active antennas */
  365. if (num_active_rx)
  366. last_rx_noise = (total_silence / num_active_rx) - 107;
  367. else
  368. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  369. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  370. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  371. last_rx_noise);
  372. }
  373. #ifdef CONFIG_IWLWIFI_DEBUGFS
  374. /*
  375. * based on the assumption of all statistics counter are in DWORD
  376. * FIXME: This function is for debugging, do not deal with
  377. * the case of counters roll-over.
  378. */
  379. static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
  380. __le32 *max_delta, __le32 *accum, int size)
  381. {
  382. int i;
  383. for (i = 0;
  384. i < size / sizeof(__le32);
  385. i++, prev++, cur++, delta++, max_delta++, accum++) {
  386. if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
  387. *delta = cpu_to_le32(
  388. le32_to_cpu(*cur) - le32_to_cpu(*prev));
  389. le32_add_cpu(accum, le32_to_cpu(*delta));
  390. if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
  391. *max_delta = *delta;
  392. }
  393. }
  394. }
  395. static void
  396. iwl_accumulative_statistics(struct iwl_priv *priv,
  397. struct statistics_general_common *common,
  398. struct statistics_rx_non_phy *rx_non_phy,
  399. struct statistics_rx_phy *rx_ofdm,
  400. struct statistics_rx_ht_phy *rx_ofdm_ht,
  401. struct statistics_rx_phy *rx_cck,
  402. struct statistics_tx *tx,
  403. struct statistics_bt_activity *bt_activity)
  404. {
  405. #define ACCUM(_name) \
  406. accum_stats((__le32 *)&priv->statistics._name, \
  407. (__le32 *)_name, \
  408. (__le32 *)&priv->delta_stats._name, \
  409. (__le32 *)&priv->max_delta_stats._name, \
  410. (__le32 *)&priv->accum_stats._name, \
  411. sizeof(*_name));
  412. ACCUM(common);
  413. ACCUM(rx_non_phy);
  414. ACCUM(rx_ofdm);
  415. ACCUM(rx_ofdm_ht);
  416. ACCUM(rx_cck);
  417. ACCUM(tx);
  418. if (bt_activity)
  419. ACCUM(bt_activity);
  420. #undef ACCUM
  421. }
  422. #else
  423. static inline void
  424. iwl_accumulative_statistics(struct iwl_priv *priv,
  425. struct statistics_general_common *common,
  426. struct statistics_rx_non_phy *rx_non_phy,
  427. struct statistics_rx_phy *rx_ofdm,
  428. struct statistics_rx_ht_phy *rx_ofdm_ht,
  429. struct statistics_rx_phy *rx_cck,
  430. struct statistics_tx *tx,
  431. struct statistics_bt_activity *bt_activity)
  432. {
  433. }
  434. #endif
  435. static int iwl_rx_statistics(struct iwl_priv *priv,
  436. struct iwl_rx_mem_buffer *rxb,
  437. struct iwl_device_cmd *cmd)
  438. {
  439. unsigned long stamp = jiffies;
  440. const int reg_recalib_period = 60;
  441. int change;
  442. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  443. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  444. __le32 *flag;
  445. struct statistics_general_common *common;
  446. struct statistics_rx_non_phy *rx_non_phy;
  447. struct statistics_rx_phy *rx_ofdm;
  448. struct statistics_rx_ht_phy *rx_ofdm_ht;
  449. struct statistics_rx_phy *rx_cck;
  450. struct statistics_tx *tx;
  451. struct statistics_bt_activity *bt_activity;
  452. len -= sizeof(struct iwl_cmd_header); /* skip header */
  453. IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
  454. len);
  455. if (len == sizeof(struct iwl_bt_notif_statistics)) {
  456. struct iwl_bt_notif_statistics *stats;
  457. stats = &pkt->u.stats_bt;
  458. flag = &stats->flag;
  459. common = &stats->general.common;
  460. rx_non_phy = &stats->rx.general.common;
  461. rx_ofdm = &stats->rx.ofdm;
  462. rx_ofdm_ht = &stats->rx.ofdm_ht;
  463. rx_cck = &stats->rx.cck;
  464. tx = &stats->tx;
  465. bt_activity = &stats->general.activity;
  466. #ifdef CONFIG_IWLWIFI_DEBUGFS
  467. /* handle this exception directly */
  468. priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
  469. le32_add_cpu(&priv->statistics.accum_num_bt_kills,
  470. le32_to_cpu(stats->rx.general.num_bt_kills));
  471. #endif
  472. } else if (len == sizeof(struct iwl_notif_statistics)) {
  473. struct iwl_notif_statistics *stats;
  474. stats = &pkt->u.stats;
  475. flag = &stats->flag;
  476. common = &stats->general.common;
  477. rx_non_phy = &stats->rx.general;
  478. rx_ofdm = &stats->rx.ofdm;
  479. rx_ofdm_ht = &stats->rx.ofdm_ht;
  480. rx_cck = &stats->rx.cck;
  481. tx = &stats->tx;
  482. bt_activity = NULL;
  483. } else {
  484. WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
  485. len, sizeof(struct iwl_bt_notif_statistics),
  486. sizeof(struct iwl_notif_statistics));
  487. return 0;
  488. }
  489. change = common->temperature != priv->statistics.common.temperature ||
  490. (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  491. (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
  492. iwl_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
  493. rx_ofdm_ht, rx_cck, tx, bt_activity);
  494. iwl_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
  495. priv->statistics.flag = *flag;
  496. memcpy(&priv->statistics.common, common, sizeof(*common));
  497. memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
  498. memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
  499. memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
  500. memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
  501. memcpy(&priv->statistics.tx, tx, sizeof(*tx));
  502. #ifdef CONFIG_IWLWIFI_DEBUGFS
  503. if (bt_activity)
  504. memcpy(&priv->statistics.bt_activity, bt_activity,
  505. sizeof(*bt_activity));
  506. #endif
  507. priv->rx_statistics_jiffies = stamp;
  508. set_bit(STATUS_STATISTICS, &priv->shrd->status);
  509. /* Reschedule the statistics timer to occur in
  510. * reg_recalib_period seconds to ensure we get a
  511. * thermal update even if the uCode doesn't give
  512. * us one */
  513. mod_timer(&priv->statistics_periodic, jiffies +
  514. msecs_to_jiffies(reg_recalib_period * 1000));
  515. if (unlikely(!test_bit(STATUS_SCANNING, &priv->shrd->status)) &&
  516. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  517. iwl_rx_calc_noise(priv);
  518. queue_work(priv->shrd->workqueue, &priv->run_time_calib_work);
  519. }
  520. if (priv->cfg->lib->temperature && change)
  521. priv->cfg->lib->temperature(priv);
  522. return 0;
  523. }
  524. static int iwl_rx_reply_statistics(struct iwl_priv *priv,
  525. struct iwl_rx_mem_buffer *rxb,
  526. struct iwl_device_cmd *cmd)
  527. {
  528. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  529. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  530. #ifdef CONFIG_IWLWIFI_DEBUGFS
  531. memset(&priv->accum_stats, 0,
  532. sizeof(priv->accum_stats));
  533. memset(&priv->delta_stats, 0,
  534. sizeof(priv->delta_stats));
  535. memset(&priv->max_delta_stats, 0,
  536. sizeof(priv->max_delta_stats));
  537. #endif
  538. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  539. }
  540. iwl_rx_statistics(priv, rxb, cmd);
  541. return 0;
  542. }
  543. /* Handle notification from uCode that card's power state is changing
  544. * due to software, hardware, or critical temperature RFKILL */
  545. static int iwl_rx_card_state_notif(struct iwl_priv *priv,
  546. struct iwl_rx_mem_buffer *rxb,
  547. struct iwl_device_cmd *cmd)
  548. {
  549. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  550. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  551. unsigned long status = priv->shrd->status;
  552. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
  553. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  554. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  555. (flags & CT_CARD_DISABLED) ?
  556. "Reached" : "Not reached");
  557. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  558. CT_CARD_DISABLED)) {
  559. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_SET,
  560. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  561. iwl_write_direct32(bus(priv), HBUS_TARG_MBX_C,
  562. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  563. if (!(flags & RXON_CARD_DISABLED)) {
  564. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
  565. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  566. iwl_write_direct32(bus(priv), HBUS_TARG_MBX_C,
  567. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  568. }
  569. if (flags & CT_CARD_DISABLED)
  570. iwl_tt_enter_ct_kill(priv);
  571. }
  572. if (!(flags & CT_CARD_DISABLED))
  573. iwl_tt_exit_ct_kill(priv);
  574. if (flags & HW_CARD_DISABLED)
  575. set_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  576. else
  577. clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  578. if (!(flags & RXON_CARD_DISABLED))
  579. iwl_scan_cancel(priv);
  580. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  581. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status)))
  582. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  583. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  584. else
  585. wake_up(&priv->shrd->wait_command_queue);
  586. return 0;
  587. }
  588. static int iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
  589. struct iwl_rx_mem_buffer *rxb,
  590. struct iwl_device_cmd *cmd)
  591. {
  592. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  593. struct iwl_missed_beacon_notif *missed_beacon;
  594. missed_beacon = &pkt->u.missed_beacon;
  595. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  596. priv->missed_beacon_threshold) {
  597. IWL_DEBUG_CALIB(priv,
  598. "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  599. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  600. le32_to_cpu(missed_beacon->total_missed_becons),
  601. le32_to_cpu(missed_beacon->num_recvd_beacons),
  602. le32_to_cpu(missed_beacon->num_expected_beacons));
  603. if (!test_bit(STATUS_SCANNING, &priv->shrd->status))
  604. iwl_init_sensitivity(priv);
  605. }
  606. return 0;
  607. }
  608. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  609. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  610. static int iwl_rx_reply_rx_phy(struct iwl_priv *priv,
  611. struct iwl_rx_mem_buffer *rxb,
  612. struct iwl_device_cmd *cmd)
  613. {
  614. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  615. priv->last_phy_res_valid = true;
  616. memcpy(&priv->last_phy_res, pkt->u.raw,
  617. sizeof(struct iwl_rx_phy_res));
  618. return 0;
  619. }
  620. /*
  621. * returns non-zero if packet should be dropped
  622. */
  623. static int iwl_set_decrypted_flag(struct iwl_priv *priv,
  624. struct ieee80211_hdr *hdr,
  625. u32 decrypt_res,
  626. struct ieee80211_rx_status *stats)
  627. {
  628. u16 fc = le16_to_cpu(hdr->frame_control);
  629. /*
  630. * All contexts have the same setting here due to it being
  631. * a module parameter, so OK to check any context.
  632. */
  633. if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
  634. RXON_FILTER_DIS_DECRYPT_MSK)
  635. return 0;
  636. if (!(fc & IEEE80211_FCTL_PROTECTED))
  637. return 0;
  638. IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
  639. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  640. case RX_RES_STATUS_SEC_TYPE_TKIP:
  641. /* The uCode has got a bad phase 1 Key, pushes the packet.
  642. * Decryption will be done in SW. */
  643. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  644. RX_RES_STATUS_BAD_KEY_TTAK)
  645. break;
  646. case RX_RES_STATUS_SEC_TYPE_WEP:
  647. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  648. RX_RES_STATUS_BAD_ICV_MIC) {
  649. /* bad ICV, the packet is destroyed since the
  650. * decryption is inplace, drop it */
  651. IWL_DEBUG_RX(priv, "Packet destroyed\n");
  652. return -1;
  653. }
  654. case RX_RES_STATUS_SEC_TYPE_CCMP:
  655. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  656. RX_RES_STATUS_DECRYPT_OK) {
  657. IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
  658. stats->flag |= RX_FLAG_DECRYPTED;
  659. }
  660. break;
  661. default:
  662. break;
  663. }
  664. return 0;
  665. }
  666. static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
  667. struct ieee80211_hdr *hdr,
  668. u16 len,
  669. u32 ampdu_status,
  670. struct iwl_rx_mem_buffer *rxb,
  671. struct ieee80211_rx_status *stats)
  672. {
  673. struct sk_buff *skb;
  674. __le16 fc = hdr->frame_control;
  675. struct iwl_rxon_context *ctx;
  676. /* We only process data packets if the interface is open */
  677. if (unlikely(!priv->is_open)) {
  678. IWL_DEBUG_DROP_LIMIT(priv,
  679. "Dropping packet while interface is not open.\n");
  680. return;
  681. }
  682. /* In case of HW accelerated crypto and bad decryption, drop */
  683. if (!iwlagn_mod_params.sw_crypto &&
  684. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  685. return;
  686. skb = dev_alloc_skb(128);
  687. if (!skb) {
  688. IWL_ERR(priv, "dev_alloc_skb failed\n");
  689. return;
  690. }
  691. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  692. iwl_update_stats(priv, false, fc, len);
  693. /*
  694. * Wake any queues that were stopped due to a passive channel tx
  695. * failure. This can happen because the regulatory enforcement in
  696. * the device waits for a beacon before allowing transmission,
  697. * sometimes even after already having transmitted frames for the
  698. * association because the new RXON may reset the information.
  699. */
  700. if (unlikely(ieee80211_is_beacon(fc))) {
  701. for_each_context(priv, ctx) {
  702. if (!ctx->last_tx_rejected)
  703. continue;
  704. if (compare_ether_addr(hdr->addr3,
  705. ctx->active.bssid_addr))
  706. continue;
  707. ctx->last_tx_rejected = false;
  708. iwl_trans_wake_any_queue(trans(priv), ctx->ctxid);
  709. }
  710. }
  711. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  712. ieee80211_rx(priv->hw, skb);
  713. rxb->page = NULL;
  714. }
  715. static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  716. {
  717. u32 decrypt_out = 0;
  718. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  719. RX_RES_STATUS_STATION_FOUND)
  720. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  721. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  722. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  723. /* packet was not encrypted */
  724. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  725. RX_RES_STATUS_SEC_TYPE_NONE)
  726. return decrypt_out;
  727. /* packet was encrypted with unknown alg */
  728. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  729. RX_RES_STATUS_SEC_TYPE_ERR)
  730. return decrypt_out;
  731. /* decryption was not done in HW */
  732. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  733. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  734. return decrypt_out;
  735. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  736. case RX_RES_STATUS_SEC_TYPE_CCMP:
  737. /* alg is CCM: check MIC only */
  738. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  739. /* Bad MIC */
  740. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  741. else
  742. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  743. break;
  744. case RX_RES_STATUS_SEC_TYPE_TKIP:
  745. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  746. /* Bad TTAK */
  747. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  748. break;
  749. }
  750. /* fall through if TTAK OK */
  751. default:
  752. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  753. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  754. else
  755. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  756. break;
  757. }
  758. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  759. decrypt_in, decrypt_out);
  760. return decrypt_out;
  761. }
  762. /* Calc max signal level (dBm) among 3 possible receivers */
  763. static int iwlagn_calc_rssi(struct iwl_priv *priv,
  764. struct iwl_rx_phy_res *rx_resp)
  765. {
  766. /* data from PHY/DSP regarding signal strength, etc.,
  767. * contents are always there, not configurable by host
  768. */
  769. struct iwlagn_non_cfg_phy *ncphy =
  770. (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  771. u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
  772. u8 agc;
  773. val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
  774. agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
  775. /* Find max rssi among 3 possible receivers.
  776. * These values are measured by the digital signal processor (DSP).
  777. * They should stay fairly constant even as the signal strength varies,
  778. * if the radio's automatic gain control (AGC) is working right.
  779. * AGC value (see below) will provide the "interesting" info.
  780. */
  781. val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
  782. rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
  783. IWLAGN_OFDM_RSSI_A_BIT_POS;
  784. rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
  785. IWLAGN_OFDM_RSSI_B_BIT_POS;
  786. val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
  787. rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
  788. IWLAGN_OFDM_RSSI_C_BIT_POS;
  789. max_rssi = max_t(u32, rssi_a, rssi_b);
  790. max_rssi = max_t(u32, max_rssi, rssi_c);
  791. IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  792. rssi_a, rssi_b, rssi_c, max_rssi, agc);
  793. /* dBm = max_rssi dB - agc dB - constant.
  794. * Higher AGC (higher radio gain) means lower signal. */
  795. return max_rssi - agc - IWLAGN_RSSI_OFFSET;
  796. }
  797. /* Called for REPLY_RX (legacy ABG frames), or
  798. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  799. static int iwl_rx_reply_rx(struct iwl_priv *priv,
  800. struct iwl_rx_mem_buffer *rxb,
  801. struct iwl_device_cmd *cmd)
  802. {
  803. struct ieee80211_hdr *header;
  804. struct ieee80211_rx_status rx_status;
  805. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  806. struct iwl_rx_phy_res *phy_res;
  807. __le32 rx_pkt_status;
  808. struct iwl_rx_mpdu_res_start *amsdu;
  809. u32 len;
  810. u32 ampdu_status;
  811. u32 rate_n_flags;
  812. /**
  813. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  814. * REPLY_RX: physical layer info is in this buffer
  815. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  816. * command and cached in priv->last_phy_res
  817. *
  818. * Here we set up local variables depending on which command is
  819. * received.
  820. */
  821. if (pkt->hdr.cmd == REPLY_RX) {
  822. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  823. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  824. + phy_res->cfg_phy_cnt);
  825. len = le16_to_cpu(phy_res->byte_count);
  826. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  827. phy_res->cfg_phy_cnt + len);
  828. ampdu_status = le32_to_cpu(rx_pkt_status);
  829. } else {
  830. if (!priv->last_phy_res_valid) {
  831. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  832. return 0;
  833. }
  834. phy_res = &priv->last_phy_res;
  835. amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
  836. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  837. len = le16_to_cpu(amsdu->byte_count);
  838. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  839. ampdu_status = iwl_translate_rx_status(priv,
  840. le32_to_cpu(rx_pkt_status));
  841. }
  842. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  843. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  844. phy_res->cfg_phy_cnt);
  845. return 0;
  846. }
  847. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  848. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  849. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  850. le32_to_cpu(rx_pkt_status));
  851. return 0;
  852. }
  853. /* This will be used in several places later */
  854. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  855. /* rx_status carries information about the packet to mac80211 */
  856. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  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.freq =
  860. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  861. rx_status.band);
  862. rx_status.rate_idx =
  863. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  864. rx_status.flag = 0;
  865. /* TSF isn't reliable. In order to allow smooth user experience,
  866. * this W/A doesn't propagate it to the mac80211 */
  867. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
  868. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  869. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  870. rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
  871. iwl_dbg_log_rx_data_frame(priv, len, header);
  872. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  873. rx_status.signal, (unsigned long long)rx_status.mactime);
  874. /*
  875. * "antenna number"
  876. *
  877. * It seems that the antenna field in the phy flags value
  878. * is actually a bit field. This is undefined by radiotap,
  879. * it wants an actual antenna number but I always get "7"
  880. * for most legacy frames I receive indicating that the
  881. * same frame was received on all three RX chains.
  882. *
  883. * I think this field should be removed in favor of a
  884. * new 802.11n radiotap field "RX chains" that is defined
  885. * as a bitmask.
  886. */
  887. rx_status.antenna =
  888. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  889. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  890. /* set the preamble flag if appropriate */
  891. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  892. rx_status.flag |= RX_FLAG_SHORTPRE;
  893. /* Set up the HT phy flags */
  894. if (rate_n_flags & RATE_MCS_HT_MSK)
  895. rx_status.flag |= RX_FLAG_HT;
  896. if (rate_n_flags & RATE_MCS_HT40_MSK)
  897. rx_status.flag |= RX_FLAG_40MHZ;
  898. if (rate_n_flags & RATE_MCS_SGI_MSK)
  899. rx_status.flag |= RX_FLAG_SHORT_GI;
  900. iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  901. rxb, &rx_status);
  902. return 0;
  903. }
  904. /**
  905. * iwl_setup_rx_handlers - Initialize Rx handler callbacks
  906. *
  907. * Setup the RX handlers for each of the reply types sent from the uCode
  908. * to the host.
  909. */
  910. void iwl_setup_rx_handlers(struct iwl_priv *priv)
  911. {
  912. int (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
  913. struct iwl_device_cmd *cmd);
  914. handlers = priv->rx_handlers;
  915. handlers[REPLY_ERROR] = iwl_rx_reply_error;
  916. handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  917. handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif;
  918. handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  919. handlers[PM_DEBUG_STATISTIC_NOTIFIC] = iwl_rx_pm_debug_statistics_notif;
  920. handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
  921. handlers[REPLY_ADD_STA] = iwl_add_sta_callback;
  922. /*
  923. * The same handler is used for both the REPLY to a discrete
  924. * statistics request from the host as well as for the periodic
  925. * statistics notifications (after received beacons) from the uCode.
  926. */
  927. handlers[REPLY_STATISTICS_CMD] = iwl_rx_reply_statistics;
  928. handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
  929. iwl_setup_rx_scan_handlers(priv);
  930. handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
  931. handlers[MISSED_BEACONS_NOTIFICATION] = iwl_rx_missed_beacon_notif;
  932. /* Rx handlers */
  933. handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
  934. handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
  935. /* block ack */
  936. handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
  937. /* init calibration handlers */
  938. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  939. iwlagn_rx_calib_result;
  940. priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
  941. /* set up notification wait support */
  942. spin_lock_init(&priv->notif_wait_lock);
  943. INIT_LIST_HEAD(&priv->notif_waits);
  944. init_waitqueue_head(&priv->notif_waitq);
  945. /* Set up BT Rx handlers */
  946. if (priv->cfg->lib->bt_rx_handler_setup)
  947. priv->cfg->lib->bt_rx_handler_setup(priv);
  948. }
  949. int iwl_rx_dispatch(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
  950. struct iwl_device_cmd *cmd)
  951. {
  952. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  953. int err = 0;
  954. /*
  955. * Do the notification wait before RX handlers so
  956. * even if the RX handler consumes the RXB we have
  957. * access to it in the notification wait entry.
  958. */
  959. if (!list_empty(&priv->notif_waits)) {
  960. struct iwl_notification_wait *w;
  961. spin_lock(&priv->notif_wait_lock);
  962. list_for_each_entry(w, &priv->notif_waits, list) {
  963. if (w->cmd != pkt->hdr.cmd)
  964. continue;
  965. IWL_DEBUG_RX(priv,
  966. "Notif: %s, 0x%02x - wake the callers up\n",
  967. get_cmd_string(pkt->hdr.cmd),
  968. pkt->hdr.cmd);
  969. w->triggered = true;
  970. if (w->fn)
  971. w->fn(priv, pkt, w->fn_data);
  972. }
  973. spin_unlock(&priv->notif_wait_lock);
  974. wake_up_all(&priv->notif_waitq);
  975. }
  976. if (priv->pre_rx_handler)
  977. priv->pre_rx_handler(priv, rxb);
  978. /* Based on type of command response or notification,
  979. * handle those that need handling via function in
  980. * rx_handlers table. See iwl_setup_rx_handlers() */
  981. if (priv->rx_handlers[pkt->hdr.cmd]) {
  982. priv->rx_handlers_stats[pkt->hdr.cmd]++;
  983. err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd);
  984. } else {
  985. /* No handling needed */
  986. IWL_DEBUG_RX(priv,
  987. "No handler needed for %s, 0x%02x\n",
  988. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  989. }
  990. return err;
  991. }