Commit 43897a4e authored by Dean Sellers's avatar Dean Sellers Committed by Anas Nashif
Browse files

drivers: ethernet: enc28j60: Fix carrier on race on init



If there is a carrier (cable plugged in) on device initialisation
there is a race between the interrupt service and the L2 init.

Signed-off-by: default avatarDean Sellers <dsellers@evos.com.au>
parent 01f27400
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -713,7 +713,14 @@ static void eth_enc28j60_rx_thread(void *p1, void *p2, void *p3)
			eth_enc28j60_read_phy(dev, ENC28J60_PHY_PHSTAT2, &phstat2);
			if (phstat2 & ENC28J60_BIT_PHSTAT2_LSTAT) {
				LOG_INF("%s: Link up", dev->name);
				/* We may have been interrupted before L2 init complete
				 * If so flag that the carrier should be set on in init
				 */
				if (context->iface_initialized) {
					net_eth_carrier_on(context->iface);
				} else {
					context->iface_carrier_on_init = true;
				}
			} else {
				LOG_INF("%s: Link down", dev->name);

@@ -751,7 +758,12 @@ static void eth_enc28j60_iface_init(struct net_if *iface)

	ethernet_init(iface);

	/* The device may have already interrupted us to flag link UP */
	if (context->iface_carrier_on_init) {
		net_if_carrier_on(iface);
	} else {
		net_if_carrier_off(iface);
	}
	context->iface_initialized = true;
}

+1 −0
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ struct eth_enc28j60_runtime {
	struct k_sem tx_rx_sem;
	struct k_sem int_sem;
	bool iface_initialized : 1;
	bool iface_carrier_on_init : 1;
};

#endif /*_ENC28J60_*/