* [PATCH net-next 1/3] cxgb4: support the enable_rdma devlink param in runtime cmode
2026-11-30 22:09 [PATCH net-next 0/3] devlink: support the enable_rdma param in runtime cmode for cxgb4, mlx5 and ice Stefan Metzmacher
@ 2026-11-30 22:09 ` Stefan Metzmacher
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Metzmacher @ 2026-11-30 22:09 UTC (permalink / raw)
To: netdev
Cc: metze, Potnuri Bharat Teja, Jason Gunthorpe, Leon Romanovsky,
linux-rdma, linux-kernel, Jiri Pirko, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Willem de Bruijn, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Andrew Lunn, linux-doc
The RDMA upper layer driver (iw_cxgb4) can only be detached from an
adapter by unloading iw_cxgb4, which affects all adapters. This is
needed e.g. to use siw on the ports of the adapter instead.
Register a devlink instance for adapters with offload support, with
the generic enable_rdma param in runtime cmode:
devlink dev param set pci/0000:08:00.4 name enable_rdma \
value false cmode runtime
This detaches the RDMA ULD from this adapter, like unloading
iw_cxgb4, but only for this adapter, the netdevs and their
configuration stay. While disabled, loading iw_cxgb4 doesn't attach it
to this adapter. Enabling it attaches the RDMA ULD again if iw_cxgb4
is loaded, otherwise iw_cxgb4 attaches once it's loaded. If attaching
fails, -EIO is returned and the param stays false.
iw_cxgb4 can't disassociate user contexts, so ib_unregister_device()
would wait until all user space applications closed the RDMA device,
while holding uld_mutex, which blocks all adapters. So disabling is
refused with -EBUSY while iw_cxgb4 is in use, like unloading it. For
that iw_cxgb4 sets the new owner field of struct cxgb4_uld_info. The
module refcount covers the RDMA devices of all adapters, so an
application using the RDMA device of another adapter also makes
disabling fail.
Without "RDMA/cxgb4: reuse the uld context when attached to an adapter
again", sent separately to linux-rdma, every disable/enable cycle leaks
a uld context of iw_cxgb4 until iw_cxgb4 is unloaded.
There's one RDMA device for all ports of an adapter, so it can't be
done per port.
Cc: Potnuri Bharat Teja <bharat@chelsio.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@kernel.org>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
Documentation/networking/devlink/cxgb4.rst | 31 +++++++
Documentation/networking/devlink/index.rst | 1 +
drivers/infiniband/hw/cxgb4/device.c | 1 +
drivers/net/ethernet/chelsio/Kconfig | 1 +
drivers/net/ethernet/chelsio/cxgb4/Makefile | 2 +-
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 7 ++
.../ethernet/chelsio/cxgb4/cxgb4_devlink.c | 93 +++++++++++++++++++
.../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 6 ++
.../net/ethernet/chelsio/cxgb4/cxgb4_uld.c | 74 +++++++++++++++
.../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 2 +
10 files changed, 217 insertions(+), 1 deletion(-)
create mode 100644 Documentation/networking/devlink/cxgb4.rst
create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cxgb4_devlink.c
diff --git a/Documentation/networking/devlink/cxgb4.rst b/Documentation/networking/devlink/cxgb4.rst
new file mode 100644
index 000000000000..13323b45f1a2
--- /dev/null
+++ b/Documentation/networking/devlink/cxgb4.rst
@@ -0,0 +1,31 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====================
+cxgb4 devlink support
+=====================
+
+This document describes the devlink features implemented by the ``cxgb4``
+device driver.
+
+Parameters
+==========
+
+.. list-table:: Generic parameters implemented
+ :widths: 5 5 90
+
+ * - Name
+ - Mode
+ - Notes
+ * - ``enable_rdma``
+ - runtime
+ - Controls whether the RDMA upper layer driver (iw_cxgb4) is attached
+ to the adapter. Disabling it has the same effect as unloading
+ iw_cxgb4, but only for this adapter, the netdevs and their
+ configuration stay. There's one RDMA device for all ports of the
+ adapter. If iw_cxgb4 isn't loaded, enabling it lets iw_cxgb4 attach
+ once it's loaded. Disabling it is refused while user space
+ applications use an RDMA device of iw_cxgb4, as iw_cxgb4 can't detach
+ them, also if they use the RDMA device of another adapter; an
+ application opening the device during the detach makes it wait until
+ the device is closed. Only available for adapters with offload
+ support.
diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst
index be0d59cbaa3c..9e8e45e94f60 100644
--- a/Documentation/networking/devlink/index.rst
+++ b/Documentation/networking/devlink/index.rst
@@ -81,6 +81,7 @@ parameters, info versions, and other features it supports.
am65-nuss-cpsw-switch
bnxt
+ cxgb4
etas_es58x
hns3
i40e
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index 24ac9871ce67..43d1c76a43f7 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -1503,6 +1503,7 @@ static int c4iw_uld_control(void *handle, enum cxgb4_control control, ...)
static struct cxgb4_uld_info c4iw_uld_info = {
.name = DRV_NAME,
+ .owner = THIS_MODULE,
.nrxq = MAX_ULD_QSETS,
.ntxq = MAX_ULD_QSETS,
.rxq_size = 511,
diff --git a/drivers/net/ethernet/chelsio/Kconfig b/drivers/net/ethernet/chelsio/Kconfig
index 96d7779cd2f0..1e2927ec25b3 100644
--- a/drivers/net/ethernet/chelsio/Kconfig
+++ b/drivers/net/ethernet/chelsio/Kconfig
@@ -72,6 +72,7 @@ config CHELSIO_T4
depends on PTP_1588_CLOCK_OPTIONAL
select FW_LOADER
select MDIO
+ select NET_DEVLINK
select ZLIB_DEFLATE
help
This driver supports Chelsio T4, T5 & T6 based gigabit, 10Gb Ethernet
diff --git a/drivers/net/ethernet/chelsio/cxgb4/Makefile b/drivers/net/ethernet/chelsio/cxgb4/Makefile
index a4b4d475abf8..3b73ada29ce7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/Makefile
+++ b/drivers/net/ethernet/chelsio/cxgb4/Makefile
@@ -9,7 +9,7 @@ cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o
cxgb4_uld.o srq.o sched.o cxgb4_filter.o cxgb4_tc_u32.o \
cxgb4_ptp.o cxgb4_tc_flower.o cxgb4_cudbg.o cxgb4_mps.o \
cudbg_common.o cudbg_lib.o cudbg_zlib.o cxgb4_tc_mqprio.o \
- cxgb4_tc_matchall.o
+ cxgb4_tc_matchall.o cxgb4_devlink.o
cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o
cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
index f20f4bc58492..c1115a6330ee 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
@@ -1018,6 +1018,7 @@ struct sge {
#define for_each_ofldtxq(sge, i) for (i = 0; i < (sge)->ofldqsets; i++)
struct l2t_data;
+struct devlink;
#ifdef CONFIG_PCI_IOV
@@ -1151,6 +1152,9 @@ struct adapter {
unsigned int num_uld;
unsigned int num_ofld_uld;
struct list_head list_node;
+ struct devlink *devlink;
+ /* the RDMA ULD is detached, see cxgb4_uld_set_rdma() */
+ bool rdma_disabled;
struct list_head rcu_node;
struct list_head mac_hlist; /* list of MAC addresses in MPS Hash */
struct list_head mps_ref;
@@ -2088,6 +2092,9 @@ void t4_tp_mib_read(struct adapter *adap, u32 *buff, u32 nregs,
void t4_uld_mem_free(struct adapter *adap);
int t4_uld_mem_alloc(struct adapter *adap);
void t4_uld_clean_up(struct adapter *adap);
+int cxgb4_uld_set_rdma(struct adapter *adap, bool enable);
+int cxgb4_devlink_register(struct adapter *adap);
+void cxgb4_devlink_unregister(struct adapter *adap);
void t4_register_netevent_notifier(void);
int t4_i2c_rd(struct adapter *adap, unsigned int mbox, int port,
unsigned int devid, unsigned int offset,
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_devlink.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_devlink.c
new file mode 100644
index 000000000000..e0d0500cac4f
--- /dev/null
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_devlink.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * devlink support for cxgb4
+ */
+
+#include <net/devlink.h>
+
+#include "cxgb4.h"
+
+struct cxgb4_devlink {
+ struct adapter *adap;
+};
+
+static const struct devlink_ops cxgb4_devlink_ops = {
+};
+
+static int cxgb4_devlink_enable_rdma_get(struct devlink *devlink, u32 id,
+ struct devlink_param_gset_ctx *ctx,
+ struct netlink_ext_ack *extack)
+{
+ struct cxgb4_devlink *priv = devlink_priv(devlink);
+
+ ctx->val.vbool = !priv->adap->rdma_disabled;
+
+ return 0;
+}
+
+/*
+ * The RDMA ULD (iw_cxgb4) is detached or attached again for this
+ * adapter, which has the same effect as unloading or loading iw_cxgb4,
+ * but the other adapters and the netdevs stay. There's one RDMA device
+ * for all ports of the adapter.
+ */
+static int cxgb4_devlink_enable_rdma_set(struct devlink *devlink, u32 id,
+ struct devlink_param_gset_ctx *ctx,
+ struct netlink_ext_ack *extack)
+{
+ struct cxgb4_devlink *priv = devlink_priv(devlink);
+ int ret;
+
+ ret = cxgb4_uld_set_rdma(priv->adap, ctx->val.vbool);
+ if (ret == -EBUSY)
+ NL_SET_ERR_MSG_MOD(extack,
+ "The RDMA device is in use by user space applications");
+ return ret;
+}
+
+static const struct devlink_param cxgb4_devlink_params[] = {
+ DEVLINK_PARAM_GENERIC(ENABLE_RDMA, BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+ cxgb4_devlink_enable_rdma_get,
+ cxgb4_devlink_enable_rdma_set, NULL),
+};
+
+int cxgb4_devlink_register(struct adapter *adap)
+{
+ struct cxgb4_devlink *priv;
+ struct devlink *devlink;
+ int ret;
+
+ devlink = devlink_alloc(&cxgb4_devlink_ops, sizeof(*priv),
+ adap->pdev_dev);
+ if (!devlink)
+ return -ENOMEM;
+
+ priv = devlink_priv(devlink);
+ priv->adap = adap;
+
+ ret = devlink_params_register(devlink, cxgb4_devlink_params,
+ ARRAY_SIZE(cxgb4_devlink_params));
+ if (ret) {
+ devlink_free(devlink);
+ return ret;
+ }
+
+ devlink_register(devlink);
+ adap->devlink = devlink;
+
+ return 0;
+}
+
+void cxgb4_devlink_unregister(struct adapter *adap)
+{
+ struct devlink *devlink = adap->devlink;
+
+ if (!devlink)
+ return;
+
+ devlink_unregister(devlink);
+ devlink_params_unregister(devlink, cxgb4_devlink_params,
+ ARRAY_SIZE(cxgb4_devlink_params));
+ devlink_free(devlink);
+ adap->devlink = NULL;
+}
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index e21162a86f38..d4fdd5fbeb34 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -7033,6 +7033,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
if (is_uld(adapter))
cxgb4_uld_enable(adapter);
+ if (is_offload(adapter) && cxgb4_devlink_register(adapter))
+ dev_warn(&pdev->dev, "could not register devlink\n");
+
if (!is_t4(adapter->params.chip))
cxgb4_ptp_init(adapter);
@@ -7088,6 +7091,9 @@ static void remove_one(struct pci_dev *pdev)
if (adapter->pf == 4) {
int i;
+ /* no more changes of enable_rdma */
+ cxgb4_devlink_unregister(adapter);
+
/* Tear down per-adapter Work Queue first since it can contain
* references to our adapter data structure.
*/
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
index 23244cdfc1bc..f66899b4f932 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
@@ -732,6 +732,8 @@ static void cxgb4_uld_alloc_resources(struct adapter *adap,
return;
if (type == CXGB4_ULD_ISCSIT && is_t4(adap->params.chip))
return;
+ if (type == CXGB4_ULD_RDMA && adap->rdma_disabled)
+ return;
ret = cfg_queues_uld(adap, type, p);
if (ret)
goto out;
@@ -771,6 +773,78 @@ static void cxgb4_uld_alloc_resources(struct adapter *adap,
"ULD registration failed for uld type %d\n", type);
}
+/**
+ * cxgb4_uld_set_rdma - detach or attach the RDMA ULD of an adapter
+ * @adap: the adapter
+ * @enable: attach (true) or detach (false) the RDMA ULD
+ *
+ * Detaching has the same effect as unloading iw_cxgb4, but only for
+ * this adapter, the netdevs stay. While detached, loading iw_cxgb4
+ * doesn't attach it to this adapter. If iw_cxgb4 isn't loaded,
+ * attaching only allows it to attach once it's loaded. Used for the
+ * enable_rdma devlink param.
+ *
+ * iw_cxgb4 doesn't support disassociating user contexts, so detaching
+ * waits in ib_unregister_device() until all user space applications
+ * closed the RDMA device, while holding uld_mutex. So detaching is
+ * refused with -EBUSY while iw_cxgb4 is in use, like unloading it. The
+ * module refcount covers the RDMA devices of all adapters, so an
+ * application using the RDMA device of another adapter also makes
+ * detaching fail. An application opening the device right after that
+ * check still makes detaching wait until it's closed.
+ */
+int cxgb4_uld_set_rdma(struct adapter *adap, bool enable)
+{
+ struct cxgb4_uld_list *uld_entry;
+ int ret = 0;
+
+ if (!is_offload(adap))
+ return -EOPNOTSUPP;
+
+ mutex_lock(&uld_mutex);
+ if (adap->flags & CXGB4_SHUTTING_DOWN) {
+ ret = -ESHUTDOWN;
+ goto out;
+ }
+ if (adap->rdma_disabled == !enable)
+ goto out;
+
+ if (!enable && adap->uld[CXGB4_ULD_RDMA].handle) {
+ list_for_each_entry(uld_entry, &uld_list, list_node) {
+ struct module *owner = uld_entry->uld_info.owner;
+
+ if (uld_entry->uld_type == CXGB4_ULD_RDMA &&
+ owner && module_refcount(owner) > 0) {
+ ret = -EBUSY;
+ goto out;
+ }
+ }
+ }
+ adap->rdma_disabled = !enable;
+
+ if (!enable) {
+ if (adap->uld[CXGB4_ULD_RDMA].handle)
+ adap->uld[CXGB4_ULD_RDMA].state_change(adap->uld[CXGB4_ULD_RDMA].handle,
+ CXGB4_STATE_DETACH);
+ cxgb4_shutdown_uld_adapter(adap, CXGB4_ULD_RDMA);
+ goto out;
+ }
+
+ list_for_each_entry(uld_entry, &uld_list, list_node) {
+ if (uld_entry->uld_type != CXGB4_ULD_RDMA)
+ continue;
+ cxgb4_uld_alloc_resources(adap, CXGB4_ULD_RDMA,
+ &uld_entry->uld_info);
+ if (!adap->uld[CXGB4_ULD_RDMA].handle) {
+ adap->rdma_disabled = true;
+ ret = -EIO;
+ }
+ }
+out:
+ mutex_unlock(&uld_mutex);
+ return ret;
+}
+
void cxgb4_uld_enable(struct adapter *adap)
{
struct cxgb4_uld_list *uld_entry;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
index d7713038386c..0ec0f6c515ad 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
@@ -472,6 +472,8 @@ struct cxgb4_lld_info {
struct cxgb4_uld_info {
char name[IFNAMSIZ];
+ /* for the enable_rdma devlink param, see cxgb4_uld_set_rdma() */
+ struct module *owner;
void *handle;
unsigned int nrxq;
unsigned int rxq_size;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread