ops.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/module.h>
  66. #include <linux/vmalloc.h>
  67. #include <net/mac80211.h>
  68. #include "iwl-notif-wait.h"
  69. #include "iwl-trans.h"
  70. #include "iwl-op-mode.h"
  71. #include "iwl-fw.h"
  72. #include "iwl-debug.h"
  73. #include "iwl-drv.h"
  74. #include "iwl-modparams.h"
  75. #include "mvm.h"
  76. #include "iwl-phy-db.h"
  77. #include "iwl-eeprom-parse.h"
  78. #include "iwl-csr.h"
  79. #include "iwl-io.h"
  80. #include "iwl-prph.h"
  81. #include "rs.h"
  82. #include "fw-api-scan.h"
  83. #include "time-event.h"
  84. #define DRV_DESCRIPTION "The new Intel(R) wireless AGN driver for Linux"
  85. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  86. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  87. MODULE_LICENSE("GPL");
  88. static const struct iwl_op_mode_ops iwl_mvm_ops;
  89. struct iwl_mvm_mod_params iwlmvm_mod_params = {
  90. .power_scheme = IWL_POWER_SCHEME_BPS,
  91. .tfd_q_hang_detect = true
  92. /* rest of fields are 0 by default */
  93. };
  94. module_param_named(init_dbg, iwlmvm_mod_params.init_dbg, bool, S_IRUGO);
  95. MODULE_PARM_DESC(init_dbg,
  96. "set to true to debug an ASSERT in INIT fw (default: false");
  97. module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, S_IRUGO);
  98. MODULE_PARM_DESC(power_scheme,
  99. "power management scheme: 1-active, 2-balanced, 3-low power, default: 2");
  100. module_param_named(tfd_q_hang_detect, iwlmvm_mod_params.tfd_q_hang_detect,
  101. bool, S_IRUGO);
  102. MODULE_PARM_DESC(tfd_q_hang_detect,
  103. "TFD queues hang detection (default: true");
  104. /*
  105. * module init and exit functions
  106. */
  107. static int __init iwl_mvm_init(void)
  108. {
  109. int ret;
  110. ret = iwl_mvm_rate_control_register();
  111. if (ret) {
  112. pr_err("Unable to register rate control algorithm: %d\n", ret);
  113. return ret;
  114. }
  115. ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops);
  116. if (ret) {
  117. pr_err("Unable to register MVM op_mode: %d\n", ret);
  118. iwl_mvm_rate_control_unregister();
  119. }
  120. return ret;
  121. }
  122. module_init(iwl_mvm_init);
  123. static void __exit iwl_mvm_exit(void)
  124. {
  125. iwl_opmode_deregister("iwlmvm");
  126. iwl_mvm_rate_control_unregister();
  127. }
  128. module_exit(iwl_mvm_exit);
  129. static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)
  130. {
  131. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  132. u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash;
  133. u32 reg_val = 0;
  134. u32 phy_config = iwl_mvm_get_phy_config(mvm);
  135. radio_cfg_type = (phy_config & FW_PHY_CFG_RADIO_TYPE) >>
  136. FW_PHY_CFG_RADIO_TYPE_POS;
  137. radio_cfg_step = (phy_config & FW_PHY_CFG_RADIO_STEP) >>
  138. FW_PHY_CFG_RADIO_STEP_POS;
  139. radio_cfg_dash = (phy_config & FW_PHY_CFG_RADIO_DASH) >>
  140. FW_PHY_CFG_RADIO_DASH_POS;
  141. /* SKU control */
  142. reg_val |= CSR_HW_REV_STEP(mvm->trans->hw_rev) <<
  143. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP;
  144. reg_val |= CSR_HW_REV_DASH(mvm->trans->hw_rev) <<
  145. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH;
  146. /* radio configuration */
  147. reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;
  148. reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;
  149. reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  150. WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &
  151. ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);
  152. /*
  153. * TODO: Bits 7-8 of CSR in 8000 HW family set the ADC sampling, and
  154. * shouldn't be set to any non-zero value. The same is supposed to be
  155. * true of the other HW, but unsetting them (such as the 7260) causes
  156. * automatic tests to fail on seemingly unrelated errors. Need to
  157. * further investigate this, but for now we'll separate cases.
  158. */
  159. if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
  160. reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;
  161. iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,
  162. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  163. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP |
  164. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  165. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  166. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |
  167. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  168. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI,
  169. reg_val);
  170. IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
  171. radio_cfg_step, radio_cfg_dash);
  172. /*
  173. * W/A : NIC is stuck in a reset state after Early PCIe power off
  174. * (PCIe power is lost before PERST# is asserted), causing ME FW
  175. * to lose ownership and not being able to obtain it back.
  176. */
  177. if (!mvm->trans->cfg->apmg_not_supported)
  178. iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,
  179. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  180. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  181. }
  182. struct iwl_rx_handlers {
  183. u16 cmd_id;
  184. bool async;
  185. void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
  186. };
  187. #define RX_HANDLER(_cmd_id, _fn, _async) \
  188. { .cmd_id = _cmd_id , .fn = _fn , .async = _async }
  189. #define RX_HANDLER_GRP(_grp, _cmd, _fn, _async) \
  190. { .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .async = _async }
  191. /*
  192. * Handlers for fw notifications
  193. * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
  194. * This list should be in order of frequency for performance purposes.
  195. *
  196. * The handler can be SYNC - this means that it will be called in the Rx path
  197. * which can't acquire mvm->mutex. If the handler needs to hold mvm->mutex (and
  198. * only in this case!), it should be set as ASYNC. In that case, it will be
  199. * called from a worker with mvm->mutex held.
  200. */
  201. static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
  202. RX_HANDLER(REPLY_RX_PHY_CMD, iwl_mvm_rx_rx_phy_cmd, false),
  203. RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, false),
  204. RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, false),
  205. RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif, true),
  206. RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif, true),
  207. RX_HANDLER(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics, true),
  208. RX_HANDLER(ANTENNA_COUPLING_NOTIFICATION,
  209. iwl_mvm_rx_ant_coupling_notif, true),
  210. RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif, false),
  211. RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc, true),
  212. RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, false),
  213. RX_HANDLER(SCAN_ITERATION_COMPLETE,
  214. iwl_mvm_rx_lmac_scan_iter_complete_notif, false),
  215. RX_HANDLER(SCAN_OFFLOAD_COMPLETE,
  216. iwl_mvm_rx_lmac_scan_complete_notif, true),
  217. RX_HANDLER(MATCH_FOUND_NOTIFICATION, iwl_mvm_rx_scan_match_found,
  218. false),
  219. RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,
  220. true),
  221. RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,
  222. iwl_mvm_rx_umac_scan_iter_complete_notif, false),
  223. RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif, false),
  224. RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif,
  225. false),
  226. RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, false),
  227. RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,
  228. iwl_mvm_power_uapsd_misbehaving_ap_notif, false),
  229. RX_HANDLER(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif, true),
  230. RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,
  231. true),
  232. RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif, false),
  233. RX_HANDLER(TOF_NOTIFICATION, iwl_mvm_tof_resp_handler, true),
  234. };
  235. #undef RX_HANDLER
  236. #undef RX_HANDLER_GRP
  237. #define CMD(x) [x] = #x
  238. static const char *const iwl_mvm_cmd_strings[REPLY_MAX] = {
  239. CMD(MVM_ALIVE),
  240. CMD(REPLY_ERROR),
  241. CMD(INIT_COMPLETE_NOTIF),
  242. CMD(PHY_CONTEXT_CMD),
  243. CMD(MGMT_MCAST_KEY),
  244. CMD(TX_CMD),
  245. CMD(TXPATH_FLUSH),
  246. CMD(SHARED_MEM_CFG),
  247. CMD(MAC_CONTEXT_CMD),
  248. CMD(TIME_EVENT_CMD),
  249. CMD(TIME_EVENT_NOTIFICATION),
  250. CMD(BINDING_CONTEXT_CMD),
  251. CMD(TIME_QUOTA_CMD),
  252. CMD(NON_QOS_TX_COUNTER_CMD),
  253. CMD(DC2DC_CONFIG_CMD),
  254. CMD(NVM_ACCESS_CMD),
  255. CMD(PHY_CONFIGURATION_CMD),
  256. CMD(CALIB_RES_NOTIF_PHY_DB),
  257. CMD(SET_CALIB_DEFAULT_CMD),
  258. CMD(ADD_STA_KEY),
  259. CMD(ADD_STA),
  260. CMD(REMOVE_STA),
  261. CMD(LQ_CMD),
  262. CMD(SCAN_OFFLOAD_CONFIG_CMD),
  263. CMD(MATCH_FOUND_NOTIFICATION),
  264. CMD(SCAN_OFFLOAD_REQUEST_CMD),
  265. CMD(SCAN_OFFLOAD_ABORT_CMD),
  266. CMD(HOT_SPOT_CMD),
  267. CMD(SCAN_OFFLOAD_COMPLETE),
  268. CMD(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
  269. CMD(SCAN_ITERATION_COMPLETE),
  270. CMD(POWER_TABLE_CMD),
  271. CMD(WEP_KEY),
  272. CMD(REPLY_RX_PHY_CMD),
  273. CMD(REPLY_RX_MPDU_CMD),
  274. CMD(BEACON_NOTIFICATION),
  275. CMD(BEACON_TEMPLATE_CMD),
  276. CMD(STATISTICS_CMD),
  277. CMD(STATISTICS_NOTIFICATION),
  278. CMD(EOSP_NOTIFICATION),
  279. CMD(REDUCE_TX_POWER_CMD),
  280. CMD(TX_ANT_CONFIGURATION_CMD),
  281. CMD(D3_CONFIG_CMD),
  282. CMD(D0I3_END_CMD),
  283. CMD(PROT_OFFLOAD_CONFIG_CMD),
  284. CMD(OFFLOADS_QUERY_CMD),
  285. CMD(REMOTE_WAKE_CONFIG_CMD),
  286. CMD(WOWLAN_PATTERNS),
  287. CMD(WOWLAN_CONFIGURATION),
  288. CMD(WOWLAN_TSC_RSC_PARAM),
  289. CMD(WOWLAN_TKIP_PARAM),
  290. CMD(WOWLAN_KEK_KCK_MATERIAL),
  291. CMD(WOWLAN_GET_STATUSES),
  292. CMD(WOWLAN_TX_POWER_PER_DB),
  293. CMD(SCAN_OFFLOAD_PROFILES_QUERY_CMD),
  294. CMD(SCAN_OFFLOAD_HOTSPOTS_CONFIG_CMD),
  295. CMD(SCAN_OFFLOAD_HOTSPOTS_QUERY_CMD),
  296. CMD(CARD_STATE_NOTIFICATION),
  297. CMD(MISSED_BEACONS_NOTIFICATION),
  298. CMD(BT_COEX_PRIO_TABLE),
  299. CMD(BT_COEX_PROT_ENV),
  300. CMD(BT_PROFILE_NOTIFICATION),
  301. CMD(BT_CONFIG),
  302. CMD(MCAST_FILTER_CMD),
  303. CMD(BCAST_FILTER_CMD),
  304. CMD(REPLY_SF_CFG_CMD),
  305. CMD(REPLY_BEACON_FILTERING_CMD),
  306. CMD(CMD_DTS_MEASUREMENT_TRIGGER),
  307. CMD(DTS_MEASUREMENT_NOTIFICATION),
  308. CMD(REPLY_THERMAL_MNG_BACKOFF),
  309. CMD(MAC_PM_POWER_TABLE),
  310. CMD(LTR_CONFIG),
  311. CMD(BT_COEX_CI),
  312. CMD(BT_COEX_UPDATE_SW_BOOST),
  313. CMD(BT_COEX_UPDATE_CORUN_LUT),
  314. CMD(BT_COEX_UPDATE_REDUCED_TXP),
  315. CMD(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),
  316. CMD(ANTENNA_COUPLING_NOTIFICATION),
  317. CMD(SCD_QUEUE_CFG),
  318. CMD(SCAN_CFG_CMD),
  319. CMD(SCAN_REQ_UMAC),
  320. CMD(SCAN_ABORT_UMAC),
  321. CMD(SCAN_COMPLETE_UMAC),
  322. CMD(TDLS_CHANNEL_SWITCH_CMD),
  323. CMD(TDLS_CHANNEL_SWITCH_NOTIFICATION),
  324. CMD(TDLS_CONFIG_CMD),
  325. CMD(MCC_UPDATE_CMD),
  326. CMD(SCAN_ITERATION_COMPLETE_UMAC),
  327. };
  328. #undef CMD
  329. /* this forward declaration can avoid to export the function */
  330. static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
  331. static void iwl_mvm_d0i3_exit_work(struct work_struct *wk);
  332. static u32 calc_min_backoff(struct iwl_trans *trans, const struct iwl_cfg *cfg)
  333. {
  334. const struct iwl_pwr_tx_backoff *pwr_tx_backoff = cfg->pwr_tx_backoffs;
  335. if (!pwr_tx_backoff)
  336. return 0;
  337. while (pwr_tx_backoff->pwr) {
  338. if (trans->dflt_pwr_limit >= pwr_tx_backoff->pwr)
  339. return pwr_tx_backoff->backoff;
  340. pwr_tx_backoff++;
  341. }
  342. return 0;
  343. }
  344. static void iwl_mvm_fw_error_dump_wk(struct work_struct *work);
  345. static struct iwl_op_mode *
  346. iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  347. const struct iwl_fw *fw, struct dentry *dbgfs_dir)
  348. {
  349. struct ieee80211_hw *hw;
  350. struct iwl_op_mode *op_mode;
  351. struct iwl_mvm *mvm;
  352. struct iwl_trans_config trans_cfg = {};
  353. static const u8 no_reclaim_cmds[] = {
  354. TX_CMD,
  355. };
  356. int err, scan_size;
  357. u32 min_backoff;
  358. /*
  359. * We use IWL_MVM_STATION_COUNT to check the validity of the station
  360. * index all over the driver - check that its value corresponds to the
  361. * array size.
  362. */
  363. BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) != IWL_MVM_STATION_COUNT);
  364. /********************************
  365. * 1. Allocating and configuring HW data
  366. ********************************/
  367. hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
  368. sizeof(struct iwl_mvm),
  369. &iwl_mvm_hw_ops);
  370. if (!hw)
  371. return NULL;
  372. if (cfg->max_rx_agg_size)
  373. hw->max_rx_aggregation_subframes = cfg->max_rx_agg_size;
  374. if (cfg->max_tx_agg_size)
  375. hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
  376. op_mode = hw->priv;
  377. op_mode->ops = &iwl_mvm_ops;
  378. mvm = IWL_OP_MODE_GET_MVM(op_mode);
  379. mvm->dev = trans->dev;
  380. mvm->trans = trans;
  381. mvm->cfg = cfg;
  382. mvm->fw = fw;
  383. mvm->hw = hw;
  384. mvm->restart_fw = iwlwifi_mod_params.restart_fw ? -1 : 0;
  385. mvm->aux_queue = 15;
  386. mvm->first_agg_queue = 16;
  387. mvm->last_agg_queue = mvm->cfg->base_params->num_of_queues - 1;
  388. if (mvm->cfg->base_params->num_of_queues == 16) {
  389. mvm->aux_queue = 11;
  390. mvm->first_agg_queue = 12;
  391. }
  392. mvm->sf_state = SF_UNINIT;
  393. mvm->low_latency_agg_frame_limit = 6;
  394. mvm->cur_ucode = IWL_UCODE_INIT;
  395. mutex_init(&mvm->mutex);
  396. mutex_init(&mvm->d0i3_suspend_mutex);
  397. spin_lock_init(&mvm->async_handlers_lock);
  398. INIT_LIST_HEAD(&mvm->time_event_list);
  399. INIT_LIST_HEAD(&mvm->aux_roc_te_list);
  400. INIT_LIST_HEAD(&mvm->async_handlers_list);
  401. spin_lock_init(&mvm->time_event_lock);
  402. INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
  403. INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
  404. INIT_WORK(&mvm->sta_drained_wk, iwl_mvm_sta_drained_wk);
  405. INIT_WORK(&mvm->d0i3_exit_work, iwl_mvm_d0i3_exit_work);
  406. INIT_DELAYED_WORK(&mvm->fw_dump_wk, iwl_mvm_fw_error_dump_wk);
  407. INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
  408. spin_lock_init(&mvm->d0i3_tx_lock);
  409. spin_lock_init(&mvm->refs_lock);
  410. skb_queue_head_init(&mvm->d0i3_tx);
  411. init_waitqueue_head(&mvm->d0i3_exit_waitq);
  412. SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
  413. /*
  414. * Populate the state variables that the transport layer needs
  415. * to know about.
  416. */
  417. trans_cfg.op_mode = op_mode;
  418. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  419. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  420. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  421. trans_cfg.wide_cmd_header = fw_has_api(&mvm->fw->ucode_capa,
  422. IWL_UCODE_TLV_API_WIDE_CMD_HDR);
  423. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DW_BC_TABLE)
  424. trans_cfg.bc_table_dword = true;
  425. trans_cfg.command_names = iwl_mvm_cmd_strings;
  426. trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
  427. trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
  428. trans_cfg.scd_set_active = true;
  429. trans_cfg.sdio_adma_addr = fw->sdio_adma_addr;
  430. /* Set a short watchdog for the command queue */
  431. trans_cfg.cmd_q_wdg_timeout =
  432. iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
  433. snprintf(mvm->hw->wiphy->fw_version,
  434. sizeof(mvm->hw->wiphy->fw_version),
  435. "%s", fw->fw_version);
  436. /* Configure transport layer */
  437. iwl_trans_configure(mvm->trans, &trans_cfg);
  438. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  439. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  440. trans->dbg_dest_tlv = mvm->fw->dbg_dest_tlv;
  441. trans->dbg_dest_reg_num = mvm->fw->dbg_dest_reg_num;
  442. memcpy(trans->dbg_conf_tlv, mvm->fw->dbg_conf_tlv,
  443. sizeof(trans->dbg_conf_tlv));
  444. trans->dbg_trigger_tlv = mvm->fw->dbg_trigger_tlv;
  445. /* set up notification wait support */
  446. iwl_notification_wait_init(&mvm->notif_wait);
  447. /* Init phy db */
  448. mvm->phy_db = iwl_phy_db_init(trans);
  449. if (!mvm->phy_db) {
  450. IWL_ERR(mvm, "Cannot init phy_db\n");
  451. goto out_free;
  452. }
  453. IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
  454. mvm->cfg->name, mvm->trans->hw_rev);
  455. min_backoff = calc_min_backoff(trans, cfg);
  456. iwl_mvm_tt_initialize(mvm, min_backoff);
  457. if (iwlwifi_mod_params.nvm_file)
  458. mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
  459. else
  460. IWL_DEBUG_EEPROM(mvm->trans->dev,
  461. "working without external nvm file\n");
  462. if (WARN(cfg->no_power_up_nic_in_init && !mvm->nvm_file_name,
  463. "not allowing power-up and not having nvm_file\n"))
  464. goto out_free;
  465. /*
  466. * Even if nvm exists in the nvm_file driver should read again the nvm
  467. * from the nic because there might be entries that exist in the OTP
  468. * and not in the file.
  469. * for nics with no_power_up_nic_in_init: rely completley on nvm_file
  470. */
  471. if (cfg->no_power_up_nic_in_init && mvm->nvm_file_name) {
  472. err = iwl_nvm_init(mvm, false);
  473. if (err)
  474. goto out_free;
  475. } else {
  476. err = iwl_trans_start_hw(mvm->trans);
  477. if (err)
  478. goto out_free;
  479. mutex_lock(&mvm->mutex);
  480. err = iwl_run_init_mvm_ucode(mvm, true);
  481. if (!err || !iwlmvm_mod_params.init_dbg)
  482. iwl_trans_stop_device(trans);
  483. mutex_unlock(&mvm->mutex);
  484. /* returns 0 if successful, 1 if success but in rfkill */
  485. if (err < 0 && !iwlmvm_mod_params.init_dbg) {
  486. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err);
  487. goto out_free;
  488. }
  489. }
  490. scan_size = iwl_mvm_scan_size(mvm);
  491. mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
  492. if (!mvm->scan_cmd)
  493. goto out_free;
  494. /* Set EBS as successful as long as not stated otherwise by the FW. */
  495. mvm->last_ebs_successful = true;
  496. err = iwl_mvm_mac_setup_register(mvm);
  497. if (err)
  498. goto out_free;
  499. err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
  500. if (err)
  501. goto out_unregister;
  502. memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
  503. /* rpm starts with a taken ref. only set the appropriate bit here. */
  504. mvm->refs[IWL_MVM_REF_UCODE_DOWN] = 1;
  505. iwl_mvm_tof_init(mvm);
  506. return op_mode;
  507. out_unregister:
  508. ieee80211_unregister_hw(mvm->hw);
  509. iwl_mvm_leds_exit(mvm);
  510. out_free:
  511. iwl_phy_db_free(mvm->phy_db);
  512. kfree(mvm->scan_cmd);
  513. if (!cfg->no_power_up_nic_in_init || !mvm->nvm_file_name)
  514. iwl_trans_op_mode_leave(trans);
  515. ieee80211_free_hw(mvm->hw);
  516. return NULL;
  517. }
  518. static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
  519. {
  520. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  521. int i;
  522. iwl_mvm_leds_exit(mvm);
  523. iwl_mvm_tt_exit(mvm);
  524. ieee80211_unregister_hw(mvm->hw);
  525. kfree(mvm->scan_cmd);
  526. kfree(mvm->mcast_filter_cmd);
  527. mvm->mcast_filter_cmd = NULL;
  528. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
  529. kfree(mvm->d3_resume_sram);
  530. if (mvm->nd_config) {
  531. kfree(mvm->nd_config->match_sets);
  532. kfree(mvm->nd_config);
  533. mvm->nd_config = NULL;
  534. }
  535. #endif
  536. iwl_trans_op_mode_leave(mvm->trans);
  537. iwl_phy_db_free(mvm->phy_db);
  538. mvm->phy_db = NULL;
  539. iwl_free_nvm_data(mvm->nvm_data);
  540. for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
  541. kfree(mvm->nvm_sections[i].data);
  542. iwl_mvm_tof_clean(mvm);
  543. ieee80211_free_hw(mvm->hw);
  544. }
  545. struct iwl_async_handler_entry {
  546. struct list_head list;
  547. struct iwl_rx_cmd_buffer rxb;
  548. void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
  549. };
  550. void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
  551. {
  552. struct iwl_async_handler_entry *entry, *tmp;
  553. spin_lock_bh(&mvm->async_handlers_lock);
  554. list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
  555. iwl_free_rxb(&entry->rxb);
  556. list_del(&entry->list);
  557. kfree(entry);
  558. }
  559. spin_unlock_bh(&mvm->async_handlers_lock);
  560. }
  561. static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
  562. {
  563. struct iwl_mvm *mvm =
  564. container_of(wk, struct iwl_mvm, async_handlers_wk);
  565. struct iwl_async_handler_entry *entry, *tmp;
  566. struct list_head local_list;
  567. INIT_LIST_HEAD(&local_list);
  568. /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
  569. mutex_lock(&mvm->mutex);
  570. /*
  571. * Sync with Rx path with a lock. Remove all the entries from this list,
  572. * add them to a local one (lock free), and then handle them.
  573. */
  574. spin_lock_bh(&mvm->async_handlers_lock);
  575. list_splice_init(&mvm->async_handlers_list, &local_list);
  576. spin_unlock_bh(&mvm->async_handlers_lock);
  577. list_for_each_entry_safe(entry, tmp, &local_list, list) {
  578. entry->fn(mvm, &entry->rxb);
  579. iwl_free_rxb(&entry->rxb);
  580. list_del(&entry->list);
  581. kfree(entry);
  582. }
  583. mutex_unlock(&mvm->mutex);
  584. }
  585. static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
  586. struct iwl_rx_packet *pkt)
  587. {
  588. struct iwl_fw_dbg_trigger_tlv *trig;
  589. struct iwl_fw_dbg_trigger_cmd *cmds_trig;
  590. int i;
  591. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF))
  592. return;
  593. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF);
  594. cmds_trig = (void *)trig->data;
  595. if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
  596. return;
  597. for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
  598. /* don't collect on CMD 0 */
  599. if (!cmds_trig->cmds[i].cmd_id)
  600. break;
  601. if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
  602. cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
  603. continue;
  604. iwl_mvm_fw_dbg_collect_trig(mvm, trig,
  605. "CMD 0x%02x.%02x received",
  606. pkt->hdr.group_id, pkt->hdr.cmd);
  607. break;
  608. }
  609. }
  610. static void iwl_mvm_rx_dispatch(struct iwl_op_mode *op_mode,
  611. struct iwl_rx_cmd_buffer *rxb)
  612. {
  613. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  614. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  615. u8 i;
  616. if (likely(pkt->hdr.cmd == REPLY_RX_MPDU_CMD)) {
  617. iwl_mvm_rx_rx_mpdu(mvm, rxb);
  618. return;
  619. }
  620. iwl_mvm_rx_check_trigger(mvm, pkt);
  621. /*
  622. * Do the notification wait before RX handlers so
  623. * even if the RX handler consumes the RXB we have
  624. * access to it in the notification wait entry.
  625. */
  626. iwl_notification_wait_notify(&mvm->notif_wait, pkt);
  627. for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
  628. const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
  629. struct iwl_async_handler_entry *entry;
  630. if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
  631. continue;
  632. if (!rx_h->async) {
  633. rx_h->fn(mvm, rxb);
  634. return;
  635. }
  636. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  637. /* we can't do much... */
  638. if (!entry)
  639. return;
  640. entry->rxb._page = rxb_steal_page(rxb);
  641. entry->rxb._offset = rxb->_offset;
  642. entry->rxb._rx_page_order = rxb->_rx_page_order;
  643. entry->fn = rx_h->fn;
  644. spin_lock(&mvm->async_handlers_lock);
  645. list_add_tail(&entry->list, &mvm->async_handlers_list);
  646. spin_unlock(&mvm->async_handlers_lock);
  647. schedule_work(&mvm->async_handlers_wk);
  648. break;
  649. }
  650. }
  651. static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  652. {
  653. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  654. int mq = mvm->queue_to_mac80211[queue];
  655. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  656. return;
  657. if (atomic_inc_return(&mvm->mac80211_queue_stop_count[mq]) > 1) {
  658. IWL_DEBUG_TX_QUEUES(mvm,
  659. "queue %d (mac80211 %d) already stopped\n",
  660. queue, mq);
  661. return;
  662. }
  663. ieee80211_stop_queue(mvm->hw, mq);
  664. }
  665. static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  666. {
  667. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  668. int mq = mvm->queue_to_mac80211[queue];
  669. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  670. return;
  671. if (atomic_dec_return(&mvm->mac80211_queue_stop_count[mq]) > 0) {
  672. IWL_DEBUG_TX_QUEUES(mvm,
  673. "queue %d (mac80211 %d) still stopped\n",
  674. queue, mq);
  675. return;
  676. }
  677. ieee80211_wake_queue(mvm->hw, mq);
  678. }
  679. void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
  680. {
  681. if (state)
  682. set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
  683. else
  684. clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
  685. wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm));
  686. }
  687. static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  688. {
  689. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  690. bool calibrating = ACCESS_ONCE(mvm->calibrating);
  691. if (state)
  692. set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  693. else
  694. clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  695. wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm));
  696. /* iwl_run_init_mvm_ucode is waiting for results, abort it */
  697. if (calibrating)
  698. iwl_abort_notification_waits(&mvm->notif_wait);
  699. /*
  700. * Stop the device if we run OPERATIONAL firmware or if we are in the
  701. * middle of the calibrations.
  702. */
  703. return state && (mvm->cur_ucode != IWL_UCODE_INIT || calibrating);
  704. }
  705. static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  706. {
  707. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  708. struct ieee80211_tx_info *info;
  709. info = IEEE80211_SKB_CB(skb);
  710. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  711. ieee80211_free_txskb(mvm->hw, skb);
  712. }
  713. struct iwl_mvm_reprobe {
  714. struct device *dev;
  715. struct work_struct work;
  716. };
  717. static void iwl_mvm_reprobe_wk(struct work_struct *wk)
  718. {
  719. struct iwl_mvm_reprobe *reprobe;
  720. reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
  721. if (device_reprobe(reprobe->dev))
  722. dev_err(reprobe->dev, "reprobe failed!\n");
  723. kfree(reprobe);
  724. module_put(THIS_MODULE);
  725. }
  726. static void iwl_mvm_fw_error_dump_wk(struct work_struct *work)
  727. {
  728. struct iwl_mvm *mvm =
  729. container_of(work, struct iwl_mvm, fw_dump_wk.work);
  730. if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_FW_DBG_COLLECT))
  731. return;
  732. mutex_lock(&mvm->mutex);
  733. /* stop recording */
  734. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  735. iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  736. } else {
  737. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
  738. /* wait before we collect the data till the DBGC stop */
  739. udelay(100);
  740. }
  741. iwl_mvm_fw_error_dump(mvm);
  742. /* start recording again if the firmware is not crashed */
  743. WARN_ON_ONCE((!test_bit(STATUS_FW_ERROR, &mvm->trans->status)) &&
  744. mvm->fw->dbg_dest_tlv &&
  745. iwl_mvm_start_fw_dbg_conf(mvm, mvm->fw_dbg_conf));
  746. mutex_unlock(&mvm->mutex);
  747. iwl_mvm_unref(mvm, IWL_MVM_REF_FW_DBG_COLLECT);
  748. }
  749. void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
  750. {
  751. iwl_abort_notification_waits(&mvm->notif_wait);
  752. /*
  753. * This is a bit racy, but worst case we tell mac80211 about
  754. * a stopped/aborted scan when that was already done which
  755. * is not a problem. It is necessary to abort any os scan
  756. * here because mac80211 requires having the scan cleared
  757. * before restarting.
  758. * We'll reset the scan_status to NONE in restart cleanup in
  759. * the next start() call from mac80211. If restart isn't called
  760. * (no fw restart) scan status will stay busy.
  761. */
  762. iwl_mvm_report_scan_aborted(mvm);
  763. /*
  764. * If we're restarting already, don't cycle restarts.
  765. * If INIT fw asserted, it will likely fail again.
  766. * If WoWLAN fw asserted, don't restart either, mac80211
  767. * can't recover this since we're already half suspended.
  768. */
  769. if (!mvm->restart_fw && fw_error) {
  770. iwl_mvm_fw_dbg_collect_desc(mvm, &iwl_mvm_dump_desc_assert, 0);
  771. } else if (test_and_set_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  772. &mvm->status)) {
  773. struct iwl_mvm_reprobe *reprobe;
  774. IWL_ERR(mvm,
  775. "Firmware error during reconfiguration - reprobe!\n");
  776. /*
  777. * get a module reference to avoid doing this while unloading
  778. * anyway and to avoid scheduling a work with code that's
  779. * being removed.
  780. */
  781. if (!try_module_get(THIS_MODULE)) {
  782. IWL_ERR(mvm, "Module is being unloaded - abort\n");
  783. return;
  784. }
  785. reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
  786. if (!reprobe) {
  787. module_put(THIS_MODULE);
  788. return;
  789. }
  790. reprobe->dev = mvm->trans->dev;
  791. INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
  792. schedule_work(&reprobe->work);
  793. } else if (mvm->cur_ucode == IWL_UCODE_REGULAR) {
  794. /* don't let the transport/FW power down */
  795. iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
  796. if (fw_error && mvm->restart_fw > 0)
  797. mvm->restart_fw--;
  798. ieee80211_restart_hw(mvm->hw);
  799. }
  800. }
  801. static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode)
  802. {
  803. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  804. iwl_mvm_dump_nic_error_log(mvm);
  805. iwl_mvm_nic_restart(mvm, true);
  806. }
  807. static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
  808. {
  809. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  810. WARN_ON(1);
  811. iwl_mvm_nic_restart(mvm, true);
  812. }
  813. struct iwl_d0i3_iter_data {
  814. struct iwl_mvm *mvm;
  815. u8 ap_sta_id;
  816. u8 vif_count;
  817. u8 offloading_tid;
  818. bool disable_offloading;
  819. };
  820. static bool iwl_mvm_disallow_offloading(struct iwl_mvm *mvm,
  821. struct ieee80211_vif *vif,
  822. struct iwl_d0i3_iter_data *iter_data)
  823. {
  824. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  825. struct ieee80211_sta *ap_sta;
  826. struct iwl_mvm_sta *mvmsta;
  827. u32 available_tids = 0;
  828. u8 tid;
  829. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION ||
  830. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
  831. return false;
  832. ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id]);
  833. if (IS_ERR_OR_NULL(ap_sta))
  834. return false;
  835. mvmsta = iwl_mvm_sta_from_mac80211(ap_sta);
  836. spin_lock_bh(&mvmsta->lock);
  837. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  838. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  839. /*
  840. * in case of pending tx packets, don't use this tid
  841. * for offloading in order to prevent reuse of the same
  842. * qos seq counters.
  843. */
  844. if (iwl_mvm_tid_queued(tid_data))
  845. continue;
  846. if (tid_data->state != IWL_AGG_OFF)
  847. continue;
  848. available_tids |= BIT(tid);
  849. }
  850. spin_unlock_bh(&mvmsta->lock);
  851. /*
  852. * disallow protocol offloading if we have no available tid
  853. * (with no pending frames and no active aggregation,
  854. * as we don't handle "holes" properly - the scheduler needs the
  855. * frame's seq number and TFD index to match)
  856. */
  857. if (!available_tids)
  858. return true;
  859. /* for simplicity, just use the first available tid */
  860. iter_data->offloading_tid = ffs(available_tids) - 1;
  861. return false;
  862. }
  863. static void iwl_mvm_enter_d0i3_iterator(void *_data, u8 *mac,
  864. struct ieee80211_vif *vif)
  865. {
  866. struct iwl_d0i3_iter_data *data = _data;
  867. struct iwl_mvm *mvm = data->mvm;
  868. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  869. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
  870. IWL_DEBUG_RPM(mvm, "entering D0i3 - vif %pM\n", vif->addr);
  871. if (vif->type != NL80211_IFTYPE_STATION ||
  872. !vif->bss_conf.assoc)
  873. return;
  874. /*
  875. * in case of pending tx packets or active aggregations,
  876. * avoid offloading features in order to prevent reuse of
  877. * the same qos seq counters.
  878. */
  879. if (iwl_mvm_disallow_offloading(mvm, vif, data))
  880. data->disable_offloading = true;
  881. iwl_mvm_update_d0i3_power_mode(mvm, vif, true, flags);
  882. iwl_mvm_send_proto_offload(mvm, vif, data->disable_offloading, flags);
  883. /*
  884. * on init/association, mvm already configures POWER_TABLE_CMD
  885. * and REPLY_MCAST_FILTER_CMD, so currently don't
  886. * reconfigure them (we might want to use different
  887. * params later on, though).
  888. */
  889. data->ap_sta_id = mvmvif->ap_sta_id;
  890. data->vif_count++;
  891. }
  892. static void iwl_mvm_set_wowlan_data(struct iwl_mvm *mvm,
  893. struct iwl_wowlan_config_cmd *cmd,
  894. struct iwl_d0i3_iter_data *iter_data)
  895. {
  896. struct ieee80211_sta *ap_sta;
  897. struct iwl_mvm_sta *mvm_ap_sta;
  898. if (iter_data->ap_sta_id == IWL_MVM_STATION_COUNT)
  899. return;
  900. rcu_read_lock();
  901. ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[iter_data->ap_sta_id]);
  902. if (IS_ERR_OR_NULL(ap_sta))
  903. goto out;
  904. mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
  905. cmd->is_11n_connection = ap_sta->ht_cap.ht_supported;
  906. cmd->offloading_tid = iter_data->offloading_tid;
  907. /*
  908. * The d0i3 uCode takes care of the nonqos counters,
  909. * so configure only the qos seq ones.
  910. */
  911. iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, cmd);
  912. out:
  913. rcu_read_unlock();
  914. }
  915. int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode)
  916. {
  917. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  918. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
  919. int ret;
  920. struct iwl_d0i3_iter_data d0i3_iter_data = {
  921. .mvm = mvm,
  922. };
  923. struct iwl_wowlan_config_cmd wowlan_config_cmd = {
  924. .wakeup_filter = cpu_to_le32(IWL_WOWLAN_WAKEUP_RX_FRAME |
  925. IWL_WOWLAN_WAKEUP_BEACON_MISS |
  926. IWL_WOWLAN_WAKEUP_LINK_CHANGE |
  927. IWL_WOWLAN_WAKEUP_BCN_FILTERING),
  928. };
  929. struct iwl_d3_manager_config d3_cfg_cmd = {
  930. .min_sleep_time = cpu_to_le32(1000),
  931. .wakeup_flags = cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR),
  932. };
  933. IWL_DEBUG_RPM(mvm, "MVM entering D0i3\n");
  934. /* make sure we have no running tx while configuring the qos */
  935. set_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  936. synchronize_net();
  937. /*
  938. * iwl_mvm_ref_sync takes a reference before checking the flag.
  939. * so by checking there is no held reference we prevent a state
  940. * in which iwl_mvm_ref_sync continues successfully while we
  941. * configure the firmware to enter d0i3
  942. */
  943. if (iwl_mvm_ref_taken(mvm)) {
  944. IWL_DEBUG_RPM(mvm->trans, "abort d0i3 due to taken ref\n");
  945. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  946. wake_up(&mvm->d0i3_exit_waitq);
  947. return 1;
  948. }
  949. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  950. IEEE80211_IFACE_ITER_NORMAL,
  951. iwl_mvm_enter_d0i3_iterator,
  952. &d0i3_iter_data);
  953. if (d0i3_iter_data.vif_count == 1) {
  954. mvm->d0i3_ap_sta_id = d0i3_iter_data.ap_sta_id;
  955. mvm->d0i3_offloading = !d0i3_iter_data.disable_offloading;
  956. } else {
  957. WARN_ON_ONCE(d0i3_iter_data.vif_count > 1);
  958. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  959. mvm->d0i3_offloading = false;
  960. }
  961. iwl_mvm_set_wowlan_data(mvm, &wowlan_config_cmd, &d0i3_iter_data);
  962. ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, flags,
  963. sizeof(wowlan_config_cmd),
  964. &wowlan_config_cmd);
  965. if (ret)
  966. return ret;
  967. return iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD,
  968. flags | CMD_MAKE_TRANS_IDLE,
  969. sizeof(d3_cfg_cmd), &d3_cfg_cmd);
  970. }
  971. static void iwl_mvm_exit_d0i3_iterator(void *_data, u8 *mac,
  972. struct ieee80211_vif *vif)
  973. {
  974. struct iwl_mvm *mvm = _data;
  975. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO;
  976. IWL_DEBUG_RPM(mvm, "exiting D0i3 - vif %pM\n", vif->addr);
  977. if (vif->type != NL80211_IFTYPE_STATION ||
  978. !vif->bss_conf.assoc)
  979. return;
  980. iwl_mvm_update_d0i3_power_mode(mvm, vif, false, flags);
  981. }
  982. static void iwl_mvm_d0i3_disconnect_iter(void *data, u8 *mac,
  983. struct ieee80211_vif *vif)
  984. {
  985. struct iwl_mvm *mvm = data;
  986. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  987. if (vif->type == NL80211_IFTYPE_STATION && vif->bss_conf.assoc &&
  988. mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
  989. iwl_mvm_connection_loss(mvm, vif, "D0i3");
  990. }
  991. void iwl_mvm_d0i3_enable_tx(struct iwl_mvm *mvm, __le16 *qos_seq)
  992. {
  993. struct ieee80211_sta *sta = NULL;
  994. struct iwl_mvm_sta *mvm_ap_sta;
  995. int i;
  996. bool wake_queues = false;
  997. lockdep_assert_held(&mvm->mutex);
  998. spin_lock_bh(&mvm->d0i3_tx_lock);
  999. if (mvm->d0i3_ap_sta_id == IWL_MVM_STATION_COUNT)
  1000. goto out;
  1001. IWL_DEBUG_RPM(mvm, "re-enqueue packets\n");
  1002. /* get the sta in order to update seq numbers and re-enqueue skbs */
  1003. sta = rcu_dereference_protected(
  1004. mvm->fw_id_to_mac_id[mvm->d0i3_ap_sta_id],
  1005. lockdep_is_held(&mvm->mutex));
  1006. if (IS_ERR_OR_NULL(sta)) {
  1007. sta = NULL;
  1008. goto out;
  1009. }
  1010. if (mvm->d0i3_offloading && qos_seq) {
  1011. /* update qos seq numbers if offloading was enabled */
  1012. mvm_ap_sta = iwl_mvm_sta_from_mac80211(sta);
  1013. for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
  1014. u16 seq = le16_to_cpu(qos_seq[i]);
  1015. /* firmware stores last-used one, we store next one */
  1016. seq += 0x10;
  1017. mvm_ap_sta->tid_data[i].seq_number = seq;
  1018. }
  1019. }
  1020. out:
  1021. /* re-enqueue (or drop) all packets */
  1022. while (!skb_queue_empty(&mvm->d0i3_tx)) {
  1023. struct sk_buff *skb = __skb_dequeue(&mvm->d0i3_tx);
  1024. if (!sta || iwl_mvm_tx_skb(mvm, skb, sta))
  1025. ieee80211_free_txskb(mvm->hw, skb);
  1026. /* if the skb_queue is not empty, we need to wake queues */
  1027. wake_queues = true;
  1028. }
  1029. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  1030. wake_up(&mvm->d0i3_exit_waitq);
  1031. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  1032. if (wake_queues)
  1033. ieee80211_wake_queues(mvm->hw);
  1034. spin_unlock_bh(&mvm->d0i3_tx_lock);
  1035. }
  1036. static void iwl_mvm_d0i3_exit_work(struct work_struct *wk)
  1037. {
  1038. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, d0i3_exit_work);
  1039. struct iwl_host_cmd get_status_cmd = {
  1040. .id = WOWLAN_GET_STATUSES,
  1041. .flags = CMD_HIGH_PRIO | CMD_WANT_SKB,
  1042. };
  1043. struct iwl_wowlan_status *status;
  1044. int ret;
  1045. u32 disconnection_reasons, wakeup_reasons;
  1046. __le16 *qos_seq = NULL;
  1047. mutex_lock(&mvm->mutex);
  1048. ret = iwl_mvm_send_cmd(mvm, &get_status_cmd);
  1049. if (ret)
  1050. goto out;
  1051. if (!get_status_cmd.resp_pkt)
  1052. goto out;
  1053. status = (void *)get_status_cmd.resp_pkt->data;
  1054. wakeup_reasons = le32_to_cpu(status->wakeup_reasons);
  1055. qos_seq = status->qos_seq_ctr;
  1056. IWL_DEBUG_RPM(mvm, "wakeup reasons: 0x%x\n", wakeup_reasons);
  1057. disconnection_reasons =
  1058. IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
  1059. IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH;
  1060. if (wakeup_reasons & disconnection_reasons)
  1061. ieee80211_iterate_active_interfaces(
  1062. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1063. iwl_mvm_d0i3_disconnect_iter, mvm);
  1064. out:
  1065. iwl_mvm_d0i3_enable_tx(mvm, qos_seq);
  1066. /* qos_seq might point inside resp_pkt, so free it only now */
  1067. if (get_status_cmd.resp_pkt)
  1068. iwl_free_resp(&get_status_cmd);
  1069. /* the FW might have updated the regdomain */
  1070. iwl_mvm_update_changed_regdom(mvm);
  1071. iwl_mvm_unref(mvm, IWL_MVM_REF_EXIT_WORK);
  1072. mutex_unlock(&mvm->mutex);
  1073. }
  1074. int _iwl_mvm_exit_d0i3(struct iwl_mvm *mvm)
  1075. {
  1076. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE |
  1077. CMD_WAKE_UP_TRANS;
  1078. int ret;
  1079. IWL_DEBUG_RPM(mvm, "MVM exiting D0i3\n");
  1080. mutex_lock(&mvm->d0i3_suspend_mutex);
  1081. if (test_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags)) {
  1082. IWL_DEBUG_RPM(mvm, "Deferring d0i3 exit until resume\n");
  1083. __set_bit(D0I3_PENDING_WAKEUP, &mvm->d0i3_suspend_flags);
  1084. mutex_unlock(&mvm->d0i3_suspend_mutex);
  1085. return 0;
  1086. }
  1087. mutex_unlock(&mvm->d0i3_suspend_mutex);
  1088. ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, flags, 0, NULL);
  1089. if (ret)
  1090. goto out;
  1091. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  1092. IEEE80211_IFACE_ITER_NORMAL,
  1093. iwl_mvm_exit_d0i3_iterator,
  1094. mvm);
  1095. out:
  1096. schedule_work(&mvm->d0i3_exit_work);
  1097. return ret;
  1098. }
  1099. int iwl_mvm_exit_d0i3(struct iwl_op_mode *op_mode)
  1100. {
  1101. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1102. iwl_mvm_ref(mvm, IWL_MVM_REF_EXIT_WORK);
  1103. return _iwl_mvm_exit_d0i3(mvm);
  1104. }
  1105. static void iwl_mvm_napi_add(struct iwl_op_mode *op_mode,
  1106. struct napi_struct *napi,
  1107. struct net_device *napi_dev,
  1108. int (*poll)(struct napi_struct *, int),
  1109. int weight)
  1110. {
  1111. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1112. netif_napi_add(napi_dev, napi, poll, weight);
  1113. mvm->napi = napi;
  1114. }
  1115. static const struct iwl_op_mode_ops iwl_mvm_ops = {
  1116. .start = iwl_op_mode_mvm_start,
  1117. .stop = iwl_op_mode_mvm_stop,
  1118. .rx = iwl_mvm_rx_dispatch,
  1119. .queue_full = iwl_mvm_stop_sw_queue,
  1120. .queue_not_full = iwl_mvm_wake_sw_queue,
  1121. .hw_rf_kill = iwl_mvm_set_hw_rfkill_state,
  1122. .free_skb = iwl_mvm_free_skb,
  1123. .nic_error = iwl_mvm_nic_error,
  1124. .cmd_queue_full = iwl_mvm_cmd_queue_full,
  1125. .nic_config = iwl_mvm_nic_config,
  1126. .enter_d0i3 = iwl_mvm_enter_d0i3,
  1127. .exit_d0i3 = iwl_mvm_exit_d0i3,
  1128. .napi_add = iwl_mvm_napi_add,
  1129. };