net: enetc: Prepare for ENETC v4 VF support
Wei Fang
maintainerv2 cover net: enetc: Prepare for ENETC v4 VF support
This patch series refactors and extends the ENETC driver infrastructure to prepare for upcoming ENETC v4 Virtual Function (VF) support. The main focus is on code commonization, improved VF-PF communication, and dynamic resource allocation.
The ENETC IP has evolved across different revisions, and the existing driver architecture was primarily designed around v1 hardware. To support v4 VFs efficiently, we need to share common code between PF drivers of different IP versions while maintaining compatibility.
Key changes in this series:
1. VF-PF Messaging Infrastructure:
- Convert mailbox messages to new formats
- Use read_poll_timeout() for simplifying VF mailbox polling
- Add support for IP minor revision query via messaging
2. Code Commonization:
- Relocate SR-IOV configuration helpers to common PF code
- Move VF message handlers to dedicated enetc_msg.c
- Integrate enetc_msg.c into enetc-pf-common driver
3. CBDR (Control Buffer Descriptor Ring) Improvements:
- Align v1 CBDR API with v4 for VF driver sharing
- Add CBDR setup/teardown hooks to enetc_si_ops
4. Dynamic Resource Management:
- Dynamically allocate rxmsg based on actual VF count
- Use MADDR_TYPE constant for MAC filter array sizing
5. Generic SR-IOV Initialization:
- Add generic helper to initialize SR-IOV resources
This refactoring lays the groundwork for cleanly integrating ENETC v4 VF support in subsequent patch series, allowing code reuse between v1 and v4 PF drivers while maintaining a clean separation of version-specific logic.
---
v2:
1. Drop patch 3, 14 and 15 in v1.
2. Use enetc_set_si_hw_addr() instead of pf->ops->set_si_primary_mac() in patch 1, update title and commit message
3. Refine the implementation of patch 6, such as remove bitfields from the message structure (struct enetc_msg_header), remove union enetc_pf_msg, change the prototypes of some functions, add a generic error code (ENETC_MSG_CLASS_ID_CMD_FAIL) for PF message, and update the commit message
4. Remove class_code from struct enetc_msg_swbd. enetc_msg_vsi_send() directly returns the message code for 'get' messages, as the message code is >= 0
5. Update commit messages of some other patches
v1 link: https://lore.kernel.org/imx/[email protected]/
---
Wei Fang (12):
net: enetc: use enetc_set_si_hw_addr() for setting MAC address
net: enetc: move VF message handlers to enetc_msg.c
net: enetc: relocate SR-IOV configuration helper for common PF support
net: enetc: integrate enetc_msg.c into enetc-pf-common driver
net: enetc: use read_poll_timeout() for VF mailbox polling
net: enetc: convert mailbox messages to new formats
net: enetc: add VF-PF messaging support for IP minor revision query
net: enetc: align v1 CBDR API with v4 for VF driver sharing
net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF
support
net: enetc: add generic helper to initialize SR-IOV resources
net: enetc: use MADDR_TYPE for MAC filter array size
net: enetc: dynamically allocate rxmsg based on VF count
drivers/net/ethernet/freescale/enetc/Kconfig | 2 + drivers/net/ethernet/freescale/enetc/Makefile | 2 +- drivers/net/ethernet/freescale/enetc/enetc.h | 22 +- .../net/ethernet/freescale/enetc/enetc4_pf.c | 4 - .../net/ethernet/freescale/enetc/enetc_cbdr.c | 16 +- .../net/ethernet/freescale/enetc/enetc_hw.h | 1 - .../ethernet/freescale/enetc/enetc_mailbox.h | 170 ++++++++++++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 209 +++++++++++++++++- .../net/ethernet/freescale/enetc/enetc_pf.c | 142 +----------- .../net/ethernet/freescale/enetc/enetc_pf.h | 10 +- .../freescale/enetc/enetc_pf_common.c | 31 ++- .../freescale/enetc/enetc_pf_common.h | 11 + .../net/ethernet/freescale/enetc/enetc_vf.c | 175 +++++++++++---- 13 files changed, 581 insertions(+), 214 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_mailbox.h
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 1/12 net: enetc: use enetc_set_si_hw_addr() for setting MAC address
Replace enetc_pf_set_primary_mac_addr() with the generic enetc_set_si_hw_addr() function. This prepares for moving enetc_msg_pf_set_vf_primary_mac_addr() to the enetc-pf-common driver, where it can be shared between ENETC v1 and v4 PF drivers.
--- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 2 +- drivers/net/ethernet/freescale/enetc/enetc_pf_common.c | 4 ++-- drivers/net/ethernet/freescale/enetc/enetc_pf_common.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -1
@@ -509,7 +509,7 @@ static u16 enetc_msg_pf_set_vf_primary_mac_addr(struct enetc_pf *pf,return ENETC_MSG_CMD_STATUS_FAIL ; } -enetc_pf_set_primary_mac_addr (&pf->si->hw, vf_id +1 , addr); +enetc_set_si_hw_addr (pf, vf_id +1 , addr);mutex_unlock (&vf_state->lock);return ENETC_MSG_CMD_STATUS_OK ;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2 -2
@@ -7,13 +7,13 @@#include "enetc_pf_common.h" -static void enetc_set_si_hw_addr (struct enetc_pf *pf,int si, -const u8 *mac_addr) +void enetc_set_si_hw_addr (struct enetc_pf *pf,int si,const u8 *mac_addr) {struct enetc_hw *hw = &pf->si->hw; pf->ops->set_si_primary_mac (hw, si, mac_addr); } +EXPORT_SYMBOL_GPL (enetc_set_si_hw_addr);static void enetc_get_si_hw_addr (struct enetc_pf *pf,int si,u8 *mac_addr) {
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +1 -0
@@ -3,6 +3,7 @@#include "enetc_pf.h" +void enetc_set_si_hw_addr (struct enetc_pf *pf,int si,const u8 *mac_addr);int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr);int enetc_setup_mac_addresses (struct device_node *np,struct enetc_pf *pf); void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 net-next 01/12] net: enetc: use enetc_set_si_hw_addr() for setting MAC address
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Hardware registers for MAC address configuration are accessed using __raw_readl and __raw_writel without endianness conversions, causing incorrect MAC addresses on Big Endian systems. --
commit 9950ab386f64a0d2f5b71b2003e9ca960d52dddd
Author: Wei Fang <[email protected]>
net: enetc: use enetc_set_si_hw_addr() for setting MAC address
This commit replaces enetc_pf_set_primary_mac_addr() with the generic enetc_set_si_hw_addr() function to prepare for moving MAC address setting logic to the common driver for reuse.
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0
[ ... ]
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c line 14
Quoted 11 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-2@@ -7,13 +7,13 @@#include "enetc_pf_common.h" -static void enetc_set_si_hw_addr (struct enetc_pf *pf,int si, -const u8 *mac_addr) +void enetc_set_si_hw_addr (struct enetc_pf *pf,int si,const u8 *mac_addr) {struct enetc_hw *hw = &pf->si->hw; pf->ops->set_si_primary_mac (hw, si, mac_addr);
[Severity: High]
This is a pre-existing issue, but does the underlying MAC address configuration code have an endianness bug on Big Endian systems?
Hardware registers for MAC address configuration are accessed using __raw_readl() and __raw_writel() without endianness conversions.
The code uses get_unaligned_le32() to read the first 4 bytes of the MAC address into a host-endian u32. For a MAC address starting with 12:34:56:78, on a Big Endian CPU this creates the u32 value 0x78563412.
It then uses __raw_writel() to write this u32 to the PCIe memory-mapped register. __raw_writel() performs a raw host-endian memory store without any byte swapping. On a Big Endian CPU, 0x78563412 is stored in memory as the byte sequence 0x78, 0x56, 0x34, 0x12.
Since the PCIe controller interprets the MMIO space as Little Endian, it reads those bytes back as 0x12345678, completely reversing the MAC address bytes. Could this break network configuration and communication on Big Endian systems?
The rest of the driver correctly uses iowrite32() and ioread32() (via enetc_wr() and enetc_rd()), which handle the host-to-LE conversion properly.
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-0} +EXPORT_SYMBOL_GPL (enetc_set_si_hw_addr);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Wei Fang
maintainerPATCH v2 2/12 net: enetc: move VF message handlers to enetc_msg.c
In reply to Wei FangMove enetc_msg_pf_set_vf_primary_mac_addr() and enetc_msg_handle_rxmsg() to enetc_msg.c to consolidate VF mailbox message handling logic.
Make enetc_msg_handle_rxmsg() static since it's only called from enetc_msg_task() within the same file.
This prepares for integrating enetc_msg.c into the enetc-pf-common driver to be shared between ENETC v1 and v4 PF drivers.
--- .../net/ethernet/freescale/enetc/enetc_msg.c | 78 ++++++++++++++++++- .../net/ethernet/freescale/enetc/enetc_pf.c | 75 ------------------ .../net/ethernet/freescale/enetc/enetc_pf.h | 1 - 3 files changed, 77 insertions(+), 77 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_msg.c +77 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) /* Copyright 2017-2019 NXP */ -#include "enetc_pf.h" +#include "enetc_pf_common.h" static void enetc_msg_disable_mr_int (struct enetc_pf *pf) {
@@ -35,6 +35,82 @@ static irqreturn_t enetc_msg_psi_msix(int irq, void *data)return IRQ_HANDLED ; } +/* Messaging */ +static u16 enetc_msg_pf_set_vf_primary_mac_addr (struct enetc_pf *pf, +int vf_id,void *msg) +{ +struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; +struct enetc_msg_cmd_set_primary_mac *cmd = msg; +struct device *dev = &pf->si->pdev->dev; +u16 cmd_id = cmd->header.id; +char *addr; + +if (cmd_id !=ENETC_MSG_CMD_MNG_ADD ) +return ENETC_MSG_CMD_STATUS_FAIL ; + + addr = cmd->mac.sa_data; +if (!is_valid_ether_addr (addr)) { +dev_err_ratelimited (dev,"VF%d attempted to set invalid MAC\n" , + vf_id); +return ENETC_MSG_CMD_STATUS_FAIL ; + } + +mutex_lock (&vf_state->lock); +if (vf_state->flags &ENETC_VF_FLAG_PF_SET_MAC ) { +mutex_unlock (&vf_state->lock); +dev_err_ratelimited (dev, +"VF%d attempted to override PF set MAC\n" , + vf_id); +return ENETC_MSG_CMD_STATUS_FAIL ; + } + +enetc_set_si_hw_addr (pf, vf_id +1 , addr); +mutex_unlock (&vf_state->lock); + +return ENETC_MSG_CMD_STATUS_OK ; +} + +static void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int vf_id, +u16 *status) +{ +struct enetc_msg_swbd *msg_swbd = &pf->rxmsg[vf_id]; +struct device *dev = &pf->si->pdev->dev; +struct enetc_msg_cmd_header *cmd_hdr; +u16 cmd_type; +u8 *msg; + + msg =kzalloc_objs (*msg, msg_swbd->size); +if (!msg) { +dev_err_ratelimited (dev, +"Failed to allocate message buffer\n" ); + *status =ENETC_MSG_CMD_STATUS_FAIL ; +return ; + } + +/* Currently, only ENETC_MSG_CMD_MNG_MAC command is supported, so +* only sizeof(struct enetc_msg_cmd_set_primary_mac) bytes need to +* be copied. This data already includes the cmd_type field, so it +* can correctly return an error code. +*/ +memcpy (msg, msg_swbd->vaddr, +sizeof (struct enetc_msg_cmd_set_primary_mac )); + cmd_hdr = (struct enetc_msg_cmd_header *)msg; + cmd_type = cmd_hdr->type; + +switch (cmd_type) { +case ENETC_MSG_CMD_MNG_MAC : + *status =enetc_msg_pf_set_vf_primary_mac_addr (pf, vf_id, msg); +break ; +default : + *status =ENETC_MSG_CMD_STATUS_FAIL ; +dev_err_ratelimited (dev, +"command not supported (cmd_type: 0x%x)\n" , + cmd_type); + } + +kfree (msg); +} +static void enetc_msg_task (struct work_struct *work) { struct enetc_pf *pf = container_of(work, struct enetc_pf, msg_task);
drivers/net/ethernet/freescale/enetc/enetc_pf.c +0 -75
81 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -1
@@ -71,4 +71,3 @@ struct enetc_pf {int enetc_msg_psi_init (struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf); -void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int mbox_id,u16 *status);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 3/12 net: enetc: relocate SR-IOV configuration helper for common PF support
In reply to Wei FangMove enetc_sriov_configure() from enetc_pf.c to enetc_msg.c to prepare for integrating enetc_msg.c into the enetc-pf-common driver, where it will be shared between ENETC v1 and v4 PF drivers.
Since enetc_msg_psi_init() and enetc_msg_psi_free() are now only called from enetc_sriov_configure() within the same file, make them static.
--- .../net/ethernet/freescale/enetc/enetc_msg.c | 40 ++++++++++++++++++- .../net/ethernet/freescale/enetc/enetc_pf.c | 40 ------------------- .../net/ethernet/freescale/enetc/enetc_pf.h | 3 -- .../freescale/enetc/enetc_pf_common.h | 9 +++++ 4 files changed, 47 insertions(+), 45 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_msg.c +38 -2
@@ -189,7 +189,7 @@ static void enetc_msg_free_mbx(struct enetc_si *si, int idx)memset (msg,0 ,sizeof (*msg)); } -int enetc_msg_psi_init (struct enetc_pf *pf) +static int enetc_msg_psi_init (struct enetc_pf *pf) {struct enetc_si *si = pf->si;int vector, i, err;
@@ -229,7 +229,7 @@ int enetc_msg_psi_init(struct enetc_pf *pf)return err; } -void enetc_msg_psi_free (struct enetc_pf *pf) +static void enetc_msg_psi_free (struct enetc_pf *pf) {struct enetc_si *si = pf->si;int i;
@@ -248,3 +248,39 @@ void enetc_msg_psi_free(struct enetc_pf *pf)for (i =0 ; i < pf->num_vfs; i++)enetc_msg_free_mbx (si, i); } + +int enetc_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +struct enetc_si *si =pci_get_drvdata (pdev); +struct enetc_pf *pf =enetc_si_priv (si); +int err; + +if (!num_vfs) { +pci_disable_sriov (pdev); +enetc_msg_psi_free (pf); + pf->num_vfs =0 ; + }else { + pf->num_vfs = num_vfs; + + err =enetc_msg_psi_init (pf); +if (err) { +dev_err (&pdev->dev,"enetc_msg_psi_init (%d)\n" , err); + goto err_msg_psi; + } + + err =pci_enable_sriov (pdev, num_vfs); +if (err) { +dev_err (&pdev->dev,"pci_enable_sriov err %d\n" , err); + goto err_en_sriov; + } + } + +return num_vfs; + +err_en_sriov: +enetc_msg_psi_free (pf); +err_msg_psi: + pf->num_vfs =0 ; + +return err; +}
drivers/net/ethernet/freescale/enetc/enetc_pf.c +0 -40
@@ -480,46 +480,6 @@ static void enetc_configure_port(struct enetc_pf *pf)enetc_port_wr (hw,ENETC_PMR ,ENETC_PMR_EN ); } -#ifdef CONFIG_PCI_IOV -static int enetc_sriov_configure (struct pci_dev *pdev,int num_vfs) -{ -struct enetc_si *si =pci_get_drvdata (pdev); -struct enetc_pf *pf =enetc_si_priv (si); -int err; - -if (!num_vfs) { -pci_disable_sriov (pdev); -enetc_msg_psi_free (pf); - pf->num_vfs =0 ; - }else { - pf->num_vfs = num_vfs; - - err =enetc_msg_psi_init (pf); -if (err) { -dev_err (&pdev->dev,"enetc_msg_psi_init (%d)\n" , err); - goto err_msg_psi; - } - - err =pci_enable_sriov (pdev, num_vfs); -if (err) { -dev_err (&pdev->dev,"pci_enable_sriov err %d\n" , err); - goto err_en_sriov; - } - } - -return num_vfs; - -err_en_sriov: -enetc_msg_psi_free (pf); -err_msg_psi: - pf->num_vfs =0 ; - -return err; -} -#else -#define enetc_sriov_configure (pdev, num_vfs) (void)0 -#endif -static int enetc_pf_set_features (struct net_device *ndev,netdev_features_t features) {
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -3
@@ -68,6 +68,3 @@ struct enetc_pf {#define phylink_to_enetc_pf (config) \ container_of((config), struct enetc_pf, phylink_config) - -int enetc_msg_psi_init (struct enetc_pf *pf); -void enetc_msg_psi_free (struct enetc_pf *pf);
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +9 -0
@@ -21,3 +21,12 @@ static inline u16 enetc_get_ip_revision(struct enetc_hw *hw) {return enetc_global_rd (hw,ENETC_G_EIPBRR0 ) &EIPBRR0_REVISION ; } + +#if IS_ENABLED (CONFIG_PCI_IOV ) +int enetc_sriov_configure (struct pci_dev *pdev,int num_vfs); +#else +static inline int enetc_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +return 0 ; +} +#endif
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 4/12 net: enetc: integrate enetc_msg.c into enetc-pf-common driver
In reply to Wei FangMove enetc_msg.c from the fsl-enetc driver to the nxp-enetc-pf-common driver so that SR-IOV mailbox handling can be shared between ENETC v1 and v4 PF drivers.
Changes:
- Move enetc_msg.o compilation from fsl-enetc to nxp-enetc-pf-common
- Export enetc_sriov_configure() with EXPORT_SYMBOL_GPL for use by both PF drivers
The fsl-enetc driver now depends on nxp-enetc-pf-common for SR-IOV functionality.
--- drivers/net/ethernet/freescale/enetc/Makefile | 2 +- drivers/net/ethernet/freescale/enetc/enetc_msg.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/Makefile +1 -1
@@ -5,13 +5,13 @@ fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o nxp-enetc-pf-common-y := enetc_pf_common.o +nxp-enetc-pf-common-$(CONFIG_PCI_IOV) += enetc_msg.o obj-$(CONFIG_NXP_NETC_LIB) += nxp-netc-lib.o nxp-netc-lib-y := ntmp.o obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o fsl-enetc-y := enetc_pf.o -fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o obj-$(CONFIG_NXP_ENETC4) += nxp-enetc4.o
drivers/net/ethernet/freescale/enetc/enetc_msg.c +1 -0
@@ -284,3 +284,4 @@ int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs)return err; } +EXPORT_SYMBOL_GPL (enetc_sriov_configure);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 5/12 net: enetc: use read_poll_timeout() for VF mailbox polling
In reply to Wei FangReplace the manual do-while polling loop in enetc_msg_vsi_send() with the standard read_poll_timeout() helper to simplify the code.
--- .../net/ethernet/freescale/enetc/enetc_vf.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_vf.c +7 -12
@@ -1,6 +1,7 @@// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) /* Copyright 2017-2019 NXP */ +#include <linux/iopoll.h> #include <linux/module.h> #include "enetc.h"
@@ -28,8 +29,8 @@ static void enetc_msg_dma_free(struct device *dev, struct enetc_msg_swbd *msg)static int enetc_msg_vsi_send (struct enetc_si *si,struct enetc_msg_swbd *msg) {struct device *dev = &si->pdev->dev; -int timeout =100 ;u32 vsimsgsr; +int err;/* The VSI mailbox may be busy if last message was not yet processed * by PSI. So need to check the mailbox status before sending.
@@ -48,19 +49,13 @@ static int enetc_msg_vsi_send(struct enetc_si *si, struct enetc_msg_swbd *msg)enetc_msg_dma_free (dev, &si->msg); si->msg = *msg;enetc_msg_vsi_write_msg (&si->hw, msg); - -do { - vsimsgsr =enetc_rd (&si->hw,ENETC_VSIMSGSR ); -if (!(vsimsgsr &ENETC_VSIMSGSR_MB )) -break ; - -usleep_range (1000 ,2000 ); - }while (--timeout); - -if (!timeout) { + err =read_poll_timeout (enetc_rd, vsimsgsr, + !(vsimsgsr &ENETC_VSIMSGSR_MB ), +1000 ,200000 , false, &si->hw,ENETC_VSIMSGSR ); +if (err) {dev_err (dev,"VSI mailbox timeout\n" ); -return -ETIMEDOUT ; +return err; }/* check for message delivery error */
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 6/12 net: enetc: convert mailbox messages to new formats
In reply to Wei FangOn the LS1028A platform, the PF-VF mailbox was only used to update the VF's MAC address. The original message format is minimal, lacks a clear structure, and provides no means for the receiver to validate message integrity, making it difficult to extend for new features.
With the introduction of i.MX ENETC v4, the interaction between PF and VF has become significantly more complex. Typical deployments now include scenarios where the PF is controlled by an M core while the VF is driven by either the Linux kernel or DPDK, or where the PF is controlled by the Linux kernel while the VF is controlled by DPDK. These heterogeneous driver combinations require a unified and extensible message format to ensure compatibility across different operating environments.
This patch introduces a newly defined PF-VF message structure and converts the existing MAC-update mechanism to use the new format. The redesigned message layout provides:
- extensibility to support future PF-VF features on ENETC v4,
- consistent framing for all message types,
- improved data integrity checking,
- a common protocol usable across Linux, M core firmware, and DPDK.
Additional PF-VF message types will be added in subsequent patches.
Note that switch to the new message format will not affect ENETC v1 (LS1028A). Due to a hardware limitation of ENETC v1, the ENETC PF and VFs can only be controlled by the same OS. If the PF is controlled by the Linux kernel driver, then the VFs must also be controlled by the Linux kernel driver.
--- drivers/net/ethernet/freescale/enetc/Kconfig | 2 + drivers/net/ethernet/freescale/enetc/enetc.h | 15 +- .../net/ethernet/freescale/enetc/enetc4_pf.c | 4 - .../ethernet/freescale/enetc/enetc_mailbox.h | 151 ++++++++++++++++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 127 +++++++++++---- .../net/ethernet/freescale/enetc/enetc_vf.c | 97 ++++++++--- 6 files changed, 326 insertions(+), 70 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_mailbox.h
drivers/net/ethernet/freescale/enetc/Kconfig +2 -0
@@ -10,6 +10,7 @@ config FSL_ENETC_CORE config NXP_ENETC_PF_COMMON tristate + select CRC_ITU_T help This module supports common functionality between drivers of different versions of NXP ENETC PF controllers.
@@ -70,6 +71,7 @@ config FSL_ENETC_VF select FSL_ENETC_MDIO select PHYLINK select DIMLIB + select CRC_ITU_T help This driver supports NXP ENETC gigabit ethernet controller PCIe virtual function (VF) devices enabled by the ENETC PF driver.
drivers/net/ethernet/freescale/enetc/enetc.h +1 -14
@@ -16,6 +16,7 @@#include "enetc_hw.h" #include "enetc4_hw.h" +#include "enetc_mailbox.h" #define ENETC_MAC_MAXFRM_SIZE 9600#define ENETC_MAX_MTU (ENETC_MAC_MAXFRM_SIZE - \
@@ -257,12 +258,6 @@ static inline union enetc_rx_bd *enetc_rxbd_ext(union enetc_rx_bd *rxbd)return ++rxbd; } -struct enetc_msg_swbd { -void *vaddr; -dma_addr_t dma; -int size; -}; -#define ENETC_REV1 0x1#define ENETC_REV4 0x4
@@ -490,14 +485,6 @@ struct enetc_ndev_priv {u64 sysclk_freq;/* NETC system clock frequency */ }; -/* Messaging */ - -/* VF-PF set primary MAC address message format */ -struct enetc_msg_cmd_set_primary_mac { -struct enetc_msg_cmd_header header; -struct sockaddr mac; -}; -#define ENETC_CBD (R , i) (&(((struct enetc_cbd *)((R).bd_base))[i]))#define ENETC_CBDR_TIMEOUT 1000/* usecs */
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -4
@@ -17,10 +17,6 @@#define ENETC_MAC_FILTER_TYPE_ALL (ENETC_MAC_FILTER_TYPE_UC | \ ENETC_MAC_FILTER_TYPE_MC) -struct enetc_mac_addr { -u8 addr[ETH_ALEN ]; -}; -static void enetc4_get_port_caps (struct enetc_pf *pf) {struct enetc_hw *hw = &pf->si->hw;
drivers/net/ethernet/freescale/enetc/enetc_mailbox.h new file +151 -0
151 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_msg.c +94 -33
176 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_vf.c +78 -19
127 lines not on this page · raw message
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 7/12 net: enetc: add VF-PF messaging support for IP minor revision query
In reply to Wei FangFor ENETC v4, different SoCs use different minor revisions, such as i.MX95 v4.1, i.MX94 v4.3, and i.MX952 v4.6. Unlike the PF, the VF does not have access to a global register that exposes the IP minor revision. In the current driver model, the VF must select the appropriate driver data based on this revision information.
To support this requirement, the VF now sends a minor revision query message to the PF through the VSI-to-PSI mailbox mechanism. The PF responds with the IP minor revision so that the VF can match the correct driver data.
This patch adds PF-side support for replying to the minor revision message and VF-side support for sending the query.
--- .../ethernet/freescale/enetc/enetc_mailbox.h | 19 +++++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 29 +++++++++++ .../net/ethernet/freescale/enetc/enetc_vf.c | 52 +++++++++++++++++-- 3 files changed, 97 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_mailbox.h +19 -0
@@ -65,6 +65,9 @@* (blocking requests), and * 2) PSI_TX_control: PSIMSGSR[MC] - for PSI to VSI notification messages * (async mode) +* +* Note that for some GET messages, there is no COOKIE field, and the CLASS +* CODE field is expanded to 8 bits. */ #ifndef __ENETC_MAILBOX_H
@@ -84,6 +87,8 @@/* The fileds of PSI-to-VSI message, the message is only 16-bit */ #define ENETC_PF_MSG_COOKIE GENMASK(3, 0)#define ENETC_PF_MSG_CLASS_CODE GENMASK(7, 4) +/* Extend the class code to 8-bit for GET messages without COOKIE */ +#define ENETC_PF_MSG_CLASS_CODE_U8 GENMASK(7, 0)#define ENETC_PF_MSG_CLASS_ID GENMASK(15, 8)enum enetc_msg_class_id {
@@ -102,12 +107,17 @@ enum enetc_msg_class_id {/* Common Class ID for PSI-to-VSI and VSI-to-PSI messages */ ENETC_MSG_CLASS_ID_MAC_FILTER =0x20 , + ENETC_MSG_CLASS_ID_IP_REVISION = 0xf0, };enum enetc_msg_mac_filter_cmd_id {ENETC_MSG_SET_PRIMARY_MAC , }; +enum enetc_msg_ip_revision_cmd_id { +ENETC_MSG_GET_IP_MN =1 , +}; +/* Class-specific error return codes of MAC filter */ enum enetc_mac_filter_class_code { ENETC_MF_CLASS_CODE_INVALID_MAC,
@@ -148,4 +158,13 @@ struct enetc_msg_mac_exact_filter { struct enetc_mac_addr mac[]; }; +/* The generic message format applies to the following messages: +* Get IP revision message, class_id 0xf0. +* cmd_id 1: get IP minor revision +*/ +struct enetc_msg_generic { +struct enetc_msg_header hdr; +u8 resv[16 ]; +}; +#endif
drivers/net/ethernet/freescale/enetc/enetc_msg.c +29 -0
@@ -101,6 +101,21 @@ static u16 enetc_msg_handle_mac_filter(struct enetc_pf *pf, int vf_id, } } +static u16 enetc_msg_handle_ip_revision (struct enetc_pf *pf,void *vf_msg) +{ +struct enetc_msg_header *msg_hdr = vf_msg; + +switch (msg_hdr->cmd_id) { +case ENETC_MSG_GET_IP_MN : +return (FIELD_PREP (ENETC_PF_MSG_CLASS_ID , +ENETC_MSG_CLASS_ID_IP_REVISION ) | +FIELD_PREP (ENETC_PF_MSG_CLASS_CODE_U8 , + pf->si->revision)); +default : +return ENETC_PF_MSG_NOTSUPP ; + } +} +static void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int vf_id,u16 *pf_msg) {
@@ -158,10 +173,24 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, goto free_msg; } +/* The new messages are currently only supported on ENETC v4. If v1 +* requires them, the current restriction can be lifted. +*/ +if (is_enetc_rev1 (pf->si) && + !(msg_hdr->class_id ==ENETC_MSG_CLASS_ID_MAC_FILTER && + msg_hdr->cmd_id ==ENETC_MSG_SET_PRIMARY_MAC )) { +dev_err_ratelimited (dev,"Unsupported message for ENETC v1\n" ); + + goto free_msg; + } +switch (msg_hdr->class_id) {case ENETC_MSG_CLASS_ID_MAC_FILTER : *pf_msg =enetc_msg_handle_mac_filter (pf, vf_id, msg);break ; +case ENETC_MSG_CLASS_ID_IP_REVISION : + *pf_msg =enetc_msg_handle_ip_revision (pf, msg); +break ;default : dev_err_ratelimited(dev, "Unsupported message class ID: 0x%x\n",
drivers/net/ethernet/freescale/enetc/enetc_vf.c +49 -3
100 lines not on this page · raw message
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 8/12 net: enetc: align v1 CBDR API with v4 for VF driver sharing
In reply to Wei FangThe upcoming ENETC v4 VF will share the enetc-vf driver with the v1 VF. However, ENETC v4 introduces different CBDR (command BD ring) setup and teardown semantics that are incompatible with v1.
To support both versions in the same driver, the .setup_cbdr() and .teardown_cbdr() hooks will be added to struct enetc_si_ops, allowing the driver to register version-specific implementations. So refactor the v1 CBDR functions to match the v4-style interface (taking struct enetc_si* instead of individual parameters), enabling them to be registered via si_ops in the subsequent patch.
Changes:
- Update enetc_setup_cbdr() and enetc_teardown_cbdr() prototypes to take 'struct enetc_si *' as the sole parameter
- Extract parameters (dev, hw) from the enetc_si structure within the function implementations
- ENETC_CBDR_DEFAULT_SIZE has always been used as the number of command BDs, and there is no need to adjust the size of the command BD ring. Therefore, ENETC_CBDR_DEFAULT_SIZE is moved into the enetc_setup_cbdr()
- Update all call sites in enetc_pf.c and enetc_vf.c
No functional changes. This prepares for adding v4-specific CBDR handling in subsequent patches.
--- drivers/net/ethernet/freescale/enetc/enetc.h | 5 ++--- .../net/ethernet/freescale/enetc/enetc_cbdr.c | 16 ++++++++++------ drivers/net/ethernet/freescale/enetc/enetc_pf.c | 7 +++---- drivers/net/ethernet/freescale/enetc/enetc_vf.c | 7 +++---- 4 files changed, 18 insertions(+), 17 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.h +2 -3
@@ -537,9 +537,8 @@ void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link);void enetc_mm_commit_preemptible_tcs (struct enetc_ndev_priv *priv);/* control buffer descriptor ring (CBDR) */ -int enetc_setup_cbdr (struct device *dev,struct enetc_hw *hw,int bd_count, -struct enetc_cbdr *cbdr); -void enetc_teardown_cbdr (struct enetc_cbdr *cbdr); +int enetc_setup_cbdr (struct enetc_si *si); +void enetc_teardown_cbdr (struct enetc_si *si);int enetc4_setup_cbdr (struct enetc_si *si);void enetc4_teardown_cbdr (struct enetc_si *si); int enetc_set_mac_flt_entry(struct enetc_si *si, int index,
drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +10 -6
@@ -3,10 +3,12 @@#include "enetc.h" -int enetc_setup_cbdr (struct device *dev,struct enetc_hw *hw,int bd_count, -struct enetc_cbdr *cbdr) +int enetc_setup_cbdr (struct enetc_si *si) { -int size = bd_count *sizeof (struct enetc_cbd ); +int size =ENETC_CBDR_DEFAULT_SIZE *sizeof (struct enetc_cbd ); +struct enetc_cbdr *cbdr = &si->cbd_ring; +struct device *dev = &si->pdev->dev; +struct enetc_hw *hw = &si->hw; cbdr->bd_base =dma_alloc_coherent (dev, size, &cbdr->bd_dma_base,GFP_KERNEL );
@@ -23,7 +25,7 @@ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, cbdr->next_to_clean =0 ; cbdr->next_to_use =0 ; cbdr->dma_dev = dev; - cbdr->bd_count = bd_count; + cbdr->bd_count =ENETC_CBDR_DEFAULT_SIZE ; cbdr->pir = hw->reg +ENETC_SICBDRPIR ; cbdr->cir = hw->reg +ENETC_SICBDRCIR ;
@@ -46,13 +48,15 @@ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, }EXPORT_SYMBOL_GPL (enetc_setup_cbdr); -void enetc_teardown_cbdr (struct enetc_cbdr *cbdr) +void enetc_teardown_cbdr (struct enetc_si *si) { -int size = cbdr->bd_count *sizeof (struct enetc_cbd ); +struct enetc_cbdr *cbdr = &si->cbd_ring; +int size;/* disable ring */ enetc_wr_reg (cbdr->mr,0 ); + size = cbdr->bd_count *sizeof (struct enetc_cbd );dma_free_coherent (cbdr->dma_dev, size, cbdr->bd_base, cbdr->bd_dma_base); cbdr->bd_base =NULL ;
drivers/net/ethernet/freescale/enetc/enetc_pf.c +3 -4
@@ -802,8 +802,7 @@ static struct enetc_si *enetc_psi_create(struct pci_dev *pdev) goto out_pci_remove; } - err =enetc_setup_cbdr (&pdev->dev, &si->hw,ENETC_CBDR_DEFAULT_SIZE , - &si->cbd_ring); + err =enetc_setup_cbdr (si);if (err) goto out_pci_remove;
@@ -822,7 +821,7 @@ static struct enetc_si *enetc_psi_create(struct pci_dev *pdev)return si; out_teardown_cbdr: -enetc_teardown_cbdr (&si->cbd_ring); +enetc_teardown_cbdr (si); out_pci_remove:enetc_pci_remove (pdev); out:
@@ -833,7 +832,7 @@ static void enetc_psi_destroy(struct pci_dev *pdev) {struct enetc_si *si =pci_get_drvdata (pdev); -enetc_teardown_cbdr (&si->cbd_ring); +enetc_teardown_cbdr (si);enetc_pci_remove (pdev); }
drivers/net/ethernet/freescale/enetc/enetc_vf.c +3 -4
@@ -328,8 +328,7 @@ static int enetc_vf_probe(struct pci_dev *pdev,enetc_init_si_rings_params (priv); - err =enetc_setup_cbdr (priv->dev, &si->hw,ENETC_CBDR_DEFAULT_SIZE , - &si->cbd_ring); + err =enetc_setup_cbdr (si);if (err) goto err_setup_cbdr;
@@ -365,7 +364,7 @@ static int enetc_vf_probe(struct pci_dev *pdev, err_alloc_msix:enetc_free_si_resources (priv); err_alloc_si_res: -enetc_teardown_cbdr (&si->cbd_ring); +enetc_teardown_cbdr (si); err_setup_cbdr: si->ndev =NULL ;free_netdev (ndev);
@@ -390,7 +389,7 @@ static void enetc_vf_remove(struct pci_dev *pdev)enetc_free_msix (priv);enetc_free_si_resources (priv); -enetc_teardown_cbdr (&si->cbd_ring); +enetc_teardown_cbdr (si);free_netdev (si->ndev);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 9/12 net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF support
In reply to Wei FangThe upcoming ENETC v4 VF will share the enetc-vf driver with the existing v1 VF. However, ENETC v4 uses a revised CBDR (command BD ring) setup/teardown API that differs from v1.
To support both versions in the same driver, add setup_cbdr() and teardown_cbdr() function pointers to struct enetc_si_ops. This allows each hardware version to register its own CBDR implementation:
- ENETC v1 VF registers enetc_setup_cbdr/enetc_teardown_cbdr (existing)
- ENETC v4 VF will register enetc4_setup_cbdr/enetc4_teardown_cbdr
Update the enetc-vf driver to call CBDR operations through si->ops instead of directly invoking the v1 functions. This enables runtime selection of the correct CBDR backend based on hardware version.
Changes:
- Add setup_cbdr() and teardown_cbdr() hooks to struct enetc_si_ops
- Register v1 CBDR functions in enetc_vsi_ops
- Replace direct calls with si->ops->setup_cbdr() and si->ops->teardown_cbdr() in enetc_vf.c
No functional changes to existing v1 VF behavior.
--- drivers/net/ethernet/freescale/enetc/enetc.h | 2 ++ drivers/net/ethernet/freescale/enetc/enetc_vf.c | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.h +2 -0
@@ -297,6 +297,8 @@ struct enetc_si;struct enetc_si_ops {int (*get_rss_table)(struct enetc_si *si,u32 *table,int count);int (*set_rss_table)(struct enetc_si *si,const u32 *table,int count); +int (*setup_cbdr)(struct enetc_si *si); +void (*teardown_cbdr)(struct enetc_si *si); };/* PCI IEP device data */
drivers/net/ethernet/freescale/enetc/enetc_vf.c +5 -3
@@ -288,6 +288,8 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,static const struct enetc_si_ops enetc_vsi_ops = { .get_rss_table = enetc_get_rss_table, .set_rss_table = enetc_set_rss_table, + .setup_cbdr = enetc_setup_cbdr, + .teardown_cbdr = enetc_teardown_cbdr, }; static int enetc_vf_probe(struct pci_dev *pdev,
@@ -328,7 +330,7 @@ static int enetc_vf_probe(struct pci_dev *pdev,enetc_init_si_rings_params (priv); - err =enetc_setup_cbdr (si); + err = si->ops->setup_cbdr (si);if (err) goto err_setup_cbdr;
@@ -364,7 +366,7 @@ static int enetc_vf_probe(struct pci_dev *pdev, err_alloc_msix:enetc_free_si_resources (priv); err_alloc_si_res: -enetc_teardown_cbdr (si); + si->ops->teardown_cbdr (si); err_setup_cbdr: si->ndev =NULL ;free_netdev (ndev);
@@ -389,7 +391,7 @@ static void enetc_vf_remove(struct pci_dev *pdev)enetc_free_msix (priv);enetc_free_si_resources (priv); -enetc_teardown_cbdr (si); + si->ops->teardown_cbdr (si);free_netdev (si->ndev);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 net-next 09/12] net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing PCIe posted write flush during CBDR teardown leads to potential DMA use-after-free/fault --
commit e8719566bfcc671815aca75ea6a2c0caefb79aef
Author: Wei Fang <[email protected]>
net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF support
This commit adds setup_cbdr and teardown_cbdr function pointers to struct enetc_si_ops to allow the ENETC v1 and v4 VF drivers to register their own command BD ring implementations. It updates the VF driver to call these operations through the ops structure instead of invoking the v1 functions directly, enabling runtime selection based on the hardware version.
drivers/net/ethernet/freescale/enetc/enetc_vf.c static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev, · line 292
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +2
-0@@ -288,6 +288,8 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,static const struct enetc_si_ops enetc_vsi_ops = { .get_rss_table = enetc_get_rss_table, .set_rss_table = enetc_set_rss_table, + .setup_cbdr = enetc_setup_cbdr, + .teardown_cbdr = enetc_teardown_cbdr,
[Severity: High]
This is a pre-existing issue, but looking at the implementation of enetc_teardown_cbdr(), the command ring is disabled by writing 0 to the Mode Register. Because this write translates to an iowrite32, it is a posted PCIe write that can be delayed in the interconnect fabric.
The code then frees the DMA memory immediately without reading back from a device register to flush the posted write, and without polling for a hardware busy status to clear.
If a previous command timed out and the hardware is still processing it, or if the posted write is simply delayed, could the device continue accessing the descriptor ring after the memory is unmapped? This might result in an IOMMU fault or silent memory corruption if the IOMMU is disabled.
Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_vf.c +0
-0};
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Wei Fang
maintainerPATCH v2 10/12 net: enetc: add generic helper to initialize SR-IOV resources
In reply to Wei FangThe upcoming ENETC v4 PF driver will support SR-IOV, and its logic for initializing VF resources is identical to the existing ENETC v1 PF implementation. To avoid code duplication across PF drivers, factor out the common SR-IOV initialization logic into the enetc-pf-common driver.
Add enetc_init_sriov_resources() to handle:
- Querying the total number of VFs supported by the device via pci_sriov_get_totalvfs()
- Allocating memory for the VF state array (struct enetc_vf_state)
The implementation uses devm_kcalloc() instead of kzalloc() to simplify memory management. This automatically frees VF state memory when the PF device is removed, eliminating the need for explicit cleanup in error and remove paths.
--- .../net/ethernet/freescale/enetc/enetc_pf.c | 20 ++++-------------- .../freescale/enetc/enetc_pf_common.c | 21 +++++++++++++++++++ .../freescale/enetc/enetc_pf_common.h | 1 + 3 files changed, 26 insertions(+), 16 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +4 -16
@@ -872,18 +872,9 @@ static int enetc_pf_probe(struct pci_dev *pdev, pf->si = si; pf->ops = &enetc_pf_ops; - pf->total_vfs =pci_sriov_get_totalvfs (pdev); -if (pf->total_vfs) { - pf->vf_state = kzalloc_objs(struct enetc_vf_state, - pf->total_vfs); -if (!pf->vf_state) { - err = -ENOMEM ; - goto err_alloc_vf_state; - } - -for (int i =0 ; i < pf->total_vfs; i++) -mutex_init (&pf->vf_state[i].lock); - } + err =enetc_init_sriov_resources (pf); +if (err) + goto err_init_sriov_resources; err =enetc_setup_mac_addresses (node, pf);if (err)
@@ -961,8 +952,7 @@ static int enetc_pf_probe(struct pci_dev *pdev,free_netdev (ndev); err_alloc_netdev: err_setup_mac_addresses: -kfree (pf->vf_state); -err_alloc_vf_state: +err_init_sriov_resources:enetc_psi_destroy (pdev); err_psi_create:return err;
@@ -989,8 +979,6 @@ static void enetc_pf_remove(struct pci_dev *pdev)enetc_free_si_resources (priv);free_netdev (si->ndev); -kfree (pf->vf_state); -enetc_psi_destroy (pdev); }
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +21 -0
@@ -435,5 +435,26 @@ int enetc_vlan_rx_del_vid(struct net_device *ndev, __be16 prot, u16 vid) }EXPORT_SYMBOL_GPL (enetc_vlan_rx_del_vid); +int enetc_init_sriov_resources (struct enetc_pf *pf) +{ +struct device *dev = &pf->si->pdev->dev; + + pf->total_vfs =pci_sriov_get_totalvfs (pf->si->pdev); +if (!pf->total_vfs) +return 0 ; + + pf->vf_state =devm_kcalloc (dev, pf->total_vfs, +sizeof (struct enetc_vf_state ), +GFP_KERNEL ); +if (!pf->vf_state) +return -ENOMEM ; + +for (int i =0 ; i < pf->total_vfs; i++) +mutex_init (&pf->vf_state[i].lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (enetc_init_sriov_resources); +MODULE_DESCRIPTION ("NXP ENETC PF common functionality driver" );MODULE_LICENSE ("Dual BSD/GPL" );
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +1 -0
@@ -16,6 +16,7 @@ void enetc_phylink_destroy(struct enetc_ndev_priv *priv);void enetc_set_default_rss_key (struct enetc_pf *pf);int enetc_vlan_rx_add_vid (struct net_device *ndev,__be16 prot,u16 vid);int enetc_vlan_rx_del_vid (struct net_device *ndev,__be16 prot,u16 vid); +int enetc_init_sriov_resources (struct enetc_pf *pf);static inline u16 enetc_get_ip_revision (struct enetc_hw *hw) {
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 11/12 net: enetc: use MADDR_TYPE for MAC filter array size
In reply to Wei FangThe mac_filter array in struct enetc_pf is sized as ENETC_MAX_NUM_MAC_FLT, defined as (ENETC_MAX_NUM_VFS + 1) * MADDR_TYPE. This resulted in an array of 6 elements (for 2 VFs), but only the first 2 entries are actually used.
The PF driver maintains MAC filters for unicast (UC) and multicast (MC) addresses, indexed by the enum enetc_mac_addr_type (UC=0, MC=1). The code only iterates over MADDR_TYPE (2) entries and directly accesses mac_filter[UC] and mac_filter[MC]. The extra space allocated for (ENETC_MAX_NUM_VFS * MADDR_TYPE) entries is never used because VF MAC filtering is not implemented yet.
Remove the ENETC_MAX_NUM_MAC_FLT macro and size the array as MADDR_TYPE, reducing the allocation from 6 to 2 entries. This saves 48 bytes per PF and better reflects the actual usage.
This change has no functional impact. Future VF MAC filtering support will move mac_filter into struct enetc_si, allowing each SI (PF or VF) to maintain its own independent filter table.
--- drivers/net/ethernet/freescale/enetc/enetc_pf.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_pf.h +1 -3
@@ -5,8 +5,6 @@#include <linux/phylink.h> #define ENETC_PF_NUM_RINGS 8 -#define ENETC_MAX_NUM_MAC_FLT ((ENETC_MAX_NUM_VFS + 1) * MADDR_TYPE) -#define ENETC_VLAN_HT_SIZE 64enum enetc_vf_flags {
@@ -43,7 +41,7 @@ struct enetc_pf {int total_vfs;/* max number of VFs, set for PF at probe */ struct enetc_vf_state *vf_state; -struct enetc_mac_filter mac_filter[ENETC_MAX_NUM_MAC_FLT ]; +struct enetc_mac_filter mac_filter[MADDR_TYPE ];struct enetc_msg_swbd rxmsg[ENETC_MAX_NUM_VFS ];struct work_struct msg_task;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 12/12 net: enetc: dynamically allocate rxmsg based on VF count
In reply to Wei FangThe constant ENETC_MAX_NUM_VFS is defined as 2 when enabling support for LS1028A. This works for LS1028A because its ENETC hardware supports up to 2 VFs. However, ENETC v4 has varying VF capabilities depending on the SoC:
i.MX94 standalone ENETC: 0 VFs i.MX94 internal ENETC: 3 VFs i.MX952: 1 VF
Using a fixed ENETC_MAX_NUM_VFS for memory allocation leads to over-allocation on SoCs with fewer or no VF support. To better match hardware capabilities and avoid unnecessary memory usage, change rxmsg memory allocation from a fixed-size array to dynamic allocation based on the actual VF count retrieved via pci_sriov_get_totalvfs().
--- drivers/net/ethernet/freescale/enetc/enetc_hw.h | 1 - drivers/net/ethernet/freescale/enetc/enetc_pf.h | 2 +- drivers/net/ethernet/freescale/enetc/enetc_pf_common.c | 6 ++++++ 3 files changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_hw.h +0 -1
@@ -681,7 +681,6 @@ union enetc_rx_bd {#define ENETC_MAC_ADDR_FILT_CNT 8/* # of supported entries per port */ #define EMETC_MAC_ADDR_FILT_RES 3/* # of reserved entries at the beginning */ -#define ENETC_MAX_NUM_VFS 2#define ENETC_CBD_FLAGS_SF BIT(7)/* short format */ #define ENETC_CBD_STATUS_MASK 0xf
drivers/net/ethernet/freescale/enetc/enetc_pf.h +1 -1
@@ -43,7 +43,7 @@ struct enetc_pf {struct enetc_mac_filter mac_filter[MADDR_TYPE ]; -struct enetc_msg_swbd rxmsg[ENETC_MAX_NUM_VFS ]; +struct enetc_msg_swbd *rxmsg;struct work_struct msg_task;char msg_int_name[ENETC_INT_NAME_MAX ];
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +6 -0
@@ -443,6 +443,12 @@ int enetc_init_sriov_resources(struct enetc_pf *pf)if (!pf->total_vfs)return 0 ; + pf->rxmsg =devm_kcalloc (dev, pf->total_vfs, +sizeof (struct enetc_msg_swbd ), +GFP_KERNEL ); +if (!pf->rxmsg) +return -ENOMEM ; + pf->vf_state =devm_kcalloc (dev, pf->total_vfs,sizeof (struct enetc_vf_state ),GFP_KERNEL );
Signature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH v2 net-next 12/12] net: enetc: dynamically allocate rxmsg based on VF count
The below issues reported by Sashiko are false positives. The ENETC v4 (i.MX series) uses a different driver (enetc4_pf.c). enetc_pf.c and ENETC_PSIPVMR_SET_VP and are only used by the ENETC v1 driver, and ENETC v1 supports 2 VFs, so the issues do not actually exist.
Sashio:
Quoted 1 line
i.MX94 standalone ENETC: 0 VFs
This is a pre-existing issue, but if a device supports 0 VFs and reports more than 8 hardware rings during probe, will this result in a division by zero?
In enetc_port_si_configure(), the driver reserves 8 rings for the PF and distributes the rest to the VFs:
drivers/net/ethernet/freescale/enetc/enetc_pf.c:enetc_port_si_configure() {
...
if (num_rings)
num_rings -= ENETC_PF_NUM_RINGS;
...
if (num_rings) {
num_rings /= pf->total_vfs;
val |= ENETC_PSICFGR0_SET_TXBDR(num_rings);
val |= ENETC_PSICFGR0_SET_RXBDR(num_rings);
}
...
}If pf->total_vfs is 0 and there are remaining rings, the division by zero will cause a kernel panic.
Quoted 1 line
i.MX94 internal ENETC: 3 VFs
This isn't a bug introduced by this patch, but since 3 VFs means there are 4 Station Interfaces (1 PF + 3 VFs) in total, will VLAN promiscuous mode work for the 3rd VF?
The ENETC_PSIPVMR_SET_VP() macro uses a hardcoded 0x7 mask (3 bits), which covers only the first 3 Station Interfaces:
drivers/net/ethernet/freescale/enetc/enetc_hw.h:
#define ENETC_PSIPVMR_SET_VP(simap) ((simap) & 0x7)
Because of this mask, the 4th Station Interface (the 3rd VF mapped to bit 3) is silently dropped from the VLAN promiscuous mode configuration.
[email protected]
AI reviewRe: [PATCH v2 net-next 12/12] net: enetc: dynamically allocate rxmsg based on VF count
In reply to Wei FangThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] VLAN promiscuous mode is silently broken for Virtual Functions beyond the first two due to a hardcoded 3-bit mask.
- [High] Potential division by zero when allocating hardware rings to VFs if the device supports 0 VFs and has more than 8 rings. --
commit 03bc9cb8ddeec88c130b193926ea03b84b9d152b
Author: Wei Fang <[email protected]>
net: enetc: dynamically allocate rxmsg based on VF count
This commit updates the ENETC driver to dynamically allocate the rxmsg array based on the actual number of Virtual Functions supported by the hardware. It removes the fixed allocation size to prevent memory over-allocation on hardware variants with fewer or zero VFs.
Quoted 1 line
i.MX94 standalone ENETC: 0 VFs
[Severity: High]
This is a pre-existing issue, but if a device supports 0 VFs and reports more than 8 hardware rings during probe, will this result in a division by zero?
In enetc_port_si_configure(), the driver reserves 8 rings for the PF and distributes the rest to the VFs:
drivers/net/ethernet/freescale/enetc/enetc_pf.c:enetc_port_si_configure() {
...
if (num_rings)
num_rings -= ENETC_PF_NUM_RINGS;
...
if (num_rings) {
num_rings /= pf->total_vfs;
val |= ENETC_PSICFGR0_SET_TXBDR(num_rings);
val |= ENETC_PSICFGR0_SET_RXBDR(num_rings);
}
...
}If pf->total_vfs is 0 and there are remaining rings, the division by zero will cause a kernel panic.
Quoted 1 line
i.MX94 internal ENETC: 3 VFs
[Severity: High]
This isn't a bug introduced by this patch, but since 3 VFs means there are 4 Station Interfaces (1 PF + 3 VFs) in total, will VLAN promiscuous mode work for the 3rd VF?
The ENETC_PSIPVMR_SET_VP() macro uses a hardcoded 0x7 mask (3 bits), which covers only the first 3 Station Interfaces:
drivers/net/ethernet/freescale/enetc/enetc_hw.h:
#define ENETC_PSIPVMR_SET_VP(simap) ((simap) & 0x7)
Because of this mask, the 4th Station Interface (the 3rd VF mapped to bit 3) is silently dropped from the VLAN promiscuous mode configuration.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Fri, 22 May 2026 17:24:26 +0800 you wrote:
This patch series refactors and extends the ENETC driver infrastructure to prepare for upcoming ENETC v4 Virtual Function (VF) support. The main focus is on code commonization, improved VF-PF communication, and dynamic resource allocation.
The ENETC IP has evolved across different revisions, and the existing driver architecture was primarily designed around v1 hardware. To support v4 VFs efficiently, we need to share common code between PF drivers of different IP versions while maintaining compatibility.
[...]
Here is the summary with links:
- [v2,net-next,01/12] net: enetc: use enetc_set_si_hw_addr() for setting MAC address
https://git.kernel.org/netdev/net-next/c/443a573e7940 - [v2,net-next,02/12] net: enetc: move VF message handlers to enetc_msg.c https://git.kernel.org/netdev/net-next/c/9ba01f877040 - [v2,net-next,03/12] net: enetc: relocate SR-IOV configuration helper for common PF support https://git.kernel.org/netdev/net-next/c/bb69b9fd1c60 - [v2,net-next,04/12] net: enetc: integrate enetc_msg.c into enetc-pf-common driver https://git.kernel.org/netdev/net-next/c/7a3c77287039 - [v2,net-next,05/12] net: enetc: use read_poll_timeout() for VF mailbox polling https://git.kernel.org/netdev/net-next/c/55d62e801dde - [v2,net-next,06/12] net: enetc: convert mailbox messages to new formats https://git.kernel.org/netdev/net-next/c/3c4542b252fb - [v2,net-next,07/12] net: enetc: add VF-PF messaging support for IP minor revision query https://git.kernel.org/netdev/net-next/c/72037f953a34 - [v2,net-next,08/12] net: enetc: align v1 CBDR API with v4 for VF driver sharing https://git.kernel.org/netdev/net-next/c/4f46f1accd02 - [v2,net-next,09/12] net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF support https://git.kernel.org/netdev/net-next/c/6bdc3144c0dc - [v2,net-next,10/12] net: enetc: add generic helper to initialize SR-IOV resources https://git.kernel.org/netdev/net-next/c/250069ef0df3 - [v2,net-next,11/12] net: enetc: use MADDR_TYPE for MAC filter array size https://git.kernel.org/netdev/net-next/c/c55a33014b52 - [v2,net-next,12/12] net: enetc: dynamically allocate rxmsg based on VF count https://git.kernel.org/netdev/net-next/c/9d7b650888ff
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html