|
|
@@ -545,6 +545,20 @@ static void set_rx_mode(void)
|
|
|
w32(REG_RxConfig, cfg);
|
|
|
}
|
|
|
|
|
|
+/* Bounded poll of PHYstatus.LINK. Only used to recover a link that was
|
|
|
+ * established before the probe reset; a missing cable must not delay boot. */
|
|
|
+static int wait_link(unsigned int timeout_ms)
|
|
|
+{
|
|
|
+ unsigned int t0 = get_ticks_ms();
|
|
|
+
|
|
|
+ while (!(r8(REG_PHYstatus) & PHYST_LINK)) {
|
|
|
+ if (timed_out(t0, timeout_ms))
|
|
|
+ return 0;
|
|
|
+ __asm__ volatile ("pause");
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
static void phy_autoneg(void)
|
|
|
{
|
|
|
int id1 = mdio_read(MII_PHYSID1);
|
|
|
@@ -564,8 +578,8 @@ static void phy_autoneg(void)
|
|
|
/* ---- netdev interface ---- */
|
|
|
|
|
|
/* Rings + configuration registers + PHY + RX/TX enable. Used by both the
|
|
|
- * first probe and `netreset`. */
|
|
|
-static void hw_start(void)
|
|
|
+ * first probe and `netreset`; the latter forces a fresh auto-negotiation. */
|
|
|
+static void hw_start(int restart_phy)
|
|
|
{
|
|
|
w8(REG_Cfg9346, Cfg9346_Unlock);
|
|
|
setup_rings();
|
|
|
@@ -580,7 +594,11 @@ static void hw_start(void)
|
|
|
w8(REG_Cfg9346, 0x00);
|
|
|
dbg("regs ok");
|
|
|
|
|
|
- phy_autoneg();
|
|
|
+ /* Keep a link the firmware already established: the boot network
|
|
|
+ * policy samples PHYstatus to choose between wired and WiFi, and
|
|
|
+ * restarting auto-negotiation would make a plugged cable look down. */
|
|
|
+ if (restart_phy || !(r8(REG_PHYstatus) & PHYST_LINK))
|
|
|
+ phy_autoneg();
|
|
|
dbg("phy up");
|
|
|
|
|
|
w8(REG_ChipCmd, ChipCmd_RxEnb | ChipCmd_TxEnb);
|
|
|
@@ -595,6 +613,7 @@ int r8168_init(void)
|
|
|
{
|
|
|
char buf[40];
|
|
|
unsigned int i;
|
|
|
+ int had_link;
|
|
|
|
|
|
if (inited)
|
|
|
return present ? 0 : -1;
|
|
|
@@ -632,6 +651,9 @@ int r8168_init(void)
|
|
|
}
|
|
|
|
|
|
xid = (r32(REG_TxConfig) >> 20) & 0xfcf;
|
|
|
+ /* Sample before the reset: a cable that was already linked keeps
|
|
|
+ * the boot DHCP on the wired path instead of falling back to WiFi. */
|
|
|
+ had_link = (r8(REG_PHYstatus) & PHYST_LINK) != 0;
|
|
|
|
|
|
if (hw_reset() != 0) {
|
|
|
dbg("reset timeout");
|
|
|
@@ -654,7 +676,9 @@ int r8168_init(void)
|
|
|
}
|
|
|
dbg("ring memory ok");
|
|
|
|
|
|
- hw_start();
|
|
|
+ hw_start(0);
|
|
|
+ if (had_link && !(r8(REG_PHYstatus) & PHYST_LINK))
|
|
|
+ wait_link(3000);
|
|
|
|
|
|
/* "<chip> XID <xxx> <mac>" */
|
|
|
i = 0;
|
|
|
@@ -688,7 +712,7 @@ void r8168_reset(void)
|
|
|
return;
|
|
|
}
|
|
|
read_mac();
|
|
|
- hw_start();
|
|
|
+ hw_start(1);
|
|
|
dbg("netreset done");
|
|
|
}
|
|
|
|
|
|
@@ -907,6 +931,15 @@ void r8168_print_info(void)
|
|
|
io_putchar('\n');
|
|
|
}
|
|
|
|
|
|
+/* Physical link state: kernel_main and `wifi autoconnect` prefer a wired
|
|
|
+ * link over the saved WiFi network. */
|
|
|
+static int r8168_link_up(void)
|
|
|
+{
|
|
|
+ if (!present || !mmio)
|
|
|
+ return 0;
|
|
|
+ return (r8(REG_PHYstatus) & PHYST_LINK) ? 1 : 0;
|
|
|
+}
|
|
|
+
|
|
|
void r8168_dump_regs(void)
|
|
|
{
|
|
|
static const struct {
|
|
|
@@ -986,5 +1019,5 @@ const struct netdev r8168_netdev = {
|
|
|
r8168_init, r8168_get_mac, r8168_rx, r8168_tx, r8168_print_info,
|
|
|
r8168_dump_regs, r8168_set_loopback, r8168_reset,
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
- 0,
|
|
|
+ r8168_link_up,
|
|
|
};
|