Skip to content

RTIO: default to the fallback function when driver doesnt support RTIO #88733

@VynDragon

Description

@VynDragon
Contributor

Description
When using a driver that uses RTIO (for example sensor async api provider), it will not default to the i2c_iodev_submit_fallback function if it has not been implemented by the driver.

Solution
Implement automatic default fallback.

Activity

ubieda

ubieda commented on Apr 16, 2025

@ubieda
Member

Thanks for capturing the issue.

IIRC - There was a reason why the auto-fallback was not implemented for bus-drivers. I think the run-time check was something we wanted to stay away from (it would apply both to those having it). However, I see for I2C and I3C we do have a run-time check that resolves in an error:

static inline void i2c_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
{
const struct i2c_dt_spec *dt_spec = (const struct i2c_dt_spec *)iodev_sqe->sqe.iodev->data;
const struct device *dev = dt_spec->bus;
const struct i2c_driver_api *api = (const struct i2c_driver_api *)dev->api;
if (api->iodev_submit == NULL) {
rtio_iodev_sqe_err(iodev_sqe, -ENOSYS);
return;
}
api->iodev_submit(dt_spec->bus, iodev_sqe);
}

static inline void i3c_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
{
const struct i3c_iodev_data *data =
(const struct i3c_iodev_data *)iodev_sqe->sqe.iodev->data;
const struct i3c_driver_api *api = (const struct i3c_driver_api *)data->bus->api;
if (api->iodev_submit == NULL) {
rtio_iodev_sqe_err(iodev_sqe, -ENOSYS);
return;
}
api->iodev_submit(data->bus, iodev_sqe);
}

This is not consistent with SPI:

static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
{
const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
const struct device *dev = dt_spec->bus;
const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
api->iodev_submit(dt_spec->bus, iodev_sqe);
}

To move forward, we should standardize this pattern, by either:

  1. Auto-fallback should the submit API is not implemented, or
  2. Throw a compile-time error indicating that a particular bus-driver does not implement it, while the corresponding Kconfig flags are enabled (e.g: CONFIG_I2C_RTIO and CONFIG_SENSOR_ASYNC_API).

I would rather prefer No. 2, but TBD how that would be implemented.

ubieda

ubieda commented on Apr 16, 2025

@ubieda
Member

@teburd @yperess feel free to chime in here

teburd

teburd commented on Apr 16, 2025

@teburd
Contributor

Compile time error is the right option here imho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EnhancementChanges/Updates/Additions to existing featuresarea: RTIO

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @teburd@VynDragon@ubieda

      Issue actions

        RTIO: default to the fallback function when driver doesnt support RTIO · Issue #88733 · zephyrproject-rtos/zephyr