From owner-svn-src-head@FreeBSD.ORG Wed Oct 6 18:36:50 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D602A106566B; Wed, 6 Oct 2010 18:36:50 +0000 (UTC) (envelope-from ambrisko@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C50FC8FC19; Wed, 6 Oct 2010 18:36:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o96IaoPf013947; Wed, 6 Oct 2010 18:36:50 GMT (envelope-from ambrisko@svn.freebsd.org) Received: (from ambrisko@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o96Iaosw013943; Wed, 6 Oct 2010 18:36:50 GMT (envelope-from ambrisko@svn.freebsd.org) Message-Id: <201010061836.o96Iaosw013943@svn.freebsd.org> From: Doug Ambrisko Date: Wed, 6 Oct 2010 18:36:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r213489 - in head/sys: conf dev/bce X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Oct 2010 18:36:50 -0000 Author: ambrisko Date: Wed Oct 6 18:36:50 2010 New Revision: 213489 URL: http://svn.freebsd.org/changeset/base/213489 Log: Add the capability to read the complete contents of the NVRAM via sysctl dev.bce..nvram_dump Add the capability to write the complete contents of the NVRAM via sysctl dev.bce..nvram_write These are only available if the kernel option BCE_DEBUG is enabled. The nvram_write sysctl also requires the kernel option BCE_NVRAM_WRITE_SUPPORT to be enabled. These are to be used at your own caution. Since the MAC addresses are stored in the NVRAM, if you dump one NIC and restore it on another NIC the destination NIC's MAC addresses will not be preserved. A tool can be made using these sysctl's to manage the on-chip firmware. Reviewed by: davidch, yongari Modified: head/sys/conf/options head/sys/dev/bce/if_bce.c head/sys/dev/bce/if_bcereg.h Modified: head/sys/conf/options ============================================================================== --- head/sys/conf/options Wed Oct 6 18:20:39 2010 (r213488) +++ head/sys/conf/options Wed Oct 6 18:36:50 2010 (r213489) @@ -696,6 +696,7 @@ ED_SIC opt_ed.h # bce driver BCE_DEBUG opt_bce.h +BCE_NVRAM_WRITE_SUPPORT opt_bce.h SOCKBUF_DEBUG opt_global.h Modified: head/sys/dev/bce/if_bce.c ============================================================================== --- head/sys/dev/bce/if_bce.c Wed Oct 6 18:20:39 2010 (r213488) +++ head/sys/dev/bce/if_bce.c Wed Oct 6 18:36:50 2010 (r213489) @@ -343,6 +343,12 @@ static int bce_miibus_read_reg (device static int bce_miibus_write_reg (device_t, int, int, int); static void bce_miibus_statchg (device_t); +#ifdef BCE_DEBUG +static int sysctl_nvram_dump(SYSCTL_HANDLER_ARGS); +#ifdef BCE_NVRAM_WRITE_SUPPORT +static int sysctl_nvram_write(SYSCTL_HANDLER_ARGS); +#endif +#endif /****************************************************************************/ /* BCE NVRAM Access Routines */ @@ -8342,6 +8348,57 @@ bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS) } +static int +sysctl_nvram_dump(SYSCTL_HANDLER_ARGS) +{ + struct bce_softc *sc = (struct bce_softc *)arg1; + int error, i; + + if (sc->nvram_buf == NULL) { + sc->nvram_buf = malloc(sc->bce_flash_size, + M_TEMP, M_ZERO | M_WAITOK); + } + if (sc->nvram_buf == NULL) { + return(ENOMEM); + } + if (req->oldlen == sc->bce_flash_size) { + for (i = 0; i < sc->bce_flash_size; i++) { + bce_nvram_read(sc, i, &sc->nvram_buf[i], 1); + } + } + + error = SYSCTL_OUT(req, sc->nvram_buf, sc->bce_flash_size); + + return error; +} + +#ifdef BCE_NVRAM_WRITE_SUPPORT +static int +sysctl_nvram_write(SYSCTL_HANDLER_ARGS) +{ + struct bce_softc *sc = (struct bce_softc *)arg1; + int error; + + if (sc->nvram_buf == NULL) { + sc->nvram_buf = malloc(sc->bce_flash_size, + M_TEMP, M_ZERO | M_WAITOK); + } + if (sc->nvram_buf == NULL) { + return(ENOMEM); + } + bzero(sc->nvram_buf, sc->bce_flash_size); + error = SYSCTL_IN(req, sc->nvram_buf, sc->bce_flash_size); + + if (req->newlen == sc->bce_flash_size) { + bce_nvram_write(sc, 0, sc->nvram_buf , sc->bce_flash_size); + } + + + return error; +} +#endif + + /****************************************************************************/ /* Provides a sysctl interface to allow reading a CID. */ /* */ @@ -8566,6 +8623,16 @@ bce_add_sysctls(struct bce_softc *sc) "interrupts_tx", CTLFLAG_RD, &sc->interrupts_tx, 0, "Number of TX interrupts"); + SYSCTL_ADD_PROC(ctx, children, OID_AUTO, + "nvram_dump", CTLTYPE_OPAQUE | CTLFLAG_RD, + (void *)sc, 0, + sysctl_nvram_dump, "S", ""); +#ifdef BCE_NVRAM_WRITE_SUPPORT + SYSCTL_ADD_PROC(ctx, children, OID_AUTO, + "nvram_write", CTLTYPE_OPAQUE | CTLFLAG_WR, + (void *)sc, 0, + sysctl_nvram_write, "S", ""); +#endif #endif SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, Modified: head/sys/dev/bce/if_bcereg.h ============================================================================== --- head/sys/dev/bce/if_bcereg.h Wed Oct 6 18:20:39 2010 (r213488) +++ head/sys/dev/bce/if_bcereg.h Wed Oct 6 18:36:50 2010 (r213489) @@ -6790,6 +6790,7 @@ struct bce_softc /* Number of VLAN tagged frames stripped. */ u32 vlan_tagged_frames_stripped; #endif + uint8_t *nvram_buf; }; #endif /* __BCEREG_H_DEFINED */