nvm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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 - 2014 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/firmware.h>
  66. #include "iwl-trans.h"
  67. #include "iwl-csr.h"
  68. #include "mvm.h"
  69. #include "iwl-eeprom-parse.h"
  70. #include "iwl-eeprom-read.h"
  71. #include "iwl-nvm-parse.h"
  72. /* Default NVM size to read */
  73. #define IWL_NVM_DEFAULT_CHUNK_SIZE (2*1024)
  74. #define IWL_MAX_NVM_SECTION_SIZE 0x1b58
  75. #define IWL_MAX_NVM_8000A_SECTION_SIZE 0xffc
  76. #define IWL_MAX_NVM_8000B_SECTION_SIZE 0x1ffc
  77. #define NVM_WRITE_OPCODE 1
  78. #define NVM_READ_OPCODE 0
  79. /* load nvm chunk response */
  80. enum {
  81. READ_NVM_CHUNK_SUCCEED = 0,
  82. READ_NVM_CHUNK_NOT_VALID_ADDRESS = 1
  83. };
  84. /*
  85. * prepare the NVM host command w/ the pointers to the nvm buffer
  86. * and send it to fw
  87. */
  88. static int iwl_nvm_write_chunk(struct iwl_mvm *mvm, u16 section,
  89. u16 offset, u16 length, const u8 *data)
  90. {
  91. struct iwl_nvm_access_cmd nvm_access_cmd = {
  92. .offset = cpu_to_le16(offset),
  93. .length = cpu_to_le16(length),
  94. .type = cpu_to_le16(section),
  95. .op_code = NVM_WRITE_OPCODE,
  96. };
  97. struct iwl_host_cmd cmd = {
  98. .id = NVM_ACCESS_CMD,
  99. .len = { sizeof(struct iwl_nvm_access_cmd), length },
  100. .flags = CMD_SEND_IN_RFKILL,
  101. .data = { &nvm_access_cmd, data },
  102. /* data may come from vmalloc, so use _DUP */
  103. .dataflags = { 0, IWL_HCMD_DFL_DUP },
  104. };
  105. return iwl_mvm_send_cmd(mvm, &cmd);
  106. }
  107. static int iwl_nvm_read_chunk(struct iwl_mvm *mvm, u16 section,
  108. u16 offset, u16 length, u8 *data)
  109. {
  110. struct iwl_nvm_access_cmd nvm_access_cmd = {
  111. .offset = cpu_to_le16(offset),
  112. .length = cpu_to_le16(length),
  113. .type = cpu_to_le16(section),
  114. .op_code = NVM_READ_OPCODE,
  115. };
  116. struct iwl_nvm_access_resp *nvm_resp;
  117. struct iwl_rx_packet *pkt;
  118. struct iwl_host_cmd cmd = {
  119. .id = NVM_ACCESS_CMD,
  120. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  121. .data = { &nvm_access_cmd, },
  122. };
  123. int ret, bytes_read, offset_read;
  124. u8 *resp_data;
  125. cmd.len[0] = sizeof(struct iwl_nvm_access_cmd);
  126. ret = iwl_mvm_send_cmd(mvm, &cmd);
  127. if (ret)
  128. return ret;
  129. pkt = cmd.resp_pkt;
  130. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  131. IWL_ERR(mvm, "Bad return from NVM_ACCES_COMMAND (0x%08X)\n",
  132. pkt->hdr.flags);
  133. ret = -EIO;
  134. goto exit;
  135. }
  136. /* Extract NVM response */
  137. nvm_resp = (void *)pkt->data;
  138. ret = le16_to_cpu(nvm_resp->status);
  139. bytes_read = le16_to_cpu(nvm_resp->length);
  140. offset_read = le16_to_cpu(nvm_resp->offset);
  141. resp_data = nvm_resp->data;
  142. if (ret) {
  143. if ((offset != 0) &&
  144. (ret == READ_NVM_CHUNK_NOT_VALID_ADDRESS)) {
  145. /*
  146. * meaning of NOT_VALID_ADDRESS:
  147. * driver try to read chunk from address that is
  148. * multiple of 2K and got an error since addr is empty.
  149. * meaning of (offset != 0): driver already
  150. * read valid data from another chunk so this case
  151. * is not an error.
  152. */
  153. IWL_DEBUG_EEPROM(mvm->trans->dev,
  154. "NVM access command failed on offset 0x%x since that section size is multiple 2K\n",
  155. offset);
  156. ret = 0;
  157. } else {
  158. IWL_DEBUG_EEPROM(mvm->trans->dev,
  159. "NVM access command failed with status %d (device: %s)\n",
  160. ret, mvm->cfg->name);
  161. ret = -EIO;
  162. }
  163. goto exit;
  164. }
  165. if (offset_read != offset) {
  166. IWL_ERR(mvm, "NVM ACCESS response with invalid offset %d\n",
  167. offset_read);
  168. ret = -EINVAL;
  169. goto exit;
  170. }
  171. /* Write data to NVM */
  172. memcpy(data + offset, resp_data, bytes_read);
  173. ret = bytes_read;
  174. exit:
  175. iwl_free_resp(&cmd);
  176. return ret;
  177. }
  178. static int iwl_nvm_write_section(struct iwl_mvm *mvm, u16 section,
  179. const u8 *data, u16 length)
  180. {
  181. int offset = 0;
  182. /* copy data in chunks of 2k (and remainder if any) */
  183. while (offset < length) {
  184. int chunk_size, ret;
  185. chunk_size = min(IWL_NVM_DEFAULT_CHUNK_SIZE,
  186. length - offset);
  187. ret = iwl_nvm_write_chunk(mvm, section, offset,
  188. chunk_size, data + offset);
  189. if (ret < 0)
  190. return ret;
  191. offset += chunk_size;
  192. }
  193. return 0;
  194. }
  195. /*
  196. * Reads an NVM section completely.
  197. * NICs prior to 7000 family doesn't have a real NVM, but just read
  198. * section 0 which is the EEPROM. Because the EEPROM reading is unlimited
  199. * by uCode, we need to manually check in this case that we don't
  200. * overflow and try to read more than the EEPROM size.
  201. * For 7000 family NICs, we supply the maximal size we can read, and
  202. * the uCode fills the response with as much data as we can,
  203. * without overflowing, so no check is needed.
  204. */
  205. static int iwl_nvm_read_section(struct iwl_mvm *mvm, u16 section,
  206. u8 *data, u32 size_read)
  207. {
  208. u16 length, offset = 0;
  209. int ret;
  210. /* Set nvm section read length */
  211. length = IWL_NVM_DEFAULT_CHUNK_SIZE;
  212. ret = length;
  213. /* Read the NVM until exhausted (reading less than requested) */
  214. while (ret == length) {
  215. /* Check no memory assumptions fail and cause an overflow */
  216. if ((size_read + offset + length) >
  217. mvm->cfg->base_params->eeprom_size) {
  218. IWL_ERR(mvm, "EEPROM size is too small for NVM\n");
  219. return -ENOBUFS;
  220. }
  221. ret = iwl_nvm_read_chunk(mvm, section, offset, length, data);
  222. if (ret < 0) {
  223. IWL_DEBUG_EEPROM(mvm->trans->dev,
  224. "Cannot read NVM from section %d offset %d, length %d\n",
  225. section, offset, length);
  226. return ret;
  227. }
  228. offset += ret;
  229. }
  230. IWL_DEBUG_EEPROM(mvm->trans->dev,
  231. "NVM section %d read completed\n", section);
  232. return offset;
  233. }
  234. static struct iwl_nvm_data *
  235. iwl_parse_nvm_sections(struct iwl_mvm *mvm)
  236. {
  237. struct iwl_nvm_section *sections = mvm->nvm_sections;
  238. const __le16 *hw, *sw, *calib, *regulatory, *mac_override;
  239. /* Checking for required sections */
  240. if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  241. if (!mvm->nvm_sections[NVM_SECTION_TYPE_SW].data ||
  242. !mvm->nvm_sections[mvm->cfg->nvm_hw_section_num].data) {
  243. IWL_ERR(mvm, "Can't parse empty OTP/NVM sections\n");
  244. return NULL;
  245. }
  246. } else {
  247. /* SW and REGULATORY sections are mandatory */
  248. if (!mvm->nvm_sections[NVM_SECTION_TYPE_SW].data ||
  249. !mvm->nvm_sections[NVM_SECTION_TYPE_REGULATORY].data) {
  250. IWL_ERR(mvm,
  251. "Can't parse empty family 8000 OTP/NVM sections\n");
  252. return NULL;
  253. }
  254. /* MAC_OVERRIDE or at least HW section must exist */
  255. if (!mvm->nvm_sections[mvm->cfg->nvm_hw_section_num].data &&
  256. !mvm->nvm_sections[NVM_SECTION_TYPE_MAC_OVERRIDE].data) {
  257. IWL_ERR(mvm,
  258. "Can't parse mac_address, empty sections\n");
  259. return NULL;
  260. }
  261. }
  262. if (WARN_ON(!mvm->cfg))
  263. return NULL;
  264. hw = (const __le16 *)sections[mvm->cfg->nvm_hw_section_num].data;
  265. sw = (const __le16 *)sections[NVM_SECTION_TYPE_SW].data;
  266. calib = (const __le16 *)sections[NVM_SECTION_TYPE_CALIBRATION].data;
  267. regulatory = (const __le16 *)sections[NVM_SECTION_TYPE_REGULATORY].data;
  268. mac_override =
  269. (const __le16 *)sections[NVM_SECTION_TYPE_MAC_OVERRIDE].data;
  270. return iwl_parse_nvm_data(mvm->trans->dev, mvm->cfg, hw, sw, calib,
  271. regulatory, mac_override,
  272. mvm->fw->valid_tx_ant,
  273. mvm->fw->valid_rx_ant);
  274. }
  275. #define MAX_NVM_FILE_LEN 16384
  276. /*
  277. * Reads external NVM from a file into mvm->nvm_sections
  278. *
  279. * HOW TO CREATE THE NVM FILE FORMAT:
  280. * ------------------------------
  281. * 1. create hex file, format:
  282. * 3800 -> header
  283. * 0000 -> header
  284. * 5a40 -> data
  285. *
  286. * rev - 6 bit (word1)
  287. * len - 10 bit (word1)
  288. * id - 4 bit (word2)
  289. * rsv - 12 bit (word2)
  290. *
  291. * 2. flip 8bits with 8 bits per line to get the right NVM file format
  292. *
  293. * 3. create binary file from the hex file
  294. *
  295. * 4. save as "iNVM_xxx.bin" under /lib/firmware
  296. */
  297. static int iwl_mvm_read_external_nvm(struct iwl_mvm *mvm)
  298. {
  299. int ret, section_size;
  300. u16 section_id;
  301. const struct firmware *fw_entry;
  302. const struct {
  303. __le16 word1;
  304. __le16 word2;
  305. u8 data[];
  306. } *file_sec;
  307. const u8 *eof, *temp;
  308. int max_section_size;
  309. const __le32 *dword_buff;
  310. #define NVM_WORD1_LEN(x) (8 * (x & 0x03FF))
  311. #define NVM_WORD2_ID(x) (x >> 12)
  312. #define NVM_WORD2_LEN_FAMILY_8000(x) (2 * ((x & 0xFF) << 8 | x >> 8))
  313. #define NVM_WORD1_ID_FAMILY_8000(x) (x >> 4)
  314. #define NVM_HEADER_0 (0x2A504C54)
  315. #define NVM_HEADER_1 (0x4E564D2A)
  316. #define NVM_HEADER_SIZE (4 * sizeof(u32))
  317. IWL_DEBUG_EEPROM(mvm->trans->dev, "Read from external NVM\n");
  318. /* Maximal size depends on HW family and step */
  319. if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
  320. max_section_size = IWL_MAX_NVM_SECTION_SIZE;
  321. else if (CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP)
  322. max_section_size = IWL_MAX_NVM_8000A_SECTION_SIZE;
  323. else /* Family 8000 B-step or C-step */
  324. max_section_size = IWL_MAX_NVM_8000B_SECTION_SIZE;
  325. /*
  326. * Obtain NVM image via request_firmware. Since we already used
  327. * request_firmware_nowait() for the firmware binary load and only
  328. * get here after that we assume the NVM request can be satisfied
  329. * synchronously.
  330. */
  331. ret = request_firmware(&fw_entry, mvm->nvm_file_name,
  332. mvm->trans->dev);
  333. if (ret) {
  334. IWL_ERR(mvm, "ERROR: %s isn't available %d\n",
  335. mvm->nvm_file_name, ret);
  336. return ret;
  337. }
  338. IWL_INFO(mvm, "Loaded NVM file %s (%zu bytes)\n",
  339. mvm->nvm_file_name, fw_entry->size);
  340. if (fw_entry->size > MAX_NVM_FILE_LEN) {
  341. IWL_ERR(mvm, "NVM file too large\n");
  342. ret = -EINVAL;
  343. goto out;
  344. }
  345. eof = fw_entry->data + fw_entry->size;
  346. dword_buff = (__le32 *)fw_entry->data;
  347. /* some NVM file will contain a header.
  348. * The header is identified by 2 dwords header as follow:
  349. * dword[0] = 0x2A504C54
  350. * dword[1] = 0x4E564D2A
  351. *
  352. * This header must be skipped when providing the NVM data to the FW.
  353. */
  354. if (fw_entry->size > NVM_HEADER_SIZE &&
  355. dword_buff[0] == cpu_to_le32(NVM_HEADER_0) &&
  356. dword_buff[1] == cpu_to_le32(NVM_HEADER_1)) {
  357. file_sec = (void *)(fw_entry->data + NVM_HEADER_SIZE);
  358. IWL_INFO(mvm, "NVM Version %08X\n", le32_to_cpu(dword_buff[2]));
  359. IWL_INFO(mvm, "NVM Manufacturing date %08X\n",
  360. le32_to_cpu(dword_buff[3]));
  361. } else {
  362. file_sec = (void *)fw_entry->data;
  363. }
  364. while (true) {
  365. if (file_sec->data > eof) {
  366. IWL_ERR(mvm,
  367. "ERROR - NVM file too short for section header\n");
  368. ret = -EINVAL;
  369. break;
  370. }
  371. /* check for EOF marker */
  372. if (!file_sec->word1 && !file_sec->word2) {
  373. ret = 0;
  374. break;
  375. }
  376. if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  377. section_size =
  378. 2 * NVM_WORD1_LEN(le16_to_cpu(file_sec->word1));
  379. section_id = NVM_WORD2_ID(le16_to_cpu(file_sec->word2));
  380. } else {
  381. section_size = 2 * NVM_WORD2_LEN_FAMILY_8000(
  382. le16_to_cpu(file_sec->word2));
  383. section_id = NVM_WORD1_ID_FAMILY_8000(
  384. le16_to_cpu(file_sec->word1));
  385. }
  386. if (section_size > max_section_size) {
  387. IWL_ERR(mvm, "ERROR - section too large (%d)\n",
  388. section_size);
  389. ret = -EINVAL;
  390. break;
  391. }
  392. if (!section_size) {
  393. IWL_ERR(mvm, "ERROR - section empty\n");
  394. ret = -EINVAL;
  395. break;
  396. }
  397. if (file_sec->data + section_size > eof) {
  398. IWL_ERR(mvm,
  399. "ERROR - NVM file too short for section (%d bytes)\n",
  400. section_size);
  401. ret = -EINVAL;
  402. break;
  403. }
  404. if (WARN(section_id >= NVM_MAX_NUM_SECTIONS,
  405. "Invalid NVM section ID %d\n", section_id)) {
  406. ret = -EINVAL;
  407. break;
  408. }
  409. temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
  410. if (!temp) {
  411. ret = -ENOMEM;
  412. break;
  413. }
  414. mvm->nvm_sections[section_id].data = temp;
  415. mvm->nvm_sections[section_id].length = section_size;
  416. /* advance to the next section */
  417. file_sec = (void *)(file_sec->data + section_size);
  418. }
  419. out:
  420. release_firmware(fw_entry);
  421. return ret;
  422. }
  423. /* Loads the NVM data stored in mvm->nvm_sections into the NIC */
  424. int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm)
  425. {
  426. int i, ret = 0;
  427. struct iwl_nvm_section *sections = mvm->nvm_sections;
  428. IWL_DEBUG_EEPROM(mvm->trans->dev, "'Write to NVM\n");
  429. for (i = 0; i < ARRAY_SIZE(mvm->nvm_sections); i++) {
  430. if (!mvm->nvm_sections[i].data || !mvm->nvm_sections[i].length)
  431. continue;
  432. ret = iwl_nvm_write_section(mvm, i, sections[i].data,
  433. sections[i].length);
  434. if (ret < 0) {
  435. IWL_ERR(mvm, "iwl_mvm_send_cmd failed: %d\n", ret);
  436. break;
  437. }
  438. }
  439. return ret;
  440. }
  441. int iwl_nvm_init(struct iwl_mvm *mvm, bool read_nvm_from_nic)
  442. {
  443. int ret, section;
  444. u32 size_read = 0;
  445. u8 *nvm_buffer, *temp;
  446. if (WARN_ON_ONCE(mvm->cfg->nvm_hw_section_num >= NVM_MAX_NUM_SECTIONS))
  447. return -EINVAL;
  448. /* load NVM values from nic */
  449. if (read_nvm_from_nic) {
  450. /* Read From FW NVM */
  451. IWL_DEBUG_EEPROM(mvm->trans->dev, "Read from NVM\n");
  452. nvm_buffer = kmalloc(mvm->cfg->base_params->eeprom_size,
  453. GFP_KERNEL);
  454. if (!nvm_buffer)
  455. return -ENOMEM;
  456. for (section = 0; section < NVM_MAX_NUM_SECTIONS; section++) {
  457. /* we override the constness for initial read */
  458. ret = iwl_nvm_read_section(mvm, section, nvm_buffer,
  459. size_read);
  460. if (ret < 0)
  461. continue;
  462. size_read += ret;
  463. temp = kmemdup(nvm_buffer, ret, GFP_KERNEL);
  464. if (!temp) {
  465. ret = -ENOMEM;
  466. break;
  467. }
  468. mvm->nvm_sections[section].data = temp;
  469. mvm->nvm_sections[section].length = ret;
  470. #ifdef CONFIG_IWLWIFI_DEBUGFS
  471. switch (section) {
  472. case NVM_SECTION_TYPE_SW:
  473. mvm->nvm_sw_blob.data = temp;
  474. mvm->nvm_sw_blob.size = ret;
  475. break;
  476. case NVM_SECTION_TYPE_CALIBRATION:
  477. mvm->nvm_calib_blob.data = temp;
  478. mvm->nvm_calib_blob.size = ret;
  479. break;
  480. case NVM_SECTION_TYPE_PRODUCTION:
  481. mvm->nvm_prod_blob.data = temp;
  482. mvm->nvm_prod_blob.size = ret;
  483. break;
  484. default:
  485. if (section == mvm->cfg->nvm_hw_section_num) {
  486. mvm->nvm_hw_blob.data = temp;
  487. mvm->nvm_hw_blob.size = ret;
  488. break;
  489. }
  490. }
  491. #endif
  492. }
  493. if (!size_read)
  494. IWL_ERR(mvm, "OTP is blank\n");
  495. kfree(nvm_buffer);
  496. }
  497. /* load external NVM if configured */
  498. if (mvm->nvm_file_name) {
  499. /* move to External NVM flow */
  500. ret = iwl_mvm_read_external_nvm(mvm);
  501. if (ret)
  502. return ret;
  503. }
  504. /* parse the relevant nvm sections */
  505. mvm->nvm_data = iwl_parse_nvm_sections(mvm);
  506. if (!mvm->nvm_data)
  507. return -ENODATA;
  508. IWL_DEBUG_EEPROM(mvm->trans->dev, "nvm version = %x\n",
  509. mvm->nvm_data->nvm_version);
  510. return 0;
  511. }