iwl-core.c 22 KB

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