rx.c 36 KB

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