fw.c 35 KB

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