ops.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  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_PM_NOTIF),
  414. HCMD_NAME(MU_GROUP_MGMT_NOTIF),
  415. HCMD_NAME(RX_QUEUES_NOTIFICATION),
  416. };
  417. /* Please keep this array *SORTED* by hex value.
  418. * Access is done through binary search
  419. */
  420. static const struct iwl_hcmd_names iwl_mvm_debug_names[] = {
  421. HCMD_NAME(MFU_ASSERT_DUMP_NTF),
  422. };
  423. /* Please keep this array *SORTED* by hex value.
  424. * Access is done through binary search
  425. */
  426. static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = {
  427. HCMD_NAME(STORED_BEACON_NTF),
  428. };
  429. /* Please keep this array *SORTED* by hex value.
  430. * Access is done through binary search
  431. */
  432. static const struct iwl_hcmd_names iwl_mvm_regulatory_and_nvm_names[] = {
  433. HCMD_NAME(NVM_ACCESS_COMPLETE),
  434. HCMD_NAME(NVM_GET_INFO),
  435. };
  436. static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
  437. [LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
  438. [LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
  439. [SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),
  440. [MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names),
  441. [PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),
  442. [DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names),
  443. [PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names),
  444. [REGULATORY_AND_NVM_GROUP] =
  445. HCMD_ARR(iwl_mvm_regulatory_and_nvm_names),
  446. };
  447. /* this forward declaration can avoid to export the function */
  448. static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
  449. static void iwl_mvm_d0i3_exit_work(struct work_struct *wk);
  450. static u32 iwl_mvm_min_backoff(struct iwl_mvm *mvm)
  451. {
  452. const struct iwl_pwr_tx_backoff *backoff = mvm->cfg->pwr_tx_backoffs;
  453. u64 dflt_pwr_limit;
  454. if (!backoff)
  455. return 0;
  456. dflt_pwr_limit = iwl_acpi_get_pwr_limit(mvm->dev);
  457. while (backoff->pwr) {
  458. if (dflt_pwr_limit >= backoff->pwr)
  459. return backoff->backoff;
  460. backoff++;
  461. }
  462. return 0;
  463. }
  464. static void iwl_mvm_tx_unblock_dwork(struct work_struct *work)
  465. {
  466. struct iwl_mvm *mvm =
  467. container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work);
  468. struct ieee80211_vif *tx_blocked_vif;
  469. struct iwl_mvm_vif *mvmvif;
  470. mutex_lock(&mvm->mutex);
  471. tx_blocked_vif =
  472. rcu_dereference_protected(mvm->csa_tx_blocked_vif,
  473. lockdep_is_held(&mvm->mutex));
  474. if (!tx_blocked_vif)
  475. goto unlock;
  476. mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif);
  477. iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
  478. RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
  479. unlock:
  480. mutex_unlock(&mvm->mutex);
  481. }
  482. static int iwl_mvm_fwrt_dump_start(void *ctx)
  483. {
  484. struct iwl_mvm *mvm = ctx;
  485. int ret;
  486. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_FW_DBG_COLLECT);
  487. if (ret)
  488. return ret;
  489. mutex_lock(&mvm->mutex);
  490. return 0;
  491. }
  492. static void iwl_mvm_fwrt_dump_end(void *ctx)
  493. {
  494. struct iwl_mvm *mvm = ctx;
  495. mutex_unlock(&mvm->mutex);
  496. iwl_mvm_unref(mvm, IWL_MVM_REF_FW_DBG_COLLECT);
  497. }
  498. static bool iwl_mvm_fwrt_fw_running(void *ctx)
  499. {
  500. return iwl_mvm_firmware_running(ctx);
  501. }
  502. static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {
  503. .dump_start = iwl_mvm_fwrt_dump_start,
  504. .dump_end = iwl_mvm_fwrt_dump_end,
  505. .fw_running = iwl_mvm_fwrt_fw_running,
  506. };
  507. static struct iwl_op_mode *
  508. iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  509. const struct iwl_fw *fw, struct dentry *dbgfs_dir)
  510. {
  511. struct ieee80211_hw *hw;
  512. struct iwl_op_mode *op_mode;
  513. struct iwl_mvm *mvm;
  514. struct iwl_trans_config trans_cfg = {};
  515. static const u8 no_reclaim_cmds[] = {
  516. TX_CMD,
  517. };
  518. int err, scan_size;
  519. u32 min_backoff;
  520. /*
  521. * We use IWL_MVM_STATION_COUNT to check the validity of the station
  522. * index all over the driver - check that its value corresponds to the
  523. * array size.
  524. */
  525. BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) != IWL_MVM_STATION_COUNT);
  526. /********************************
  527. * 1. Allocating and configuring HW data
  528. ********************************/
  529. hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
  530. sizeof(struct iwl_mvm),
  531. &iwl_mvm_hw_ops);
  532. if (!hw)
  533. return NULL;
  534. if (cfg->max_rx_agg_size)
  535. hw->max_rx_aggregation_subframes = cfg->max_rx_agg_size;
  536. if (cfg->max_tx_agg_size)
  537. hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
  538. op_mode = hw->priv;
  539. mvm = IWL_OP_MODE_GET_MVM(op_mode);
  540. mvm->dev = trans->dev;
  541. mvm->trans = trans;
  542. mvm->cfg = cfg;
  543. mvm->fw = fw;
  544. mvm->hw = hw;
  545. iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm,
  546. dbgfs_dir);
  547. mvm->init_status = 0;
  548. if (iwl_mvm_has_new_rx_api(mvm)) {
  549. op_mode->ops = &iwl_mvm_ops_mq;
  550. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_desc);
  551. } else {
  552. op_mode->ops = &iwl_mvm_ops;
  553. trans->rx_mpdu_cmd_hdr_size =
  554. sizeof(struct iwl_rx_mpdu_res_start);
  555. if (WARN_ON(trans->num_rx_queues > 1))
  556. goto out_free;
  557. }
  558. mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0;
  559. mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE;
  560. mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE;
  561. mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
  562. mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
  563. mvm->sf_state = SF_UNINIT;
  564. if (iwl_mvm_has_unified_ucode(mvm))
  565. iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR);
  566. else
  567. iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT);
  568. mvm->drop_bcn_ap_mode = true;
  569. mutex_init(&mvm->mutex);
  570. mutex_init(&mvm->d0i3_suspend_mutex);
  571. spin_lock_init(&mvm->async_handlers_lock);
  572. INIT_LIST_HEAD(&mvm->time_event_list);
  573. INIT_LIST_HEAD(&mvm->aux_roc_te_list);
  574. INIT_LIST_HEAD(&mvm->async_handlers_list);
  575. spin_lock_init(&mvm->time_event_lock);
  576. spin_lock_init(&mvm->queue_info_lock);
  577. INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
  578. INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
  579. INIT_WORK(&mvm->d0i3_exit_work, iwl_mvm_d0i3_exit_work);
  580. INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
  581. INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk);
  582. INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);
  583. spin_lock_init(&mvm->d0i3_tx_lock);
  584. spin_lock_init(&mvm->refs_lock);
  585. skb_queue_head_init(&mvm->d0i3_tx);
  586. init_waitqueue_head(&mvm->d0i3_exit_waitq);
  587. init_waitqueue_head(&mvm->rx_sync_waitq);
  588. atomic_set(&mvm->queue_sync_counter, 0);
  589. SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
  590. spin_lock_init(&mvm->tcm.lock);
  591. INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work);
  592. mvm->tcm.ts = jiffies;
  593. mvm->tcm.ll_ts = jiffies;
  594. mvm->tcm.uapsd_nonagg_ts = jiffies;
  595. INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);
  596. /*
  597. * Populate the state variables that the transport layer needs
  598. * to know about.
  599. */
  600. trans_cfg.op_mode = op_mode;
  601. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  602. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  603. switch (iwlwifi_mod_params.amsdu_size) {
  604. case IWL_AMSDU_DEF:
  605. case IWL_AMSDU_4K:
  606. trans_cfg.rx_buf_size = IWL_AMSDU_4K;
  607. break;
  608. case IWL_AMSDU_8K:
  609. trans_cfg.rx_buf_size = IWL_AMSDU_8K;
  610. break;
  611. case IWL_AMSDU_12K:
  612. trans_cfg.rx_buf_size = IWL_AMSDU_12K;
  613. break;
  614. default:
  615. pr_err("%s: Unsupported amsdu_size: %d\n", KBUILD_MODNAME,
  616. iwlwifi_mod_params.amsdu_size);
  617. trans_cfg.rx_buf_size = IWL_AMSDU_4K;
  618. }
  619. /* the hardware splits the A-MSDU */
  620. if (mvm->cfg->mq_rx_supported)
  621. trans_cfg.rx_buf_size = IWL_AMSDU_4K;
  622. trans->wide_cmd_header = true;
  623. trans_cfg.bc_table_dword = true;
  624. trans_cfg.command_groups = iwl_mvm_groups;
  625. trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
  626. trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;
  627. trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
  628. trans_cfg.scd_set_active = true;
  629. trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
  630. driver_data[2]);
  631. trans_cfg.sw_csum_tx = IWL_MVM_SW_TX_CSUM_OFFLOAD;
  632. /* Set a short watchdog for the command queue */
  633. trans_cfg.cmd_q_wdg_timeout =
  634. iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
  635. snprintf(mvm->hw->wiphy->fw_version,
  636. sizeof(mvm->hw->wiphy->fw_version),
  637. "%s", fw->fw_version);
  638. /* Configure transport layer */
  639. iwl_trans_configure(mvm->trans, &trans_cfg);
  640. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  641. trans->dbg_dest_tlv = mvm->fw->dbg_dest_tlv;
  642. trans->dbg_dest_reg_num = mvm->fw->dbg_dest_reg_num;
  643. memcpy(trans->dbg_conf_tlv, mvm->fw->dbg_conf_tlv,
  644. sizeof(trans->dbg_conf_tlv));
  645. trans->dbg_trigger_tlv = mvm->fw->dbg_trigger_tlv;
  646. trans->iml = mvm->fw->iml;
  647. trans->iml_len = mvm->fw->iml_len;
  648. /* set up notification wait support */
  649. iwl_notification_wait_init(&mvm->notif_wait);
  650. /* Init phy db */
  651. mvm->phy_db = iwl_phy_db_init(trans);
  652. if (!mvm->phy_db) {
  653. IWL_ERR(mvm, "Cannot init phy_db\n");
  654. goto out_free;
  655. }
  656. IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
  657. mvm->cfg->name, mvm->trans->hw_rev);
  658. if (iwlwifi_mod_params.nvm_file)
  659. mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
  660. else
  661. IWL_DEBUG_EEPROM(mvm->trans->dev,
  662. "working without external nvm file\n");
  663. err = iwl_trans_start_hw(mvm->trans);
  664. if (err)
  665. goto out_free;
  666. mutex_lock(&mvm->mutex);
  667. iwl_mvm_ref(mvm, IWL_MVM_REF_INIT_UCODE);
  668. err = iwl_run_init_mvm_ucode(mvm, true);
  669. if (!iwlmvm_mod_params.init_dbg || !err)
  670. iwl_mvm_stop_device(mvm);
  671. iwl_mvm_unref(mvm, IWL_MVM_REF_INIT_UCODE);
  672. mutex_unlock(&mvm->mutex);
  673. if (err < 0) {
  674. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", err);
  675. goto out_free;
  676. }
  677. scan_size = iwl_mvm_scan_size(mvm);
  678. mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
  679. if (!mvm->scan_cmd)
  680. goto out_free;
  681. /* Set EBS as successful as long as not stated otherwise by the FW. */
  682. mvm->last_ebs_successful = true;
  683. err = iwl_mvm_mac_setup_register(mvm);
  684. if (err)
  685. goto out_free;
  686. mvm->hw_registered = true;
  687. min_backoff = iwl_mvm_min_backoff(mvm);
  688. iwl_mvm_thermal_initialize(mvm, min_backoff);
  689. err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
  690. if (err)
  691. goto out_unregister;
  692. if (!iwl_mvm_has_new_rx_stats_api(mvm))
  693. memset(&mvm->rx_stats_v3, 0,
  694. sizeof(struct mvm_statistics_rx_v3));
  695. else
  696. memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
  697. /* The transport always starts with a taken reference, we can
  698. * release it now if d0i3 is supported */
  699. if (iwl_mvm_is_d0i3_supported(mvm))
  700. iwl_trans_unref(mvm->trans);
  701. iwl_mvm_tof_init(mvm);
  702. return op_mode;
  703. out_unregister:
  704. if (iwlmvm_mod_params.init_dbg)
  705. return op_mode;
  706. ieee80211_unregister_hw(mvm->hw);
  707. mvm->hw_registered = false;
  708. iwl_mvm_leds_exit(mvm);
  709. iwl_mvm_thermal_exit(mvm);
  710. out_free:
  711. iwl_fw_flush_dump(&mvm->fwrt);
  712. if (iwlmvm_mod_params.init_dbg)
  713. return op_mode;
  714. iwl_phy_db_free(mvm->phy_db);
  715. kfree(mvm->scan_cmd);
  716. iwl_trans_op_mode_leave(trans);
  717. ieee80211_free_hw(mvm->hw);
  718. return NULL;
  719. }
  720. static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
  721. {
  722. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  723. int i;
  724. /* If d0i3 is supported, we have released the reference that
  725. * the transport started with, so we should take it back now
  726. * that we are leaving.
  727. */
  728. if (iwl_mvm_is_d0i3_supported(mvm))
  729. iwl_trans_ref(mvm->trans);
  730. iwl_mvm_leds_exit(mvm);
  731. iwl_mvm_thermal_exit(mvm);
  732. if (mvm->init_status & IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE) {
  733. ieee80211_unregister_hw(mvm->hw);
  734. mvm->init_status &= ~IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
  735. }
  736. kfree(mvm->scan_cmd);
  737. kfree(mvm->mcast_filter_cmd);
  738. mvm->mcast_filter_cmd = NULL;
  739. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
  740. kfree(mvm->d3_resume_sram);
  741. #endif
  742. iwl_trans_op_mode_leave(mvm->trans);
  743. iwl_phy_db_free(mvm->phy_db);
  744. mvm->phy_db = NULL;
  745. kfree(mvm->nvm_data);
  746. for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
  747. kfree(mvm->nvm_sections[i].data);
  748. cancel_delayed_work_sync(&mvm->tcm.work);
  749. iwl_mvm_tof_clean(mvm);
  750. mutex_destroy(&mvm->mutex);
  751. mutex_destroy(&mvm->d0i3_suspend_mutex);
  752. ieee80211_free_hw(mvm->hw);
  753. }
  754. struct iwl_async_handler_entry {
  755. struct list_head list;
  756. struct iwl_rx_cmd_buffer rxb;
  757. enum iwl_rx_handler_context context;
  758. void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
  759. };
  760. void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
  761. {
  762. struct iwl_async_handler_entry *entry, *tmp;
  763. spin_lock_bh(&mvm->async_handlers_lock);
  764. list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
  765. iwl_free_rxb(&entry->rxb);
  766. list_del(&entry->list);
  767. kfree(entry);
  768. }
  769. spin_unlock_bh(&mvm->async_handlers_lock);
  770. }
  771. static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
  772. {
  773. struct iwl_mvm *mvm =
  774. container_of(wk, struct iwl_mvm, async_handlers_wk);
  775. struct iwl_async_handler_entry *entry, *tmp;
  776. LIST_HEAD(local_list);
  777. /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
  778. /*
  779. * Sync with Rx path with a lock. Remove all the entries from this list,
  780. * add them to a local one (lock free), and then handle them.
  781. */
  782. spin_lock_bh(&mvm->async_handlers_lock);
  783. list_splice_init(&mvm->async_handlers_list, &local_list);
  784. spin_unlock_bh(&mvm->async_handlers_lock);
  785. list_for_each_entry_safe(entry, tmp, &local_list, list) {
  786. if (entry->context == RX_HANDLER_ASYNC_LOCKED)
  787. mutex_lock(&mvm->mutex);
  788. entry->fn(mvm, &entry->rxb);
  789. iwl_free_rxb(&entry->rxb);
  790. list_del(&entry->list);
  791. if (entry->context == RX_HANDLER_ASYNC_LOCKED)
  792. mutex_unlock(&mvm->mutex);
  793. kfree(entry);
  794. }
  795. }
  796. static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
  797. struct iwl_rx_packet *pkt)
  798. {
  799. struct iwl_fw_dbg_trigger_tlv *trig;
  800. struct iwl_fw_dbg_trigger_cmd *cmds_trig;
  801. int i;
  802. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF))
  803. return;
  804. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF);
  805. cmds_trig = (void *)trig->data;
  806. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt, NULL, trig))
  807. return;
  808. for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
  809. /* don't collect on CMD 0 */
  810. if (!cmds_trig->cmds[i].cmd_id)
  811. break;
  812. if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
  813. cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
  814. continue;
  815. iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
  816. "CMD 0x%02x.%02x received",
  817. pkt->hdr.group_id, pkt->hdr.cmd);
  818. break;
  819. }
  820. }
  821. static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
  822. struct iwl_rx_cmd_buffer *rxb,
  823. struct iwl_rx_packet *pkt)
  824. {
  825. int i;
  826. iwl_mvm_rx_check_trigger(mvm, pkt);
  827. /*
  828. * Do the notification wait before RX handlers so
  829. * even if the RX handler consumes the RXB we have
  830. * access to it in the notification wait entry.
  831. */
  832. iwl_notification_wait_notify(&mvm->notif_wait, pkt);
  833. for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
  834. const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
  835. struct iwl_async_handler_entry *entry;
  836. if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
  837. continue;
  838. if (rx_h->context == RX_HANDLER_SYNC) {
  839. rx_h->fn(mvm, rxb);
  840. return;
  841. }
  842. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  843. /* we can't do much... */
  844. if (!entry)
  845. return;
  846. entry->rxb._page = rxb_steal_page(rxb);
  847. entry->rxb._offset = rxb->_offset;
  848. entry->rxb._rx_page_order = rxb->_rx_page_order;
  849. entry->fn = rx_h->fn;
  850. entry->context = rx_h->context;
  851. spin_lock(&mvm->async_handlers_lock);
  852. list_add_tail(&entry->list, &mvm->async_handlers_list);
  853. spin_unlock(&mvm->async_handlers_lock);
  854. schedule_work(&mvm->async_handlers_wk);
  855. return;
  856. }
  857. iwl_fwrt_handle_notification(&mvm->fwrt, rxb);
  858. }
  859. static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
  860. struct napi_struct *napi,
  861. struct iwl_rx_cmd_buffer *rxb)
  862. {
  863. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  864. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  865. u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
  866. if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
  867. iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
  868. else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD))
  869. iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
  870. else
  871. iwl_mvm_rx_common(mvm, rxb, pkt);
  872. }
  873. static void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
  874. struct napi_struct *napi,
  875. struct iwl_rx_cmd_buffer *rxb)
  876. {
  877. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  878. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  879. u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
  880. if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
  881. iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
  882. else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
  883. RX_QUEUES_NOTIFICATION)))
  884. iwl_mvm_rx_queue_notif(mvm, rxb, 0);
  885. else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))
  886. iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);
  887. else
  888. iwl_mvm_rx_common(mvm, rxb, pkt);
  889. }
  890. void iwl_mvm_stop_mac_queues(struct iwl_mvm *mvm, unsigned long mq)
  891. {
  892. int q;
  893. if (WARN_ON_ONCE(!mq))
  894. return;
  895. for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
  896. if (atomic_inc_return(&mvm->mac80211_queue_stop_count[q]) > 1) {
  897. IWL_DEBUG_TX_QUEUES(mvm,
  898. "mac80211 %d already stopped\n", q);
  899. continue;
  900. }
  901. ieee80211_stop_queue(mvm->hw, q);
  902. }
  903. }
  904. static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode,
  905. const struct iwl_device_cmd *cmd)
  906. {
  907. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  908. /*
  909. * For now, we only set the CMD_WANT_ASYNC_CALLBACK for ADD_STA
  910. * commands that need to block the Tx queues.
  911. */
  912. iwl_trans_block_txq_ptrs(mvm->trans, false);
  913. }
  914. static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
  915. {
  916. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  917. unsigned long mq;
  918. spin_lock_bh(&mvm->queue_info_lock);
  919. mq = mvm->hw_queue_to_mac80211[hw_queue];
  920. spin_unlock_bh(&mvm->queue_info_lock);
  921. iwl_mvm_stop_mac_queues(mvm, mq);
  922. }
  923. void iwl_mvm_start_mac_queues(struct iwl_mvm *mvm, unsigned long mq)
  924. {
  925. int q;
  926. if (WARN_ON_ONCE(!mq))
  927. return;
  928. for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
  929. if (atomic_dec_return(&mvm->mac80211_queue_stop_count[q]) > 0) {
  930. IWL_DEBUG_TX_QUEUES(mvm,
  931. "mac80211 %d still stopped\n", q);
  932. continue;
  933. }
  934. ieee80211_wake_queue(mvm->hw, q);
  935. }
  936. }
  937. static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
  938. {
  939. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  940. unsigned long mq;
  941. spin_lock_bh(&mvm->queue_info_lock);
  942. mq = mvm->hw_queue_to_mac80211[hw_queue];
  943. spin_unlock_bh(&mvm->queue_info_lock);
  944. iwl_mvm_start_mac_queues(mvm, mq);
  945. }
  946. static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm)
  947. {
  948. bool state = iwl_mvm_is_radio_killed(mvm);
  949. if (state)
  950. wake_up(&mvm->rx_sync_waitq);
  951. wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state);
  952. }
  953. void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
  954. {
  955. if (state)
  956. set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
  957. else
  958. clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
  959. iwl_mvm_set_rfkill_state(mvm);
  960. }
  961. static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  962. {
  963. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  964. bool calibrating = READ_ONCE(mvm->calibrating);
  965. if (state)
  966. set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  967. else
  968. clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
  969. iwl_mvm_set_rfkill_state(mvm);
  970. /* iwl_run_init_mvm_ucode is waiting for results, abort it */
  971. if (calibrating)
  972. iwl_abort_notification_waits(&mvm->notif_wait);
  973. /*
  974. * Stop the device if we run OPERATIONAL firmware or if we are in the
  975. * middle of the calibrations.
  976. */
  977. return state && (mvm->fwrt.cur_fw_img != IWL_UCODE_INIT || calibrating);
  978. }
  979. static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  980. {
  981. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  982. struct ieee80211_tx_info *info;
  983. info = IEEE80211_SKB_CB(skb);
  984. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  985. ieee80211_free_txskb(mvm->hw, skb);
  986. }
  987. struct iwl_mvm_reprobe {
  988. struct device *dev;
  989. struct work_struct work;
  990. };
  991. static void iwl_mvm_reprobe_wk(struct work_struct *wk)
  992. {
  993. struct iwl_mvm_reprobe *reprobe;
  994. reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
  995. if (device_reprobe(reprobe->dev))
  996. dev_err(reprobe->dev, "reprobe failed!\n");
  997. kfree(reprobe);
  998. module_put(THIS_MODULE);
  999. }
  1000. void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
  1001. {
  1002. iwl_abort_notification_waits(&mvm->notif_wait);
  1003. /*
  1004. * This is a bit racy, but worst case we tell mac80211 about
  1005. * a stopped/aborted scan when that was already done which
  1006. * is not a problem. It is necessary to abort any os scan
  1007. * here because mac80211 requires having the scan cleared
  1008. * before restarting.
  1009. * We'll reset the scan_status to NONE in restart cleanup in
  1010. * the next start() call from mac80211. If restart isn't called
  1011. * (no fw restart) scan status will stay busy.
  1012. */
  1013. iwl_mvm_report_scan_aborted(mvm);
  1014. /*
  1015. * If we're restarting already, don't cycle restarts.
  1016. * If INIT fw asserted, it will likely fail again.
  1017. * If WoWLAN fw asserted, don't restart either, mac80211
  1018. * can't recover this since we're already half suspended.
  1019. */
  1020. if (!mvm->fw_restart && fw_error) {
  1021. iwl_fw_dbg_collect_desc(&mvm->fwrt, &iwl_dump_desc_assert,
  1022. NULL);
  1023. } else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  1024. struct iwl_mvm_reprobe *reprobe;
  1025. IWL_ERR(mvm,
  1026. "Firmware error during reconfiguration - reprobe!\n");
  1027. /*
  1028. * get a module reference to avoid doing this while unloading
  1029. * anyway and to avoid scheduling a work with code that's
  1030. * being removed.
  1031. */
  1032. if (!try_module_get(THIS_MODULE)) {
  1033. IWL_ERR(mvm, "Module is being unloaded - abort\n");
  1034. return;
  1035. }
  1036. reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
  1037. if (!reprobe) {
  1038. module_put(THIS_MODULE);
  1039. return;
  1040. }
  1041. reprobe->dev = mvm->trans->dev;
  1042. INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
  1043. schedule_work(&reprobe->work);
  1044. } else if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR &&
  1045. mvm->hw_registered) {
  1046. /* don't let the transport/FW power down */
  1047. iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
  1048. if (fw_error && mvm->fw_restart > 0)
  1049. mvm->fw_restart--;
  1050. set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
  1051. ieee80211_restart_hw(mvm->hw);
  1052. }
  1053. }
  1054. static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode)
  1055. {
  1056. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1057. iwl_mvm_dump_nic_error_log(mvm);
  1058. iwl_mvm_nic_restart(mvm, true);
  1059. }
  1060. static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
  1061. {
  1062. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1063. WARN_ON(1);
  1064. iwl_mvm_nic_restart(mvm, true);
  1065. }
  1066. struct iwl_d0i3_iter_data {
  1067. struct iwl_mvm *mvm;
  1068. struct ieee80211_vif *connected_vif;
  1069. u8 ap_sta_id;
  1070. u8 vif_count;
  1071. u8 offloading_tid;
  1072. bool disable_offloading;
  1073. };
  1074. static bool iwl_mvm_disallow_offloading(struct iwl_mvm *mvm,
  1075. struct ieee80211_vif *vif,
  1076. struct iwl_d0i3_iter_data *iter_data)
  1077. {
  1078. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1079. struct iwl_mvm_sta *mvmsta;
  1080. u32 available_tids = 0;
  1081. u8 tid;
  1082. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION ||
  1083. mvmvif->ap_sta_id == IWL_MVM_INVALID_STA))
  1084. return false;
  1085. mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
  1086. if (!mvmsta)
  1087. return false;
  1088. spin_lock_bh(&mvmsta->lock);
  1089. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  1090. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  1091. /*
  1092. * in case of pending tx packets, don't use this tid
  1093. * for offloading in order to prevent reuse of the same
  1094. * qos seq counters.
  1095. */
  1096. if (iwl_mvm_tid_queued(mvm, tid_data))
  1097. continue;
  1098. if (tid_data->state != IWL_AGG_OFF)
  1099. continue;
  1100. available_tids |= BIT(tid);
  1101. }
  1102. spin_unlock_bh(&mvmsta->lock);
  1103. /*
  1104. * disallow protocol offloading if we have no available tid
  1105. * (with no pending frames and no active aggregation,
  1106. * as we don't handle "holes" properly - the scheduler needs the
  1107. * frame's seq number and TFD index to match)
  1108. */
  1109. if (!available_tids)
  1110. return true;
  1111. /* for simplicity, just use the first available tid */
  1112. iter_data->offloading_tid = ffs(available_tids) - 1;
  1113. return false;
  1114. }
  1115. static void iwl_mvm_enter_d0i3_iterator(void *_data, u8 *mac,
  1116. struct ieee80211_vif *vif)
  1117. {
  1118. struct iwl_d0i3_iter_data *data = _data;
  1119. struct iwl_mvm *mvm = data->mvm;
  1120. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1121. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
  1122. IWL_DEBUG_RPM(mvm, "entering D0i3 - vif %pM\n", vif->addr);
  1123. if (vif->type != NL80211_IFTYPE_STATION ||
  1124. !vif->bss_conf.assoc)
  1125. return;
  1126. /*
  1127. * in case of pending tx packets or active aggregations,
  1128. * avoid offloading features in order to prevent reuse of
  1129. * the same qos seq counters.
  1130. */
  1131. if (iwl_mvm_disallow_offloading(mvm, vif, data))
  1132. data->disable_offloading = true;
  1133. iwl_mvm_update_d0i3_power_mode(mvm, vif, true, flags);
  1134. iwl_mvm_send_proto_offload(mvm, vif, data->disable_offloading,
  1135. false, flags);
  1136. /*
  1137. * on init/association, mvm already configures POWER_TABLE_CMD
  1138. * and REPLY_MCAST_FILTER_CMD, so currently don't
  1139. * reconfigure them (we might want to use different
  1140. * params later on, though).
  1141. */
  1142. data->ap_sta_id = mvmvif->ap_sta_id;
  1143. data->vif_count++;
  1144. /*
  1145. * no new commands can be sent at this stage, so it's safe
  1146. * to save the vif pointer during d0i3 entrance.
  1147. */
  1148. data->connected_vif = vif;
  1149. }
  1150. static void iwl_mvm_set_wowlan_data(struct iwl_mvm *mvm,
  1151. struct iwl_wowlan_config_cmd *cmd,
  1152. struct iwl_d0i3_iter_data *iter_data)
  1153. {
  1154. struct ieee80211_sta *ap_sta;
  1155. struct iwl_mvm_sta *mvm_ap_sta;
  1156. if (iter_data->ap_sta_id == IWL_MVM_INVALID_STA)
  1157. return;
  1158. rcu_read_lock();
  1159. ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[iter_data->ap_sta_id]);
  1160. if (IS_ERR_OR_NULL(ap_sta))
  1161. goto out;
  1162. mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
  1163. cmd->is_11n_connection = ap_sta->ht_cap.ht_supported;
  1164. cmd->offloading_tid = iter_data->offloading_tid;
  1165. cmd->flags = ENABLE_L3_FILTERING | ENABLE_NBNS_FILTERING |
  1166. ENABLE_DHCP_FILTERING | ENABLE_STORE_BEACON;
  1167. /*
  1168. * The d0i3 uCode takes care of the nonqos counters,
  1169. * so configure only the qos seq ones.
  1170. */
  1171. iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, cmd);
  1172. out:
  1173. rcu_read_unlock();
  1174. }
  1175. int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode)
  1176. {
  1177. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1178. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE;
  1179. int ret;
  1180. struct iwl_d0i3_iter_data d0i3_iter_data = {
  1181. .mvm = mvm,
  1182. };
  1183. struct iwl_wowlan_config_cmd wowlan_config_cmd = {
  1184. .wakeup_filter = cpu_to_le32(IWL_WOWLAN_WAKEUP_RX_FRAME |
  1185. IWL_WOWLAN_WAKEUP_BEACON_MISS |
  1186. IWL_WOWLAN_WAKEUP_LINK_CHANGE),
  1187. };
  1188. struct iwl_d3_manager_config d3_cfg_cmd = {
  1189. .min_sleep_time = cpu_to_le32(1000),
  1190. .wakeup_flags = cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR),
  1191. };
  1192. IWL_DEBUG_RPM(mvm, "MVM entering D0i3\n");
  1193. if (WARN_ON_ONCE(mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR))
  1194. return -EINVAL;
  1195. set_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  1196. /*
  1197. * iwl_mvm_ref_sync takes a reference before checking the flag.
  1198. * so by checking there is no held reference we prevent a state
  1199. * in which iwl_mvm_ref_sync continues successfully while we
  1200. * configure the firmware to enter d0i3
  1201. */
  1202. if (iwl_mvm_ref_taken(mvm)) {
  1203. IWL_DEBUG_RPM(mvm->trans, "abort d0i3 due to taken ref\n");
  1204. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  1205. wake_up(&mvm->d0i3_exit_waitq);
  1206. return 1;
  1207. }
  1208. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  1209. IEEE80211_IFACE_ITER_NORMAL,
  1210. iwl_mvm_enter_d0i3_iterator,
  1211. &d0i3_iter_data);
  1212. if (d0i3_iter_data.vif_count == 1) {
  1213. mvm->d0i3_ap_sta_id = d0i3_iter_data.ap_sta_id;
  1214. mvm->d0i3_offloading = !d0i3_iter_data.disable_offloading;
  1215. } else {
  1216. WARN_ON_ONCE(d0i3_iter_data.vif_count > 1);
  1217. mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
  1218. mvm->d0i3_offloading = false;
  1219. }
  1220. iwl_mvm_pause_tcm(mvm, true);
  1221. /* make sure we have no running tx while configuring the seqno */
  1222. synchronize_net();
  1223. /* Flush the hw queues, in case something got queued during entry */
  1224. /* TODO new tx api */
  1225. if (iwl_mvm_has_new_tx_api(mvm)) {
  1226. WARN_ONCE(1, "d0i3: Need to implement flush TX queue\n");
  1227. } else {
  1228. ret = iwl_mvm_flush_tx_path(mvm, iwl_mvm_flushable_queues(mvm),
  1229. flags);
  1230. if (ret)
  1231. return ret;
  1232. }
  1233. /* configure wowlan configuration only if needed */
  1234. if (mvm->d0i3_ap_sta_id != IWL_MVM_INVALID_STA) {
  1235. /* wake on beacons only if beacon storing isn't supported */
  1236. if (!fw_has_capa(&mvm->fw->ucode_capa,
  1237. IWL_UCODE_TLV_CAPA_BEACON_STORING))
  1238. wowlan_config_cmd.wakeup_filter |=
  1239. cpu_to_le32(IWL_WOWLAN_WAKEUP_BCN_FILTERING);
  1240. iwl_mvm_wowlan_config_key_params(mvm,
  1241. d0i3_iter_data.connected_vif,
  1242. true, flags);
  1243. iwl_mvm_set_wowlan_data(mvm, &wowlan_config_cmd,
  1244. &d0i3_iter_data);
  1245. ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, flags,
  1246. sizeof(wowlan_config_cmd),
  1247. &wowlan_config_cmd);
  1248. if (ret)
  1249. return ret;
  1250. }
  1251. return iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD,
  1252. flags | CMD_MAKE_TRANS_IDLE,
  1253. sizeof(d3_cfg_cmd), &d3_cfg_cmd);
  1254. }
  1255. static void iwl_mvm_exit_d0i3_iterator(void *_data, u8 *mac,
  1256. struct ieee80211_vif *vif)
  1257. {
  1258. struct iwl_mvm *mvm = _data;
  1259. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO;
  1260. IWL_DEBUG_RPM(mvm, "exiting D0i3 - vif %pM\n", vif->addr);
  1261. if (vif->type != NL80211_IFTYPE_STATION ||
  1262. !vif->bss_conf.assoc)
  1263. return;
  1264. iwl_mvm_update_d0i3_power_mode(mvm, vif, false, flags);
  1265. }
  1266. struct iwl_mvm_d0i3_exit_work_iter_data {
  1267. struct iwl_mvm *mvm;
  1268. struct iwl_wowlan_status *status;
  1269. u32 wakeup_reasons;
  1270. };
  1271. static void iwl_mvm_d0i3_exit_work_iter(void *_data, u8 *mac,
  1272. struct ieee80211_vif *vif)
  1273. {
  1274. struct iwl_mvm_d0i3_exit_work_iter_data *data = _data;
  1275. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1276. u32 reasons = data->wakeup_reasons;
  1277. /* consider only the relevant station interface */
  1278. if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
  1279. data->mvm->d0i3_ap_sta_id != mvmvif->ap_sta_id)
  1280. return;
  1281. if (reasons & IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH)
  1282. iwl_mvm_connection_loss(data->mvm, vif, "D0i3");
  1283. else if (reasons & IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON)
  1284. ieee80211_beacon_loss(vif);
  1285. else
  1286. iwl_mvm_d0i3_update_keys(data->mvm, vif, data->status);
  1287. }
  1288. void iwl_mvm_d0i3_enable_tx(struct iwl_mvm *mvm, __le16 *qos_seq)
  1289. {
  1290. struct ieee80211_sta *sta = NULL;
  1291. struct iwl_mvm_sta *mvm_ap_sta;
  1292. int i;
  1293. bool wake_queues = false;
  1294. lockdep_assert_held(&mvm->mutex);
  1295. spin_lock_bh(&mvm->d0i3_tx_lock);
  1296. if (mvm->d0i3_ap_sta_id == IWL_MVM_INVALID_STA)
  1297. goto out;
  1298. IWL_DEBUG_RPM(mvm, "re-enqueue packets\n");
  1299. /* get the sta in order to update seq numbers and re-enqueue skbs */
  1300. sta = rcu_dereference_protected(
  1301. mvm->fw_id_to_mac_id[mvm->d0i3_ap_sta_id],
  1302. lockdep_is_held(&mvm->mutex));
  1303. if (IS_ERR_OR_NULL(sta)) {
  1304. sta = NULL;
  1305. goto out;
  1306. }
  1307. if (mvm->d0i3_offloading && qos_seq) {
  1308. /* update qos seq numbers if offloading was enabled */
  1309. mvm_ap_sta = iwl_mvm_sta_from_mac80211(sta);
  1310. for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
  1311. u16 seq = le16_to_cpu(qos_seq[i]);
  1312. /* firmware stores last-used one, we store next one */
  1313. seq += 0x10;
  1314. mvm_ap_sta->tid_data[i].seq_number = seq;
  1315. }
  1316. }
  1317. out:
  1318. /* re-enqueue (or drop) all packets */
  1319. while (!skb_queue_empty(&mvm->d0i3_tx)) {
  1320. struct sk_buff *skb = __skb_dequeue(&mvm->d0i3_tx);
  1321. if (!sta || iwl_mvm_tx_skb(mvm, skb, sta))
  1322. ieee80211_free_txskb(mvm->hw, skb);
  1323. /* if the skb_queue is not empty, we need to wake queues */
  1324. wake_queues = true;
  1325. }
  1326. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  1327. wake_up(&mvm->d0i3_exit_waitq);
  1328. mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
  1329. if (wake_queues)
  1330. ieee80211_wake_queues(mvm->hw);
  1331. spin_unlock_bh(&mvm->d0i3_tx_lock);
  1332. }
  1333. static void iwl_mvm_d0i3_exit_work(struct work_struct *wk)
  1334. {
  1335. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, d0i3_exit_work);
  1336. struct iwl_host_cmd get_status_cmd = {
  1337. .id = WOWLAN_GET_STATUSES,
  1338. .flags = CMD_HIGH_PRIO | CMD_WANT_SKB,
  1339. };
  1340. struct iwl_mvm_d0i3_exit_work_iter_data iter_data = {
  1341. .mvm = mvm,
  1342. };
  1343. struct iwl_wowlan_status *status;
  1344. int ret;
  1345. u32 wakeup_reasons = 0;
  1346. __le16 *qos_seq = NULL;
  1347. mutex_lock(&mvm->mutex);
  1348. ret = iwl_mvm_send_cmd(mvm, &get_status_cmd);
  1349. if (ret)
  1350. goto out;
  1351. status = (void *)get_status_cmd.resp_pkt->data;
  1352. wakeup_reasons = le32_to_cpu(status->wakeup_reasons);
  1353. qos_seq = status->qos_seq_ctr;
  1354. IWL_DEBUG_RPM(mvm, "wakeup reasons: 0x%x\n", wakeup_reasons);
  1355. iter_data.wakeup_reasons = wakeup_reasons;
  1356. iter_data.status = status;
  1357. ieee80211_iterate_active_interfaces(mvm->hw,
  1358. IEEE80211_IFACE_ITER_NORMAL,
  1359. iwl_mvm_d0i3_exit_work_iter,
  1360. &iter_data);
  1361. out:
  1362. iwl_mvm_d0i3_enable_tx(mvm, qos_seq);
  1363. IWL_DEBUG_INFO(mvm, "d0i3 exit completed (wakeup reasons: 0x%x)\n",
  1364. wakeup_reasons);
  1365. /* qos_seq might point inside resp_pkt, so free it only now */
  1366. if (get_status_cmd.resp_pkt)
  1367. iwl_free_resp(&get_status_cmd);
  1368. /* the FW might have updated the regdomain */
  1369. iwl_mvm_update_changed_regdom(mvm);
  1370. iwl_mvm_resume_tcm(mvm);
  1371. iwl_mvm_unref(mvm, IWL_MVM_REF_EXIT_WORK);
  1372. mutex_unlock(&mvm->mutex);
  1373. }
  1374. int _iwl_mvm_exit_d0i3(struct iwl_mvm *mvm)
  1375. {
  1376. u32 flags = CMD_ASYNC | CMD_HIGH_PRIO | CMD_SEND_IN_IDLE |
  1377. CMD_WAKE_UP_TRANS;
  1378. int ret;
  1379. IWL_DEBUG_RPM(mvm, "MVM exiting D0i3\n");
  1380. if (WARN_ON_ONCE(mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR))
  1381. return -EINVAL;
  1382. mutex_lock(&mvm->d0i3_suspend_mutex);
  1383. if (test_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags)) {
  1384. IWL_DEBUG_RPM(mvm, "Deferring d0i3 exit until resume\n");
  1385. __set_bit(D0I3_PENDING_WAKEUP, &mvm->d0i3_suspend_flags);
  1386. mutex_unlock(&mvm->d0i3_suspend_mutex);
  1387. return 0;
  1388. }
  1389. mutex_unlock(&mvm->d0i3_suspend_mutex);
  1390. ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, flags, 0, NULL);
  1391. if (ret)
  1392. goto out;
  1393. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  1394. IEEE80211_IFACE_ITER_NORMAL,
  1395. iwl_mvm_exit_d0i3_iterator,
  1396. mvm);
  1397. out:
  1398. schedule_work(&mvm->d0i3_exit_work);
  1399. return ret;
  1400. }
  1401. int iwl_mvm_exit_d0i3(struct iwl_op_mode *op_mode)
  1402. {
  1403. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1404. iwl_mvm_ref(mvm, IWL_MVM_REF_EXIT_WORK);
  1405. return _iwl_mvm_exit_d0i3(mvm);
  1406. }
  1407. #define IWL_MVM_COMMON_OPS \
  1408. /* these could be differentiated */ \
  1409. .async_cb = iwl_mvm_async_cb, \
  1410. .queue_full = iwl_mvm_stop_sw_queue, \
  1411. .queue_not_full = iwl_mvm_wake_sw_queue, \
  1412. .hw_rf_kill = iwl_mvm_set_hw_rfkill_state, \
  1413. .free_skb = iwl_mvm_free_skb, \
  1414. .nic_error = iwl_mvm_nic_error, \
  1415. .cmd_queue_full = iwl_mvm_cmd_queue_full, \
  1416. .nic_config = iwl_mvm_nic_config, \
  1417. .enter_d0i3 = iwl_mvm_enter_d0i3, \
  1418. .exit_d0i3 = iwl_mvm_exit_d0i3, \
  1419. /* as we only register one, these MUST be common! */ \
  1420. .start = iwl_op_mode_mvm_start, \
  1421. .stop = iwl_op_mode_mvm_stop
  1422. static const struct iwl_op_mode_ops iwl_mvm_ops = {
  1423. IWL_MVM_COMMON_OPS,
  1424. .rx = iwl_mvm_rx,
  1425. };
  1426. static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
  1427. struct napi_struct *napi,
  1428. struct iwl_rx_cmd_buffer *rxb,
  1429. unsigned int queue)
  1430. {
  1431. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  1432. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1433. u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
  1434. if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)))
  1435. iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);
  1436. else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
  1437. RX_QUEUES_NOTIFICATION)))
  1438. iwl_mvm_rx_queue_notif(mvm, rxb, queue);
  1439. else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
  1440. iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
  1441. }
  1442. static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {
  1443. IWL_MVM_COMMON_OPS,
  1444. .rx = iwl_mvm_rx_mq,
  1445. .rx_rss = iwl_mvm_rx_mq_rss,
  1446. };