Support to get and set device EEPROM data.

Signed-off-by: Jiawen Wu <jiawe...@trustnetic.com>
---
 doc/guides/nics/features/ngbe.ini   |  1 +
 drivers/net/ngbe/base/ngbe_dummy.h  | 12 +++++
 drivers/net/ngbe/base/ngbe_eeprom.c | 77 +++++++++++++++++++++++++++++
 drivers/net/ngbe/base/ngbe_eeprom.h |  5 ++
 drivers/net/ngbe/base/ngbe_hw.c     |  2 +
 drivers/net/ngbe/base/ngbe_mng.c    | 41 +++++++++++++++
 drivers/net/ngbe/base/ngbe_mng.h    | 13 +++++
 drivers/net/ngbe/base/ngbe_type.h   |  4 ++
 drivers/net/ngbe/ngbe_ethdev.c      | 52 +++++++++++++++++++
 9 files changed, 207 insertions(+)

diff --git a/doc/guides/nics/features/ngbe.ini 
b/doc/guides/nics/features/ngbe.ini
index 00150282cb..3c169ab774 100644
--- a/doc/guides/nics/features/ngbe.ini
+++ b/doc/guides/nics/features/ngbe.ini
@@ -35,6 +35,7 @@ Basic stats          = Y
 Extended stats       = Y
 Stats per queue      = Y
 FW version           = Y
+EEPROM dump          = Y
 Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
diff --git a/drivers/net/ngbe/base/ngbe_dummy.h 
b/drivers/net/ngbe/base/ngbe_dummy.h
index 9930a3a1d6..61b0d82bfb 100644
--- a/drivers/net/ngbe/base/ngbe_dummy.h
+++ b/drivers/net/ngbe/base/ngbe_dummy.h
@@ -33,11 +33,21 @@ static inline s32 ngbe_rom_init_params_dummy(struct ngbe_hw 
*TUP0)
 {
        return NGBE_ERR_OPS_DUMMY;
 }
+static inline s32 ngbe_rom_readw_buffer_dummy(struct ngbe_hw *TUP0, u32 TUP1,
+                                       u32 TUP2, void *TUP3)
+{
+       return NGBE_ERR_OPS_DUMMY;
+}
 static inline s32 ngbe_rom_read32_dummy(struct ngbe_hw *TUP0, u32 TUP1,
                                        u32 *TUP2)
 {
        return NGBE_ERR_OPS_DUMMY;
 }
+static inline s32 ngbe_rom_writew_buffer_dummy(struct ngbe_hw *TUP0, u32 TUP1,
+                                       u32 TUP2, void *TUP3)
+{
+       return NGBE_ERR_OPS_DUMMY;
+}
 static inline s32 ngbe_rom_validate_checksum_dummy(struct ngbe_hw *TUP0,
                                        u16 *TUP1)
 {
@@ -270,7 +280,9 @@ static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)
 {
        hw->bus.set_lan_id = ngbe_bus_set_lan_id_dummy;
        hw->rom.init_params = ngbe_rom_init_params_dummy;
+       hw->rom.readw_buffer = ngbe_rom_readw_buffer_dummy;
        hw->rom.read32 = ngbe_rom_read32_dummy;
+       hw->rom.writew_buffer = ngbe_rom_writew_buffer_dummy;
        hw->rom.validate_checksum = ngbe_rom_validate_checksum_dummy;
        hw->mac.init_hw = ngbe_mac_init_hw_dummy;
        hw->mac.reset_hw = ngbe_mac_reset_hw_dummy;
diff --git a/drivers/net/ngbe/base/ngbe_eeprom.c 
b/drivers/net/ngbe/base/ngbe_eeprom.c
index 9ae2f0badb..f9a876e9bd 100644
--- a/drivers/net/ngbe/base/ngbe_eeprom.c
+++ b/drivers/net/ngbe/base/ngbe_eeprom.c
@@ -161,6 +161,45 @@ void ngbe_release_eeprom_semaphore(struct ngbe_hw *hw)
        ngbe_flush(hw);
 }
 
+/**
+ *  ngbe_ee_read_buffer- Read EEPROM word(s) using hostif
+ *  @hw: pointer to hardware structure
+ *  @offset: offset of  word in the EEPROM to read
+ *  @words: number of words
+ *  @data: word(s) read from the EEPROM
+ *
+ *  Reads a 16 bit word(s) from the EEPROM using the hostif.
+ **/
+s32 ngbe_ee_readw_buffer(struct ngbe_hw *hw,
+                                    u32 offset, u32 words, void *data)
+{
+       const u32 mask = NGBE_MNGSEM_SWMBX | NGBE_MNGSEM_SWFLASH;
+       u32 addr = (offset << 1);
+       u32 len = (words << 1);
+       u8 *buf = (u8 *)data;
+       int err;
+
+       err = hw->mac.acquire_swfw_sync(hw, mask);
+       if (err)
+               return err;
+
+       while (len) {
+               u32 seg = (len <= NGBE_PMMBX_DATA_SIZE
+                               ? len : NGBE_PMMBX_DATA_SIZE);
+
+               err = ngbe_hic_sr_read(hw, addr, buf, seg);
+               if (err)
+                       break;
+
+               len -= seg;
+               addr += seg;
+               buf += seg;
+       }
+
+       hw->mac.release_swfw_sync(hw, mask);
+       return err;
+}
+
 /**
  *  ngbe_ee_read32 - Read EEPROM word using a host interface cmd
  *  @hw: pointer to hardware structure
@@ -185,6 +224,44 @@ s32 ngbe_ee_read32(struct ngbe_hw *hw, u32 addr, u32 *data)
        return err;
 }
 
+/**
+ *  ngbe_ee_write_buffer - Write EEPROM word(s) using hostif
+ *  @hw: pointer to hardware structure
+ *  @offset: offset of  word in the EEPROM to write
+ *  @words: number of words
+ *  @data: word(s) write to the EEPROM
+ *
+ *  Write a 16 bit word(s) to the EEPROM using the hostif.
+ **/
+s32 ngbe_ee_writew_buffer(struct ngbe_hw *hw,
+                                     u32 offset, u32 words, void *data)
+{
+       const u32 mask = NGBE_MNGSEM_SWMBX | NGBE_MNGSEM_SWFLASH;
+       u32 addr = (offset << 1);
+       u32 len = (words << 1);
+       u8 *buf = (u8 *)data;
+       int err;
+
+       err = hw->mac.acquire_swfw_sync(hw, mask);
+       if (err)
+               return err;
+
+       while (len) {
+               u32 seg = (len <= NGBE_PMMBX_DATA_SIZE
+                               ? len : NGBE_PMMBX_DATA_SIZE);
+
+               err = ngbe_hic_sr_write(hw, addr, buf, seg);
+               if (err)
+                       break;
+
+               len -= seg;
+               buf += seg;
+       }
+
+       hw->mac.release_swfw_sync(hw, mask);
+       return err;
+}
+
 /**
  *  ngbe_validate_eeprom_checksum_em - Validate EEPROM checksum
  *  @hw: pointer to hardware structure
diff --git a/drivers/net/ngbe/base/ngbe_eeprom.h 
b/drivers/net/ngbe/base/ngbe_eeprom.h
index 5f27425913..26ac686723 100644
--- a/drivers/net/ngbe/base/ngbe_eeprom.h
+++ b/drivers/net/ngbe/base/ngbe_eeprom.h
@@ -17,6 +17,11 @@ s32 ngbe_get_eeprom_semaphore(struct ngbe_hw *hw);
 void ngbe_release_eeprom_semaphore(struct ngbe_hw *hw);
 s32 ngbe_save_eeprom_version(struct ngbe_hw *hw);
 
+s32 ngbe_ee_readw_buffer(struct ngbe_hw *hw, u32 offset, u32 words,
+                               void *data);
 s32 ngbe_ee_read32(struct ngbe_hw *hw, u32 addr, u32 *data);
 
+s32 ngbe_ee_writew_buffer(struct ngbe_hw *hw, u32 offset, u32 words,
+                               void *data);
+
 #endif /* _NGBE_EEPROM_H_ */
diff --git a/drivers/net/ngbe/base/ngbe_hw.c b/drivers/net/ngbe/base/ngbe_hw.c
index 476e5f25cf..218e612461 100644
--- a/drivers/net/ngbe/base/ngbe_hw.c
+++ b/drivers/net/ngbe/base/ngbe_hw.c
@@ -1920,7 +1920,9 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
 
        /* EEPROM */
        rom->init_params = ngbe_init_eeprom_params;
+       rom->readw_buffer = ngbe_ee_readw_buffer;
        rom->read32 = ngbe_ee_read32;
+       rom->writew_buffer = ngbe_ee_writew_buffer;
        rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
 
        mac->mcft_size          = NGBE_EM_MC_TBL_SIZE;
diff --git a/drivers/net/ngbe/base/ngbe_mng.c b/drivers/net/ngbe/base/ngbe_mng.c
index 9416ea4c8d..a3dd8093ce 100644
--- a/drivers/net/ngbe/base/ngbe_mng.c
+++ b/drivers/net/ngbe/base/ngbe_mng.c
@@ -202,6 +202,47 @@ s32 ngbe_hic_sr_read(struct ngbe_hw *hw, u32 addr, u8 
*buf, int len)
        return 0;
 }
 
+/**
+ *  ngbe_hic_sr_write - Write EEPROM word using hostif
+ *  @hw: pointer to hardware structure
+ *  @offset: offset of  word in the EEPROM to write
+ *  @data: word write to the EEPROM
+ *
+ *  Write a 16 bit word to the EEPROM using the hostif.
+ **/
+s32 ngbe_hic_sr_write(struct ngbe_hw *hw, u32 addr, u8 *buf, int len)
+{
+       struct ngbe_hic_write_shadow_ram command;
+       u32 value;
+       int err = 0, i = 0, j = 0;
+
+       if (len > NGBE_PMMBX_DATA_SIZE)
+               return NGBE_ERR_HOST_INTERFACE_COMMAND;
+
+       memset(&command, 0, sizeof(command));
+       command.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
+       command.hdr.req.buf_lenh = 0;
+       command.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
+       command.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
+       command.address = cpu_to_be32(addr);
+       command.length = cpu_to_be16(len);
+
+       while (i < (len >> 2)) {
+               value = ((u32 *)buf)[i];
+               wr32a(hw, NGBE_MNGMBX, FW_NVM_DATA_OFFSET + i, value);
+               i++;
+       }
+
+       for (i <<= 2; i < len; i++)
+               ((u8 *)&value)[j++] = ((u8 *)buf)[i];
+
+       wr32a(hw, NGBE_MNGMBX, FW_NVM_DATA_OFFSET + (i >> 2), value);
+
+       UNREFERENCED_PARAMETER(&command);
+
+       return err;
+}
+
 s32 ngbe_hic_check_cap(struct ngbe_hw *hw)
 {
        struct ngbe_hic_read_shadow_ram command;
diff --git a/drivers/net/ngbe/base/ngbe_mng.h b/drivers/net/ngbe/base/ngbe_mng.h
index 6f368b028f..e3d0309cbc 100644
--- a/drivers/net/ngbe/base/ngbe_mng.h
+++ b/drivers/net/ngbe/base/ngbe_mng.h
@@ -18,6 +18,8 @@
 #define FW_CEM_RESP_STATUS_SUCCESS      0x1
 #define FW_READ_SHADOW_RAM_CMD          0x31
 #define FW_READ_SHADOW_RAM_LEN          0x6
+#define FW_WRITE_SHADOW_RAM_CMD         0x33
+#define FW_WRITE_SHADOW_RAM_LEN         0xA /* 8 plus 1 WORD to write */
 #define FW_DEFAULT_CHECKSUM             0xFF /* checksum always 0xFF */
 #define FW_NVM_DATA_OFFSET              3
 #define FW_EEPROM_CHECK_STATUS         0xE9
@@ -65,6 +67,17 @@ struct ngbe_hic_read_shadow_ram {
        u16 pad3;
 };
 
+struct ngbe_hic_write_shadow_ram {
+       union ngbe_hic_hdr2 hdr;
+       u32 address;
+       u16 length;
+       u16 pad2;
+       u16 data;
+       u16 pad3;
+};
+
 s32 ngbe_hic_sr_read(struct ngbe_hw *hw, u32 addr, u8 *buf, int len);
+s32 ngbe_hic_sr_write(struct ngbe_hw *hw, u32 addr, u8 *buf, int len);
+
 s32 ngbe_hic_check_cap(struct ngbe_hw *hw);
 #endif /* _NGBE_MNG_H_ */
diff --git a/drivers/net/ngbe/base/ngbe_type.h 
b/drivers/net/ngbe/base/ngbe_type.h
index 886dffc0db..32d3ab5d03 100644
--- a/drivers/net/ngbe/base/ngbe_type.h
+++ b/drivers/net/ngbe/base/ngbe_type.h
@@ -231,7 +231,11 @@ typedef u8* (*ngbe_mc_addr_itr) (struct ngbe_hw *hw, u8 
**mc_addr_ptr,
 
 struct ngbe_rom_info {
        s32 (*init_params)(struct ngbe_hw *hw);
+       s32 (*readw_buffer)(struct ngbe_hw *hw, u32 offset, u32 words,
+                           void *data);
        s32 (*read32)(struct ngbe_hw *hw, u32 addr, u32 *data);
+       s32 (*writew_buffer)(struct ngbe_hw *hw, u32 offset, u32 words,
+                            void *data);
        s32 (*validate_checksum)(struct ngbe_hw *hw, u16 *checksum_val);
 
        enum ngbe_eeprom_type type;
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 6ed836df9e..1cf4ca54af 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -2769,6 +2769,55 @@ ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
                                         ngbe_dev_addr_list_itr, TRUE);
 }
 
+static int
+ngbe_get_eeprom_length(struct rte_eth_dev *dev)
+{
+       struct ngbe_hw *hw = ngbe_dev_hw(dev);
+
+       /* Return unit is byte count */
+       return hw->rom.word_size * 2;
+}
+
+static int
+ngbe_get_eeprom(struct rte_eth_dev *dev,
+               struct rte_dev_eeprom_info *in_eeprom)
+{
+       struct ngbe_hw *hw = ngbe_dev_hw(dev);
+       struct ngbe_rom_info *eeprom = &hw->rom;
+       uint16_t *data = in_eeprom->data;
+       int first, length;
+
+       first = in_eeprom->offset >> 1;
+       length = in_eeprom->length >> 1;
+       if (first > hw->rom.word_size ||
+           ((first + length) > hw->rom.word_size))
+               return -EINVAL;
+
+       in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
+
+       return eeprom->readw_buffer(hw, first, length, data);
+}
+
+static int
+ngbe_set_eeprom(struct rte_eth_dev *dev,
+               struct rte_dev_eeprom_info *in_eeprom)
+{
+       struct ngbe_hw *hw = ngbe_dev_hw(dev);
+       struct ngbe_rom_info *eeprom = &hw->rom;
+       uint16_t *data = in_eeprom->data;
+       int first, length;
+
+       first = in_eeprom->offset >> 1;
+       length = in_eeprom->length >> 1;
+       if (first > hw->rom.word_size ||
+           ((first + length) > hw->rom.word_size))
+               return -EINVAL;
+
+       in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
+
+       return eeprom->writew_buffer(hw,  first, length, data);
+}
+
 static const struct eth_dev_ops ngbe_eth_dev_ops = {
        .dev_configure              = ngbe_dev_configure,
        .dev_infos_get              = ngbe_dev_info_get,
@@ -2819,6 +2868,9 @@ static const struct eth_dev_ops ngbe_eth_dev_ops = {
        .rss_hash_update            = ngbe_dev_rss_hash_update,
        .rss_hash_conf_get          = ngbe_dev_rss_hash_conf_get,
        .set_mc_addr_list           = ngbe_dev_set_mc_addr_list,
+       .get_eeprom_length          = ngbe_get_eeprom_length,
+       .get_eeprom                 = ngbe_get_eeprom,
+       .set_eeprom                 = ngbe_set_eeprom,
 };
 
 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
-- 
2.21.0.windows.1



Reply via email to