DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 8/8] net/nfp: revise the logic of MAC address
Date: Fri, 19 May 2023 10:59:50 +0800	[thread overview]
Message-ID: <20230519025950.1642943-9-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20230519025950.1642943-1-chaoyong.he@corigine.com>

Drop the usage of customed macro and function about MAC address,
using the macro and function from framework.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 .../net/nfp/flower/nfp_flower_representor.c    |  3 +--
 drivers/net/nfp/nfp_common.c                   | 11 -----------
 drivers/net/nfp/nfp_common.h                   |  4 +---
 drivers/net/nfp/nfp_ethdev.c                   | 17 +++++++----------
 drivers/net/nfp/nfp_ethdev_vf.c                | 18 ++++++++----------
 drivers/net/nfp/nfp_flow.c                     |  6 +++---
 drivers/net/nfp/nfpcore/nfp_nsp.h              |  4 +---
 drivers/net/nfp/nfpcore/nfp_nsp_eth.c          |  8 ++++----
 8 files changed, 25 insertions(+), 46 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 86b7d1a220..c3764b4de7 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -768,8 +768,7 @@ nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower)
 		flower_repr.vf_id = i + 1;
 
 		/* Copy the real mac of the interface to the representor struct */
-		rte_ether_addr_copy((struct rte_ether_addr *)eth_port->mac_addr,
-				&flower_repr.mac_addr);
+		rte_ether_addr_copy(&eth_port->mac_addr, &flower_repr.mac_addr);
 		sprintf(flower_repr.name, "flower_repr_p%d", i);
 
 		/*
diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index b7a7296999..c9fea765a4 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -453,17 +453,6 @@ nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
 	hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
 }
 
-#define ETH_ADDR_LEN	6
-
-void
-nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
-{
-	int i;
-
-	for (i = 0; i < ETH_ADDR_LEN; i++)
-		dst[i] = src[i];
-}
-
 void
 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
 {
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index 914903f587..47df0510c5 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -232,7 +232,7 @@ struct nfp_net_hw {
 #endif
 #endif
 
-	uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
+	struct rte_ether_addr mac_addr;
 
 	/* Records starting point for counters */
 	struct rte_eth_stats eth_stats_base;
@@ -428,7 +428,6 @@ 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_eth_copy_mac(uint8_t *dst, const uint8_t *src);
 void nfp_net_write_mac(struct nfp_net_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,
@@ -463,7 +462,6 @@ int nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
 int nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
 void nfp_net_params_setup(struct nfp_net_hw *hw);
 void nfp_net_cfg_queue_setup(struct nfp_net_hw *hw);
-void nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src);
 void nfp_net_dev_interrupt_handler(void *param);
 void nfp_net_dev_interrupt_delayed_handler(void *param);
 int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 06146050ff..722ec17dce 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -45,8 +45,7 @@ nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic, int port)
 
 	nfp_eth_table = nfp_eth_read_ports(app_fw_nic->pf_dev->cpp);
 
-	nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
-			 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
+	rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->mac_addr);
 
 	free(nfp_eth_table);
 	return 0;
@@ -654,19 +653,18 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 	}
 
 	nfp_net_pf_read_mac(app_fw_nic, port);
-	nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
+	nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
 
-	tmp_ether_addr = (struct rte_ether_addr *)&hw->mac_addr;
+	tmp_ether_addr = &hw->mac_addr;
 	if (!rte_is_valid_assigned_ether_addr(tmp_ether_addr)) {
 		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[0]);
-		nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
+		rte_eth_random_addr(&hw->mac_addr.addr_bytes[0]);
+		nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
 	}
 
 	/* Copying mac address to DPDK eth_dev struct */
-	rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
-			&eth_dev->data->mac_addrs[0]);
+	rte_ether_addr_copy(&hw->mac_addr, eth_dev->data->mac_addrs);
 
 	if ((hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR) == 0)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
@@ -677,8 +675,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,
-		     hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
-		     hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
+		     RTE_ETHER_ADDR_BYTES(&hw->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 bac8df6142..ce55e3b728 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -23,10 +23,10 @@ nfp_netvf_read_mac(struct nfp_net_hw *hw)
 	uint32_t tmp;
 
 	tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
-	memcpy(&hw->mac_addr[0], &tmp, 4);
+	memcpy(&hw->mac_addr.addr_bytes[0], &tmp, 4);
 
 	tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
-	memcpy(&hw->mac_addr[4], &tmp, 2);
+	memcpy(&hw->mac_addr.addr_bytes[4], &tmp, 2);
 }
 
 static int
@@ -406,18 +406,17 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
 
 	nfp_netvf_read_mac(hw);
 
-	tmp_ether_addr = (struct rte_ether_addr *)&hw->mac_addr;
+	tmp_ether_addr = &hw->mac_addr;
 	if (!rte_is_valid_assigned_ether_addr(tmp_ether_addr)) {
 		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[0]);
-		nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
+		rte_eth_random_addr(&hw->mac_addr.addr_bytes[0]);
+		nfp_net_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
 	}
 
 	/* Copying mac address to DPDK eth_dev struct */
-	rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
-			&eth_dev->data->mac_addrs[0]);
+	rte_ether_addr_copy(&hw->mac_addr, eth_dev->data->mac_addrs);
 
 	if ((hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR) == 0)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
@@ -425,11 +424,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
 	PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
-		     "mac=%02x:%02x:%02x:%02x:%02x:%02x",
+		     "mac=" RTE_ETHER_ADDR_PRT_FMT,
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id,
-		     hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
-		     hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
+		     RTE_ETHER_ADDR_BYTES(&hw->mac_addr));
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		/* Registering LSC interrupt handler */
diff --git a/drivers/net/nfp/nfp_flow.c b/drivers/net/nfp/nfp_flow.c
index b46acf6a39..cb7073f361 100644
--- a/drivers/net/nfp/nfp_flow.c
+++ b/drivers/net/nfp/nfp_flow.c
@@ -85,7 +85,7 @@ struct nfp_mask_id_entry {
 struct nfp_pre_tun_entry {
 	uint16_t mac_index;
 	uint16_t ref_cnt;
-	uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
+	struct rte_ether_addr mac_addr;
 } __rte_aligned(32);
 
 static inline struct nfp_flow_priv *
@@ -2894,7 +2894,7 @@ nfp_pre_tun_table_check_add(struct nfp_flower_representor *repr,
 	}
 
 	entry->ref_cnt = 1U;
-	memcpy(entry->mac_addr, repr->mac_addr.addr_bytes, RTE_ETHER_ADDR_LEN);
+	rte_ether_addr_copy(&repr->mac_addr, &entry->mac_addr);
 
 	/* 0 is considered a failed match */
 	for (i = 1; i < NFP_TUN_PRE_TUN_RULE_LIMIT; i++) {
@@ -2954,7 +2954,7 @@ nfp_pre_tun_table_check_del(struct nfp_flower_representor *repr,
 	}
 
 	entry->ref_cnt = 1U;
-	memcpy(entry->mac_addr, repr->mac_addr.addr_bytes, RTE_ETHER_ADDR_LEN);
+	rte_ether_addr_copy(&repr->mac_addr, &entry->mac_addr);
 
 	/* 0 is considered a failed match */
 	for (i = 1; i < NFP_TUN_PRE_TUN_RULE_LIMIT; i++) {
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h
index 50cdec3a58..9905b2d3d3 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.h
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.h
@@ -157,8 +157,6 @@ enum nfp_eth_fec {
 #define NFP_FEC_REED_SOLOMON	RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT)
 #define NFP_FEC_DISABLED	RTE_BIT32(NFP_FEC_DISABLED_BIT)
 
-#define ETH_ALEN	6
-
 /**
  * struct nfp_eth_table - ETH table information
  * @count:	number of table entries
@@ -205,7 +203,7 @@ struct nfp_eth_table {
 		enum nfp_eth_fec fec;
 		enum nfp_eth_aneg aneg;
 
-		uint8_t mac_addr[ETH_ALEN];
+		struct rte_ether_addr mac_addr;
 
 		uint8_t label_port;
 		uint8_t label_subport;
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
index f8d1416d4b..01b4652280 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
+++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
@@ -115,7 +115,7 @@ union eth_table_entry {
 	struct {
 		uint64_t port;
 		uint64_t state;
-		uint8_t mac_addr[6];
+		uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
 		uint8_t resv[2];
 		uint64_t control;
 	};
@@ -163,8 +163,8 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src)
 {
 	int i;
 
-	for (i = 0; i < (int)ETH_ALEN; i++)
-		dst[ETH_ALEN - i - 1] = src[i];
+	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
+		dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i];
 }
 
 static void
@@ -194,7 +194,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src,
 	dst->interface = FIELD_GET(NSP_ETH_STATE_INTERFACE, state);
 	dst->media = FIELD_GET(NSP_ETH_STATE_MEDIA, state);
 
-	nfp_eth_copy_mac_reverse(dst->mac_addr, src->mac_addr);
+	nfp_eth_copy_mac_reverse(&dst->mac_addr.addr_bytes[0], src->mac_addr);
 
 	dst->label_port = FIELD_GET(NSP_ETH_PORT_PHYLABEL, port);
 	dst->label_subport = FIELD_GET(NSP_ETH_PORT_LABEL, port);
-- 
2.39.1


  parent reply	other threads:[~2023-05-19  3:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19  2:59 [PATCH 0/8] make the logic conform the coding style of DPDK Chaoyong He
2023-05-19  2:59 ` [PATCH 1/8] net/nfp: reuse the ring buffer struct Chaoyong He
2023-05-19  2:59 ` [PATCH 2/8] net/nfp: modify the rxq struct Chaoyong He
2023-05-19  2:59 ` [PATCH 3/8] net/nfp: modify the Rx descriptor struct Chaoyong He
2023-05-19  2:59 ` [PATCH 4/8] net/nfp: modify the txq struct Chaoyong He
2023-05-19  2:59 ` [PATCH 5/8] net/nfp: remove the custom round macro Chaoyong He
2023-05-19  2:59 ` [PATCH 6/8] net/nfp: remove the unneeded comment Chaoyong He
2023-05-19  2:59 ` [PATCH 7/8] net/nfp: revise cast from void pointer Chaoyong He
2023-05-19  2:59 ` Chaoyong He [this message]
2023-05-19 13:55 ` [PATCH 0/8] make the logic conform the coding style of DPDK Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519025950.1642943-9-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=niklas.soderlund@corigine.com \
    --cc=oss-drivers@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).