fw.c 37 KB

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