From 49680c44f6f5b4935ea7619301f5b8ad48ecc515 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 22 Jun 2025 04:02:22 -0400 Subject: kernel: e1000: Reset the controller before init Signed-off-by: Ian Moffett --- sys/dev/phy/e1000.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'sys/dev/phy/e1000.c') diff --git a/sys/dev/phy/e1000.c b/sys/dev/phy/e1000.c index 9f1b492..95efe6d 100644 --- a/sys/dev/phy/e1000.c +++ b/sys/dev/phy/e1000.c @@ -242,6 +242,29 @@ e1000_read_macaddr(struct e1000_nic *np, struct netif_addr *addr) return 0; } +/* + * Reset the entire E1000 + */ +static int +e1000_reset(struct e1000_nic *np) +{ + uint32_t ctl, *ctl_p; + int error; + + ctl_p = PTR_OFFSET(np->vap, E1000_CTL); + ctl = mmio_read32(&ctl_p); + ctl |= E1000_CTL_RST; + mmio_write32(&ctl_p, ctl); + + error = e1000_poll_reg(ctl_p, E1000_CTL_RST, false); + if (error < 0) { + pr_error("reset timeout\n"); + return error; + } + + return 0; +} + /* * Initialize an E1000(e) chip */ @@ -251,6 +274,19 @@ e1000_chip_init(struct e1000_nic *np) struct netif_addr *addr = &netif.addr; int error; + /* + * To ensure that BIOS/UEFI or whatever firmware got us + * here didn't fuck anything up in the process or at the + * very least, put the controller in a seemingly alright + * state that gives us a suprise screwing in the future, + * we'll reset everything to its default startup state. + * + * Better safe than sorry... + */ + if ((error = e1000_reset(np)) < 0) { + return error; + } + eeprom_query(np); if ((error = e1000_read_macaddr(np, addr)) < 0) { return error; -- cgit v1.2.3