From owner-freebsd-current@FreeBSD.ORG Wed Oct 15 00:39:48 2008 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B86DC106569A for ; Wed, 15 Oct 2008 00:39:48 +0000 (UTC) (envelope-from pyunyh@gmail.com) Received: from ti-out-0910.google.com (ti-out-0910.google.com [209.85.142.188]) by mx1.freebsd.org (Postfix) with ESMTP id 300AC8FC08 for ; Wed, 15 Oct 2008 00:39:47 +0000 (UTC) (envelope-from pyunyh@gmail.com) Received: by ti-out-0910.google.com with SMTP id d27so1326649tid.3 for ; Tue, 14 Oct 2008 17:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:received:date:from :to:subject:message-id:reply-to:mime-version:content-type :content-disposition:user-agent; bh=jVB4iGgA6HcNJafK8uxvfCyc9eOzLM0Fiww/PvbG2LY=; b=kvCG40t17rGeOh360HvBRtJKQx/vqz5X5cM1blRLwPDeinDH1BlTwplRHQU1hpwOQF gk9EsMqsmCOxJ3ejomnyit14bLev459t9l1VMfxvroVYtKrjbQeBAgx40OfSMrJmjjRO iAREzZFcEmQl40ikf7YU4VbXTpwK4jHlrPcJE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:reply-to:mime-version:content-type :content-disposition:user-agent; b=re2HYoLQcawoK+N0hI8/nJBqnXNFjPYpTrPwb+GpEWGLwo/iUQoyCPJi+7rMt17H8H sGRSjBziry/yVLD3/WfGaLiZaOLuQgHubXe9N8Mfo3ar3AjRZzlwBqixSxVBlqiqroCP DVz1EJ4k4RRRA2Emhcq6AoqWhv6t46GIiyU+Y= Received: by 10.110.39.20 with SMTP id m20mr182209tim.24.1224031186560; Tue, 14 Oct 2008 17:39:46 -0700 (PDT) Received: from michelle.cdnetworks.co.kr ([211.53.35.84]) by mx.google.com with ESMTPS id d7sm2258813tib.7.2008.10.14.17.39.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Oct 2008 17:39:44 -0700 (PDT) Received: from michelle.cdnetworks.co.kr (localhost.cdnetworks.co.kr [127.0.0.1]) by michelle.cdnetworks.co.kr (8.13.5/8.13.5) with ESMTP id m9F0bk0D019111 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 15 Oct 2008 09:37:46 +0900 (KST) (envelope-from pyunyh@gmail.com) Received: (from yongari@localhost) by michelle.cdnetworks.co.kr (8.13.5/8.13.5/Submit) id m9F0bkSG019110 for freebsd-current@FreeBSD.org; Wed, 15 Oct 2008 09:37:46 +0900 (KST) (envelope-from pyunyh@gmail.com) Date: Wed, 15 Oct 2008 09:37:45 +0900 From: Pyun YongHyeon To: freebsd-current@FreeBSD.org Message-ID: <20081015003745.GG14769@cdnetworks.co.kr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Cc: Subject: Call for testers: fxp(4) WOL X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: pyunyh@gmail.com List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 00:39:48 -0000 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've implemented WOL for fxp(4) and it works ok to me. Because there too many variants of fxp(4) hardwares I'd like to hear success/failure report before committing attached patch to tree. It seems that the following Intel 8255x supports WOL. Apparently 82557 lacks WOL capabillity. 82558 82559 82550 82551 If your suspend/resume works on your system you can also wake up your system in suspend by WOL. Thanks. -- Regards, Pyun YongHyeon --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fxp.wol.patch" Index: sys/dev/fxp/if_fxp.c =================================================================== --- sys/dev/fxp/if_fxp.c (revision 183858) +++ sys/dev/fxp/if_fxp.c (working copy) @@ -402,7 +402,7 @@ uint32_t val; uint16_t data, myea[ETHER_ADDR_LEN / 2]; u_char eaddr[ETHER_ADDR_LEN]; - int i, prefer_iomap; + int i, pmc, prefer_iomap; int error; error = 0; @@ -480,6 +480,16 @@ sc->revision = pci_get_revid(dev); /* + * Check availability of WOL. + */ + if (sc->revision >= FXP_REV_82558_A4) { + fxp_read_eeprom(sc, &data, 10, 1); + if ((data & 0x20) != 0 && + pci_find_extcap(sc->dev, PCIY_PMG, &pmc) == 0) + sc->flags |= FXP_FLAG_WOLCAP; + } + + /* * Determine whether we must use the 503 serial interface. */ fxp_read_eeprom(sc, &data, 6, 1); @@ -778,6 +788,11 @@ ifp->if_capenable |= IFCAP_HWCSUM; } + if (sc->flags & FXP_FLAG_WOLCAP) { + ifp->if_capabilities |= IFCAP_WOL_MAGIC; + ifp->if_capenable |= IFCAP_WOL_MAGIC; + } + #ifdef DEVICE_POLLING /* Inform the world we support polling. */ ifp->if_capabilities |= IFCAP_POLLING; @@ -938,17 +953,13 @@ static int fxp_shutdown(device_t dev) { - struct fxp_softc *sc = device_get_softc(dev); /* * Make sure that DMA is disabled prior to reboot. Not doing * do could allow DMA to corrupt kernel memory during the * reboot before the driver initializes. */ - FXP_LOCK(sc); - fxp_stop(sc); - FXP_UNLOCK(sc); - return (0); + return (fxp_suspend(dev)); } /* @@ -960,11 +971,26 @@ fxp_suspend(device_t dev) { struct fxp_softc *sc = device_get_softc(dev); + struct ifnet *ifp; + int pmc; + uint16_t pmstat; FXP_LOCK(sc); + ifp = sc->ifp; + if (pci_find_extcap(sc->dev, PCIY_PMG, &pmc) == 0) { + pmstat = pci_read_config(sc->dev, pmc + PCIR_POWER_STATUS, 2); + pmstat &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE); + if ((ifp->if_capenable & IFCAP_WOL_MAGIC) != 0) { + /* Request PME. */ + pmstat |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE; + sc->flags |= FXP_FLAG_WOL; + /* Reconfigure hardware to accept magic frames. */ + fxp_init_body(sc); + } + pci_write_config(sc->dev, pmc + PCIR_POWER_STATUS, pmstat, 2); + } fxp_stop(sc); - sc->suspended = 1; FXP_UNLOCK(sc); @@ -980,9 +1006,23 @@ { struct fxp_softc *sc = device_get_softc(dev); struct ifnet *ifp = sc->ifp; + int pmc; + uint16_t pmstat; FXP_LOCK(sc); + if (pci_find_extcap(sc->dev, PCIY_PMG, &pmc) == 0) { + sc->flags &= ~FXP_FLAG_WOL; + pmstat = pci_read_config(sc->dev, pmc + PCIR_POWER_STATUS, 2); + /* Disable PME and clear PME status. */ + pmstat &= ~PCIM_PSTAT_PMEENABLE; + pci_write_config(sc->dev, pmc + PCIR_POWER_STATUS, pmstat, 2); + if ((sc->flags & FXP_FLAG_WOL) != 0) { + /* Clear wakeup events. */ + CSR_READ_1(sc, FXP_CSR_PMDR); + } + } + CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET); DELAY(10); @@ -2047,8 +2087,7 @@ cbp->rcv_crc_xfer = 0; /* (don't) xfer CRC to host */ cbp->long_rx_en = sc->flags & FXP_FLAG_LONG_PKT_EN ? 1 : 0; cbp->ia_wake_en = 0; /* (don't) wake up on address match */ - cbp->magic_pkt_dis = 0; /* (don't) disable magic packet */ - /* must set wake_en in PMCSR also */ + cbp->magic_pkt_dis = sc->flags & FXP_FLAG_WOL ? 0 : 1; cbp->force_fdx = 0; /* (don't) force full duplex */ cbp->fdx_pin_en = 1; /* (enable) FDX# pin */ cbp->multi_ia = 0; /* (don't) accept multiple IAs */ @@ -2458,6 +2497,10 @@ } } #endif + if ((mask & IFCAP_WOL_MAGIC) != 0 && + (ifp->if_capabilities & IFCAP_WOL_MAGIC) != 0) + ifp->if_capenable ^= IFCAP_WOL_MAGIC; + if (mask & IFCAP_VLAN_MTU) { FXP_LOCK(sc); ifp->if_capenable ^= IFCAP_VLAN_MTU; Index: sys/dev/fxp/if_fxpreg.h =================================================================== --- sys/dev/fxp/if_fxpreg.h (revision 183858) +++ sys/dev/fxp/if_fxpreg.h (working copy) @@ -46,6 +46,7 @@ #define FXP_CSR_EEPROMCONTROL 14 /* eeprom control (2 bytes) */ #define FXP_CSR_MDICONTROL 16 /* mdi control (4 bytes) */ #define FXP_CSR_FLOWCONTROL 0x19 /* flow control (2 bytes) */ +#define FXP_CSR_PMDR 0x1B /* power management driver (1 byte) */ #define FXP_CSR_GENCONTROL 0x1C /* general control (1 byte) */ /* Index: sys/dev/fxp/if_fxpvar.h =================================================================== --- sys/dev/fxp/if_fxpvar.h (revision 183858) +++ sys/dev/fxp/if_fxpvar.h (working copy) @@ -193,6 +193,8 @@ #define FXP_FLAG_DEFERRED_RNR 0x0200 /* DEVICE_POLLING deferred RNR */ #define FXP_FLAG_EXT_RFA 0x0400 /* extended RFDs for csum offload */ #define FXP_FLAG_SAVE_BAD 0x0800 /* save bad pkts: bad size, CRC, etc */ +#define FXP_FLAG_WOLCAP 0x1000 /* WOL supported */ +#define FXP_FLAG_WOL 0x2000 /* WOL active */ /* Macros to ease CSR access. */ #define CSR_READ_1(sc, reg) bus_read_1(sc->fxp_res[0], reg) --Kj7319i9nmIyA2yE--