net/ice/base: add and update E822 device IDs
[dpdk.git] / drivers / net / ice / base / ice_nvm.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2019
3  */
4
5 #include "ice_common.h"
6
7 /**
8  * ice_aq_read_nvm
9  * @hw: pointer to the HW struct
10  * @module_typeid: module pointer location in words from the NVM beginning
11  * @offset: byte offset from the module beginning
12  * @length: length of the section to be read (in bytes from the offset)
13  * @data: command buffer (size [bytes] = length)
14  * @last_command: tells if this is the last command in a series
15  * @read_shadow_ram: tell if this is a shadow RAM read
16  * @cd: pointer to command details structure or NULL
17  *
18  * Read the NVM using the admin queue commands (0x0701)
19  */
20 static enum ice_status
21 ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length,
22                 void *data, bool last_command, bool read_shadow_ram,
23                 struct ice_sq_cd *cd)
24 {
25         struct ice_aq_desc desc;
26         struct ice_aqc_nvm *cmd;
27
28         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
29
30         cmd = &desc.params.nvm;
31
32         /* In offset the highest byte must be zeroed. */
33         if (offset & 0xFF000000)
34                 return ICE_ERR_PARAM;
35
36         ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_read);
37
38         if (!read_shadow_ram && module_typeid == ICE_AQC_NVM_START_POINT)
39                 cmd->cmd_flags |= ICE_AQC_NVM_FLASH_ONLY;
40
41         /* If this is the last command in a series, set the proper flag. */
42         if (last_command)
43                 cmd->cmd_flags |= ICE_AQC_NVM_LAST_CMD;
44         cmd->module_typeid = CPU_TO_LE16(module_typeid);
45         cmd->offset_low = CPU_TO_LE16(offset & 0xFFFF);
46         cmd->offset_high = (offset >> 16) & 0xFF;
47         cmd->length = CPU_TO_LE16(length);
48
49         return ice_aq_send_cmd(hw, &desc, data, length, cd);
50 }
51
52 /**
53  * ice_check_sr_access_params - verify params for Shadow RAM R/W operations.
54  * @hw: pointer to the HW structure
55  * @offset: offset in words from module start
56  * @words: number of words to access
57  */
58 static enum ice_status
59 ice_check_sr_access_params(struct ice_hw *hw, u32 offset, u16 words)
60 {
61         if ((offset + words) > hw->nvm.sr_words) {
62                 ice_debug(hw, ICE_DBG_NVM,
63                           "NVM error: offset beyond SR lmt.\n");
64                 return ICE_ERR_PARAM;
65         }
66
67         if (words > ICE_SR_SECTOR_SIZE_IN_WORDS) {
68                 /* We can access only up to 4KB (one sector), in one AQ write */
69                 ice_debug(hw, ICE_DBG_NVM,
70                           "NVM error: tried to access %d words, limit is %d.\n",
71                           words, ICE_SR_SECTOR_SIZE_IN_WORDS);
72                 return ICE_ERR_PARAM;
73         }
74
75         if (((offset + (words - 1)) / ICE_SR_SECTOR_SIZE_IN_WORDS) !=
76             (offset / ICE_SR_SECTOR_SIZE_IN_WORDS)) {
77                 /* A single access cannot spread over two sectors */
78                 ice_debug(hw, ICE_DBG_NVM,
79                           "NVM error: cannot spread over two sectors.\n");
80                 return ICE_ERR_PARAM;
81         }
82
83         return ICE_SUCCESS;
84 }
85
86 /**
87  * ice_read_sr_aq - Read Shadow RAM.
88  * @hw: pointer to the HW structure
89  * @offset: offset in words from module start
90  * @words: number of words to read
91  * @data: buffer for words reads from Shadow RAM
92  * @last_command: tells the AdminQ that this is the last command
93  *
94  * Reads 16-bit word buffers from the Shadow RAM using the admin command.
95  */
96 static enum ice_status
97 ice_read_sr_aq(struct ice_hw *hw, u32 offset, u16 words, u16 *data,
98                bool last_command)
99 {
100         enum ice_status status;
101
102         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
103
104         status = ice_check_sr_access_params(hw, offset, words);
105
106         /* values in "offset" and "words" parameters are sized as words
107          * (16 bits) but ice_aq_read_nvm expects these values in bytes.
108          * So do this conversion while calling ice_aq_read_nvm.
109          */
110         if (!status)
111                 status = ice_aq_read_nvm(hw, ICE_AQC_NVM_START_POINT,
112                                          2 * offset, 2 * words, data,
113                                          last_command, true, NULL);
114
115         return status;
116 }
117
118 /**
119  * ice_read_sr_word_aq - Reads Shadow RAM via AQ
120  * @hw: pointer to the HW structure
121  * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF)
122  * @data: word read from the Shadow RAM
123  *
124  * Reads one 16 bit word from the Shadow RAM using the ice_read_sr_aq method.
125  */
126 static enum ice_status
127 ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data)
128 {
129         enum ice_status status;
130
131         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
132
133         status = ice_read_sr_aq(hw, offset, 1, data, true);
134         if (!status)
135                 *data = LE16_TO_CPU(*(_FORCE_ __le16 *)data);
136
137         return status;
138 }
139
140 /**
141  * ice_read_sr_buf_aq - Reads Shadow RAM buf via AQ
142  * @hw: pointer to the HW structure
143  * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF)
144  * @words: (in) number of words to read; (out) number of words actually read
145  * @data: words read from the Shadow RAM
146  *
147  * Reads 16 bit words (data buf) from the SR using the ice_read_sr_aq
148  * method. Ownership of the NVM is taken before reading the buffer and later
149  * released.
150  */
151 static enum ice_status
152 ice_read_sr_buf_aq(struct ice_hw *hw, u16 offset, u16 *words, u16 *data)
153 {
154         enum ice_status status;
155         bool last_cmd = false;
156         u16 words_read = 0;
157         u16 i = 0;
158
159         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
160
161         do {
162                 u16 read_size, off_w;
163
164                 /* Calculate number of bytes we should read in this step.
165                  * It's not allowed to read more than one page at a time or
166                  * to cross page boundaries.
167                  */
168                 off_w = offset % ICE_SR_SECTOR_SIZE_IN_WORDS;
169                 read_size = off_w ?
170                         MIN_T(u16, *words,
171                               (ICE_SR_SECTOR_SIZE_IN_WORDS - off_w)) :
172                         MIN_T(u16, (*words - words_read),
173                               ICE_SR_SECTOR_SIZE_IN_WORDS);
174
175                 /* Check if this is last command, if so set proper flag */
176                 if ((words_read + read_size) >= *words)
177                         last_cmd = true;
178
179                 status = ice_read_sr_aq(hw, offset, read_size,
180                                         data + words_read, last_cmd);
181                 if (status)
182                         goto read_nvm_buf_aq_exit;
183
184                 /* Increment counter for words already read and move offset to
185                  * new read location
186                  */
187                 words_read += read_size;
188                 offset += read_size;
189         } while (words_read < *words);
190
191         for (i = 0; i < *words; i++)
192                 data[i] = LE16_TO_CPU(((_FORCE_ __le16 *)data)[i]);
193
194 read_nvm_buf_aq_exit:
195         *words = words_read;
196         return status;
197 }
198
199 /**
200  * ice_acquire_nvm - Generic request for acquiring the NVM ownership
201  * @hw: pointer to the HW structure
202  * @access: NVM access type (read or write)
203  *
204  * This function will request NVM ownership.
205  */
206 static enum ice_status
207 ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access)
208 {
209         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
210
211         if (hw->nvm.blank_nvm_mode)
212                 return ICE_SUCCESS;
213
214         return ice_acquire_res(hw, ICE_NVM_RES_ID, access, ICE_NVM_TIMEOUT);
215 }
216
217 /**
218  * ice_release_nvm - Generic request for releasing the NVM ownership
219  * @hw: pointer to the HW structure
220  *
221  * This function will release NVM ownership.
222  */
223 static void ice_release_nvm(struct ice_hw *hw)
224 {
225         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
226
227         if (hw->nvm.blank_nvm_mode)
228                 return;
229
230         ice_release_res(hw, ICE_NVM_RES_ID);
231 }
232
233 /**
234  * ice_read_sr_word - Reads Shadow RAM word and acquire NVM if necessary
235  * @hw: pointer to the HW structure
236  * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF)
237  * @data: word read from the Shadow RAM
238  *
239  * Reads one 16 bit word from the Shadow RAM using the ice_read_sr_word_aq.
240  */
241 enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data)
242 {
243         enum ice_status status;
244
245         status = ice_acquire_nvm(hw, ICE_RES_READ);
246         if (!status) {
247                 status = ice_read_sr_word_aq(hw, offset, data);
248                 ice_release_nvm(hw);
249         }
250
251         return status;
252 }
253
254 /**
255  * ice_init_nvm - initializes NVM setting
256  * @hw: pointer to the HW struct
257  *
258  * This function reads and populates NVM settings such as Shadow RAM size,
259  * max_timeout, and blank_nvm_mode
260  */
261 enum ice_status ice_init_nvm(struct ice_hw *hw)
262 {
263         u16 oem_hi, oem_lo, boot_cfg_tlv, boot_cfg_tlv_len;
264         struct ice_nvm_info *nvm = &hw->nvm;
265         u16 eetrack_lo, eetrack_hi;
266         enum ice_status status;
267         u32 fla, gens_stat;
268         u8 sr_size;
269
270         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
271
272         /* The SR size is stored regardless of the NVM programming mode
273          * as the blank mode may be used in the factory line.
274          */
275         gens_stat = rd32(hw, GLNVM_GENS);
276         sr_size = (gens_stat & GLNVM_GENS_SR_SIZE_M) >> GLNVM_GENS_SR_SIZE_S;
277
278         /* Switching to words (sr_size contains power of 2) */
279         nvm->sr_words = BIT(sr_size) * ICE_SR_WORDS_IN_1KB;
280
281         /* Check if we are in the normal or blank NVM programming mode */
282         fla = rd32(hw, GLNVM_FLA);
283         if (fla & GLNVM_FLA_LOCKED_M) { /* Normal programming mode */
284                 nvm->blank_nvm_mode = false;
285         } else {
286                 /* Blank programming mode */
287                 nvm->blank_nvm_mode = true;
288                 ice_debug(hw, ICE_DBG_NVM,
289                           "NVM init error: unsupported blank mode.\n");
290                 return ICE_ERR_NVM_BLANK_MODE;
291         }
292
293         status = ice_read_sr_word(hw, ICE_SR_NVM_DEV_STARTER_VER, &nvm->ver);
294         if (status) {
295                 ice_debug(hw, ICE_DBG_INIT,
296                           "Failed to read DEV starter version.\n");
297                 return status;
298         }
299
300         status = ice_read_sr_word(hw, ICE_SR_NVM_EETRACK_LO, &eetrack_lo);
301         if (status) {
302                 ice_debug(hw, ICE_DBG_INIT, "Failed to read EETRACK lo.\n");
303                 return status;
304         }
305         status = ice_read_sr_word(hw, ICE_SR_NVM_EETRACK_HI, &eetrack_hi);
306         if (status) {
307                 ice_debug(hw, ICE_DBG_INIT, "Failed to read EETRACK hi.\n");
308                 return status;
309         }
310
311         nvm->eetrack = (eetrack_hi << 16) | eetrack_lo;
312
313         switch (hw->device_id) {
314         /* the following devices do not have boot_cfg_tlv yet */
315         case ICE_DEV_ID_E822C_BACKPLANE:
316         case ICE_DEV_ID_E822C_QSFP:
317         case ICE_DEV_ID_E822C_10G_BASE_T:
318         case ICE_DEV_ID_E822C_SGMII:
319         case ICE_DEV_ID_E822C_SFP:
320         case ICE_DEV_ID_E822L_BACKPLANE:
321         case ICE_DEV_ID_E822L_SFP:
322         case ICE_DEV_ID_E822L_10G_BASE_T:
323         case ICE_DEV_ID_E822L_SGMII:
324                 return status;
325         default:
326                 break;
327         }
328
329         status = ice_get_pfa_module_tlv(hw, &boot_cfg_tlv, &boot_cfg_tlv_len,
330                                         ICE_SR_BOOT_CFG_PTR);
331         if (status) {
332                 ice_debug(hw, ICE_DBG_INIT,
333                           "Failed to read Boot Configuration Block TLV.\n");
334                 return status;
335         }
336
337         /* Boot Configuration Block must have length at least 2 words
338          * (Combo Image Version High and Combo Image Version Low)
339          */
340         if (boot_cfg_tlv_len < 2) {
341                 ice_debug(hw, ICE_DBG_INIT,
342                           "Invalid Boot Configuration Block TLV size.\n");
343                 return ICE_ERR_INVAL_SIZE;
344         }
345
346         status = ice_read_sr_word(hw, (boot_cfg_tlv + ICE_NVM_OEM_VER_OFF),
347                                   &oem_hi);
348         if (status) {
349                 ice_debug(hw, ICE_DBG_INIT, "Failed to read OEM_VER hi.\n");
350                 return status;
351         }
352
353         status = ice_read_sr_word(hw, (boot_cfg_tlv + ICE_NVM_OEM_VER_OFF + 1),
354                                   &oem_lo);
355         if (status) {
356                 ice_debug(hw, ICE_DBG_INIT, "Failed to read OEM_VER lo.\n");
357                 return status;
358         }
359
360         nvm->oem_ver = ((u32)oem_hi << 16) | oem_lo;
361
362         return ICE_SUCCESS;
363 }
364
365 /**
366  * ice_read_sr_buf - Reads Shadow RAM buf and acquire lock if necessary
367  * @hw: pointer to the HW structure
368  * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF)
369  * @words: (in) number of words to read; (out) number of words actually read
370  * @data: words read from the Shadow RAM
371  *
372  * Reads 16 bit words (data buf) from the SR using the ice_read_nvm_buf_aq
373  * method. The buf read is preceded by the NVM ownership take
374  * and followed by the release.
375  */
376 enum ice_status
377 ice_read_sr_buf(struct ice_hw *hw, u16 offset, u16 *words, u16 *data)
378 {
379         enum ice_status status;
380
381         status = ice_acquire_nvm(hw, ICE_RES_READ);
382         if (!status) {
383                 status = ice_read_sr_buf_aq(hw, offset, words, data);
384                 ice_release_nvm(hw);
385         }
386
387         return status;
388 }
389
390 /**
391  * ice_nvm_validate_checksum
392  * @hw: pointer to the HW struct
393  *
394  * Verify NVM PFA checksum validity (0x0706)
395  */
396 enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw)
397 {
398         struct ice_aqc_nvm_checksum *cmd;
399         struct ice_aq_desc desc;
400         enum ice_status status;
401
402         status = ice_acquire_nvm(hw, ICE_RES_READ);
403         if (status)
404                 return status;
405
406         cmd = &desc.params.nvm_checksum;
407
408         ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_checksum);
409         cmd->flags = ICE_AQC_NVM_CHECKSUM_VERIFY;
410
411         status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
412         ice_release_nvm(hw);
413
414         if (!status)
415                 if (LE16_TO_CPU(cmd->checksum) != ICE_AQC_NVM_CHECKSUM_CORRECT)
416                         status = ICE_ERR_NVM_CHECKSUM;
417
418         return status;
419 }
420
421 /**
422  * ice_nvm_access_get_features - Return the NVM access features structure
423  * @cmd: NVM access command to process
424  * @data: storage for the driver NVM features
425  *
426  * Fill in the data section of the NVM access request with a copy of the NVM
427  * features structure.
428  */
429 enum ice_status
430 ice_nvm_access_get_features(struct ice_nvm_access_cmd *cmd,
431                             union ice_nvm_access_data *data)
432 {
433         /* The provided data_size must be at least as large as our NVM
434          * features structure. A larger size should not be treated as an
435          * error, to allow future extensions to to the features structure to
436          * work on older drivers.
437          */
438         if (cmd->data_size < sizeof(struct ice_nvm_features))
439                 return ICE_ERR_NO_MEMORY;
440
441         /* Initialize the data buffer to zeros */
442         ice_memset(data, 0, cmd->data_size, ICE_NONDMA_MEM);
443
444         /* Fill in the features data */
445         data->drv_features.major = ICE_NVM_ACCESS_MAJOR_VER;
446         data->drv_features.minor = ICE_NVM_ACCESS_MINOR_VER;
447         data->drv_features.size = sizeof(struct ice_nvm_features);
448         data->drv_features.features[0] = ICE_NVM_FEATURES_0_REG_ACCESS;
449
450         return ICE_SUCCESS;
451 }
452
453 /**
454  * ice_nvm_access_get_module - Helper function to read module value
455  * @cmd: NVM access command structure
456  *
457  * Reads the module value out of the NVM access config field.
458  */
459 u32 ice_nvm_access_get_module(struct ice_nvm_access_cmd *cmd)
460 {
461         return ((cmd->config & ICE_NVM_CFG_MODULE_M) >> ICE_NVM_CFG_MODULE_S);
462 }
463
464 /**
465  * ice_nvm_access_get_flags - Helper function to read flags value
466  * @cmd: NVM access command structure
467  *
468  * Reads the flags value out of the NVM access config field.
469  */
470 u32 ice_nvm_access_get_flags(struct ice_nvm_access_cmd *cmd)
471 {
472         return ((cmd->config & ICE_NVM_CFG_FLAGS_M) >> ICE_NVM_CFG_FLAGS_S);
473 }
474
475 /**
476  * ice_nvm_access_get_adapter - Helper function to read adapter info
477  * @cmd: NVM access command structure
478  *
479  * Read the adapter info value out of the NVM access config field.
480  */
481 u32 ice_nvm_access_get_adapter(struct ice_nvm_access_cmd *cmd)
482 {
483         return ((cmd->config & ICE_NVM_CFG_ADAPTER_INFO_M) >>
484                 ICE_NVM_CFG_ADAPTER_INFO_S);
485 }
486
487 /**
488  * ice_validate_nvm_rw_reg - Check than an NVM access request is valid
489  * @cmd: NVM access command structure
490  *
491  * Validates that an NVM access structure is request to read or write a valid
492  * register offset. First validates that the module and flags are correct, and
493  * then ensures that the register offset is one of the accepted registers.
494  */
495 static enum ice_status
496 ice_validate_nvm_rw_reg(struct ice_nvm_access_cmd *cmd)
497 {
498         u32 module, flags, offset;
499         u16 i;
500
501         module = ice_nvm_access_get_module(cmd);
502         flags = ice_nvm_access_get_flags(cmd);
503         offset = cmd->offset;
504
505         /* Make sure the module and flags indicate a read/write request */
506         if (module != ICE_NVM_REG_RW_MODULE ||
507             flags != ICE_NVM_REG_RW_FLAGS ||
508             cmd->data_size != FIELD_SIZEOF(union ice_nvm_access_data, regval))
509                 return ICE_ERR_PARAM;
510
511         switch (offset) {
512         case GL_HICR:
513         case GL_HICR_EN: /* Note, this register is read only */
514         case GL_FWSTS:
515         case GL_MNG_FWSM:
516         case GLGEN_CSR_DEBUG_C:
517         case GLGEN_RSTAT:
518         case GLPCI_LBARCTRL:
519         case GLNVM_GENS:
520         case GLNVM_FLA:
521         case PF_FUNC_RID:
522                 return ICE_SUCCESS;
523         default:
524                 break;
525         }
526
527         for (i = 0; i <= ICE_NVM_ACCESS_GL_HIDA_MAX; i++)
528                 if (offset == (u32)GL_HIDA(i))
529                         return ICE_SUCCESS;
530
531         for (i = 0; i <= ICE_NVM_ACCESS_GL_HIBA_MAX; i++)
532                 if (offset == (u32)GL_HIBA(i))
533                         return ICE_SUCCESS;
534
535         /* All other register offsets are not valid */
536         return ICE_ERR_OUT_OF_RANGE;
537 }
538
539 /**
540  * ice_nvm_access_read - Handle an NVM read request
541  * @hw: pointer to the HW struct
542  * @cmd: NVM access command to process
543  * @data: storage for the register value read
544  *
545  * Process an NVM access request to read a register.
546  */
547 enum ice_status
548 ice_nvm_access_read(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
549                     union ice_nvm_access_data *data)
550 {
551         enum ice_status status;
552
553         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
554
555         /* Always initialize the output data, even on failure */
556         ice_memset(data, 0, cmd->data_size, ICE_NONDMA_MEM);
557
558         /* Make sure this is a valid read/write access request */
559         status = ice_validate_nvm_rw_reg(cmd);
560         if (status)
561                 return status;
562
563         ice_debug(hw, ICE_DBG_NVM, "NVM access: reading register %08x\n",
564                   cmd->offset);
565
566         /* Read the register and store the contents in the data field */
567         data->regval = rd32(hw, cmd->offset);
568
569         return ICE_SUCCESS;
570 }
571
572 /**
573  * ice_nvm_access_write - Handle an NVM write request
574  * @hw: pointer to the HW struct
575  * @cmd: NVM access command to process
576  * @data: NVM access data to write
577  *
578  * Process an NVM access request to write a register.
579  */
580 enum ice_status
581 ice_nvm_access_write(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
582                      union ice_nvm_access_data *data)
583 {
584         enum ice_status status;
585
586         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
587
588         /* Make sure this is a valid read/write access request */
589         status = ice_validate_nvm_rw_reg(cmd);
590         if (status)
591                 return status;
592
593         /* Reject requests to write to read-only registers */
594         switch (cmd->offset) {
595         case GL_HICR_EN:
596         case GLGEN_RSTAT:
597                 return ICE_ERR_OUT_OF_RANGE;
598         default:
599                 break;
600         }
601
602         ice_debug(hw, ICE_DBG_NVM,
603                   "NVM access: writing register %08x with value %08x\n",
604                   cmd->offset, data->regval);
605
606         /* Write the data field to the specified register */
607         wr32(hw, cmd->offset, data->regval);
608
609         return ICE_SUCCESS;
610 }
611
612 /**
613  * ice_handle_nvm_access - Handle an NVM access request
614  * @hw: pointer to the HW struct
615  * @cmd: NVM access command info
616  * @data: pointer to read or return data
617  *
618  * Process an NVM access request. Read the command structure information and
619  * determine if it is valid. If not, report an error indicating the command
620  * was invalid.
621  *
622  * For valid commands, perform the necessary function, copying the data into
623  * the provided data buffer.
624  */
625 enum ice_status
626 ice_handle_nvm_access(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
627                       union ice_nvm_access_data *data)
628 {
629         u32 module, flags, adapter_info;
630
631         ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
632
633         /* Extended flags are currently reserved and must be zero */
634         if ((cmd->config & ICE_NVM_CFG_EXT_FLAGS_M) != 0)
635                 return ICE_ERR_PARAM;
636
637         /* Adapter info must match the HW device ID */
638         adapter_info = ice_nvm_access_get_adapter(cmd);
639         if (adapter_info != hw->device_id)
640                 return ICE_ERR_PARAM;
641
642         switch (cmd->command) {
643         case ICE_NVM_CMD_READ:
644                 module = ice_nvm_access_get_module(cmd);
645                 flags = ice_nvm_access_get_flags(cmd);
646
647                 /* Getting the driver's NVM features structure shares the same
648                  * command type as reading a register. Read the config field
649                  * to determine if this is a request to get features.
650                  */
651                 if (module == ICE_NVM_GET_FEATURES_MODULE &&
652                     flags == ICE_NVM_GET_FEATURES_FLAGS &&
653                     cmd->offset == 0)
654                         return ice_nvm_access_get_features(cmd, data);
655                 else
656                         return ice_nvm_access_read(hw, cmd, data);
657         case ICE_NVM_CMD_WRITE:
658                 return ice_nvm_access_write(hw, cmd, data);
659         default:
660                 return ICE_ERR_PARAM;
661         }
662 }