Hello, a patch to enable wake-on-lan (with magic packet) in the bge network driver. Maybe you can add it. Developed this for a HP ProLiant MicroServer N40L machine with a bge0: <HP NC107i PCIe Gigabit Server Adapter, ASIC rev. 0x5784100> mem 0xfe9f0000-0xfe9fffff irq 18 at device 0.0 on pci2 Kind regards, Christian. Fix: Patch attached with submission follows:
Responsible Changed From-To: freebsd-bugs->freebsd-net Over to maintainer(s).
Responsible Changed From-To: freebsd-net->hiren Grab.
This is a bit updated patch from submitter which applied on a few months old CURRENT. Index: sys/dev/bge/if_bge.c =================================================================== --- sys/dev/bge/if_bge.c (revision 250303) +++ sys/dev/bge/if_bge.c (working copy) @@ -475,6 +475,7 @@ static void bge_stop_fw(struct bge_softc *); static int bge_reset(struct bge_softc *); static void bge_link_upd(struct bge_softc *); +static void bge_setwol(struct bge_softc *); static void bge_ape_lock_init(struct bge_softc *); static void bge_ape_read_fw_ver(struct bge_softc *); @@ -3663,7 +3664,7 @@ IFQ_SET_READY(&ifp->if_snd); ifp->if_hwassist = sc->bge_csum_features; ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING | - IFCAP_VLAN_MTU; + IFCAP_VLAN_MTU | IFCAP_WOL_MAGIC; if ((sc->bge_flags & (BGE_FLAG_TSO | BGE_FLAG_TSO3)) != 0) { ifp->if_hwassist |= CSUM_TSO; ifp->if_capabilities |= IFCAP_TSO4 | IFCAP_VLAN_HWTSO; @@ -5914,6 +5915,8 @@ sc = device_get_softc(dev); BGE_LOCK(sc); bge_stop(sc); + bge_reset(sc); + bge_setwol(sc); BGE_UNLOCK(sc); return (0); @@ -6612,3 +6615,33 @@ } return (*func == NULL ? ENXIO : 0); } + +static void +bge_setwol(struct bge_softc *sc) +{ + struct ifnet *ifp; + uint16_t pmstat; + int pmc; + + ifp = sc->bge_ifp; + + if ((ifp->if_capenable & IFCAP_WOL_MAGIC) == 0) + return; + + if (pci_find_cap(sc->bge_dev, PCIY_PMG, &pmc) != 0) + return; + + BGE_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_MAGIC_PKT_ENB); + + BGE_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); + BGE_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); + + BGE_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); + + /* Request PME. */ + pmstat = pci_read_config(sc->bge_dev, + pmc + PCIR_POWER_STATUS, 2); + pmstat |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE; + pci_write_config(sc->bge_dev, + pmc + PCIR_POWER_STATUS, pmstat, 2); +} According to yongari@: "The patch is not enough to cover other high-end controllers. The patch may work on consumer grade controllers used on Notebooks but it will break advanced controllers with ASF/IPMI firmware as well as TBI/Fiber PHY interface. Before adding support for WOL, bge(4) needs a reliable way to suspend/resume the controller and should have controller firmware know driver state as well as saving/restoring reference clock. If suspend/resume does not work its firmware will take over controller's functionality programmed by driver and WOL wouldn't work as expected. That part of magic is mostly undocumented and different controller requires different procedures." I guess its much more work than I can handle atm. I will put it back to the queue. Thanks to Pyun for his inputs and my bad for hanging on to this bug for so long.
Responsible Changed From-To: hiren->freebsd-net
I'm willing to take this on if someone can donate a high end controller to
Let's try this again... I'm willing to take this on if someone can donate an appropriate controller to me. So far a modified (for a recent CURRENT) version of the patch works.
I have a couple of working patches (11-CURRENT and 10-STABLE) which work. I'm still testing, though the only machine I have that has bge is a laptop (running both CURRENT and STABLE). I'll post them in Phabricator in a few days. In the mean time I'll take ownership of the PR for now.
Created attachment 156970 [details] Almost working patch This patch sort-of works. WOL works however on subsequent shutdown my laptop will power off and immediately power on again. Following that I can power it off. I'm unsure whether this is the fault of the patch or if I have buggy hardware. I'll post a final patch once this has been solved.
(In reply to Cy Schubert from comment #8) Hi Cy Schubert, I got a HP microserver n40l with a broadcom chip and is running 11-RELEASE, I dont mind testing the WOL patch. Please let me know if you are still interested. Thanks!
Read through PR/171744.The problem with my patch is that even though it works on my laptop, it advertises its speed while asleep at 1Gb. That can have consequences for some hardware. Until I find out how to do that I'd suggest holding off for now. I'll close this PR as a DUP of PR/171744. *** This bug has been marked as a duplicate of bug 171744 ***
^Triage: Update duplicating issue ID so all previous point to the same (and latest) one *** This bug has been marked as a duplicate of bug 218579 ***