Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Frank Li
Tue, 24 Nov 2026 20:51
Re: [PATCH v3 1/3] i3c: Add helpers to get the maximum transfer size for a device
Author: Frank Li
Date: Tue, 24 Nov 2026 20:51
Date: Tue, 24 Nov 2026 20:51
143 lines
22719 bytes
22719 bytes
On Tue, Nov 24, 2026 at 11:36:49AM +0530, Shubham Patil wrote:
> A target's MRL and MWL do not account for controller transfer limits.
> Add max_tx_bytes and max_rx_bytes to let controllers report these limits,
> and helpers returning the smaller nonzero target and controller limit.
>
> The limits apply to a single message; batched transfers may still exceed
> controller capacity. Return 0 when neither side reports a limit, leaving
> callers to apply their defaults.
>
> Signed-off-by: Shubham Patil <shubhamsanjay.patil@amd.com>
> ---
Nit: if need respin, change subject "helper" to "APIs"
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Changes in v3:
> - Rename tx_fifo_bytes/rx_fifo_bytes to max_tx_bytes/max_rx_bytes.
> - Shorten the commit message; no functional changes.
>
> drivers/i3c/device.c | 49 ++++++++++++++++++++++++++++++++++++++
> include/linux/i3c/device.h | 3 +++
> include/linux/i3c/master.h | 13 +++++++---
> 3 files changed, 62 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c
> index 4df4682af150..93adf4c74004 100644
> --- a/drivers/i3c/device.c
> +++ b/drivers/i3c/device.c
> @@ -9,6 +9,7 @@
> #include <linux/bug.h>
> #include <linux/completion.h>
> #include <linux/device.h>
> +#include <linux/minmax.h>
> #include <linux/mutex.h>
> #include <linux/slab.h>
>
> @@ -106,6 +107,54 @@ void i3c_device_get_info(const struct i3c_device *dev,
> }
> EXPORT_SYMBOL_GPL(i3c_device_get_info);
>
> +/**
> + * i3c_device_get_max_read_xfer_bytes() - get the maximum readable message size
> + *
> + * @dev: device the transfers would be directed to
> + *
> + * Return: the smaller of @dev's MRL and the controller's receive limit for a
> + * single message, or 0 if neither reports a limit.
> + */
> +u16 i3c_device_get_max_read_xfer_bytes(const struct i3c_device *dev)
> +{
> + u16 mrl = 0, max_rx_bytes = 0;
> +
> + i3c_bus_normaluse_lock(dev->bus);
> + if (dev->desc) {
> + mrl = dev->desc->info.max_read_len;
> + max_rx_bytes = i3c_dev_get_master(dev->desc)->max_rx_bytes;
> + }
> + i3c_bus_normaluse_unlock(dev->bus);
> +
> + /* 0 means "no limit reported" on either side. */
> + return min_not_zero(mrl, max_rx_bytes);
> +}
> +EXPORT_SYMBOL_GPL(i3c_device_get_max_read_xfer_bytes);
> +
> +/**
> + * i3c_device_get_max_write_xfer_bytes() - get the maximum writable message size
> + *
> + * @dev: device the transfers would be directed to
> + *
> + * Return: the smaller of @dev's MWL and the controller's transmit limit for a
> + * single message, or 0 if neither reports a limit.
> + */
> +u16 i3c_device_get_max_write_xfer_bytes(const struct i3c_device *dev)
> +{
> + u16 mwl = 0, max_tx_bytes = 0;
> +
> + i3c_bus_normaluse_lock(dev->bus);
> + if (dev->desc) {
> + mwl = dev->desc->info.max_write_len;
> + max_tx_bytes = i3c_dev_get_master(dev->desc)->max_tx_bytes;
> + }
> + i3c_bus_normaluse_unlock(dev->bus);
> +
> + /* 0 means "no limit reported" on either side. */
> + return min_not_zero(mwl, max_tx_bytes);
> +}
> +EXPORT_SYMBOL_GPL(i3c_device_get_max_write_xfer_bytes);
> +
> /**
> * i3c_device_disable_ibi() - Disable IBIs coming from a specific device
> * @dev: device on which IBIs should be disabled
> diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
> index e30ea2cb13cb..cb3374e4f9fa 100644
> --- a/include/linux/i3c/device.h
> +++ b/include/linux/i3c/device.h
> @@ -331,6 +331,9 @@ int i3c_device_do_setdasa(struct i3c_device *dev);
>
> void i3c_device_get_info(const struct i3c_device *dev, struct i3c_device_info *info);
>
> +u16 i3c_device_get_max_read_xfer_bytes(const struct i3c_device *dev);
> +u16 i3c_device_get_max_write_xfer_bytes(const struct i3c_device *dev);
> +
> struct i3c_ibi_payload {
> unsigned int len;
> const void *data;
> diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> index d58070a72a49..08a26aa9c164 100644
> --- a/include/linux/i3c/master.h
> +++ b/include/linux/i3c/master.h
> @@ -551,11 +551,16 @@ struct i3c_master_controller_ops {
> * context (notably the resume path), and is skipped if the
> * controller is shutting down
> * @dev_nack_retry_count: retry count when slave device nack
> + * @max_tx_bytes: maximum number of bytes this controller can transmit in a
> + * single message, or 0 if it has no such limit
> + * @max_rx_bytes: maximum number of bytes this controller can receive in a
> + * single message, or 0 if it has no such limit
> *
> * A &struct i3c_master_controller has to be registered to the I3C subsystem
> - * through i3c_master_register(). None of &struct i3c_master_controller fields
> - * should be set manually, just pass appropriate values to
> - * i3c_master_register().
> + * through i3c_master_register(). Except for @max_tx_bytes and
> + * @max_rx_bytes, which a controller driver may set before registering, none
> + * of &struct i3c_master_controller fields should be set manually, just pass
> + * appropriate values to i3c_master_register().
> */
> struct i3c_master_controller {
> struct device dev;
> @@ -580,6 +585,8 @@ struct i3c_master_controller {
> struct work_struct hj_work;
> struct work_struct reg_work;
> unsigned int dev_nack_retry_count;
> + u16 max_tx_bytes;
> + u16 max_rx_bytes;
> };
>
> /**
> --
> 2.34.1
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads