iwl-agn-rx.c 36 KB

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