From owner-svn-src-projects@FreeBSD.ORG Sun Dec 21 19:13:53 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5C84510656D9; Sun, 21 Dec 2008 19:13:53 +0000 (UTC) (envelope-from sam@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4C1438FC16; Sun, 21 Dec 2008 19:13:53 +0000 (UTC) (envelope-from sam@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBLJDrXA040061; Sun, 21 Dec 2008 19:13:53 GMT (envelope-from sam@svn.freebsd.org) Received: (from sam@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBLJDria040058; Sun, 21 Dec 2008 19:13:53 GMT (envelope-from sam@svn.freebsd.org) Message-Id: <200812211913.mBLJDria040058@svn.freebsd.org> From: Sam Leffler Date: Sun, 21 Dec 2008 19:13:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186376 - projects/cambria/sys/arm/xscale/ixp425 X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Dec 2008 19:13:53 -0000 Author: sam Date: Sun Dec 21 19:13:52 2008 New Revision: 186376 URL: http://svn.freebsd.org/changeset/base/186376 Log: move npe fw loading to the core code so it can used by other npe-related drivers Modified: projects/cambria/sys/arm/xscale/ixp425/if_npe.c projects/cambria/sys/arm/xscale/ixp425/ixp425_npe.c projects/cambria/sys/arm/xscale/ixp425/ixp425_npevar.h Modified: projects/cambria/sys/arm/xscale/ixp425/if_npe.c ============================================================================== --- projects/cambria/sys/arm/xscale/ixp425/if_npe.c Sun Dec 21 19:13:30 2008 (r186375) +++ projects/cambria/sys/arm/xscale/ixp425/if_npe.c Sun Dec 21 19:13:52 2008 (r186376) @@ -157,7 +157,6 @@ struct npe_softc { * assumptions probably need to be handled through hints. */ static const struct { - uint32_t imageid; /* default fw image */ uint32_t macbase; uint32_t miibase; int phy; /* phy id */ @@ -167,7 +166,6 @@ static const struct { uint8_t tx_doneqid; } npeconfig[NPE_MAX] = { [NPE_A] = { - .imageid = IXP425_NPE_A_IMAGEID, .macbase = IXP435_MAC_A_HWBASE, .miibase = IXP425_MAC_C_HWBASE, .phy = 2, @@ -177,7 +175,6 @@ static const struct { .tx_doneqid = 31 }, [NPE_B] = { - .imageid = IXP425_NPE_B_IMAGEID, .macbase = IXP425_MAC_B_HWBASE, .miibase = IXP425_MAC_C_HWBASE, .phy = 0, @@ -187,7 +184,6 @@ static const struct { .tx_doneqid = 31 }, [NPE_C] = { - .imageid = IXP425_NPE_C_IMAGEID, .macbase = IXP425_MAC_C_HWBASE, .miibase = IXP425_MAC_C_HWBASE, .phy = 1, @@ -644,22 +640,6 @@ override_unit(device_t dev, const char * return 1; } -static int -override_imageid(device_t dev, const char *resname, uint32_t *val) -{ - int unit = device_get_unit(dev); - int resval; - - if (resource_int_value("npe", unit, resname, &resval) != 0) - return 0; - /* XXX validate */ - if (bootverbose) - device_printf(dev, "using npe.%d.%s=0x%x override\n", - unit, resname, resval); - *val = resval; - return 1; -} - static void npe_mac_reset(struct npe_softc *sc) { @@ -677,7 +657,6 @@ npe_activate(device_t dev) { struct npe_softc * sc = device_get_softc(dev); int error, i, macbase, miibase; - uint32_t imageid, msg[2]; /* * Setup NEP ID, MAC, and MII bindings. We allow override @@ -722,35 +701,12 @@ npe_activate(device_t dev) sc->sc_miih = sc->sc_ioh; /* - * Load NPE firmware and start it running. We assume - * that minor version bumps remain compatible so probe - * the firmware image starting with the expected version - * and then bump the minor version up to the max. + * Load NPE firmware and start it running. */ - if (!override_imageid(dev, "imageid", &imageid)) - imageid = npeconfig[sc->sc_npeid].imageid; - for (;;) { - error = ixpnpe_init(sc->sc_npe, "npe_fw", imageid); - if (error == 0) - break; - /* ESRCH is returned when the requested image is not present */ - if (error != ESRCH) { - device_printf(dev, "cannot init NPE (error %d)\n", - error); - return error; - } - /* bump the minor version up to the max possible */ - if (NPEIMAGE_MINOR(imageid) == 0xff) { - device_printf(dev, "cannot locate firmware " - "(imageid 0x%08x)\n", imageid); - return error; - } - imageid++; - } - /* NB: firmware should respond with a status msg */ - if (ixpnpe_recvmsg_sync(sc->sc_npe, msg) != 0) { - device_printf(dev, "firmware did not respond as expected\n"); - return EIO; + error = ixpnpe_init(sc->sc_npe); + if (error != 0) { + device_printf(dev, "cannot init NPE (error %d)\n", error); + return error; } /* probe for PHY */ @@ -984,7 +940,6 @@ npe_setmac(struct npe_softc *sc, u_char WR4(sc, NPE_MAC_UNI_ADDR_4, eaddr[3]); WR4(sc, NPE_MAC_UNI_ADDR_5, eaddr[4]); WR4(sc, NPE_MAC_UNI_ADDR_6, eaddr[5]); - } static void Modified: projects/cambria/sys/arm/xscale/ixp425/ixp425_npe.c ============================================================================== --- projects/cambria/sys/arm/xscale/ixp425/ixp425_npe.c Sun Dec 21 19:13:30 2008 (r186375) +++ projects/cambria/sys/arm/xscale/ixp425/ixp425_npe.c Sun Dec 21 19:13:52 2008 (r186376) @@ -112,6 +112,7 @@ struct ixpnpe_softc { struct mtx sc_mtx; /* mailbox lock */ uint32_t sc_msg[2]; /* reply msg collected in ixpnpe_intr */ int sc_msgwaiting; /* sc_msg holds valid data */ + int sc_npeid; int validImage; /* valid ucode image loaded */ int started; /* NPE is started */ @@ -294,6 +295,7 @@ ixpnpe_attach(device_t dev, int npeid) sc->sc_dev = dev; sc->sc_iot = sa->sc_iot; mtx_init(&sc->sc_mtx, device_get_nameunit(dev), "npe driver", MTX_DEF); + sc->sc_npeid = npeid; sc->sc_size = config->size; sc->insMemSize = config->ins_memsize; /* size of instruction memory */ @@ -361,7 +363,7 @@ ixpnpe_start_locked(struct ixpnpe_softc if (!sc->started) { error = npe_cpu_start(sc); if (error == 0) - sc->started = 1; + sc->started = 1; } else error = 0; @@ -442,8 +444,9 @@ npe_findimage(struct ixpnpe_softc *sc, return ESRCH; } -int -ixpnpe_init(struct ixpnpe_softc *sc, const char *imageName, uint32_t imageId) +static int +ixpnpe_load_firmware(struct ixpnpe_softc *sc, const char *imageName, + uint32_t imageId) { static const char *devname[4] = { "IXP425", "IXP435/IXP465", "DeviceID#2", "DeviceID#3" }; @@ -504,6 +507,73 @@ done: return error; } +static int +override_imageid(device_t dev, const char *resname, uint32_t *val) +{ + int unit = device_get_unit(dev); + int resval; + + if (resource_int_value("npe", unit, resname, &resval) != 0) + return 0; + /* XXX validate */ + if (bootverbose) + device_printf(dev, "using npe.%d.%s=0x%x override\n", + unit, resname, resval); + *val = resval; + return 1; +} + +int +ixpnpe_init(struct ixpnpe_softc *sc) +{ + static const uint32_t npeconfig[NPE_MAX] = { + [NPE_A] = IXP425_NPE_A_IMAGEID, + [NPE_B] = IXP425_NPE_B_IMAGEID, + [NPE_C] = IXP425_NPE_C_IMAGEID, + }; + uint32_t imageid, msg[2]; + int error; + + if (sc->started) + return 0; + /* + * Load NPE firmware and start it running. We assume + * that minor version bumps remain compatible so probe + * the firmware image starting with the expected version + * and then bump the minor version up to the max. + */ + if (!override_imageid(sc->sc_dev, "imageid", &imageid)) + imageid = npeconfig[sc->sc_npeid]; + for (;;) { + error = ixpnpe_load_firmware(sc, "npe_fw", imageid); + if (error == 0) + break; + /* + * ESRCH is returned when the requested image + * is not present + */ + if (error != ESRCH) { + device_printf(sc->sc_dev, + "cannot init NPE (error %d)\n", error); + return error; + } + /* bump the minor version up to the max possible */ + if (NPEIMAGE_MINOR(imageid) == 0xff) { + device_printf(sc->sc_dev, "cannot locate firmware " + "(imageid 0x%08x)\n", imageid); + return error; + } + imageid++; + } + /* NB: firmware should respond with a status msg */ + if (ixpnpe_recvmsg_sync(sc, msg) != 0) { + device_printf(sc->sc_dev, + "firmware did not respond as expected\n"); + return EIO; + } + return 0; +} + int ixpnpe_getfunctionality(struct ixpnpe_softc *sc) { Modified: projects/cambria/sys/arm/xscale/ixp425/ixp425_npevar.h ============================================================================== --- projects/cambria/sys/arm/xscale/ixp425/ixp425_npevar.h Sun Dec 21 19:13:30 2008 (r186375) +++ projects/cambria/sys/arm/xscale/ixp425/ixp425_npevar.h Sun Dec 21 19:13:52 2008 (r186376) @@ -111,8 +111,7 @@ void ixpnpe_detach(struct ixpnpe_softc * int ixpnpe_stopandreset(struct ixpnpe_softc *); int ixpnpe_start(struct ixpnpe_softc *); int ixpnpe_stop(struct ixpnpe_softc *); -int ixpnpe_init(struct ixpnpe_softc *, - const char *imageName, uint32_t imageId); +int ixpnpe_init(struct ixpnpe_softc *); int ixpnpe_getfunctionality(struct ixpnpe_softc *sc); int ixpnpe_sendmsg_async(struct ixpnpe_softc *, const uint32_t msg[2]);