ops.c 46 KB

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