ops.c 47 KB

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