From: <Parthiban.Veerasooran@microchip.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<edumazet@kernel.org>, <kuba@kernel.org>, <pabeni@redhat.com>,
<hkallweit1@gmail.com>, <linux@armlinux.org.uk>,
<netdev@vger.kernel.org>, <UNGLinuxDriver@microchip.com>
Subject: Re: [PATCH net-next RESEND v4 2/4] net: ethernet: oa_tc6: deliver the PHY interrupt to phylib
Date: Tue, 1 Dec 2026 13:55:28 +0000 [thread overview]
Message-ID: <88af4553-40f3-4b0b-896b-73f62aeb8f6a@microchip.com> (raw)
In-Reply-To: <179561192720.3135.12144826803876923892@kernel.org>
On 25/11/26 6:35 pm, netdev-bot+sashiko@kernel.org wrote:
>> +static void oa_tc6_phy_irq_work(struct work_struct *work)
>> +{
>> + struct oa_tc6 *tc6 = container_of(work, struct oa_tc6, phy_irq_work);
>> + int ret;
>> +
>> + /* Dispatched off the SPI chunk-processing thread so that
>> + * phy_interrupt() taking phydev->lock and issuing synchronous SPI
>> + * control transfers from PHY handle_interrupt() cannot stall the single
>> + * thread pumping TX/RX data chunks.
>> + */
>> + handle_nested_irq(tc6->phy_virq);
>> +
>> + ret = oa_tc6_phy_irq_unmask_hw(tc6);
>> + if (ret)
>> + dev_err(&tc6->spi->dev, "Failed to unmask PHY interrupt: %d\n",
>> + ret);
>
> [Severity: Medium]
> Does this path act on PHYINT again for every remaining chunk of the
> same transfer?
>
> oa_tc6_process_spi_data_rx_buf() walks all no_of_rx_chunks footers of
> a transfer that has already been clocked in. If PHYINT was pending,
> every one of those footers has EXST set.
>
> Chunk 0 gets here, sets PHYINTM through oa_tc6_phy_irq_mask_hw() and
> schedules phy_irq_work. Writing value back to STATUS0 does not clear
> PHYINT, though. It reflects the PHY's own status and stays set until
> the PHY driver acks it from the worker.
>
> So for chunks 1 .. no_of_rx_chunks - 1 the STATUS0 read returns
> non-zero again and the !value early return is skipped. Each chunk then
> does a STATUS0 write plus a read and a write of INT_MASK0. That is four
> synchronous control transfers per chunk on the realtime thread that
> pumps TX/RX data, which is the cost the masking was meant to avoid.
>
> The repeated schedule_work() is also not always a no-op. The workqueue
> clears the pending bit before calling oa_tc6_phy_irq_work(). If the
> worker is already running on another CPU and has not yet acked the
> PHY, this queues it a second time. The second run calls
> handle_nested_irq() with nothing pending, the PHY driver returns
> IRQ_NONE, and note_interrupt() counts it as unhandled.
>
> The commit message says a reschedule on an already-pending work item
> can't duplicate an event. That only holds while the work is still
> pending, not while it is executing.
>
> The same thing happens outside the multi-chunk case. Say genirq has
> masked the IRQ, so phy_irq_masked is true (for example after
> disable_irq() from phylib), while the PHY line is still asserted. Any
> other STATUS0 event, such as an RX buffer overflow, will then see
> PHYINT here, mask it again over SPI and schedule the worker anyway.
>
> Would it make sense to skip this block when PHYINTM is already set?
> One way would be to keep a shadow of the hardware mask bit under
> phy_irq_lock, and also to ignore PHYINT while phy_irq_masked is true.
Agreed. I will add a phy_irq_dispatched bool to struct oa_tc6 as a
shadow of the hardware mask bit, separate from phy_irq_masked which
carries genirq's desired state only. The gate in
oa_tc6_process_extended_status() becomes:
if (tc6->phy_virq && !READ_ONCE(tc6->phy_irq_masked) &&
!READ_ONCE(tc6->phy_irq_dispatched) &&
FIELD_GET(OA_TC6_STATUS0_PHY_INT, value)) {
WRITE_ONCE(tc6->phy_irq_dispatched, true);
ret = oa_tc6_phy_irq_mask_hw(tc6);
if (ret) {
...
WRITE_ONCE(tc6->phy_irq_dispatched, false);
} else {
schedule_work(&tc6->phy_irq_work);
}
}
phy_irq_dispatched is cleared after unmask_hw() in the worker (see next
reply). It is also cleared on mask_hw() failure so the next chunk can
retry. This solves the multi-chunk redundant transfers, the
double-dispatch race, and the genirq-disabled case.
>
> [Severity: Medium]
> If oa_tc6_phy_irq_unmask_hw() fails here, does the PHY interrupt stay
> masked in hardware for good?
>
> On every PHYINT event, oa_tc6_process_extended_status() sets
> OA_TC6_INT_MASK0_PHY_INT_MASK through oa_tc6_phy_irq_mask_hw() before it
> schedules this work:
>
> if (tc6->phy_virq && FIELD_GET(OA_TC6_STATUS0_PHY_INT, value)) {
> ret = oa_tc6_phy_irq_mask_hw(tc6);
> ...
> else
> schedule_work(&tc6->phy_irq_work);
> }
>
> This worker is the only place that clears the bit again. Either SPI
> control transfer inside oa_tc6_phy_irq_unmask_hw() can fail, with a
> spi_sync() error or with -EPROTO from the control reply echo check. In
> that case the worker logs and returns. It does not retry or reschedule.
>
> phy_irq_masked stays false, so genirq and phylib treat the IRQ as
> enabled. oa_tc6_phy_irq_bus_sync_unlock() only runs on enable_irq(),
> disable_irq(), request_irq() or free_irq(), none of which happen in
> steady state. phydev->irq is valid, so phylib does not poll either.
>
> Would later link and PLCA status changes then be lost until the
> interface is rebound or goes through suspend/resume?
Yes, that is a real gap. I will update the code to reschedule the worker
on unmask_hw() failure:
ret = oa_tc6_phy_irq_unmask_hw(tc6);
WRITE_ONCE(tc6->phy_irq_dispatched, false);
if (ret) {
dev_err(...);
schedule_work(&tc6->phy_irq_work);
}
The retry run calls handle_nested_irq() with nothing pending (IRQ_NONE,
harmless) and retries unmask_hw() until the SPI bus recovers. The
explicit reschedule also covers the idle-link case where no SPI data
traffic would otherwise re-trigger dispatch via phy_irq_dispatched.
>
> [Severity: Medium]
> Can a PHY event that latches while PHYINTM is set be missed here?
>
> handle_nested_irq() lets the PHY driver read and ack its status. After
> that, this worker clears PHYINTM. It does not re-read STATUS0, and it
> does not wake the SPI thread (int_flag plus wakeup) to look for a
> PHYINT that became pending while the mask was set.
>
> Take an event that arrives between the PHY driver's ack and the
> INT_MASK0 write. It is only seen if the MAC-PHY re-asserts IRQn when an
> already-set status bit is unmasked. PHYINT is only noticed from a footer
> with EXST set. Otherwise the SPI thread runs only on IRQn or pending TX,
> so on an idle link the event could stay unprocessed.
>
> The commit message says:
>
> PHYINT is level triggered and stays asserted until acked, so a no-op
> reschedule on an already-pending work item can't lose or duplicate an
> event.
>
> Does this cover the MAC-PHY IRQn side, or only the PHY-side source?
>
> phylib's resume path has the same dependency. mdio_bus_phy_resume()
> does:
>
> enable_irq(phydev->irq);
> irq_wake_thread(phydev->irq, phydev);
>
> irq_wake_thread() only does something when action->thread is set. That
> is not the case for the nested-thread IRQ created with
> irq_set_nested_thread() in oa_tc6_phy_irq_map(). So a PHY interrupt
> postponed during suspend would only be delivered again if the hardware
> re-signals after the unmask in oa_tc6_phy_irq_bus_sync_unlock().
>
> Would it make sense to re-check STATUS0, or kick the SPI thread, after
> unmasking?
The hardware closes this window. PHYINT is level-triggered at the
MAC-PHY: when PHYINTM is cleared by oa_tc6_phy_irq_unmask_hw(), the MAC-PHY
immediately re-asserts IRQn if PHYINT is still active in STATUS0. The
SPI threaded IRQ fires, processes the next footer with EXST set, and
oa_tc6_process_extended_status() re-dispatches the event through the
normal path. No STATUS0 re-read or manual SPI thread kick is needed.
The same applies on resume: oa_tc6_phy_irq_bus_sync_unlock() clears
PHYINTM. If a PHY interrupt was postponed during suspend, the hardware
re-asserts IRQn at that point and delivers the event without
irq_wake_thread(). This behaviour is confirmed for the LAN865X MAC-PHY.
>
>> +}
>
> [ ... ]
>
>> @@ -624,6 +821,7 @@ static void oa_tc6_phy_exit(struct oa_tc6 *tc6)
>> if (tc6->quirk_flags & OA_TC6_BROKEN_PHY)
>> return;
>>
>> + cancel_work_sync(&tc6->phy_irq_work);
>
> [Severity: Medium]
> Can this hit the WARN_ON(!work->func) in __flush_work() when
> OA_TC6_PHY_INT is not set?
>
> The only INIT_WORK() for phy_irq_work is in oa_tc6_phy_irq_setup(). That
> function is only reached from oa_tc6_mdiobus_register() when the quirk
> is set:
>
> if (tc6->quirk_flags & OA_TC6_PHY_INT) {
> ret = oa_tc6_phy_irq_setup(tc6);
>
> In this commit lan865x_probe() still does:
>
> priv->tc6 = oa_tc6_init(spi, netdev, NULL);
>
> so quirk_flags is 0 and phy_irq_work is still zeroed from
> devm_kzalloc. Teardown then goes:
>
> lan865x_remove()
> oa_tc6_exit()
> oa_tc6_phy_exit()
> cancel_work_sync(&tc6->phy_irq_work)
> __cancel_work_sync()
> __flush_work()
> WARN_ON(!work->func)
>
> The same applies to the lan865x_probe() error paths after
> oa_tc6_init(). It also applies to the phy_exit label inside
> oa_tc6_init() itself, which is taken when oa_tc6_enable_data_transfer(),
> oa_tc6_update_buffer_status_from_register() or
> devm_request_threaded_irq() fails.
>
> The next patch, "microchip: lan865x: enable PHY interrupt via virtual
> IRQ", makes lan865x pass OA_TC6_PHY_INT, which removes the in-tree
> trigger at the end of the series. But oa_tc6_init() still accepts
> quirks == NULL, and this patch on its own breaks bisection.
>
> Could INIT_WORK() be done unconditionally in oa_tc6_init(), next to
> mutex_init(&tc6->phy_irq_lock)? Alternatively, cancel_work_sync() here
> could be gated on OA_TC6_PHY_INT or tc6->phy_virq.
Agreed, I will gate cancel_work_sync() on tc6->phy_virq (set only when
the IRQ infrastructure is fully initialised), which also fixes the
bisection break you identified:
if (tc6->phy_virq)
cancel_work_sync(&tc6->phy_irq_work);
phy_disconnect(tc6->phydev);
This avoids adding an INIT_WORK() cost for drivers that don't set
OA_TC6_PHY_INT.
Thanks,
Parthiban V
next prev parent reply other threads:[~2026-12-01 13:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:49 [PATCH net-next RESEND v4 0/4] net: microchip_t1s: fix collision detection on PLCA status change Parthiban Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 1/4] net: phy: " Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-11-27 5:23 ` Parthiban.Veerasooran
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 2/4] net: ethernet: oa_tc6: deliver the PHY interrupt to phylib Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran [this message]
2026-11-24 12:49 ` [PATCH net-next RESEND v4 3/4] microchip: lan865x: enable PHY interrupt via virtual IRQ Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 4/4] net: phy: microchip_t1s: fix collision detection for LAN867X Rev.D0 Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:52 ` [PATCH net-next RESEND v4 0/4] net: microchip_t1s: fix collision detection on PLCA status change netdev-bot+sinfo
2026-11-25 3:28 ` Parthiban.Veerasooran
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=88af4553-40f3-4b0b-896b-73f62aeb8f6a@microchip.com \
--to=parthiban.veerasooran@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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