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