From: <alejandro.lucero-palau@amd.com>
To: <linux-cxl@vger.kernel.org>, <netdev@vger.kernel.org>,
<edward.cree@amd.com>, <davem@davemloft.net>, <kuba@kernel.org>,
<pabeni@redhat.com>, <edumazet@google.com>,
<dave.jiang@intel.com>
Cc: Alejandro Lucero <alucerop@amd.com>
Subject: [RFC 2/2] sfc: add multipf support
Date: Fri, 21 Aug 2026 16:51:34 +0100 [thread overview]
Message-ID: <20260821155134.260053-3-alejandro.lucero-palau@amd.com> (raw)
In-Reply-To: <20260821155134.260053-1-alejandro.lucero-palau@amd.com>
From: Alejandro Lucero <alucerop@amd.com>
Use CXL core accelerator API for registering non-PF0 PFs to the memdev
linked to the PF0, along with its complementary unregister.
Adapt the ioremap call per PF to be an offset based on the PF function
index and a hardcoded per PF CXL.mem slot size.
Signed-off-by: Alejandro Lucero <alucerop@amd.com>
---
drivers/net/ethernet/sfc/efx_cxl.c | 106 +++++++++++++++++++++++++++--
1 file changed, 100 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c
index 348d7404cd7a..e45c8dd1969c 100644
--- a/drivers/net/ethernet/sfc/efx_cxl.c
+++ b/drivers/net/ethernet/sfc/efx_cxl.c
@@ -13,6 +13,48 @@
#include "efx_cxl.h"
#define EFX_CTPIO_BUFFER_SIZE SZ_256M
+#define EFX_CTPIO_BUFFER_PER_PF_SIZE SZ_8M
+
+#define X4_PF_DEVICE_ID 0x0c03
+
+static struct pci_dev *get_pf0_pci_device(struct pci_dev *pfx)
+{
+ struct pci_dev *pf0_pci_dev;
+
+ while ((pf0_pci_dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
+ X4_PF_DEVICE_ID, pf0_pci_dev))
+ != NULL) {
+ /* With multiple X4 installed check against pci_slot as well. */
+ if (pf0_pci_dev->slot == pfx->slot &&
+ PCI_FUNC(pf0_pci_dev->devfn) == 0)
+ break;
+ }
+ return pf0_pci_dev;
+}
+
+static int cxl_map(struct efx_probe_data *probe_data, struct efx_cxl *cxl,
+ u64 devfn, struct range cxl_pio_range)
+{
+ struct efx_nic *efx = &probe_data->efx;
+ struct pci_dev *pci_dev = efx->pci_dev;
+ u64 cxl_pio_pf_start;
+
+ cxl_pio_pf_start = cxl_pio_range.start + devfn *
+ EFX_CTPIO_BUFFER_PER_PF_SIZE;
+
+ cxl->ctpio_cxl = ioremap_wc(cxl_pio_pf_start,
+ EFX_CTPIO_BUFFER_PER_PF_SIZE);
+ if (!cxl->ctpio_cxl) {
+ pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+ &cxl_pio_range);
+ return -ENOMEM;
+ }
+
+ probe_data->cxl = cxl;
+ probe_data->cxl_pio_initialised = true;
+
+ return 0;
+}
int efx_cxl_init(struct efx_probe_data *probe_data)
{
@@ -20,9 +62,48 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
struct pci_dev *pci_dev = efx->pci_dev;
struct range cxl_pio_range;
struct efx_cxl *cxl;
+ u8 devfn;
u16 dvsec;
int rc;
+ if (efx->type->is_vf)
+ return 0;
+
+ /* are we PF0? */
+ devfn = PCI_FUNC(pci_dev->devfn);
+ if (devfn != 0) {
+ struct pci_dev *pf0_pci_dev;
+ struct cxl_memdev *cxlmd;
+
+ pf0_pci_dev = get_pf0_pci_device(pci_dev);
+
+ /* This should not happen! */
+ if (!pf0_pci_dev)
+ return 0;
+
+ /* Is the PF0 device configured with and using CXL? */
+ if (!pcie_is_cxl(pf0_pci_dev))
+ return 0;
+
+ cxlmd = cxl_get_pf0_memdev(&pf0_pci_dev->dev, &pci_dev->dev,
+ devfn, &cxl_pio_range);
+
+ if (IS_ERR(cxlmd))
+ return -EPROBE_DEFER;
+
+ cxl = kzalloc_obj(struct cxl);
+ if (!cxl)
+ return -ENOMEM;
+
+ cxl->cxlmd = cxlmd;
+
+ if (!cxl_map(probe_data, cxl, (u64)devfn, cxl_pio_range)) {
+ kfree(cxl);
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
/* Is the device configured with and using CXL? */
if (!pcie_is_cxl(pci_dev))
return 0;
@@ -80,25 +161,38 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
return PTR_ERR(cxl->cxlmd);
}
- cxl->ctpio_cxl = ioremap_wc(cxl_pio_range.start,
- range_len(&cxl_pio_range));
- if (!cxl->ctpio_cxl) {
+ if (!cxl_map(probe_data, cxl, 0, cxl_pio_range)) {
pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
&cxl_pio_range);
return -ENOMEM;
}
- probe_data->cxl_pio_initialised = true;
- probe_data->cxl = cxl;
-
return 0;
}
void efx_cxl_exit(struct efx_probe_data *probe_data)
{
+ struct efx_nic *efx = &probe_data->efx;
+ struct pci_dev *pci_dev = efx->pci_dev;
+ u8 devfn;
+
if (!probe_data->cxl)
return;
+ /* are we PF0? */
+ devfn = PCI_FUNC(pci_dev->devfn);
+ if (devfn != 0) {
+ struct pci_dev *pf0_pci_dev;
+
+ pf0_pci_dev = get_pf0_pci_device(pci_dev);
+
+ /* This should not happen! */
+ if (!pf0_pci_dev)
+ return;
+
+ cxl_put_pf0_memdev(&pf0_pci_dev->dev, &pci_dev->dev, devfn);
+ }
+
iounmap(probe_data->cxl->ctpio_cxl);
}
--
2.34.1
prev parent reply other threads:[~2026-08-21 14:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 15:51 [RFC 0/2] Type2 multipf support alejandro.lucero-palau
2026-08-21 15:51 ` [RFC 1/2] cxl/memdev: add support for mutipf device alejandro.lucero-palau
2026-08-24 8:33 ` Richard Cheng
2026-08-21 15:51 ` alejandro.lucero-palau [this message]
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=20260821155134.260053-3-alejandro.lucero-palau@amd.com \
--to=alejandro.lucero-palau@amd.com \
--cc=alucerop@amd.com \
--cc=dave.jiang@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=edward.cree@amd.com \
--cc=kuba@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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