[1/2] net/nfp: align reading of version info with kernel driver

Message ID 20230522114009.2099371-2-chaoyong.he@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series add support of showing firmware version |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure

Commit Message

Chaoyong He May 22, 2023, 11:40 a.m. UTC
  Align the method of reading the version information with the linux
driver. This is done to make it easier to share code between the
DPDK PMD and the kernel driver.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.c |  4 ++--
 drivers/net/nfp/nfp_common.c        | 30 +++++++++++++++++++----------
 drivers/net/nfp/nfp_common.h        | 21 ++------------------
 drivers/net/nfp/nfp_ctrl.h          | 22 +++++++++++++--------
 drivers/net/nfp/nfp_ethdev.c        | 10 +++++-----
 drivers/net/nfp/nfp_ethdev_vf.c     | 10 +++++-----
 drivers/net/nfp/nfp_rxtx.c          |  6 +++---
 7 files changed, 51 insertions(+), 52 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 72933e55d0..778ea777dd 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -650,7 +650,7 @@  nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type)
 	hw->rx_bar = pf_dev->hw_queues + rx_bar_off;
 
 	/* Get some of the read-only fields from the config BAR */
-	hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
+	nfp_net_cfg_read_version(hw);
 	hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
 	hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
 	/* Set the current MTU to the maximum supported */
@@ -661,7 +661,7 @@  nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type)
 		return -ENODEV;
 
 	/* read the Rx offset configured from firmware */
-	if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
+	if (hw->ver.major < 2)
 		hw->rx_offset = NFP_NET_RX_OFFSET;
 	else
 		hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index c9fea765a4..a9af215626 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -356,8 +356,7 @@  void
 nfp_net_log_device_information(const struct nfp_net_hw *hw)
 {
 	PMD_INIT_LOG(INFO, "VER: %u.%u, Maximum supported MTU: %d",
-			NFD_CFG_MAJOR_VERSION_of(hw->ver),
-			NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
+			hw->ver.major, hw->ver.minor, hw->max_mtu);
 
 	PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
 			hw->cap & NFP_NET_CFG_CTRL_PROMISC   ? "PROMISC "   : "",
@@ -1114,14 +1113,14 @@  nfp_net_tx_desc_limits(struct nfp_net_hw *hw,
 {
 	uint16_t tx_dpp;
 
-	switch (NFD_CFG_CLASS_VER_of(hw->ver)) {
+	switch (hw->ver.extend) {
 	case NFP_NET_CFG_VERSION_DP_NFD3:
 		tx_dpp = NFD3_TX_DESC_PER_PKT;
 		break;
 	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 5) {
+		if (hw->ver.major < 5) {
 			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-				NFD_CFG_MAJOR_VERSION_of(hw->ver));
+					hw->ver.major);
 			return -EINVAL;
 		}
 		tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT;
@@ -1911,11 +1910,10 @@  nfp_net_set_vxlan_port(struct nfp_net_hw *hw,
 int
 nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name)
 {
-	if (NFD_CFG_CLASS_VER_of(hw->ver) == NFP_NET_CFG_VERSION_DP_NFD3 &&
+	if (hw->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3 &&
 			rte_mem_check_dma_mask(40) != 0) {
-		PMD_DRV_LOG(ERR,
-			"The device %s can't be used: restricted dma mask to 40 bits!",
-			name);
+		PMD_DRV_LOG(ERR, "Device %s can't be used: restricted dma mask to 40 bits!",
+				name);
 		return -ENODEV;
 	}
 
@@ -1930,7 +1928,7 @@  nfp_net_init_metadata_format(struct nfp_net_hw *hw)
 	 * single metadata if only RSS(v1) is supported by hw capability, and RSS(v2)
 	 * also indicate that we are using chained metadata.
 	 */
-	if (NFD_CFG_MAJOR_VERSION_of(hw->ver) == 4) {
+	if (hw->ver.major == 4) {
 		hw->meta_format = NFP_NET_METAFORMAT_CHAINED;
 	} else if ((hw->cap & NFP_NET_CFG_CTRL_CHAIN_META) != 0) {
 		hw->meta_format = NFP_NET_METAFORMAT_CHAINED;
@@ -1944,3 +1942,15 @@  nfp_net_init_metadata_format(struct nfp_net_hw *hw)
 		hw->meta_format = NFP_NET_METAFORMAT_SINGLE;
 	}
 }
+
+void
+nfp_net_cfg_read_version(struct nfp_net_hw *hw)
+{
+	union {
+		uint32_t whole;
+		struct nfp_net_fw_ver split;
+	} version;
+
+	version.whole = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
+	hw->ver = version.split;
+}
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index 47df0510c5..424b18b0ad 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -80,24 +80,6 @@  struct nfp_net_adapter;
 #define NFP_NET_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
 #define NFP_NET_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
 
-/* Version number helper defines */
-#define NFD_CFG_CLASS_VER_msk       0xff
-#define NFD_CFG_CLASS_VER_shf       24
-#define NFD_CFG_CLASS_VER(x)        (((x) & 0xff) << 24)
-#define NFD_CFG_CLASS_VER_of(x)     (((x) >> 24) & 0xff)
-#define NFD_CFG_CLASS_TYPE_msk      0xff
-#define NFD_CFG_CLASS_TYPE_shf      16
-#define NFD_CFG_CLASS_TYPE(x)       (((x) & 0xff) << 16)
-#define NFD_CFG_CLASS_TYPE_of(x)    (((x) >> 16) & 0xff)
-#define NFD_CFG_MAJOR_VERSION_msk   0xff
-#define NFD_CFG_MAJOR_VERSION_shf   8
-#define NFD_CFG_MAJOR_VERSION(x)    (((x) & 0xff) << 8)
-#define NFD_CFG_MAJOR_VERSION_of(x) (((x) >> 8) & 0xff)
-#define NFD_CFG_MINOR_VERSION_msk   0xff
-#define NFD_CFG_MINOR_VERSION_shf   0
-#define NFD_CFG_MINOR_VERSION(x)    (((x) & 0xff) << 0)
-#define NFD_CFG_MINOR_VERSION_of(x) (((x) >> 0) & 0xff)
-
 /* Number of supported physical ports */
 #define NFP_MAX_PHYPORTS	12
 
@@ -196,7 +178,7 @@  struct nfp_net_hw {
 	struct rte_eth_dev *eth_dev;
 
 	/* Info from the firmware */
-	uint32_t ver;
+	struct nfp_net_fw_ver ver;
 	uint32_t cap;
 	uint32_t max_mtu;
 	uint32_t mtu;
@@ -490,6 +472,7 @@  int nfp_net_tx_desc_limits(struct nfp_net_hw *hw,
 		uint16_t *max_tx_desc);
 int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name);
 void nfp_net_init_metadata_format(struct nfp_net_hw *hw);
+void nfp_net_cfg_read_version(struct nfp_net_hw *hw);
 
 #define NFP_NET_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct nfp_net_adapter *)adapter)->hw)
diff --git a/drivers/net/nfp/nfp_ctrl.h b/drivers/net/nfp/nfp_ctrl.h
index bca31ac311..ff2245dfff 100644
--- a/drivers/net/nfp/nfp_ctrl.h
+++ b/drivers/net/nfp/nfp_ctrl.h
@@ -130,6 +130,20 @@ 
 
 #define NFP_NET_CFG_CTRL_CHAIN_META (NFP_NET_CFG_CTRL_RSS2 | \
 					NFP_NET_CFG_CTRL_CSUM_COMPLETE)
+
+/* Version number helper defines */
+struct nfp_net_fw_ver {
+	uint8_t minor;
+	uint8_t major;
+	uint8_t class;
+	/**
+	 * This byte can be extended for more use.
+	 * BIT0: NFD dp type, refer NFP_NET_CFG_VERSION_DP_NFDx
+	 * BIT[7:1]: reserved
+	 */
+	uint8_t extend;
+};
+
 /*
  * Read-only words (0x0030 - 0x0050):
  * @NFP_NET_CFG_VERSION:     Firmware version number
@@ -147,14 +161,6 @@ 
 #define NFP_NET_CFG_VERSION             0x0030
 #define   NFP_NET_CFG_VERSION_DP_NFD3   0
 #define   NFP_NET_CFG_VERSION_DP_NFDK   1
-#define   NFP_NET_CFG_VERSION_RESERVED_MASK	(0xff << 24)
-#define   NFP_NET_CFG_VERSION_CLASS_MASK  (0xff << 16)
-#define   NFP_NET_CFG_VERSION_CLASS(x)    (((x) & 0xff) << 16)
-#define   NFP_NET_CFG_VERSION_CLASS_GENERIC	0
-#define   NFP_NET_CFG_VERSION_MAJOR_MASK  (0xff <<  8)
-#define   NFP_NET_CFG_VERSION_MAJOR(x)    (((x) & 0xff) <<  8)
-#define   NFP_NET_CFG_VERSION_MINOR_MASK  (0xff <<  0)
-#define   NFP_NET_CFG_VERSION_MINOR(x)    (((x) & 0xff) <<  0)
 #define NFP_NET_CFG_STS                 0x0034
 #define   NFP_NET_CFG_STS_LINK            (0x1 << 0) /* Link up or down */
 /* Link rate */
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 722ec17dce..0b2dd7801b 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -466,14 +466,14 @@  static const struct eth_dev_ops nfp_net_eth_dev_ops = {
 static inline int
 nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)
 {
-	switch (NFD_CFG_CLASS_VER_of(hw->ver)) {
+	switch (hw->ver.extend) {
 	case NFP_NET_CFG_VERSION_DP_NFD3:
 		eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;
 		break;
 	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 5) {
+		if (hw->ver.major < 5) {
 			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-				NFD_CFG_MAJOR_VERSION_of(hw->ver));
+					hw->ver.major);
 			return -EINVAL;
 		}
 		eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;
@@ -571,7 +571,7 @@  nfp_net_init(struct rte_eth_dev *eth_dev)
 	PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
 	PMD_INIT_LOG(DEBUG, "MAC stats: %p", hw->mac_stats);
 
-	hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
+	nfp_net_cfg_read_version(hw);
 
 	if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
 		return -ENODEV;
@@ -629,7 +629,7 @@  nfp_net_init(struct rte_eth_dev *eth_dev)
 
 	nfp_net_init_metadata_format(hw);
 
-	if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
+	if (hw->ver.major < 2)
 		hw->rx_offset = NFP_NET_RX_OFFSET;
 	else
 		hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index ce55e3b728..cf3548e63a 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -246,14 +246,14 @@  static const struct eth_dev_ops nfp_netvf_eth_dev_ops = {
 static inline int
 nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)
 {
-	switch (NFD_CFG_CLASS_VER_of(hw->ver)) {
+	switch (hw->ver.extend) {
 	case NFP_NET_CFG_VERSION_DP_NFD3:
 		eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;
 		break;
 	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 5) {
+		if (hw->ver.major < 5) {
 			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-				NFD_CFG_MAJOR_VERSION_of(hw->ver));
+					hw->ver.major);
 			return -EINVAL;
 		}
 		eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;
@@ -298,7 +298,7 @@  nfp_netvf_init(struct rte_eth_dev *eth_dev)
 
 	PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
 
-	hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
+	nfp_net_cfg_read_version(hw);
 
 	if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
 		return -ENODEV;
@@ -380,7 +380,7 @@  nfp_netvf_init(struct rte_eth_dev *eth_dev)
 
 	nfp_net_init_metadata_format(hw);
 
-	if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
+	if (hw->ver.major < 2)
 		hw->rx_offset = NFP_NET_RX_OFFSET;
 	else
 		hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c
index 3c78557221..478752fa14 100644
--- a/drivers/net/nfp/nfp_rxtx.c
+++ b/drivers/net/nfp/nfp_rxtx.c
@@ -764,14 +764,14 @@  nfp_net_tx_queue_setup(struct rte_eth_dev *dev,
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	switch (NFD_CFG_CLASS_VER_of(hw->ver)) {
+	switch (hw->ver.extend) {
 	case NFP_NET_CFG_VERSION_DP_NFD3:
 		return nfp_net_nfd3_tx_queue_setup(dev, queue_idx,
 				nb_desc, socket_id, tx_conf);
 	case NFP_NET_CFG_VERSION_DP_NFDK:
-		if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 5) {
+		if (hw->ver.major < 5) {
 			PMD_DRV_LOG(ERR, "NFDK must use ABI 5 or newer, found: %d",
-				NFD_CFG_MAJOR_VERSION_of(hw->ver));
+					hw->ver.major);
 			return -EINVAL;
 		}
 		return nfp_net_nfdk_tx_queue_setup(dev, queue_idx,