[v3,11/25] net/nfp: extract the MAC address data field

Message ID 20231026064324.177531-12-chaoyong.he@corigine.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series add the NFP vDPA PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He Oct. 26, 2023, 6:43 a.m. UTC
  Extract the 'mac_addr' data filed into the super class, prepare for the
upcoming common library.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c     | 14 +++++++-------
 drivers/net/nfp/nfp_ethdev_vf.c  | 18 +++++++++---------
 drivers/net/nfp/nfp_net_common.c |  8 ++++----
 drivers/net/nfp/nfp_net_common.h |  5 ++---
 4 files changed, 22 insertions(+), 23 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 1378545d22..a93742a205 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -33,7 +33,7 @@  nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic,
 
 	nfp_eth_table = nfp_eth_read_ports(app_fw_nic->pf_dev->cpp);
 
-	rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->mac_addr);
+	rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->super.mac_addr);
 
 	free(nfp_eth_table);
 
@@ -599,18 +599,18 @@  nfp_net_init(struct rte_eth_dev *eth_dev)
 	}
 
 	nfp_net_pf_read_mac(app_fw_nic, port);
-	nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
+	nfp_net_write_mac(&hw->super, &hw->super.mac_addr.addr_bytes[0]);
 
-	tmp_ether_addr = &hw->mac_addr;
+	tmp_ether_addr = &hw->super.mac_addr;
 	if (rte_is_valid_assigned_ether_addr(tmp_ether_addr) == 0) {
 		PMD_INIT_LOG(INFO, "Using random mac address for port %d", port);
 		/* Using random mac addresses for VFs */
-		rte_eth_random_addr(&hw->mac_addr.addr_bytes[0]);
-		nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
+		rte_eth_random_addr(&hw->super.mac_addr.addr_bytes[0]);
+		nfp_net_write_mac(&hw->super, &hw->super.mac_addr.addr_bytes[0]);
 	}
 
 	/* Copying mac address to DPDK eth_dev struct */
-	rte_ether_addr_copy(&hw->mac_addr, eth_dev->data->mac_addrs);
+	rte_ether_addr_copy(&hw->super.mac_addr, eth_dev->data->mac_addrs);
 
 	if ((hw->super.cap & NFP_NET_CFG_CTRL_LIVE_ADDR) == 0)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
@@ -621,7 +621,7 @@  nfp_net_init(struct rte_eth_dev *eth_dev)
 			"mac=" RTE_ETHER_ADDR_PRT_FMT,
 			eth_dev->data->port_id, pci_dev->id.vendor_id,
 			pci_dev->id.device_id,
-			RTE_ETHER_ADDR_BYTES(&hw->mac_addr));
+			RTE_ETHER_ADDR_BYTES(&hw->super.mac_addr));
 
 	/* Registering LSC interrupt handler */
 	rte_intr_callback_register(pci_dev->intr_handle,
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 6ead7e02b8..dead6ca5ab 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -16,14 +16,14 @@ 
 #include "nfp_net_common.h"
 
 static void
-nfp_netvf_read_mac(struct nfp_net_hw *hw)
+nfp_netvf_read_mac(struct nfp_hw *hw)
 {
 	uint32_t tmp;
 
-	tmp = rte_be_to_cpu_32(nn_cfg_readl(&hw->super, NFP_NET_CFG_MACADDR));
+	tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
 	memcpy(&hw->mac_addr.addr_bytes[0], &tmp, 4);
 
-	tmp = rte_be_to_cpu_32(nn_cfg_readl(&hw->super, NFP_NET_CFG_MACADDR + 4));
+	tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
 	memcpy(&hw->mac_addr.addr_bytes[4], &tmp, 2);
 }
 
@@ -332,16 +332,16 @@  nfp_netvf_init(struct rte_eth_dev *eth_dev)
 		goto dev_err_ctrl_map;
 	}
 
-	nfp_netvf_read_mac(hw);
-	if (rte_is_valid_assigned_ether_addr(&hw->mac_addr) == 0) {
+	nfp_netvf_read_mac(&hw->super);
+	if (rte_is_valid_assigned_ether_addr(&hw->super.mac_addr) == 0) {
 		PMD_INIT_LOG(INFO, "Using random mac address for port %hu", port);
 		/* Using random mac addresses for VFs */
-		rte_eth_random_addr(&hw->mac_addr.addr_bytes[0]);
-		nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
+		rte_eth_random_addr(&hw->super.mac_addr.addr_bytes[0]);
+		nfp_net_write_mac(&hw->super, &hw->super.mac_addr.addr_bytes[0]);
 	}
 
 	/* Copying mac address to DPDK eth_dev struct */
-	rte_ether_addr_copy(&hw->mac_addr, eth_dev->data->mac_addrs);
+	rte_ether_addr_copy(&hw->super.mac_addr, eth_dev->data->mac_addrs);
 
 	if ((hw->super.cap & NFP_NET_CFG_CTRL_LIVE_ADDR) == 0)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
@@ -352,7 +352,7 @@  nfp_netvf_init(struct rte_eth_dev *eth_dev)
 			"mac=" RTE_ETHER_ADDR_PRT_FMT,
 			port, pci_dev->id.vendor_id,
 			pci_dev->id.device_id,
-			RTE_ETHER_ADDR_BYTES(&hw->mac_addr));
+			RTE_ETHER_ADDR_BYTES(&hw->super.mac_addr));
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		/* Registering LSC interrupt handler */
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 9e6d2fa490..a760fcf0d2 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -532,19 +532,19 @@  nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 }
 
 void
-nfp_net_write_mac(struct nfp_net_hw *hw,
+nfp_net_write_mac(struct nfp_hw *hw,
 		uint8_t *mac)
 {
 	uint32_t mac0;
 	uint16_t mac1;
 
 	mac0 = *(uint32_t *)mac;
-	nn_writel(rte_cpu_to_be_32(mac0), hw->super.ctrl_bar + NFP_NET_CFG_MACADDR);
+	nn_writel(rte_cpu_to_be_32(mac0), hw->ctrl_bar + NFP_NET_CFG_MACADDR);
 
 	mac += 4;
 	mac1 = *(uint16_t *)mac;
 	nn_writew(rte_cpu_to_be_16(mac1),
-			hw->super.ctrl_bar + NFP_NET_CFG_MACADDR + 6);
+			hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6);
 }
 
 int
@@ -565,7 +565,7 @@  nfp_net_set_mac_addr(struct rte_eth_dev *dev,
 	}
 
 	/* Writing new MAC to the specific port BAR address */
-	nfp_net_write_mac(net_hw, (uint8_t *)mac_addr);
+	nfp_net_write_mac(hw, (uint8_t *)mac_addr);
 
 	update = NFP_NET_CFG_UPDATE_MACADDR;
 	ctrl = hw->ctrl;
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index d418cd2b99..e997756091 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -120,6 +120,7 @@  struct nfp_hw {
 	uint32_t ctrl;
 	uint32_t ctrl_ext;
 	rte_spinlock_t reconfig_lock;
+	struct rte_ether_addr mac_addr;
 };
 
 struct nfp_net_hw {
@@ -159,8 +160,6 @@  struct nfp_net_hw {
 	uint16_t subsystem_device_id;
 	uint16_t subsystem_vendor_id;
 
-	struct rte_ether_addr mac_addr;
-
 	/** Records starting point for counters */
 	struct rte_eth_stats eth_stats_base;
 	struct rte_eth_xstat *eth_xstats_base;
@@ -376,7 +375,7 @@  void nfp_net_log_device_information(const struct nfp_net_hw *hw);
 void nfp_net_enable_queues(struct rte_eth_dev *dev);
 void nfp_net_disable_queues(struct rte_eth_dev *dev);
 void nfp_net_params_setup(struct nfp_net_hw *hw);
-void nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac);
+void nfp_net_write_mac(struct nfp_hw *hw, uint8_t *mac);
 int nfp_net_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
 int nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
 		struct rte_intr_handle *intr_handle);