From 39759136e3085ee0ed989d2728228f8085230333 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 09:45:41 +1100 Subject: [PATCH 1/3] soc: apple: t6050-aop: keep one ring buffer per endpoint Each AFK_GETBUF from the AOP2 firmware allocated a new device-managed coherent buffer and stored it in the endpoint's ring, replacing the one before. Those buffers are only released at unbind, which this driver does not allow, so a repeated GETBUF kept adding buffers. The stores of the buffer and its size were also not ordered against t6050_aop2_view(), which reads the rings from the resume path in another thread, so a reader could pair a new buffer with an old size. An endpoint now gets one buffer for as long as the firmware runs. A repeated GETBUF that fits in it is answered with the same IOVA; one with no size or a larger size than the buffer is refused and logged (ratelimited), without an answer. The buffer is published with smp_store_release() after its size and IOVA, and t6050_aop2_view() reads it with smp_load_acquire(), so a reader that finds the buffer also finds its size. As the buffer and its size never change once set, the readers need no lock for them. The ring offsets and sizes are still plain stores; t6050_aop2_view() checks them against the buffer's fixed size on every read, so a reader never leaves the buffer. Add KUnit tests (CONFIG_APPLE_T6050_AOP_KUNIT_TEST, suite apple_t6050_aop) for the GETBUF decision and the ring view's bounds. Signed-off-by: Ryan Murray --- drivers/soc/apple/Kconfig | 11 +++ drivers/soc/apple/t6050-aop-test.c | 91 +++++++++++++++++++++++++ drivers/soc/apple/t6050-aop.c | 54 ++++++++++++--- drivers/soc/apple/t6050-aop.kunitconfig | 10 +++ 4 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 drivers/soc/apple/t6050-aop-test.c create mode 100644 drivers/soc/apple/t6050-aop.kunitconfig diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index a9cf80938dc4e..ab4986a03f0d6 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -128,6 +128,17 @@ config APPLE_SOC_SLEEP_KUNIT_TEST If unsure, say N. +config APPLE_T6050_AOP_KUNIT_TEST + bool "KUnit tests for the T6050 AOP2 driver" if !KUNIT_ALL_TESTS + depends on APPLE_SOC_SLEEP && KUNIT=y + default KUNIT_ALL_TESTS + help + Checks that each AOP2 endpoint gets one ring buffer for as long as + its firmware runs, and that a ring is read only inside it. The tests + touch no hardware. + + If unsure, say N. + config APPLE_RTKIT tristate "Apple RTKit co-processor IPC protocol" depends on APPLE_MAILBOX diff --git a/drivers/soc/apple/t6050-aop-test.c b/drivers/soc/apple/t6050-aop-test.c new file mode 100644 index 0000000000000..00f1c0082c494 --- /dev/null +++ b/drivers/soc/apple/t6050-aop-test.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Included by t6050-aop.c: an endpoint's buffer is the firmware's first GETBUF's, for as long as + * the firmware runs; a later GETBUF that fits in it gets it again. + */ +#include + +static void t6050_aop_test_first_getbuf_allocates(struct kunit *test) +{ + struct t6050_aop_ring r = {}; + + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 0x4000), 0); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); +} + +static void t6050_aop_test_empty_getbuf_refused(struct kunit *test) +{ + static u8 mem[0x100]; + struct t6050_aop_ring r = {}; + + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0), 0); + r.buf = mem; + r.size = sizeof(mem); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0), 0); +} + +static void t6050_aop_test_repeat_getbuf_reuses(struct kunit *test) +{ + static u8 mem[0x100]; + struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; + int i; + + for (i = 0; i < 64; i++) + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, sizeof(mem)), 1); +} + +static void t6050_aop_test_smaller_getbuf_reuses(struct kunit *test) +{ + static u8 mem[0x100]; + struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; + + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, sizeof(mem) / 2), 1); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 1), 1); +} + +static void t6050_aop_test_larger_getbuf_refused(struct kunit *test) +{ + static u8 mem[0x100]; + struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; + + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, sizeof(mem) + 1), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, sizeof(mem) * 2), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); +} + +static void t6050_aop_test_view_inside_buffer(struct kunit *test) +{ + static __le32 mem[0x400 / 4]; + struct t6050_aop_ring r = {}; + struct t6050_aop_view v; + u32 bufsz = 2 * AFK_QE_SLOT; + u32 size = bufsz + 3 * 0x40; + + mem[0] = cpu_to_le32(bufsz); + /* No buffer yet. */ + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, 0, size, true, &v), -EINVAL); + r.buf = mem; + r.size = sizeof(mem); + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, 0, size, true, &v), 0); + KUNIT_EXPECT_PTR_EQ(test, (void *)v.hdr, (void *)mem); + /* A ring that does not fit the buffer. */ + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, 0x400 - 0x40, size, true, &v), -EINVAL); + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, 0x440, 0x40, true, &v), -EINVAL); +} + +static struct kunit_case t6050_aop_test_cases[] = { + KUNIT_CASE(t6050_aop_test_first_getbuf_allocates), + KUNIT_CASE(t6050_aop_test_empty_getbuf_refused), + KUNIT_CASE(t6050_aop_test_repeat_getbuf_reuses), + KUNIT_CASE(t6050_aop_test_smaller_getbuf_reuses), + KUNIT_CASE(t6050_aop_test_larger_getbuf_refused), + KUNIT_CASE(t6050_aop_test_view_inside_buffer), + {} +}; + +static struct kunit_suite t6050_aop_test_suite = { + .name = "apple_t6050_aop", + .test_cases = t6050_aop_test_cases, +}; + +kunit_test_suite(t6050_aop_test_suite); diff --git a/drivers/soc/apple/t6050-aop.c b/drivers/soc/apple/t6050-aop.c index d7115b8c2c2f9..92d583ae33702 100644 --- a/drivers/soc/apple/t6050-aop.c +++ b/drivers/soc/apple/t6050-aop.c @@ -77,8 +77,10 @@ #define AOP_EP_COUNT (AOP_EP_LAST - AOP_EP_FIRST + 1) struct t6050_aop_ring { + /* Set once, by the firmware's first GETBUF; published after its size and IOVA */ void *buf; size_t size; + dma_addr_t iova; u32 tx_off, tx_size; u32 rx_off, rx_size; bool tx_ready, rx_ready; @@ -139,21 +141,48 @@ static void t6050_aop_send(struct t6050_aop *aop, u8 ep, u64 msg) dev_err(aop->dev, "endpoint %#x: send %#llx: %d\n", ep, msg, ret); } +/* + * What a GETBUF gets: 0 a new buffer, 1 the endpoint's own again, as it fits in it, or -EINVAL for + * no size or more than the endpoint's buffer holds. An endpoint has one buffer for as long as the + * firmware runs: its rings are read from it at a sleep and a wake, by other threads. + */ +static int t6050_aop_getbuf_check(const struct t6050_aop_ring *r, size_t size) +{ + if (!size) + return -EINVAL; + if (!r->buf) + return 0; + + return size <= r->size ? 1 : -EINVAL; +} + static void t6050_aop_getbuf(struct t6050_aop *aop, u8 ep, u64 msg) { + struct t6050_aop_ring *r = &aop->ring[ep - AOP_EP_FIRST]; size_t size = (size_t)FIELD_GET(AFK_GETBUF_SIZE, msg) << AFK_BLOCK_SHIFT; - dma_addr_t iova; void *buf; + int ret; - buf = dmam_alloc_coherent(aop->dev, size, &iova, GFP_KERNEL); - if (!buf) { - dev_err(aop->dev, "endpoint %#x: no %#zx byte buffer\n", ep, size); + /* Only this endpoint's messages, in order, change its buffer. */ + ret = t6050_aop_getbuf_check(r, size); + if (ret < 0) { + dev_err_ratelimited(aop->dev, "endpoint %#x: no buffer for a %#zx byte GETBUF (has %#zx)\n", + ep, size, r->buf ? r->size : 0); return; } - aop->ring[ep - AOP_EP_FIRST].buf = buf; - aop->ring[ep - AOP_EP_FIRST].size = size; + if (!ret) { + buf = dmam_alloc_coherent(aop->dev, size, &r->iova, GFP_KERNEL); + if (!buf) { + dev_err_ratelimited(aop->dev, "endpoint %#x: no %#zx byte buffer\n", + ep, size); + return; + } + r->size = size; + /* A reader that finds the buffer finds its size. */ + smp_store_release(&r->buf, buf); + } t6050_aop_send(aop, ep, FIELD_PREP(AFK_TYPE, AFK_GETBUF_ACK) | - FIELD_PREP(AFK_GETBUF_IOVA, iova)); + FIELD_PREP(AFK_GETBUF_IOVA, r->iova)); } static int t6050_aop2_take(struct t6050_aop *aop, u8 ep, u32 old, u32 new); @@ -221,9 +250,12 @@ static const struct apple_rtkit_ops t6050_aop2_rtkit_ops = { static int t6050_aop2_view(struct t6050_aop_ring *r, u32 off, u32 size, bool ready, struct t6050_aop_view *v) { - if (!ready || !r->buf || size < sizeof(__le32) || off > r->size || size > r->size - off) + /* Pairs with t6050_aop_getbuf(): a buffer found here comes with its size. */ + u8 *buf = smp_load_acquire(&r->buf); + + if (!ready || !buf || size < sizeof(__le32) || off > r->size || size > r->size - off) return -EINVAL; - v->hdr = (u8 *)r->buf + off; + v->hdr = buf + off; v->bufsz = le32_to_cpu(READ_ONCE(*(__le32 *)v->hdr)); if (v->bufsz >= size || (size - v->bufsz) % 3 || v->bufsz < 2 * AFK_QE_SLOT || v->bufsz > AFK_RING_MAX) @@ -746,3 +778,7 @@ static struct platform_driver t6050_aop_driver = { .probe = t6050_aop_probe, }; builtin_platform_driver(t6050_aop_driver); + +#if IS_ENABLED(CONFIG_APPLE_T6050_AOP_KUNIT_TEST) +#include "t6050-aop-test.c" +#endif diff --git a/drivers/soc/apple/t6050-aop.kunitconfig b/drivers/soc/apple/t6050-aop.kunitconfig new file mode 100644 index 0000000000000..e4da56c59ad8e --- /dev/null +++ b/drivers/soc/apple/t6050-aop.kunitconfig @@ -0,0 +1,10 @@ +CONFIG_KUNIT=y +CONFIG_COMPILE_TEST=y +CONFIG_OF=y +CONFIG_PM=y +CONFIG_SUSPEND=y +CONFIG_HOTPLUG_CPU=y +CONFIG_APPLE_MAILBOX=y +CONFIG_APPLE_RTKIT=y +CONFIG_APPLE_SOC_SLEEP=y +CONFIG_APPLE_T6050_AOP_KUNIT_TEST=y From 3d1734b4a7a168d5133403caf07e826a82d7f175 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 13:22:53 +1100 Subject: [PATCH 2/3] soc: apple: t6050-aop: start an endpoint's rings over at each GETBUF A GETBUF that reuses the endpoint's buffer left its ring state from the last setup in place: both rings stayed marked ready at their old offsets and the element count went on. A sleep stop arriving between the GETBUF and the firmware's new ring announcements would then write its element at the old offsets in a buffer the firmware treats as new. The firmware announces the rings after each GETBUF, so start them over when one is answered: neither ring is ready, the element count and the recorded pointers go back to zero, and the endpoint is not open until its rings start again. A refused GETBUF changes nothing. Rename t6050_aop_getbuf_check() to t6050_aop_getbuf_claim() as it now changes the ring, and add KUnit cases for a reused and a refused GETBUF. Signed-off-by: Ryan Murray --- drivers/soc/apple/t6050-aop-test.c | 60 +++++++++++++++++++++++++----- drivers/soc/apple/t6050-aop.c | 23 +++++++++--- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/drivers/soc/apple/t6050-aop-test.c b/drivers/soc/apple/t6050-aop-test.c index 00f1c0082c494..9e7d77dec28b5 100644 --- a/drivers/soc/apple/t6050-aop-test.c +++ b/drivers/soc/apple/t6050-aop-test.c @@ -9,8 +9,8 @@ static void t6050_aop_test_first_getbuf_allocates(struct kunit *test) { struct t6050_aop_ring r = {}; - KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 0x4000), 0); - KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, 0x4000), 0); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); } static void t6050_aop_test_empty_getbuf_refused(struct kunit *test) @@ -18,10 +18,10 @@ static void t6050_aop_test_empty_getbuf_refused(struct kunit *test) static u8 mem[0x100]; struct t6050_aop_ring r = {}; - KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, 0), 0); r.buf = mem; r.size = sizeof(mem); - KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, 0), 0); } static void t6050_aop_test_repeat_getbuf_reuses(struct kunit *test) @@ -31,7 +31,7 @@ static void t6050_aop_test_repeat_getbuf_reuses(struct kunit *test) int i; for (i = 0; i < 64; i++) - KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, sizeof(mem)), 1); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, sizeof(mem)), 1); } static void t6050_aop_test_smaller_getbuf_reuses(struct kunit *test) @@ -39,8 +39,46 @@ static void t6050_aop_test_smaller_getbuf_reuses(struct kunit *test) static u8 mem[0x100]; struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; - KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, sizeof(mem) / 2), 1); - KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_check(&r, 1), 1); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, sizeof(mem) / 2), 1); + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, 1), 1); +} + +static void t6050_aop_test_reused_getbuf_restarts_rings(struct kunit *test) +{ + static __le32 mem[0x400 / 4]; + struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; + struct t6050_aop_view v; + u32 bufsz = 2 * AFK_QE_SLOT; + + mem[0] = cpu_to_le32(bufsz); + r.tx_off = 0; + r.tx_size = bufsz + 3 * 0x40; + r.tx_ready = true; + r.rx_off = 0; + r.rx_size = r.tx_size; + r.rx_ready = true; + r.seq = 5; + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, r.tx_off, r.tx_size, r.tx_ready, &v), 0); + + /* The firmware asks again: no ring until it announces them again. */ + KUNIT_EXPECT_EQ(test, t6050_aop_getbuf_claim(&r, sizeof(mem)), 1); + KUNIT_EXPECT_FALSE(test, r.tx_ready); + KUNIT_EXPECT_FALSE(test, r.rx_ready); + KUNIT_EXPECT_EQ(test, r.seq, 0); + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, r.tx_off, r.tx_size, r.tx_ready, &v), -EINVAL); + KUNIT_EXPECT_EQ(test, t6050_aop2_view(&r, r.rx_off, r.rx_size, r.rx_ready, &v), -EINVAL); +} + +static void t6050_aop_test_refused_getbuf_keeps_rings(struct kunit *test) +{ + static u8 mem[0x100]; + struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000, + .tx_ready = true, .rx_ready = true, .seq = 5 }; + + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, sizeof(mem) + 1), 0); + KUNIT_EXPECT_TRUE(test, r.tx_ready); + KUNIT_EXPECT_TRUE(test, r.rx_ready); + KUNIT_EXPECT_EQ(test, r.seq, 5); } static void t6050_aop_test_larger_getbuf_refused(struct kunit *test) @@ -48,9 +86,9 @@ static void t6050_aop_test_larger_getbuf_refused(struct kunit *test) static u8 mem[0x100]; struct t6050_aop_ring r = { .buf = mem, .size = sizeof(mem), .iova = 0x1000 }; - KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, sizeof(mem) + 1), 0); - KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, sizeof(mem) * 2), 0); - KUNIT_EXPECT_LT(test, t6050_aop_getbuf_check(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, sizeof(mem) + 1), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, sizeof(mem) * 2), 0); + KUNIT_EXPECT_LT(test, t6050_aop_getbuf_claim(&r, 0xffffUL << AFK_BLOCK_SHIFT), 0); } static void t6050_aop_test_view_inside_buffer(struct kunit *test) @@ -79,6 +117,8 @@ static struct kunit_case t6050_aop_test_cases[] = { KUNIT_CASE(t6050_aop_test_repeat_getbuf_reuses), KUNIT_CASE(t6050_aop_test_smaller_getbuf_reuses), KUNIT_CASE(t6050_aop_test_larger_getbuf_refused), + KUNIT_CASE(t6050_aop_test_reused_getbuf_restarts_rings), + KUNIT_CASE(t6050_aop_test_refused_getbuf_keeps_rings), KUNIT_CASE(t6050_aop_test_view_inside_buffer), {} }; diff --git a/drivers/soc/apple/t6050-aop.c b/drivers/soc/apple/t6050-aop.c index 92d583ae33702..14bf2b0729b55 100644 --- a/drivers/soc/apple/t6050-aop.c +++ b/drivers/soc/apple/t6050-aop.c @@ -145,15 +145,26 @@ static void t6050_aop_send(struct t6050_aop *aop, u8 ep, u64 msg) * What a GETBUF gets: 0 a new buffer, 1 the endpoint's own again, as it fits in it, or -EINVAL for * no size or more than the endpoint's buffer holds. An endpoint has one buffer for as long as the * firmware runs: its rings are read from it at a sleep and a wake, by other threads. + * + * A GETBUF that is answered starts the endpoint's rings over: they are announced again after it, + * so the endpoint has none, and sends nothing, until then. */ -static int t6050_aop_getbuf_check(const struct t6050_aop_ring *r, size_t size) +static int t6050_aop_getbuf_claim(struct t6050_aop_ring *r, size_t size) { + int ret; + if (!size) return -EINVAL; - if (!r->buf) - return 0; + ret = !r->buf ? 0 : size <= r->size ? 1 : -EINVAL; + if (ret < 0) + return ret; - return size <= r->size ? 1 : -EINVAL; + WRITE_ONCE(r->tx_ready, false); + WRITE_ONCE(r->rx_ready, false); + r->seq = 0; + r->tx_rptr = 0; + r->tx_wptr = 0; + return ret; } static void t6050_aop_getbuf(struct t6050_aop *aop, u8 ep, u64 msg) @@ -164,12 +175,14 @@ static void t6050_aop_getbuf(struct t6050_aop *aop, u8 ep, u64 msg) int ret; /* Only this endpoint's messages, in order, change its buffer. */ - ret = t6050_aop_getbuf_check(r, size); + ret = t6050_aop_getbuf_claim(r, size); if (ret < 0) { dev_err_ratelimited(aop->dev, "endpoint %#x: no buffer for a %#zx byte GETBUF (has %#zx)\n", ep, size, r->buf ? r->size : 0); return; } + /* Open again once its rings start (AFK_START_ACK). */ + clear_bit(ep - AOP_EP_FIRST, &aop->opened); if (!ret) { buf = dmam_alloc_coherent(aop->dev, size, &r->iova, GFP_KERNEL); if (!buf) { From f3ad1a8f362c0e8ce3fec0faae52748c24f16d74 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 15:26:31 +1100 Subject: [PATCH 3/3] soc: apple: t6050-aop: mark an endpoint open again when its rings restart An endpoint whose wake element went unanswered stays closed. If the firmware then starts the endpoint over (GETBUF, ring announcements, AFK_START_ACK), it is open again while still marked closed, so the next sleep stop skips it and the next restart sends it a wake element it never had a sleep element for. A restarted endpoint has no sleep element pending, so clear closed when its rings start. Also mark the rings' ready flags with WRITE_ONCE() when they are announced and read them with READ_ONCE() on the sleep and wake path, matching the WRITE_ONCE() that clears them at a GETBUF. Signed-off-by: Ryan Murray --- drivers/soc/apple/t6050-aop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/soc/apple/t6050-aop.c b/drivers/soc/apple/t6050-aop.c index 14bf2b0729b55..df00818ac506e 100644 --- a/drivers/soc/apple/t6050-aop.c +++ b/drivers/soc/apple/t6050-aop.c @@ -220,15 +220,17 @@ static void t6050_aop_recv(void *cookie, u8 ep, u64 msg) case AFK_INIT_TX: r->tx_off = FIELD_GET(AFK_RING_OFFSET, msg) << AFK_BLOCK_SHIFT; r->tx_size = FIELD_GET(AFK_RING_SIZE, msg) << AFK_BLOCK_SHIFT; - r->tx_ready = true; + WRITE_ONCE(r->tx_ready, true); break; case AFK_INIT_RX: r->rx_off = FIELD_GET(AFK_RING_OFFSET, msg) << AFK_BLOCK_SHIFT; r->rx_size = FIELD_GET(AFK_RING_SIZE, msg) << AFK_BLOCK_SHIFT; - r->rx_ready = true; + WRITE_ONCE(r->rx_ready, true); t6050_aop_send(aop, ep, FIELD_PREP(AFK_TYPE, AFK_START)); break; case AFK_START_ACK: + /* Started again from a GETBUF: no sleep element of the last setup is pending. */ + r->closed = false; set_bit(ep - AOP_EP_FIRST, &aop->opened); break; case AFK_RING: @@ -304,7 +306,7 @@ static int t6050_aop2_put(struct t6050_aop *aop, u8 ep, const u32 *msg, unsigned __le32 *qe; int ret; - ret = t6050_aop2_view(r, r->tx_off, r->tx_size, r->tx_ready, &v); + ret = t6050_aop2_view(r, r->tx_off, r->tx_size, READ_ONCE(r->tx_ready), &v); if (ret) return ret; dma_rmb(); @@ -361,7 +363,7 @@ static int t6050_aop2_rx_wptr(struct t6050_aop *aop, u8 ep) struct t6050_aop_view v; u32 wptr; - if (t6050_aop2_view(r, r->rx_off, r->rx_size, r->rx_ready, &v)) + if (t6050_aop2_view(r, r->rx_off, r->rx_size, READ_ONCE(r->rx_ready), &v)) return -EINVAL; dma_rmb(); wptr = t6050_aop2_ptr(&v, AFK_PTR_WRITE); @@ -396,8 +398,8 @@ static int t6050_aop2_take(struct t6050_aop *aop, u8 ep, u32 old, u32 new) struct t6050_aop_view v; int code; - if (t6050_aop2_view(r, r->rx_off, r->rx_size, r->rx_ready, &v) || old >= v.bufsz || - new >= v.bufsz) + if (t6050_aop2_view(r, r->rx_off, r->rx_size, READ_ONCE(r->rx_ready), &v) || + old >= v.bufsz || new >= v.bufsz) return -EINVAL; if (old == new) return -ENOMSG;