blob: 8dafca68baf0e1c77315fa6fd155cf77907c812e [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
Eran Harary12147552013-05-09 08:07:59 +030063#include <linux/firmware.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010064#include "iwl-trans.h"
65#include "mvm.h"
66#include "iwl-eeprom-parse.h"
67#include "iwl-eeprom-read.h"
68#include "iwl-nvm-parse.h"
69
Dor Shaish1fd4afe2013-02-27 10:18:07 +020070/* Default NVM size to read */
Eran Harary12147552013-05-09 08:07:59 +030071#define IWL_NVM_DEFAULT_CHUNK_SIZE (2*1024)
Idan Kahlon8a87bdd2013-10-09 16:09:13 +020072#define IWL_MAX_NVM_SECTION_SIZE 7000
Dor Shaish1fd4afe2013-02-27 10:18:07 +020073
Eran Harary12147552013-05-09 08:07:59 +030074#define NVM_WRITE_OPCODE 1
75#define NVM_READ_OPCODE 0
76
77/*
78 * prepare the NVM host command w/ the pointers to the nvm buffer
79 * and send it to fw
80 */
81static int iwl_nvm_write_chunk(struct iwl_mvm *mvm, u16 section,
82 u16 offset, u16 length, const u8 *data)
Johannes Berg8ca151b2013-01-24 14:25:36 +010083{
Eran Harary12147552013-05-09 08:07:59 +030084 struct iwl_nvm_access_cmd nvm_access_cmd = {
85 .offset = cpu_to_le16(offset),
86 .length = cpu_to_le16(length),
87 .type = cpu_to_le16(section),
88 .op_code = NVM_WRITE_OPCODE,
89 };
90 struct iwl_host_cmd cmd = {
91 .id = NVM_ACCESS_CMD,
92 .len = { sizeof(struct iwl_nvm_access_cmd), length },
Eran Harary4f593342013-05-13 07:53:26 +030093 .flags = CMD_SYNC | CMD_SEND_IN_RFKILL,
Eran Harary12147552013-05-09 08:07:59 +030094 .data = { &nvm_access_cmd, data },
95 /* data may come from vmalloc, so use _DUP */
96 .dataflags = { 0, IWL_HCMD_DFL_DUP },
97 };
98
99 return iwl_mvm_send_cmd(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100}
101
102static int iwl_nvm_read_chunk(struct iwl_mvm *mvm, u16 section,
103 u16 offset, u16 length, u8 *data)
104{
Eran Harary12147552013-05-09 08:07:59 +0300105 struct iwl_nvm_access_cmd nvm_access_cmd = {
106 .offset = cpu_to_le16(offset),
107 .length = cpu_to_le16(length),
108 .type = cpu_to_le16(section),
109 .op_code = NVM_READ_OPCODE,
110 };
Emmanuel Grumbachb9545b42013-03-06 11:34:44 +0200111 struct iwl_nvm_access_resp *nvm_resp;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100112 struct iwl_rx_packet *pkt;
113 struct iwl_host_cmd cmd = {
114 .id = NVM_ACCESS_CMD,
Eran Harary4f593342013-05-13 07:53:26 +0300115 .flags = CMD_SYNC | CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116 .data = { &nvm_access_cmd, },
117 };
118 int ret, bytes_read, offset_read;
119 u8 *resp_data;
120
Emmanuel Grumbachb9545b42013-03-06 11:34:44 +0200121 cmd.len[0] = sizeof(struct iwl_nvm_access_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100122
123 ret = iwl_mvm_send_cmd(mvm, &cmd);
124 if (ret)
125 return ret;
126
127 pkt = cmd.resp_pkt;
128 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
129 IWL_ERR(mvm, "Bad return from NVM_ACCES_COMMAND (0x%08X)\n",
130 pkt->hdr.flags);
131 ret = -EIO;
132 goto exit;
133 }
134
135 /* Extract NVM response */
136 nvm_resp = (void *)pkt->data;
Emmanuel Grumbachb9545b42013-03-06 11:34:44 +0200137 ret = le16_to_cpu(nvm_resp->status);
138 bytes_read = le16_to_cpu(nvm_resp->length);
139 offset_read = le16_to_cpu(nvm_resp->offset);
140 resp_data = nvm_resp->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141 if (ret) {
142 IWL_ERR(mvm,
143 "NVM access command failed with status %d (device: %s)\n",
144 ret, mvm->cfg->name);
145 ret = -EINVAL;
146 goto exit;
147 }
148
149 if (offset_read != offset) {
150 IWL_ERR(mvm, "NVM ACCESS response with invalid offset %d\n",
151 offset_read);
152 ret = -EINVAL;
153 goto exit;
154 }
155
156 /* Write data to NVM */
157 memcpy(data + offset, resp_data, bytes_read);
158 ret = bytes_read;
159
160exit:
161 iwl_free_resp(&cmd);
162 return ret;
163}
164
Eran Harary12147552013-05-09 08:07:59 +0300165static int iwl_nvm_write_section(struct iwl_mvm *mvm, u16 section,
166 const u8 *data, u16 length)
167{
168 int offset = 0;
169
170 /* copy data in chunks of 2k (and remainder if any) */
171
172 while (offset < length) {
173 int chunk_size, ret;
174
175 chunk_size = min(IWL_NVM_DEFAULT_CHUNK_SIZE,
176 length - offset);
177
178 ret = iwl_nvm_write_chunk(mvm, section, offset,
179 chunk_size, data + offset);
180 if (ret < 0)
181 return ret;
182
183 offset += chunk_size;
184 }
185
186 return 0;
187}
188
Johannes Berg8ca151b2013-01-24 14:25:36 +0100189/*
190 * Reads an NVM section completely.
191 * NICs prior to 7000 family doesn't have a real NVM, but just read
192 * section 0 which is the EEPROM. Because the EEPROM reading is unlimited
193 * by uCode, we need to manually check in this case that we don't
194 * overflow and try to read more than the EEPROM size.
195 * For 7000 family NICs, we supply the maximal size we can read, and
196 * the uCode fills the response with as much data as we can,
197 * without overflowing, so no check is needed.
198 */
199static int iwl_nvm_read_section(struct iwl_mvm *mvm, u16 section,
200 u8 *data)
201{
202 u16 length, offset = 0;
203 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100204
Dor Shaish1fd4afe2013-02-27 10:18:07 +0200205 /* Set nvm section read length */
206 length = IWL_NVM_DEFAULT_CHUNK_SIZE;
207
Johannes Berg8ca151b2013-01-24 14:25:36 +0100208 ret = length;
209
210 /* Read the NVM until exhausted (reading less than requested) */
211 while (ret == length) {
212 ret = iwl_nvm_read_chunk(mvm, section, offset, length, data);
213 if (ret < 0) {
214 IWL_ERR(mvm,
215 "Cannot read NVM from section %d offset %d, length %d\n",
216 section, offset, length);
217 return ret;
218 }
219 offset += ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100220 }
221
Johannes Berg07fd7d22013-05-15 14:38:25 +0200222 IWL_DEBUG_EEPROM(mvm->trans->dev,
223 "NVM section %d read completed\n", section);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100224 return offset;
225}
226
227static struct iwl_nvm_data *
228iwl_parse_nvm_sections(struct iwl_mvm *mvm)
229{
230 struct iwl_nvm_section *sections = mvm->nvm_sections;
Eran Harary77db0a32014-02-04 14:21:38 +0200231 const __le16 *hw, *sw, *calib, *regulatory, *mac_override;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100232
233 /* Checking for required sections */
Eran Harary77db0a32014-02-04 14:21:38 +0200234 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
235 if (!mvm->nvm_sections[NVM_SECTION_TYPE_SW].data ||
236 !mvm->nvm_sections[mvm->cfg->nvm_hw_section_num].data) {
237 IWL_ERR(mvm, "Can't parse empty NVM sections\n");
238 return NULL;
239 }
240 } else {
Eran Harary9f32e012014-04-28 15:22:40 +0300241 /* SW and REGULATORY sections are mandatory */
Eran Harary77db0a32014-02-04 14:21:38 +0200242 if (!mvm->nvm_sections[NVM_SECTION_TYPE_SW].data ||
Eran Harary77db0a32014-02-04 14:21:38 +0200243 !mvm->nvm_sections[NVM_SECTION_TYPE_REGULATORY].data) {
244 IWL_ERR(mvm,
245 "Can't parse empty family 8000 NVM sections\n");
246 return NULL;
247 }
Eran Harary9f32e012014-04-28 15:22:40 +0300248 /* MAC_OVERRIDE or at least HW section must exist */
Eran Hararybb926922014-04-30 15:31:59 +0300249 if (!mvm->nvm_sections[mvm->cfg->nvm_hw_section_num].data &&
Eran Harary9f32e012014-04-28 15:22:40 +0300250 !mvm->nvm_sections[NVM_SECTION_TYPE_MAC_OVERRIDE].data) {
251 IWL_ERR(mvm,
252 "Can't parse mac_address, empty sections\n");
253 return NULL;
254 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100255 }
256
257 if (WARN_ON(!mvm->cfg))
258 return NULL;
259
Eran Hararyae2b21b2014-01-09 08:08:24 +0200260 hw = (const __le16 *)sections[mvm->cfg->nvm_hw_section_num].data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100261 sw = (const __le16 *)sections[NVM_SECTION_TYPE_SW].data;
262 calib = (const __le16 *)sections[NVM_SECTION_TYPE_CALIBRATION].data;
Eran Harary77db0a32014-02-04 14:21:38 +0200263 regulatory = (const __le16 *)sections[NVM_SECTION_TYPE_REGULATORY].data;
264 mac_override =
265 (const __le16 *)sections[NVM_SECTION_TYPE_MAC_OVERRIDE].data;
266
Emmanuel Grumbach9ce4fa72013-05-22 13:16:23 +0300267 return iwl_parse_nvm_data(mvm->trans->dev, mvm->cfg, hw, sw, calib,
Eran Harary77db0a32014-02-04 14:21:38 +0200268 regulatory, mac_override,
Johannes Berg4ed735e2014-02-12 21:47:44 +0100269 mvm->fw->valid_tx_ant,
270 mvm->fw->valid_rx_ant);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271}
272
Eran Harary12147552013-05-09 08:07:59 +0300273#define MAX_NVM_FILE_LEN 16384
274
275/*
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200276 * Reads external NVM from a file into mvm->nvm_sections
277 *
Eran Harary12147552013-05-09 08:07:59 +0300278 * HOW TO CREATE THE NVM FILE FORMAT:
279 * ------------------------------
280 * 1. create hex file, format:
281 * 3800 -> header
282 * 0000 -> header
283 * 5a40 -> data
284 *
285 * rev - 6 bit (word1)
286 * len - 10 bit (word1)
287 * id - 4 bit (word2)
288 * rsv - 12 bit (word2)
289 *
290 * 2. flip 8bits with 8 bits per line to get the right NVM file format
291 *
292 * 3. create binary file from the hex file
293 *
294 * 4. save as "iNVM_xxx.bin" under /lib/firmware
295 */
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200296static int iwl_mvm_read_external_nvm(struct iwl_mvm *mvm)
Eran Harary12147552013-05-09 08:07:59 +0300297{
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200298 int ret, section_size;
299 u16 section_id;
Eran Harary12147552013-05-09 08:07:59 +0300300 const struct firmware *fw_entry;
301 const struct {
302 __le16 word1;
303 __le16 word2;
304 u8 data[];
305 } *file_sec;
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200306 const u8 *eof, *temp;
Eran Harary12147552013-05-09 08:07:59 +0300307
308#define NVM_WORD1_LEN(x) (8 * (x & 0x03FF))
309#define NVM_WORD2_ID(x) (x >> 12)
Eran Harary77db0a32014-02-04 14:21:38 +0200310#define NVM_WORD2_LEN_FAMILY_8000(x) (2 * ((x & 0xFF) << 8 | x >> 8))
311#define NVM_WORD1_ID_FAMILY_8000(x) (x >> 4)
Eran Harary12147552013-05-09 08:07:59 +0300312
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200313 IWL_DEBUG_EEPROM(mvm->trans->dev, "Read from external NVM\n");
314
Eran Harary12147552013-05-09 08:07:59 +0300315 /*
316 * Obtain NVM image via request_firmware. Since we already used
317 * request_firmware_nowait() for the firmware binary load and only
318 * get here after that we assume the NVM request can be satisfied
319 * synchronously.
320 */
Eran Hararye02a9d62014-05-07 12:27:10 +0300321 ret = request_firmware(&fw_entry, mvm->nvm_file_name,
Eran Harary12147552013-05-09 08:07:59 +0300322 mvm->trans->dev);
323 if (ret) {
324 IWL_ERR(mvm, "ERROR: %s isn't available %d\n",
Eran Hararye02a9d62014-05-07 12:27:10 +0300325 mvm->nvm_file_name, ret);
Eran Harary12147552013-05-09 08:07:59 +0300326 return ret;
327 }
328
329 IWL_INFO(mvm, "Loaded NVM file %s (%zu bytes)\n",
Eran Hararye02a9d62014-05-07 12:27:10 +0300330 mvm->nvm_file_name, fw_entry->size);
Eran Harary12147552013-05-09 08:07:59 +0300331
332 if (fw_entry->size < sizeof(*file_sec)) {
333 IWL_ERR(mvm, "NVM file too small\n");
334 ret = -EINVAL;
335 goto out;
336 }
337
338 if (fw_entry->size > MAX_NVM_FILE_LEN) {
339 IWL_ERR(mvm, "NVM file too large\n");
340 ret = -EINVAL;
341 goto out;
342 }
343
344 eof = fw_entry->data + fw_entry->size;
345
346 file_sec = (void *)fw_entry->data;
347
348 while (true) {
349 if (file_sec->data > eof) {
350 IWL_ERR(mvm,
351 "ERROR - NVM file too short for section header\n");
352 ret = -EINVAL;
353 break;
354 }
355
356 /* check for EOF marker */
357 if (!file_sec->word1 && !file_sec->word2) {
358 ret = 0;
359 break;
360 }
361
Eran Harary77db0a32014-02-04 14:21:38 +0200362 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
363 section_size =
364 2 * NVM_WORD1_LEN(le16_to_cpu(file_sec->word1));
365 section_id = NVM_WORD2_ID(le16_to_cpu(file_sec->word2));
366 } else {
367 section_size = 2 * NVM_WORD2_LEN_FAMILY_8000(
368 le16_to_cpu(file_sec->word2));
369 section_id = NVM_WORD1_ID_FAMILY_8000(
370 le16_to_cpu(file_sec->word1));
371 }
Eran Harary12147552013-05-09 08:07:59 +0300372
373 if (section_size > IWL_MAX_NVM_SECTION_SIZE) {
374 IWL_ERR(mvm, "ERROR - section too large (%d)\n",
375 section_size);
376 ret = -EINVAL;
377 break;
378 }
379
380 if (!section_size) {
381 IWL_ERR(mvm, "ERROR - section empty\n");
382 ret = -EINVAL;
383 break;
384 }
385
386 if (file_sec->data + section_size > eof) {
387 IWL_ERR(mvm,
388 "ERROR - NVM file too short for section (%d bytes)\n",
389 section_size);
390 ret = -EINVAL;
391 break;
392 }
393
Eran Hararyae2b21b2014-01-09 08:08:24 +0200394 if (WARN(section_id >= NVM_MAX_NUM_SECTIONS,
Eytan Lifshitza4a12472013-12-18 23:05:06 +0200395 "Invalid NVM section ID %d\n", section_id)) {
396 ret = -EINVAL;
397 break;
398 }
399
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200400 temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
401 if (!temp) {
402 ret = -ENOMEM;
Eran Harary12147552013-05-09 08:07:59 +0300403 break;
404 }
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200405 mvm->nvm_sections[section_id].data = temp;
406 mvm->nvm_sections[section_id].length = section_size;
Eran Harary12147552013-05-09 08:07:59 +0300407
408 /* advance to the next section */
409 file_sec = (void *)(file_sec->data + section_size);
410 }
411out:
412 release_firmware(fw_entry);
413 return ret;
414}
415
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200416/* Loads the NVM data stored in mvm->nvm_sections into the NIC */
417int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm)
418{
Eytan Lifshitz05159fc2014-01-07 12:50:45 +0200419 int i, ret = 0;
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200420 struct iwl_nvm_section *sections = mvm->nvm_sections;
421
422 IWL_DEBUG_EEPROM(mvm->trans->dev, "'Write to NVM\n");
423
Emmanuel Grumbach099d8f22014-01-05 15:09:44 +0200424 for (i = 0; i < ARRAY_SIZE(mvm->nvm_sections); i++) {
425 if (!mvm->nvm_sections[i].data || !mvm->nvm_sections[i].length)
426 continue;
427 ret = iwl_nvm_write_section(mvm, i, sections[i].data,
428 sections[i].length);
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200429 if (ret < 0) {
430 IWL_ERR(mvm, "iwl_mvm_send_cmd failed: %d\n", ret);
431 break;
432 }
433 }
434 return ret;
435}
436
Eran Harary14b485f2014-04-23 10:46:09 +0300437int iwl_nvm_init(struct iwl_mvm *mvm, bool read_nvm_from_nic)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100438{
439 int ret, i, section;
440 u8 *nvm_buffer, *temp;
Eran Harary77db0a32014-02-04 14:21:38 +0200441 int nvm_to_read[NVM_MAX_NUM_SECTIONS];
442 int num_of_sections_to_read;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100443
Eran Hararyae2b21b2014-01-09 08:08:24 +0200444 if (WARN_ON_ONCE(mvm->cfg->nvm_hw_section_num >= NVM_MAX_NUM_SECTIONS))
445 return -EINVAL;
446
Eran Harary26481bf2014-03-25 14:14:44 +0200447 /* load NVM values from nic */
Eran Harary14b485f2014-04-23 10:46:09 +0300448 if (read_nvm_from_nic) {
Eran Hararyae2b21b2014-01-09 08:08:24 +0200449 /* list of NVM sections we are allowed/need to read */
Eran Harary77db0a32014-02-04 14:21:38 +0200450 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
451 nvm_to_read[0] = mvm->cfg->nvm_hw_section_num;
452 nvm_to_read[1] = NVM_SECTION_TYPE_SW;
453 nvm_to_read[2] = NVM_SECTION_TYPE_CALIBRATION;
454 nvm_to_read[3] = NVM_SECTION_TYPE_PRODUCTION;
455 num_of_sections_to_read = 4;
456 } else {
457 nvm_to_read[0] = NVM_SECTION_TYPE_SW;
458 nvm_to_read[1] = NVM_SECTION_TYPE_CALIBRATION;
459 nvm_to_read[2] = NVM_SECTION_TYPE_PRODUCTION;
460 nvm_to_read[3] = NVM_SECTION_TYPE_REGULATORY;
461 nvm_to_read[4] = NVM_SECTION_TYPE_MAC_OVERRIDE;
462 num_of_sections_to_read = 5;
463 }
Eran Hararyae2b21b2014-01-09 08:08:24 +0200464
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200465 /* Read From FW NVM */
466 IWL_DEBUG_EEPROM(mvm->trans->dev, "Read from NVM\n");
Eran Harary12147552013-05-09 08:07:59 +0300467
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200468 nvm_buffer = kmalloc(mvm->cfg->base_params->eeprom_size,
469 GFP_KERNEL);
470 if (!nvm_buffer)
471 return -ENOMEM;
Eran Harary77db0a32014-02-04 14:21:38 +0200472 for (i = 0; i < num_of_sections_to_read; i++) {
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200473 section = nvm_to_read[i];
474 /* we override the constness for initial read */
475 ret = iwl_nvm_read_section(mvm, section, nvm_buffer);
476 if (ret < 0)
477 break;
478 temp = kmemdup(nvm_buffer, ret, GFP_KERNEL);
479 if (!temp) {
480 ret = -ENOMEM;
481 break;
482 }
483 mvm->nvm_sections[section].data = temp;
484 mvm->nvm_sections[section].length = ret;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +0200485
486#ifdef CONFIG_IWLWIFI_DEBUGFS
487 switch (section) {
Emmanuel Grumbach086f7362013-11-18 17:00:03 +0200488 case NVM_SECTION_TYPE_SW:
489 mvm->nvm_sw_blob.data = temp;
490 mvm->nvm_sw_blob.size = ret;
491 break;
492 case NVM_SECTION_TYPE_CALIBRATION:
493 mvm->nvm_calib_blob.data = temp;
494 mvm->nvm_calib_blob.size = ret;
495 break;
496 case NVM_SECTION_TYPE_PRODUCTION:
497 mvm->nvm_prod_blob.data = temp;
498 mvm->nvm_prod_blob.size = ret;
499 break;
500 default:
Eran Hararyae2b21b2014-01-09 08:08:24 +0200501 if (section == mvm->cfg->nvm_hw_section_num) {
502 mvm->nvm_hw_blob.data = temp;
503 mvm->nvm_hw_blob.size = ret;
504 break;
505 }
Emmanuel Grumbach086f7362013-11-18 17:00:03 +0200506 WARN(1, "section: %d", section);
507 }
508#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100509 }
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200510 kfree(nvm_buffer);
511 if (ret < 0)
512 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100513 }
514
Eran Harary26481bf2014-03-25 14:14:44 +0200515 /* load external NVM if configured */
Eran Hararye02a9d62014-05-07 12:27:10 +0300516 if (mvm->nvm_file_name) {
Eran Harary26481bf2014-03-25 14:14:44 +0200517 /* move to External NVM flow */
518 ret = iwl_mvm_read_external_nvm(mvm);
519 if (ret)
520 return ret;
521 }
522
523 /* parse the relevant nvm sections */
Emmanuel Grumbachb9545b42013-03-06 11:34:44 +0200524 mvm->nvm_data = iwl_parse_nvm_sections(mvm);
Johannes Berg82598b42013-05-13 21:44:42 +0200525 if (!mvm->nvm_data)
526 return -ENODATA;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100527
Johannes Berg82598b42013-05-13 21:44:42 +0200528 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100529}