rx.c 35 KB

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