Skip to contentSkip to conversation

Type2 device basic support

PATCH Superseded [email protected] 4 participants 20 messages Jun 9 – Jun 17

Subsystems (4)

v27 of 31 Superseded Latest is v31 →

lore
Share & tools
lore
#0 lore raw

v27 cover Type2 device basic support

From: Alejandro Lucero <[email protected]>

This version is likely matching better the series tittle than previous ones as:

- this is only supporting a Type2 with an HDM committed by BIOS/firmware.

- No region creation except autodiscovery.

- No interleaving support.

- adding sfc support with the last bits in patch 2 and 3 for the kind of type2 the kernel will support by now.

The series is therefore simpler than previous tries and even simpler after using Dan's patchset for solving the cxl devmen probe problem racing with potential user space actions.

It is patch 4 the one bringing the main change, so the one to focus on for reviewing, but after Dan's work, it is quite trivial and removing a lot of complexity coming with previous versions. Of course, that means that other Dan's series requires more eyes on it.

I hope this is if not the final version, one really close to that ...

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

 drivers/cxl/core/core.h               |   2 +
 drivers/cxl/core/mbox.c               |  51 +-----------
 drivers/cxl/core/memdev.c             |  67 ++++++++++++++++
 drivers/cxl/core/pci.c                |   1 +
 drivers/cxl/core/port.c               |   1 +
 drivers/cxl/core/regs.c               |   1 +
 drivers/cxl/cxlpci.h                  |  12 ---
 drivers/cxl/pci.c                     |   1 +
 drivers/net/ethernet/sfc/Kconfig      |   9 +++
 drivers/net/ethernet/sfc/Makefile     |   1 +
 drivers/net/ethernet/sfc/ef10.c       |  43 +++++++++--
 drivers/net/ethernet/sfc/efx.c        |  15 +++-
 drivers/net/ethernet/sfc/efx.h        |   1 -
 drivers/net/ethernet/sfc/efx_cxl.c    | 107 ++++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h    |  32 ++++++++
 drivers/net/ethernet/sfc/net_driver.h |  12 +++
 drivers/net/ethernet/sfc/nic.h        |   3 +
 include/cxl/cxl.h                     |   2 +
 include/cxl/pci.h                     |  22 ++++++
 19 files changed, 312 insertions(+), 71 deletions(-)
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.c
 create mode 100644 drivers/net/ethernet/sfc/efx_cxl.h
 create mode 100644 include/cxl/pci.h

base-commit: 9b1e70e8f9ec4b5c6ce7fa774a0023bb6894c686

Signature · 1 line
2.34.1
#1 lore raw

PATCH v27 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        | 14 +++++++-
 drivers/net/ethernet/sfc/efx_cxl.c    | 52 +++++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h    | 29 +++++++++++++++
 drivers/net/ethernet/sfc/net_driver.h | 10 ++++++
 6 files changed, 114 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 +13 -1
index 8f136a11d396..90ccbe310386 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,15 @@ 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, or initialization
+	 * fails, cxl_pio_initialised will be false and legacy PIO buffers
+	 * defined at specific PCI BAR regions will be used.
+	 */
+	rc = efx_cxl_init(probe_data);
+	if (rc)
+		pci_err(pci_dev, "CXL initialization failed with error %d\n", rc);
+
 	rc = efx_pci_probe_post_io(efx);
 	if (rc) {
 		/* On failure, retry once immediately.
drivers/net/ethernet/sfc/efx_cxl.c new file +52 -0

52 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 +10 -0
index b98c259f672d..3964b2c56609 100644
@@ -1197,14 +1197,24 @@ 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
+ * @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
 };
 
 static inline struct efx_nic *efx_netdev_priv(struct net_device *dev)
Signature · 1 line
2.34.1
#2 lore raw

PATCH v27 2/5 cxl/sfc: Map cxl regs

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

Export cxl core functions for a Type2 driver being able to discover and map the device registers.

Use it in sfc driver cxl initialization.

---
 drivers/cxl/core/pci.c             |  1 +
 drivers/cxl/core/port.c            |  1 +
 drivers/cxl/core/regs.c            |  1 +
 drivers/cxl/cxlpci.h               | 12 ------------
 drivers/cxl/pci.c                  |  1 +
 drivers/net/ethernet/sfc/efx_cxl.c | 26 ++++++++++++++++++++++++++
 include/cxl/pci.h                  | 22 ++++++++++++++++++++++
 7 files changed, 52 insertions(+), 12 deletions(-)
 create mode 100644 include/cxl/pci.h
drivers/cxl/core/pci.c +1 -0
index d1f487b3d809..2bcd683aa286 100644
@@ -6,6 +6,7 @@
 #include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/pci-doe.h>
+#include <cxl/pci.h>
 #include <linux/aer.h>
 #include <cxlpci.h>
 #include <cxlmem.h>
drivers/cxl/core/port.c +1 -0
index 1215ee4f4035..cb633e19151b 100644
@@ -11,6 +11,7 @@
 #include <linux/idr.h>
 #include <linux/node.h>
 #include <cxl/einj.h>
+#include <cxl/pci.h>
 #include <cxlmem.h>
 #include <cxlpci.h>
 #include <cxl.h>
drivers/cxl/core/regs.c +1 -0
index 93710cf4f0a6..20c2d9fbcfe7 100644
@@ -4,6 +4,7 @@
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
+#include <cxl/pci.h>
 #include <cxlmem.h>
 #include <cxlpci.h>
 #include <pmu.h>
drivers/cxl/cxlpci.h +0 -12
index b826eb53cf7b..110ec9c44f09 100644
@@ -13,16 +13,6 @@
  */
 #define CXL_PCI_DEFAULT_MAX_VECTORS 16
 
-/* Register Block Identifier (RBI) */
-enum cxl_regloc_type {
-	CXL_REGLOC_RBI_EMPTY = 0,
-	CXL_REGLOC_RBI_COMPONENT,
-	CXL_REGLOC_RBI_VIRT,
-	CXL_REGLOC_RBI_MEMDEV,
-	CXL_REGLOC_RBI_PMU,
-	CXL_REGLOC_RBI_TYPES
-};
-
 /*
  * Table Access DOE, CDAT Read Entry Response
  *
@@ -112,6 +102,4 @@ static inline void devm_cxl_port_ras_setup(struct cxl_port *port)
 }
 #endif
 
-int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
-		       struct cxl_register_map *map);
 #endif /* __CXL_PCI_H__ */
drivers/cxl/pci.c +1 -0
index 267c679b0b3c..bb892dbfdd6d 100644
@@ -11,6 +11,7 @@
 #include <linux/pci.h>
 #include <linux/aer.h>
 #include <linux/io.h>
+#include <cxl/pci.h>
 #include <cxl/mailbox.h>
 #include "cxlmem.h"
 #include "cxlpci.h"
drivers/net/ethernet/sfc/efx_cxl.c +26 -0
index b7e8d85a43d3..f88c2b3fbb2c 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;
 
 	probe_data->cxl_pio_initialised = false;
 
@@ -44,6 +47,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;
include/cxl/pci.h new file +22 -0
new file mode 100644
index 000000000000..3e0000015871
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2020 Intel Corporation. All rights reserved. */
+
+#ifndef __CXL_CXL_PCI_H__
+#define __CXL_CXL_PCI_H__
+
+/* Register Block Identifier (RBI) */
+enum cxl_regloc_type {
+	CXL_REGLOC_RBI_EMPTY = 0,
+	CXL_REGLOC_RBI_COMPONENT,
+	CXL_REGLOC_RBI_VIRT,
+	CXL_REGLOC_RBI_MEMDEV,
+	CXL_REGLOC_RBI_PMU,
+	CXL_REGLOC_RBI_TYPES
+};
+
+struct cxl_register_map;
+struct pci_dev;
+
+int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
+		       struct cxl_register_map *map);
+#endif
Signature · 1 line
2.34.1
#3 lore raw

PATCH v27 3/5 cxl/sfc: Initialize dpa without a mailbox

In reply to [email protected]

From: Alejandro Lucero <[email protected]>

Type3 relies on mailbox CXL_MBOX_OP_IDENTIFY command for initializing memdev state params which end up being used for DPA initialization.

Allow a Type2 driver to initialize DPA simply by giving the size of its volatile hardware partition.

Move related functions to memdev.

Add sfc driver as the client.

---
 drivers/cxl/core/core.h            |  2 +
 drivers/cxl/core/mbox.c            | 51 +----------------------
 drivers/cxl/core/memdev.c          | 67 ++++++++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.c |  5 +++
 include/cxl/cxl.h                  |  2 +
 5 files changed, 77 insertions(+), 50 deletions(-)
drivers/cxl/core/core.h +2 -0
index 07555ae63859..f7cebb026552 100644
@@ -101,6 +101,8 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
 struct dentry *cxl_debugfs_create_dir(const char *dir);
 int cxl_dpa_set_part(struct cxl_endpoint_decoder *cxled,
 		     enum cxl_partition_mode mode);
+struct cxl_memdev_state;
+int cxl_mem_get_partition_info(struct cxl_memdev_state *mds);
 int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size);
 int cxl_dpa_free(struct cxl_endpoint_decoder *cxled);
 resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled);
drivers/cxl/core/mbox.c +1 -50

63 lines not on this page · raw message

drivers/cxl/core/memdev.c +67 -0

73 lines not on this page · raw message

drivers/net/ethernet/sfc/efx_cxl.c +5 -0
index f88c2b3fbb2c..4d55c08cf2a1 100644
@@ -70,6 +70,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;
include/cxl/cxl.h +2 -0
index 016c74fb747c..802b143de83d 100644
@@ -226,4 +226,6 @@ struct cxl_dev_state *_devm_cxl_dev_state_create(struct device *dev,
 
 struct cxl_memdev *devm_cxl_probe_mem(struct cxl_dev_state *cxlds,
 				      struct range *range);
+
+int cxl_set_capacity(struct cxl_dev_state *cxlds, u64 capacity);
 #endif /* __CXL_CXL_H__ */
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v27 3/5] cxl/sfc: Initialize dpa without a mailbox

Quoted 9 lines · alejandro.lucero-palau@ wrote:

From: Alejandro Lucero <[email protected]>

Type3 relies on mailbox CXL_MBOX_OP_IDENTIFY command for initializing memdev state params which end up being used for DPA initialization.

Allow a Type2 driver to initialize DPA simply by giving the size of its volatile hardware partition.

Move related functions to memdev.

The code movement is not strictly necessary. Just add cxl_set_capacity() and we can consider a move later if mbox.o and memdev.o are ever not both included in cxl_core.o by default.

Quoted 7 lines

Add sfc driver as the client.

[..]

Quoted 4 lines

+/**
+ * cxl_set_capacity: initialize dpa by a driver without a mailbox.
+ *
++ * @cxlds: pointer to cxl_dev_state

Stray "+"?

#5 lore raw

Re: [PATCH v27 3/5] cxl/sfc: Initialize dpa without a mailbox

Quoted 6 lines · Dan Williams (nvidia)
Quoted 5 lines · alejandro.lucero-palau@ wrote:

From: Alejandro Lucero <[email protected]>

Type3 relies on mailbox CXL_MBOX_OP_IDENTIFY command for initializing memdev state params which end up being used for DPA initialization.

Quoted 7 lines
Quoted 4 lines

Allow a Type2 driver to initialize DPA simply by giving the size of its volatile hardware partition.

Move related functions to memdev.

The code movement is not strictly necessary. Just add cxl_set_capacity() and we can consider a move later if mbox.o and memdev.o are ever not both included in cxl_core.o by default.

I think it is the right thing to do as the new function uses add_part() (moved) and the other add_part() client is the other function moved, cxl_mem_dpa_fetch().

Note cxl_mem_get_partition() used by cxl_mem_dpa_fetch() is the one working with mbox commands and it remains in the same place inside core/mbox.c and the only cxl_mem_dpa_fetch() client is cxl/pci.c

This was reviewed and accepted so no reason for not doing it ...

Quoted 8 lines
Quoted 8 lines

Add sfc driver as the client.

Quoted 6 lines

[..]

Quoted 4 lines

+/**
+ * cxl_set_capacity: initialize dpa by a driver without a mailbox.
+ *
++ * @cxlds: pointer to cxl_dev_state

Stray "+"?

I'll fix it.

Thanks!

#6 lore raw

Re: [PATCH v27 3/5] cxl/sfc: Initialize dpa without a mailbox

Quoted 21 lines · Alejandro Lucero Palau
Quoted 6 lines · Dan Williams (nvidia)
Quoted 5 lines · alejandro.lucero-palau@ wrote:

From: Alejandro Lucero <[email protected]>

Type3 relies on mailbox CXL_MBOX_OP_IDENTIFY command for initializing memdev state params which end up being used for DPA initialization.

Quoted 7 lines
Quoted 4 lines

Allow a Type2 driver to initialize DPA simply by giving the size of its volatile hardware partition.

Move related functions to memdev.

The code movement is not strictly necessary. Just add cxl_set_capacity() and we can consider a move later if mbox.o and memdev.o are ever not both included in cxl_core.o by default.

I think it is the right thing to do as the new function uses add_part() (moved) and the other add_part() client is the other function moved, cxl_mem_dpa_fetch().

Quoted 6 lines

Note cxl_mem_get_partition() used by cxl_mem_dpa_fetch() is the one working with mbox commands and it remains in the same place inside core/mbox.c and the only cxl_mem_dpa_fetch() client is cxl/pci.c

This was reviewed and accepted so no reason for not doing it ...

Sure, I am ok to let it go as is.

#7 lore raw

PATCH v27 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     |  1 +
 drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
 3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
 
drivers/net/ethernet/sfc/efx_cxl.c +24 -0
index 4d55c08cf2a1..d5766a40e2cf 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;
@@ -75,9 +76,32 @@ 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_pio_initialised = true;
 	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
maintainer
#8 lore raw

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

Quoted 43 lines · On 6/9/26 2:57 PM, [email protected] wrote:

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     |  1 +
 drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
 3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
 
drivers/net/ethernet/sfc/efx_cxl.c +1 -0
index 4d55c08cf2a1..d5766a40e2cf 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;
@@ -75,9 +76,32 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
 		return -ENODEV;

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

Quoted 10 lines
drivers/net/ethernet/sfc/efx_cxl.c +8 -0
 	}
 
+	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));

Should this be devm managed? I think the mapping leaks if efx_pci_probe() fails after calling efx_cxl_init().

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

Quoted 7 lines
drivers/net/ethernet/sfc/efx_cxl.c +7 -0
+	if (!cxl->ctpio_cxl) {
+		pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+			&cxl_pio_range);
+		return -ENOMEM;
+	}
+
+	probe_data->cxl_pio_initialised = true;

Should this change be moved to the follow on patch that uses it?

DJ

Quoted 32 lines
drivers/net/ethernet/sfc/efx_cxl.c +8 -0
 	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
#9 lore raw

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

Quoted 47 lines · Dave Jiang
Quoted 45 lines · On 6/9/26 2:57 PM, [email protected] wrote:

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     |  1 +
  drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
  drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
  3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
 
drivers/net/ethernet/sfc/efx_cxl.c +1 -0
index 4d55c08cf2a1..d5766a40e2cf 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;
@@ -75,9 +76,32 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
  		return -ENODEV;
  	}
 
Quoted 10 lines

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

Quoted 8 lines
drivers/net/ethernet/sfc/efx_cxl.c +8 -0
+	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));

Should this be devm managed? I think the mapping leaks if efx_pci_probe() fails after calling efx_cxl_init().

No devm under netdev ... but you are right about the leak. I need to add a call to efx_cxl_exit inside the error path in the caller.

Quoted 8 lines

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

Quoted 7 lines
drivers/net/ethernet/sfc/efx_cxl.c +7 -0
+	if (!cxl->ctpio_cxl) {
+		pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+			&cxl_pio_range);
+		return -ENOMEM;
+	}
+
+	probe_data->cxl_pio_initialised = true;

Should this change be moved to the follow on patch that uses it?

I can do that.

Thanks!

Quoted 33 lines

DJ

Quoted 32 lines
drivers/net/ethernet/sfc/efx_cxl.c +8 -0
  	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
#10 lore raw

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

In reply to [email protected]
Quoted 47 lines · alejandro.lucero-palau@ wrote:

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     |  1 +
 drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
 3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
 
drivers/net/ethernet/sfc/efx_cxl.c +3 -0
index 4d55c08cf2a1..d5766a40e2cf 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;
@@ -75,9 +76,32 @@ 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)) {

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

Quoted 10 lines
drivers/net/ethernet/sfc/efx_cxl.c +10 -0
+		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;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Minor since something else is likely to fail if ioremap is not reliable.

Otherwise this looks good and with those fixed up the Reviewed-by still stands.

#11 lore raw

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

Quoted 46 lines · Dan Williams (nvidia)
Quoted 45 lines · alejandro.lucero-palau@ wrote:

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     |  1 +
  drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
  drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
  3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
 
drivers/net/ethernet/sfc/efx_cxl.c +1 -0
index 4d55c08cf2a1..d5766a40e2cf 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;
@@ -75,9 +76,32 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
  		return -ENODEV;
  	}
 
Quoted 15 lines

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

Quoted 12 lines
drivers/net/ethernet/sfc/efx_cxl.c +12 -0
+	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;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

I will do that.

Quoted 4 lines

Minor since something else is likely to fail if ioremap is not reliable.

Otherwise this looks good and with those fixed up the Reviewed-by still stands.

No Reviewed-by yet ... this is a new patch after your series removing previous functionality.

Thanks

#12 lore raw

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

Quoted 61 lines · Alejandro Lucero Palau
Quoted 49 lines · Dan Williams (nvidia)
Quoted 48 lines · alejandro.lucero-palau@ wrote:

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     |  1 + drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.h |  3 +++

  3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");

  diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 4d55c08cf2a1..d5766a40e2cf 100644

drivers/net/ethernet/sfc/efx_cxl.c +7 -0
@@ -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;
@@ -75,9 +76,32 @@ 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,
Quoted 8 lines

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

Quoted 5 lines
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
+                    range_len(&cxl_pio_range));
+    if (!cxl->ctpio_cxl) {
+        pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+            &cxl_pio_range);
+        return -ENOMEM;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Quoted 2 lines

I will do that.

Looking at this issue, I think an error when creating the memdev or during the region attach triggers the memdev removal, but ...

Quoted 2 lines
Quoted 2 lines

Minor since something else is likely to fail if ioremap is not reliable.

.. if we want to specifically do that with an unlikely (but possible) ioremap error something else needs to be exported like cxl_memdev_unregister(). Are you happy with that approach?

Quoted 10 lines
Quoted 3 lines

Otherwise this looks good and with those fixed up the Reviewed-by still stands.

No Reviewed-by yet ... this is a new patch after your series removing previous functionality.

Thanks

#13 lore raw

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

Quoted 67 lines · Alejandro Lucero Palau
Quoted 62 lines · Alejandro Lucero Palau
Quoted 50 lines · Dan Williams (nvidia)
Quoted 49 lines · alejandro.lucero-palau@ wrote:

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     |  1 + drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.h |  3 +++

  3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");

  diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 4d55c08cf2a1..d5766a40e2cf 100644

drivers/net/ethernet/sfc/efx_cxl.c +7 -0
@@ -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;
@@ -75,9 +76,32 @@ 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,
Quoted 8 lines

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

Quoted 5 lines
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
+                    range_len(&cxl_pio_range));
+    if (!cxl->ctpio_cxl) {
+        pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+            &cxl_pio_range);
+        return -ENOMEM;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Quoted 2 lines

I will do that.

Quoted 9 lines

Looking at this issue, I think an error when creating the memdev or during the region attach triggers the memdev removal, but ...

Quoted 2 lines
Quoted 2 lines

Minor since something else is likely to fail if ioremap is not reliable.

.. if we want to specifically do that with an unlikely (but possible) ioremap error something else needs to be exported like cxl_memdev_unregister(). Are you happy with that approach?

I have just tested with this:

+void cxl_memdev_remove(void *_cxlmd)
+{
+       struct cxl_memdev *cxlmd = _cxlmd;
+       struct device *dev = &cxlmd->dev;
+
+       devm_remove_action_nowarn(cxlmd->cxlds->dev, cxl_memdev_unregister, +                                 cxlmd);
+
+       cdev_device_del(&cxlmd->cdev, dev);
+       cxl_memdev_shutdown(dev);
+       put_device(dev);
+}
+EXPORT_SYMBOL_NS_GPL(cxl_memdev_remove, "CXL");

only called if the ioremap fails.

Please, let me know if you like this approach before sending another version.

Thank you

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Otherwise this looks good and with those fixed up the Reviewed-by still stands.

No Reviewed-by yet ... this is a new patch after your series removing previous functionality.

Thanks

#14 lore raw

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

Quoted 104 lines · Alejandro Lucero Palau
Quoted 76 lines · Alejandro Lucero Palau
Quoted 66 lines · Alejandro Lucero Palau
Quoted 54 lines · Dan Williams (nvidia)
Quoted 53 lines · alejandro.lucero-palau@ wrote:

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     |  1 + drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.h |  3 +++

  3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");

  diff --git a/drivers/net/ethernet/sfc/efx_cxl.c
b/drivers/net/ethernet/sfc/efx_cxl.c
index 4d55c08cf2a1..d5766a40e2cf 100644

drivers/net/ethernet/sfc/efx_cxl.c +7 -0
@@ -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;
@@ -75,9 +76,32 @@ 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,
Quoted 8 lines

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

Quoted 5 lines
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
+                    range_len(&cxl_pio_range));
+    if (!cxl->ctpio_cxl) {
+        pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+            &cxl_pio_range);
+        return -ENOMEM;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Quoted 2 lines

I will do that.

Looking at this issue, I think an error when creating the memdev or during the region attach triggers the memdev removal, but ...

Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Minor since something else is likely to fail if ioremap is not reliable.

.. if we want to specifically do that with an unlikely (but possible) ioremap error something else needs to be exported like cxl_memdev_unregister(). Are you happy with that approach?

I have just tested with this:

(quoted diff) +13 -0
+void cxl_memdev_remove(void *_cxlmd)
+{
+       struct cxl_memdev *cxlmd = _cxlmd;
+       struct device *dev = &cxlmd->dev;
+
+       devm_remove_action_nowarn(cxlmd->cxlds->dev, cxl_memdev_unregister,
+                                 cxlmd);
+
+       cdev_device_del(&cxlmd->cdev, dev);
+       cxl_memdev_shutdown(dev);
+       put_device(dev);
+}
+EXPORT_SYMBOL_NS_GPL(cxl_memdev_remove, "CXL");
Quoted 5 lines

only called if the ioremap fails.

Please, let me know if you like this approach before sending another version.

A devres group can automatically cleanup after devm_cxl_memdev_probe() in the error path with no new exports needed from the CXL core. Something like:

        void *group = devres_open_group(cxl->cxlds.dev, NULL, GFP_KERNEL);
        int rc = 0;

        if (!group)
                return -ENOMEM;
        
        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");
                rc = PTR_ERR(cxl->cxlmd);
                goto out;
        }

        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);
                rc = -ENOMEM;
        }

out:

        if (rc)
                devres_release_group(group);
        else
                devres_remove_group(group);
        return rc;
#15 lore raw

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

Quoted 127 lines · Dan Williams (nvidia)
Quoted 96 lines · Alejandro Lucero Palau
Quoted 71 lines · Alejandro Lucero Palau
Quoted 64 lines · Alejandro Lucero Palau
Quoted 54 lines · Dan Williams (nvidia)
Quoted 53 lines · alejandro.lucero-palau@ wrote:

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     |  1 +
   drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++
   drivers/net/ethernet/sfc/efx_cxl.h |  3 +++
   3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");
   diff --git a/drivers/net/ethernet/sfc/efx_cxl.c

b/drivers/net/ethernet/sfc/efx_cxl.c
index 4d55c08cf2a1..d5766a40e2cf 100644

drivers/net/ethernet/sfc/efx_cxl.c +7 -0
@@ -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;
@@ -75,9 +76,32 @@ 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,
Quoted 8 lines

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

Quoted 5 lines
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
+                    range_len(&cxl_pio_range));
+    if (!cxl->ctpio_cxl) {
+        pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+            &cxl_pio_range);
+        return -ENOMEM;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Quoted 2 lines

I will do that.

Looking at this issue, I think an error when creating the memdev or during the region attach triggers the memdev removal, but ...

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Minor since something else is likely to fail if ioremap is not reliable.

.. if we want to specifically do that with an unlikely (but possible) ioremap error something else needs to be exported like cxl_memdev_unregister(). Are you happy with that approach?

I have just tested with this:

(quoted diff) +13 -0
+void cxl_memdev_remove(void *_cxlmd)
+{
+       struct cxl_memdev *cxlmd = _cxlmd;
+       struct device *dev = &cxlmd->dev;
+
+       devm_remove_action_nowarn(cxlmd->cxlds->dev, cxl_memdev_unregister,
+                                 cxlmd);
+
+       cdev_device_del(&cxlmd->cdev, dev);
+       cxl_memdev_shutdown(dev);
+       put_device(dev);
+}
+EXPORT_SYMBOL_NS_GPL(cxl_memdev_remove, "CXL");
Quoted 5 lines

only called if the ioremap fails.

Please, let me know if you like this approach before sending another version.

A devres group can automatically cleanup after devm_cxl_memdev_probe() in the error path with no new exports needed from the CXL core. Something like:

         void *group = devres_open_group(cxl->cxlds.dev, NULL, GFP_KERNEL);
         int rc = 0;

         if (!group)
                 return -ENOMEM;
         
         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");
                 rc = PTR_ERR(cxl->cxlmd);
                 goto out;
         }

         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);
                 rc = -ENOMEM;
         }
Quoted 6 lines

out:

         if (rc)
                 devres_release_group(group);
         else
                 devres_remove_group(group);
         return rc;

OK. I will use this in v28 instead of that export.

Thanks

#16 lore raw

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

Quoted 139 lines · Alejandro Lucero Palau
Quoted 129 lines · Dan Williams (nvidia)
Quoted 99 lines · Alejandro Lucero Palau
Quoted 73 lines · Alejandro Lucero Palau
Quoted 66 lines · Alejandro Lucero Palau
Quoted 56 lines · Dan Williams (nvidia)
Quoted 55 lines · alejandro.lucero-palau@ wrote:

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     |  1 + drivers/net/ethernet/sfc/efx_cxl.c | 24 ++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.h |  3 +++

   3 files changed, 28 insertions(+)
drivers/net/ethernet/sfc/efx.c +1 -0
index 90ccbe310386..578054c21e79 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");

   diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c
index 4d55c08cf2a1..d5766a40e2cf 100644

drivers/net/ethernet/sfc/efx_cxl.c +1 -0
@@ -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;

drivers/net/ethernet/sfc/efx_cxl.c +6 -0
@@ -75,9 +76,32 @@ 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,
Quoted 8 lines

drivers/net/ethernet/sfc/efx_cxl.c int efx_cxl_init(struct efx_probe_data · line 90

Quoted 5 lines
drivers/net/ethernet/sfc/efx_cxl.c +5 -0
+                    range_len(&cxl_pio_range));
+    if (!cxl->ctpio_cxl) {
+        pci_err(pci_dev, "CXL ioremap region (%pra) failed\n",
+            &cxl_pio_range);
+        return -ENOMEM;

Dave caught the iounmap leak, but another concern is since you want to continue operation if efx_cxl_init() fails then you probably also want to release the successful attachment to the CXL domain if this happens.

Quoted 2 lines

I will do that.

Looking at this issue, I think an error when creating the memdev or during the region attach triggers the memdev removal, but ...

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Minor since something else is likely to fail if ioremap is not reliable.

.. if we want to specifically do that with an unlikely (but possible) ioremap error something else needs to be exported like cxl_memdev_unregister(). Are you happy with that approach?

I have just tested with this:

(quoted diff) +6 -0
+void cxl_memdev_remove(void *_cxlmd)
+{
+       struct cxl_memdev *cxlmd = _cxlmd;
+       struct device *dev = &cxlmd->dev;
+
+       devm_remove_action_nowarn(cxlmd->cxlds->dev, 

cxl_memdev_unregister,
+                                 cxlmd);

(quoted diff) +6 -0
+
+       cdev_device_del(&cxlmd->cdev, dev);
+       cxl_memdev_shutdown(dev);
+       put_device(dev);
+}
+EXPORT_SYMBOL_NS_GPL(cxl_memdev_remove, "CXL");
Quoted 5 lines

only called if the ioremap fails.

Please, let me know if you like this approach before sending another version.

A devres group can automatically cleanup after devm_cxl_memdev_probe() in the error path with no new exports needed from the CXL core. Something like:

         void *group = devres_open_group(cxl->cxlds.dev, NULL, GFP_KERNEL); int rc = 0;

         if (!group)
                 return -ENOMEM;
                  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"); rc = PTR_ERR(cxl->cxlmd);
                 goto out;
         }

         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);
                 rc = -ENOMEM;
         }

Quoted 6 lines

out:
         if (rc)
                 devres_release_group(group);
         else
                 devres_remove_group(group);
         return rc;

Quoted 2 lines

OK. I will use this in v28 instead of that export.

Adding this implies the full driver is detached from the device. The same can be obtained changing the check of efx_cxl_init() call and make the probe to fail if an error is returned.

I prefer to do this after discussing this internally. After all, if CXL.mem is there and the related initialization fails, this is not expected and it should be fixed.

Sending v28 shortly.

Quoted 3 lines

Thanks

#17 lore raw

PATCH v27 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.

Add the disabling of those CXL-based PIO buffers if the callback for potential cxl endpoint removal by the CXL core happens.

---
 drivers/net/ethernet/sfc/ef10.c       | 43 ++++++++++++++++++++++-----
 drivers/net/ethernet/sfc/efx.h        |  1 -
 drivers/net/ethernet/sfc/net_driver.h |  2 ++
 drivers/net/ethernet/sfc/nic.h        |  3 ++
 4 files changed, 41 insertions(+), 8 deletions(-)
drivers/net/ethernet/sfc/ef10.c +36 -7
index 7e04f115bbaa..b747411ffdd3 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,25 @@ 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;
+
+		probe_data->cxl_pio_in_use = true;
+	} 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 +1306,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.h +0 -1
index 45e191686625..057d30090894 100644
@@ -236,5 +236,4 @@ static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
 
 int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
 		       bool flush);
-
 #endif /* EFX_EFX_H */
drivers/net/ethernet/sfc/net_driver.h +2 -0
index 3964b2c56609..bea4eecdf842 100644
@@ -1207,6 +1207,7 @@ struct efx_cxl;
  * @efx: Efx NIC details
  * @cxl: details of related cxl objects
  * @cxl_pio_initialised: cxl initialization outcome.
+ * @cxl_pio_in_use: PIO using CXL mapping
  */
 struct efx_probe_data {
 	struct pci_dev *pci_dev;
@@ -1214,6 +1215,7 @@ struct efx_probe_data {
 #ifdef CONFIG_SFC_CXL
 	struct efx_cxl *cxl;
 	bool cxl_pio_initialised;
+	bool cxl_pio_in_use;
 #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
maintainer
#18 lore raw

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

Quoted 8 lines · On 6/9/26 2:57 PM, [email protected] wrote:

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.

Quoted 5 lines

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

Add the disabling of those CXL-based PIO buffers if the callback for potential cxl endpoint removal by the CXL core happens.

^ This seems to be missing?

Quoted 64 lines
---
 drivers/net/ethernet/sfc/ef10.c       | 43 ++++++++++++++++++++++-----
 drivers/net/ethernet/sfc/efx.h        |  1 -
 drivers/net/ethernet/sfc/net_driver.h |  2 ++
 drivers/net/ethernet/sfc/nic.h        |  3 ++
 4 files changed, 41 insertions(+), 8 deletions(-)
drivers/net/ethernet/sfc/ef10.c +16 -3
index 7e04f115bbaa..b747411ffdd3 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,25 @@ 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 */
+

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

Quoted 10 lines
drivers/net/ethernet/sfc/ef10.c +10 -0
+#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;
+
+		probe_data->cxl_pio_in_use = true;

Don't think this is used anywhere.

DJ

Quoted 77 lines
drivers/net/ethernet/sfc/ef10.c +10 -4
+	} 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 +1306,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.h +0 -1
index 45e191686625..057d30090894 100644
@@ -236,5 +236,4 @@ static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
 
 int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
 		       bool flush);
-
 #endif /* EFX_EFX_H */
drivers/net/ethernet/sfc/net_driver.h +2 -0
index 3964b2c56609..bea4eecdf842 100644
@@ -1207,6 +1207,7 @@ struct efx_cxl;
  * @efx: Efx NIC details
  * @cxl: details of related cxl objects
  * @cxl_pio_initialised: cxl initialization outcome.
+ * @cxl_pio_in_use: PIO using CXL mapping
  */
 struct efx_probe_data {
 	struct pci_dev *pci_dev;
@@ -1214,6 +1215,7 @@ struct efx_probe_data {
 #ifdef CONFIG_SFC_CXL
 	struct efx_cxl *cxl;
 	bool cxl_pio_initialised;
+	bool cxl_pio_in_use;
 #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;
#19 lore raw

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

Quoted 10 lines · Dave Jiang
Quoted 8 lines · On 6/9/26 2:57 PM, [email protected] wrote:

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.

Quoted 6 lines
Quoted 5 lines

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

Add the disabling of those CXL-based PIO buffers if the callback for potential cxl endpoint removal by the CXL core happens.

^ This seems to be missing?

Yes, this comes from v26. That is not happening anymore and I forgot to remove the reference.

<snip>

Quoted 14 lines

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

Quoted 12 lines
drivers/net/ethernet/sfc/ef10.c +12 -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;
+		nic_data->pio_write_vi_base = pio_write_vi_base;
+
+		probe_data->cxl_pio_in_use = true;

Don't think this is used anywhere.

Quoted 1 line

DJ

Right again and same reason: this is not needed anymore.

I will fix it.

Thanks!

<snip>