Skip to contentSkip to conversation

Type2 device basic support

PATCH New [email protected] 2 participants 10 messages Jun 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v31 cover Type2 device basic support

From: Alejandro Lucero <[email protected]>

This series adds the sfc netdev driver as the client for previous CXL Type2 support changes.

Changes from v30:

- Only sfc changes as CXL Type2 client.

Changes from v29:

- Only cxl core changes.

Changes from v28:

- patch 1:
fix doc (Ed Cree)
fix error path (Sashiko)

- patch 3:
removing extra + char (sashiko)

- path5:
remove stray change (Ed Cree)

Changes from v27:

- patch 1: make driver probe failing if error in efx_cxl_init (Dan)
- patch 4: add unmapping if error after efx_cxl_init (Dave)
- patch 4/5: move cxl_pio_initialised from patch 4 to patch 5 (Dave)

Tested in the cxl_for_7.3 branch.

Alejandro Lucero (5):
sfc: add cxl support
sfc: Map cxl regs
sfc: Initialize cxl dpa
sfc: obtain and map cxl range using devm_cxl_probe_mem
sfc: support pio mapping based on cxl

 drivers/net/ethernet/sfc/Kconfig      |   9 +++
 drivers/net/ethernet/sfc/Makefile     |   1 +
 drivers/net/ethernet/sfc/ef10.c       |  41 ++++++++--
 drivers/net/ethernet/sfc/efx.c        |  18 ++++-
 drivers/net/ethernet/sfc/efx_cxl.c    | 105 ++++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h    |  32 ++++++++
 drivers/net/ethernet/sfc/net_driver.h |  10 +++
 drivers/net/ethernet/sfc/nic.h        |   3 +
 8 files changed, 211 insertions(+), 8 deletions(-)
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.c
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.h

base-commit: 96ddf1af34f5f9e29891a5bfb7a18dd0a5bab9d6

Signature · 1 line
2.34.1
#1 lore raw

PATCH v31 1/5 sfc: add cxl support

From: Alejandro Lucero <[email protected]>

Add CXL initialization based on new CXL API for accel drivers and make it dependent on kernel CXL configuration.

---
 drivers/net/ethernet/sfc/Kconfig      |  9 +++++
 drivers/net/ethernet/sfc/Makefile     |  1 +
 drivers/net/ethernet/sfc/efx.c        | 16 ++++++++-
 drivers/net/ethernet/sfc/efx_cxl.c    | 50 +++++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h    | 29 ++++++++++++++++
 drivers/net/ethernet/sfc/net_driver.h |  8 +++++
 6 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.c
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.h
drivers/net/ethernet/sfc/Kconfig +9 -0
index c4c43434f314..979f2801e2a8 100644
@@ -66,6 +66,15 @@ config SFC_MCDI_LOGGING
 	  Driver-Interface) commands and responses, allowing debugging of
 	  driver/firmware interaction.  The tracing is actually enabled by
 	  a sysfs file 'mcdi_logging' under the PCI device.
+config SFC_CXL
+	bool "Solarflare SFC9100-family CXL support"
+	depends on SFC && CXL_BUS >= SFC
+	default SFC
+	help
+	  This enables SFC CXL support if the kernel is configuring CXL for
+	  using CTPIO with CXL.mem. The SFC device with CXL support and
+	  with a CXL-aware firmware can be used for minimizing latencies
+	  when sending through CTPIO.
 
 source "drivers/net/ethernet/sfc/falcon/Kconfig"
 source "drivers/net/ethernet/sfc/siena/Kconfig"
drivers/net/ethernet/sfc/Makefile +1 -0
index d99039ec468d..bb0f1891cde6 100644
@@ -13,6 +13,7 @@ sfc-$(CONFIG_SFC_SRIOV)	+= sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \
                            mae.o tc.o tc_bindings.o tc_counters.o \
                            tc_encap_actions.o tc_conntrack.o
 
+sfc-$(CONFIG_SFC_CXL)	+= efx_cxl.o
 obj-$(CONFIG_SFC)	+= sfc.o
 
 obj-$(CONFIG_SFC_FALCON) += falcon/
drivers/net/ethernet/sfc/efx.c +15 -1
index 8f136a11d396..61cbb6cfc360 100644
@@ -34,6 +34,7 @@
 #include "selftest.h"
 #include "sriov.h"
 #include "efx_devlink.h"
+#include "efx_cxl.h"
 
 #include "mcdi_port_common.h"
 #include "mcdi_pcol.h"
@@ -981,12 +982,14 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
 	efx_pci_remove_main(efx);
 
 	efx_fini_io(efx);
+
+	probe_data = container_of(efx, struct efx_probe_data, efx);
+
 	pci_dbg(efx->pci_dev, "shutdown successful\n");
 
 	efx_fini_devlink_and_unlock(efx);
 	efx_fini_struct(efx);
 	free_netdev(efx->net_dev);
-	probe_data = container_of(efx, struct efx_probe_data, efx);
 	kfree(probe_data);
 };
 
@@ -1190,6 +1193,17 @@ static int efx_pci_probe(struct pci_dev *pci_dev,
 	if (rc)
 		goto fail2;
 
+	/* A successful cxl initialization implies a CXL region created to be
+	 * used for PIO buffers. If there is no CXL support legacy PIO buffers
+	 * defined at specific PCI BAR regions will be used. If there is CXL
+	 * support and the cxl initialization fails, the driver probe fails.
+	 */
+	rc = efx_cxl_init(probe_data);
+	if (rc) {
+		pci_err(pci_dev, "CXL initialization failed with error %d\n", rc);
+		goto fail3;
+	}
+
 	rc = efx_pci_probe_post_io(efx);
 	if (rc) {
 		/* On failure, retry once immediately.
drivers/net/ethernet/sfc/efx_cxl.c new file +50 -0

50 lines not on this page · raw message

drivers/net/ethernet/sfc/efx_cxl.h new file +29 -0
new file mode 100644
index 000000000000..04e46278464d
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/****************************************************************************
+ * Driver for AMD network controllers and boards
+ * Copyright (C) 2025, Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+
+#ifndef EFX_CXL_H
+#define EFX_CXL_H
+
+#ifdef CONFIG_SFC_CXL
+
+#include <cxl/cxl.h>
+
+struct efx_probe_data;
+
+struct efx_cxl {
+	struct cxl_dev_state cxlds;
+	struct cxl_memdev *cxlmd;
+};
+
+int efx_cxl_init(struct efx_probe_data *probe_data);
+#else
+static inline int efx_cxl_init(struct efx_probe_data *probe_data) { return 0; }
+#endif
+#endif
drivers/net/ethernet/sfc/net_driver.h +8 -0
index b98c259f672d..563e6a6e85f1 100644
@@ -1197,14 +1197,22 @@ struct efx_nic {
 	atomic_t n_rx_noskb_drops;
 };
 
+#ifdef CONFIG_SFC_CXL
+struct efx_cxl;
+#endif
+
 /**
  * struct efx_probe_data - State after hardware probe
  * @pci_dev: The PCI device
  * @efx: Efx NIC details
+ * @cxl: details of related cxl objects
  */
 struct efx_probe_data {
 	struct pci_dev *pci_dev;
 	struct efx_nic efx;
+#ifdef CONFIG_SFC_CXL
+	struct efx_cxl *cxl;
+#endif
 };
 
 static inline struct efx_nic *efx_netdev_priv(struct net_device *dev)
Signature · 1 line
2.34.1
#2 lore raw

PATCH v31 2/5 sfc: Map cxl regs

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

Use cxl core functions for discovering and mapping CXL device registers.

---
 drivers/net/ethernet/sfc/efx_cxl.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/net/ethernet/sfc/efx_cxl.c +26 -0
index be252af972ab..704b0ebae937 100644
@@ -7,6 +7,8 @@
 
 #include <linux/pci.h>
 
+#include <cxl/cxl.h>
+#include <cxl/pci.h>
 #include "net_driver.h"
 #include "efx_cxl.h"
 
@@ -18,6 +20,7 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 	struct pci_dev *pci_dev = efx->pci_dev;
 	struct efx_cxl *cxl;
 	u16 dvsec;
+	int rc;
 
 	/* Is the device configured with and using CXL? */
 	if (!pcie_is_cxl(pci_dev))
@@ -42,6 +45,29 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 	if (!cxl)
 		return -ENOMEM;
 
+	rc = cxl_pci_setup_regs(pci_dev, CXL_REGLOC_RBI_COMPONENT,
+				&cxl->cxlds.reg_map);
+	if (rc) {
+		pci_err(pci_dev, "No component registers\n");
+		return rc;
+	}
+
+	if (!cxl->cxlds.reg_map.component_map.hdm_decoder.valid) {
+		pci_err(pci_dev, "Expected HDM component register not found\n");
+		return -ENODEV;
+	}
+
+	if (!cxl->cxlds.reg_map.component_map.ras.valid) {
+		pci_err(pci_dev, "Expected RAS component register not found\n");
+		return -ENODEV;
+	}
+
+	/* Set media ready explicitly as there are neither mailbox for checking
+	 * this state nor the CXL register involved, both not mandatory for
+	 * type2.
+	 */
+	cxl->cxlds.media_ready = true;
+
 	probe_data->cxl = cxl;
 
 	return 0;
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v31 2/5] sfc: Map cxl regs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The commit adds `#include <cxl/pci.h>`, but `include/cxl/pci.h` does not exist in the kernel tree…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit adds #include <cxl/pci.h>, but include/cxl/pci.h does not exist in the kernel tree, resulting in a fatal compilation error. --

commit fd1792aaa5cf6782d5137f23ed3db63b260303d5
Author: Alejandro Lucero <[email protected]>

sfc: Map cxl regs

This commit introduces CXL core functions to the SFC driver for discovering and mapping CXL device registers. It sets up the component registers and verifies the presence of HDM and RAS capabilities.

drivers/net/ethernet/sfc/efx_cxl.c line 11

Quoted 10 lines
drivers/net/ethernet/sfc/efx_cxl.c +2 -0
index be252af972ab3..704b0ebae9374 100644
@@ -7,6 +7,8 @@
 
 #include <linux/pci.h>
 
+#include <cxl/cxl.h>
+#include <cxl/pci.h>

[Severity: Low]
Is this the correct header path? The cxl/pci.h file doesn't appear to exist in the kernel tree. The cxl_pci_setup_regs() function and the CXL_REGLOC_RBI_COMPONENT enum seem to be defined in drivers/cxl/cxlpci.h, which is internal to the CXL subsystem and not exposed to other drivers. Will this cause a build failure when compiling the sfc driver?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/sfc/efx_cxl.c +2 -0
@@ -42,6 +45,29 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 	if (!cxl)
 		return -ENOMEM;
 
+	rc = cxl_pci_setup_regs(pci_dev, CXL_REGLOC_RBI_COMPONENT,
+				&cxl->cxlds.reg_map);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

PATCH v31 3/5 sfc: Initialize cxl dpa

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

Use cxl_set_capacity() for DPA initialization as no mailbox is available.

---
 drivers/net/ethernet/sfc/efx_cxl.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
index 704b0ebae937..18b535b3ea40 100644
@@ -68,6 +68,11 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 	 */
 	cxl->cxlds.media_ready = true;
 
+	if (cxl_set_capacity(&cxl->cxlds, EFX_CTPIO_BUFFER_SIZE)) {
+		pci_err(pci_dev, "dpa capacity setup failed\n");
+		return -ENODEV;
+	}
+
 	probe_data->cxl = cxl;
 
 	return 0;
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v31 3/5] sfc: Initialize cxl dpa

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The patch adds a call to an undefined function `cxl_set_capacity()`, which will cause a build…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The patch adds a call to an undefined function cxl_set_capacity(), which will cause a build failure.
- [Low] The file includes <cxl/pci.h> which does not exist in the source tree, causing a build failure. --

commit 658adf5bd8fde62f9bb534a3960bfeef69a61055
Author: Alejandro Lucero <[email protected]>

sfc: Initialize cxl dpa

Use cxl_set_capacity() for DPA initialization as no mailbox is available.

drivers/net/ethernet/sfc/efx_cxl.c int efx_cxl_init(struct efx_probe_data *probe_data) · line 71

Quoted 9 lines
drivers/net/ethernet/sfc/efx_cxl.c +1 -0
index 704b0ebae9374..18b535b3ea405 100644
@@ -68,6 +68,11 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 	 */
 	cxl->cxlds.media_ready = true;
 
+	if (cxl_set_capacity(&cxl->cxlds, EFX_CTPIO_BUFFER_SIZE)) {

[Severity: Low]
Are we calling an undefined function here? cxl_set_capacity() is neither declared nor defined anywhere in the kernel source tree, which causes a build failure.

drivers/net/ethernet/sfc/efx_cxl.c int efx_cxl_init(struct efx_probe_data *probe_data) · line 78

Quoted 7 lines
drivers/net/ethernet/sfc/efx_cxl.c +4 -0
+		pci_err(pci_dev, "dpa capacity setup failed\n");
+		return -ENODEV;
+	}
+
 	probe_data->cxl = cxl;
 
 	return 0;

[Severity: Low]
Is there a missing header file in this file? It includes <cxl/pci.h> which does not exist in the kernel tree, causing a fatal compilation error:

drivers/net/ethernet/sfc/efx_cxl.c:

    ...
    #include <linux/pci.h>

    #include <cxl/cxl.h>
    #include <cxl/pci.h>
    #include "net_driver.h"
    ...
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#6 lore raw

PATCH v31 4/5 sfc: obtain and map cxl range using devm_cxl_probe_mem

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

Use core API for safely obtain the CXL range linked to an HDM committed by the BIOS. Map such a range for being used as the ctpio buffer.

A potential user space action through sysfs unbinding or core cxl modules remove will trigger sfc driver device detachment, with that case not racing with this mapping as this is done during driver probe and therefore protected with device lock against those user space actions.

---
 drivers/net/ethernet/sfc/efx.c     |  2 ++
 drivers/net/ethernet/sfc/efx_cxl.c | 23 +++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
 3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +2 -0
index 61cbb6cfc360..3806cd3dd7f4 100644
@@ -984,6 +984,7 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
 	efx_fini_io(efx);
 
 	probe_data = container_of(efx, struct efx_probe_data, efx);
+	efx_cxl_exit(probe_data);
 
 	pci_dbg(efx->pci_dev, "shutdown successful\n");
 
@@ -1242,6 +1243,7 @@ static int efx_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
  fail3:
+	efx_cxl_exit(probe_data);
 	efx_fini_io(efx);
  fail2:
 	efx_fini_struct(efx);
drivers/net/ethernet/sfc/efx_cxl.c +23 -0
index 18b535b3ea40..3e7c950f83e9 100644
@@ -18,6 +18,7 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 {
 	struct efx_nic *efx = &probe_data->efx;
 	struct pci_dev *pci_dev = efx->pci_dev;
+	struct range cxl_pio_range;
 	struct efx_cxl *cxl;
 	u16 dvsec;
 	int rc;
@@ -73,9 +74,31 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 		return -ENODEV;
 	}
 
+	cxl->cxlmd = devm_cxl_probe_mem(&cxl->cxlds, &cxl_pio_range);
+	if (IS_ERR(cxl->cxlmd)) {
+		pci_err(pci_dev, "CXL accel memdev creation failed\n");
+		return PTR_ERR(cxl->cxlmd);
+	}
+
+	cxl->ctpio_cxl = ioremap_wc(cxl_pio_range.start,
+				    range_len(&cxl_pio_range));
+	if (!cxl->ctpio_cxl) {
+		pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+			&cxl_pio_range);
+		return -ENOMEM;
+	}
+
 	probe_data->cxl = cxl;
 
 	return 0;
 }
 
+void efx_cxl_exit(struct efx_probe_data *probe_data)
+{
+	if (!probe_data->cxl)
+		return;
+
+	iounmap(probe_data->cxl->ctpio_cxl);
+}
+
 MODULE_IMPORT_NS("CXL");
drivers/net/ethernet/sfc/efx_cxl.h +3 -0
index 04e46278464d..3e2705cb063f 100644
@@ -20,10 +20,13 @@ struct efx_probe_data;
 struct efx_cxl {
 	struct cxl_dev_state cxlds;
 	struct cxl_memdev *cxlmd;
+	void __iomem *ctpio_cxl;
 };
 
 int efx_cxl_init(struct efx_probe_data *probe_data);
+void efx_cxl_exit(struct efx_probe_data *probe_data);
 #else
 static inline int efx_cxl_init(struct efx_probe_data *probe_data) { return 0; }
+static inline void efx_cxl_exit(struct efx_probe_data *probe_data) {}
 #endif
 #endif
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v31 4/5] sfc: obtain and map cxl range using devm_cxl_probe_mem

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Inverted teardown order unmaps write-combining memory and cleans up devm CXL resources after the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Inverted teardown order unmaps write-combining memory and cleans up devm CXL resources after the PCI device is disabled. --

commit 8a6ea64dcd83c4ec06b3116375770f0f9dce6ca6
Author: Alejandro Lucero <[email protected]>
Subject: sfc: obtain and map cxl range using devm_cxl_probe_mem

This commit uses the core CXL API to safely obtain and map the CXL range linked to an HDM committed by the BIOS. The mapped range is used as the ctpio buffer.

drivers/net/ethernet/sfc/efx.c static void efx_pci_remove(struct pci_dev *pci_dev) · line 987

Quoted 9 lines
drivers/net/ethernet/sfc/efx.c +1 -0
index 61cbb6cfc3602..3806cd3dd7f48 100644
@@ -984,6 +984,7 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
 	efx_fini_io(efx);
 
 	probe_data = container_of(efx, struct efx_probe_data, efx);
+	efx_cxl_exit(probe_data);

[Severity: High]
Does this sequence unmap the Write-Combining memory after the PCI device is disabled?

In efx_pci_remove(), efx_fini_io() is called first, which calls pci_disable_device(). Then efx_cxl_exit() calls iounmap() on the ctpio_cxl mapping.

If a CPU write-combining buffer flush occurs during iounmap() on a disabled device, could it trigger a fatal PCIe error (Master Abort) and a kernel panic?

Also, since devm_cxl_probe_mem() and devm_cxl_dev_state_create() are used during initialization, devres will clean up these resources after efx_pci_remove() returns. Does this mean the devm cleanup also accesses the device after it has been disabled?

Quoted 3 lines
drivers/net/ethernet/sfc/efx.c +0 -0
 	pci_dbg(efx->pci_dev, "shutdown successful\n");
 

[ ... ]

drivers/net/ethernet/sfc/efx.c static int efx_pci_probe(struct pci_dev *pci_dev, · line 1247

Quoted 6 lines
drivers/net/ethernet/sfc/efx.c +1 -0
@@ -1242,6 +1243,7 @@ static int efx_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
  fail3:
+	efx_cxl_exit(probe_data);
 	efx_fini_io(efx);

[Severity: High]
Does this error path cause devm-managed CXL resources to be cleaned up on a disabled device?

While efx_cxl_exit() correctly unmaps the region before efx_fini_io() disables the device here, the devm-managed resources (like the CXL accel memdev) will be destroyed by devres after efx_pci_probe() returns.

By the time devres runs, efx_fini_io() has already called pci_disable_device(), so the devm cleanup will happen with the PCI device already disabled.

Quoted 2 lines
drivers/net/ethernet/sfc/efx.c +0 -0
  fail2:
 	efx_fini_struct(efx);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#8 lore raw

PATCH v31 5/5 sfc: support pio mapping based on cxl

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

A PIO buffer is a region of device memory to which the driver can write a packet for TX, with the device handling the transmit doorbell without requiring a DMA for getting the packet data, which helps reducing latency in certain exchanges. With CXL mem protocol this latency can be lowered further.

With a device supporting CXL and successfully initialised, use the cxl region to map the memory range and use this mapping for PIO buffers.

---
 drivers/net/ethernet/sfc/ef10.c       | 41 ++++++++++++++++++++++-----
 drivers/net/ethernet/sfc/efx_cxl.c    |  1 +
 drivers/net/ethernet/sfc/net_driver.h |  2 ++
 drivers/net/ethernet/sfc/nic.h        |  3 ++
 4 files changed, 40 insertions(+), 7 deletions(-)
drivers/net/ethernet/sfc/ef10.c +34 -7
index 7e04f115bbaa..73bc064929f6 100644
@@ -24,6 +24,7 @@
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 #include <net/udp_tunnel.h>
+#include "efx_cxl.h"
 
 /* Hardware control for EF10 architecture including 'Huntington'. */
 
@@ -106,7 +107,7 @@ static int efx_ef10_get_vf_index(struct efx_nic *efx)
 
 static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
 {
-	MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
+	MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V7_OUT_LEN);
 	struct efx_ef10_nic_data *nic_data = efx->nic_data;
 	size_t outlen;
 	int rc;
@@ -177,6 +178,12 @@ static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
 			  efx->num_mac_stats);
 	}
 
+	if (outlen < MC_CMD_GET_CAPABILITIES_V7_OUT_LEN)
+		nic_data->datapath_caps3 = 0;
+	else
+		nic_data->datapath_caps3 = MCDI_DWORD(outbuf,
+						      GET_CAPABILITIES_V7_OUT_FLAGS3);
+
 	return 0;
 }
 
@@ -1140,6 +1147,9 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx)
 	unsigned int channel_vis, pio_write_vi_base, max_vis;
 	struct efx_ef10_nic_data *nic_data = efx->nic_data;
 	unsigned int uc_mem_map_size, wc_mem_map_size;
+#ifdef CONFIG_SFC_CXL
+	struct efx_probe_data *probe_data;
+#endif
 	void __iomem *membase;
 	int rc;
 
@@ -1263,8 +1273,23 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx)
 	iounmap(efx->membase);
 	efx->membase = membase;
 
-	/* Set up the WC mapping if needed */
-	if (wc_mem_map_size) {
+	if (!wc_mem_map_size)
+		goto skip_pio;
+
+	/* Set up the WC mapping */
+
+#ifdef CONFIG_SFC_CXL
+	probe_data = container_of(efx, struct efx_probe_data, efx);
+	if ((nic_data->datapath_caps3 &
+	    (1 << MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_LBN)) &&
+	    probe_data->cxl_pio_initialised) {
+		/* Using PIO through CXL mapping */
+		nic_data->pio_write_base = probe_data->cxl->ctpio_cxl;
+		nic_data->pio_write_vi_base = pio_write_vi_base;
+	} else
+#endif
+	{
+		/* Using legacy PIO BAR mapping */
 		nic_data->wc_membase = ioremap_wc(efx->membase_phys +
 						  uc_mem_map_size,
 						  wc_mem_map_size);
@@ -1279,12 +1304,14 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx)
 			nic_data->wc_membase +
 			(pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
 			 uc_mem_map_size);
-
-		rc = efx_ef10_link_piobufs(efx);
-		if (rc)
-			efx_ef10_free_piobufs(efx);
 	}
 
+	rc = efx_ef10_link_piobufs(efx);
+	if (rc)
+		efx_ef10_free_piobufs(efx);
+
+skip_pio:
+
 	netif_dbg(efx, probe, efx->net_dev,
 		  "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
 		  &efx->membase_phys, efx->membase, uc_mem_map_size,
drivers/net/ethernet/sfc/efx_cxl.c +1 -0
index 3e7c950f83e9..348d7404cd7a 100644
@@ -88,6 +88,7 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 		return -ENOMEM;
 	}
 
+	probe_data->cxl_pio_initialised = true;
 	probe_data->cxl = cxl;
 
 	return 0;
drivers/net/ethernet/sfc/net_driver.h +2 -0
index 563e6a6e85f1..3964b2c56609 100644
@@ -1206,12 +1206,14 @@ struct efx_cxl;
  * @pci_dev: The PCI device
  * @efx: Efx NIC details
  * @cxl: details of related cxl objects
+ * @cxl_pio_initialised: cxl initialization outcome.
  */
 struct efx_probe_data {
 	struct pci_dev *pci_dev;
 	struct efx_nic efx;
 #ifdef CONFIG_SFC_CXL
 	struct efx_cxl *cxl;
+	bool cxl_pio_initialised;
 #endif
 };
 
drivers/net/ethernet/sfc/nic.h +3 -0
index ec3b2df43b68..7480f9995dfb 100644
@@ -152,6 +152,8 @@ enum {
  *	%MC_CMD_GET_CAPABILITIES response)
  * @datapath_caps2: Further Capabilities of datapath firmware (FLAGS2 field of
  * %MC_CMD_GET_CAPABILITIES response)
+ * @datapath_caps3: Further Capabilities of datapath firmware (FLAGS3 field of
+ * %MC_CMD_GET_CAPABILITIES response)
  * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU
  * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU
  * @must_probe_vswitching: Flag: vswitching has yet to be setup after MC reboot
@@ -187,6 +189,7 @@ struct efx_ef10_nic_data {
 	bool must_check_datapath_caps;
 	u32 datapath_caps;
 	u32 datapath_caps2;
+	u32 datapath_caps3;
 	unsigned int rx_dpcpu_fw_id;
 	unsigned int tx_dpcpu_fw_id;
 	bool must_probe_vswitching;
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v31 5/5] sfc: support pio mapping based on cxl

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Missing VI base and PIO register offsets in CXL PIO mapping, leading to hardware register…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Missing VI base and PIO register offsets in CXL PIO mapping, leading to hardware register corruption --

commit 125e7b168b7494938907570e29acc3c906cb9a0a
Author: Alejandro Lucero <[email protected]>

sfc: support pio mapping based on cxl

This patch adds support for mapping PIO buffers using CXL memory if the device supports it and is successfully initialized. Using CXL for the PIO buffer region can help further reduce latency during TX packet exchanges.

Quoted 4 lines
drivers/net/ethernet/sfc/ef10.c +0 -0
index 7e04f115bbaaa..73bc064929f63 100644

[ ... ]

Quoted 8 lines
drivers/net/ethernet/sfc/ef10.c +2 -2
@@ -1263,8 +1273,23 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx)
 	iounmap(efx->membase);
 	efx->membase = membase;
 
-	/* Set up the WC mapping if needed */
-	if (wc_mem_map_size) {
+	if (!wc_mem_map_size)
+		goto skip_pio;

drivers/net/ethernet/sfc/ef10.c static int efx_ef10_dimension_resources(struct efx_nic *efx) · line 1287

Quoted 10 lines
drivers/net/ethernet/sfc/ef10.c +10 -0
+
+	/* Set up the WC mapping */
+
+#ifdef CONFIG_SFC_CXL
+	probe_data = container_of(efx, struct efx_probe_data, efx);
+	if ((nic_data->datapath_caps3 &
+	    (1 << MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_LBN)) &&
+	    probe_data->cxl_pio_initialised) {
+		/* Using PIO through CXL mapping */
+		nic_data->pio_write_base = probe_data->cxl->ctpio_cxl;

[Severity: Critical]
Does this assignment miss the required hardware offsets for the VI base and PIO buffer register?

In the legacy PIO BAR mapping path just below, the base is calculated with these offsets:

    pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF - uc_mem_map_size

When efx_ef10_link_piobufs() sets up the TX queue, it computes the pointer using this base:

    tx_queue->piobuf =
        nic_data->pio_write_base +
        index * efx->vi_stride + offset;

Without adding the VI base and PIO register offsets to the CXL mapping, will the calculated pointer target the doorbell registers at offset 0 (e.g., ER_DZ_EVQ_RPTR, ER_DZ_TX_DESC_UPD) instead of the PIO buffers, causing packet data writes to corrupt hardware state?

Quoted 8 lines
drivers/net/ethernet/sfc/ef10.c +5 -0
+		nic_data->pio_write_vi_base = pio_write_vi_base;
+	} else
+#endif
+	{
+		/* Using legacy PIO BAR mapping */
 		nic_data->wc_membase = ioremap_wc(efx->membase_phys +
 						  uc_mem_map_size,
 						  wc_mem_map_size);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5