ops.c 50 KB

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