fw.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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 "iwl-fw.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_free_fw_paging(struct iwl_mvm *mvm)
  133. {
  134. int i;
  135. if (!mvm->fw_paging_db[0].fw_paging_block)
  136. return;
  137. for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) {
  138. struct iwl_fw_paging *paging = &mvm->fw_paging_db[i];
  139. if (!paging->fw_paging_block) {
  140. IWL_DEBUG_FW(mvm,
  141. "Paging: block %d already freed, continue to next page\n",
  142. i);
  143. continue;
  144. }
  145. dma_unmap_page(mvm->trans->dev, paging->fw_paging_phys,
  146. paging->fw_paging_size, DMA_BIDIRECTIONAL);
  147. __free_pages(paging->fw_paging_block,
  148. get_order(paging->fw_paging_size));
  149. paging->fw_paging_block = NULL;
  150. }
  151. kfree(mvm->trans->paging_download_buf);
  152. mvm->trans->paging_download_buf = NULL;
  153. mvm->trans->paging_db = NULL;
  154. memset(mvm->fw_paging_db, 0, sizeof(mvm->fw_paging_db));
  155. }
  156. static int iwl_fill_paging_mem(struct iwl_mvm *mvm, const struct fw_img *image)
  157. {
  158. int sec_idx, idx;
  159. u32 offset = 0;
  160. /*
  161. * find where is the paging image start point:
  162. * if CPU2 exist and it's in paging format, then the image looks like:
  163. * CPU1 sections (2 or more)
  164. * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2
  165. * CPU2 sections (not paged)
  166. * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2
  167. * non paged to CPU2 paging sec
  168. * CPU2 paging CSS
  169. * CPU2 paging image (including instruction and data)
  170. */
  171. for (sec_idx = 0; sec_idx < image->num_sec; sec_idx++) {
  172. if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) {
  173. sec_idx++;
  174. break;
  175. }
  176. }
  177. /*
  178. * If paging is enabled there should be at least 2 more sections left
  179. * (one for CSS and one for Paging data)
  180. */
  181. if (sec_idx >= image->num_sec - 1) {
  182. IWL_ERR(mvm, "Paging: Missing CSS and/or paging sections\n");
  183. iwl_free_fw_paging(mvm);
  184. return -EINVAL;
  185. }
  186. /* copy the CSS block to the dram */
  187. IWL_DEBUG_FW(mvm, "Paging: load paging CSS to FW, sec = %d\n",
  188. sec_idx);
  189. memcpy(page_address(mvm->fw_paging_db[0].fw_paging_block),
  190. image->sec[sec_idx].data,
  191. mvm->fw_paging_db[0].fw_paging_size);
  192. dma_sync_single_for_device(mvm->trans->dev,
  193. mvm->fw_paging_db[0].fw_paging_phys,
  194. mvm->fw_paging_db[0].fw_paging_size,
  195. DMA_BIDIRECTIONAL);
  196. IWL_DEBUG_FW(mvm,
  197. "Paging: copied %d CSS bytes to first block\n",
  198. mvm->fw_paging_db[0].fw_paging_size);
  199. sec_idx++;
  200. /*
  201. * copy the paging blocks to the dram
  202. * loop index start from 1 since that CSS block already copied to dram
  203. * and CSS index is 0.
  204. * loop stop at num_of_paging_blk since that last block is not full.
  205. */
  206. for (idx = 1; idx < mvm->num_of_paging_blk; idx++) {
  207. struct iwl_fw_paging *block = &mvm->fw_paging_db[idx];
  208. memcpy(page_address(block->fw_paging_block),
  209. image->sec[sec_idx].data + offset,
  210. block->fw_paging_size);
  211. dma_sync_single_for_device(mvm->trans->dev,
  212. block->fw_paging_phys,
  213. block->fw_paging_size,
  214. DMA_BIDIRECTIONAL);
  215. IWL_DEBUG_FW(mvm,
  216. "Paging: copied %d paging bytes to block %d\n",
  217. mvm->fw_paging_db[idx].fw_paging_size,
  218. idx);
  219. offset += mvm->fw_paging_db[idx].fw_paging_size;
  220. }
  221. /* copy the last paging block */
  222. if (mvm->num_of_pages_in_last_blk > 0) {
  223. struct iwl_fw_paging *block = &mvm->fw_paging_db[idx];
  224. memcpy(page_address(block->fw_paging_block),
  225. image->sec[sec_idx].data + offset,
  226. FW_PAGING_SIZE * mvm->num_of_pages_in_last_blk);
  227. dma_sync_single_for_device(mvm->trans->dev,
  228. block->fw_paging_phys,
  229. block->fw_paging_size,
  230. DMA_BIDIRECTIONAL);
  231. IWL_DEBUG_FW(mvm,
  232. "Paging: copied %d pages in the last block %d\n",
  233. mvm->num_of_pages_in_last_blk, idx);
  234. }
  235. return 0;
  236. }
  237. void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
  238. struct iwl_rx_cmd_buffer *rxb)
  239. {
  240. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  241. struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
  242. __le32 *dump_data = mfu_dump_notif->data;
  243. int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
  244. int i;
  245. if (mfu_dump_notif->index_num == 0)
  246. IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
  247. le32_to_cpu(mfu_dump_notif->assert_id));
  248. for (i = 0; i < n_words; i++)
  249. IWL_DEBUG_INFO(mvm,
  250. "MFUART assert dump, dword %u: 0x%08x\n",
  251. le16_to_cpu(mfu_dump_notif->index_num) *
  252. n_words + i,
  253. le32_to_cpu(dump_data[i]));
  254. }
  255. static int iwl_alloc_fw_paging_mem(struct iwl_mvm *mvm,
  256. const struct fw_img *image)
  257. {
  258. struct page *block;
  259. dma_addr_t phys = 0;
  260. int blk_idx, order, num_of_pages, size, dma_enabled;
  261. if (mvm->fw_paging_db[0].fw_paging_block)
  262. return 0;
  263. dma_enabled = is_device_dma_capable(mvm->trans->dev);
  264. /* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */
  265. BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE);
  266. num_of_pages = image->paging_mem_size / FW_PAGING_SIZE;
  267. mvm->num_of_paging_blk =
  268. DIV_ROUND_UP(num_of_pages, NUM_OF_PAGE_PER_GROUP);
  269. mvm->num_of_pages_in_last_blk =
  270. num_of_pages -
  271. NUM_OF_PAGE_PER_GROUP * (mvm->num_of_paging_blk - 1);
  272. IWL_DEBUG_FW(mvm,
  273. "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n",
  274. mvm->num_of_paging_blk,
  275. mvm->num_of_pages_in_last_blk);
  276. /*
  277. * Allocate CSS and paging blocks in dram.
  278. */
  279. for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
  280. /* For CSS allocate 4KB, for others PAGING_BLOCK_SIZE (32K) */
  281. size = blk_idx ? PAGING_BLOCK_SIZE : FW_PAGING_SIZE;
  282. order = get_order(size);
  283. block = alloc_pages(GFP_KERNEL, order);
  284. if (!block) {
  285. /* free all the previous pages since we failed */
  286. iwl_free_fw_paging(mvm);
  287. return -ENOMEM;
  288. }
  289. mvm->fw_paging_db[blk_idx].fw_paging_block = block;
  290. mvm->fw_paging_db[blk_idx].fw_paging_size = size;
  291. if (dma_enabled) {
  292. phys = dma_map_page(mvm->trans->dev, block, 0,
  293. PAGE_SIZE << order,
  294. DMA_BIDIRECTIONAL);
  295. if (dma_mapping_error(mvm->trans->dev, phys)) {
  296. /*
  297. * free the previous pages and the current one
  298. * since we failed to map_page.
  299. */
  300. iwl_free_fw_paging(mvm);
  301. return -ENOMEM;
  302. }
  303. mvm->fw_paging_db[blk_idx].fw_paging_phys = phys;
  304. } else {
  305. mvm->fw_paging_db[blk_idx].fw_paging_phys =
  306. PAGING_ADDR_SIG |
  307. blk_idx << BLOCK_2_EXP_SIZE;
  308. }
  309. if (!blk_idx)
  310. IWL_DEBUG_FW(mvm,
  311. "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n",
  312. order);
  313. else
  314. IWL_DEBUG_FW(mvm,
  315. "Paging: allocated 32K bytes (order %d) for firmware paging.\n",
  316. order);
  317. }
  318. return 0;
  319. }
  320. static int iwl_save_fw_paging(struct iwl_mvm *mvm,
  321. const struct fw_img *fw)
  322. {
  323. int ret;
  324. ret = iwl_alloc_fw_paging_mem(mvm, fw);
  325. if (ret)
  326. return ret;
  327. return iwl_fill_paging_mem(mvm, fw);
  328. }
  329. /* send paging cmd to FW in case CPU2 has paging image */
  330. static int iwl_send_paging_cmd(struct iwl_mvm *mvm, const struct fw_img *fw)
  331. {
  332. struct iwl_fw_paging_cmd paging_cmd = {
  333. .flags =
  334. cpu_to_le32(PAGING_CMD_IS_SECURED |
  335. PAGING_CMD_IS_ENABLED |
  336. (mvm->num_of_pages_in_last_blk <<
  337. PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)),
  338. .block_size = cpu_to_le32(BLOCK_2_EXP_SIZE),
  339. .block_num = cpu_to_le32(mvm->num_of_paging_blk),
  340. };
  341. int blk_idx, size = sizeof(paging_cmd);
  342. /* A bit hard coded - but this is the old API and will be deprecated */
  343. if (!iwl_mvm_has_new_tx_api(mvm))
  344. size -= NUM_OF_FW_PAGING_BLOCKS * 4;
  345. /* loop for for all paging blocks + CSS block */
  346. for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
  347. dma_addr_t addr = mvm->fw_paging_db[blk_idx].fw_paging_phys;
  348. addr = addr >> PAGE_2_EXP_SIZE;
  349. if (iwl_mvm_has_new_tx_api(mvm)) {
  350. __le64 phy_addr = cpu_to_le64(addr);
  351. paging_cmd.device_phy_addr.addr64[blk_idx] = phy_addr;
  352. } else {
  353. __le32 phy_addr = cpu_to_le32(addr);
  354. paging_cmd.device_phy_addr.addr32[blk_idx] = phy_addr;
  355. }
  356. }
  357. return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(FW_PAGING_BLOCK_CMD,
  358. IWL_ALWAYS_LONG_GROUP, 0),
  359. 0, size, &paging_cmd);
  360. }
  361. /*
  362. * Send paging item cmd to FW in case CPU2 has paging image
  363. */
  364. static int iwl_trans_get_paging_item(struct iwl_mvm *mvm)
  365. {
  366. int ret;
  367. struct iwl_fw_get_item_cmd fw_get_item_cmd = {
  368. .item_id = cpu_to_le32(IWL_FW_ITEM_ID_PAGING),
  369. };
  370. struct iwl_fw_get_item_resp *item_resp;
  371. struct iwl_host_cmd cmd = {
  372. .id = iwl_cmd_id(FW_GET_ITEM_CMD, IWL_ALWAYS_LONG_GROUP, 0),
  373. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  374. .data = { &fw_get_item_cmd, },
  375. };
  376. cmd.len[0] = sizeof(struct iwl_fw_get_item_cmd);
  377. ret = iwl_mvm_send_cmd(mvm, &cmd);
  378. if (ret) {
  379. IWL_ERR(mvm,
  380. "Paging: Failed to send FW_GET_ITEM_CMD cmd (err = %d)\n",
  381. ret);
  382. return ret;
  383. }
  384. item_resp = (void *)((struct iwl_rx_packet *)cmd.resp_pkt)->data;
  385. if (item_resp->item_id != cpu_to_le32(IWL_FW_ITEM_ID_PAGING)) {
  386. IWL_ERR(mvm,
  387. "Paging: got wrong item in FW_GET_ITEM_CMD resp (item_id = %u)\n",
  388. le32_to_cpu(item_resp->item_id));
  389. ret = -EIO;
  390. goto exit;
  391. }
  392. /* Add an extra page for headers */
  393. mvm->trans->paging_download_buf = kzalloc(PAGING_BLOCK_SIZE +
  394. FW_PAGING_SIZE,
  395. GFP_KERNEL);
  396. if (!mvm->trans->paging_download_buf) {
  397. ret = -ENOMEM;
  398. goto exit;
  399. }
  400. mvm->trans->paging_req_addr = le32_to_cpu(item_resp->item_val);
  401. mvm->trans->paging_db = mvm->fw_paging_db;
  402. IWL_DEBUG_FW(mvm,
  403. "Paging: got paging request address (paging_req_addr 0x%08x)\n",
  404. mvm->trans->paging_req_addr);
  405. exit:
  406. iwl_free_resp(&cmd);
  407. return ret;
  408. }
  409. static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
  410. struct iwl_rx_packet *pkt, void *data)
  411. {
  412. struct iwl_mvm *mvm =
  413. container_of(notif_wait, struct iwl_mvm, notif_wait);
  414. struct iwl_mvm_alive_data *alive_data = data;
  415. struct mvm_alive_resp_v3 *palive3;
  416. struct mvm_alive_resp *palive;
  417. struct iwl_umac_alive *umac;
  418. struct iwl_lmac_alive *lmac1;
  419. struct iwl_lmac_alive *lmac2 = NULL;
  420. u16 status;
  421. if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
  422. palive = (void *)pkt->data;
  423. umac = &palive->umac_data;
  424. lmac1 = &palive->lmac_data[0];
  425. lmac2 = &palive->lmac_data[1];
  426. status = le16_to_cpu(palive->status);
  427. } else {
  428. palive3 = (void *)pkt->data;
  429. umac = &palive3->umac_data;
  430. lmac1 = &palive3->lmac_data;
  431. status = le16_to_cpu(palive3->status);
  432. }
  433. mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
  434. if (lmac2)
  435. mvm->error_event_table[1] =
  436. le32_to_cpu(lmac2->error_event_table_ptr);
  437. mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
  438. mvm->sf_space.addr = le32_to_cpu(lmac1->st_fwrd_addr);
  439. mvm->sf_space.size = le32_to_cpu(lmac1->st_fwrd_size);
  440. mvm->umac_error_event_table = le32_to_cpu(umac->error_info_addr);
  441. alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
  442. alive_data->valid = status == IWL_ALIVE_STATUS_OK;
  443. if (mvm->umac_error_event_table)
  444. mvm->support_umac_log = true;
  445. IWL_DEBUG_FW(mvm,
  446. "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
  447. status, lmac1->ver_type, lmac1->ver_subtype);
  448. if (lmac2)
  449. IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
  450. IWL_DEBUG_FW(mvm,
  451. "UMAC version: Major - 0x%x, Minor - 0x%x\n",
  452. le32_to_cpu(umac->umac_major),
  453. le32_to_cpu(umac->umac_minor));
  454. return true;
  455. }
  456. static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
  457. struct iwl_rx_packet *pkt, void *data)
  458. {
  459. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  460. return true;
  461. }
  462. static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
  463. struct iwl_rx_packet *pkt, void *data)
  464. {
  465. struct iwl_phy_db *phy_db = data;
  466. if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
  467. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  468. return true;
  469. }
  470. WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
  471. return false;
  472. }
  473. static int iwl_mvm_init_paging(struct iwl_mvm *mvm)
  474. {
  475. const struct fw_img *fw = &mvm->fw->img[mvm->cur_ucode];
  476. int ret;
  477. /*
  478. * Configure and operate fw paging mechanism.
  479. * The driver configures the paging flow only once.
  480. * The CPU2 paging image is included in the IWL_UCODE_INIT image.
  481. */
  482. if (!fw->paging_mem_size)
  483. return 0;
  484. /*
  485. * When dma is not enabled, the driver needs to copy / write
  486. * the downloaded / uploaded page to / from the smem.
  487. * This gets the location of the place were the pages are
  488. * stored.
  489. */
  490. if (!is_device_dma_capable(mvm->trans->dev)) {
  491. ret = iwl_trans_get_paging_item(mvm);
  492. if (ret) {
  493. IWL_ERR(mvm, "failed to get FW paging item\n");
  494. return ret;
  495. }
  496. }
  497. ret = iwl_save_fw_paging(mvm, fw);
  498. if (ret) {
  499. IWL_ERR(mvm, "failed to save the FW paging image\n");
  500. return ret;
  501. }
  502. ret = iwl_send_paging_cmd(mvm, fw);
  503. if (ret) {
  504. IWL_ERR(mvm, "failed to send the paging cmd\n");
  505. iwl_free_fw_paging(mvm);
  506. return ret;
  507. }
  508. return 0;
  509. }
  510. static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
  511. enum iwl_ucode_type ucode_type)
  512. {
  513. struct iwl_notification_wait alive_wait;
  514. struct iwl_mvm_alive_data alive_data;
  515. const struct fw_img *fw;
  516. int ret, i;
  517. enum iwl_ucode_type old_type = mvm->cur_ucode;
  518. static const u16 alive_cmd[] = { MVM_ALIVE };
  519. struct iwl_sf_region st_fwrd_space;
  520. if (ucode_type == IWL_UCODE_REGULAR &&
  521. iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
  522. !(fw_has_capa(&mvm->fw->ucode_capa,
  523. IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
  524. fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
  525. else
  526. fw = iwl_get_ucode_image(mvm->fw, ucode_type);
  527. if (WARN_ON(!fw))
  528. return -EINVAL;
  529. mvm->cur_ucode = ucode_type;
  530. mvm->ucode_loaded = false;
  531. iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
  532. alive_cmd, ARRAY_SIZE(alive_cmd),
  533. iwl_alive_fn, &alive_data);
  534. ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
  535. if (ret) {
  536. mvm->cur_ucode = old_type;
  537. iwl_remove_notification(&mvm->notif_wait, &alive_wait);
  538. return ret;
  539. }
  540. /*
  541. * Some things may run in the background now, but we
  542. * just wait for the ALIVE notification here.
  543. */
  544. ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
  545. MVM_UCODE_ALIVE_TIMEOUT);
  546. if (ret) {
  547. struct iwl_trans *trans = mvm->trans;
  548. if (trans->cfg->gen2)
  549. IWL_ERR(mvm,
  550. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  551. iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
  552. iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
  553. else if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  554. IWL_ERR(mvm,
  555. "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
  556. iwl_read_prph(trans, SB_CPU_1_STATUS),
  557. iwl_read_prph(trans, SB_CPU_2_STATUS));
  558. mvm->cur_ucode = old_type;
  559. return ret;
  560. }
  561. if (!alive_data.valid) {
  562. IWL_ERR(mvm, "Loaded ucode is not valid!\n");
  563. mvm->cur_ucode = old_type;
  564. return -EIO;
  565. }
  566. /*
  567. * update the sdio allocation according to the pointer we get in the
  568. * alive notification.
  569. */
  570. st_fwrd_space.addr = mvm->sf_space.addr;
  571. st_fwrd_space.size = mvm->sf_space.size;
  572. ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
  573. if (ret) {
  574. IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
  575. return ret;
  576. }
  577. iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
  578. /*
  579. * Note: all the queues are enabled as part of the interface
  580. * initialization, but in firmware restart scenarios they
  581. * could be stopped, so wake them up. In firmware restart,
  582. * mac80211 will have the queues stopped as well until the
  583. * reconfiguration completes. During normal startup, they
  584. * will be empty.
  585. */
  586. memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
  587. if (iwl_mvm_is_dqa_supported(mvm))
  588. mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
  589. else
  590. mvm->queue_info[IWL_MVM_CMD_QUEUE].hw_queue_refcount = 1;
  591. for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
  592. atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
  593. mvm->ucode_loaded = true;
  594. return 0;
  595. }
  596. static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
  597. {
  598. struct iwl_phy_cfg_cmd phy_cfg_cmd;
  599. enum iwl_ucode_type ucode_type = mvm->cur_ucode;
  600. /* Set parameters */
  601. phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
  602. phy_cfg_cmd.calib_control.event_trigger =
  603. mvm->fw->default_calib[ucode_type].event_trigger;
  604. phy_cfg_cmd.calib_control.flow_trigger =
  605. mvm->fw->default_calib[ucode_type].flow_trigger;
  606. IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
  607. phy_cfg_cmd.phy_cfg);
  608. return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
  609. sizeof(phy_cfg_cmd), &phy_cfg_cmd);
  610. }
  611. int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  612. {
  613. struct iwl_notification_wait calib_wait;
  614. static const u16 init_complete[] = {
  615. INIT_COMPLETE_NOTIF,
  616. CALIB_RES_NOTIF_PHY_DB
  617. };
  618. int ret;
  619. lockdep_assert_held(&mvm->mutex);
  620. if (WARN_ON_ONCE(mvm->calibrating))
  621. return 0;
  622. iwl_init_notification_wait(&mvm->notif_wait,
  623. &calib_wait,
  624. init_complete,
  625. ARRAY_SIZE(init_complete),
  626. iwl_wait_phy_db_entry,
  627. mvm->phy_db);
  628. /* Will also start the device */
  629. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
  630. if (ret) {
  631. IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
  632. goto error;
  633. }
  634. ret = iwl_send_bt_init_conf(mvm);
  635. if (ret)
  636. goto error;
  637. /* Read the NVM only at driver load time, no need to do this twice */
  638. if (read_nvm) {
  639. /* Read nvm */
  640. ret = iwl_nvm_init(mvm, true);
  641. if (ret) {
  642. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  643. goto error;
  644. }
  645. }
  646. /* In case we read the NVM from external file, load it to the NIC */
  647. if (mvm->nvm_file_name)
  648. iwl_mvm_load_nvm_to_nic(mvm);
  649. ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
  650. WARN_ON(ret);
  651. /*
  652. * abort after reading the nvm in case RF Kill is on, we will complete
  653. * the init seq later when RF kill will switch to off
  654. */
  655. if (iwl_mvm_is_radio_hw_killed(mvm)) {
  656. IWL_DEBUG_RF_KILL(mvm,
  657. "jump over all phy activities due to RF kill\n");
  658. iwl_remove_notification(&mvm->notif_wait, &calib_wait);
  659. ret = 1;
  660. goto out;
  661. }
  662. mvm->calibrating = true;
  663. /* Send TX valid antennas before triggering calibrations */
  664. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  665. if (ret)
  666. goto error;
  667. /*
  668. * Send phy configurations command to init uCode
  669. * to start the 16.0 uCode init image internal calibrations.
  670. */
  671. ret = iwl_send_phy_cfg_cmd(mvm);
  672. if (ret) {
  673. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  674. ret);
  675. goto error;
  676. }
  677. /*
  678. * Some things may run in the background now, but we
  679. * just wait for the calibration complete notification.
  680. */
  681. ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
  682. MVM_UCODE_CALIB_TIMEOUT);
  683. if (ret && iwl_mvm_is_radio_hw_killed(mvm)) {
  684. IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
  685. ret = 1;
  686. }
  687. goto out;
  688. error:
  689. iwl_remove_notification(&mvm->notif_wait, &calib_wait);
  690. out:
  691. mvm->calibrating = false;
  692. if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
  693. /* we want to debug INIT and we have no NVM - fake */
  694. mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
  695. sizeof(struct ieee80211_channel) +
  696. sizeof(struct ieee80211_rate),
  697. GFP_KERNEL);
  698. if (!mvm->nvm_data)
  699. return -ENOMEM;
  700. mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
  701. mvm->nvm_data->bands[0].n_channels = 1;
  702. mvm->nvm_data->bands[0].n_bitrates = 1;
  703. mvm->nvm_data->bands[0].bitrates =
  704. (void *)mvm->nvm_data->channels + 1;
  705. mvm->nvm_data->bands[0].bitrates->hw_value = 10;
  706. }
  707. return ret;
  708. }
  709. int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  710. {
  711. struct iwl_notification_wait init_wait;
  712. struct iwl_nvm_access_complete_cmd nvm_complete = {};
  713. static const u16 init_complete[] = {
  714. INIT_COMPLETE_NOTIF,
  715. };
  716. int ret;
  717. lockdep_assert_held(&mvm->mutex);
  718. iwl_init_notification_wait(&mvm->notif_wait,
  719. &init_wait,
  720. init_complete,
  721. ARRAY_SIZE(init_complete),
  722. iwl_wait_init_complete,
  723. NULL);
  724. /* Will also start the device */
  725. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  726. if (ret) {
  727. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  728. goto error;
  729. }
  730. /* Read the NVM only at driver load time, no need to do this twice */
  731. if (read_nvm) {
  732. /* Read nvm */
  733. ret = iwl_nvm_init(mvm, true);
  734. if (ret) {
  735. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  736. goto error;
  737. }
  738. }
  739. /* In case we read the NVM from external file, load it to the NIC */
  740. if (mvm->nvm_file_name)
  741. iwl_mvm_load_nvm_to_nic(mvm);
  742. ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
  743. if (WARN_ON(ret))
  744. goto error;
  745. ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
  746. NVM_ACCESS_COMPLETE), 0,
  747. sizeof(nvm_complete), &nvm_complete);
  748. if (ret) {
  749. IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
  750. ret);
  751. goto error;
  752. }
  753. /* We wait for the INIT complete notification */
  754. return iwl_wait_notification(&mvm->notif_wait, &init_wait,
  755. MVM_UCODE_ALIVE_TIMEOUT);
  756. error:
  757. iwl_remove_notification(&mvm->notif_wait, &init_wait);
  758. return ret;
  759. }
  760. static void iwl_mvm_parse_shared_mem_a000(struct iwl_mvm *mvm,
  761. struct iwl_rx_packet *pkt)
  762. {
  763. struct iwl_shared_mem_cfg *mem_cfg = (void *)pkt->data;
  764. int i;
  765. mvm->shared_mem_cfg.num_txfifo_entries =
  766. ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size);
  767. for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++)
  768. mvm->shared_mem_cfg.txfifo_size[i] =
  769. le32_to_cpu(mem_cfg->txfifo_size[i]);
  770. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
  771. mvm->shared_mem_cfg.rxfifo_size[i] =
  772. le32_to_cpu(mem_cfg->rxfifo_size[i]);
  773. BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) !=
  774. sizeof(mem_cfg->internal_txfifo_size));
  775. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
  776. i++)
  777. mvm->shared_mem_cfg.internal_txfifo_size[i] =
  778. le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
  779. }
  780. static void iwl_mvm_parse_shared_mem(struct iwl_mvm *mvm,
  781. struct iwl_rx_packet *pkt)
  782. {
  783. struct iwl_shared_mem_cfg_v1 *mem_cfg = (void *)pkt->data;
  784. int i;
  785. mvm->shared_mem_cfg.num_txfifo_entries =
  786. ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size);
  787. for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++)
  788. mvm->shared_mem_cfg.txfifo_size[i] =
  789. le32_to_cpu(mem_cfg->txfifo_size[i]);
  790. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
  791. mvm->shared_mem_cfg.rxfifo_size[i] =
  792. le32_to_cpu(mem_cfg->rxfifo_size[i]);
  793. /* new API has more data, from rxfifo_addr field and on */
  794. if (fw_has_capa(&mvm->fw->ucode_capa,
  795. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  796. BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) !=
  797. sizeof(mem_cfg->internal_txfifo_size));
  798. for (i = 0;
  799. i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
  800. i++)
  801. mvm->shared_mem_cfg.internal_txfifo_size[i] =
  802. le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
  803. }
  804. }
  805. static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm)
  806. {
  807. struct iwl_host_cmd cmd = {
  808. .flags = CMD_WANT_SKB,
  809. .data = { NULL, },
  810. .len = { 0, },
  811. };
  812. struct iwl_rx_packet *pkt;
  813. lockdep_assert_held(&mvm->mutex);
  814. if (fw_has_capa(&mvm->fw->ucode_capa,
  815. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
  816. cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0);
  817. else
  818. cmd.id = SHARED_MEM_CFG;
  819. if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd)))
  820. return;
  821. pkt = cmd.resp_pkt;
  822. if (iwl_mvm_has_new_tx_api(mvm))
  823. iwl_mvm_parse_shared_mem_a000(mvm, pkt);
  824. else
  825. iwl_mvm_parse_shared_mem(mvm, pkt);
  826. IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n");
  827. iwl_free_resp(&cmd);
  828. }
  829. static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
  830. {
  831. struct iwl_ltr_config_cmd cmd = {
  832. .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
  833. };
  834. if (!mvm->trans->ltr_enabled)
  835. return 0;
  836. return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
  837. sizeof(cmd), &cmd);
  838. }
  839. #define ACPI_WRDS_METHOD "WRDS"
  840. #define ACPI_WRDS_WIFI (0x07)
  841. #define ACPI_WRDS_TABLE_SIZE 10
  842. struct iwl_mvm_sar_table {
  843. bool enabled;
  844. u8 values[ACPI_WRDS_TABLE_SIZE];
  845. };
  846. #ifdef CONFIG_ACPI
  847. static int iwl_mvm_sar_get_wrds(struct iwl_mvm *mvm, union acpi_object *wrds,
  848. struct iwl_mvm_sar_table *sar_table)
  849. {
  850. union acpi_object *data_pkg;
  851. u32 i;
  852. /* We need at least two packages, one for the revision and one
  853. * for the data itself. Also check that the revision is valid
  854. * (i.e. it is an integer set to 0).
  855. */
  856. if (wrds->type != ACPI_TYPE_PACKAGE ||
  857. wrds->package.count < 2 ||
  858. wrds->package.elements[0].type != ACPI_TYPE_INTEGER ||
  859. wrds->package.elements[0].integer.value != 0) {
  860. IWL_DEBUG_RADIO(mvm, "Unsupported wrds structure\n");
  861. return -EINVAL;
  862. }
  863. /* loop through all the packages to find the one for WiFi */
  864. for (i = 1; i < wrds->package.count; i++) {
  865. union acpi_object *domain;
  866. data_pkg = &wrds->package.elements[i];
  867. /* Skip anything that is not a package with the right
  868. * amount of elements (i.e. domain_type,
  869. * enabled/disabled plus the sar table size.
  870. */
  871. if (data_pkg->type != ACPI_TYPE_PACKAGE ||
  872. data_pkg->package.count != ACPI_WRDS_TABLE_SIZE + 2)
  873. continue;
  874. domain = &data_pkg->package.elements[0];
  875. if (domain->type == ACPI_TYPE_INTEGER &&
  876. domain->integer.value == ACPI_WRDS_WIFI)
  877. break;
  878. data_pkg = NULL;
  879. }
  880. if (!data_pkg)
  881. return -ENOENT;
  882. if (data_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
  883. return -EINVAL;
  884. sar_table->enabled = !!(data_pkg->package.elements[1].integer.value);
  885. for (i = 0; i < ACPI_WRDS_TABLE_SIZE; i++) {
  886. union acpi_object *entry;
  887. entry = &data_pkg->package.elements[i + 2];
  888. if ((entry->type != ACPI_TYPE_INTEGER) ||
  889. (entry->integer.value > U8_MAX))
  890. return -EINVAL;
  891. sar_table->values[i] = entry->integer.value;
  892. }
  893. return 0;
  894. }
  895. static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
  896. struct iwl_mvm_sar_table *sar_table)
  897. {
  898. acpi_handle root_handle;
  899. acpi_handle handle;
  900. struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL};
  901. acpi_status status;
  902. int ret;
  903. root_handle = ACPI_HANDLE(mvm->dev);
  904. if (!root_handle) {
  905. IWL_DEBUG_RADIO(mvm,
  906. "Could not retrieve root port ACPI handle\n");
  907. return -ENOENT;
  908. }
  909. /* Get the method's handle */
  910. status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD,
  911. &handle);
  912. if (ACPI_FAILURE(status)) {
  913. IWL_DEBUG_RADIO(mvm, "WRDS method not found\n");
  914. return -ENOENT;
  915. }
  916. /* Call WRDS with no arguments */
  917. status = acpi_evaluate_object(handle, NULL, NULL, &wrds);
  918. if (ACPI_FAILURE(status)) {
  919. IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status);
  920. return -ENOENT;
  921. }
  922. ret = iwl_mvm_sar_get_wrds(mvm, wrds.pointer, sar_table);
  923. kfree(wrds.pointer);
  924. return ret;
  925. }
  926. #else /* CONFIG_ACPI */
  927. static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
  928. struct iwl_mvm_sar_table *sar_table)
  929. {
  930. return -ENOENT;
  931. }
  932. #endif /* CONFIG_ACPI */
  933. static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
  934. {
  935. struct iwl_mvm_sar_table sar_table;
  936. struct iwl_dev_tx_power_cmd cmd = {
  937. .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
  938. };
  939. int ret, i, j, idx;
  940. int len = sizeof(cmd);
  941. if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
  942. len = sizeof(cmd.v3);
  943. ret = iwl_mvm_sar_get_table(mvm, &sar_table);
  944. if (ret < 0) {
  945. IWL_DEBUG_RADIO(mvm,
  946. "SAR BIOS table invalid or unavailable. (%d)\n",
  947. ret);
  948. /* we don't fail if the table is not available */
  949. return 0;
  950. }
  951. if (!sar_table.enabled)
  952. return 0;
  953. IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
  954. BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS !=
  955. ACPI_WRDS_TABLE_SIZE);
  956. for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
  957. IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
  958. for (j = 0; j < IWL_NUM_SUB_BANDS; j++) {
  959. idx = (i * IWL_NUM_SUB_BANDS) + j;
  960. cmd.v3.per_chain_restriction[i][j] =
  961. cpu_to_le16(sar_table.values[idx]);
  962. IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
  963. j, sar_table.values[idx]);
  964. }
  965. }
  966. ret = iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
  967. if (ret)
  968. IWL_ERR(mvm, "failed to set per-chain TX power: %d\n", ret);
  969. return ret;
  970. }
  971. static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
  972. {
  973. int ret;
  974. if (iwl_mvm_has_new_tx_api(mvm))
  975. return iwl_run_unified_mvm_ucode(mvm, false);
  976. ret = iwl_run_init_mvm_ucode(mvm, false);
  977. if (iwlmvm_mod_params.init_dbg)
  978. return 0;
  979. if (ret) {
  980. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
  981. /* this can't happen */
  982. if (WARN_ON(ret > 0))
  983. ret = -ERFKILL;
  984. return ret;
  985. }
  986. /*
  987. * Stop and start the transport without entering low power
  988. * mode. This will save the state of other components on the
  989. * device that are triggered by the INIT firwmare (MFUART).
  990. */
  991. _iwl_trans_stop_device(mvm->trans, false);
  992. ret = _iwl_trans_start_hw(mvm->trans, false);
  993. if (ret)
  994. return ret;
  995. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  996. if (ret)
  997. return ret;
  998. return iwl_mvm_init_paging(mvm);
  999. }
  1000. int iwl_mvm_up(struct iwl_mvm *mvm)
  1001. {
  1002. int ret, i;
  1003. struct ieee80211_channel *chan;
  1004. struct cfg80211_chan_def chandef;
  1005. lockdep_assert_held(&mvm->mutex);
  1006. ret = iwl_trans_start_hw(mvm->trans);
  1007. if (ret)
  1008. return ret;
  1009. ret = iwl_mvm_load_rt_fw(mvm);
  1010. if (ret) {
  1011. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  1012. goto error;
  1013. }
  1014. iwl_mvm_get_shared_mem_conf(mvm);
  1015. ret = iwl_mvm_sf_update(mvm, NULL, false);
  1016. if (ret)
  1017. IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
  1018. mvm->fw_dbg_conf = FW_DBG_INVALID;
  1019. /* if we have a destination, assume EARLY START */
  1020. if (mvm->fw->dbg_dest_tlv)
  1021. mvm->fw_dbg_conf = FW_DBG_START_FROM_ALIVE;
  1022. iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_START_FROM_ALIVE);
  1023. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  1024. if (ret)
  1025. goto error;
  1026. ret = iwl_send_bt_init_conf(mvm);
  1027. if (ret)
  1028. goto error;
  1029. /* Send phy db control command and then phy db calibration*/
  1030. if (!iwl_mvm_has_new_tx_api(mvm)) {
  1031. ret = iwl_send_phy_db_data(mvm->phy_db);
  1032. if (ret)
  1033. goto error;
  1034. ret = iwl_send_phy_cfg_cmd(mvm);
  1035. if (ret)
  1036. goto error;
  1037. }
  1038. /* Init RSS configuration */
  1039. if (iwl_mvm_has_new_rx_api(mvm)) {
  1040. ret = iwl_send_rss_cfg_cmd(mvm);
  1041. if (ret) {
  1042. IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
  1043. ret);
  1044. goto error;
  1045. }
  1046. }
  1047. /* init the fw <-> mac80211 STA mapping */
  1048. for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
  1049. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  1050. mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
  1051. /* reset quota debouncing buffer - 0xff will yield invalid data */
  1052. memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
  1053. /* Enable DQA-mode if required */
  1054. if (iwl_mvm_is_dqa_supported(mvm)) {
  1055. ret = iwl_mvm_send_dqa_cmd(mvm);
  1056. if (ret)
  1057. goto error;
  1058. } else {
  1059. IWL_DEBUG_FW(mvm, "Working in non-DQA mode\n");
  1060. }
  1061. /* Add auxiliary station for scanning */
  1062. ret = iwl_mvm_add_aux_sta(mvm);
  1063. if (ret)
  1064. goto error;
  1065. /* Add all the PHY contexts */
  1066. chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
  1067. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
  1068. for (i = 0; i < NUM_PHY_CTX; i++) {
  1069. /*
  1070. * The channel used here isn't relevant as it's
  1071. * going to be overwritten in the other flows.
  1072. * For now use the first channel we have.
  1073. */
  1074. ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
  1075. &chandef, 1, 1);
  1076. if (ret)
  1077. goto error;
  1078. }
  1079. #ifdef CONFIG_THERMAL
  1080. if (iwl_mvm_is_tt_in_fw(mvm)) {
  1081. /* in order to give the responsibility of ct-kill and
  1082. * TX backoff to FW we need to send empty temperature reporting
  1083. * cmd during init time
  1084. */
  1085. iwl_mvm_send_temp_report_ths_cmd(mvm);
  1086. } else {
  1087. /* Initialize tx backoffs to the minimal possible */
  1088. iwl_mvm_tt_tx_backoff(mvm, 0);
  1089. }
  1090. /* TODO: read the budget from BIOS / Platform NVM */
  1091. if (iwl_mvm_is_ctdp_supported(mvm) && mvm->cooling_dev.cur_state > 0) {
  1092. ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
  1093. mvm->cooling_dev.cur_state);
  1094. if (ret)
  1095. goto error;
  1096. }
  1097. #else
  1098. /* Initialize tx backoffs to the minimal possible */
  1099. iwl_mvm_tt_tx_backoff(mvm, 0);
  1100. #endif
  1101. WARN_ON(iwl_mvm_config_ltr(mvm));
  1102. ret = iwl_mvm_power_update_device(mvm);
  1103. if (ret)
  1104. goto error;
  1105. /*
  1106. * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
  1107. * anyway, so don't init MCC.
  1108. */
  1109. if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
  1110. ret = iwl_mvm_init_mcc(mvm);
  1111. if (ret)
  1112. goto error;
  1113. }
  1114. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1115. mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
  1116. ret = iwl_mvm_config_scan(mvm);
  1117. if (ret)
  1118. goto error;
  1119. }
  1120. if (iwl_mvm_is_csum_supported(mvm) &&
  1121. mvm->cfg->features & NETIF_F_RXCSUM)
  1122. iwl_trans_write_prph(mvm->trans, RX_EN_CSUM, 0x3);
  1123. /* allow FW/transport low power modes if not during restart */
  1124. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1125. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  1126. ret = iwl_mvm_sar_init(mvm);
  1127. if (ret)
  1128. goto error;
  1129. IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
  1130. return 0;
  1131. error:
  1132. iwl_mvm_stop_device(mvm);
  1133. return ret;
  1134. }
  1135. int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
  1136. {
  1137. int ret, i;
  1138. lockdep_assert_held(&mvm->mutex);
  1139. ret = iwl_trans_start_hw(mvm->trans);
  1140. if (ret)
  1141. return ret;
  1142. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
  1143. if (ret) {
  1144. IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
  1145. goto error;
  1146. }
  1147. ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
  1148. if (ret)
  1149. goto error;
  1150. /* Send phy db control command and then phy db calibration*/
  1151. ret = iwl_send_phy_db_data(mvm->phy_db);
  1152. if (ret)
  1153. goto error;
  1154. ret = iwl_send_phy_cfg_cmd(mvm);
  1155. if (ret)
  1156. goto error;
  1157. /* init the fw <-> mac80211 STA mapping */
  1158. for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
  1159. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  1160. /* Add auxiliary station for scanning */
  1161. ret = iwl_mvm_add_aux_sta(mvm);
  1162. if (ret)
  1163. goto error;
  1164. return 0;
  1165. error:
  1166. iwl_mvm_stop_device(mvm);
  1167. return ret;
  1168. }
  1169. void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
  1170. struct iwl_rx_cmd_buffer *rxb)
  1171. {
  1172. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1173. struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
  1174. u32 flags = le32_to_cpu(card_state_notif->flags);
  1175. IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
  1176. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1177. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  1178. (flags & CT_KILL_CARD_DISABLED) ?
  1179. "Reached" : "Not reached");
  1180. }
  1181. void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
  1182. struct iwl_rx_cmd_buffer *rxb)
  1183. {
  1184. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1185. struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
  1186. IWL_DEBUG_INFO(mvm,
  1187. "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
  1188. le32_to_cpu(mfuart_notif->installed_ver),
  1189. le32_to_cpu(mfuart_notif->external_ver),
  1190. le32_to_cpu(mfuart_notif->status),
  1191. le32_to_cpu(mfuart_notif->duration));
  1192. if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
  1193. IWL_DEBUG_INFO(mvm,
  1194. "MFUART: image size: 0x%08x\n",
  1195. le32_to_cpu(mfuart_notif->image_size));
  1196. }