All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael Reeves" <michael.reeves077@gmail.com>
Cc: devicetree@vger.kernel.org, linux-input@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v5 3/8] mailbox: apple: Add DockChannel FIFO controller
Date: Sun, 08 Nov 2026 07:45:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-203639@kernel.org> (raw)
In-Reply-To: <20261108-b4-apple-mtp-keyboard-v5-3-e2c97b82669a@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mailbox: apple: unhandled TX IRQ storm in
  apple_dockchannel_irq_thread()
- [Medium] mailbox: apple: premature RX IRQ_FLAG clear in
  apple_dockchannel_irq_thread()
- [Medium] mailbox: apple: TX queue stall when FIFO is non-empty with
  tx_active false
--

commit b95e903761484cc55af89a24caaf5c68658e43d3
Author: Michael Reeves <michael.reeves077@gmail.com>

mailbox: apple: Add DockChannel FIFO controller

This commit adds a mailbox controller driver for the Apple DockChannel
hardware FIFO, handling TX completion and RX data in a threaded interrupt
handler.

> diff --git a/drivers/mailbox/apple-dockchannel.c b/drivers/mailbox/apple-dockchannel.c
> new file mode 100644
> index 0000000000000..4400d767f6ad5
> --- /dev/null
> +++ b/drivers/mailbox/apple-dockchannel.c

[ ... ]

> +static int apple_dockchannel_send_data(struct mbox_chan *chan, void *data)
> +{
> +	struct apple_dockchannel *dc = chan->con_priv;
> +	struct apple_dockchannel_msg *msg = data;
> +	unsigned long flags;
> +
> +	if (!msg || !msg->data || !msg->len)
> +		return -EINVAL;
> +
> +	if (msg->len > APPLE_DOCKCHANNEL_FIFO_SIZE)
> +		return -EMSGSIZE;
> +
> +	spin_lock_irqsave(&dc->lock, flags);
> +
> +	if (dc->tx_active || !apple_dockchannel_tx_empty(dc)) {
> +		spin_unlock_irqrestore(&dc->lock, flags);
> +		return -EBUSY;
> +	}

[Severity: Medium]
Can this stall the mailbox TX queue if the hardware TX FIFO is non-empty
while dc->tx_active is false?

When msg_submit() gets -EBUSY from send_data() on a txdone_irq controller,
it leaves the message queued in chan->msg_data and waits for
mbox_chan_txdone() to retry submission.  If residual bytes are in the FIFO
at apple_dockchannel_startup() or after apple_dockchannel_shutdown()
clears dc->tx_active and masks dc->irq_tx, returning -EBUSY here without
arming dc->irq_tx and setting dc->tx_active means no interrupt will fire
when the FIFO drains and mbox_chan_txdone() will never be called.

[ ... ]

> +static irqreturn_t apple_dockchannel_irq_thread(int irq, void *data)
> +{
> +	struct apple_dockchannel *dc = data;
> +	unsigned long irqflags;
> +	u32 flags;
> +	u32 pending;
> +	bool tx_done = false;
> +
> +	spin_lock_irqsave(&dc->lock, irqflags);
> +
> +	flags = readl_relaxed(dc->irq_base + IRQ_FLAG);
> +
> +	pending = flags & dc->irq_mask & (dc->irq_tx | dc->irq_rx);
> +	if (!pending)
> +		goto out_unlock_none;
> +
> +	if (pending & dc->irq_tx) {
> +		if (apple_dockchannel_tx_empty(dc)) {
> +			apple_dockchannel_irq_disable(dc, dc->irq_tx);
> +			tx_done = dc->tx_active;
> +			dc->tx_active = false;
> +		} else {
> +			pending &= ~dc->irq_tx;
> +		}
> +	}
> +
> +	writel_relaxed(pending, dc->irq_base + IRQ_FLAG);
> +
> +	spin_unlock_irqrestore(&dc->lock, irqflags);
> +
> +	if (tx_done)
> +		mbox_chan_txdone(&dc->chan, 0);
> +
> +	if (!(pending & dc->irq_rx))
> +		return pending ? IRQ_HANDLED : IRQ_NONE;

[Severity: High]
Can clearing dc->irq_tx from pending when apple_dockchannel_tx_empty() is
false cause an unhandled IRQ storm?

In apple_dockchannel_send_data(), FIFO writes go to dc->data_base,
CONFIG_TX_THRESH goes to dc->config_base, and apple_dockchannel_irq_enable()
clears IRQ_FLAG and unmasks dc->irq_tx in dc->irq_base using relaxed MMIO
without a readback.  If dc->irq_tx is latched in IRQ_FLAG before
DATA_TX_FREE reaches APPLE_DOCKCHANNEL_FIFO_SIZE, removing dc->irq_tx from
pending skips clearing it in the write-to-clear IRQ_FLAG register while
leaving it unmasked in IRQ_MASK.  When dc->irq_rx is not also set, the
handler returns IRQ_NONE with the level-high interrupt still asserted,
re-entering the handler in a tight loop until genirq disables the IRQ line.

Also, because IRQ_FLAG is written after apple_dockchannel_tx_empty() is
checked, acknowledging IRQ_FLAG before checking DATA_TX_FREE is needed so a
FIFO that finishes draining between the check and the IRQ_FLAG write does
not lose its completion interrupt.

> +
> +	for (;;) {
> +		struct apple_dockchannel_msg msg;
> +		size_t avail;
> +
> +		avail = readl_relaxed(dc->data_base + DATA_RX_COUNT);
> +		if (!avail)
> +			break;
> +
> +		avail = min_t(size_t, avail, APPLE_DOCKCHANNEL_FIFO_SIZE);
> +
> +		apple_dockchannel_read(dc, dc->rx_buf, avail);
> +
> +		msg.data = dc->rx_buf;
> +		msg.len = avail;
> +		mbox_chan_received_data(&dc->chan, &msg);
> +	}
> +
> +	return IRQ_HANDLED;

[Severity: Medium]
Does clearing dc->irq_rx in IRQ_FLAG before draining the RX FIFO cause a
spurious interrupt after every RX transfer?

IRQ_FLAG is a sticky write-to-clear status register, and CONFIG_RX_THRESH
is set to 1.  When IRQ_FLAG is written before reading the FIFO,
DATA_RX_COUNT is still at least 1 (and more bytes may arrive while the loop
drains the FIFO), so dc->irq_rx immediately re-latches in IRQ_FLAG and triggers
an extra wakeup of apple_dockchannel_irq_thread() once the line is unmasked.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-b4-apple-mtp-keyboard-v5-0-e2c97b82669a@gmail.com?part=3

  reply	other threads:[~2026-11-08  7:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08  7:25 [PATCH v5 0/8] Add support for Apple Silicon DockChannel internal keyboards Michael Reeves via B4 Relay
2026-11-08  7:25 ` Michael Reeves
2026-11-08  7:25 ` [PATCH v5 1/8] dt-bindings: mailbox: apple: Add DockChannel mailbox Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:25 ` [PATCH v5 2/8] dt-bindings: input: apple: Add DockChannel HID transport Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-10  9:20   ` Krzysztof Kozlowski
2026-11-10 11:26     ` Michael Reeves
2026-11-10 11:30       ` Krzysztof Kozlowski
2026-11-11  1:57         ` Michael Reeves
2026-11-08  7:25 ` [PATCH v5 3/8] mailbox: apple: Add DockChannel FIFO controller Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:45   ` sashiko-bot [this message]
2026-11-08  7:25 ` [PATCH v5 4/8] soc: apple: rtkit: Add tracekit endpoint Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:25 ` [PATCH v5 5/8] HID: apple: Add support for DockChannel HID keyboards Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:38   ` sashiko-bot
2026-11-08  7:25 ` [PATCH v5 6/8] HID: apple: Add DockChannel HID transport driver Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:48   ` sashiko-bot
2026-11-08  7:25 ` [PATCH v5 7/8] arm64: dts: apple: Add MTP DockChannel HID nodes Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves
2026-11-08  7:40   ` sashiko-bot
2026-11-08  7:48     ` Michael Reeves
2026-11-08  7:25 ` [PATCH v5 8/8] arm64: dts: apple: Enable DockChannel HID on M2 and M3 laptops Michael Reeves via B4 Relay
2026-11-08  7:25   ` Michael Reeves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-203639@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=michael.reeves077@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.