iwl-core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. /*
  43. * initialize rxon structure with default values from eeprom
  44. */
  45. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  46. struct iwl_rxon_context *ctx)
  47. {
  48. const struct iwl_channel_info *ch_info;
  49. memset(&ctx->staging, 0, sizeof(ctx->staging));
  50. if (!ctx->vif) {
  51. ctx->staging.dev_type = ctx->unused_devtype;
  52. } else switch (ctx->vif->type) {
  53. case NL80211_IFTYPE_AP:
  54. ctx->staging.dev_type = ctx->ap_devtype;
  55. break;
  56. case NL80211_IFTYPE_STATION:
  57. ctx->staging.dev_type = ctx->station_devtype;
  58. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  59. break;
  60. case NL80211_IFTYPE_ADHOC:
  61. ctx->staging.dev_type = ctx->ibss_devtype;
  62. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  63. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  64. RXON_FILTER_ACCEPT_GRP_MSK;
  65. break;
  66. default:
  67. IWL_ERR(priv, "Unsupported interface type %d\n",
  68. ctx->vif->type);
  69. break;
  70. }
  71. #if 0
  72. /* TODO: Figure out when short_preamble would be set and cache from
  73. * that */
  74. if (!hw_to_local(priv->hw)->short_preamble)
  75. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  76. else
  77. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  78. #endif
  79. ch_info = iwl_get_channel_info(priv, priv->band,
  80. le16_to_cpu(ctx->active.channel));
  81. if (!ch_info)
  82. ch_info = &priv->channel_info[0];
  83. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  84. priv->band = ch_info->band;
  85. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  86. ctx->staging.ofdm_basic_rates =
  87. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  88. ctx->staging.cck_basic_rates =
  89. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  90. /* clear both MIX and PURE40 mode flag */
  91. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  92. RXON_FLG_CHANNEL_MODE_PURE_40);
  93. if (ctx->vif)
  94. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  95. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  96. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  97. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  98. }
  99. void iwl_set_rate(struct iwl_priv *priv)
  100. {
  101. struct iwl_rxon_context *ctx;
  102. for_each_context(priv, ctx) {
  103. ctx->staging.cck_basic_rates =
  104. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  105. ctx->staging.ofdm_basic_rates =
  106. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  107. }
  108. }
  109. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  110. {
  111. /*
  112. * MULTI-FIXME
  113. * See iwlagn_mac_channel_switch.
  114. */
  115. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  116. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  117. return;
  118. if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  119. ieee80211_chswitch_done(ctx->vif, is_success);
  120. }
  121. #ifdef CONFIG_IWLWIFI_DEBUG
  122. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  123. enum iwl_rxon_context_id ctxid)
  124. {
  125. struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
  126. struct iwl_rxon_cmd *rxon = &ctx->staging;
  127. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  128. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  129. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  130. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  131. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  132. le32_to_cpu(rxon->filter_flags));
  133. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  134. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  135. rxon->ofdm_basic_rates);
  136. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  137. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  138. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  139. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  140. }
  141. #endif
  142. void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  143. {
  144. unsigned int reload_msec;
  145. unsigned long reload_jiffies;
  146. #ifdef CONFIG_IWLWIFI_DEBUG
  147. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  148. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  149. #endif
  150. /* uCode is no longer loaded. */
  151. priv->ucode_loaded = false;
  152. /* Set the FW error flag -- cleared on iwl_down */
  153. set_bit(STATUS_FW_ERROR, &priv->status);
  154. /* Cancel currently queued command. */
  155. clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
  156. iwl_abort_notification_waits(&priv->notif_wait);
  157. /* Keep the restart process from trying to send host
  158. * commands by clearing the ready bit */
  159. clear_bit(STATUS_READY, &priv->status);
  160. wake_up(&trans(priv)->wait_command_queue);
  161. if (!ondemand) {
  162. /*
  163. * If firmware keep reloading, then it indicate something
  164. * serious wrong and firmware having problem to recover
  165. * from it. Instead of keep trying which will fill the syslog
  166. * and hang the system, let's just stop it
  167. */
  168. reload_jiffies = jiffies;
  169. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  170. (long) priv->reload_jiffies);
  171. priv->reload_jiffies = reload_jiffies;
  172. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  173. priv->reload_count++;
  174. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  175. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  176. return;
  177. }
  178. } else
  179. priv->reload_count = 0;
  180. }
  181. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  182. if (iwlagn_mod_params.restart_fw) {
  183. IWL_DEBUG_FW_ERRORS(priv,
  184. "Restarting adapter due to uCode error.\n");
  185. queue_work(priv->workqueue, &priv->restart);
  186. } else
  187. IWL_DEBUG_FW_ERRORS(priv,
  188. "Detected FW error, but not restarting\n");
  189. }
  190. }
  191. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  192. {
  193. int ret;
  194. s8 prev_tx_power;
  195. bool defer;
  196. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  197. lockdep_assert_held(&priv->mutex);
  198. if (priv->tx_power_user_lmt == tx_power && !force)
  199. return 0;
  200. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  201. IWL_WARN(priv,
  202. "Requested user TXPOWER %d below lower limit %d.\n",
  203. tx_power,
  204. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  205. return -EINVAL;
  206. }
  207. if (tx_power > priv->tx_power_device_lmt) {
  208. IWL_WARN(priv,
  209. "Requested user TXPOWER %d above upper limit %d.\n",
  210. tx_power, priv->tx_power_device_lmt);
  211. return -EINVAL;
  212. }
  213. if (!iwl_is_ready_rf(priv))
  214. return -EIO;
  215. /* scan complete and commit_rxon use tx_power_next value,
  216. * it always need to be updated for newest request */
  217. priv->tx_power_next = tx_power;
  218. /* do not set tx power when scanning or channel changing */
  219. defer = test_bit(STATUS_SCANNING, &priv->status) ||
  220. memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
  221. if (defer && !force) {
  222. IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
  223. return 0;
  224. }
  225. prev_tx_power = priv->tx_power_user_lmt;
  226. priv->tx_power_user_lmt = tx_power;
  227. ret = iwlagn_send_tx_power(priv);
  228. /* if fail to set tx_power, restore the orig. tx power */
  229. if (ret) {
  230. priv->tx_power_user_lmt = prev_tx_power;
  231. priv->tx_power_next = prev_tx_power;
  232. }
  233. return ret;
  234. }
  235. void iwl_send_bt_config(struct iwl_priv *priv)
  236. {
  237. struct iwl_bt_cmd bt_cmd = {
  238. .lead_time = BT_LEAD_TIME_DEF,
  239. .max_kill = BT_MAX_KILL_DEF,
  240. .kill_ack_mask = 0,
  241. .kill_cts_mask = 0,
  242. };
  243. if (!iwlagn_mod_params.bt_coex_active)
  244. bt_cmd.flags = BT_COEX_DISABLE;
  245. else
  246. bt_cmd.flags = BT_COEX_ENABLE;
  247. priv->bt_enable_flag = bt_cmd.flags;
  248. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  249. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  250. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  251. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  252. IWL_ERR(priv, "failed to send BT Coex Config\n");
  253. }
  254. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  255. {
  256. struct iwl_statistics_cmd statistics_cmd = {
  257. .configuration_flags =
  258. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  259. };
  260. if (flags & CMD_ASYNC)
  261. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  262. CMD_ASYNC,
  263. sizeof(struct iwl_statistics_cmd),
  264. &statistics_cmd);
  265. else
  266. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  267. CMD_SYNC,
  268. sizeof(struct iwl_statistics_cmd),
  269. &statistics_cmd);
  270. }
  271. #ifdef CONFIG_IWLWIFI_DEBUGFS
  272. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  273. void iwl_reset_traffic_log(struct iwl_priv *priv)
  274. {
  275. priv->tx_traffic_idx = 0;
  276. priv->rx_traffic_idx = 0;
  277. if (priv->tx_traffic)
  278. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  279. if (priv->rx_traffic)
  280. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  281. }
  282. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  283. {
  284. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  285. if (iwl_have_debug_level(IWL_DL_TX)) {
  286. if (!priv->tx_traffic) {
  287. priv->tx_traffic =
  288. kzalloc(traffic_size, GFP_KERNEL);
  289. if (!priv->tx_traffic)
  290. return -ENOMEM;
  291. }
  292. }
  293. if (iwl_have_debug_level(IWL_DL_RX)) {
  294. if (!priv->rx_traffic) {
  295. priv->rx_traffic =
  296. kzalloc(traffic_size, GFP_KERNEL);
  297. if (!priv->rx_traffic)
  298. return -ENOMEM;
  299. }
  300. }
  301. iwl_reset_traffic_log(priv);
  302. return 0;
  303. }
  304. void iwl_free_traffic_mem(struct iwl_priv *priv)
  305. {
  306. kfree(priv->tx_traffic);
  307. priv->tx_traffic = NULL;
  308. kfree(priv->rx_traffic);
  309. priv->rx_traffic = NULL;
  310. }
  311. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  312. u16 length, struct ieee80211_hdr *header)
  313. {
  314. __le16 fc;
  315. u16 len;
  316. if (likely(!iwl_have_debug_level(IWL_DL_TX)))
  317. return;
  318. if (!priv->tx_traffic)
  319. return;
  320. fc = header->frame_control;
  321. if (ieee80211_is_data(fc)) {
  322. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  323. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  324. memcpy((priv->tx_traffic +
  325. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  326. header, len);
  327. priv->tx_traffic_idx =
  328. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  329. }
  330. }
  331. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  332. u16 length, struct ieee80211_hdr *header)
  333. {
  334. __le16 fc;
  335. u16 len;
  336. if (likely(!iwl_have_debug_level(IWL_DL_RX)))
  337. return;
  338. if (!priv->rx_traffic)
  339. return;
  340. fc = header->frame_control;
  341. if (ieee80211_is_data(fc)) {
  342. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  343. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  344. memcpy((priv->rx_traffic +
  345. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  346. header, len);
  347. priv->rx_traffic_idx =
  348. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  349. }
  350. }
  351. const char *get_mgmt_string(int cmd)
  352. {
  353. switch (cmd) {
  354. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  355. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  356. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  357. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  358. IWL_CMD(MANAGEMENT_PROBE_REQ);
  359. IWL_CMD(MANAGEMENT_PROBE_RESP);
  360. IWL_CMD(MANAGEMENT_BEACON);
  361. IWL_CMD(MANAGEMENT_ATIM);
  362. IWL_CMD(MANAGEMENT_DISASSOC);
  363. IWL_CMD(MANAGEMENT_AUTH);
  364. IWL_CMD(MANAGEMENT_DEAUTH);
  365. IWL_CMD(MANAGEMENT_ACTION);
  366. default:
  367. return "UNKNOWN";
  368. }
  369. }
  370. const char *get_ctrl_string(int cmd)
  371. {
  372. switch (cmd) {
  373. IWL_CMD(CONTROL_BACK_REQ);
  374. IWL_CMD(CONTROL_BACK);
  375. IWL_CMD(CONTROL_PSPOLL);
  376. IWL_CMD(CONTROL_RTS);
  377. IWL_CMD(CONTROL_CTS);
  378. IWL_CMD(CONTROL_ACK);
  379. IWL_CMD(CONTROL_CFEND);
  380. IWL_CMD(CONTROL_CFENDACK);
  381. default:
  382. return "UNKNOWN";
  383. }
  384. }
  385. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  386. {
  387. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  388. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  389. }
  390. /*
  391. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  392. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  393. * Use debugFs to display the rx/rx_statistics
  394. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  395. * information will be recorded, but DATA pkt still will be recorded
  396. * for the reason of iwl_led.c need to control the led blinking based on
  397. * number of tx and rx data.
  398. *
  399. */
  400. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  401. {
  402. struct traffic_stats *stats;
  403. if (is_tx)
  404. stats = &priv->tx_stats;
  405. else
  406. stats = &priv->rx_stats;
  407. if (ieee80211_is_mgmt(fc)) {
  408. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  409. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  410. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  411. break;
  412. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  413. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  414. break;
  415. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  416. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  417. break;
  418. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  419. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  420. break;
  421. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  422. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  423. break;
  424. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  425. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  426. break;
  427. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  428. stats->mgmt[MANAGEMENT_BEACON]++;
  429. break;
  430. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  431. stats->mgmt[MANAGEMENT_ATIM]++;
  432. break;
  433. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  434. stats->mgmt[MANAGEMENT_DISASSOC]++;
  435. break;
  436. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  437. stats->mgmt[MANAGEMENT_AUTH]++;
  438. break;
  439. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  440. stats->mgmt[MANAGEMENT_DEAUTH]++;
  441. break;
  442. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  443. stats->mgmt[MANAGEMENT_ACTION]++;
  444. break;
  445. }
  446. } else if (ieee80211_is_ctl(fc)) {
  447. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  448. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  449. stats->ctrl[CONTROL_BACK_REQ]++;
  450. break;
  451. case cpu_to_le16(IEEE80211_STYPE_BACK):
  452. stats->ctrl[CONTROL_BACK]++;
  453. break;
  454. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  455. stats->ctrl[CONTROL_PSPOLL]++;
  456. break;
  457. case cpu_to_le16(IEEE80211_STYPE_RTS):
  458. stats->ctrl[CONTROL_RTS]++;
  459. break;
  460. case cpu_to_le16(IEEE80211_STYPE_CTS):
  461. stats->ctrl[CONTROL_CTS]++;
  462. break;
  463. case cpu_to_le16(IEEE80211_STYPE_ACK):
  464. stats->ctrl[CONTROL_ACK]++;
  465. break;
  466. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  467. stats->ctrl[CONTROL_CFEND]++;
  468. break;
  469. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  470. stats->ctrl[CONTROL_CFENDACK]++;
  471. break;
  472. }
  473. } else {
  474. /* data */
  475. stats->data_cnt++;
  476. stats->data_bytes += len;
  477. }
  478. }
  479. #endif
  480. int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
  481. {
  482. struct iwl_rf_reset *rf_reset;
  483. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  484. return -EAGAIN;
  485. if (!iwl_is_any_associated(priv)) {
  486. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  487. return -ENOLINK;
  488. }
  489. rf_reset = &priv->rf_reset;
  490. rf_reset->reset_request_count++;
  491. if (!external && rf_reset->last_reset_jiffies &&
  492. time_after(rf_reset->last_reset_jiffies +
  493. IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
  494. IWL_DEBUG_INFO(priv, "RF reset rejected\n");
  495. rf_reset->reset_reject_count++;
  496. return -EAGAIN;
  497. }
  498. rf_reset->reset_success_count++;
  499. rf_reset->last_reset_jiffies = jiffies;
  500. /*
  501. * There is no easy and better way to force reset the radio,
  502. * the only known method is switching channel which will force to
  503. * reset and tune the radio.
  504. * Use internal short scan (single channel) operation to should
  505. * achieve this objective.
  506. * Driver should reset the radio when number of consecutive missed
  507. * beacon, or any other uCode error condition detected.
  508. */
  509. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  510. iwl_internal_short_hw_scan(priv);
  511. return 0;
  512. }
  513. int iwl_cmd_echo_test(struct iwl_priv *priv)
  514. {
  515. int ret;
  516. struct iwl_host_cmd cmd = {
  517. .id = REPLY_ECHO,
  518. .len = { 0 },
  519. .flags = CMD_SYNC,
  520. };
  521. ret = iwl_dvm_send_cmd(priv, &cmd);
  522. if (ret)
  523. IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
  524. else
  525. IWL_DEBUG_INFO(priv, "echo testing pass\n");
  526. return ret;
  527. }