fw.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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 <net/mac80211.h>
  70. #include <linux/netdevice.h>
  71. #include "iwl-trans.h"
  72. #include "iwl-op-mode.h"
  73. #include "fw/img.h"
  74. #include "iwl-debug.h"
  75. #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
  76. #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
  77. #include "iwl-prph.h"
  78. #include "fw/acpi.h"
  79. #include "mvm.h"
  80. #include "fw/dbg.h"
  81. #include "iwl-phy-db.h"
  82. #include "iwl-modparams.h"
  83. #include "iwl-nvm-parse.h"
  84. #define MVM_UCODE_ALIVE_TIMEOUT HZ
  85. #define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
  86. #define UCODE_VALID_OK cpu_to_le32(0x1)
  87. struct iwl_mvm_alive_data {
  88. bool valid;
  89. u32 scd_base_addr;
  90. };
  91. static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
  92. {
  93. struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
  94. .valid = cpu_to_le32(valid_tx_ant),
  95. };
  96. IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
  97. return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
  98. sizeof(tx_ant_cmd), &tx_ant_cmd);
  99. }
  100. static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
  101. {
  102. int i;
  103. struct iwl_rss_config_cmd cmd = {
  104. .flags = cpu_to_le32(IWL_RSS_ENABLE),
  105. .hash_mask = BIT(IWL_RSS_HASH_TYPE_IPV4_TCP) |
  106. BIT(IWL_RSS_HASH_TYPE_IPV4_UDP) |
  107. BIT(IWL_RSS_HASH_TYPE_IPV4_PAYLOAD) |
  108. BIT(IWL_RSS_HASH_TYPE_IPV6_TCP) |
  109. BIT(IWL_RSS_HASH_TYPE_IPV6_UDP) |
  110. BIT(IWL_RSS_HASH_TYPE_IPV6_PAYLOAD),
  111. };
  112. if (mvm->trans->num_rx_queues == 1)
  113. return 0;
  114. /* Do not direct RSS traffic to Q 0 which is our fallback queue */
  115. for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
  116. cmd.indirection_table[i] =
  117. 1 + (i % (mvm->trans->num_rx_queues - 1));
  118. netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
  119. return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
  120. }
  121. static int iwl_configure_rxq(struct iwl_mvm *mvm)
  122. {
  123. int i, num_queues, size, ret;
  124. struct iwl_rfh_queue_config *cmd;
  125. struct iwl_host_cmd hcmd = {
  126. .id = WIDE_ID(DATA_PATH_GROUP, RFH_QUEUE_CONFIG_CMD),
  127. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  128. };
  129. /* Do not configure default queue, it is configured via context info */
  130. num_queues = mvm->trans->num_rx_queues - 1;
  131. size = struct_size(cmd, data, num_queues);
  132. cmd = kzalloc(size, GFP_KERNEL);
  133. if (!cmd)
  134. return -ENOMEM;
  135. cmd->num_queues = num_queues;
  136. for (i = 0; i < num_queues; i++) {
  137. struct iwl_trans_rxq_dma_data data;
  138. cmd->data[i].q_num = i + 1;
  139. iwl_trans_get_rxq_dma_data(mvm->trans, i + 1, &data);
  140. cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
  141. cmd->data[i].urbd_stts_wrptr =
  142. cpu_to_le64(data.urbd_stts_wrptr);
  143. cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
  144. cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
  145. }
  146. hcmd.data[0] = cmd;
  147. hcmd.len[0] = size;
  148. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  149. kfree(cmd);
  150. return ret;
  151. }
  152. static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
  153. {
  154. struct iwl_dqa_enable_cmd dqa_cmd = {
  155. .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
  156. };
  157. u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
  158. int ret;
  159. ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
  160. if (ret)
  161. IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
  162. else
  163. IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
  164. return ret;
  165. }
  166. void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
  167. struct iwl_rx_cmd_buffer *rxb)
  168. {
  169. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  170. struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
  171. __le32 *dump_data = mfu_dump_notif->data;
  172. int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
  173. int i;
  174. if (mfu_dump_notif->index_num == 0)
  175. IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
  176. le32_to_cpu(mfu_dump_notif->assert_id));
  177. for (i = 0; i < n_words; i++)
  178. IWL_DEBUG_INFO(mvm,
  179. "MFUART assert dump, dword %u: 0x%08x\n",
  180. le16_to_cpu(mfu_dump_notif->index_num) *
  181. n_words + i,
  182. le32_to_cpu(dump_data[i]));
  183. }
  184. static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
  185. struct iwl_rx_packet *pkt, void *data)
  186. {
  187. struct iwl_mvm *mvm =
  188. container_of(notif_wait, struct iwl_mvm, notif_wait);
  189. struct iwl_mvm_alive_data *alive_data = data;
  190. struct mvm_alive_resp_v3 *palive3;
  191. struct mvm_alive_resp *palive;
  192. struct iwl_umac_alive *umac;
  193. struct iwl_lmac_alive *lmac1;
  194. struct iwl_lmac_alive *lmac2 = NULL;
  195. u16 status;
  196. u32 umac_error_event_table;
  197. if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
  198. palive = (void *)pkt->data;
  199. umac = &palive->umac_data;
  200. lmac1 = &palive->lmac_data[0];
  201. lmac2 = &palive->lmac_data[1];
  202. status = le16_to_cpu(palive->status);
  203. } else {
  204. palive3 = (void *)pkt->data;
  205. umac = &palive3->umac_data;
  206. lmac1 = &palive3->lmac_data;
  207. status = le16_to_cpu(palive3->status);
  208. }
  209. mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
  210. if (lmac2)
  211. mvm->error_event_table[1] =
  212. le32_to_cpu(lmac2->error_event_table_ptr);
  213. mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
  214. umac_error_event_table = le32_to_cpu(umac->error_info_addr);
  215. if (!umac_error_event_table) {
  216. mvm->support_umac_log = false;
  217. } else if (umac_error_event_table >=
  218. mvm->trans->cfg->min_umac_error_event_table) {
  219. mvm->support_umac_log = true;
  220. mvm->umac_error_event_table = umac_error_event_table;
  221. } else {
  222. IWL_ERR(mvm,
  223. "Not valid error log pointer 0x%08X for %s uCode\n",
  224. mvm->umac_error_event_table,
  225. (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
  226. "Init" : "RT");
  227. mvm->support_umac_log = false;
  228. }
  229. alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
  230. alive_data->valid = status == IWL_ALIVE_STATUS_OK;
  231. IWL_DEBUG_FW(mvm,
  232. "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
  233. status, lmac1->ver_type, lmac1->ver_subtype);
  234. if (lmac2)
  235. IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
  236. IWL_DEBUG_FW(mvm,
  237. "UMAC version: Major - 0x%x, Minor - 0x%x\n",
  238. le32_to_cpu(umac->umac_major),
  239. le32_to_cpu(umac->umac_minor));
  240. return true;
  241. }
  242. static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
  243. struct iwl_rx_packet *pkt, void *data)
  244. {
  245. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  246. return true;
  247. }
  248. static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
  249. struct iwl_rx_packet *pkt, void *data)
  250. {
  251. struct iwl_phy_db *phy_db = data;
  252. if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
  253. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  254. return true;
  255. }
  256. WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
  257. return false;
  258. }
  259. static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
  260. enum iwl_ucode_type ucode_type)
  261. {
  262. struct iwl_notification_wait alive_wait;
  263. struct iwl_mvm_alive_data alive_data;
  264. const struct fw_img *fw;
  265. int ret, i;
  266. enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
  267. static const u16 alive_cmd[] = { MVM_ALIVE };
  268. if (ucode_type == IWL_UCODE_REGULAR &&
  269. iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
  270. !(fw_has_capa(&mvm->fw->ucode_capa,
  271. IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
  272. fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
  273. else
  274. fw = iwl_get_ucode_image(mvm->fw, ucode_type);
  275. if (WARN_ON(!fw))
  276. return -EINVAL;
  277. iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
  278. clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
  279. iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
  280. alive_cmd, ARRAY_SIZE(alive_cmd),
  281. iwl_alive_fn, &alive_data);
  282. ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
  283. if (ret) {
  284. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  285. iwl_remove_notification(&mvm->notif_wait, &alive_wait);
  286. return ret;
  287. }
  288. /*
  289. * Some things may run in the background now, but we
  290. * just wait for the ALIVE notification here.
  291. */
  292. ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
  293. MVM_UCODE_ALIVE_TIMEOUT);
  294. if (ret) {
  295. struct iwl_trans *trans = mvm->trans;
  296. if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000)
  297. IWL_ERR(mvm,
  298. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  299. iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
  300. iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
  301. else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
  302. IWL_ERR(mvm,
  303. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  304. iwl_read_prph(trans, SB_CPU_1_STATUS),
  305. iwl_read_prph(trans, SB_CPU_2_STATUS));
  306. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  307. return ret;
  308. }
  309. if (!alive_data.valid) {
  310. IWL_ERR(mvm, "Loaded ucode is not valid!\n");
  311. iwl_fw_set_current_image(&mvm->fwrt, old_type);
  312. return -EIO;
  313. }
  314. iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
  315. /*
  316. * Note: all the queues are enabled as part of the interface
  317. * initialization, but in firmware restart scenarios they
  318. * could be stopped, so wake them up. In firmware restart,
  319. * mac80211 will have the queues stopped as well until the
  320. * reconfiguration completes. During normal startup, they
  321. * will be empty.
  322. */
  323. memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
  324. mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
  325. for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
  326. atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
  327. set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
  328. return 0;
  329. }
  330. static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  331. {
  332. struct iwl_notification_wait init_wait;
  333. struct iwl_nvm_access_complete_cmd nvm_complete = {};
  334. struct iwl_init_extended_cfg_cmd init_cfg = {
  335. .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
  336. };
  337. static const u16 init_complete[] = {
  338. INIT_COMPLETE_NOTIF,
  339. };
  340. int ret;
  341. lockdep_assert_held(&mvm->mutex);
  342. iwl_init_notification_wait(&mvm->notif_wait,
  343. &init_wait,
  344. init_complete,
  345. ARRAY_SIZE(init_complete),
  346. iwl_wait_init_complete,
  347. NULL);
  348. /* Will also start the device */
  349. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  350. if (ret) {
  351. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  352. goto error;
  353. }
  354. /* Send init config command to mark that we are sending NVM access
  355. * commands
  356. */
  357. ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
  358. INIT_EXTENDED_CFG_CMD), 0,
  359. sizeof(init_cfg), &init_cfg);
  360. if (ret) {
  361. IWL_ERR(mvm, "Failed to run init config command: %d\n",
  362. ret);
  363. goto error;
  364. }
  365. /* Load NVM to NIC if needed */
  366. if (mvm->nvm_file_name) {
  367. iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
  368. mvm->nvm_sections);
  369. iwl_mvm_load_nvm_to_nic(mvm);
  370. }
  371. if (IWL_MVM_PARSE_NVM && read_nvm) {
  372. ret = iwl_nvm_init(mvm);
  373. if (ret) {
  374. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  375. goto error;
  376. }
  377. }
  378. ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
  379. NVM_ACCESS_COMPLETE), 0,
  380. sizeof(nvm_complete), &nvm_complete);
  381. if (ret) {
  382. IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
  383. ret);
  384. goto error;
  385. }
  386. /* We wait for the INIT complete notification */
  387. ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
  388. MVM_UCODE_ALIVE_TIMEOUT);
  389. if (ret)
  390. return ret;
  391. /* Read the NVM only at driver load time, no need to do this twice */
  392. if (!IWL_MVM_PARSE_NVM && read_nvm) {
  393. mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
  394. if (IS_ERR(mvm->nvm_data)) {
  395. ret = PTR_ERR(mvm->nvm_data);
  396. mvm->nvm_data = NULL;
  397. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  398. return ret;
  399. }
  400. }
  401. return 0;
  402. error:
  403. iwl_remove_notification(&mvm->notif_wait, &init_wait);
  404. return ret;
  405. }
  406. static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
  407. {
  408. struct iwl_phy_cfg_cmd phy_cfg_cmd;
  409. enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
  410. /* Set parameters */
  411. phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
  412. /* set flags extra PHY configuration flags from the device's cfg */
  413. phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags);
  414. phy_cfg_cmd.calib_control.event_trigger =
  415. mvm->fw->default_calib[ucode_type].event_trigger;
  416. phy_cfg_cmd.calib_control.flow_trigger =
  417. mvm->fw->default_calib[ucode_type].flow_trigger;
  418. IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
  419. phy_cfg_cmd.phy_cfg);
  420. return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
  421. sizeof(phy_cfg_cmd), &phy_cfg_cmd);
  422. }
  423. int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  424. {
  425. struct iwl_notification_wait calib_wait;
  426. static const u16 init_complete[] = {
  427. INIT_COMPLETE_NOTIF,
  428. CALIB_RES_NOTIF_PHY_DB
  429. };
  430. int ret;
  431. if (iwl_mvm_has_unified_ucode(mvm))
  432. return iwl_run_unified_mvm_ucode(mvm, true);
  433. lockdep_assert_held(&mvm->mutex);
  434. if (WARN_ON_ONCE(mvm->calibrating))
  435. return 0;
  436. iwl_init_notification_wait(&mvm->notif_wait,
  437. &calib_wait,
  438. init_complete,
  439. ARRAY_SIZE(init_complete),
  440. iwl_wait_phy_db_entry,
  441. mvm->phy_db);
  442. /* Will also start the device */
  443. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
  444. if (ret) {
  445. IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
  446. goto remove_notif;
  447. }
  448. if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
  449. ret = iwl_mvm_send_bt_init_conf(mvm);
  450. if (ret)
  451. goto remove_notif;
  452. }
  453. /* Read the NVM only at driver load time, no need to do this twice */
  454. if (read_nvm) {
  455. ret = iwl_nvm_init(mvm);
  456. if (ret) {
  457. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  458. goto remove_notif;
  459. }
  460. }
  461. /* In case we read the NVM from external file, load it to the NIC */
  462. if (mvm->nvm_file_name)
  463. iwl_mvm_load_nvm_to_nic(mvm);
  464. WARN_ONCE(mvm->nvm_data->nvm_version < mvm->trans->cfg->nvm_ver,
  465. "Too old NVM version (0x%0x, required = 0x%0x)",
  466. mvm->nvm_data->nvm_version, mvm->trans->cfg->nvm_ver);
  467. /*
  468. * abort after reading the nvm in case RF Kill is on, we will complete
  469. * the init seq later when RF kill will switch to off
  470. */
  471. if (iwl_mvm_is_radio_hw_killed(mvm)) {
  472. IWL_DEBUG_RF_KILL(mvm,
  473. "jump over all phy activities due to RF kill\n");
  474. goto remove_notif;
  475. }
  476. mvm->calibrating = true;
  477. /* Send TX valid antennas before triggering calibrations */
  478. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  479. if (ret)
  480. goto remove_notif;
  481. ret = iwl_send_phy_cfg_cmd(mvm);
  482. if (ret) {
  483. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  484. ret);
  485. goto remove_notif;
  486. }
  487. /*
  488. * Some things may run in the background now, but we
  489. * just wait for the calibration complete notification.
  490. */
  491. ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
  492. MVM_UCODE_CALIB_TIMEOUT);
  493. if (!ret)
  494. goto out;
  495. if (iwl_mvm_is_radio_hw_killed(mvm)) {
  496. IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
  497. ret = 0;
  498. } else {
  499. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  500. ret);
  501. }
  502. goto out;
  503. remove_notif:
  504. iwl_remove_notification(&mvm->notif_wait, &calib_wait);
  505. out:
  506. mvm->calibrating = false;
  507. if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
  508. /* we want to debug INIT and we have no NVM - fake */
  509. mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
  510. sizeof(struct ieee80211_channel) +
  511. sizeof(struct ieee80211_rate),
  512. GFP_KERNEL);
  513. if (!mvm->nvm_data)
  514. return -ENOMEM;
  515. mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
  516. mvm->nvm_data->bands[0].n_channels = 1;
  517. mvm->nvm_data->bands[0].n_bitrates = 1;
  518. mvm->nvm_data->bands[0].bitrates =
  519. (void *)mvm->nvm_data->channels + 1;
  520. mvm->nvm_data->bands[0].bitrates->hw_value = 10;
  521. }
  522. return ret;
  523. }
  524. static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
  525. {
  526. struct iwl_ltr_config_cmd cmd = {
  527. .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
  528. };
  529. if (!mvm->trans->ltr_enabled)
  530. return 0;
  531. return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
  532. sizeof(cmd), &cmd);
  533. }
  534. #ifdef CONFIG_ACPI
  535. static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
  536. union acpi_object *table,
  537. struct iwl_mvm_sar_profile *profile,
  538. bool enabled)
  539. {
  540. int i;
  541. profile->enabled = enabled;
  542. for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
  543. if ((table[i].type != ACPI_TYPE_INTEGER) ||
  544. (table[i].integer.value > U8_MAX))
  545. return -EINVAL;
  546. profile->table[i] = table[i].integer.value;
  547. }
  548. return 0;
  549. }
  550. static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
  551. {
  552. union acpi_object *wifi_pkg, *table, *data;
  553. bool enabled;
  554. int ret;
  555. data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD);
  556. if (IS_ERR(data))
  557. return PTR_ERR(data);
  558. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  559. ACPI_WRDS_WIFI_DATA_SIZE);
  560. if (IS_ERR(wifi_pkg)) {
  561. ret = PTR_ERR(wifi_pkg);
  562. goto out_free;
  563. }
  564. if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
  565. ret = -EINVAL;
  566. goto out_free;
  567. }
  568. enabled = !!(wifi_pkg->package.elements[1].integer.value);
  569. /* position of the actual table */
  570. table = &wifi_pkg->package.elements[2];
  571. /* The profile from WRDS is officially profile 1, but goes
  572. * into sar_profiles[0] (because we don't have a profile 0).
  573. */
  574. ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
  575. enabled);
  576. out_free:
  577. kfree(data);
  578. return ret;
  579. }
  580. static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
  581. {
  582. union acpi_object *wifi_pkg, *data;
  583. bool enabled;
  584. int i, n_profiles, ret;
  585. data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD);
  586. if (IS_ERR(data))
  587. return PTR_ERR(data);
  588. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  589. ACPI_EWRD_WIFI_DATA_SIZE);
  590. if (IS_ERR(wifi_pkg)) {
  591. ret = PTR_ERR(wifi_pkg);
  592. goto out_free;
  593. }
  594. if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
  595. (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
  596. ret = -EINVAL;
  597. goto out_free;
  598. }
  599. enabled = !!(wifi_pkg->package.elements[1].integer.value);
  600. n_profiles = wifi_pkg->package.elements[2].integer.value;
  601. /*
  602. * Check the validity of n_profiles. The EWRD profiles start
  603. * from index 1, so the maximum value allowed here is
  604. * ACPI_SAR_PROFILES_NUM - 1.
  605. */
  606. if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) {
  607. ret = -EINVAL;
  608. goto out_free;
  609. }
  610. for (i = 0; i < n_profiles; i++) {
  611. /* the tables start at element 3 */
  612. int pos = 3;
  613. /* The EWRD profiles officially go from 2 to 4, but we
  614. * save them in sar_profiles[1-3] (because we don't
  615. * have profile 0). So in the array we start from 1.
  616. */
  617. ret = iwl_mvm_sar_set_profile(mvm,
  618. &wifi_pkg->package.elements[pos],
  619. &mvm->sar_profiles[i + 1],
  620. enabled);
  621. if (ret < 0)
  622. break;
  623. /* go to the next table */
  624. pos += ACPI_SAR_TABLE_SIZE;
  625. }
  626. out_free:
  627. kfree(data);
  628. return ret;
  629. }
  630. static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
  631. {
  632. union acpi_object *wifi_pkg, *data;
  633. int i, j, ret;
  634. int idx = 1;
  635. data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD);
  636. if (IS_ERR(data))
  637. return PTR_ERR(data);
  638. wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
  639. ACPI_WGDS_WIFI_DATA_SIZE);
  640. if (IS_ERR(wifi_pkg)) {
  641. ret = PTR_ERR(wifi_pkg);
  642. goto out_free;
  643. }
  644. for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
  645. for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
  646. union acpi_object *entry;
  647. entry = &wifi_pkg->package.elements[idx++];
  648. if ((entry->type != ACPI_TYPE_INTEGER) ||
  649. (entry->integer.value > U8_MAX)) {
  650. ret = -EINVAL;
  651. goto out_free;
  652. }
  653. mvm->geo_profiles[i].values[j] = entry->integer.value;
  654. }
  655. }
  656. ret = 0;
  657. out_free:
  658. kfree(data);
  659. return ret;
  660. }
  661. int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
  662. {
  663. struct iwl_dev_tx_power_cmd cmd = {
  664. .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
  665. };
  666. int i, j, idx;
  667. int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
  668. int len = sizeof(cmd);
  669. BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
  670. BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
  671. ACPI_SAR_TABLE_SIZE);
  672. if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
  673. len = sizeof(cmd.v3);
  674. for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
  675. struct iwl_mvm_sar_profile *prof;
  676. /* don't allow SAR to be disabled (profile 0 means disable) */
  677. if (profs[i] == 0)
  678. return -EPERM;
  679. /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
  680. if (profs[i] > ACPI_SAR_PROFILE_NUM)
  681. return -EINVAL;
  682. /* profiles go from 1 to 4, so decrement to access the array */
  683. prof = &mvm->sar_profiles[profs[i] - 1];
  684. /* if the profile is disabled, do nothing */
  685. if (!prof->enabled) {
  686. IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
  687. profs[i]);
  688. /* if one of the profiles is disabled, we fail all */
  689. return -ENOENT;
  690. }
  691. IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
  692. for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
  693. idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
  694. cmd.v3.per_chain_restriction[i][j] =
  695. cpu_to_le16(prof->table[idx]);
  696. IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
  697. j, prof->table[idx]);
  698. }
  699. }
  700. IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
  701. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
  702. }
  703. static bool iwl_mvm_sar_geo_support(struct iwl_mvm *mvm)
  704. {
  705. /*
  706. * The GEO_TX_POWER_LIMIT command is not supported on earlier
  707. * firmware versions. Unfortunately, we don't have a TLV API
  708. * flag to rely on, so rely on the major version which is in
  709. * the first byte of ucode_ver. This was implemented
  710. * initially on version 38 and then backported to 17. It was
  711. * also backported to 29, but only for 7265D devices. The
  712. * intention was to have it in 36 as well, but not all 8000
  713. * family got this feature enabled. The 8000 family is the
  714. * only one using version 36, so skip this version entirely.
  715. */
  716. return IWL_UCODE_SERIAL(mvm->fw->ucode_ver) >= 38 ||
  717. IWL_UCODE_SERIAL(mvm->fw->ucode_ver) == 17 ||
  718. (IWL_UCODE_SERIAL(mvm->fw->ucode_ver) == 29 &&
  719. ((mvm->trans->hw_rev & CSR_HW_REV_TYPE_MSK) ==
  720. CSR_HW_REV_TYPE_7265D));
  721. }
  722. int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
  723. {
  724. struct iwl_geo_tx_power_profiles_resp *resp;
  725. int ret;
  726. struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
  727. .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
  728. };
  729. struct iwl_host_cmd cmd = {
  730. .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
  731. .len = { sizeof(geo_cmd), },
  732. .flags = CMD_WANT_SKB,
  733. .data = { &geo_cmd },
  734. };
  735. if (!iwl_mvm_sar_geo_support(mvm))
  736. return -EOPNOTSUPP;
  737. ret = iwl_mvm_send_cmd(mvm, &cmd);
  738. if (ret) {
  739. IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
  740. return ret;
  741. }
  742. resp = (void *)cmd.resp_pkt->data;
  743. ret = le32_to_cpu(resp->profile_idx);
  744. if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
  745. ret = -EIO;
  746. IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
  747. }
  748. iwl_free_resp(&cmd);
  749. return ret;
  750. }
  751. static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
  752. {
  753. struct iwl_geo_tx_power_profiles_cmd cmd = {
  754. .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
  755. };
  756. int ret, i, j;
  757. u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
  758. if (!iwl_mvm_sar_geo_support(mvm))
  759. return 0;
  760. ret = iwl_mvm_sar_get_wgds_table(mvm);
  761. if (ret < 0) {
  762. IWL_DEBUG_RADIO(mvm,
  763. "Geo SAR BIOS table invalid or unavailable. (%d)\n",
  764. ret);
  765. /* we don't fail if the table is not available */
  766. return 0;
  767. }
  768. IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
  769. BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
  770. ACPI_WGDS_TABLE_SIZE + 1 != ACPI_WGDS_WIFI_DATA_SIZE);
  771. BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
  772. for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
  773. struct iwl_per_chain_offset *chain =
  774. (struct iwl_per_chain_offset *)&cmd.table[i];
  775. for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
  776. u8 *value;
  777. value = &mvm->geo_profiles[i].values[j *
  778. ACPI_GEO_PER_CHAIN_SIZE];
  779. chain[j].max_tx_power = cpu_to_le16(value[0]);
  780. chain[j].chain_a = value[1];
  781. chain[j].chain_b = value[2];
  782. IWL_DEBUG_RADIO(mvm,
  783. "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
  784. i, j, value[1], value[2], value[0]);
  785. }
  786. }
  787. return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
  788. }
  789. #else /* CONFIG_ACPI */
  790. static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
  791. {
  792. return -ENOENT;
  793. }
  794. static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
  795. {
  796. return -ENOENT;
  797. }
  798. static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
  799. {
  800. return -ENOENT;
  801. }
  802. static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
  803. {
  804. return 0;
  805. }
  806. int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a,
  807. int prof_b)
  808. {
  809. return -ENOENT;
  810. }
  811. int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
  812. {
  813. return -ENOENT;
  814. }
  815. #endif /* CONFIG_ACPI */
  816. static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
  817. {
  818. int ret;
  819. ret = iwl_mvm_sar_get_wrds_table(mvm);
  820. if (ret < 0) {
  821. IWL_DEBUG_RADIO(mvm,
  822. "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
  823. ret);
  824. /*
  825. * If not available, don't fail and don't bother with EWRD.
  826. * Return 1 to tell that we can't use WGDS either.
  827. */
  828. return 1;
  829. }
  830. ret = iwl_mvm_sar_get_ewrd_table(mvm);
  831. /* if EWRD is not available, we can still use WRDS, so don't fail */
  832. if (ret < 0)
  833. IWL_DEBUG_RADIO(mvm,
  834. "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
  835. ret);
  836. /* choose profile 1 (WRDS) as default for both chains */
  837. ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
  838. /*
  839. * If we don't have profile 0 from BIOS, just skip it. This
  840. * means that SAR Geo will not be enabled either, even if we
  841. * have other valid profiles.
  842. */
  843. if (ret == -ENOENT)
  844. return 1;
  845. return ret;
  846. }
  847. static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
  848. {
  849. int ret;
  850. if (iwl_mvm_has_unified_ucode(mvm))
  851. return iwl_run_unified_mvm_ucode(mvm, false);
  852. ret = iwl_run_init_mvm_ucode(mvm, false);
  853. if (ret) {
  854. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
  855. if (iwlmvm_mod_params.init_dbg)
  856. return 0;
  857. return ret;
  858. }
  859. /*
  860. * Stop and start the transport without entering low power
  861. * mode. This will save the state of other components on the
  862. * device that are triggered by the INIT firwmare (MFUART).
  863. */
  864. _iwl_trans_stop_device(mvm->trans, false);
  865. ret = _iwl_trans_start_hw(mvm->trans, false);
  866. if (ret)
  867. return ret;
  868. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  869. if (ret)
  870. return ret;
  871. return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
  872. }
  873. int iwl_mvm_up(struct iwl_mvm *mvm)
  874. {
  875. int ret, i;
  876. struct ieee80211_channel *chan;
  877. struct cfg80211_chan_def chandef;
  878. lockdep_assert_held(&mvm->mutex);
  879. ret = iwl_trans_start_hw(mvm->trans);
  880. if (ret)
  881. return ret;
  882. ret = iwl_mvm_load_rt_fw(mvm);
  883. if (ret) {
  884. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  885. goto error;
  886. }
  887. iwl_get_shared_mem_conf(&mvm->fwrt);
  888. ret = iwl_mvm_sf_update(mvm, NULL, false);
  889. if (ret)
  890. IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
  891. mvm->fwrt.dump.conf = FW_DBG_INVALID;
  892. /* if we have a destination, assume EARLY START */
  893. if (mvm->fw->dbg_dest_tlv)
  894. mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
  895. iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
  896. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  897. if (ret)
  898. goto error;
  899. if (!iwl_mvm_has_unified_ucode(mvm)) {
  900. /* Send phy db control command and then phy db calibration */
  901. ret = iwl_send_phy_db_data(mvm->phy_db);
  902. if (ret)
  903. goto error;
  904. ret = iwl_send_phy_cfg_cmd(mvm);
  905. if (ret)
  906. goto error;
  907. }
  908. ret = iwl_mvm_send_bt_init_conf(mvm);
  909. if (ret)
  910. goto error;
  911. /* Init RSS configuration */
  912. if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
  913. ret = iwl_configure_rxq(mvm);
  914. if (ret) {
  915. IWL_ERR(mvm, "Failed to configure RX queues: %d\n",
  916. ret);
  917. goto error;
  918. }
  919. }
  920. if (iwl_mvm_has_new_rx_api(mvm)) {
  921. ret = iwl_send_rss_cfg_cmd(mvm);
  922. if (ret) {
  923. IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
  924. ret);
  925. goto error;
  926. }
  927. }
  928. /* init the fw <-> mac80211 STA mapping */
  929. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
  930. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  931. mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
  932. /* reset quota debouncing buffer - 0xff will yield invalid data */
  933. memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
  934. ret = iwl_mvm_send_dqa_cmd(mvm);
  935. if (ret)
  936. goto error;
  937. /* Add auxiliary station for scanning */
  938. ret = iwl_mvm_add_aux_sta(mvm);
  939. if (ret)
  940. goto error;
  941. /* Add all the PHY contexts */
  942. chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
  943. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
  944. for (i = 0; i < NUM_PHY_CTX; i++) {
  945. /*
  946. * The channel used here isn't relevant as it's
  947. * going to be overwritten in the other flows.
  948. * For now use the first channel we have.
  949. */
  950. ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
  951. &chandef, 1, 1);
  952. if (ret)
  953. goto error;
  954. }
  955. #ifdef CONFIG_THERMAL
  956. if (iwl_mvm_is_tt_in_fw(mvm)) {
  957. /* in order to give the responsibility of ct-kill and
  958. * TX backoff to FW we need to send empty temperature reporting
  959. * cmd during init time
  960. */
  961. iwl_mvm_send_temp_report_ths_cmd(mvm);
  962. } else {
  963. /* Initialize tx backoffs to the minimal possible */
  964. iwl_mvm_tt_tx_backoff(mvm, 0);
  965. }
  966. /* TODO: read the budget from BIOS / Platform NVM */
  967. /*
  968. * In case there is no budget from BIOS / Platform NVM the default
  969. * budget should be 2000mW (cooling state 0).
  970. */
  971. if (iwl_mvm_is_ctdp_supported(mvm)) {
  972. ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
  973. mvm->cooling_dev.cur_state);
  974. if (ret)
  975. goto error;
  976. }
  977. #else
  978. /* Initialize tx backoffs to the minimal possible */
  979. iwl_mvm_tt_tx_backoff(mvm, 0);
  980. #endif
  981. WARN_ON(iwl_mvm_config_ltr(mvm));
  982. ret = iwl_mvm_power_update_device(mvm);
  983. if (ret)
  984. goto error;
  985. /*
  986. * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
  987. * anyway, so don't init MCC.
  988. */
  989. if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
  990. ret = iwl_mvm_init_mcc(mvm);
  991. if (ret)
  992. goto error;
  993. }
  994. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  995. mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
  996. mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
  997. ret = iwl_mvm_config_scan(mvm);
  998. if (ret)
  999. goto error;
  1000. }
  1001. /* allow FW/transport low power modes if not during restart */
  1002. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1003. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  1004. ret = iwl_mvm_sar_init(mvm);
  1005. if (ret == 0) {
  1006. ret = iwl_mvm_sar_geo_init(mvm);
  1007. } else if (ret > 0 && !iwl_mvm_sar_get_wgds_table(mvm)) {
  1008. /*
  1009. * If basic SAR is not available, we check for WGDS,
  1010. * which should *not* be available either. If it is
  1011. * available, issue an error, because we can't use SAR
  1012. * Geo without basic SAR.
  1013. */
  1014. IWL_ERR(mvm, "BIOS contains WGDS but no WRDS\n");
  1015. }
  1016. if (ret < 0)
  1017. goto error;
  1018. iwl_mvm_leds_sync(mvm);
  1019. IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
  1020. return 0;
  1021. error:
  1022. if (!iwlmvm_mod_params.init_dbg || !ret)
  1023. iwl_mvm_stop_device(mvm);
  1024. return ret;
  1025. }
  1026. int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
  1027. {
  1028. int ret, i;
  1029. lockdep_assert_held(&mvm->mutex);
  1030. ret = iwl_trans_start_hw(mvm->trans);
  1031. if (ret)
  1032. return ret;
  1033. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
  1034. if (ret) {
  1035. IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
  1036. goto error;
  1037. }
  1038. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  1039. if (ret)
  1040. goto error;
  1041. /* Send phy db control command and then phy db calibration*/
  1042. ret = iwl_send_phy_db_data(mvm->phy_db);
  1043. if (ret)
  1044. goto error;
  1045. ret = iwl_send_phy_cfg_cmd(mvm);
  1046. if (ret)
  1047. goto error;
  1048. /* init the fw <-> mac80211 STA mapping */
  1049. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
  1050. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  1051. /* Add auxiliary station for scanning */
  1052. ret = iwl_mvm_add_aux_sta(mvm);
  1053. if (ret)
  1054. goto error;
  1055. return 0;
  1056. error:
  1057. iwl_mvm_stop_device(mvm);
  1058. return ret;
  1059. }
  1060. void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
  1061. struct iwl_rx_cmd_buffer *rxb)
  1062. {
  1063. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1064. struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
  1065. u32 flags = le32_to_cpu(card_state_notif->flags);
  1066. IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
  1067. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1068. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  1069. (flags & CT_KILL_CARD_DISABLED) ?
  1070. "Reached" : "Not reached");
  1071. }
  1072. void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
  1073. struct iwl_rx_cmd_buffer *rxb)
  1074. {
  1075. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1076. struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
  1077. IWL_DEBUG_INFO(mvm,
  1078. "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
  1079. le32_to_cpu(mfuart_notif->installed_ver),
  1080. le32_to_cpu(mfuart_notif->external_ver),
  1081. le32_to_cpu(mfuart_notif->status),
  1082. le32_to_cpu(mfuart_notif->duration));
  1083. if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
  1084. IWL_DEBUG_INFO(mvm,
  1085. "MFUART: image size: 0x%08x\n",
  1086. le32_to_cpu(mfuart_notif->image_size));
  1087. }