ops.c 51 KB

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