ops.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/module.h>
  64. #include <net/mac80211.h>
  65. #include "iwl-notif-wait.h"
  66. #include "iwl-trans.h"
  67. #include "iwl-op-mode.h"
  68. #include "iwl-fw.h"
  69. #include "iwl-debug.h"
  70. #include "iwl-drv.h"
  71. #include "iwl-modparams.h"
  72. #include "mvm.h"
  73. #include "iwl-phy-db.h"
  74. #include "iwl-eeprom-parse.h"
  75. #include "iwl-csr.h"
  76. #include "iwl-io.h"
  77. #include "iwl-prph.h"
  78. #include "rs.h"
  79. #include "fw-api-scan.h"
  80. #include "time-event.h"
  81. /*
  82. * module name, copyright, version, etc.
  83. */
  84. #define DRV_DESCRIPTION "The new Intel(R) wireless AGN driver for Linux"
  85. #define DRV_VERSION IWLWIFI_VERSION
  86. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  87. MODULE_VERSION(DRV_VERSION);
  88. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  89. MODULE_LICENSE("GPL");
  90. static const struct iwl_op_mode_ops iwl_mvm_ops;
  91. struct iwl_mvm_mod_params iwlmvm_mod_params = {
  92. .power_scheme = IWL_POWER_SCHEME_BPS,
  93. /* rest of fields are 0 by default */
  94. };
  95. module_param_named(init_dbg, iwlmvm_mod_params.init_dbg, bool, S_IRUGO);
  96. MODULE_PARM_DESC(init_dbg,
  97. "set to true to debug an ASSERT in INIT fw (default: false");
  98. module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, S_IRUGO);
  99. MODULE_PARM_DESC(power_scheme,
  100. "power management scheme: 1-active, 2-balanced, 3-low power, default: 2");
  101. /*
  102. * module init and exit functions
  103. */
  104. static int __init iwl_mvm_init(void)
  105. {
  106. int ret;
  107. ret = iwl_mvm_rate_control_register();
  108. if (ret) {
  109. pr_err("Unable to register rate control algorithm: %d\n", ret);
  110. return ret;
  111. }
  112. ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops);
  113. if (ret) {
  114. pr_err("Unable to register MVM op_mode: %d\n", ret);
  115. iwl_mvm_rate_control_unregister();
  116. }
  117. return ret;
  118. }
  119. module_init(iwl_mvm_init);
  120. static void __exit iwl_mvm_exit(void)
  121. {
  122. iwl_opmode_deregister("iwlmvm");
  123. iwl_mvm_rate_control_unregister();
  124. }
  125. module_exit(iwl_mvm_exit);
  126. static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)
  127. {
  128. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  129. u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash;
  130. u32 reg_val = 0;
  131. radio_cfg_type = (mvm->fw->phy_config & FW_PHY_CFG_RADIO_TYPE) >>
  132. FW_PHY_CFG_RADIO_TYPE_POS;
  133. radio_cfg_step = (mvm->fw->phy_config & FW_PHY_CFG_RADIO_STEP) >>
  134. FW_PHY_CFG_RADIO_STEP_POS;
  135. radio_cfg_dash = (mvm->fw->phy_config & FW_PHY_CFG_RADIO_DASH) >>
  136. FW_PHY_CFG_RADIO_DASH_POS;
  137. /* SKU control */
  138. reg_val |= CSR_HW_REV_STEP(mvm->trans->hw_rev) <<
  139. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP;
  140. reg_val |= CSR_HW_REV_DASH(mvm->trans->hw_rev) <<
  141. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH;
  142. /* radio configuration */
  143. reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;
  144. reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;
  145. reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  146. WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &
  147. ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);
  148. /* silicon bits */
  149. reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;
  150. iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,
  151. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  152. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP |
  153. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  154. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  155. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |
  156. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  157. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI,
  158. reg_val);
  159. IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
  160. radio_cfg_step, radio_cfg_dash);
  161. /*
  162. * W/A : NIC is stuck in a reset state after Early PCIe power off
  163. * (PCIe power is lost before PERST# is asserted), causing ME FW
  164. * to lose ownership and not being able to obtain it back.
  165. */
  166. iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,
  167. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  168. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  169. }
  170. struct iwl_rx_handlers {
  171. u8 cmd_id;
  172. bool async;
  173. int (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  174. struct iwl_device_cmd *cmd);
  175. };
  176. #define RX_HANDLER(_cmd_id, _fn, _async) \
  177. { .cmd_id = _cmd_id , .fn = _fn , .async = _async }
  178. /*
  179. * Handlers for fw notifications
  180. * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
  181. * This list should be in order of frequency for performance purposes.
  182. *
  183. * The handler can be SYNC - this means that it will be called in the Rx path
  184. * which can't acquire mvm->mutex. If the handler needs to hold mvm->mutex (and
  185. * only in this case!), it should be set as ASYNC. In that case, it will be
  186. * called from a worker with mvm->mutex held.
  187. */
  188. static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
  189. RX_HANDLER(REPLY_RX_MPDU_CMD, iwl_mvm_rx_rx_mpdu, false),
  190. RX_HANDLER(REPLY_RX_PHY_CMD, iwl_mvm_rx_rx_phy_cmd, false),
  191. RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, false),
  192. RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, false),
  193. RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif, false),
  194. RX_HANDLER(SCAN_REQUEST_CMD, iwl_mvm_rx_scan_response, false),
  195. RX_HANDLER(SCAN_COMPLETE_NOTIFICATION, iwl_mvm_rx_scan_complete, false),
  196. RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif, true),
  197. RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif, false),
  198. RX_HANDLER(RADIO_VERSION_NOTIFICATION, iwl_mvm_rx_radio_ver, false),
  199. RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif, false),
  200. RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, false),
  201. };
  202. #undef RX_HANDLER
  203. #define CMD(x) [x] = #x
  204. static const char *iwl_mvm_cmd_strings[REPLY_MAX] = {
  205. CMD(MVM_ALIVE),
  206. CMD(REPLY_ERROR),
  207. CMD(INIT_COMPLETE_NOTIF),
  208. CMD(PHY_CONTEXT_CMD),
  209. CMD(MGMT_MCAST_KEY),
  210. CMD(TX_CMD),
  211. CMD(TXPATH_FLUSH),
  212. CMD(MAC_CONTEXT_CMD),
  213. CMD(TIME_EVENT_CMD),
  214. CMD(TIME_EVENT_NOTIFICATION),
  215. CMD(BINDING_CONTEXT_CMD),
  216. CMD(TIME_QUOTA_CMD),
  217. CMD(RADIO_VERSION_NOTIFICATION),
  218. CMD(SCAN_REQUEST_CMD),
  219. CMD(SCAN_ABORT_CMD),
  220. CMD(SCAN_START_NOTIFICATION),
  221. CMD(SCAN_RESULTS_NOTIFICATION),
  222. CMD(SCAN_COMPLETE_NOTIFICATION),
  223. CMD(NVM_ACCESS_CMD),
  224. CMD(PHY_CONFIGURATION_CMD),
  225. CMD(CALIB_RES_NOTIF_PHY_DB),
  226. CMD(SET_CALIB_DEFAULT_CMD),
  227. CMD(CALIBRATION_COMPLETE_NOTIFICATION),
  228. CMD(ADD_STA),
  229. CMD(REMOVE_STA),
  230. CMD(LQ_CMD),
  231. CMD(SCAN_OFFLOAD_CONFIG_CMD),
  232. CMD(SCAN_OFFLOAD_REQUEST_CMD),
  233. CMD(SCAN_OFFLOAD_ABORT_CMD),
  234. CMD(SCAN_OFFLOAD_COMPLETE),
  235. CMD(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
  236. CMD(POWER_TABLE_CMD),
  237. CMD(WEP_KEY),
  238. CMD(REPLY_RX_PHY_CMD),
  239. CMD(REPLY_RX_MPDU_CMD),
  240. CMD(BEACON_NOTIFICATION),
  241. CMD(BEACON_TEMPLATE_CMD),
  242. CMD(STATISTICS_NOTIFICATION),
  243. CMD(TX_ANT_CONFIGURATION_CMD),
  244. CMD(D3_CONFIG_CMD),
  245. CMD(PROT_OFFLOAD_CONFIG_CMD),
  246. CMD(OFFLOADS_QUERY_CMD),
  247. CMD(REMOTE_WAKE_CONFIG_CMD),
  248. CMD(WOWLAN_PATTERNS),
  249. CMD(WOWLAN_CONFIGURATION),
  250. CMD(WOWLAN_TSC_RSC_PARAM),
  251. CMD(WOWLAN_TKIP_PARAM),
  252. CMD(WOWLAN_KEK_KCK_MATERIAL),
  253. CMD(WOWLAN_GET_STATUSES),
  254. CMD(WOWLAN_TX_POWER_PER_DB),
  255. CMD(NET_DETECT_CONFIG_CMD),
  256. CMD(NET_DETECT_PROFILES_QUERY_CMD),
  257. CMD(NET_DETECT_PROFILES_CMD),
  258. CMD(NET_DETECT_HOTSPOTS_CMD),
  259. CMD(NET_DETECT_HOTSPOTS_QUERY_CMD),
  260. CMD(CARD_STATE_NOTIFICATION),
  261. CMD(BT_COEX_PRIO_TABLE),
  262. CMD(BT_COEX_PROT_ENV),
  263. CMD(BT_PROFILE_NOTIFICATION),
  264. CMD(BT_CONFIG),
  265. CMD(MCAST_FILTER_CMD),
  266. CMD(REPLY_BEACON_FILTERING_CMD),
  267. };
  268. #undef CMD
  269. /* this forward declaration can avoid to export the function */
  270. static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
  271. static struct iwl_op_mode *
  272. iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  273. const struct iwl_fw *fw, struct dentry *dbgfs_dir)
  274. {
  275. struct ieee80211_hw *hw;
  276. struct iwl_op_mode *op_mode;
  277. struct iwl_mvm *mvm;
  278. struct iwl_trans_config trans_cfg = {};
  279. static const u8 no_reclaim_cmds[] = {
  280. TX_CMD,
  281. };
  282. int err, scan_size;
  283. /********************************
  284. * 1. Allocating and configuring HW data
  285. ********************************/
  286. hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
  287. sizeof(struct iwl_mvm),
  288. &iwl_mvm_hw_ops);
  289. if (!hw)
  290. return NULL;
  291. op_mode = hw->priv;
  292. op_mode->ops = &iwl_mvm_ops;
  293. op_mode->trans = trans;
  294. mvm = IWL_OP_MODE_GET_MVM(op_mode);
  295. mvm->dev = trans->dev;
  296. mvm->trans = trans;
  297. mvm->cfg = cfg;
  298. mvm->fw = fw;
  299. mvm->hw = hw;
  300. mutex_init(&mvm->mutex);
  301. spin_lock_init(&mvm->async_handlers_lock);
  302. INIT_LIST_HEAD(&mvm->time_event_list);
  303. INIT_LIST_HEAD(&mvm->async_handlers_list);
  304. spin_lock_init(&mvm->time_event_lock);
  305. INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
  306. INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
  307. INIT_WORK(&mvm->sta_drained_wk, iwl_mvm_sta_drained_wk);
  308. SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
  309. /*
  310. * Populate the state variables that the transport layer needs
  311. * to know about.
  312. */
  313. trans_cfg.op_mode = op_mode;
  314. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  315. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  316. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  317. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DW_BC_TABLE)
  318. trans_cfg.bc_table_dword = true;
  319. if (!iwlwifi_mod_params.wd_disable)
  320. trans_cfg.queue_watchdog_timeout = cfg->base_params->wd_timeout;
  321. else
  322. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  323. trans_cfg.command_names = iwl_mvm_cmd_strings;
  324. trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
  325. trans_cfg.cmd_fifo = IWL_MVM_CMD_FIFO;
  326. snprintf(mvm->hw->wiphy->fw_version,
  327. sizeof(mvm->hw->wiphy->fw_version),
  328. "%s", fw->fw_version);
  329. /* Configure transport layer */
  330. iwl_trans_configure(mvm->trans, &trans_cfg);
  331. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  332. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  333. /* set up notification wait support */
  334. iwl_notification_wait_init(&mvm->notif_wait);
  335. /* Init phy db */
  336. mvm->phy_db = iwl_phy_db_init(trans);
  337. if (!mvm->phy_db) {
  338. IWL_ERR(mvm, "Cannot init phy_db\n");
  339. goto out_free;
  340. }
  341. IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
  342. mvm->cfg->name, mvm->trans->hw_rev);
  343. err = iwl_trans_start_hw(mvm->trans);
  344. if (err)
  345. goto out_free;
  346. mutex_lock(&mvm->mutex);
  347. err = iwl_run_init_mvm_ucode(mvm, true);
  348. mutex_unlock(&mvm->mutex);
  349. /* returns 0 if successful, 1 if success but in rfkill */
  350. if (err < 0 && !iwlmvm_mod_params.init_dbg) {
  351. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err);
  352. goto out_free;
  353. }
  354. /* Stop the hw after the ALIVE and NVM has been read */
  355. if (!iwlmvm_mod_params.init_dbg)
  356. iwl_trans_stop_hw(mvm->trans, false);
  357. scan_size = sizeof(struct iwl_scan_cmd) +
  358. mvm->fw->ucode_capa.max_probe_length +
  359. (MAX_NUM_SCAN_CHANNELS * sizeof(struct iwl_scan_channel));
  360. mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
  361. if (!mvm->scan_cmd)
  362. goto out_free;
  363. err = iwl_mvm_mac_setup_register(mvm);
  364. if (err)
  365. goto out_free;
  366. err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
  367. if (err)
  368. goto out_unregister;
  369. return op_mode;
  370. out_unregister:
  371. ieee80211_unregister_hw(mvm->hw);
  372. out_free:
  373. iwl_phy_db_free(mvm->phy_db);
  374. kfree(mvm->scan_cmd);
  375. iwl_trans_stop_hw(trans, true);
  376. ieee80211_free_hw(mvm->hw);
  377. return NULL;
  378. }
  379. static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
  380. {
  381. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  382. int i;
  383. iwl_mvm_leds_exit(mvm);
  384. ieee80211_unregister_hw(mvm->hw);
  385. kfree(mvm->scan_cmd);
  386. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
  387. kfree(mvm->d3_resume_sram);
  388. #endif
  389. iwl_trans_stop_hw(mvm->trans, true);
  390. iwl_phy_db_free(mvm->phy_db);
  391. mvm->phy_db = NULL;
  392. iwl_free_nvm_data(mvm->nvm_data);
  393. for (i = 0; i < NVM_NUM_OF_SECTIONS; i++)
  394. kfree(mvm->nvm_sections[i].data);
  395. ieee80211_free_hw(mvm->hw);
  396. }
  397. struct iwl_async_handler_entry {
  398. struct list_head list;
  399. struct iwl_rx_cmd_buffer rxb;
  400. int (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  401. struct iwl_device_cmd *cmd);
  402. };
  403. void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
  404. {
  405. struct iwl_async_handler_entry *entry, *tmp;
  406. spin_lock_bh(&mvm->async_handlers_lock);
  407. list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
  408. iwl_free_rxb(&entry->rxb);
  409. list_del(&entry->list);
  410. kfree(entry);
  411. }
  412. spin_unlock_bh(&mvm->async_handlers_lock);
  413. }
  414. static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
  415. {
  416. struct iwl_mvm *mvm =
  417. container_of(wk, struct iwl_mvm, async_handlers_wk);
  418. struct iwl_async_handler_entry *entry, *tmp;
  419. struct list_head local_list;
  420. INIT_LIST_HEAD(&local_list);
  421. /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
  422. mutex_lock(&mvm->mutex);
  423. /*
  424. * Sync with Rx path with a lock. Remove all the entries from this list,
  425. * add them to a local one (lock free), and then handle them.
  426. */
  427. spin_lock_bh(&mvm->async_handlers_lock);
  428. list_splice_init(&mvm->async_handlers_list, &local_list);
  429. spin_unlock_bh(&mvm->async_handlers_lock);
  430. list_for_each_entry_safe(entry, tmp, &local_list, list) {
  431. if (entry->fn(mvm, &entry->rxb, NULL))
  432. IWL_WARN(mvm,
  433. "returned value from ASYNC handlers are ignored\n");
  434. iwl_free_rxb(&entry->rxb);
  435. list_del(&entry->list);
  436. kfree(entry);
  437. }
  438. mutex_unlock(&mvm->mutex);
  439. }
  440. static int iwl_mvm_rx_dispatch(struct iwl_op_mode *op_mode,
  441. struct iwl_rx_cmd_buffer *rxb,
  442. struct iwl_device_cmd *cmd)
  443. {
  444. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  445. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  446. u8 i;
  447. /*
  448. * Do the notification wait before RX handlers so
  449. * even if the RX handler consumes the RXB we have
  450. * access to it in the notification wait entry.
  451. */
  452. iwl_notification_wait_notify(&mvm->notif_wait, pkt);
  453. for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
  454. const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
  455. struct iwl_async_handler_entry *entry;
  456. if (rx_h->cmd_id != pkt->hdr.cmd)
  457. continue;
  458. if (!rx_h->async)
  459. return rx_h->fn(mvm, rxb, cmd);
  460. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  461. /* we can't do much... */
  462. if (!entry)
  463. return 0;
  464. entry->rxb._page = rxb_steal_page(rxb);
  465. entry->rxb._offset = rxb->_offset;
  466. entry->rxb._rx_page_order = rxb->_rx_page_order;
  467. entry->fn = rx_h->fn;
  468. spin_lock(&mvm->async_handlers_lock);
  469. list_add_tail(&entry->list, &mvm->async_handlers_list);
  470. spin_unlock(&mvm->async_handlers_lock);
  471. schedule_work(&mvm->async_handlers_wk);
  472. break;
  473. }
  474. return 0;
  475. }
  476. static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  477. {
  478. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  479. int mq = mvm->queue_to_mac80211[queue];
  480. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  481. return;
  482. if (atomic_inc_return(&mvm->queue_stop_count[mq]) > 1) {
  483. IWL_DEBUG_TX_QUEUES(mvm,
  484. "queue %d (mac80211 %d) already stopped\n",
  485. queue, mq);
  486. return;
  487. }
  488. set_bit(mq, &mvm->transport_queue_stop);
  489. ieee80211_stop_queue(mvm->hw, mq);
  490. }
  491. static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  492. {
  493. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  494. int mq = mvm->queue_to_mac80211[queue];
  495. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  496. return;
  497. if (atomic_dec_return(&mvm->queue_stop_count[mq]) > 0) {
  498. IWL_DEBUG_TX_QUEUES(mvm,
  499. "queue %d (mac80211 %d) already awake\n",
  500. queue, mq);
  501. return;
  502. }
  503. clear_bit(mq, &mvm->transport_queue_stop);
  504. ieee80211_wake_queue(mvm->hw, mq);
  505. }
  506. static void iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  507. {
  508. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  509. if (state)
  510. set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  511. else
  512. clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  513. wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state);
  514. }
  515. static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  516. {
  517. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  518. struct ieee80211_tx_info *info;
  519. info = IEEE80211_SKB_CB(skb);
  520. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  521. ieee80211_free_txskb(mvm->hw, skb);
  522. }
  523. static void iwl_mvm_nic_restart(struct iwl_mvm *mvm)
  524. {
  525. iwl_abort_notification_waits(&mvm->notif_wait);
  526. /*
  527. * If we're restarting already, don't cycle restarts.
  528. * If INIT fw asserted, it will likely fail again.
  529. * If WoWLAN fw asserted, don't restart either, mac80211
  530. * can't recover this since we're already half suspended.
  531. */
  532. if (test_and_set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  533. IWL_ERR(mvm, "Firmware error during reconfiguration! Abort.\n");
  534. } else if (mvm->cur_ucode == IWL_UCODE_REGULAR &&
  535. iwlwifi_mod_params.restart_fw) {
  536. /*
  537. * This is a bit racy, but worst case we tell mac80211 about
  538. * a stopped/aborted (sched) scan when that was already done
  539. * which is not a problem. It is necessary to abort any scan
  540. * here because mac80211 requires having the scan cleared
  541. * before restarting.
  542. * We'll reset the scan_status to NONE in restart cleanup in
  543. * the next start() call from mac80211.
  544. */
  545. switch (mvm->scan_status) {
  546. case IWL_MVM_SCAN_NONE:
  547. break;
  548. case IWL_MVM_SCAN_OS:
  549. ieee80211_scan_completed(mvm->hw, true);
  550. break;
  551. }
  552. ieee80211_restart_hw(mvm->hw);
  553. }
  554. }
  555. static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode)
  556. {
  557. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  558. iwl_mvm_dump_nic_error_log(mvm);
  559. iwl_mvm_nic_restart(mvm);
  560. }
  561. static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
  562. {
  563. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  564. WARN_ON(1);
  565. iwl_mvm_nic_restart(mvm);
  566. }
  567. static const struct iwl_op_mode_ops iwl_mvm_ops = {
  568. .start = iwl_op_mode_mvm_start,
  569. .stop = iwl_op_mode_mvm_stop,
  570. .rx = iwl_mvm_rx_dispatch,
  571. .queue_full = iwl_mvm_stop_sw_queue,
  572. .queue_not_full = iwl_mvm_wake_sw_queue,
  573. .hw_rf_kill = iwl_mvm_set_hw_rfkill_state,
  574. .free_skb = iwl_mvm_free_skb,
  575. .nic_error = iwl_mvm_nic_error,
  576. .cmd_queue_full = iwl_mvm_cmd_queue_full,
  577. .nic_config = iwl_mvm_nic_config,
  578. };