From: Jie Liu <[email protected]>

This patch implements the logic to retrieve the firmware version and
Build ID from the hardware during device initialization.

The version is exposed to applications through the dev_info_get API.

Signed-off-by: Jie Liu <[email protected]>
---
 drivers/net/sxe2/sxe2_ethdev.c | 35 +++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index 14c8f6c16d..215ae772b5 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -120,7 +120,8 @@ static int32_t sxe2_udp_tunnel_port_add(struct rte_eth_dev 
*dev,
                                        struct rte_eth_udp_tunnel *tunnel_udp);
 static int32_t sxe2_udp_tunnel_port_del(struct rte_eth_dev *dev,
                                        struct rte_eth_udp_tunnel *tunnel_udp);
-
+static int32_t sxe2_fw_version_string_get(struct rte_eth_dev *dev,
+                                     char *fw_version, size_t fw_size);
 
 static const struct eth_dev_ops sxe2_eth_dev_ops = {
        .dev_configure              = sxe2_dev_configure,
@@ -181,6 +182,8 @@ static const struct eth_dev_ops sxe2_eth_dev_ops = {
        .xstats_reset               = sxe2_stats_info_reset,
 
        .queue_stats_mapping_set    = sxe2_queue_stats_mapping_set,
+
+       .fw_version_get             = sxe2_fw_version_string_get,
 };
 
 static int32_t sxe2_dev_configure(struct rte_eth_dev *dev)
@@ -1575,6 +1578,36 @@ static int32_t sxe2_eth_pmd_remove(struct 
sxe2_common_device *cdev)
        return ret;
 }
 
+static int32_t sxe2_fw_version_string_get(struct rte_eth_dev *dev, char 
*fw_version, size_t fw_size)
+{
+       struct sxe2_adapter *adapter =
+               SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
+       struct sxe2_fw_info *fw_info = &adapter->dev_info.fw;
+       int32_t ret_len;
+       int32_t ret;
+
+       ret_len = snprintf(fw_version, fw_size,
+                          "%u.%u.%u.%u",
+                          fw_info->main_version_id,
+                          fw_info->sub_version_id,
+                          fw_info->fix_version_id,
+                          fw_info->build_id);
+
+       if (ret_len < 0) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret_len += 1;
+       if (fw_size < (size_t)ret_len)
+               ret = -EINVAL;
+       else
+               ret = 0;
+
+out:
+       return ret;
+}
+
 static uint16_t sxe2_switchdev_repr_id_encode_get(struct sxe2_switchdev_info 
*switchdev_info)
 {
        enum rte_eth_representor_type type;
-- 
2.47.3

Reply via email to