From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 3/6] usb: typec: fusb302: Read out the RX FIFO rather than flush it as PD RX goes on
Date: Fri, 27 Nov 2026 11:00:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-237197@kernel.org> (raw)
In-Reply-To: <20261127-fusb302-getsourcecap-v2-3-6770eb1e7945@flipper.net>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] usb: typec: fusb302: RX FIFO flush of acked messages in
fusb302_pd_rx_start()
- [Medium] usb: typec: fusb302: single message discard in
fusb302_pd_rx_start() misclassifies packets
--
commit 54397075ee71cab92e4ff1f9f4be91c84e562300
Author: Alexey Charkov <alchark@flipper.net>
usb: typec: fusb302: Read out the RX FIFO rather than flush it as PD RX goes on
This commit drains and drops unacknowledged packets from the RX FIFO when
turning PD RX on instead of flushing it, and checks GCRCSENT after enabling
automatic GoodCRC generation to determine whether an in-flight packet was
acknowledged.
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index d57f9ae6621d6..5cf1b78e7669b 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
[ ... ]
> @@ -1835,6 +1847,102 @@ static void fusb302_pd_rx_recheck_work(struct work_struct *work)
> mutex_unlock(&chip->lock);
> }
>
> +/* Tries at reading out the RX FIFO, before turning PD RX on */
> +#define FUSB302_RX_DISCARD_TRIES 4
> +
> +/*
> + * Turn automatic GoodCRCs on, and keep messages that came in before from TCPM:
> + * the partner, failing to deliver one, keeps its MessageID for the next, which
> + * TCPM would then drop as a retry. Read them out rather than flush the FIFO,
> + * which would cut short a packet coming in, so that the chip may acknowledge
> + * it and leave the rest of it behind. A packet on CC as GoodCRCs come on goes
> + * to TCPM only if it gets one.
> + */
> +static int fusb302_pd_rx_start(struct fusb302_chip *chip)
> +{
[ ... ]
> + /*
> + * Only the packet that was on CC as GoodCRCs came on can have gone
> + * without one, if it is in the FIFO by now: whatever lands after it
> + * got a GoodCRC from the chip
> + */
> + chip->rx_discard = !(status1 & FUSB_REG_STATUS1_RX_EMPTY) &&
> + !(interruptb & FUSB_REG_INTERRUPTB_GCRCSENT);
> + if (chip->rx_discard) {
> + ret = fusb302_pd_read_message(chip);
> + chip->rx_discard = false;
> + if (ret < 0)
> + goto out;
> + }
[Severity: Medium]
Can calling fusb302_pd_read_message() once here misclassify packets when
GCRCSENT is not set?
When !(status1 & FUSB_REG_STATUS1_RX_EMPTY) &&
!(interruptb & FUSB_REG_INTERRUPTB_GCRCSENT) holds, none of the data
currently in the RX FIFO was acknowledged. However, if those bytes are a
cut-short fragment (for example, after the fallback fusb302_pd_rx_flush()
above) or fail the CRC check, fusb302_pd_read_message() stays in its
resync loop reading from the live FIFO until it finds a valid message or
the FIFO runs dry:
drivers/usb/typec/tcpm/fusb302.c:fusb302_pd_read_message() {
...
if (fusb302_pd_rx_crc_ok(chip, 0, len))
break;
if (!chip->rx_resync)
fusb302_log(chip, "PD message failed CRC check, header: %x",
get_unaligned_le16(chip->rx_buf + 1));
chip->rx_resync = true;
fusb302_pd_rx_drop(chip, 1);
dropped++;
}
...
}
If a new packet arrives while those I2C reads are in progress, the chip
acknowledges it with a GoodCRC (since AUTO_GCRC is already on), and
fusb302_pd_read_message() consumes and drops that acknowledged message.
Conversely, if I2C or scheduling latency between exiting the initial
discard loop and setting AUTO_GCRC allowed two unacknowledged packets into
the FIFO, discarding only one message leaves the second unacknowledged
message to be passed to TCPM. Either case desynchronizes MessageID
tracking with the partner.
> + ret = fusb302_pd_read_messages(chip);
> +out:
> + if (ret > 0) {
> + /*
> + * CC stayed busy with GoodCRCs on, so which packets in the FIFO
> + * the chip acknowledged is unknown: flush them all
> + */
> + fusb302_log(chip, "CC busy as PD RX went on, flushing RX FIFO");
> + ret = fusb302_pd_rx_flush(chip);
> + fusb302_pd_rx_reset(chip, true);
> + }
> + /* TCPM then treats PD RX as off */
> + if (ret < 0 && gcrc_on)
> + fusb302_pd_set_auto_goodcrc(chip, false);
> + chip->rx_discard = false;
> +
> + return ret;
> +}
[Severity: Medium]
Does calling fusb302_pd_read_messages() instead of fusb302_pd_rx_drain() at
the end of fusb302_pd_rx_start() flush packets that the chip has already
acknowledged?
By the time execution reaches this call, AUTO_GCRC is enabled and any
unacknowledged packet that was on CC during the transition has already been
handled. If CC is now busy with a new incoming packet (or
FUSB302_RX_FIFO_MAX_MSGS messages were read), fusb302_pd_read_messages()
returns 1 and the out: block flushes the RX FIFO instead of scheduling
chip->rx_recheck. Because the chip has already sent (or will send) a
GoodCRC for those packets, the partner considers them delivered and will
not retry them.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-fusb302-getsourcecap-v2-0-6770eb1e7945@flipper.net?part=3
next prev parent reply other threads:[~2026-11-27 11:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:40 [PATCH v2 0/6] usb: typec: fusb302: Make full PD 3.0 work on the 2.0-only FUSB302 Alexey Charkov
2026-11-27 10:40 ` [PATCH v2 1/6] usb: typec: fusb302: Find the next message when the RX FIFO is out of step Alexey Charkov
2026-11-27 10:40 ` [PATCH v2 2/6] usb: typec: fusb302: Drain the RX FIFO on each PD interrupt Alexey Charkov
2026-11-27 10:58 ` sashiko-bot
2026-11-27 10:40 ` [PATCH v2 3/6] usb: typec: fusb302: Read out the RX FIFO rather than flush it as PD RX goes on Alexey Charkov
2026-11-27 11:00 ` sashiko-bot [this message]
2026-11-27 10:40 ` [PATCH v2 4/6] usb: typec: fusb302: Handle interrupts in the IRQ thread Alexey Charkov
2026-11-27 10:40 ` [PATCH v2 5/6] usb: typec: fusb302: Acknowledge Get_Source_Cap_Extended from the driver Alexey Charkov
2026-11-27 11:01 ` sashiko-bot
2026-11-27 10:40 ` [PATCH v2 6/6] usb: typec: fusb302: Acknowledge Get_Source_Cap_Extended in time Alexey Charkov
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-237197@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alchark@flipper.net \
--cc=linux-usb@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox