ops.c 50 KB

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