rx.c 34 KB

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