fw.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <net/mac80211.h>
  68. #include <linux/netdevice.h>
  69. #include "iwl-trans.h"
  70. #include "iwl-op-mode.h"
  71. #include "fw/img.h"
  72. #include "iwl-debug.h"
  73. #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
  74. #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
  75. #include "iwl-prph.h"
  76. #include "fw/acpi.h"
  77. #include "mvm.h"
  78. #include "fw/dbg.h"
  79. #include "iwl-phy-db.h"
  80. #define MVM_UCODE_ALIVE_TIMEOUT HZ
  81. #define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
  82. #define UCODE_VALID_OK cpu_to_le32(0x1)
  83. struct iwl_mvm_alive_data {
  84. bool valid;
  85. u32 scd_base_addr;
  86. };
  87. static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
  88. {
  89. struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
  90. .valid = cpu_to_le32(valid_tx_ant),
  91. };
  92. IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
  93. return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
  94. sizeof(tx_ant_cmd), &tx_ant_cmd);
  95. }
  96. static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
  97. {
  98. int i;
  99. struct iwl_rss_config_cmd cmd = {
  100. .flags = cpu_to_le32(IWL_RSS_ENABLE),
  101. .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
  102. IWL_RSS_HASH_TYPE_IPV4_UDP |
  103. IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
  104. IWL_RSS_HASH_TYPE_IPV6_TCP |
  105. IWL_RSS_HASH_TYPE_IPV6_UDP |
  106. IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
  107. };
  108. if (mvm->trans->num_rx_queues == 1)
  109. return 0;
  110. /* Do not direct RSS traffic to Q 0 which is our fallback queue */
  111. for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
  112. cmd.indirection_table[i] =
  113. 1 + (i % (mvm->trans->num_rx_queues - 1));
  114. netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
  115. return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
  116. }
  117. static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
  118. {
  119. struct iwl_dqa_enable_cmd dqa_cmd = {
  120. .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
  121. };
  122. u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
  123. int ret;
  124. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
  125. if (ret)
  126. IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
  127. else
  128. IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
  129. return ret;
  130. }
  131. void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
  132. struct iwl_rx_cmd_buffer *rxb)
  133. {
  134. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  135. struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
  136. __le32 *dump_data = mfu_dump_notif->data;
  137. int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
  138. int i;
  139. if (mfu_dump_notif->index_num == 0)
  140. IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
  141. le32_to_cpu(mfu_dump_notif->assert_id));
  142. for (i = 0; i < n_words; i++)
  143. IWL_DEBUG_INFO(mvm,
  144. "MFUART assert dump, dword %u: 0x%08x\n",
  145. le16_to_cpu(mfu_dump_notif->index_num) *
  146. n_words + i,
  147. le32_to_cpu(dump_data[i]));
  148. }
  149. static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
  150. struct iwl_rx_packet *pkt, void *data)
  151. {
  152. struct iwl_mvm *mvm =
  153. container_of(notif_wait, struct iwl_mvm, notif_wait);
  154. struct iwl_mvm_alive_data *alive_data = data;
  155. struct mvm_alive_resp_v3 *palive3;
  156. struct mvm_alive_resp *palive;
  157. struct iwl_umac_alive *umac;
  158. struct iwl_lmac_alive *lmac1;
  159. struct iwl_lmac_alive *lmac2 = NULL;
  160. u16 status;
  161. u32 umac_error_event_table;
  162. if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
  163. palive = (void *)pkt->data;
  164. umac = &palive->umac_data;
  165. lmac1 = &palive->lmac_data[0];
  166. lmac2 = &palive->lmac_data[1];
  167. status = le16_to_cpu(palive->status);
  168. } else {
  169. palive3 = (void *)pkt->data;
  170. umac = &palive3->umac_data;
  171. lmac1 = &palive3->lmac_data;
  172. status = le16_to_cpu(palive3->status);
  173. }
  174. mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
  175. if (lmac2)
  176. mvm->error_event_table[1] =
  177. le32_to_cpu(lmac2->error_event_table_ptr);
  178. mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
  179. umac_error_event_table = le32_to_cpu(umac->error_info_addr);
  180. if (!umac_error_event_table) {
  181. mvm->support_umac_log = false;
  182. } else if (umac_error_event_table >=
  183. mvm->trans->cfg->min_umac_error_event_table) {
  184. mvm->support_umac_log = true;
  185. mvm->umac_error_event_table = umac_error_event_table;
  186. } else {
  187. IWL_ERR(mvm,
  188. "Not valid error log pointer 0x%08X for %s uCode\n",
  189. mvm->umac_error_event_table,
  190. (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
  191. "Init" : "RT");
  192. mvm->support_umac_log = false;
  193. }
  194. alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
  195. alive_data->valid = status == IWL_ALIVE_STATUS_OK;
  196. IWL_DEBUG_FW(mvm,
  197. "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
  198. status, lmac1->ver_type, lmac1->ver_subtype);
  199. if (lmac2)
  200. IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
  201. IWL_DEBUG_FW(mvm,
  202. "UMAC version: Major - 0x%x, Minor - 0x%x\n",
  203. le32_to_cpu(umac->umac_major),
  204. le32_to_cpu(umac->umac_minor));
  205. return true;
  206. }
  207. static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
  208. struct iwl_rx_packet *pkt, void *data)
  209. {
  210. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  211. return true;
  212. }
  213. static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
  214. struct iwl_rx_packet *pkt, void *data)
  215. {
  216. struct iwl_phy_db *phy_db = data;
  217. if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
  218. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  219. return true;
  220. }
  221. WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
  222. return false;
  223. }
  224. static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
  225. enum iwl_ucode_type ucode_type)
  226. {
  227. struct iwl_notification_wait alive_wait;
  228. struct iwl_mvm_alive_data alive_data;
  229. const struct fw_img *fw;
  230. int ret, i;
  231. enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
  232. static const u16 alive_cmd[] = { MVM_ALIVE };
  233. if (ucode_type == IWL_UCODE_REGULAR &&
  234. iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
  235. !(fw_has_capa(&mvm->fw->ucode_capa,
  236. IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
  237. fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
  238. else
  239. fw = iwl_get_ucode_image(mvm->fw, ucode_type);
  240. if (WARN_ON(!fw))
  241. return -EINVAL;
  242. iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
  243. clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
  244. iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
  245. alive_cmd, ARRAY_SIZE(alive_cmd),
  246. iwl_alive_fn, &alive_data);
  247. ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
  248. if (ret) {
  249. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  250. iwl_remove_notification(&mvm->notif_wait, &alive_wait);
  251. return ret;
  252. }
  253. /*
  254. * Some things may run in the background now, but we
  255. * just wait for the ALIVE notification here.
  256. */
  257. ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
  258. MVM_UCODE_ALIVE_TIMEOUT);
  259. if (ret) {
  260. struct iwl_trans *trans = mvm->trans;
  261. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_22000)
  262. IWL_ERR(mvm,
  263. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  264. iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
  265. iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
  266. else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
  267. IWL_ERR(mvm,
  268. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  269. iwl_read_prph(trans, SB_CPU_1_STATUS),
  270. iwl_read_prph(trans, SB_CPU_2_STATUS));
  271. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  272. return ret;
  273. }
  274. if (!alive_data.valid) {
  275. IWL_ERR(mvm, "Loaded ucode is not valid!\n");
  276. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  277. return -EIO;
  278. }
  279. iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
  280. /*
  281. * Note: all the queues are enabled as part of the interface
  282. * initialization, but in firmware restart scenarios they
  283. * could be stopped, so wake them up. In firmware restart,
  284. * mac80211 will have the queues stopped as well until the
  285. * reconfiguration completes. During normal startup, they
  286. * will be empty.
  287. */
  288. memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
  289. mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
  290. for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
  291. atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
  292. set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
  293. return 0;
  294. }
  295. static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  296. {
  297. struct iwl_notification_wait init_wait;
  298. struct iwl_nvm_access_complete_cmd nvm_complete = {};
  299. struct iwl_init_extended_cfg_cmd init_cfg = {
  300. .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
  301. };
  302. static const u16 init_complete[] = {
  303. INIT_COMPLETE_NOTIF,
  304. };
  305. int ret;
  306. lockdep_assert_held(&mvm->mutex);
  307. iwl_init_notification_wait(&mvm->notif_wait,
  308. &init_wait,
  309. init_complete,
  310. ARRAY_SIZE(init_complete),
  311. iwl_wait_init_complete,
  312. NULL);
  313. /* Will also start the device */
  314. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  315. if (ret) {
  316. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  317. goto error;
  318. }
  319. /* Send init config command to mark that we are sending NVM access
  320. * commands
  321. */
  322. ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
  323. INIT_EXTENDED_CFG_CMD), 0,
  324. sizeof(init_cfg), &init_cfg);
  325. if (ret) {
  326. IWL_ERR(mvm, "Failed to run init config command: %d\n",
  327. ret);
  328. goto error;
  329. }
  330. /* Load NVM to NIC if needed */
  331. if (mvm->nvm_file_name) {
  332. iwl_mvm_read_external_nvm(mvm);
  333. iwl_mvm_load_nvm_to_nic(mvm);
  334. }
  335. if (IWL_MVM_PARSE_NVM && read_nvm) {
  336. ret = iwl_nvm_init(mvm);
  337. if (ret) {
  338. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  339. goto error;
  340. }
  341. }
  342. ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
  343. NVM_ACCESS_COMPLETE), 0,
  344. sizeof(nvm_complete), &nvm_complete);
  345. if (ret) {
  346. IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
  347. ret);
  348. goto error;
  349. }
  350. /* We wait for the INIT complete notification */
  351. ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
  352. MVM_UCODE_ALIVE_TIMEOUT);
  353. if (ret)
  354. return ret;
  355. /* Read the NVM only at driver load time, no need to do this twice */
  356. if (!IWL_MVM_PARSE_NVM && read_nvm) {
  357. mvm->nvm_data = iwl_fw_get_nvm(&mvm->fwrt);
  358. if (IS_ERR(mvm->nvm_data)) {
  359. ret = PTR_ERR(mvm->nvm_data);
  360. mvm->nvm_data = NULL;
  361. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  362. return ret;
  363. }
  364. }
  365. return 0;
  366. error:
  367. iwl_remove_notification(&mvm->notif_wait, &init_wait);
  368. return ret;
  369. }
  370. static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
  371. {
  372. struct iwl_phy_cfg_cmd phy_cfg_cmd;
  373. enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
  374. /* Set parameters */
  375. phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
  376. /* set flags extra PHY configuration flags from the device's cfg */
  377. phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags);
  378. phy_cfg_cmd.calib_control.event_trigger =
  379. mvm->fw->default_calib[ucode_type].event_trigger;
  380. phy_cfg_cmd.calib_control.flow_trigger =
  381. mvm->fw->default_calib[ucode_type].flow_trigger;
  382. IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
  383. phy_cfg_cmd.phy_cfg);
  384. return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
  385. sizeof(phy_cfg_cmd), &phy_cfg_cmd);
  386. }
  387. int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  388. {
  389. struct iwl_notification_wait calib_wait;
  390. static const u16 init_complete[] = {
  391. INIT_COMPLETE_NOTIF,
  392. CALIB_RES_NOTIF_PHY_DB
  393. };
  394. int ret;
  395. if (iwl_mvm_has_unified_ucode(mvm))
  396. return iwl_run_unified_mvm_ucode(mvm, true);
  397. lockdep_assert_held(&mvm->mutex);
  398. if (WARN_ON_ONCE(mvm->calibrating))
  399. return 0;
  400. iwl_init_notification_wait(&mvm->notif_wait,
  401. &calib_wait,
  402. init_complete,
  403. ARRAY_SIZE(init_complete),
  404. iwl_wait_phy_db_entry,
  405. mvm->phy_db);
  406. /* Will also start the device */
  407. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
  408. if (ret) {
  409. IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
  410. goto remove_notif;
  411. }
  412. if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
  413. ret = iwl_mvm_send_bt_init_conf(mvm);
  414. if (ret)
  415. goto remove_notif;
  416. }
  417. /* Read the NVM only at driver load time, no need to do this twice */
  418. if (read_nvm) {
  419. ret = iwl_nvm_init(mvm);
  420. if (ret) {
  421. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  422. goto remove_notif;
  423. }
  424. }
  425. /* In case we read the NVM from external file, load it to the NIC */
  426. if (mvm->nvm_file_name)
  427. iwl_mvm_load_nvm_to_nic(mvm);
  428. WARN_ON(iwl_nvm_check_version(mvm->nvm_data, mvm->trans));
  429. /*
  430. * abort after reading the nvm in case RF Kill is on, we will complete
  431. * the init seq later when RF kill will switch to off
  432. */
  433. if (iwl_mvm_is_radio_hw_killed(mvm)) {
  434. IWL_DEBUG_RF_KILL(mvm,
  435. "jump over all phy activities due to RF kill\n");
  436. goto remove_notif;
  437. }
  438. mvm->calibrating = true;
  439. /* Send TX valid antennas before triggering calibrations */
  440. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  441. if (ret)
  442. goto remove_notif;
  443. ret = iwl_send_phy_cfg_cmd(mvm);
  444. if (ret) {
  445. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  446. ret);
  447. goto remove_notif;
  448. }
  449. /*
  450. * Some things may run in the background now, but we
  451. * just wait for the calibration complete notification.
  452. */
  453. ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
  454. MVM_UCODE_CALIB_TIMEOUT);
  455. if (!ret)
  456. goto out;
  457. if (iwl_mvm_is_radio_hw_killed(mvm)) {
  458. IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
  459. ret = 0;
  460. } else {
  461. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  462. ret);
  463. }
  464. goto out;
  465. remove_notif:
  466. iwl_remove_notification(&mvm->notif_wait, &calib_wait);
  467. out:
  468. mvm->calibrating = false;
  469. if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
  470. /* we want to debug INIT and we have no NVM - fake */
  471. mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
  472. sizeof(struct ieee80211_channel) +
  473. sizeof(struct ieee80211_rate),
  474. GFP_KERNEL);
  475. if (!mvm->nvm_data)
  476. return -ENOMEM;
  477. mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
  478. mvm->nvm_data->bands[0].n_channels = 1;
  479. mvm->nvm_data->bands[0].n_bitrates = 1;
  480. mvm->nvm_data->bands[0].bitrates =
  481. (void *)mvm->nvm_data->channels + 1;
  482. mvm->nvm_data->bands[0].bitrates->hw_value = 10;
  483. }
  484. return ret;
  485. }
  486. static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
  487. {
  488. struct iwl_ltr_config_cmd cmd = {
  489. .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
  490. };
  491. if (!mvm->trans->ltr_enabled)
  492. return 0;
  493. return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
  494. sizeof(cmd), &cmd);
  495. }
  496. #ifdef CONFIG_ACPI
  497. static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
  498. union acpi_object *table,
  499. struct iwl_mvm_sar_profile *profile,
  500. bool enabled)
  501. {
  502. int i;
  503. profile->enabled = enabled;
  504. for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
  505. if ((table[i].type != ACPI_TYPE_INTEGER) ||
  506. (table[i].integer.value > U8_MAX))
  507. return -EINVAL;
  508. profile->table[i] = table[i].integer.value;
  509. }
  510. return 0;
  511. }
  512. static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
  513. {
  514. union acpi_object *wifi_pkg, *table, *data;
  515. bool enabled;
  516. int ret;
  517. data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD);
  518. if (IS_ERR(data))
  519. return PTR_ERR(data);
  520. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  521. ACPI_WRDS_WIFI_DATA_SIZE);
  522. if (IS_ERR(wifi_pkg)) {
  523. ret = PTR_ERR(wifi_pkg);
  524. goto out_free;
  525. }
  526. if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
  527. ret = -EINVAL;
  528. goto out_free;
  529. }
  530. enabled = !!(wifi_pkg->package.elements[1].integer.value);
  531. /* position of the actual table */
  532. table = &wifi_pkg->package.elements[2];
  533. /* The profile from WRDS is officially profile 1, but goes
  534. * into sar_profiles[0] (because we don't have a profile 0).
  535. */
  536. ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
  537. enabled);
  538. out_free:
  539. kfree(data);
  540. return ret;
  541. }
  542. static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
  543. {
  544. union acpi_object *wifi_pkg, *data;
  545. bool enabled;
  546. int i, n_profiles, ret;
  547. data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD);
  548. if (IS_ERR(data))
  549. return PTR_ERR(data);
  550. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  551. ACPI_EWRD_WIFI_DATA_SIZE);
  552. if (IS_ERR(wifi_pkg)) {
  553. ret = PTR_ERR(wifi_pkg);
  554. goto out_free;
  555. }
  556. if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
  557. (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
  558. ret = -EINVAL;
  559. goto out_free;
  560. }
  561. enabled = !!(wifi_pkg->package.elements[1].integer.value);
  562. n_profiles = wifi_pkg->package.elements[2].integer.value;
  563. /* in case of BIOS bug */
  564. if (n_profiles <= 0) {
  565. ret = -EINVAL;
  566. goto out_free;
  567. }
  568. for (i = 0; i < n_profiles; i++) {
  569. /* the tables start at element 3 */
  570. static int pos = 3;
  571. /* The EWRD profiles officially go from 2 to 4, but we
  572. * save them in sar_profiles[1-3] (because we don't
  573. * have profile 0). So in the array we start from 1.
  574. */
  575. ret = iwl_mvm_sar_set_profile(mvm,
  576. &wifi_pkg->package.elements[pos],
  577. &mvm->sar_profiles[i + 1],
  578. enabled);
  579. if (ret < 0)
  580. break;
  581. /* go to the next table */
  582. pos += ACPI_SAR_TABLE_SIZE;
  583. }
  584. out_free:
  585. kfree(data);
  586. return ret;
  587. }
  588. static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
  589. {
  590. union acpi_object *wifi_pkg, *data;
  591. int i, j, ret;
  592. int idx = 1;
  593. data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD);
  594. if (IS_ERR(data))
  595. return PTR_ERR(data);
  596. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  597. ACPI_WGDS_WIFI_DATA_SIZE);
  598. if (IS_ERR(wifi_pkg)) {
  599. ret = PTR_ERR(wifi_pkg);
  600. goto out_free;
  601. }
  602. for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
  603. for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
  604. union acpi_object *entry;
  605. entry = &wifi_pkg->package.elements[idx++];
  606. if ((entry->type != ACPI_TYPE_INTEGER) ||
  607. (entry->integer.value > U8_MAX)) {
  608. ret = -EINVAL;
  609. goto out_free;
  610. }
  611. mvm->geo_profiles[i].values[j] = entry->integer.value;
  612. }
  613. }
  614. ret = 0;
  615. out_free:
  616. kfree(data);
  617. return ret;
  618. }
  619. int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
  620. {
  621. struct iwl_dev_tx_power_cmd cmd = {
  622. .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
  623. };
  624. int i, j, idx;
  625. int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
  626. int len = sizeof(cmd);
  627. BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
  628. BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
  629. ACPI_SAR_TABLE_SIZE);
  630. if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
  631. len = sizeof(cmd.v3);
  632. for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
  633. struct iwl_mvm_sar_profile *prof;
  634. /* don't allow SAR to be disabled (profile 0 means disable) */
  635. if (profs[i] == 0)
  636. return -EPERM;
  637. /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
  638. if (profs[i] > ACPI_SAR_PROFILE_NUM)
  639. return -EINVAL;
  640. /* profiles go from 1 to 4, so decrement to access the array */
  641. prof = &mvm->sar_profiles[profs[i] - 1];
  642. /* if the profile is disabled, do nothing */
  643. if (!prof->enabled) {
  644. IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
  645. profs[i]);
  646. /* if one of the profiles is disabled, we fail all */
  647. return -ENOENT;
  648. }
  649. IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
  650. for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
  651. idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
  652. cmd.v3.per_chain_restriction[i][j] =
  653. cpu_to_le16(prof->table[idx]);
  654. IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
  655. j, prof->table[idx]);
  656. }
  657. }
  658. IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
  659. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
  660. }
  661. int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
  662. {
  663. struct iwl_geo_tx_power_profiles_resp *resp;
  664. int ret;
  665. struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
  666. .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
  667. };
  668. struct iwl_host_cmd cmd = {
  669. .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
  670. .len = { sizeof(geo_cmd), },
  671. .flags = CMD_WANT_SKB,
  672. .data = { &geo_cmd },
  673. };
  674. ret = iwl_mvm_send_cmd(mvm, &cmd);
  675. if (ret) {
  676. IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
  677. return ret;
  678. }
  679. resp = (void *)cmd.resp_pkt->data;
  680. ret = le32_to_cpu(resp->profile_idx);
  681. if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
  682. ret = -EIO;
  683. IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
  684. }
  685. iwl_free_resp(&cmd);
  686. return ret;
  687. }
  688. static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
  689. {
  690. struct iwl_geo_tx_power_profiles_cmd cmd = {
  691. .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
  692. };
  693. int ret, i, j;
  694. u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
  695. ret = iwl_mvm_sar_get_wgds_table(mvm);
  696. if (ret < 0) {
  697. IWL_DEBUG_RADIO(mvm,
  698. "Geo SAR BIOS table invalid or unavailable. (%d)\n",
  699. ret);
  700. /* we don't fail if the table is not available */
  701. return 0;
  702. }
  703. IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
  704. BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
  705. ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE);
  706. BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
  707. for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
  708. struct iwl_per_chain_offset *chain =
  709. (struct iwl_per_chain_offset *)&cmd.table[i];
  710. for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
  711. u8 *value;
  712. value = &mvm->geo_profiles[i].values[j *
  713. ACPI_GEO_PER_CHAIN_SIZE];
  714. chain[j].max_tx_power = cpu_to_le16(value[0]);
  715. chain[j].chain_a = value[1];
  716. chain[j].chain_b = value[2];
  717. IWL_DEBUG_RADIO(mvm,
  718. "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
  719. i, j, value[1], value[2], value[0]);
  720. }
  721. }
  722. return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
  723. }
  724. #else /* CONFIG_ACPI */
  725. static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
  726. {
  727. return -ENOENT;
  728. }
  729. static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
  730. {
  731. return -ENOENT;
  732. }
  733. static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
  734. {
  735. return 0;
  736. }
  737. int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a,
  738. int prof_b)
  739. {
  740. return -ENOENT;
  741. }
  742. int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
  743. {
  744. return -ENOENT;
  745. }
  746. #endif /* CONFIG_ACPI */
  747. static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
  748. {
  749. int ret;
  750. ret = iwl_mvm_sar_get_wrds_table(mvm);
  751. if (ret < 0) {
  752. IWL_DEBUG_RADIO(mvm,
  753. "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
  754. ret);
  755. /* if not available, don't fail and don't bother with EWRD */
  756. return 0;
  757. }
  758. ret = iwl_mvm_sar_get_ewrd_table(mvm);
  759. /* if EWRD is not available, we can still use WRDS, so don't fail */
  760. if (ret < 0)
  761. IWL_DEBUG_RADIO(mvm,
  762. "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
  763. ret);
  764. /* choose profile 1 (WRDS) as default for both chains */
  765. ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
  766. /* if we don't have profile 0 from BIOS, just skip it */
  767. if (ret == -ENOENT)
  768. return 0;
  769. return ret;
  770. }
  771. static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
  772. {
  773. int ret;
  774. if (iwl_mvm_has_unified_ucode(mvm))
  775. return iwl_run_unified_mvm_ucode(mvm, false);
  776. ret = iwl_run_init_mvm_ucode(mvm, false);
  777. if (ret) {
  778. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
  779. if (iwlmvm_mod_params.init_dbg)
  780. return 0;
  781. return ret;
  782. }
  783. /*
  784. * Stop and start the transport without entering low power
  785. * mode. This will save the state of other components on the
  786. * device that are triggered by the INIT firwmare (MFUART).
  787. */
  788. _iwl_trans_stop_device(mvm->trans, false);
  789. ret = _iwl_trans_start_hw(mvm->trans, false);
  790. if (ret)
  791. return ret;
  792. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  793. if (ret)
  794. return ret;
  795. return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
  796. }
  797. int iwl_mvm_up(struct iwl_mvm *mvm)
  798. {
  799. int ret, i;
  800. struct ieee80211_channel *chan;
  801. struct cfg80211_chan_def chandef;
  802. lockdep_assert_held(&mvm->mutex);
  803. ret = iwl_trans_start_hw(mvm->trans);
  804. if (ret)
  805. return ret;
  806. ret = iwl_mvm_load_rt_fw(mvm);
  807. if (ret) {
  808. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  809. goto error;
  810. }
  811. iwl_get_shared_mem_conf(&mvm->fwrt);
  812. ret = iwl_mvm_sf_update(mvm, NULL, false);
  813. if (ret)
  814. IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
  815. mvm->fwrt.dump.conf = FW_DBG_INVALID;
  816. /* if we have a destination, assume EARLY START */
  817. if (mvm->fw->dbg_dest_tlv)
  818. mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
  819. iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
  820. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  821. if (ret)
  822. goto error;
  823. if (!iwl_mvm_has_unified_ucode(mvm)) {
  824. /* Send phy db control command and then phy db calibration */
  825. ret = iwl_send_phy_db_data(mvm->phy_db);
  826. if (ret)
  827. goto error;
  828. ret = iwl_send_phy_cfg_cmd(mvm);
  829. if (ret)
  830. goto error;
  831. }
  832. ret = iwl_mvm_send_bt_init_conf(mvm);
  833. if (ret)
  834. goto error;
  835. /* Init RSS configuration */
  836. /* TODO - remove 22000 disablement when we have RXQ config API */
  837. if (iwl_mvm_has_new_rx_api(mvm) &&
  838. mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_22000) {
  839. ret = iwl_send_rss_cfg_cmd(mvm);
  840. if (ret) {
  841. IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
  842. ret);
  843. goto error;
  844. }
  845. }
  846. /* init the fw <-> mac80211 STA mapping */
  847. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
  848. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  849. mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
  850. /* reset quota debouncing buffer - 0xff will yield invalid data */
  851. memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
  852. ret = iwl_mvm_send_dqa_cmd(mvm);
  853. if (ret)
  854. goto error;
  855. /* Add auxiliary station for scanning */
  856. ret = iwl_mvm_add_aux_sta(mvm);
  857. if (ret)
  858. goto error;
  859. /* Add all the PHY contexts */
  860. chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
  861. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
  862. for (i = 0; i < NUM_PHY_CTX; i++) {
  863. /*
  864. * The channel used here isn't relevant as it's
  865. * going to be overwritten in the other flows.
  866. * For now use the first channel we have.
  867. */
  868. ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
  869. &chandef, 1, 1);
  870. if (ret)
  871. goto error;
  872. }
  873. #ifdef CONFIG_THERMAL
  874. if (iwl_mvm_is_tt_in_fw(mvm)) {
  875. /* in order to give the responsibility of ct-kill and
  876. * TX backoff to FW we need to send empty temperature reporting
  877. * cmd during init time
  878. */
  879. iwl_mvm_send_temp_report_ths_cmd(mvm);
  880. } else {
  881. /* Initialize tx backoffs to the minimal possible */
  882. iwl_mvm_tt_tx_backoff(mvm, 0);
  883. }
  884. /* TODO: read the budget from BIOS / Platform NVM */
  885. /*
  886. * In case there is no budget from BIOS / Platform NVM the default
  887. * budget should be 2000mW (cooling state 0).
  888. */
  889. if (iwl_mvm_is_ctdp_supported(mvm)) {
  890. ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
  891. mvm->cooling_dev.cur_state);
  892. if (ret)
  893. goto error;
  894. }
  895. #else
  896. /* Initialize tx backoffs to the minimal possible */
  897. iwl_mvm_tt_tx_backoff(mvm, 0);
  898. #endif
  899. WARN_ON(iwl_mvm_config_ltr(mvm));
  900. ret = iwl_mvm_power_update_device(mvm);
  901. if (ret)
  902. goto error;
  903. /*
  904. * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
  905. * anyway, so don't init MCC.
  906. */
  907. if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
  908. ret = iwl_mvm_init_mcc(mvm);
  909. if (ret)
  910. goto error;
  911. }
  912. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  913. mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
  914. ret = iwl_mvm_config_scan(mvm);
  915. if (ret)
  916. goto error;
  917. }
  918. /* allow FW/transport low power modes if not during restart */
  919. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  920. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  921. ret = iwl_mvm_sar_init(mvm);
  922. if (ret)
  923. goto error;
  924. ret = iwl_mvm_sar_geo_init(mvm);
  925. if (ret)
  926. goto error;
  927. iwl_mvm_leds_sync(mvm);
  928. IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
  929. return 0;
  930. error:
  931. if (!iwlmvm_mod_params.init_dbg || !ret)
  932. iwl_mvm_stop_device(mvm);
  933. return ret;
  934. }
  935. int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
  936. {
  937. int ret, i;
  938. lockdep_assert_held(&mvm->mutex);
  939. ret = iwl_trans_start_hw(mvm->trans);
  940. if (ret)
  941. return ret;
  942. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
  943. if (ret) {
  944. IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
  945. goto error;
  946. }
  947. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  948. if (ret)
  949. goto error;
  950. /* Send phy db control command and then phy db calibration*/
  951. ret = iwl_send_phy_db_data(mvm->phy_db);
  952. if (ret)
  953. goto error;
  954. ret = iwl_send_phy_cfg_cmd(mvm);
  955. if (ret)
  956. goto error;
  957. /* init the fw <-> mac80211 STA mapping */
  958. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
  959. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  960. /* Add auxiliary station for scanning */
  961. ret = iwl_mvm_add_aux_sta(mvm);
  962. if (ret)
  963. goto error;
  964. return 0;
  965. error:
  966. iwl_mvm_stop_device(mvm);
  967. return ret;
  968. }
  969. void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
  970. struct iwl_rx_cmd_buffer *rxb)
  971. {
  972. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  973. struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
  974. u32 flags = le32_to_cpu(card_state_notif->flags);
  975. IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
  976. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  977. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  978. (flags & CT_KILL_CARD_DISABLED) ?
  979. "Reached" : "Not reached");
  980. }
  981. void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
  982. struct iwl_rx_cmd_buffer *rxb)
  983. {
  984. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  985. struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
  986. IWL_DEBUG_INFO(mvm,
  987. "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
  988. le32_to_cpu(mfuart_notif->installed_ver),
  989. le32_to_cpu(mfuart_notif->external_ver),
  990. le32_to_cpu(mfuart_notif->status),
  991. le32_to_cpu(mfuart_notif->duration));
  992. if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
  993. IWL_DEBUG_INFO(mvm,
  994. "MFUART: image size: 0x%08x\n",
  995. le32_to_cpu(mfuart_notif->image_size));
  996. }