ops.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. };
  266. #undef CMD
  267. /* this forward declaration can avoid to export the function */
  268. static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
  269. static struct iwl_op_mode *
  270. iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  271. const struct iwl_fw *fw, struct dentry *dbgfs_dir)
  272. {
  273. struct ieee80211_hw *hw;
  274. struct iwl_op_mode *op_mode;
  275. struct iwl_mvm *mvm;
  276. struct iwl_trans_config trans_cfg = {};
  277. static const u8 no_reclaim_cmds[] = {
  278. TX_CMD,
  279. };
  280. int err, scan_size;
  281. /********************************
  282. * 1. Allocating and configuring HW data
  283. ********************************/
  284. hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
  285. sizeof(struct iwl_mvm),
  286. &iwl_mvm_hw_ops);
  287. if (!hw)
  288. return NULL;
  289. op_mode = hw->priv;
  290. op_mode->ops = &iwl_mvm_ops;
  291. op_mode->trans = trans;
  292. mvm = IWL_OP_MODE_GET_MVM(op_mode);
  293. mvm->dev = trans->dev;
  294. mvm->trans = trans;
  295. mvm->cfg = cfg;
  296. mvm->fw = fw;
  297. mvm->hw = hw;
  298. mutex_init(&mvm->mutex);
  299. spin_lock_init(&mvm->async_handlers_lock);
  300. INIT_LIST_HEAD(&mvm->time_event_list);
  301. INIT_LIST_HEAD(&mvm->async_handlers_list);
  302. spin_lock_init(&mvm->time_event_lock);
  303. INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
  304. INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
  305. INIT_WORK(&mvm->sta_drained_wk, iwl_mvm_sta_drained_wk);
  306. SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
  307. /*
  308. * Populate the state variables that the transport layer needs
  309. * to know about.
  310. */
  311. trans_cfg.op_mode = op_mode;
  312. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  313. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  314. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  315. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DW_BC_TABLE)
  316. trans_cfg.bc_table_dword = true;
  317. if (!iwlwifi_mod_params.wd_disable)
  318. trans_cfg.queue_watchdog_timeout = cfg->base_params->wd_timeout;
  319. else
  320. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  321. trans_cfg.command_names = iwl_mvm_cmd_strings;
  322. trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
  323. trans_cfg.cmd_fifo = IWL_MVM_CMD_FIFO;
  324. snprintf(mvm->hw->wiphy->fw_version,
  325. sizeof(mvm->hw->wiphy->fw_version),
  326. "%s", fw->fw_version);
  327. /* Configure transport layer */
  328. iwl_trans_configure(mvm->trans, &trans_cfg);
  329. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  330. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  331. /* set up notification wait support */
  332. iwl_notification_wait_init(&mvm->notif_wait);
  333. /* Init phy db */
  334. mvm->phy_db = iwl_phy_db_init(trans);
  335. if (!mvm->phy_db) {
  336. IWL_ERR(mvm, "Cannot init phy_db\n");
  337. goto out_free;
  338. }
  339. IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
  340. mvm->cfg->name, mvm->trans->hw_rev);
  341. err = iwl_trans_start_hw(mvm->trans);
  342. if (err)
  343. goto out_free;
  344. mutex_lock(&mvm->mutex);
  345. err = iwl_run_init_mvm_ucode(mvm, true);
  346. mutex_unlock(&mvm->mutex);
  347. if (err && !iwlmvm_mod_params.init_dbg) {
  348. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err);
  349. goto out_free;
  350. }
  351. /* Stop the hw after the ALIVE and NVM has been read */
  352. if (!iwlmvm_mod_params.init_dbg)
  353. iwl_trans_stop_hw(mvm->trans, false);
  354. scan_size = sizeof(struct iwl_scan_cmd) +
  355. mvm->fw->ucode_capa.max_probe_length +
  356. (MAX_NUM_SCAN_CHANNELS * sizeof(struct iwl_scan_channel));
  357. mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
  358. if (!mvm->scan_cmd)
  359. goto out_free;
  360. err = iwl_mvm_mac_setup_register(mvm);
  361. if (err)
  362. goto out_free;
  363. err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
  364. if (err)
  365. goto out_unregister;
  366. return op_mode;
  367. out_unregister:
  368. ieee80211_unregister_hw(mvm->hw);
  369. out_free:
  370. iwl_phy_db_free(mvm->phy_db);
  371. kfree(mvm->scan_cmd);
  372. iwl_trans_stop_hw(trans, true);
  373. ieee80211_free_hw(mvm->hw);
  374. return NULL;
  375. }
  376. static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
  377. {
  378. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  379. int i;
  380. iwl_mvm_leds_exit(mvm);
  381. ieee80211_unregister_hw(mvm->hw);
  382. kfree(mvm->scan_cmd);
  383. iwl_trans_stop_hw(mvm->trans, true);
  384. iwl_phy_db_free(mvm->phy_db);
  385. mvm->phy_db = NULL;
  386. iwl_free_nvm_data(mvm->nvm_data);
  387. for (i = 0; i < NVM_NUM_OF_SECTIONS; i++)
  388. kfree(mvm->nvm_sections[i].data);
  389. ieee80211_free_hw(mvm->hw);
  390. }
  391. struct iwl_async_handler_entry {
  392. struct list_head list;
  393. struct iwl_rx_cmd_buffer rxb;
  394. int (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  395. struct iwl_device_cmd *cmd);
  396. };
  397. void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
  398. {
  399. struct iwl_async_handler_entry *entry, *tmp;
  400. spin_lock_bh(&mvm->async_handlers_lock);
  401. list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
  402. iwl_free_rxb(&entry->rxb);
  403. list_del(&entry->list);
  404. kfree(entry);
  405. }
  406. spin_unlock_bh(&mvm->async_handlers_lock);
  407. }
  408. static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
  409. {
  410. struct iwl_mvm *mvm =
  411. container_of(wk, struct iwl_mvm, async_handlers_wk);
  412. struct iwl_async_handler_entry *entry, *tmp;
  413. struct list_head local_list;
  414. INIT_LIST_HEAD(&local_list);
  415. /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
  416. mutex_lock(&mvm->mutex);
  417. /*
  418. * Sync with Rx path with a lock. Remove all the entries from this list,
  419. * add them to a local one (lock free), and then handle them.
  420. */
  421. spin_lock_bh(&mvm->async_handlers_lock);
  422. list_splice_init(&mvm->async_handlers_list, &local_list);
  423. spin_unlock_bh(&mvm->async_handlers_lock);
  424. list_for_each_entry_safe(entry, tmp, &local_list, list) {
  425. if (entry->fn(mvm, &entry->rxb, NULL))
  426. IWL_WARN(mvm,
  427. "returned value from ASYNC handlers are ignored\n");
  428. iwl_free_rxb(&entry->rxb);
  429. list_del(&entry->list);
  430. kfree(entry);
  431. }
  432. mutex_unlock(&mvm->mutex);
  433. }
  434. static int iwl_mvm_rx_dispatch(struct iwl_op_mode *op_mode,
  435. struct iwl_rx_cmd_buffer *rxb,
  436. struct iwl_device_cmd *cmd)
  437. {
  438. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  439. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  440. u8 i;
  441. /*
  442. * Do the notification wait before RX handlers so
  443. * even if the RX handler consumes the RXB we have
  444. * access to it in the notification wait entry.
  445. */
  446. iwl_notification_wait_notify(&mvm->notif_wait, pkt);
  447. for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
  448. const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
  449. struct iwl_async_handler_entry *entry;
  450. if (rx_h->cmd_id != pkt->hdr.cmd)
  451. continue;
  452. if (!rx_h->async)
  453. return rx_h->fn(mvm, rxb, cmd);
  454. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  455. /* we can't do much... */
  456. if (!entry)
  457. return 0;
  458. entry->rxb._page = rxb_steal_page(rxb);
  459. entry->rxb._offset = rxb->_offset;
  460. entry->rxb._rx_page_order = rxb->_rx_page_order;
  461. entry->fn = rx_h->fn;
  462. spin_lock(&mvm->async_handlers_lock);
  463. list_add_tail(&entry->list, &mvm->async_handlers_list);
  464. spin_unlock(&mvm->async_handlers_lock);
  465. schedule_work(&mvm->async_handlers_wk);
  466. break;
  467. }
  468. return 0;
  469. }
  470. static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  471. {
  472. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  473. int mq = mvm->queue_to_mac80211[queue];
  474. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  475. return;
  476. if (atomic_inc_return(&mvm->queue_stop_count[mq]) > 1) {
  477. IWL_DEBUG_TX_QUEUES(mvm,
  478. "queue %d (mac80211 %d) already stopped\n",
  479. queue, mq);
  480. return;
  481. }
  482. set_bit(mq, &mvm->transport_queue_stop);
  483. ieee80211_stop_queue(mvm->hw, mq);
  484. }
  485. static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  486. {
  487. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  488. int mq = mvm->queue_to_mac80211[queue];
  489. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  490. return;
  491. if (atomic_dec_return(&mvm->queue_stop_count[mq]) > 0) {
  492. IWL_DEBUG_TX_QUEUES(mvm,
  493. "queue %d (mac80211 %d) already awake\n",
  494. queue, mq);
  495. return;
  496. }
  497. clear_bit(mq, &mvm->transport_queue_stop);
  498. ieee80211_wake_queue(mvm->hw, mq);
  499. }
  500. static void iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  501. {
  502. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  503. if (state)
  504. set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  505. else
  506. clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  507. wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state);
  508. }
  509. static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  510. {
  511. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  512. struct ieee80211_tx_info *info;
  513. info = IEEE80211_SKB_CB(skb);
  514. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  515. ieee80211_free_txskb(mvm->hw, skb);
  516. }
  517. static void iwl_mvm_nic_restart(struct iwl_mvm *mvm)
  518. {
  519. iwl_abort_notification_waits(&mvm->notif_wait);
  520. /*
  521. * If we're restarting already, don't cycle restarts.
  522. * If INIT fw asserted, it will likely fail again.
  523. * If WoWLAN fw asserted, don't restart either, mac80211
  524. * can't recover this since we're already half suspended.
  525. */
  526. if (test_and_set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  527. IWL_ERR(mvm, "Firmware error during reconfiguration! Abort.\n");
  528. } else if (mvm->cur_ucode == IWL_UCODE_REGULAR &&
  529. iwlwifi_mod_params.restart_fw) {
  530. /*
  531. * This is a bit racy, but worst case we tell mac80211 about
  532. * a stopped/aborted (sched) scan when that was already done
  533. * which is not a problem. It is necessary to abort any scan
  534. * here because mac80211 requires having the scan cleared
  535. * before restarting.
  536. * We'll reset the scan_status to NONE in restart cleanup in
  537. * the next start() call from mac80211.
  538. */
  539. switch (mvm->scan_status) {
  540. case IWL_MVM_SCAN_NONE:
  541. break;
  542. case IWL_MVM_SCAN_OS:
  543. ieee80211_scan_completed(mvm->hw, true);
  544. break;
  545. }
  546. ieee80211_restart_hw(mvm->hw);
  547. }
  548. }
  549. static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode)
  550. {
  551. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  552. iwl_mvm_dump_nic_error_log(mvm);
  553. iwl_mvm_nic_restart(mvm);
  554. }
  555. static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
  556. {
  557. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  558. WARN_ON(1);
  559. iwl_mvm_nic_restart(mvm);
  560. }
  561. static const struct iwl_op_mode_ops iwl_mvm_ops = {
  562. .start = iwl_op_mode_mvm_start,
  563. .stop = iwl_op_mode_mvm_stop,
  564. .rx = iwl_mvm_rx_dispatch,
  565. .queue_full = iwl_mvm_stop_sw_queue,
  566. .queue_not_full = iwl_mvm_wake_sw_queue,
  567. .hw_rf_kill = iwl_mvm_set_hw_rfkill_state,
  568. .free_skb = iwl_mvm_free_skb,
  569. .nic_error = iwl_mvm_nic_error,
  570. .cmd_queue_full = iwl_mvm_cmd_queue_full,
  571. .nic_config = iwl_mvm_nic_config,
  572. };