iwl-agn-rx.c 36 KB

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