- Return error status instead of value in get_e().

- Modify ep_get_macaddr() to return an error status.
- Reverse the return value logic of eeprom_rdy().
This commit is contained in:
Matthew N. Dodd 2003-03-29 21:44:46 +00:00
parent 63b9b38eb8
commit bb25efadc4
4 changed files with 71 additions and 32 deletions

View File

@ -123,42 +123,54 @@ eeprom_rdy(sc)
}
if (i >= MAX_EEPROMBUSY) {
printf("ep%d: eeprom failed to come ready.\n", sc->unit);
return (0);
return (ENXIO);
}
return (1);
return (0);
}
/*
* get_e: gets a 16 bits word from the EEPROM. we must have set the window
* before
*/
u_int16_t
get_e(sc, offset)
int
get_e(sc, offset, result)
struct ep_softc *sc;
u_int16_t offset;
u_int16_t *result;
{
if (!eeprom_rdy(sc))
if (eeprom_rdy(sc))
return (ENXIO);
outw(BASE + EP_W0_EEPROM_COMMAND,
(EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
if (eeprom_rdy(sc))
return (ENXIO);
(*result) = inw(BASE + EP_W0_EEPROM_DATA);
return (0);
outw(BASE + EP_W0_EEPROM_COMMAND, (EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
if (!eeprom_rdy(sc))
return (0);
return (inw(BASE + EP_W0_EEPROM_DATA));
}
void
int
ep_get_macaddr(sc, addr)
struct ep_softc * sc;
u_char * addr;
{
int i;
u_int16_t * macaddr = (u_int16_t *)addr;
u_int16_t result;
int error;
u_int16_t * macaddr;
macaddr = (u_int16_t *)addr;
GO_WINDOW(0);
for(i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
macaddr[i] = htons(get_e(sc, i));
error = get_e(sc, i, &result);
if (error)
return (error);
macaddr[i] = htons(result);
}
return;
return (0);
}
int
@ -167,6 +179,7 @@ ep_alloc(device_t dev)
struct ep_softc * sc = device_get_softc(dev);
int rid;
int error = 0;
u_int16_t result;
rid = 0;
sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
@ -200,8 +213,16 @@ ep_alloc(device_t dev)
GO_WINDOW(0);
sc->epb.cmd_off = 0;
sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID);
sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);
error = get_e(sc, EEPROM_PROD_ID, &result);
if (error)
goto bad;
sc->epb.prod_id = result;
error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
if (error)
goto bad;
sc->epb.res_cfg = result;
bad:
return (error);
@ -259,10 +280,15 @@ ep_attach(sc)
u_short * p;
int i;
int attached;
int error;
sc->gone = 0;
ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
if (error) {
device_printf(sc->dev, "Unable to retrieve Ethernet address!\n");
return (ENXIO);
}
/*
* Setup the station address

View File

@ -38,8 +38,8 @@
#include <net/if_arp.h>
#include <net/if_media.h>
#include <dev/eisa/eisaconf.h>
#include <dev/eisa/eisa_busreg.h>
#include <dev/eisa/eisa_busvar.h>
#include <dev/ep/if_epreg.h>
#include <dev/ep/if_epvar.h>
@ -122,8 +122,8 @@ ep_eisa_probe(device_t dev)
if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f)
return ENXIO;
eisa_add_iospace(dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE);
eisa_add_iospace(dev, port, EP_IOSIZE, RESVADDR_NONE);
eisa_add_iospace(dev, iobase, EP_EISA_IOSIZE);
eisa_add_iospace(dev, port, EP_IOSIZE);
conf = inw(iobase + EISA_IOCONF);
/* Determine our IRQ */
@ -171,7 +171,7 @@ ep_eisa_probe(device_t dev)
break;
}
eisa_add_intr(dev, irq, int_trig);
eisa_add_irq(dev, irq, int_trig);
return 0;
}

View File

@ -71,6 +71,7 @@ ep_pccard_probe(device_t dev)
struct ep_softc * sc = device_get_softc(dev);
struct ep_board * epb = &sc->epb;
const char * desc;
u_int16_t result;
int error;
error = ep_alloc(dev);
@ -86,13 +87,17 @@ ep_pccard_probe(device_t dev)
*/
epb->cmd_off = 0;
epb->prod_id = get_e(sc, EEPROM_PROD_ID);
error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */
epb->prod_id = result;
if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
if (bootverbose)
device_printf(dev, "Pass 1 of 2 detection "
"failed (nonfatal) id 0x%x\n", epb->prod_id);
epb->cmd_off = 2;
epb->prod_id = get_e(sc, EEPROM_PROD_ID);
error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */
epb->prod_id = result;
if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
device_printf(dev, "Unit failed to come ready or "
"product ID unknown! (id 0x%x)\n", epb->prod_id);
@ -105,7 +110,7 @@ ep_pccard_probe(device_t dev)
/*
* For some reason the 3c574 needs this.
*/
ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
ep_free(dev);
return (0);
@ -159,6 +164,7 @@ static int
ep_pccard_attach(device_t dev)
{
struct ep_softc * sc = device_get_softc(dev);
u_int16_t result;
int error = 0;
if ((error = ep_alloc(dev))) {
@ -167,11 +173,16 @@ ep_pccard_attach(device_t dev)
}
sc->epb.cmd_off = 0;
sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID);
error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */
sc->epb.prod_id = result;
if (!ep_pccard_card_attach(&sc->epb)) {
sc->epb.cmd_off = 2;
sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID);
sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);
error = get_e(sc, EEPROM_PROD_ID, &result);
sc->epb.prod_id = result;
error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
sc->epb.res_cfg = result;
if (!ep_pccard_card_attach(&sc->epb)) {
device_printf(dev,
"Probe found ID, attach failed so ignore card!\n");
@ -180,9 +191,11 @@ ep_pccard_attach(device_t dev)
}
}
error = get_e(sc, EEPROM_ADDR_CFG, &result);
/* ROM size = 0, ROM base = 0 */
/* For now, ignore AUTO SELECT feature of 3C589B and later. */
outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000);
outw(BASE + EP_W0_ADDRESS_CFG, result & 0xc000);
/* Fake IRQ must be 3 */
outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000);

View File

@ -79,5 +79,5 @@ void ep_free (device_t);
void ep_get_media (struct ep_softc *);
int ep_attach (struct ep_softc *);
void ep_intr (void *);
u_int16_t get_e (struct ep_softc *, int);
void ep_get_macaddr (struct ep_softc *, u_char *);
int get_e (struct ep_softc *, u_int16_t, u_int16_t *);
int ep_get_macaddr (struct ep_softc *, u_char *);