From ae74dc8ae0bff96894d560ec20452bc045b4dd7a Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 5 May 2025 20:35:59 +0000 Subject: [PATCH] firewall: wait for PHY IRQ before starting stack Depends on https://github.com/CHERIoT-Platform/cheriot-rtos/pull/530 Work towards https://github.com/lowRISC/sonata-system/issues/410 --- lib/firewall/firewall.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/firewall/firewall.cc b/lib/firewall/firewall.cc index a55710e..d3436ee 100644 --- a/lib/firewall/firewall.cc +++ b/lib/firewall/firewall.cc @@ -1186,6 +1186,22 @@ bool ethernet_driver_start(std::atomic *state) auto ðernet = lazy_network_interface(); ethernet.mac_address_set(mac_address()); initialize_dns_resolver(firewall_mac_address_get()); + + /* + * If the interface link isn't ready, wait for any IRQ. Acknowledging + * it can't hurt, since the driver's thread's about to go poll for frames. + */ + { + uint32_t firstInterrupt = ethernet.receive_interrupt_value(); + if (!ethernet.phy_link_status()) + { + Debug::log("Link not ready; wait for first IRQ"); + Timeout t{UnlimitedTimeout}; + ethernet.receive_interrupt_complete(&t, firstInterrupt); + Debug::log("Link ready? {}", ethernet.phy_link_status()); + } + } + // Poke the barrier and make the driver thread start. barrier = 2; barrier.notify_one();