svn commit: r186376 - projects/cambria/sys/arm/xscale/ixp425
Sam Leffler
sam at FreeBSD.org
Sun Dec 21 11:13:53 PST 2008
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]);
More information about the svn-src-projects
mailing list