This patch refines function to let eeprom checksum calculation return
either a negative error code on error, or the 16-bit checksum in IXGBE 
base code.

Signed-off-by: Changchun Ouyang <changchun.ouyang at intel.com>
---
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.c |  96 ++++++++++++++----------
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.h |   2 +-
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_type.h   |   2 +-
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.c   | 118 +++++++++++++++---------------
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.h   |   2 +-
 5 files changed, 123 insertions(+), 97 deletions(-)

diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.c 
b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.c
index e36b3a8..4bd004c 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.c
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.c
@@ -2096,8 +2096,10 @@ STATIC void ixgbe_release_eeprom(struct ixgbe_hw *hw)
 /**
  *  ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
  *  @hw: pointer to hardware structure
+ *
+ *  Returns a negative error code on error, or the 16-bit checksum
  **/
-u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
+s32 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
 {
        u16 i;
        u16 j;
@@ -2110,33 +2112,44 @@ u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw 
*hw)

        /* Include 0x0-0x3F in the checksum */
        for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
-               if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) {
+               if (hw->eeprom.ops.read(hw, i, &word)) {
                        DEBUGOUT("EEPROM read failed\n");
-                       break;
+                       return IXGBE_ERR_EEPROM;
                }
                checksum += word;
        }

        /* Include all data from pointers except for the fw pointer */
        for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
-               hw->eeprom.ops.read(hw, i, &pointer);
+               if (hw->eeprom.ops.read(hw, i, &pointer)) {
+                       DEBUGOUT("EEPROM read failed\n");
+                       return IXGBE_ERR_EEPROM;
+               }

-               /* Make sure the pointer seems valid */
-               if (pointer != 0xFFFF && pointer != 0) {
-                       hw->eeprom.ops.read(hw, pointer, &length);
+               /* If the pointer seems invalid */
+               if (pointer == 0xFFFF || pointer == 0)
+                       continue;
+
+               if (hw->eeprom.ops.read(hw, pointer, &length)) {
+                       DEBUGOUT("EEPROM read failed\n");
+                       return IXGBE_ERR_EEPROM;
+               }

-                       if (length != 0xFFFF && length != 0) {
-                               for (j = pointer+1; j <= pointer+length; j++) {
-                                       hw->eeprom.ops.read(hw, j, &word);
-                                       checksum += word;
-                               }
+               if (length == 0xFFFF || length == 0)
+                       continue;
+
+               for (j = pointer + 1; j <= pointer + length; j++) {
+                       if (hw->eeprom.ops.read(hw, j, &word)) {
+                               DEBUGOUT("EEPROM read failed\n");
+                               return IXGBE_ERR_EEPROM;
                        }
+                       checksum += word;
                }
        }

        checksum = (u16)IXGBE_EEPROM_SUM - checksum;

-       return checksum;
+       return (s32)checksum;
 }

 /**
@@ -2156,32 +2169,38 @@ s32 ixgbe_validate_eeprom_checksum_generic(struct 
ixgbe_hw *hw,

        DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");

-       /*
-        * Read the first word from the EEPROM. If this times out or fails, do
+       /* Read the first word from the EEPROM. If this times out or fails, do
         * not continue or we could be in for a very long wait while every
         * EEPROM read fails
         */
        status = hw->eeprom.ops.read(hw, 0, &checksum);
+       if (status) {
+               DEBUGOUT("EEPROM read failed\n");
+               return status;
+       }

-       if (status == IXGBE_SUCCESS) {
-               checksum = hw->eeprom.ops.calc_checksum(hw);
-
-               hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
+       status = hw->eeprom.ops.calc_checksum(hw);
+       if (status < 0)
+               return status;

-               /*
-                * Verify read checksum from EEPROM is the same as
-                * calculated checksum
-                */
-               if (read_checksum != checksum)
-                       status = IXGBE_ERR_EEPROM_CHECKSUM;
+       checksum = (u16)(status & 0xffff);

-               /* If the user cares, return the calculated checksum */
-               if (checksum_val)
-                       *checksum_val = checksum;
-       } else {
+       status = hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
+       if (status) {
                DEBUGOUT("EEPROM read failed\n");
+               return status;
        }

+       /* Verify read checksum from EEPROM is the same as
+        * calculated checksum
+        */
+       if (read_checksum != checksum)
+               status = IXGBE_ERR_EEPROM_CHECKSUM;
+
+       /* If the user cares, return the calculated checksum */
+       if (checksum_val)
+               *checksum_val = checksum;
+
        return status;
 }

@@ -2196,21 +2215,24 @@ s32 ixgbe_update_eeprom_checksum_generic(struct 
ixgbe_hw *hw)

        DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");

-       /*
-        * Read the first word from the EEPROM. If this times out or fails, do
+       /* Read the first word from the EEPROM. If this times out or fails, do
         * not continue or we could be in for a very long wait while every
         * EEPROM read fails
         */
        status = hw->eeprom.ops.read(hw, 0, &checksum);
-
-       if (status == IXGBE_SUCCESS) {
-               checksum = hw->eeprom.ops.calc_checksum(hw);
-               status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
-                                             checksum);
-       } else {
+       if (status) {
                DEBUGOUT("EEPROM read failed\n");
+               return status;
        }

+       status = hw->eeprom.ops.calc_checksum(hw);
+       if (status < 0)
+               return status;
+
+       checksum = (u16)(status & 0xffff);
+
+       status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, checksum);
+
        return status;
 }

diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.h 
b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.h
index 8ee1dba..03e71c0 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.h
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_common.h
@@ -88,7 +88,7 @@ s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, 
u16 offset,
                                       u16 *data);
 s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
                                              u16 words, u16 *data);
-u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw);
+s32 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw);
 s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
                                           u16 *checksum_val);
 s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw);
diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_type.h 
b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_type.h
index f4c2534..b266e94 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_type.h
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_type.h
@@ -3075,7 +3075,7 @@ struct ixgbe_eeprom_operations {
        s32 (*write_buffer)(struct ixgbe_hw *, u16, u16, u16 *);
        s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
        s32 (*update_checksum)(struct ixgbe_hw *);
-       u16 (*calc_checksum)(struct ixgbe_hw *);
+       s32 (*calc_checksum)(struct ixgbe_hw *);
 };

 struct ixgbe_mac_operations {
diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.c 
b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.c
index acb37c3..9cecd29 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.c
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.c
@@ -475,8 +475,10 @@ s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
  *  be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
  *
  *  @hw: pointer to hardware structure
+ *
+ *  Returns a negative error code on error, or the 16-bit checksum
  **/
-u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
+s32 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
 {
        u16 i, j;
        u16 checksum = 0;
@@ -495,9 +497,9 @@ u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)

        /* Include 0x0-0x3F in the checksum */
        for (i = 0; i <= checksum_last_word; i++) {
-               if (ixgbe_read_eerd_generic(hw, i, &word) != IXGBE_SUCCESS) {
+               if (ixgbe_read_eerd_generic(hw, i, &word)) {
                        DEBUGOUT("EEPROM read failed\n");
-                       break;
+                       return IXGBE_ERR_EEPROM;
                }
                if (i != IXGBE_EEPROM_CHECKSUM)
                        checksum += word;
@@ -510,9 +512,9 @@ u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
                if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
                        continue;

-               if (ixgbe_read_eerd_generic(hw, i, &pointer) != IXGBE_SUCCESS) {
+               if (ixgbe_read_eerd_generic(hw, i, &pointer)) {
                        DEBUGOUT("EEPROM read failed\n");
-                       break;
+                       return IXGBE_ERR_EEPROM;
                }

                /* Skip pointer section if the pointer is invalid. */
@@ -520,10 +522,9 @@ u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
                    pointer >= hw->eeprom.word_size)
                        continue;

-               if (ixgbe_read_eerd_generic(hw, pointer, &length) !=
-                   IXGBE_SUCCESS) {
+               if (ixgbe_read_eerd_generic(hw, pointer, &length)) {
                        DEBUGOUT("EEPROM read failed\n");
-                       break;
+                       return IXGBE_ERR_EEPROM;
                }

                /* Skip pointer section if length is invalid. */
@@ -531,11 +532,10 @@ u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
                    (pointer + length) >= hw->eeprom.word_size)
                        continue;

-               for (j = pointer+1; j <= pointer+length; j++) {
-                       if (ixgbe_read_eerd_generic(hw, j, &word) !=
-                           IXGBE_SUCCESS) {
+               for (j = pointer + 1; j <= pointer + length; j++) {
+                       if (ixgbe_read_eerd_generic(hw, j, &word)) {
                                DEBUGOUT("EEPROM read failed\n");
-                               break;
+                               return IXGBE_ERR_EEPROM;
                        }
                        checksum += word;
                }
@@ -543,7 +543,7 @@ u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)

        checksum = (u16)IXGBE_EEPROM_SUM - checksum;

-       return checksum;
+       return (s32)checksum;
 }

 /**
@@ -568,42 +568,44 @@ s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw 
*hw,
         * EEPROM read fails
         */
        status = hw->eeprom.ops.read(hw, 0, &checksum);
-
-       if (status != IXGBE_SUCCESS) {
+       if (status) {
                DEBUGOUT("EEPROM read failed\n");
-               goto out;
+               return status;
        }

-       if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
-           IXGBE_SUCCESS) {
-               checksum = hw->eeprom.ops.calc_checksum(hw);
+       if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
+               return IXGBE_ERR_SWFW_SYNC;

-               /*
-                * Do not use hw->eeprom.ops.read because we do not want to take
-                * the synchronization semaphores twice here.
-               */
-               ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
-                                       &read_checksum);
+       status = hw->eeprom.ops.calc_checksum(hw);
+       if (status < 0)
+               goto out;

-               /*
-                * Verify read checksum from EEPROM is the same as
-                * calculated checksum
-                */
-               if (read_checksum != checksum) {
-                       status = IXGBE_ERR_EEPROM_CHECKSUM;
-                       ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
-                                    "Invalid EEPROM checksum");
-               }
+       checksum = (u16)(status & 0xffff);

-               /* If the user cares, return the calculated checksum */
-               if (checksum_val)
-                       *checksum_val = checksum;
-               hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
-       } else {
-               status = IXGBE_ERR_SWFW_SYNC;
+       /* Do not use hw->eeprom.ops.read because we do not want to take
+        * the synchronization semaphores twice here.
+        */
+       status = ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
+                                        &read_checksum);
+       if (status)
+               goto out;
+
+       /* Verify read checksum from EEPROM is the same as
+        * calculated checksum
+        */
+       if (read_checksum != checksum) {
+               ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
+                            "Invalid EEPROM checksum");
+               status = IXGBE_ERR_EEPROM_CHECKSUM;
        }

+       /* If the user cares, return the calculated checksum */
+       if (checksum_val)
+               *checksum_val = checksum;
+
 out:
+       hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
+
        return status;
 }

@@ -627,29 +629,31 @@ s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
         * EEPROM read fails
         */
        status = hw->eeprom.ops.read(hw, 0, &checksum);
-
-       if (status != IXGBE_SUCCESS) {
+       if (status) {
                DEBUGOUT("EEPROM read failed\n");
                return status;
        }

-       if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
-           IXGBE_SUCCESS) {
-               checksum = hw->eeprom.ops.calc_checksum(hw);
+       if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
+               return IXGBE_ERR_SWFW_SYNC;

-               /*
-                * Do not use hw->eeprom.ops.write because we do not want to
-                * take the synchronization semaphores twice here.
-                */
-               status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM,
-                                                 checksum);
+       status = hw->eeprom.ops.calc_checksum(hw);
+       if (status < 0)
+               goto out;

-               if (status == IXGBE_SUCCESS)
-                       status = ixgbe_update_flash_X540(hw);
-               hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
-       } else {
-               status = IXGBE_ERR_SWFW_SYNC;
-       }
+       checksum = (u16)(status & 0xffff);
+
+       /* Do not use hw->eeprom.ops.write because we do not want to
+        * take the synchronization semaphores twice here.
+        */
+       status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM, checksum);
+       if (status)
+               goto out;
+
+       status = ixgbe_update_flash_X540(hw);
+
+out:
+       hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);

        return status;
 }
diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.h 
b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.h
index 4742f41..86158e6 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.h
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x540.h
@@ -55,7 +55,7 @@ s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw, u16 
offset, u16 words,
                                 u16 *data);
 s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw);
 s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw, u16 
*checksum_val);
-u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw);
+s32 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw);
 s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);

 s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
-- 
1.8.4.2

Reply via email to