From: Wei Fang <wei.fang@nxp.com>
To: claudiu.manoil@nxp.com, vladimir.oltean@nxp.com,
xiaoning.wang@nxp.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: imx@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 net-next 02/12] net: enetc: move VF message handlers to enetc_msg.c
Date: Fri, 22 May 2026 17:24:28 +0800 [thread overview]
Message-ID: <20260522092438.1264020-3-wei.fang@nxp.com> (raw)
In-Reply-To: <20260522092438.1264020-1-wei.fang@nxp.com>
Move 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.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
.../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(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c
index c09635e7eb3d..73da2018034e 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c
@@ -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);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 4d72e2b77072..67cc80adec72 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -480,81 +480,6 @@ static void enetc_configure_port(struct enetc_pf *pf)
enetc_port_wr(hw, ENETC_PMR, ENETC_PMR_EN);
}
-/* 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;
-}
-
-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);
-}
-
#ifdef CONFIG_PCI_IOV
static int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs)
{
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
index 35d484858c7b..3b265ad8d845 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
@@ -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);
--
2.34.1
next prev parent reply other threads:[~2026-05-22 9:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 9:24 [PATCH v2 net-next 00/12] net: enetc: Prepare for ENETC v4 VF support Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 01/12] net: enetc: use enetc_set_si_hw_addr() for setting MAC address Wei Fang
2026-05-22 9:24 ` Wei Fang [this message]
2026-05-22 9:24 ` [PATCH v2 net-next 03/12] net: enetc: relocate SR-IOV configuration helper for common PF support Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 04/12] net: enetc: integrate enetc_msg.c into enetc-pf-common driver Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 05/12] net: enetc: use read_poll_timeout() for VF mailbox polling Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 06/12] net: enetc: convert mailbox messages to new formats Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 07/12] net: enetc: add VF-PF messaging support for IP minor revision query Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 08/12] net: enetc: align v1 CBDR API with v4 for VF driver sharing Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 09/12] net: enetc: add CBDR setup/teardown hooks to enetc_si_ops for VF support Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 10/12] net: enetc: add generic helper to initialize SR-IOV resources Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 11/12] net: enetc: use MADDR_TYPE for MAC filter array size Wei Fang
2026-05-22 9:24 ` [PATCH v2 net-next 12/12] net: enetc: dynamically allocate rxmsg based on VF count Wei Fang
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=20260522092438.1264020-3-wei.fang@nxp.com \
--to=wei.fang@nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vladimir.oltean@nxp.com \
--cc=xiaoning.wang@nxp.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