iwl-core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  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. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/sched.h>
  31. #include <linux/slab.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-eeprom.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-power.h"
  38. #include "iwl-shared.h"
  39. #include "iwl-agn.h"
  40. #include "iwl-trans.h"
  41. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  42. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  43. struct iwl_ht_config *ht_conf,
  44. struct iwl_rxon_context *ctx)
  45. {
  46. struct iwl_rxon_cmd *rxon = &ctx->staging;
  47. if (!ctx->ht.enabled) {
  48. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  49. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  50. RXON_FLG_HT40_PROT_MSK |
  51. RXON_FLG_HT_PROT_MSK);
  52. return;
  53. }
  54. /* FIXME: if the definition of ht.protection changed, the "translation"
  55. * will be needed for rxon->flags
  56. */
  57. rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
  58. /* Set up channel bandwidth:
  59. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  60. /* clear the HT channel mode before set the mode */
  61. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  62. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  63. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  64. /* pure ht40 */
  65. if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  66. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  67. /* Note: control channel is opposite of extension channel */
  68. switch (ctx->ht.extension_chan_offset) {
  69. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  70. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  71. break;
  72. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  73. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  74. break;
  75. }
  76. } else {
  77. /* Note: control channel is opposite of extension channel */
  78. switch (ctx->ht.extension_chan_offset) {
  79. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  80. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  81. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  82. break;
  83. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  84. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  85. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  86. break;
  87. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  88. default:
  89. /* channel location only valid if in Mixed mode */
  90. IWL_ERR(priv, "invalid extension channel offset\n");
  91. break;
  92. }
  93. }
  94. } else {
  95. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  96. }
  97. iwlagn_set_rxon_chain(priv, ctx);
  98. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  99. "extension channel offset 0x%x\n",
  100. le32_to_cpu(rxon->flags), ctx->ht.protection,
  101. ctx->ht.extension_chan_offset);
  102. }
  103. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  104. {
  105. struct iwl_rxon_context *ctx;
  106. for_each_context(priv, ctx)
  107. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  108. }
  109. /**
  110. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  111. * @ch: requested channel as a pointer to struct ieee80211_channel
  112. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  113. * in the staging RXON flag structure based on the ch->band
  114. */
  115. void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  116. struct iwl_rxon_context *ctx)
  117. {
  118. enum ieee80211_band band = ch->band;
  119. u16 channel = ch->hw_value;
  120. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  121. (priv->band == band))
  122. return;
  123. ctx->staging.channel = cpu_to_le16(channel);
  124. if (band == IEEE80211_BAND_5GHZ)
  125. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  126. else
  127. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  128. priv->band = band;
  129. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  130. }
  131. void iwl_set_flags_for_band(struct iwl_priv *priv,
  132. struct iwl_rxon_context *ctx,
  133. enum ieee80211_band band,
  134. struct ieee80211_vif *vif)
  135. {
  136. if (band == IEEE80211_BAND_5GHZ) {
  137. ctx->staging.flags &=
  138. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  139. | RXON_FLG_CCK_MSK);
  140. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  141. } else {
  142. /* Copied from iwl_post_associate() */
  143. if (vif && vif->bss_conf.use_short_slot)
  144. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  145. else
  146. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  147. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  148. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  149. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  150. }
  151. }
  152. /*
  153. * initialize rxon structure with default values from eeprom
  154. */
  155. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  156. struct iwl_rxon_context *ctx)
  157. {
  158. const struct iwl_channel_info *ch_info;
  159. memset(&ctx->staging, 0, sizeof(ctx->staging));
  160. if (!ctx->vif) {
  161. ctx->staging.dev_type = ctx->unused_devtype;
  162. } else switch (ctx->vif->type) {
  163. case NL80211_IFTYPE_AP:
  164. ctx->staging.dev_type = ctx->ap_devtype;
  165. break;
  166. case NL80211_IFTYPE_STATION:
  167. ctx->staging.dev_type = ctx->station_devtype;
  168. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  169. break;
  170. case NL80211_IFTYPE_ADHOC:
  171. ctx->staging.dev_type = ctx->ibss_devtype;
  172. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  173. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  174. RXON_FILTER_ACCEPT_GRP_MSK;
  175. break;
  176. default:
  177. IWL_ERR(priv, "Unsupported interface type %d\n",
  178. ctx->vif->type);
  179. break;
  180. }
  181. #if 0
  182. /* TODO: Figure out when short_preamble would be set and cache from
  183. * that */
  184. if (!hw_to_local(priv->hw)->short_preamble)
  185. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  186. else
  187. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  188. #endif
  189. ch_info = iwl_get_channel_info(priv, priv->band,
  190. le16_to_cpu(ctx->active.channel));
  191. if (!ch_info)
  192. ch_info = &priv->channel_info[0];
  193. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  194. priv->band = ch_info->band;
  195. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  196. ctx->staging.ofdm_basic_rates =
  197. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  198. ctx->staging.cck_basic_rates =
  199. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  200. /* clear both MIX and PURE40 mode flag */
  201. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  202. RXON_FLG_CHANNEL_MODE_PURE_40);
  203. if (ctx->vif)
  204. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  205. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  206. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  207. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  208. }
  209. void iwl_set_rate(struct iwl_priv *priv)
  210. {
  211. struct iwl_rxon_context *ctx;
  212. for_each_context(priv, ctx) {
  213. ctx->staging.cck_basic_rates =
  214. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  215. ctx->staging.ofdm_basic_rates =
  216. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  217. }
  218. }
  219. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  220. {
  221. /*
  222. * MULTI-FIXME
  223. * See iwlagn_mac_channel_switch.
  224. */
  225. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  226. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  227. return;
  228. if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  229. ieee80211_chswitch_done(ctx->vif, is_success);
  230. }
  231. #ifdef CONFIG_IWLWIFI_DEBUG
  232. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  233. enum iwl_rxon_context_id ctxid)
  234. {
  235. struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
  236. struct iwl_rxon_cmd *rxon = &ctx->staging;
  237. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  238. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  239. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  240. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  241. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  242. le32_to_cpu(rxon->filter_flags));
  243. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  244. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  245. rxon->ofdm_basic_rates);
  246. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  247. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  248. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  249. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  250. }
  251. #endif
  252. void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  253. {
  254. unsigned int reload_msec;
  255. unsigned long reload_jiffies;
  256. #ifdef CONFIG_IWLWIFI_DEBUG
  257. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  258. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  259. #endif
  260. /* uCode is no longer loaded. */
  261. priv->ucode_loaded = false;
  262. /* Set the FW error flag -- cleared on iwl_down */
  263. set_bit(STATUS_FW_ERROR, &priv->status);
  264. /* Cancel currently queued command. */
  265. clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
  266. iwl_abort_notification_waits(&priv->notif_wait);
  267. /* Keep the restart process from trying to send host
  268. * commands by clearing the ready bit */
  269. clear_bit(STATUS_READY, &priv->status);
  270. wake_up(&trans(priv)->wait_command_queue);
  271. if (!ondemand) {
  272. /*
  273. * If firmware keep reloading, then it indicate something
  274. * serious wrong and firmware having problem to recover
  275. * from it. Instead of keep trying which will fill the syslog
  276. * and hang the system, let's just stop it
  277. */
  278. reload_jiffies = jiffies;
  279. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  280. (long) priv->reload_jiffies);
  281. priv->reload_jiffies = reload_jiffies;
  282. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  283. priv->reload_count++;
  284. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  285. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  286. return;
  287. }
  288. } else
  289. priv->reload_count = 0;
  290. }
  291. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  292. if (iwlagn_mod_params.restart_fw) {
  293. IWL_DEBUG_FW_ERRORS(priv,
  294. "Restarting adapter due to uCode error.\n");
  295. queue_work(priv->workqueue, &priv->restart);
  296. } else
  297. IWL_DEBUG_FW_ERRORS(priv,
  298. "Detected FW error, but not restarting\n");
  299. }
  300. }
  301. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  302. {
  303. int ret;
  304. s8 prev_tx_power;
  305. bool defer;
  306. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  307. lockdep_assert_held(&priv->mutex);
  308. if (priv->tx_power_user_lmt == tx_power && !force)
  309. return 0;
  310. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  311. IWL_WARN(priv,
  312. "Requested user TXPOWER %d below lower limit %d.\n",
  313. tx_power,
  314. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  315. return -EINVAL;
  316. }
  317. if (tx_power > priv->tx_power_device_lmt) {
  318. IWL_WARN(priv,
  319. "Requested user TXPOWER %d above upper limit %d.\n",
  320. tx_power, priv->tx_power_device_lmt);
  321. return -EINVAL;
  322. }
  323. if (!iwl_is_ready_rf(priv))
  324. return -EIO;
  325. /* scan complete and commit_rxon use tx_power_next value,
  326. * it always need to be updated for newest request */
  327. priv->tx_power_next = tx_power;
  328. /* do not set tx power when scanning or channel changing */
  329. defer = test_bit(STATUS_SCANNING, &priv->status) ||
  330. memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
  331. if (defer && !force) {
  332. IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
  333. return 0;
  334. }
  335. prev_tx_power = priv->tx_power_user_lmt;
  336. priv->tx_power_user_lmt = tx_power;
  337. ret = iwlagn_send_tx_power(priv);
  338. /* if fail to set tx_power, restore the orig. tx power */
  339. if (ret) {
  340. priv->tx_power_user_lmt = prev_tx_power;
  341. priv->tx_power_next = prev_tx_power;
  342. }
  343. return ret;
  344. }
  345. void iwl_send_bt_config(struct iwl_priv *priv)
  346. {
  347. struct iwl_bt_cmd bt_cmd = {
  348. .lead_time = BT_LEAD_TIME_DEF,
  349. .max_kill = BT_MAX_KILL_DEF,
  350. .kill_ack_mask = 0,
  351. .kill_cts_mask = 0,
  352. };
  353. if (!iwlagn_mod_params.bt_coex_active)
  354. bt_cmd.flags = BT_COEX_DISABLE;
  355. else
  356. bt_cmd.flags = BT_COEX_ENABLE;
  357. priv->bt_enable_flag = bt_cmd.flags;
  358. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  359. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  360. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  361. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  362. IWL_ERR(priv, "failed to send BT Coex Config\n");
  363. }
  364. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  365. {
  366. struct iwl_statistics_cmd statistics_cmd = {
  367. .configuration_flags =
  368. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  369. };
  370. if (flags & CMD_ASYNC)
  371. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  372. CMD_ASYNC,
  373. sizeof(struct iwl_statistics_cmd),
  374. &statistics_cmd);
  375. else
  376. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  377. CMD_SYNC,
  378. sizeof(struct iwl_statistics_cmd),
  379. &statistics_cmd);
  380. }
  381. #ifdef CONFIG_IWLWIFI_DEBUGFS
  382. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  383. void iwl_reset_traffic_log(struct iwl_priv *priv)
  384. {
  385. priv->tx_traffic_idx = 0;
  386. priv->rx_traffic_idx = 0;
  387. if (priv->tx_traffic)
  388. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  389. if (priv->rx_traffic)
  390. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  391. }
  392. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  393. {
  394. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  395. if (iwl_have_debug_level(IWL_DL_TX)) {
  396. if (!priv->tx_traffic) {
  397. priv->tx_traffic =
  398. kzalloc(traffic_size, GFP_KERNEL);
  399. if (!priv->tx_traffic)
  400. return -ENOMEM;
  401. }
  402. }
  403. if (iwl_have_debug_level(IWL_DL_RX)) {
  404. if (!priv->rx_traffic) {
  405. priv->rx_traffic =
  406. kzalloc(traffic_size, GFP_KERNEL);
  407. if (!priv->rx_traffic)
  408. return -ENOMEM;
  409. }
  410. }
  411. iwl_reset_traffic_log(priv);
  412. return 0;
  413. }
  414. void iwl_free_traffic_mem(struct iwl_priv *priv)
  415. {
  416. kfree(priv->tx_traffic);
  417. priv->tx_traffic = NULL;
  418. kfree(priv->rx_traffic);
  419. priv->rx_traffic = NULL;
  420. }
  421. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  422. u16 length, struct ieee80211_hdr *header)
  423. {
  424. __le16 fc;
  425. u16 len;
  426. if (likely(!iwl_have_debug_level(IWL_DL_TX)))
  427. return;
  428. if (!priv->tx_traffic)
  429. return;
  430. fc = header->frame_control;
  431. if (ieee80211_is_data(fc)) {
  432. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  433. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  434. memcpy((priv->tx_traffic +
  435. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  436. header, len);
  437. priv->tx_traffic_idx =
  438. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  439. }
  440. }
  441. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  442. u16 length, struct ieee80211_hdr *header)
  443. {
  444. __le16 fc;
  445. u16 len;
  446. if (likely(!iwl_have_debug_level(IWL_DL_RX)))
  447. return;
  448. if (!priv->rx_traffic)
  449. return;
  450. fc = header->frame_control;
  451. if (ieee80211_is_data(fc)) {
  452. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  453. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  454. memcpy((priv->rx_traffic +
  455. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  456. header, len);
  457. priv->rx_traffic_idx =
  458. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  459. }
  460. }
  461. const char *get_mgmt_string(int cmd)
  462. {
  463. switch (cmd) {
  464. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  465. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  466. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  467. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  468. IWL_CMD(MANAGEMENT_PROBE_REQ);
  469. IWL_CMD(MANAGEMENT_PROBE_RESP);
  470. IWL_CMD(MANAGEMENT_BEACON);
  471. IWL_CMD(MANAGEMENT_ATIM);
  472. IWL_CMD(MANAGEMENT_DISASSOC);
  473. IWL_CMD(MANAGEMENT_AUTH);
  474. IWL_CMD(MANAGEMENT_DEAUTH);
  475. IWL_CMD(MANAGEMENT_ACTION);
  476. default:
  477. return "UNKNOWN";
  478. }
  479. }
  480. const char *get_ctrl_string(int cmd)
  481. {
  482. switch (cmd) {
  483. IWL_CMD(CONTROL_BACK_REQ);
  484. IWL_CMD(CONTROL_BACK);
  485. IWL_CMD(CONTROL_PSPOLL);
  486. IWL_CMD(CONTROL_RTS);
  487. IWL_CMD(CONTROL_CTS);
  488. IWL_CMD(CONTROL_ACK);
  489. IWL_CMD(CONTROL_CFEND);
  490. IWL_CMD(CONTROL_CFENDACK);
  491. default:
  492. return "UNKNOWN";
  493. }
  494. }
  495. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  496. {
  497. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  498. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  499. }
  500. /*
  501. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  502. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  503. * Use debugFs to display the rx/rx_statistics
  504. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  505. * information will be recorded, but DATA pkt still will be recorded
  506. * for the reason of iwl_led.c need to control the led blinking based on
  507. * number of tx and rx data.
  508. *
  509. */
  510. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  511. {
  512. struct traffic_stats *stats;
  513. if (is_tx)
  514. stats = &priv->tx_stats;
  515. else
  516. stats = &priv->rx_stats;
  517. if (ieee80211_is_mgmt(fc)) {
  518. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  519. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  520. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  521. break;
  522. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  523. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  524. break;
  525. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  526. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  527. break;
  528. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  529. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  530. break;
  531. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  532. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  533. break;
  534. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  535. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  536. break;
  537. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  538. stats->mgmt[MANAGEMENT_BEACON]++;
  539. break;
  540. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  541. stats->mgmt[MANAGEMENT_ATIM]++;
  542. break;
  543. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  544. stats->mgmt[MANAGEMENT_DISASSOC]++;
  545. break;
  546. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  547. stats->mgmt[MANAGEMENT_AUTH]++;
  548. break;
  549. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  550. stats->mgmt[MANAGEMENT_DEAUTH]++;
  551. break;
  552. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  553. stats->mgmt[MANAGEMENT_ACTION]++;
  554. break;
  555. }
  556. } else if (ieee80211_is_ctl(fc)) {
  557. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  558. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  559. stats->ctrl[CONTROL_BACK_REQ]++;
  560. break;
  561. case cpu_to_le16(IEEE80211_STYPE_BACK):
  562. stats->ctrl[CONTROL_BACK]++;
  563. break;
  564. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  565. stats->ctrl[CONTROL_PSPOLL]++;
  566. break;
  567. case cpu_to_le16(IEEE80211_STYPE_RTS):
  568. stats->ctrl[CONTROL_RTS]++;
  569. break;
  570. case cpu_to_le16(IEEE80211_STYPE_CTS):
  571. stats->ctrl[CONTROL_CTS]++;
  572. break;
  573. case cpu_to_le16(IEEE80211_STYPE_ACK):
  574. stats->ctrl[CONTROL_ACK]++;
  575. break;
  576. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  577. stats->ctrl[CONTROL_CFEND]++;
  578. break;
  579. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  580. stats->ctrl[CONTROL_CFENDACK]++;
  581. break;
  582. }
  583. } else {
  584. /* data */
  585. stats->data_cnt++;
  586. stats->data_bytes += len;
  587. }
  588. }
  589. #endif
  590. int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
  591. {
  592. struct iwl_rf_reset *rf_reset;
  593. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  594. return -EAGAIN;
  595. if (!iwl_is_any_associated(priv)) {
  596. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  597. return -ENOLINK;
  598. }
  599. rf_reset = &priv->rf_reset;
  600. rf_reset->reset_request_count++;
  601. if (!external && rf_reset->last_reset_jiffies &&
  602. time_after(rf_reset->last_reset_jiffies +
  603. IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
  604. IWL_DEBUG_INFO(priv, "RF reset rejected\n");
  605. rf_reset->reset_reject_count++;
  606. return -EAGAIN;
  607. }
  608. rf_reset->reset_success_count++;
  609. rf_reset->last_reset_jiffies = jiffies;
  610. /*
  611. * There is no easy and better way to force reset the radio,
  612. * the only known method is switching channel which will force to
  613. * reset and tune the radio.
  614. * Use internal short scan (single channel) operation to should
  615. * achieve this objective.
  616. * Driver should reset the radio when number of consecutive missed
  617. * beacon, or any other uCode error condition detected.
  618. */
  619. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  620. iwl_internal_short_hw_scan(priv);
  621. return 0;
  622. }
  623. int iwl_cmd_echo_test(struct iwl_priv *priv)
  624. {
  625. int ret;
  626. struct iwl_host_cmd cmd = {
  627. .id = REPLY_ECHO,
  628. .len = { 0 },
  629. .flags = CMD_SYNC,
  630. };
  631. ret = iwl_dvm_send_cmd(priv, &cmd);
  632. if (ret)
  633. IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
  634. else
  635. IWL_DEBUG_INFO(priv, "echo testing pass\n");
  636. return ret;
  637. }