]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: enetc: move VF message handlers to enetc_msg.c
authorWei Fang <wei.fang@nxp.com>
Fri, 22 May 2026 09:24:28 +0000 (17:24 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 26 May 2026 11:20:13 +0000 (13:20 +0200)
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>
Link: https://patch.msgid.link/20260522092438.1264020-3-wei.fang@nxp.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/freescale/enetc/enetc_msg.c
drivers/net/ethernet/freescale/enetc/enetc_pf.c
drivers/net/ethernet/freescale/enetc/enetc_pf.h

index c09635e7eb3dff77bf1f6a652bfe4a8e17e2fa12..73da2018034e1f78b152ecd325d07c9de8132b11 100644 (file)
@@ -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);
index 4d72e2b7707259f1b5e212abd2f7976596d2a3fc..67cc80adec72d4fb7e34b69ca3cd46e290d36723 100644 (file)
@@ -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)
 {
index 35d484858c7bdf4332af7f4d6334d0a96e375172..3b265ad8d845bef3b6e5e8c20ff4b3d572d4fd40 100644 (file)
@@ -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);