From: Hemant Agrawal <hemant.agrawal@nxp.com>
To: dev@dpdk.org, stephen@networkplumber.org, david.marchand@redhat.com
Subject: [PATCH 10/11] net/enetfec: support to set MAC address
Date: Mon, 6 Oct 2025 13:34:09 +0530 [thread overview]
Message-ID: <20251006080410.1433284-11-hemant.agrawal@nxp.com> (raw)
In-Reply-To: <20251006080410.1433284-1-hemant.agrawal@nxp.com>
This patch adds the support of mac_addr_set.
Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
drivers/net/enetfec/enet_ethdev.c | 76 ++++++++++++++++---------------
drivers/net/enetfec/enet_ethdev.h | 30 ++++++++++++
2 files changed, 69 insertions(+), 37 deletions(-)
diff --git a/drivers/net/enetfec/enet_ethdev.c b/drivers/net/enetfec/enet_ethdev.c
index 6d4d3e0fc2..959d5d4a6e 100644
--- a/drivers/net/enetfec/enet_ethdev.c
+++ b/drivers/net/enetfec/enet_ethdev.c
@@ -14,30 +14,6 @@
#include "enet_regs.h"
#include "enet_uio.h"
-#define ENETFEC_NAME_PMD net_enetfec
-
-/* FEC receive acceleration */
-#define ENETFEC_RACC_IPDIS RTE_BIT32(1)
-#define ENETFEC_RACC_PRODIS RTE_BIT32(2)
-#define ENETFEC_RACC_SHIFT16 RTE_BIT32(7)
-#define ENETFEC_RACC_OPTIONS (ENETFEC_RACC_IPDIS | \
- ENETFEC_RACC_PRODIS)
-
-#define ENETFEC_PAUSE_FLAG_AUTONEG 0x1
-#define ENETFEC_PAUSE_FLAG_ENABLE 0x2
-
-/* Pause frame field and FIFO threshold */
-#define ENETFEC_FCE RTE_BIT32(5)
-#define ENETFEC_RSEM_V 0x84
-#define ENETFEC_RSFL_V 16
-#define ENETFEC_RAEM_V 0x8
-#define ENETFEC_RAFL_V 0x8
-#define ENETFEC_OPD_V 0xFFF0
-
-/* Extended buffer descriptor */
-#define ENETFEC_EXTENDED_BD 0
-#define NUM_OF_BD_QUEUES 6
-
/* Supported Rx offloads */
static uint64_t dev_rx_offloads_sup =
RTE_ETH_RX_OFFLOAD_CHECKSUM |
@@ -298,8 +274,7 @@ enetfec_multicast_enable(struct rte_eth_dev *dev)
/* Set a MAC change in hardware. */
static int
-enetfec_set_mac_address(struct rte_eth_dev *dev,
- struct rte_ether_addr *addr)
+enetfec_set_mac_address(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
{
struct enetfec_private *fep = dev->data->dev_private;
@@ -588,15 +563,15 @@ enetfec_eth_init(struct rte_eth_dev *dev)
static int
pmd_enetfec_probe(struct rte_vdev_device *vdev)
{
+ char eth_name[ENETFEC_ETH_NAMESIZE];
struct rte_eth_dev *dev = NULL;
struct enetfec_private *fep;
- const char *name;
- int rc;
- int i;
+ uint16_t *mac, high_mac = 0;
+ struct rte_ether_addr addr;
+ uint32_t tmac, low_mac = 0;
unsigned int bdsize;
- struct rte_ether_addr macaddr = {
- .addr_bytes = { 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }
- };
+ const char *name;
+ int rc, i;
name = rte_vdev_device_name(vdev);
ENETFEC_PMD_LOG(INFO, "Initializing pmd_fec for %s", name);
@@ -637,8 +612,12 @@ pmd_enetfec_probe(struct rte_vdev_device *vdev)
fep->bd_addr_p = fep->bd_addr_p + bdsize;
}
+ /* Allocate memory for storing MAC addresses */
+ snprintf(eth_name, sizeof(eth_name), "enetfec_eth_mac_%d",
+ dev->data->port_id);
+
/* Copy the station address into the dev structure, */
- dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
+ dev->data->mac_addrs = rte_zmalloc(eth_name, RTE_ETHER_ADDR_LEN, 0);
if (dev->data->mac_addrs == NULL) {
ENETFEC_PMD_ERR("Failed to allocate mem %d to store MAC addresses",
RTE_ETHER_ADDR_LEN);
@@ -646,10 +625,33 @@ pmd_enetfec_probe(struct rte_vdev_device *vdev)
goto err;
}
- /*
- * Set default mac address
- */
- enetfec_set_mac_address(dev, &macaddr);
+ /* Set mac address */
+ mac = (uint16_t *)addr.addr_bytes;
+ low_mac = (uint32_t)rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_PALR);
+ *mac = (uint16_t)low_mac;
+ mac++;
+ *mac = (uint16_t)(low_mac >> ENETFEC_MAC_SHIFT);
+ mac++;
+ tmac = (uint32_t)rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_PAUR);
+ *mac = (uint16_t)(tmac >> ENETFEC_MAC_SHIFT);
+ high_mac = (uint16_t)(*mac);
+
+ if ((high_mac | low_mac) == 0 || (high_mac | low_mac) == ENETFEC_MAC_RESET) {
+ uint8_t *first_byte;
+
+ mac = (uint16_t *)addr.addr_bytes;
+ tmac = (uint32_t)rte_rand();
+ first_byte = (uint8_t *)&tmac;
+ *first_byte &= (uint8_t)~RTE_ETHER_GROUP_ADDR; /* clear multicast bit */
+ *first_byte |= RTE_ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit (IEEE802) */
+ *mac = (uint16_t)tmac;
+ mac++;
+ *mac = (uint16_t)(tmac >> ENETFEC_MAC_SHIFT);
+ mac++;
+ *mac = (uint16_t)rte_rand();
+ }
+
+ enetfec_set_mac_address(dev, &addr);
fep->bufdesc_ex = ENETFEC_EXTENDED_BD;
rc = enetfec_eth_init(dev);
diff --git a/drivers/net/enetfec/enet_ethdev.h b/drivers/net/enetfec/enet_ethdev.h
index ee5c244c91..4c063d1799 100644
--- a/drivers/net/enetfec/enet_ethdev.h
+++ b/drivers/net/enetfec/enet_ethdev.h
@@ -20,6 +20,36 @@
#define OPT_FRAME_SIZE (PKT_MAX_BUF_SIZE << 16)
#define ENETFEC_MAX_RX_PKT_LEN 3000
+#define ENETFEC_NAME_PMD net_enetfec
+
+/* eth name size */
+#define ENETFEC_ETH_NAMESIZE 20
+#define ENETFEC_MAC_SHIFT 16
+/* mac addr reset */
+#define ENETFEC_MAC_RESET 0xFFFFFFFF
+
+/* FEC receive acceleration */
+#define ENETFEC_RACC_IPDIS RTE_BIT32(1)
+#define ENETFEC_RACC_PRODIS RTE_BIT32(2)
+#define ENETFEC_RACC_SHIFT16 RTE_BIT32(7)
+#define ENETFEC_RACC_OPTIONS (ENETFEC_RACC_IPDIS | \
+ ENETFEC_RACC_PRODIS)
+
+#define ENETFEC_PAUSE_FLAG_AUTONEG 0x1
+#define ENETFEC_PAUSE_FLAG_ENABLE 0x2
+
+/* Pause frame field and FIFO threshold */
+#define ENETFEC_FCE RTE_BIT32(5)
+#define ENETFEC_RSEM_V 0x84
+#define ENETFEC_RSFL_V 16
+#define ENETFEC_RAEM_V 0x8
+#define ENETFEC_RAFL_V 0x8
+#define ENETFEC_OPD_V 0xFFF0
+
+/* Extended buffer descriptor */
+#define ENETFEC_EXTENDED_BD 0
+#define NUM_OF_BD_QUEUES 6
+
#define __iomem
#if defined(RTE_ARCH_ARM)
#if defined(RTE_ARCH_64)
--
2.25.1
next prev parent reply other threads:[~2025-10-06 8:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 8:03 [PATCH 00/11] net/enetc: various fixes and enhancements Hemant Agrawal
2025-10-06 8:04 ` [PATCH 01/11] net/enetfec: fix file descriptor leak on read error Hemant Agrawal
2025-10-06 8:04 ` [PATCH 02/11] net/enetfec: fix out-of-bounds access in UIO mapping Hemant Agrawal
2025-10-06 8:04 ` [PATCH 03/11] net/enetfec: fix buffer descriptor size configuration Hemant Agrawal
2025-10-06 8:04 ` [PATCH 04/11] net/enetfec: fix incorrect Tx queue free logic Hemant Agrawal
2025-10-06 8:04 ` [PATCH 05/11] net/enetfec: fix checksum flag handling and error return Hemant Agrawal
2025-10-06 8:04 ` [PATCH 06/11] net/enetfec: fix to reject multi-queue configuration Hemant Agrawal
2025-10-06 8:04 ` [PATCH 07/11] net/enetfec: fix memory leak in Rx buffer cleanup Hemant Agrawal
2025-10-06 8:04 ` [PATCH 08/11] net/enetfec: fix to add check for Rx/Tx deferred queue Hemant Agrawal
2025-10-06 8:04 ` [PATCH 09/11] net/enetfec: handle cache for forwarded packets Hemant Agrawal
2025-10-06 8:04 ` Hemant Agrawal [this message]
2025-10-06 8:04 ` [PATCH 11/11] net/enetfec: add software packet type parsing and cleanup Hemant Agrawal
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=20251006080410.1433284-11-hemant.agrawal@nxp.com \
--to=hemant.agrawal@nxp.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/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).