iwl-agn-rx.c 35 KB

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