From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8F1C8A0547; Thu, 21 Oct 2021 11:53:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE6D741260; Thu, 21 Oct 2021 11:51:15 +0200 (CEST) Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) by mails.dpdk.org (Postfix) with ESMTP id A7CBB411D6 for ; Thu, 21 Oct 2021 11:51:12 +0200 (CEST) X-QQ-mid: bizesmtp38t1634809869tbc1rm81 Received: from jiawenwu.trustnetic.com (unknown [183.129.236.74]) by esmtp6.qq.com (ESMTP) with id ; Thu, 21 Oct 2021 17:51:08 +0800 (CST) X-QQ-SSF: 01400000000000E0I000000A0000000 X-QQ-FEAT: k0yT7W7BRd1rE0xqJqQmyowLk5/rhDoEy+9pEyON9/FMFFqHUedNpfGdbxKT7 AxvtyUZbiyHjXoppC2dbkcfq0xOtYZUL1uauPEXIuZJRo+YJGNsAuEJkOoc9M33L4RmdG2V pgwU/anltwHQ9rTj/cRUIWCma/wnQPSAxMITDWmsKhRMyAZFQpVkbtBxU4VDfw4mcTxn25h HhvsrJ7qQe3FYaXu1FFztmqsJ2bwTBVe65SeWSbowFDdWYXMBRDetU/M5RijNk3T5+Hsq65 pGo2UN4NwGGCf0g4ZufIfjpwN/nImS2fyWS5S6zHyG+3ZkG/JjH/W7j65w/oNt8T1OsqgUX XqJVb47+LR1vkfq2PGzxD85cSaW7MzSsPTc+UXgQFn7SzPWYZQ= X-QQ-GoodBg: 2 From: Jiawen Wu To: dev@dpdk.org Cc: Jiawen Wu Date: Thu, 21 Oct 2021 17:50:18 +0800 Message-Id: <20211021095023.18288-22-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20211021095023.18288-1-jiawenwu@trustnetic.com> References: <20211021095023.18288-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Subject: [dpdk-dev] [PATCH v2 21/26] net/ngbe: support EEPROM dump X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Support to get and set device EEPROM data. Signed-off-by: Jiawen Wu --- 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 1652e611fb..8cc556aea0 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 cd547eee6f..0716357725 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 93072f5f34..9838e2966e 100644 --- a/drivers/net/ngbe/ngbe_ethdev.c +++ b/drivers/net/ngbe/ngbe_ethdev.c @@ -2672,6 +2672,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, @@ -2722,6 +2771,9 @@ static const struct eth_dev_ops ngbe_eth_dev_ops = { .set_mc_addr_list = ngbe_dev_set_mc_addr_list, .rx_burst_mode_get = ngbe_rx_burst_mode_get, .tx_burst_mode_get = ngbe_tx_burst_mode_get, + .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