hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/intel/i40e/i40e_nvm.c
....@@ -210,11 +210,11 @@
210210 * @hw: pointer to the HW structure.
211211 * @module_pointer: module pointer location in words from the NVM beginning
212212 * @offset: offset in words from module start
213
- * @words: number of words to write
214
- * @data: buffer with words to write to the Shadow RAM
213
+ * @words: number of words to read
214
+ * @data: buffer with words to read to the Shadow RAM
215215 * @last_command: tells the AdminQ that this is the last command
216216 *
217
- * Writes a 16 bit words buffer to the Shadow RAM using the admin command.
217
+ * Reads a 16 bit words buffer to the Shadow RAM using the admin command.
218218 **/
219219 static i40e_status i40e_read_nvm_aq(struct i40e_hw *hw,
220220 u8 module_pointer, u32 offset,
....@@ -234,18 +234,18 @@
234234 */
235235 if ((offset + words) > hw->nvm.sr_size)
236236 i40e_debug(hw, I40E_DEBUG_NVM,
237
- "NVM write error: offset %d beyond Shadow RAM limit %d\n",
237
+ "NVM read error: offset %d beyond Shadow RAM limit %d\n",
238238 (offset + words), hw->nvm.sr_size);
239239 else if (words > I40E_SR_SECTOR_SIZE_IN_WORDS)
240
- /* We can write only up to 4KB (one sector), in one AQ write */
240
+ /* We can read only up to 4KB (one sector), in one AQ write */
241241 i40e_debug(hw, I40E_DEBUG_NVM,
242
- "NVM write fail error: tried to write %d words, limit is %d.\n",
242
+ "NVM read fail error: tried to read %d words, limit is %d.\n",
243243 words, I40E_SR_SECTOR_SIZE_IN_WORDS);
244244 else if (((offset + (words - 1)) / I40E_SR_SECTOR_SIZE_IN_WORDS)
245245 != (offset / I40E_SR_SECTOR_SIZE_IN_WORDS))
246
- /* A single write cannot spread over two sectors */
246
+ /* A single read cannot spread over two sectors */
247247 i40e_debug(hw, I40E_DEBUG_NVM,
248
- "NVM write error: cannot spread over two sectors in a single write offset=%d words=%d\n",
248
+ "NVM read error: cannot spread over two sectors in a single read offset=%d words=%d\n",
249249 offset, words);
250250 else
251251 ret_code = i40e_aq_read_nvm(hw, module_pointer,
....@@ -319,6 +319,80 @@
319319 i40e_release_nvm(hw);
320320
321321 return ret_code;
322
+}
323
+
324
+/**
325
+ * i40e_read_nvm_module_data - Reads NVM Buffer to specified memory location
326
+ * @hw: Pointer to the HW structure
327
+ * @module_ptr: Pointer to module in words with respect to NVM beginning
328
+ * @module_offset: Offset in words from module start
329
+ * @data_offset: Offset in words from reading data area start
330
+ * @words_data_size: Words to read from NVM
331
+ * @data_ptr: Pointer to memory location where resulting buffer will be stored
332
+ **/
333
+enum i40e_status_code i40e_read_nvm_module_data(struct i40e_hw *hw,
334
+ u8 module_ptr,
335
+ u16 module_offset,
336
+ u16 data_offset,
337
+ u16 words_data_size,
338
+ u16 *data_ptr)
339
+{
340
+ i40e_status status;
341
+ u16 specific_ptr = 0;
342
+ u16 ptr_value = 0;
343
+ u32 offset = 0;
344
+
345
+ if (module_ptr != 0) {
346
+ status = i40e_read_nvm_word(hw, module_ptr, &ptr_value);
347
+ if (status) {
348
+ i40e_debug(hw, I40E_DEBUG_ALL,
349
+ "Reading nvm word failed.Error code: %d.\n",
350
+ status);
351
+ return I40E_ERR_NVM;
352
+ }
353
+ }
354
+#define I40E_NVM_INVALID_PTR_VAL 0x7FFF
355
+#define I40E_NVM_INVALID_VAL 0xFFFF
356
+
357
+ /* Pointer not initialized */
358
+ if (ptr_value == I40E_NVM_INVALID_PTR_VAL ||
359
+ ptr_value == I40E_NVM_INVALID_VAL) {
360
+ i40e_debug(hw, I40E_DEBUG_ALL, "Pointer not initialized.\n");
361
+ return I40E_ERR_BAD_PTR;
362
+ }
363
+
364
+ /* Check whether the module is in SR mapped area or outside */
365
+ if (ptr_value & I40E_PTR_TYPE) {
366
+ /* Pointer points outside of the Shared RAM mapped area */
367
+ i40e_debug(hw, I40E_DEBUG_ALL,
368
+ "Reading nvm data failed. Pointer points outside of the Shared RAM mapped area.\n");
369
+
370
+ return I40E_ERR_PARAM;
371
+ } else {
372
+ /* Read from the Shadow RAM */
373
+
374
+ status = i40e_read_nvm_word(hw, ptr_value + module_offset,
375
+ &specific_ptr);
376
+ if (status) {
377
+ i40e_debug(hw, I40E_DEBUG_ALL,
378
+ "Reading nvm word failed.Error code: %d.\n",
379
+ status);
380
+ return I40E_ERR_NVM;
381
+ }
382
+
383
+ offset = ptr_value + module_offset + specific_ptr +
384
+ data_offset;
385
+
386
+ status = i40e_read_nvm_buffer(hw, offset, &words_data_size,
387
+ data_ptr);
388
+ if (status) {
389
+ i40e_debug(hw, I40E_DEBUG_ALL,
390
+ "Reading nvm buffer failed.Error code: %d.\n",
391
+ status);
392
+ }
393
+ }
394
+
395
+ return status;
322396 }
323397
324398 /**
....@@ -427,6 +501,36 @@
427501 return i40e_read_nvm_buffer_aq(hw, offset, words, data);
428502
429503 return i40e_read_nvm_buffer_srctl(hw, offset, words, data);
504
+}
505
+
506
+/**
507
+ * i40e_read_nvm_buffer - Reads Shadow RAM buffer and acquire lock if necessary
508
+ * @hw: pointer to the HW structure
509
+ * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF).
510
+ * @words: (in) number of words to read; (out) number of words actually read
511
+ * @data: words read from the Shadow RAM
512
+ *
513
+ * Reads 16 bit words (data buffer) from the SR using the i40e_read_nvm_srrd()
514
+ * method. The buffer read is preceded by the NVM ownership take
515
+ * and followed by the release.
516
+ **/
517
+i40e_status i40e_read_nvm_buffer(struct i40e_hw *hw, u16 offset,
518
+ u16 *words, u16 *data)
519
+{
520
+ i40e_status ret_code = 0;
521
+
522
+ if (hw->flags & I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE) {
523
+ ret_code = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
524
+ if (!ret_code) {
525
+ ret_code = i40e_read_nvm_buffer_aq(hw, offset, words,
526
+ data);
527
+ i40e_release_nvm(hw);
528
+ }
529
+ } else {
530
+ ret_code = i40e_read_nvm_buffer_srctl(hw, offset, words, data);
531
+ }
532
+
533
+ return ret_code;
430534 }
431535
432536 /**
....@@ -578,11 +682,10 @@
578682 __le16 le_sum;
579683
580684 ret_code = i40e_calc_nvm_checksum(hw, &checksum);
581
- if (!ret_code) {
582
- le_sum = cpu_to_le16(checksum);
685
+ le_sum = cpu_to_le16(checksum);
686
+ if (!ret_code)
583687 ret_code = i40e_write_nvm_aq(hw, 0x00, I40E_SR_SW_CHECKSUM_WORD,
584688 1, &le_sum, true);
585
- }
586689
587690 return ret_code;
588691 }