-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spi: rtio: Refactor common SPI RTIO APIs to use across common drivers #77136
spi: rtio: Refactor common SPI RTIO APIs to use across common drivers #77136
Conversation
28e8df7
to
19bb5a4
Compare
include/zephyr/drivers/spi/rtio.h
Outdated
@@ -0,0 +1,114 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this belongs to include/zephyr, it's not a public API as far as I know. Only spi drivers are meant to use it as it generalizes common parts. Thus its proper place should be in drivers/spi/ .
I don't know why it was done this way in i2c, it's anyway not uncommon to see variations in how things are done depending on the domain. For instance spi_rtio_copy ended in the public spi.h where instead, in i2c in ended up in i2c_rtio.h only via its signature (but public as well), even though in both case: it's meant to be used by drivers only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well drivers may exist out of tree, I think this goes to a pr @dcpleung has. I generally believe the application and driver used apis should be public, just not necessarily in the same header. So far we have the one header for the application in include but that’s not very supportive of out of tree drivers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw daniel's PR, it's a good idea. So it could go into include/zephyr/drivers/internal/spi.h then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It hasn’t been sorted out where that stuff should go exactly I don’t think, but yeah something along those lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw daniel's PR, it's a good idea. So it could go into include/zephyr/drivers/internal/spi.h then
Can you provide your rationale behind suggesting that path? I don't see how lumping internal header files behind drivers/internal/
is better than drivers/<area>/*
.
In this case, specifically, I don't think we'll want to lump all-things SPI (zephyr/drivers/internal/spi.h)
in the same file as SPI RTIO (zephyr/drivers/spi/rtio.h
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from #77361 and a related larger tree wide PR doing much the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from #77361 and a related larger tree wide PR doing much the same
Thanks for the link. By looking at the diff + the comment below: It appears this goes along the same lines?
I would say that, in terms of a hierarchical tree, anything under drivers/serial and drivers/uart should be considered internal if they do not need to be exposed outside this "subtree". One can collapse this subtree into a single node and nothing else outside would be affected.
if (spi_rtio_submit(rtio_ctx, iodev_sqe)) { | ||
spi_mcux_iodev_prepare_start(dev); | ||
spi_mcux_iodev_start(dev); | ||
} | ||
} | ||
|
||
static void spi_mcux_iodev_complete(const struct device *dev, int status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The i2c_rtio_complete does much the same thing and returns true/false from what I recall to inform the driver whether more work should be started. Perhaps spi_rtio_complete could be an equivalent here.
That would reduce the code duplication further.
It's possible that i2c_rtio and spi_rtio do almost the same things entirely and could be converged into bus_rtio, with the blocking call wrappers still being done per bus type (as they each have their own call parameters). That sort of thing can be done after this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads-up: I did come up with a spi_rtio_complete() (see further down); it's just that it's very limited as there's no handling of spi_context to perform spi_context_cs_control()
calls.
I can take another look to further optimize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a second pass, I find it a bit hard to optimize (without having spi_rtio
deal with the spi_context
, or change the API signature to diverge from i2c_rtio
's). May we explore this further optimization out of scope for this PR?
It's possible that i2c_rtio and spi_rtio do almost the same things entirely and could be converged into bus_rtio, with the blocking call wrappers still being done per bus type (as they each have their own call parameters). That sort of thing can be done after this though.
BTW - I do agree we'd gain a lot from this bus_rtio refactoring.
19bb5a4
to
9b6d09d
Compare
I've made one push to move spi_rtio_copy to spi_rtio.h |
Likely needs a rebase and some conflicts fixed for the const tx buf changes |
05fba17
to
097ef3b
Compare
I've rebased this PR. May I get another review @teburd @tbursztyka? |
There's a new max32 driver that could really benefit from having this work in #78346 |
Roger - I'll rebase soon to adress conflicts |
As a step to make them common code: spi_rtio.c. Verified this refactorization builds and passes spi_loopback, both with CONFIG_SPI_RTIO enabled, as well as disabled. Tested on mimxrt1010_evk. Signed-off-by: Luis Ubieda <luisf@croxel.com>
Does not seem to be required. This allows hiding away the spin lock APIs. Signed-off-by: Luis Ubieda <luisf@croxel.com>
Extracted common SPI RTIO operations from the spi_mcux_lpspi driver into spi_rtio, which should be common across RTIO drivers. Tested with spi_loopback with and without CONFIG_SPI_RTIO. Ran on mimxrt1010_evk. Also, verified the other SPI RTIO driver (spi_sam) is not broken by these changes (tested building for target: robokit1 with the same conditions as above). Signed-off-by: Luis Ubieda <luisf@croxel.com>
To group all common APIs for SPI RTIO. Signed-off-by: Luis Ubieda <luisf@croxel.com>
097ef3b
to
48146dc
Compare
I've rebased this PR to resolve conflicts. I've re-tested it on hardware and it looks good. |
Description
This PR is the result of an analysis performed to the SPI RTIO drivers in the tree (
spi_sam.c
andspi_mcux_lpspi.c
), in which common patterns were detected with the objective of extracting them into a separate file (spi_rtio.c
) so that effort is reduced when implementing SPI RTIO drivers moving forward.Note
Only the spi_mcux_spi.c driver has been refactored. spi_sam.c will be refactored on a separate PR.
Changes
spi/rtio.h
andspi_rtio.c
) with common APIs.Testing
Ran spi_loopback test with and without RTIO enabled:
Console output (RTIO variant):