From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 5/6] usb: typec: fusb302: Acknowledge Get_Source_Cap_Extended from the driver
Date: Fri, 27 Nov 2026 11:01:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-237201@kernel.org> (raw)
In-Reply-To: <20261127-fusb302-getsourcecap-v2-5-6770eb1e7945@flipper.net>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] usb: typec: fusb302: CRC_CHK drain in fusb302_irq_handle()
runs before TX end
- [Medium] usb: typec: fusb302: unacknowledged message passed to
tcpm_pd_receive()
- [Medium] usb: typec: fusb302: rx_recheck wakes IRQ thread after
synchronize_irq()
- [Medium] usb: typec: fusb302: irq_wake_thread() is a no-op on nested
threaded IRQs
- [Low] usb: typec: fusb302: fusb302_pd_check_ack() saves masked
interrupt bits
--
commit dc7071ade05719019e8a6d55a3f3fc80613971c7
Author: Alexey Charkov <alchark@flipper.net>
usb: typec: fusb302: Acknowledge Get_Source_Cap_Extended from the driver
This commit sends a software GoodCRC from the driver upon receiving a PD 3.0
Get_Source_Cap_Extended message, which the PD 2.0 FUSB302 hardware mistakes
for a GoodCRC and leaves unacknowledged.
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index aa0e4dbe31dbd..c98a74fc7a2ac 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
[ ... ]
> @@ -1531,10 +1559,110 @@ static int fusb302_pd_reset(struct fusb302_chip *chip)
> FUSB_REG_RESET_PD_RESET);
> }
>
> +static void fusb302_pd_tx_complete(struct fusb302_chip *chip,
> + enum tcpm_transmit_status status)
> +{
> + chip->tx_pending = false;
> + tcpm_pd_transmit_complete(chip->tcpm_port, status);
> +}
> +
> +/*
> + * See whether a GoodCRC the driver sent collided before releasing chip->lock:
> + * by the next interrupt, TCPM may have started a transmission, and the
> + * COLLISION would then be reported against it. The chip sets COLLISION when
> + * TXON finds CC busy, so it is there to see by now. Keep the other bits, which
> + * reading the register clears, pending for fusb302_irq_handle().
> + */
> +static int fusb302_pd_check_ack(struct fusb302_chip *chip)
> +{
> + u8 interrupt;
> + int ret;
> +
> + /* Left set on an error, for fusb302_irq_handle() to tell COLLISION */
> + ret = fusb302_i2c_read(chip, FUSB_REG_INTERRUPT, &interrupt);
> + if (ret < 0)
> + return ret;
> + chip->ack_check = false;
> + if (interrupt & FUSB_REG_INTERRUPT_COLLISION)
> + fusb302_log(chip, "GoodCRC sent by the driver collided");
> + chip->pending_interrupt |= interrupt & ~FUSB_REG_INTERRUPT_COLLISION;
> +
> + return 0;
> +}
[Severity: Low]
Does fusb302_pd_check_ack() leave masked status bits such as
FUSB_REG_INTERRUPT_ACTIVITY set in chip->pending_interrupt?
The FUSB302 latches FUSB_REG_INTERRUPT_ACTIVITY in FUSB_REG_INTERRUPT on CC
activity even when masked in FUSB_REG_MASK, including from the GoodCRC
transmission itself. Because chip->pending_interrupt is then always
non-zero after a driver-sent GoodCRC, fusb302_irq_handle() will loop through
its "goto again" path and perform four extra I2C register reads every time,
and fusb302_pd_check_ack_async() will always wake the IRQ thread.
> +
> +/*
> + * As fusb302_pd_check_ack(), outside the IRQ thread: reading INTERRUPT clears
> + * the flags that raise the IRQ, so have the IRQ thread handle what it read
> + */
> +static void fusb302_pd_check_ack_async(struct fusb302_chip *chip)
> +{
> + if (!chip->ack_check || fusb302_pd_check_ack(chip) < 0)
> + return;
> + if (chip->pending_interrupt)
> + irq_wake_thread(chip->gpio_int_n_irq, chip);
> +}
[Severity: Medium]
Can chip->pending_interrupt be stranded when chip->gpio_int_n_irq is behind
an I2C GPIO expander?
Interrupts behind a sleeping GPIO expander are registered as nested threaded
IRQs (IRQ_NESTED_THREAD), where irqaction->thread is NULL and handlers run on
the parent controller's thread. irq_wake_thread() does nothing when
action->thread is NULL:
kernel/irq/manage.c:irq_wake_thread() {
...
for_each_action_of_desc(desc, action) {
if (action->dev_id == dev_id) {
if (action->thread)
__irq_wake_thread(desc, action);
break;
}
}
}
Since fusb302_pd_check_ack() has already read and cleared FUSB_REG_INTERRUPT
in the chip, INT_N deasserts and the events saved in chip->pending_interrupt
will not be processed until an unrelated interrupt fires.
> +
> +/*
> + * TCPM waits for the outcome of its last transmission, unless it gave up after
> + * PD_T_TCPC_TX_TIMEOUT, which it does without telling the driver
> + */
> +static bool fusb302_pd_tx_waiting(struct fusb302_chip *chip)
> +{
> + return chip->tx_pending &&
> + ktime_ms_delta(ktime_get(), chip->tx_start) <
> + PD_T_TCPC_TX_TIMEOUT;
> +}
> +
> +/*
> + * The chip only decodes the low four bits of the message type, so it mistakes
> + * Get_Source_Cap_Extended (0x11) for a GoodCRC (0x1): it neither acknowledges
> + * it nor raises GCRCSENT, only CRC_CHK, yet still queues it in the RX FIFO.
> + * Send the GoodCRC from here once the message checks out. It goes out well
> + * after 195us (tTransmit), but the partner retries with the same MessageID and
> + * usually accepts it then, rather than soft reset over and over.
> + */
> +static void fusb302_pd_rx_ack(struct fusb302_chip *chip)
> +{
> + u16 header = get_unaligned_le16(chip->rx_buf + 1);
> + struct pd_message ack = {};
> + int ret;
> +
> + if (chip->rx_discard || chip->rx_acked || pd_header_cnt(header) ||
> + pd_header_type(header) != PD_CTRL_GET_SOURCE_CAP_EXT ||
> + (chip->rx_buf[0] & FUSB302_RX_TKN_MASK) == FUSB302_RX_TKN_SOP1)
> + return;
> + chip->rx_acked = true;
> +
> + /*
> + * The outcome of a GoodCRC sent now would pass for that of the
> + * transmission TCPM waits for, so leave the partner to retry then
> + */
> + if (fusb302_pd_tx_waiting(chip)) {
> + fusb302_log(chip, "not acknowledging PD message, TX pending");
> + return;
> + }
> +
> + /*
> + * The chip's own GoodCRCs go out as revision 2.0. As it decodes only
> + * the low four bits of the message type, it treats any GoodCRC it
> + * sends as one that needs no GoodCRC in return, so it sends this one
> + * once, without retries or RETRYFAIL, whatever the retry count is.
> + */
> + ack.header = PD_HEADER_LE(PD_CTRL_GOOD_CRC, chip->pwr_role,
> + chip->data_role, PD_REV20,
> + pd_header_msgid(header), 0);
> + ret = fusb302_pd_send_message(chip, TCPC_TX_SOP, &ack);
> + if (ret >= 0)
> + chip->ack_check = true;
> + else
> + fusb302_log(chip, "cannot acknowledge PD message, ret=%d", ret);
> +}
[ ... ]
> @@ -1680,6 +1808,8 @@ static int fusb302_pd_read_message(struct fusb302_chip *chip)
> dropped++;
> }
>
> + /* The CRC checks out: acknowledge it, should the chip not have */
> + fusb302_pd_rx_ack(chip);
> chip->rx_resync = false;
> token = chip->rx_buf[0];
> memcpy(&msg, chip->rx_buf + 1, len - 5);
[Severity: Medium]
When fusb302_pd_rx_ack() withholds the GoodCRC because
fusb302_pd_tx_waiting(chip) is true (or fusb302_pd_send_message() fails),
does fusb302_pd_read_message() still pass the unacknowledged
Get_Source_Cap_Extended message to tcpm_pd_receive()?
Delivering the unacknowledged message causes tcpm_pd_rx_handler() to record
its MessageID in port->rx_msgid and start transmitting a reply (setting
chip->tx_pending = true again), while any later acknowledged retry from the
partner with the same MessageID will be dropped by TCPM as a duplicate.
[ ... ]
> @@ -1847,6 +1977,7 @@ static void fusb302_pd_rx_recheck_work(struct work_struct *work)
> if (ret < 0)
> fusb302_log(chip, "cannot read in PD message, ret=%d",
> ret);
> + fusb302_pd_check_ack_async(chip);
> }
> mutex_unlock(&chip->lock);
> }
[Severity: Medium]
Can fusb302_pd_rx_recheck_work() wake the IRQ thread after synchronize_irq()
in fusb302_pm_suspend() has already returned?
drivers/usb/typec/tcpm/fusb302.c:fusb302_pm_suspend() {
...
/* Let an IRQ being handled finish before the bus suspends */
synchronize_irq(chip->gpio_int_n_irq);
/* No RX FIFO recheck may run until the bus is back either */
cancel_delayed_work_sync(&chip->rx_recheck);
return 0;
}
CPU0 CPU1 (kworker)
fusb302_pm_suspend()
chip->irq_suspended = true
synchronize_irq(...)
fusb302_pd_rx_recheck_work()
fusb302_pd_rx_drain()
fusb302_pd_check_ack_async()
irq_wake_thread(...)
cancel_delayed_work_sync(...)
return 0
fusb302_irq_intn() <-- runs during suspend
Because cancel_delayed_work_sync(&chip->rx_recheck) runs after
synchronize_irq(), fusb302_pm_suspend() can return while the newly woken IRQ
thread is still pending or running.
[ ... ]
> @@ -2014,6 +2151,22 @@ static void fusb302_irq_handle(struct fusb302_chip *chip)
> chip->pending_interrupt = 0;
> chip->pending_interrupta = 0;
> chip->pending_interruptb = 0;
> +
> + /*
> + * A message the chip didn't acknowledge raises CRC_CHK alone: read it
> + * out first thing, as its GoodCRC is past due already. Those that came
> + * before PD was on, which nothing acknowledged, were dropped then.
> + */
> + if (chip->pd_rx_on && (interrupt & FUSB_REG_INTERRUPT_CRC_CHK) &&
> + !(interrupta & FUSB_REG_INTERRUPTA_TX_SUCCESS) &&
> + !(interruptb & FUSB_REG_INTERRUPTB_GCRCSENT)) {
> + /* Still handle the other events then */
> + ret = fusb302_pd_rx_drain(chip);
> + if (ret < 0)
> + fusb302_log(chip,
> + "cannot read in PD message, ret=%d", ret);
> + }
[ ... ]
> @@ -2061,14 +2214,19 @@ static void fusb302_irq_handle(struct fusb302_chip *chip)
> }
> }
>
> + /* Not for TCPM if it came from a GoodCRC the driver sent */
> if (interrupt & FUSB_REG_INTERRUPT_COLLISION) {
> fusb302_log(chip, "IRQ: PD collision");
> - tcpm_pd_transmit_complete(chip->tcpm_port, TCPC_TX_FAILED);
> + if (chip->ack_check)
> + chip->ack_check = false;
> + else if (chip->tx_pending)
> + fusb302_pd_tx_complete(chip, TCPC_TX_FAILED);
> }
>
> if (interrupta & FUSB_REG_INTERRUPTA_RETRYFAIL) {
> fusb302_log(chip, "IRQ: PD retry failed");
> - tcpm_pd_transmit_complete(chip->tcpm_port, TCPC_TX_FAILED);
> + if (chip->tx_pending)
> + fusb302_pd_tx_complete(chip, TCPC_TX_FAILED);
> }
[Severity: Medium]
Does draining the RX FIFO on FUSB_REG_INTERRUPT_CRC_CHK before handling
FUSB_REG_INTERRUPT_COLLISION and FUSB_REG_INTERRUPTA_RETRYFAIL from the same
interrupt snapshot mix up TX state before and after the drain?
If TCPM's transmission fails with COLLISION or RETRYFAIL in the same
interrupt snapshot as an incoming Get_Source_Cap_Extended, chip->tx_pending
has not been cleared yet when fusb302_pd_rx_drain() runs, so
fusb302_pd_rx_ack() sees fusb302_pd_tx_waiting(chip) as true and skips
sending the GoodCRC.
Conversely, if fusb302_pd_rx_ack() sends a GoodCRC during the CRC_CHK drain
and sets chip->ack_check = true while the earlier interrupt snapshot already
had FUSB_REG_INTERRUPT_COLLISION set, the COLLISION handler below will clear
the new chip->ack_check against that older COLLISION bit, skipping both any
chip->tx_pending failure report and the done-path fusb302_pd_check_ack()
call for the newly sent GoodCRC.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-fusb302-getsourcecap-v2-0-6770eb1e7945@flipper.net?part=5
next prev parent reply other threads:[~2026-11-27 11:01 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
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 [this message]
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-237201@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