Re-write ice_get_orom_civd_data to allocate memory to store the
Option ROM data. This change significantly reduces the time
to read the Option ROM CIVD section from ~10 seconds down to ~1 second.

Signed-off-by: Jacob Keller <jacob.e.kel...@intel.com>
Signed-off-by: Qiming Yang <qiming.y...@intel.com>
---
 drivers/net/ice/base/ice_nvm.c | 50 +++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ice/base/ice_nvm.c b/drivers/net/ice/base/ice_nvm.c
index cb45cb8134..e46aded12a 100644
--- a/drivers/net/ice/base/ice_nvm.c
+++ b/drivers/net/ice/base/ice_nvm.c
@@ -724,43 +724,67 @@ static enum ice_status
 ice_get_orom_civd_data(struct ice_hw *hw, enum ice_bank_select bank,
                       struct ice_orom_civd_info *civd)
 {
-       struct ice_orom_civd_info tmp;
+       u8 *orom_data;
+       enum ice_status status;
        u32 offset;
 
        /* The CIVD section is located in the Option ROM aligned to 512 bytes.
         * The first 4 bytes must contain the ASCII characters "$CIV".
         * A simple modulo 256 sum of all of the bytes of the structure must
         * equal 0.
+        *
+        * The exact location is unknown and varies between images but is
+        * usually somewhere in the middle of the bank. We need to scan the
+        * Option ROM bank to locate it.
+        *
+        * It's significantly faster to read the entire Option ROM up front
+        * using the maximum page size, than to read each possible location
+        * with a separate firmware command.
         */
+       orom_data = (u8 *)ice_calloc(hw, hw->flash.banks.orom_size, sizeof(u8));
+       if (!orom_data)
+               return ICE_ERR_NO_MEMORY;
+
+       status = ice_read_flash_module(hw, bank, ICE_SR_1ST_OROM_BANK_PTR, 0,
+                                      orom_data, hw->flash.banks.orom_size);
+       if (status) {
+               ice_debug(hw, ICE_DBG_NVM, "Unable to read Option ROM data\n");
+               return status;
+       }
+
+       /* Scan the memory buffer to locate the CIVD data section */
        for (offset = 0; (offset + 512) <= hw->flash.banks.orom_size; offset += 
512) {
-               enum ice_status status;
+               struct ice_orom_civd_info *tmp;
                u8 sum = 0, i;
 
-               status = ice_read_flash_module(hw, bank, 
ICE_SR_1ST_OROM_BANK_PTR,
-                                              offset, (u8 *)&tmp, sizeof(tmp));
-               if (status) {
-                       ice_debug(hw, ICE_DBG_NVM, "Unable to read Option ROM 
CIVD data\n");
-                       return status;
-               }
+               tmp = (struct ice_orom_civd_info *)&orom_data[offset];
 
                /* Skip forward until we find a matching signature */
-               if (memcmp("$CIV", tmp.signature, sizeof(tmp.signature)) != 0)
+               if (memcmp("$CIV", tmp->signature, sizeof(tmp->signature)) != 0)
                        continue;
 
+               ice_debug(hw, ICE_DBG_NVM, "Found CIVD section at offset %u\n",
+                         offset);
+
                /* Verify that the simple checksum is zero */
-               for (i = 0; i < sizeof(tmp); i++)
-                       sum += ((u8 *)&tmp)[i];
+               for (i = 0; i < sizeof(*tmp); i++)
+                       sum += ((u8 *)tmp)[i];
 
                if (sum) {
                        ice_debug(hw, ICE_DBG_NVM, "Found CIVD data with 
invalid checksum of %u\n",
                                  sum);
-                       return ICE_ERR_NVM;
+                       goto err_invalid_checksum;
                }
 
-               *civd = tmp;
+               *civd = *tmp;
+               ice_free(hw, orom_data);
                return ICE_SUCCESS;
        }
 
+       ice_debug(hw, ICE_DBG_NVM, "Unable to locate CIVD data within the 
Option ROM\n");
+
+err_invalid_checksum:
+       ice_free(hw, orom_data);
        return ICE_ERR_NVM;
 }
 
-- 
2.25.1

Reply via email to