diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 2000-06-05 20:56:21 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 2000-06-05 20:56:21 +0000 |
commit | cb93c551e9ce9846b9f004a0eed7991d15b8b260 (patch) | |
tree | 5a75b8ae06df375dd19cec6ed0fde064970e4083 /sys/dev/isa | |
parent | ebd70f770677cb2264be271028fbe161ff058e4a (diff) |
Untested busification of this driver done years ago.
Noone ever answered my call for testers so here it goes.. helps ne problems
as ne at 0x300 gets a bit whacked by eg's probe
Diffstat (limited to 'sys/dev/isa')
-rw-r--r-- | sys/dev/isa/if_eg.c | 226 | ||||
-rw-r--r-- | sys/dev/isa/if_egreg.h | 4 |
2 files changed, 142 insertions, 88 deletions
diff --git a/sys/dev/isa/if_eg.c b/sys/dev/isa/if_eg.c index 8c132fd8517..cdf954728b7 100644 --- a/sys/dev/isa/if_eg.c +++ b/sys/dev/isa/if_eg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_eg.c,v 1.15 1999/11/30 23:48:07 aaron Exp $ */ +/* $OpenBSD: if_eg.c,v 1.16 2000/06/05 20:56:20 niklas Exp $ */ /* $NetBSD: if_eg.c,v 1.26 1996/05/12 23:52:27 mycroft Exp $ */ /* @@ -97,11 +97,9 @@ struct eg_softc { struct device sc_dev; void *sc_ih; + bus_space_tag_t sc_bst; + bus_space_handle_t sc_bsh; struct arpcom sc_arpcom; /* Ethernet common part */ - int eg_cmd; /* Command register R/W */ - int eg_ctl; /* Control register R/W (EG_CTL_*) */ - int eg_stat; /* Status register R/O (EG_STAT_*) */ - int eg_data; /* Data register R/W (16 bits) */ u_char eg_rom_major; /* Cards ROM version (major number) */ u_char eg_rom_minor; /* Cards ROM version (minor number) */ short eg_ram; /* Amount of RAM on the card */ @@ -133,8 +131,8 @@ void egread __P((struct eg_softc *, caddr_t, int)); struct mbuf *egget __P((struct eg_softc *, caddr_t, int)); void egstop __P((struct eg_softc *)); -static inline void egprintpcb __P((struct eg_softc *)); -static inline void egprintstat __P((u_char)); +static __inline void egprintpcb __P((struct eg_softc *)); +static __inline void egprintstat __P((u_char)); static int egoutPCB __P((struct eg_softc *, u_char)); static int egreadPCBstat __P((struct eg_softc *, u_char)); static int egreadPCBready __P((struct eg_softc *)); @@ -145,7 +143,7 @@ static int egreadPCB __P((struct eg_softc *)); * Support stuff */ -static inline void +static __inline void egprintpcb(sc) struct eg_softc *sc; { @@ -156,18 +154,18 @@ egprintpcb(sc) } -static inline void +static __inline void egprintstat(b) u_char b; { dprintf(("%s %s %s %s %s %s %s\n", - (b & EG_STAT_HCRE)?"HCRE":"", - (b & EG_STAT_ACRF)?"ACRF":"", - (b & EG_STAT_DIR )?"DIR ":"", - (b & EG_STAT_DONE)?"DONE":"", - (b & EG_STAT_ASF3)?"ASF3":"", - (b & EG_STAT_ASF2)?"ASF2":"", - (b & EG_STAT_ASF1)?"ASF1":"")); + (b & EG_STAT_HCRE)?"HCRE":"", + (b & EG_STAT_ACRF)?"ACRF":"", + (b & EG_STAT_DIR )?"DIR ":"", + (b & EG_STAT_DONE)?"DONE":"", + (b & EG_STAT_ASF3)?"ASF3":"", + (b & EG_STAT_ASF2)?"ASF2":"", + (b & EG_STAT_ASF1)?"ASF1":"")); } static int @@ -175,17 +173,19 @@ egoutPCB(sc, b) struct eg_softc *sc; u_char b; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int i; for (i=0; i < 4000; i++) { - if (inb(sc->eg_stat) & EG_STAT_HCRE) { - outb(sc->eg_cmd, b); + if (bus_space_read_1(bst, bsh, EG_STATUS) & EG_STAT_HCRE) { + bus_space_write_1(bst, bsh, EG_COMMAND, b); return 0; } delay(10); } dprintf(("egoutPCB failed\n")); - return 1; + return (1); } static int @@ -193,104 +193,122 @@ egreadPCBstat(sc, statb) struct eg_softc *sc; u_char statb; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int i; for (i=0; i < 5000; i++) { - if ((inb(sc->eg_stat) & EG_PCB_STAT) != EG_PCB_NULL) + if ((bus_space_read_1(bst, bsh, EG_STATUS) & EG_PCB_STAT) != + EG_PCB_NULL) break; delay(10); } - if ((inb(sc->eg_stat) & EG_PCB_STAT) == statb) - return 0; - return 1; + if ((bus_space_read_1(bst, bsh, EG_STATUS) & EG_PCB_STAT) == statb) + return (0); + return (1); } static int egreadPCBready(sc) struct eg_softc *sc; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int i; for (i=0; i < 10000; i++) { - if (inb(sc->eg_stat) & EG_STAT_ACRF) - return 0; + if (bus_space_read_1(bst, bsh, EG_STATUS) & EG_STAT_ACRF) + return (0); delay(5); } dprintf(("PCB read not ready\n")); - return 1; + return (1); } static int egwritePCB(sc) struct eg_softc *sc; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int i; u_char len; - outb(sc->eg_ctl, (inb(sc->eg_ctl) & ~EG_PCB_STAT) | EG_PCB_NULL); + bus_space_write_1(bst, bsh, EG_CONTROL, + (bus_space_read_1(bst, bsh, EG_CONTROL) & ~EG_PCB_STAT) | + EG_PCB_NULL); len = sc->eg_pcb[1] + 2; for (i = 0; i < len; i++) egoutPCB(sc, sc->eg_pcb[i]); for (i=0; i < 4000; i++) { - if (inb(sc->eg_stat) & EG_STAT_HCRE) + if (bus_space_read_1(bst, bsh, EG_STATUS) & EG_STAT_HCRE) break; delay(10); } - outb(sc->eg_ctl, (inb(sc->eg_ctl) & ~EG_PCB_STAT) | EG_PCB_DONE); + bus_space_write_1(bst, bsh, EG_CONTROL, + (bus_space_read_1(bst, bsh, EG_CONTROL) & ~EG_PCB_STAT) | + EG_PCB_DONE); egoutPCB(sc, len); if (egreadPCBstat(sc, EG_PCB_ACCEPT)) - return 1; - return 0; + return (1); + return (0); } static int egreadPCB(sc) struct eg_softc *sc; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int i; u_char b; - outb(sc->eg_ctl, (inb(sc->eg_ctl) & ~EG_PCB_STAT) | EG_PCB_NULL); + bus_space_write_1(bst, bsh, EG_CONTROL, + (bus_space_read_1(bst, bsh, EG_CONTROL) & ~EG_PCB_STAT) | + EG_PCB_NULL); bzero(sc->eg_pcb, sizeof(sc->eg_pcb)); if (egreadPCBready(sc)) - return 1; + return (1); - sc->eg_pcb[0] = inb(sc->eg_cmd); + sc->eg_pcb[0] = bus_space_read_1(bst, bsh, EG_COMMAND); if (egreadPCBready(sc)) - return 1; + return (1); - sc->eg_pcb[1] = inb(sc->eg_cmd); + sc->eg_pcb[1] = bus_space_read_1(bst, bsh, EG_COMMAND); if (sc->eg_pcb[1] > 62) { dprintf(("len %d too large\n", sc->eg_pcb[1])); - return 1; + return (1); } for (i = 0; i < sc->eg_pcb[1]; i++) { if (egreadPCBready(sc)) - return 1; - sc->eg_pcb[2+i] = inb(sc->eg_cmd); + return (1); + sc->eg_pcb[2+i] = bus_space_read_1(bst, bsh, EG_COMMAND); } if (egreadPCBready(sc)) - return 1; + return (1); if (egreadPCBstat(sc, EG_PCB_DONE)) - return 1; - if ((b = inb(sc->eg_cmd)) != sc->eg_pcb[1] + 2) { + return (1); + if ((b = bus_space_read_1(bst, bsh, EG_COMMAND)) != sc->eg_pcb[1] + 2) + { dprintf(("%d != %d\n", b, sc->eg_pcb[1] + 2)); - return 1; + return (1); } - outb(sc->eg_ctl, (inb(sc->eg_ctl) & ~EG_PCB_STAT) | EG_PCB_ACCEPT); + bus_space_write_1(bst, bsh, EG_CONTROL, + (bus_space_read_1(bst, bsh, EG_CONTROL) & ~EG_PCB_STAT) | + EG_PCB_ACCEPT); - return 0; + return (0); } /* @@ -304,44 +322,49 @@ egprobe(parent, match, aux) { struct eg_softc *sc = match; struct isa_attach_args *ia = aux; + bus_space_tag_t bst = sc->sc_bst = ia->ia_iot; + bus_space_handle_t bsh; int i; if ((ia->ia_iobase & ~0x07f0) != 0) { dprintf(("Weird iobase %x\n", ia->ia_iobase)); - return 0; + return (0); } - sc->eg_cmd = ia->ia_iobase + EG_COMMAND; - sc->eg_ctl = ia->ia_iobase + EG_CONTROL; - sc->eg_stat = ia->ia_iobase + EG_STATUS; - sc->eg_data = ia->ia_iobase + EG_DATA; + if (bus_space_map(bst, ia->ia_iobase, EG_IO_PORTS, 0, &bsh)) { + printf("%s: can't map I/O space\n", sc->sc_dev.dv_xname); + return (0); + } + sc->sc_bsh = bsh; /* hard reset card */ - outb(sc->eg_ctl, EG_CTL_RESET); - outb(sc->eg_ctl, 0); + bus_space_write_1(bst, bsh, EG_CONTROL, EG_CTL_RESET); + bus_space_write_1(bst, bsh, EG_CONTROL, 0); for (i = 0; i < 5000; i++) { delay(1000); - if ((inb(sc->eg_stat) & EG_PCB_STAT) == EG_PCB_NULL) + if ((bus_space_read_1(bst, bsh, EG_STATUS) & EG_PCB_STAT) == + EG_PCB_NULL) break; } - if ((inb(sc->eg_stat) & EG_PCB_STAT) != EG_PCB_NULL) { + if ((bus_space_read_1(bst, bsh, EG_STATUS) & EG_PCB_STAT) != + EG_PCB_NULL) { dprintf(("eg: Reset failed\n")); - return 0; + goto lose; } sc->eg_pcb[0] = EG_CMD_GETINFO; /* Get Adapter Info */ sc->eg_pcb[1] = 0; if (egwritePCB(sc) != 0) - return 0; + goto lose; if (egreadPCB(sc) != 0) { egprintpcb(sc); - return 0; + goto lose; } if (sc->eg_pcb[0] != EG_RSP_GETINFO || /* Get Adapter Info Response */ sc->eg_pcb[1] != 0x0a) { egprintpcb(sc); - return 0; + goto lose; } sc->eg_rom_major = sc->eg_pcb[3]; sc->eg_rom_minor = sc->eg_pcb[2]; @@ -349,7 +372,13 @@ egprobe(parent, match, aux) ia->ia_iosize = 0x08; ia->ia_msize = 0; - return 1; + bus_space_unmap(bst, bsh, EG_IO_PORTS); + return (1); + +lose: + sc->sc_bst = sc->sc_bsh = 0; + bus_space_unmap(bst, bsh, EG_IO_PORTS); + return (0); } void @@ -359,8 +388,14 @@ egattach(parent, self, aux) { struct eg_softc *sc = (void *)self; struct isa_attach_args *ia = aux; + bus_space_tag_t bst = sc->sc_bst = ia->ia_iot; + bus_space_handle_t bsh; struct ifnet *ifp = &sc->sc_arpcom.ac_if; + if (bus_space_map(bst, ia->ia_iobase, EG_IO_PORTS, 0, &bsh)) + panic("%s: can't map I/O space", sc->sc_dev.dv_xname); + sc->sc_bsh = bsh; + egstop(sc); sc->eg_pcb[0] = EG_CMD_GETEADDR; /* Get Station address */ @@ -428,14 +463,16 @@ void eginit(sc) register struct eg_softc *sc; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; register struct ifnet *ifp = &sc->sc_arpcom.ac_if; /* soft reset the board */ - outb(sc->eg_ctl, EG_CTL_FLSH); + bus_space_write_1(bst, bsh, EG_CONTROL, EG_CTL_FLSH); delay(100); - outb(sc->eg_ctl, EG_CTL_ATTN); + bus_space_write_1(bst, bsh, EG_CONTROL, EG_CTL_ATTN); delay(100); - outb(sc->eg_ctl, 0); + bus_space_write_1(bst, bsh, EG_CONTROL, 0); delay(200); sc->eg_pcb[0] = EG_CMD_CONFIG82586; /* Configure 82586 */ @@ -459,7 +496,7 @@ eginit(sc) if (sc->eg_outbuf == 0) sc->eg_outbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT); - outb(sc->eg_ctl, EG_CTL_CMDE); + bus_space_write_1(bst, bsh, EG_CONTROL, EG_CTL_CMDE); sc->eg_incount = 0; egrecv(sc); @@ -498,7 +535,9 @@ void egstart(ifp) struct ifnet *ifp; { - register struct eg_softc *sc = ifp->if_softc; + struct eg_softc *sc = ifp->if_softc; + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; struct mbuf *m0, *m; caddr_t buffer; int len; @@ -549,11 +588,12 @@ loop: } /* set direction bit: host -> adapter */ - outb(sc->eg_ctl, inb(sc->eg_ctl) & ~EG_CTL_DIR); + bus_space_write_1(bst, bsh, EG_CONTROL, + bus_space_read_1(bst, bsh, EG_CONTROL) & ~EG_CTL_DIR); - for (ptr = (u_short *) sc->eg_outbuf; len > 0; len -= 2) { - outw(sc->eg_data, *ptr++); - while (!(inb(sc->eg_stat) & EG_STAT_HRDY)) + for (ptr = (u_short *)sc->eg_outbuf; len > 0; len -= 2) { + bus_space_write_2(bst, bsh, EG_DATA, *ptr++); + while (!(bus_space_read_1(bst, bsh, EG_STATUS) & EG_STAT_HRDY)) ; /* XXX need timeout here */ } @@ -564,12 +604,14 @@ int egintr(arg) void *arg; { - register struct eg_softc *sc = arg; + struct eg_softc *sc = arg; + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; int ret = 0; int i, len; u_short *ptr; - while (inb(sc->eg_stat) & EG_STAT_ACRF) { + while (bus_space_read_1(bst, bsh, EG_STATUS) & EG_STAT_ACRF) { ret = 1; egreadPCB(sc); switch (sc->eg_pcb[0]) { @@ -577,12 +619,16 @@ egintr(arg) len = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8); /* Set direction bit : Adapter -> host */ - outb(sc->eg_ctl, inb(sc->eg_ctl) | EG_CTL_DIR); - - for (ptr = (u_short *) sc->eg_inbuf; len > 0; len -= 2) { - while (!(inb(sc->eg_stat) & EG_STAT_HRDY)) + bus_space_write_1(bst, bsh, EG_CONTROL, + bus_space_read_1(bst, bsh, EG_CONTROL) | + EG_CTL_DIR); + + for (ptr = (u_short *)sc->eg_inbuf; len > 0; len -= 2) + { + while (!(bus_space_read_1(bst, bsh, + EG_STATUS) & EG_STAT_HRDY)) ; - *ptr++ = inw(sc->eg_data); + *ptr++ = bus_space_read_2(bst, bsh, EG_DATA); } len = sc->eg_pcb[8] | (sc->eg_pcb[9] << 8); @@ -598,7 +644,8 @@ egintr(arg) sc->sc_arpcom.ac_if.if_oerrors++; } else sc->sc_arpcom.ac_if.if_opackets++; - sc->sc_arpcom.ac_if.if_collisions += sc->eg_pcb[8] & 0xf; + sc->sc_arpcom.ac_if.if_collisions += + sc->eg_pcb[8] & 0xf; sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE; egstart(&sc->sc_arpcom.ac_if); break; @@ -609,10 +656,13 @@ egintr(arg) dprintf(("Receive Packets %d\n", i)); bcopy(&sc->eg_pcb[6], &i, sizeof(i)); dprintf(("Transmit Packets %d\n", i)); - dprintf(("CRC errors %d\n", *(short*) &sc->eg_pcb[10])); - dprintf(("alignment errors %d\n", *(short*) &sc->eg_pcb[12])); - dprintf(("no resources errors %d\n", *(short*) &sc->eg_pcb[14])); - dprintf(("overrun errors %d\n", *(short*) &sc->eg_pcb[16])); + dprintf(("CRC errors %d\n", *(short*)&sc->eg_pcb[10])); + dprintf(("alignment errors %d\n", + *(short*)&sc->eg_pcb[12])); + dprintf(("no resources errors %d\n", + *(short*)&sc->eg_pcb[14])); + dprintf(("overrun errors %d\n", + *(short*)&sc->eg_pcb[16])); break; default: @@ -623,7 +673,7 @@ egintr(arg) } } - return ret; + return (ret); } /* @@ -688,7 +738,7 @@ egget(sc, buf, totlen) MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == 0) - return 0; + return (0); m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = totlen; len = MHLEN; @@ -700,7 +750,7 @@ egget(sc, buf, totlen) MGET(m, M_DONTWAIT, MT_DATA); if (m == 0) { m_freem(top); - return 0; + return (0); } len = MLEN; } @@ -717,7 +767,7 @@ egget(sc, buf, totlen) mp = &m->m_next; } - return top; + return (top); } int @@ -734,7 +784,7 @@ egioctl(ifp, cmd, data) if ((error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data)) > 0) { splx(s); - return error; + return (error); } switch (cmd) { @@ -790,7 +840,7 @@ egioctl(ifp, cmd, data) } splx(s); - return error; + return (error); } void @@ -822,6 +872,8 @@ void egstop(sc) register struct eg_softc *sc; { + bus_space_tag_t bst = sc->sc_bst; + bus_space_handle_t bsh = sc->sc_bsh; - outb(sc->eg_ctl, 0); + bus_space_write_1(bst, bsh, EG_CONTROL, 0); } diff --git a/sys/dev/isa/if_egreg.h b/sys/dev/isa/if_egreg.h index a15c870d0ec..24f6492c9fd 100644 --- a/sys/dev/isa/if_egreg.h +++ b/sys/dev/isa/if_egreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_egreg.h,v 1.2 1997/11/07 08:06:48 niklas Exp $ */ +/* $OpenBSD: if_egreg.h,v 1.3 2000/06/05 20:56:20 niklas Exp $ */ /* $NetBSD: if_egreg.h,v 1.3 1995/07/23 21:14:35 mycroft Exp $ */ /* @@ -39,6 +39,8 @@ #define EG_DATA 0x04 #define EG_CONTROL 0x06 +#define EG_IO_PORTS 8 + /* * Host Control Register bits * EG_CTL_ATTN - does a soft reset |