rx.c 35 KB

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