igb: Update firmware version info for ethtool output.
authorCarolyn Wyborny <carolyn.wyborny@intel.com>
Thu, 18 Oct 2012 07:16:19 +0000 (07:16 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Tue, 30 Oct 2012 06:49:29 +0000 (23:49 -0700)
There are multiple places in our device nvm where the version is stored.
This update fixes some output errors with some types of images and
refactors the way the version data is gathered and stored for ethtool output.

Signed-off-by: Carolyn Wyborny <carolyn.wyborny@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/igb/e1000_defines.h
drivers/net/ethernet/intel/igb/e1000_nvm.c
drivers/net/ethernet/intel/igb/e1000_nvm.h
drivers/net/ethernet/intel/igb/igb_main.c

index de4b41ec3c402da0829357edc5f77c1821369a5e..e647cff9a5e3b981fed0d53de95c936f72f6d635 100644 (file)
 /* NVM Word Offsets */
 #define NVM_COMPAT                 0x0003
 #define NVM_ID_LED_SETTINGS        0x0004 /* SERDES output amplitude */
+#define NVM_VERSION                0x0005
 #define NVM_INIT_CONTROL2_REG      0x000F
 #define NVM_INIT_CONTROL3_PORT_B   0x0014
 #define NVM_INIT_CONTROL3_PORT_A   0x0024
 #define NVM_LED_1_CFG              0x001C
 #define NVM_LED_0_2_CFG            0x001F
 
+/* NVM version defines */
+#define NVM_ETRACK_WORD            0x0042
+#define NVM_COMB_VER_OFF           0x0083
+#define NVM_COMB_VER_PTR           0x003d
+#define NVM_MAJOR_MASK             0xF000
+#define NVM_MINOR_MASK             0x0FF0
+#define NVM_BUILD_MASK             0x000F
+#define NVM_COMB_VER_MASK          0x00FF
+#define NVM_MAJOR_SHIFT                12
+#define NVM_MINOR_SHIFT                 4
+#define NVM_COMB_VER_SHFT               8
+#define NVM_VER_INVALID            0xFFFF
+#define NVM_ETRACK_SHIFT               16
 
 #define E1000_NVM_CFG_DONE_PORT_0  0x040000 /* MNG config cycle done */
 #define E1000_NVM_CFG_DONE_PORT_1  0x080000 /* ...for second port */
index aa5fcdf3f357f033947857716d1f102310ebacab..54ff53905ffe70f7d16db93f93d7c23744d83023 100644 (file)
@@ -710,3 +710,73 @@ s32 igb_update_nvm_checksum(struct e1000_hw *hw)
 out:
        return ret_val;
 }
+
+/**
+ *  igb_get_fw_version - Get firmware version information
+ *  @hw: pointer to the HW structure
+ *  @fw_vers: pointer to output structure
+ *
+ *  unsupported MAC types will return all 0 version structure
+ **/
+void igb_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
+{
+       u16 eeprom_verh, eeprom_verl, comb_verh, comb_verl, comb_offset;
+       u16 fw_version;
+
+       memset(fw_vers, 0, sizeof(struct e1000_fw_version));
+
+       switch (hw->mac.type) {
+       case e1000_i211:
+               return;
+       case e1000_82575:
+       case e1000_82576:
+       case e1000_82580:
+       case e1000_i350:
+       case e1000_i210:
+               break;
+       default:
+               return;
+       }
+       /* basic eeprom version numbers */
+       hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
+       fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) >> NVM_MAJOR_SHIFT;
+       fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK);
+
+       /* etrack id */
+       hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
+       hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
+       fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) | eeprom_verl;
+
+       switch (hw->mac.type) {
+       case e1000_i210:
+       case e1000_i350:
+               /* find combo image version */
+               hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
+               if ((comb_offset != 0x0) && (comb_offset != NVM_VER_INVALID)) {
+
+                       hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
+                                        + 1), 1, &comb_verh);
+                       hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
+                                        1, &comb_verl);
+
+                       /* get Option Rom version if it exists and is valid */
+                       if ((comb_verh && comb_verl) &&
+                           ((comb_verh != NVM_VER_INVALID) &&
+                            (comb_verl != NVM_VER_INVALID))) {
+
+                               fw_vers->or_valid = true;
+                               fw_vers->or_major =
+                                       comb_verl >> NVM_COMB_VER_SHFT;
+                               fw_vers->or_build =
+                                       ((comb_verl << NVM_COMB_VER_SHFT)
+                                       | (comb_verh >> NVM_COMB_VER_SHFT));
+                               fw_vers->or_patch =
+                                       comb_verh & NVM_COMB_VER_MASK;
+                       }
+               }
+               break;
+       default:
+               break;
+       }
+       return;
+}
index 825b0228cac0ac5c17dcd9a903240b9a17d95e6b..7012d458c6f7eff8df5ae1c0e25cd4a5abaa486d 100644 (file)
@@ -40,4 +40,20 @@ s32  igb_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
 s32  igb_validate_nvm_checksum(struct e1000_hw *hw);
 s32  igb_update_nvm_checksum(struct e1000_hw *hw);
 
+struct e1000_fw_version {
+       u32 etrack_id;
+       u16 eep_major;
+       u16 eep_minor;
+
+       u8 invm_major;
+       u8 invm_minor;
+       u8 invm_img_type;
+
+       bool or_valid;
+       u16 or_major;
+       u16 or_build;
+       u16 or_patch;
+};
+void igb_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers);
+
 #endif
index b07d679b46f295d4535b5fadd948e63432e966df..df1e7907bbaff4d74bd16d48c5963633e31b1b7b 100644 (file)
@@ -1785,58 +1785,34 @@ static const struct net_device_ops igb_netdev_ops = {
 void igb_set_fw_version(struct igb_adapter *adapter)
 {
        struct e1000_hw *hw = &adapter->hw;
-       u16 eeprom_verh, eeprom_verl, comb_verh, comb_verl, comb_offset;
-       u16 major, build, patch, fw_version;
-       u32 etrack_id;
-
-       hw->nvm.ops.read(hw, 5, 1, &fw_version);
-       if (adapter->hw.mac.type != e1000_i211) {
-               hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh);
-               hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl);
-               etrack_id = (eeprom_verh << IGB_ETRACK_SHIFT) | eeprom_verl;
-
-               /* combo image version needs to be found */
-               hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
-               if ((comb_offset != 0x0) &&
-                   (comb_offset != IGB_NVM_VER_INVALID)) {
-                       hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
-                                        + 1), 1, &comb_verh);
-                       hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
-                                        1, &comb_verl);
-
-                       /* Only display Option Rom if it exists and is valid */
-                       if ((comb_verh && comb_verl) &&
-                           ((comb_verh != IGB_NVM_VER_INVALID) &&
-                            (comb_verl != IGB_NVM_VER_INVALID))) {
-                               major = comb_verl >> IGB_COMB_VER_SHFT;
-                               build = (comb_verl << IGB_COMB_VER_SHFT) |
-                                       (comb_verh >> IGB_COMB_VER_SHFT);
-                               patch = comb_verh & IGB_COMB_VER_MASK;
-                               snprintf(adapter->fw_version,
-                                        sizeof(adapter->fw_version),
-                                        "%d.%d%d, 0x%08x, %d.%d.%d",
-                                        (fw_version & IGB_MAJOR_MASK) >>
-                                        IGB_MAJOR_SHIFT,
-                                        (fw_version & IGB_MINOR_MASK) >>
-                                        IGB_MINOR_SHIFT,
-                                        (fw_version & IGB_BUILD_MASK),
-                                        etrack_id, major, build, patch);
-                               goto out;
-                       }
-               }
-               snprintf(adapter->fw_version, sizeof(adapter->fw_version),
-                        "%d.%d%d, 0x%08x",
-                        (fw_version & IGB_MAJOR_MASK) >> IGB_MAJOR_SHIFT,
-                        (fw_version & IGB_MINOR_MASK) >> IGB_MINOR_SHIFT,
-                        (fw_version & IGB_BUILD_MASK), etrack_id);
-       } else {
+       struct e1000_fw_version fw;
+
+       igb_get_fw_version(hw, &fw);
+
+       switch (hw->mac.type) {
+       case e1000_i211:
                snprintf(adapter->fw_version, sizeof(adapter->fw_version),
-                        "%d.%d%d",
-                        (fw_version & IGB_MAJOR_MASK) >> IGB_MAJOR_SHIFT,
-                        (fw_version & IGB_MINOR_MASK) >> IGB_MINOR_SHIFT,
-                        (fw_version & IGB_BUILD_MASK));
+                        "%2d.%2d-%d",
+                        fw.invm_major, fw.invm_minor, fw.invm_img_type);
+               break;
+
+       default:
+               /* if option is rom valid, display its version too */
+               if (fw.or_valid) {
+                       snprintf(adapter->fw_version,
+                                sizeof(adapter->fw_version),
+                                "%d.%d, 0x%08x, %d.%d.%d",
+                                fw.eep_major, fw.eep_minor, fw.etrack_id,
+                                fw.or_major, fw.or_build, fw.or_patch);
+               /* no option rom */
+               } else {
+                       snprintf(adapter->fw_version,
+                                sizeof(adapter->fw_version),
+                                "%d.%d, 0x%08x",
+                                fw.eep_major, fw.eep_minor, fw.etrack_id);
+               }
+               break;
        }
-out:
        return;
 }