diff options
author | fjoe <fjoe@FreeBSD.org> | 2002-08-05 18:14:16 +0000 |
---|---|---|
committer | fjoe <fjoe@FreeBSD.org> | 2002-08-05 18:14:16 +0000 |
commit | 7bf0358c9be16f539efb653a254020d6a7783ba2 (patch) | |
tree | 18b819182d98f4667836ffe471888ad337afb789 /sys/dev/sbni/if_sbni.c | |
parent | 504ae196a93f4a0c787e415600dffc3e6e1c8405 (diff) | |
download | FreeBSD-src-7bf0358c9be16f539efb653a254020d6a7783ba2.zip FreeBSD-src-7bf0358c9be16f539efb653a254020d6a7783ba2.tar.gz |
Make driver portable:
- bus_space'ify
- generate fake ethernet address using read_random() instead of reading
from timer i/o ports
Other minor fixes:
- remove "hack" in connect_to_master()
- use M_ZERO
- remove unused variable in sbni_ioctl()
- properly release irq in sbni_attach_isa() on attach errors
Diffstat (limited to 'sys/dev/sbni/if_sbni.c')
-rw-r--r-- | sys/dev/sbni/if_sbni.c | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/sys/dev/sbni/if_sbni.c b/sys/dev/sbni/if_sbni.c index df46da6..1c30896 100644 --- a/sys/dev/sbni/if_sbni.c +++ b/sys/dev/sbni/if_sbni.c @@ -68,6 +68,11 @@ #include <sys/proc.h> #include <sys/callout.h> #include <sys/syslog.h> +#include <sys/random.h> + +#include <machine/bus.h> +#include <sys/rman.h> +#include <machine/resource.h> #include <net/if.h> #include <net/ethernet.h> @@ -126,25 +131,37 @@ u_int32_t next_sbni_unit; static __inline u_char sbni_inb(struct sbni_softc *sc, enum sbni_reg reg) { - return (inb(sc->base_addr + reg)); + return bus_space_read_1( + rman_get_bustag(sc->io_res), + rman_get_bushandle(sc->io_res), + sc->io_off + reg); } static __inline void sbni_outb(struct sbni_softc *sc, enum sbni_reg reg, u_char value) { - outb(sc->base_addr + reg, value); + bus_space_write_1( + rman_get_bustag(sc->io_res), + rman_get_bushandle(sc->io_res), + sc->io_off + reg, value); } static __inline void sbni_insb(struct sbni_softc *sc, u_char *to, u_int len) { - insb(sc->base_addr + DAT, to, len); + bus_space_read_multi_1( + rman_get_bustag(sc->io_res), + rman_get_bushandle(sc->io_res), + sc->io_off + DAT, to, len); } static __inline void sbni_outsb(struct sbni_softc *sc, u_char *from, u_int len) { - outsb(sc->base_addr + DAT, from, len); + bus_space_write_multi_1( + rman_get_bustag(sc->io_res), + rman_get_bushandle(sc->io_res), + sc->io_off + DAT, from, len); } @@ -947,43 +964,33 @@ set_initial_values(struct sbni_softc *sc, struct sbni_flags flags) /* * generate Ethernet address (0x00ff01xxxxxx) */ - *(u_int16_t*)sc->arpcom.ac_enaddr = htons(0x00ff); - if (flags.mac_addr) - *(u_int32_t*)(sc->arpcom.ac_enaddr+2) = - htonl(flags.mac_addr | 0x01000000); - else { - /* reading timer value */ - outb(0x43, 0); - insb(0x40, sc->arpcom.ac_enaddr + 3, 4); - *(u_char*)(sc->arpcom.ac_enaddr + 2) = 0x01; + *(u_int16_t *) sc->arpcom.ac_enaddr = htons(0x00ff); + if (flags.mac_addr) { + *(u_int32_t *) (sc->arpcom.ac_enaddr + 2) = + htonl(flags.mac_addr | 0x01000000); + } else { + *(u_char *) (sc->arpcom.ac_enaddr + 2) = 0x01; + read_random(sc->arpcom.ac_enaddr + 3, 3); } } #ifdef SBNI_DUAL_COMPOUND -#ifndef offsetof -#define offsetof(type, member) ((u_int32_t)(&((type *)0)->member)) -#endif - - struct sbni_softc * connect_to_master(struct sbni_softc *sc) { - struct sbni_softc *p; - - p = (struct sbni_softc *)(((char *)&sbni_headlist) - - offsetof(struct sbni_softc, link)); - - for (; p->link; p = p->link) { - if (p->link->irq == sc->irq - && (p->link->base_addr == sc->base_addr + 4 - || p->link->base_addr == sc->base_addr - 4)) { - - struct sbni_softc *t = p->link; - t->slave_sc = sc; - p->link = p->link->link; - return (t); + struct sbni_softc *p, *p_prev; + + for (p = sbni_headlist, p_prev = NULL; p; p_prev = p, p = p->link) { + if (rman_get_start(p->io_res) == rman_get_start(sc->io_res) + 4 || + rman_get_start(p->io_res) == rman_get_start(sc->io_res) - 4) { + p->slave_sc = sc; + if (p_prev) + p_prev->link = p->link; + else + sbni_headlist = p->link; + return p; } } @@ -1045,7 +1052,6 @@ sbni_ioctl(struct ifnet *ifp, u_long command, caddr_t data) struct sbni_softc *sc; struct ifreq *ifr; struct thread *td; - struct proc *p; struct sbni_in_stats *in_stats; struct sbni_flags flags; int error, s; @@ -1053,7 +1059,6 @@ sbni_ioctl(struct ifnet *ifp, u_long command, caddr_t data) sc = ifp->if_softc; ifr = (struct ifreq *)data; td = curthread; - p = td->td_proc; error = 0; s = splimp(); |