[PATCH v3 fwctl 1/3] fwctl: Add driver_data field to fwctl_rpc

From: Pavan Chebbi

Date: Tue May 26 2026 - 10:58:33 EST


Add a driver_data field to struct fwctl_rpc in the UAPI and thread the
value through the fw_rpc() ops callback as a new __u64 parameter. The
field is opaque and driver-defined.

Drivers that do not define a driver_data format may return -EOPNOTSUPP.
Update the existing drivers' fw_rpc implementations to enforce this.

Signed-off-by: Pavan Chebbi <pavan.chebbi@xxxxxxxxxxxx>
---
drivers/cxl/core/features.c | 6 +++++-
drivers/fwctl/bnxt/main.c | 6 +++++-
drivers/fwctl/main.c | 3 ++-
drivers/fwctl/mlx5/main.c | 6 +++++-
drivers/fwctl/pds/main.c | 6 +++++-
include/linux/fwctl.h | 8 ++++++--
include/uapi/fwctl/fwctl.h | 3 +++
7 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c
index 3435db9ea6b1..a0d7f26c5b6d 100644
--- a/drivers/cxl/core/features.c
+++ b/drivers/cxl/core/features.c
@@ -643,7 +643,8 @@ static void *cxlctl_handle_commands(struct cxl_features_state *cxlfs,
}

static void *cxlctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
- void *in, size_t in_len, size_t *out_len)
+ void *in, size_t in_len, size_t *out_len,
+ __u64 driver_data)
{
struct fwctl_device *fwctl_dev = uctx->fwctl;
struct cxl_memdev *cxlmd = fwctl_to_memdev(fwctl_dev);
@@ -651,6 +652,9 @@ static void *cxlctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
const struct fwctl_rpc_cxl *rpc_in = in;
u16 opcode = rpc_in->opcode;

+ if (driver_data)
+ return ERR_PTR(-EOPNOTSUPP);
+
if (!cxlctl_validate_hw_command(cxlfs, rpc_in, scope, opcode))
return ERR_PTR(-EINVAL);

diff --git a/drivers/fwctl/bnxt/main.c b/drivers/fwctl/bnxt/main.c
index 951c8ac2e0a1..5eb3651a1784 100644
--- a/drivers/fwctl/bnxt/main.c
+++ b/drivers/fwctl/bnxt/main.c
@@ -172,7 +172,8 @@ static unsigned int bnxtctl_get_timeout(struct input *req)

static void *bnxtctl_fw_rpc(struct fwctl_uctx *uctx,
enum fwctl_rpc_scope scope,
- void *in, size_t in_len, size_t *out_len)
+ void *in, size_t in_len, size_t *out_len,
+ __u64 driver_data)
{
struct bnxtctl_dev *bnxtctl =
container_of(uctx->fwctl, struct bnxtctl_dev, fwctl);
@@ -180,6 +181,9 @@ static void *bnxtctl_fw_rpc(struct fwctl_uctx *uctx,
struct bnxt_fw_msg rpc_in = {0};
int rc;

+ if (driver_data)
+ return ERR_PTR(-EOPNOTSUPP);
+
if (in_len < sizeof(struct input) || in_len > HWRM_MAX_REQ_LEN)
return ERR_PTR(-EINVAL);

diff --git a/drivers/fwctl/main.c b/drivers/fwctl/main.c
index 098c3824ad75..32c4c66dd7d5 100644
--- a/drivers/fwctl/main.c
+++ b/drivers/fwctl/main.c
@@ -122,7 +122,8 @@ static int fwctl_cmd_rpc(struct fwctl_ucmd *ucmd)

out_len = cmd->out_len;
void *outbuf __free(kvfree) = fwctl->ops->fw_rpc(
- ucmd->uctx, cmd->scope, inbuf, cmd->in_len, &out_len);
+ ucmd->uctx, cmd->scope, inbuf, cmd->in_len, &out_len,
+ cmd->driver_data);
if (IS_ERR(outbuf))
return PTR_ERR(outbuf);
if (outbuf == inbuf) {
diff --git a/drivers/fwctl/mlx5/main.c b/drivers/fwctl/mlx5/main.c
index e86ab703c767..2a5105769126 100644
--- a/drivers/fwctl/mlx5/main.c
+++ b/drivers/fwctl/mlx5/main.c
@@ -304,7 +304,8 @@ static bool mlx5ctl_validate_rpc(const void *in, enum fwctl_rpc_scope scope)
}

static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
- void *rpc_in, size_t in_len, size_t *out_len)
+ void *rpc_in, size_t in_len, size_t *out_len,
+ __u64 driver_data)
{
struct mlx5ctl_dev *mcdev =
container_of(uctx->fwctl, struct mlx5ctl_dev, fwctl);
@@ -313,6 +314,9 @@ static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
void *rpc_out;
int ret;

+ if (driver_data)
+ return ERR_PTR(-EOPNOTSUPP);
+
if (in_len < MLX5_ST_SZ_BYTES(mbox_in_hdr) ||
*out_len < MLX5_ST_SZ_BYTES(mbox_out_hdr))
return ERR_PTR(-EMSGSIZE);
diff --git a/drivers/fwctl/pds/main.c b/drivers/fwctl/pds/main.c
index 08872ee8422f..bb61e60843cf 100644
--- a/drivers/fwctl/pds/main.c
+++ b/drivers/fwctl/pds/main.c
@@ -348,7 +348,8 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
}

static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
- void *in, size_t in_len, size_t *out_len)
+ void *in, size_t in_len, size_t *out_len,
+ __u64 driver_data)
{
struct pdsfc_dev *pdsfc = container_of(uctx->fwctl, struct pdsfc_dev, fwctl);
struct device *dev = &uctx->fwctl->dev;
@@ -362,6 +363,9 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
void *out = NULL;
int err;

+ if (driver_data)
+ return ERR_PTR(-EOPNOTSUPP);
+
err = pdsfc_validate_rpc(pdsfc, rpc, scope);
if (err)
return ERR_PTR(err);
diff --git a/include/linux/fwctl.h b/include/linux/fwctl.h
index 5d61fc8a6871..afb7f72d0cb1 100644
--- a/include/linux/fwctl.h
+++ b/include/linux/fwctl.h
@@ -51,10 +51,14 @@ struct fwctl_ops {
* @fw_rpc: Implement FWCTL_RPC. Deliver rpc_in/in_len to the FW and
* return the response and set out_len. rpc_in can be returned as the
* response pointer. Otherwise the returned pointer is freed with
- * kvfree().
+ * kvfree(). driver_data is the opaque value from fwctl_rpc, passed
+ * verbatim from userspace. The driver is responsible for interpreting
+ * and validating it. Drivers that do not define a driver_data format
+ * must return -EOPNOTSUPP if driver_data is non-zero.
*/
void *(*fw_rpc)(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
- void *rpc_in, size_t in_len, size_t *out_len);
+ void *rpc_in, size_t in_len, size_t *out_len,
+ __u64 driver_data);
};

/**
diff --git a/include/uapi/fwctl/fwctl.h b/include/uapi/fwctl/fwctl.h
index 2d6d4049c205..2e07425402a3 100644
--- a/include/uapi/fwctl/fwctl.h
+++ b/include/uapi/fwctl/fwctl.h
@@ -120,6 +120,8 @@ enum fwctl_rpc_scope {
* @out_len: Length of the out memory
* @in: Request message in device specific format
* @out: Response message in device specific format
+ * @driver_data: Opaque userspace pointer passed verbatim to the driver.
+ * Must be 0 for drivers that do not define a driver_data format.
*
* Deliver a Remote Procedure Call to the device FW and return the response. The
* call's parameters and return are marshaled into linear buffers of memory. Any
@@ -136,6 +138,7 @@ struct fwctl_rpc {
__u32 out_len;
__aligned_u64 in;
__aligned_u64 out;
+ __aligned_u64 driver_data;
};
#define FWCTL_RPC _IO(FWCTL_TYPE, FWCTL_CMD_RPC)

--
2.52.0