diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2013-09-24 20:11:06 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2013-09-24 20:11:06 +0000 |
commit | 8462f305c90bf8f0be07bebe2ba800fef136fa7f (patch) | |
tree | b4d498958840e8a209a12c3d48baf37230883687 | |
parent | 9ee7ed799de3b09ef90511dd85a93ff687af1116 (diff) |
Sync the MI LANCE code ( le(4) ) with NetBSD, except for the following:
- the am7990_get() - now lance_get() - is unchanged.
- the interrupt acknowledge logic is unchanged, and will disable interrupts,
then acknowledge all interrupt conditions.
Add ILACC (79900) support (from NetBSD).
Both LANCE (am7990.c) and ILACC (am79900.c) code share as much common code
(lance.c) as possible. This affects all le(4) attachments, but the changes
are mostly mechanical, to split am7990-specific parts from lance-agnostic
parts.
Compile tested on all affected platforms. Tested on alpha, hp300, luna88k,
mvme88k, sparc, sparc64 and vax.
37 files changed, 2415 insertions, 1548 deletions
diff --git a/sys/arch/hp300/conf/files.hp300 b/sys/arch/hp300/conf/files.hp300 index be350469270..99c49a44621 100644 --- a/sys/arch/hp300/conf/files.hp300 +++ b/sys/arch/hp300/conf/files.hp300 @@ -1,4 +1,4 @@ -# $OpenBSD: files.hp300,v 1.35 2011/12/21 23:12:03 miod Exp $ +# $OpenBSD: files.hp300,v 1.36 2013/09/24 20:10:42 miod Exp $ # $NetBSD: files.hp300,v 1.28 1997/05/12 08:23:28 thorpej Exp $ # # hp300-specific configuration info @@ -122,7 +122,7 @@ attach dcm at dio file arch/hp300/dev/dcm.c dcm needs-flag # LANCE ethernet -attach le at dio +attach le at dio: le24 file arch/hp300/dev/if_le.c le # 425e digital audio diff --git a/sys/arch/hp300/dev/if_le.c b/sys/arch/hp300/dev/if_le.c index 09d25841993..80386ad2dd5 100644 --- a/sys/arch/hp300/dev/if_le.c +++ b/sys/arch/hp300/dev/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.17 2005/01/15 21:13:08 miod Exp $ */ +/* $OpenBSD: if_le.c,v 1.18 2013/09/24 20:10:44 miod Exp $ */ /* $NetBSD: if_le.c,v 1.43 1997/05/05 21:05:32 thorpej Exp $ */ /*- @@ -58,6 +58,8 @@ #include <machine/cpu.h> #include <machine/intr.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -81,15 +83,13 @@ struct cfattach le_ca = { int leintr(void *); /* offsets for: ID, REGS, MEM, NVRAM */ -int lestd[] = { 0, 0x4000, 0x8000, 0xC008 }; +const int lestd[] = { 0, 0x4000, 0x8000, 0xC008 }; -hide void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -hide u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); +void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t lerdcsr(struct lance_softc *, uint16_t); -hide void -lewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +void +lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0; struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; @@ -102,14 +102,12 @@ lewrcsr(sc, port, val) } while ((ler0->ler0_status & LE_ACK) == 0); } -hide u_int16_t -lerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +lerdcsr(struct lance_softc *sc, uint16_t port) { struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0; struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; - u_int16_t val; + uint16_t val; do { ler1->ler1_rap = port; @@ -147,7 +145,7 @@ leattach(parent, self, aux) struct dio_attach_args *da = aux; struct le_softc *lesc = (struct le_softc *)self; caddr_t addr; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; char *cp; int i, ipl; @@ -182,18 +180,18 @@ leattach(parent, self, aux) cp++; } - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = lerdcsr; sc->sc_wrcsr = lewrcsr; sc->sc_hwreset = NULL; sc->sc_hwinit = NULL; - am7990_config(sc); + am7990_config(&lesc->sc_am7990); /* Establish the interrupt handler. */ lesc->sc_isr.isr_func = leintr; @@ -209,9 +207,9 @@ leintr(arg) void *arg; { struct le_softc *lesc = (struct le_softc *)arg; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; #ifdef USELEDS - u_int16_t isr; + uint16_t isr; isr = lerdcsr(sc, LE_CSR0); diff --git a/sys/arch/luna88k/conf/files.luna88k b/sys/arch/luna88k/conf/files.luna88k index 9c99a60a82a..a8e21351c67 100644 --- a/sys/arch/luna88k/conf/files.luna88k +++ b/sys/arch/luna88k/conf/files.luna88k @@ -1,4 +1,4 @@ -# $OpenBSD: files.luna88k,v 1.17 2013/05/22 11:35:02 aoyama Exp $ +# $OpenBSD: files.luna88k,v 1.18 2013/09/24 20:10:44 miod Exp $ # maxpartitions 16 @@ -14,7 +14,7 @@ device lcd attach lcd at mainbus file arch/luna88k/dev/lcd.c lcd needs-flag -attach le at mainbus +attach le at mainbus: le24 file arch/luna88k/dev/if_le.c le device sio {[channel = -1]} diff --git a/sys/arch/luna88k/dev/if_le.c b/sys/arch/luna88k/dev/if_le.c index 5966294d9f8..7c9e9b9c43e 100644 --- a/sys/arch/luna88k/dev/if_le.c +++ b/sys/arch/luna88k/dev/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.5 2008/06/26 05:42:11 ray Exp $ */ +/* $OpenBSD: if_le.c,v 1.6 2013/09/24 20:10:45 miod Exp $ */ /* $NetBSD: if_le.c,v 1.33 1996/11/20 18:56:52 gwr Exp $ */ /*- @@ -52,6 +52,8 @@ #include <machine/board.h> #include <machine/cpu.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -62,9 +64,9 @@ * The real stuff is in dev/ic/am7990reg.h */ struct lereg1 { - volatile u_int16_t ler1_rdp; /* data port */ - volatile unsigned : 16 ; /* LUNA-88K2 has a 16 bit gap */ - volatile u_int16_t ler1_rap; /* register select port */ + volatile uint16_t ler1_rdp; /* data port */ + volatile unsigned :16 ; /* LUNA-88K2 has a 16 bit gap */ + volatile uint16_t ler1_rap; /* register select port */ }; /* @@ -77,21 +79,19 @@ struct le_softc { struct lereg1 *sc_r1; /* LANCE registers */ }; -static int le_match(struct device *, void *, void *); -static void le_attach(struct device *, struct device *, void *); +int le_match(struct device *, void *, void *); +void le_attach(struct device *, struct device *, void *); -struct cfattach le_ca = { +const struct cfattach le_ca = { sizeof(struct le_softc), le_match, le_attach }; -hide void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -hide u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); -hide void myetheraddr(u_int8_t *); +void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t lerdcsr(struct lance_softc *, uint16_t); +void myetheraddr(uint8_t *); -hide void -lewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +void +lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; @@ -99,23 +99,19 @@ lewrcsr(sc, port, val) ler1->ler1_rdp = val; } -hide u_int16_t -lerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +lerdcsr(struct lance_softc *sc, uint16_t port) { register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; - u_int16_t val; + uint16_t val; ler1->ler1_rap = port; val = ler1->ler1_rdp; return (val); } -static int -le_match(parent, cf, aux) - struct device *parent; - void *cf, *aux; +int +le_match(struct device *parent, void *cf, void *aux) { struct mainbus_attach_args *ma = aux; @@ -126,12 +122,10 @@ le_match(parent, cf, aux) } void -le_attach(parent, self, aux) - struct device *parent, *self; - void *aux; +le_attach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct mainbus_attach_args *ma = aux; lesc->sc_r1 = (struct lereg1 *)ma->ma_addr; /* LANCE */ @@ -143,18 +137,18 @@ le_attach(parent, self, aux) myetheraddr(sc->sc_arpcom.ac_enaddr); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = lerdcsr; sc->sc_wrcsr = lewrcsr; sc->sc_hwreset = NULL; sc->sc_hwinit = NULL; - am7990_config(sc); + am7990_config(&lesc->sc_am7990); isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET, self->dv_xname); @@ -174,12 +168,11 @@ le_attach(parent, self, aux) extern int machtype; extern char fuse_rom_data[]; -hide void -myetheraddr(ether) - u_int8_t *ether; +void +myetheraddr(uint8_t *ether) { unsigned i, loc; - volatile struct { u_int32_t ctl; } *ds1220; + volatile struct { uint32_t ctl; } *ds1220; switch (machtype) { case LUNA_88K: diff --git a/sys/arch/mvme68k/conf/files.mvme68k b/sys/arch/mvme68k/conf/files.mvme68k index 07df830a9d6..f3af61c555a 100644 --- a/sys/arch/mvme68k/conf/files.mvme68k +++ b/sys/arch/mvme68k/conf/files.mvme68k @@ -1,4 +1,4 @@ -# $OpenBSD: files.mvme68k,v 1.36 2013/05/19 20:32:47 miod Exp $ +# $OpenBSD: files.mvme68k,v 1.37 2013/09/24 20:10:45 miod Exp $ # config file for mvme68k @@ -64,7 +64,7 @@ file arch/mvme68k/dev/vmel.c vmel needs-count #attach vsb at lrc, ofobio #file arch/mvme68k/dev/vsb.c vsb needs-flag -attach le at pcc, vmes +attach le at pcc, vmes: le24 file arch/mvme68k/dev/if_le.c le attach ie at mc, pcctwo diff --git a/sys/arch/mvme68k/dev/if_le.c b/sys/arch/mvme68k/dev/if_le.c index 145bcb98533..46baff0a762 100644 --- a/sys/arch/mvme68k/dev/if_le.c +++ b/sys/arch/mvme68k/dev/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.33 2009/02/21 20:33:08 miod Exp $ */ +/* $OpenBSD: if_le.c,v 1.34 2013/09/24 20:10:46 miod Exp $ */ /*- * Copyright (c) 1982, 1992, 1993 @@ -53,6 +53,8 @@ #include <machine/autoconf.h> #include <machine/cpu.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -73,25 +75,20 @@ struct cfattach le_ca = { sizeof(struct le_softc), lematch, leattach }; -static int lebustype; - -void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); -void vlewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t vlerdcsr(struct am7990_softc *, u_int16_t); -void nvram_cmd(struct am7990_softc *, u_char, u_short); -u_int16_t nvram_read(struct am7990_softc *, u_char); -void vleetheraddr(struct am7990_softc *); -void vleinit(struct am7990_softc *); -void vlereset(struct am7990_softc *); -int vle_intr(void *); +void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t lerdcsr(struct lance_softc *, uint16_t); +void vlewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t vlerdcsr(struct lance_softc *, uint16_t); +void nvram_cmd(struct lance_softc *, uint8_t, uint16_t); +uint16_t nvram_read(struct lance_softc *, uint8_t); +void vleetheraddr(struct lance_softc *); +void vleinit(struct lance_softc *); +void vlereset(struct lance_softc *); +int vle_intr(void *); /* send command to the nvram controller */ void -nvram_cmd(sc, cmd, addr) - struct am7990_softc *sc; - u_char cmd; - u_short addr; +nvram_cmd(struct lance_softc *sc, uint8_t cmd, uint16_t addr) { int i; struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; @@ -103,13 +100,11 @@ nvram_cmd(sc, cmd, addr) } /* read nvram one bit at a time */ -u_int16_t -nvram_read(sc, nvram_addr) - struct am7990_softc *sc; - u_char nvram_addr; +uint16_t +nvram_read(struct lance_softc *sc, uint8_t nvram_addr) { - u_short val = 0, mask = 0x04000; - u_int16_t wbit; + uint16_t val = 0, mask = 0x04000; + uint16_t wbit; /* these used by macros DO NOT CHANGE!*/ struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; ((struct le_softc *)sc)->csr = 0x4f; @@ -131,12 +126,11 @@ nvram_read(sc, nvram_addr) } void -vleetheraddr(sc) - struct am7990_softc *sc; +vleetheraddr(struct lance_softc *sc) { - u_char * cp = sc->sc_arpcom.ac_enaddr; - u_int16_t ival[3]; - u_char i; + uint8_t * cp = sc->sc_arpcom.ac_enaddr; + uint16_t ival[3]; + uint8_t i; for (i=0; i<3; i++) { ival[i] = nvram_read(sc, i); @@ -145,47 +139,39 @@ vleetheraddr(sc) } void -lewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { - register struct lereg1 *ler1 = (struct lereg1 *)((struct le_softc *)sc)->sc_r1; + struct lereg1 *ler1 = (struct lereg1 *)((struct le_softc *)sc)->sc_r1; ler1->ler1_rap = port; ler1->ler1_rdp = val; } void -vlewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +vlewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { - register struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; + struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; ler1->ler1_rap = port; ler1->ler1_rdp = val; } -u_int16_t -lerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +lerdcsr(struct lance_softc *sc, uint16_t port) { - register struct lereg1 *ler1 = (struct lereg1 *)((struct le_softc *)sc)->sc_r1; - u_int16_t val; + struct lereg1 *ler1 = (struct lereg1 *)((struct le_softc *)sc)->sc_r1; + uint16_t val; ler1->ler1_rap = port; val = ler1->ler1_rdp; return (val); } -u_int16_t -vlerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +vlerdcsr(struct lance_softc *sc, uint16_t port) { - register struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; - u_int16_t val; + struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; + uint16_t val; ler1->ler1_rap = port; val = ler1->ler1_rdp; @@ -194,12 +180,11 @@ vlerdcsr(sc, port) /* init MVME376, set ipl and vec */ void -vleinit(sc) - struct am7990_softc *sc; +vleinit(struct lance_softc *sc) { - register struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; - u_char vec = ((struct le_softc *)sc)->sc_vec; - u_char ipl = ((struct le_softc *)sc)->sc_ipl; + struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; + uint8_t vec = ((struct le_softc *)sc)->sc_vec; + uint8_t ipl = ((struct le_softc *)sc)->sc_ipl; ((struct le_softc *)sc)->csr = 0x4f; WRITE_CSR_AND( ~ipl ); SET_VEC(vec); @@ -208,10 +193,9 @@ vleinit(sc) /* MVME376 hardware reset */ void -vlereset(sc) - struct am7990_softc *sc; +vlereset(struct lance_softc *sc) { - register struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; + struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; RESET_HW; #ifdef LEDEBUG if (sc->sc_debug) { @@ -223,10 +207,9 @@ vlereset(sc) } int -vle_intr(sc) - void *sc; +vle_intr(void *sc) { - register struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; + struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; int rc; rc = am7990_intr(sc); ENABLE_INTR; @@ -234,9 +217,7 @@ vle_intr(sc) } int -lematch(parent, vcf, args) - struct device *parent; - void *vcf, *args; +lematch(struct device *parent, void *vcf, void *args) { struct confargs *ca = args; bus_space_tag_t iot = ca->ca_iot; @@ -263,13 +244,10 @@ lematch(parent, vcf, args) * to accept packets. */ void -leattach(parent, self, aux) - struct device *parent; - struct device *self; - void *aux; +leattach(struct device *parent, struct device *self, void *aux) { - register struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct le_softc *lesc = (struct le_softc *)self; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct confargs *ca = aux; int pri = ca->ca_ipl; extern void *etherbuf; @@ -279,11 +257,9 @@ leattach(parent, self, aux) bus_space_handle_t ioh, memh; /* XXX the following declarations should be elsewhere */ - extern void myetheraddr(u_char *); + extern void myetheraddr(uint8_t *); - lebustype = ca->ca_bustype; - - switch (lebustype) { + switch (ca->ca_bustype) { case BUS_VMES: /* * get the first available etherbuf. MVME376 uses its own @@ -341,11 +317,11 @@ leattach(parent, self, aux) sc->sc_rdcsr = vlerdcsr; sc->sc_wrcsr = vlewrcsr; sc->sc_hwinit = vleinit; - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; /* get ether address */ vleetheraddr(sc); break; @@ -359,11 +335,11 @@ leattach(parent, self, aux) sc->sc_wrcsr = lewrcsr; sc->sc_hwreset = NULL; sc->sc_hwinit = NULL; - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; /* get ether address */ myetheraddr(sc->sc_arpcom.ac_enaddr); break; @@ -372,10 +348,10 @@ leattach(parent, self, aux) return; } - am7990_config(sc); + am7990_config(&lesc->sc_am7990); /* connect the interrupt */ - switch (lebustype) { + switch (ca->ca_bustype) { case BUS_VMES: lesc->sc_ih.ih_fn = vle_intr; lesc->sc_ih.ih_arg = sc; diff --git a/sys/arch/mvme88k/conf/files.mvme88k b/sys/arch/mvme88k/conf/files.mvme88k index 12aff1d05fb..e11c21fc414 100644 --- a/sys/arch/mvme88k/conf/files.mvme88k +++ b/sys/arch/mvme88k/conf/files.mvme88k @@ -1,4 +1,4 @@ -# $OpenBSD: files.mvme88k,v 1.50 2013/06/11 21:06:31 miod Exp $ +# $OpenBSD: files.mvme88k,v 1.51 2013/09/24 20:10:47 miod Exp $ # maxpartitions 16 @@ -102,7 +102,7 @@ attach ie at pcctwo: ifnet, ether file arch/mvme88k/dev/if_ie.c ie # MVME376 -attach le at vmes +attach le at vmes: le24 file arch/mvme88k/dev/if_le.c le # MVME374 diff --git a/sys/arch/mvme88k/dev/if_le.c b/sys/arch/mvme88k/dev/if_le.c index d7f203103c5..0db823ae7a8 100644 --- a/sys/arch/mvme88k/dev/if_le.c +++ b/sys/arch/mvme88k/dev/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.15 2006/05/08 14:36:10 miod Exp $ */ +/* $OpenBSD: if_le.c,v 1.16 2013/09/24 20:10:48 miod Exp $ */ /*- * Copyright (c) 1982, 1992, 1993 @@ -51,6 +51,8 @@ #include <machine/autoconf.h> #include <machine/cpu.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -62,25 +64,22 @@ void leattach(struct device *, struct device *, void *); int lematch(struct device *, void *, void *); -struct cfattach le_ca = { +const struct cfattach le_ca = { sizeof(struct le_softc), lematch, leattach }; -void vlewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t vlerdcsr(struct am7990_softc *, u_int16_t); -void nvram_cmd(struct am7990_softc *, u_char, u_short); -u_int16_t nvram_read(struct am7990_softc *, u_char); -void vleetheraddr(struct am7990_softc *); -void vleinit(struct am7990_softc *); -void vlereset(struct am7990_softc *); -int vle_intr(void *); +void vlewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t vlerdcsr(struct lance_softc *, uint16_t); +void nvram_cmd(struct lance_softc *, uint8_t, uint16_t); +uint16_t nvram_read(struct lance_softc *, uint8_t); +void vleetheraddr(struct lance_softc *); +void vleinit(struct lance_softc *); +void vlereset(struct lance_softc *); +int vle_intr(void *); /* send command to the nvram controller */ void -nvram_cmd(sc, cmd, addr) - struct am7990_softc *sc; - u_char cmd; - u_short addr; +nvram_cmd(struct lance_softc *sc, uint8_t cmd, uint16_t addr) { struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; int i; @@ -92,13 +91,11 @@ nvram_cmd(sc, cmd, addr) } /* read nvram one bit at a time */ -u_int16_t -nvram_read(sc, nvram_addr) - struct am7990_softc *sc; - u_char nvram_addr; +uint16_t +nvram_read(struct lance_softc *sc, uint8_t nvram_addr) { - u_short val = 0, mask = 0x04000; - u_int16_t wbit; + uint16_t val = 0, mask = 0x04000; + uint16_t wbit; struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; ((struct le_softc *)sc)->sc_csr = 0x4f; @@ -126,11 +123,10 @@ nvram_read(sc, nvram_addr) } void -vleetheraddr(sc) - struct am7990_softc *sc; +vleetheraddr(struct lance_softc *sc) { - u_char *cp = sc->sc_arpcom.ac_enaddr; - u_int16_t ival[3]; + uint8_t *cp = sc->sc_arpcom.ac_enaddr; + uint16_t ival[3]; int i; for (i = 0; i < 3; i++) { @@ -140,9 +136,7 @@ vleetheraddr(sc) } void -vlewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +vlewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; @@ -150,13 +144,11 @@ vlewrcsr(sc, port, val) ler1->ler1_rdp = val; } -u_int16_t -vlerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +vlerdcsr(struct lance_softc *sc, uint16_t port) { struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; - u_int16_t val; + uint16_t val; ler1->ler1_rap = port; val = ler1->ler1_rdp; @@ -165,12 +157,11 @@ vlerdcsr(sc, port) /* init MVME376, set ipl and vec */ void -vleinit(sc) - struct am7990_softc *sc; +vleinit(struct lance_softc *sc) { struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; - u_char vec = ((struct le_softc *)sc)->sc_vec; - u_char ipl = ((struct le_softc *)sc)->sc_ipl; + uint8_t vec = ((struct le_softc *)sc)->sc_vec; + uint8_t ipl = ((struct le_softc *)sc)->sc_ipl; ((struct le_softc *)sc)->sc_csr = 0x4f; WRITE_CSR_AND(ipl); @@ -180,8 +171,7 @@ vleinit(sc) /* MVME376 hardware reset */ void -vlereset(sc) - struct am7990_softc *sc; +vlereset(struct lance_softc *sc) { struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1; @@ -195,8 +185,7 @@ vlereset(sc) } int -vle_intr(sc) - void *sc; +vle_intr(void *sc) { struct le_softc *lesc = (struct le_softc *)sc; struct vlereg1 *reg1 = (struct vlereg1 *)lesc->sc_r1; @@ -208,9 +197,7 @@ vle_intr(sc) } int -lematch(parent, vcf, args) - struct device *parent; - void *vcf, *args; +lematch(struct device *parent, void *vcf, void *args) { struct confargs *ca = args; bus_space_tag_t iot = ca->ca_iot; @@ -231,13 +218,10 @@ lematch(parent, vcf, args) * to accept packets. */ void -leattach(parent, self, aux) - struct device *parent; - struct device *self; - void *aux; +leattach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct confargs *ca = aux; paddr_t paddr; int card; @@ -252,11 +236,10 @@ leattach(parent, self, aux) ca->ca_ipl = IPL_NET; /* - * get the first available etherbuf. MVME376 uses its own dual-ported - * RAM for etherbuf. It is set by dip switches on board. We support - * the six Motorola address locations, however, the board can be set up - * at any other address. - * XXX These physical addresses should be mapped in extio!!! + * MVME376 uses its own dual-ported RAM for buffers. + * Its address is set by DIP switches on board. We support the six + * Motorola address locations; however, the board can be set up at + * any other address. */ switch (ca->ca_paddr) { case 0xffff1200: @@ -306,16 +289,16 @@ leattach(parent, self, aux) sc->sc_rdcsr = vlerdcsr; sc->sc_wrcsr = vlewrcsr; sc->sc_hwinit = vleinit; - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; /* get Ethernet address */ vleetheraddr(sc); - am7990_config(sc); + am7990_config(&lesc->sc_am7990); /* connect the interrupt */ lesc->sc_ih.ih_fn = vle_intr; diff --git a/sys/arch/sparc/conf/files.sparc b/sys/arch/sparc/conf/files.sparc index 57bb7172310..213c829a9f7 100644 --- a/sys/arch/sparc/conf/files.sparc +++ b/sys/arch/sparc/conf/files.sparc @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc,v 1.93 2013/06/04 21:05:54 miod Exp $ +# $OpenBSD: files.sparc,v 1.94 2013/09/24 20:10:49 miod Exp $ # $NetBSD: files.sparc,v 1.44 1997/08/31 21:29:16 pk Exp $ # @(#)files.sparc 8.1 (Berkeley) 7/19/93 @@ -239,7 +239,7 @@ attach zx at sbus file arch/sparc/dev/zx.c zx # device definition in sys/conf/files -attach le at sbus, ledma, lebuffer, obio +attach le at sbus, ledma, lebuffer, obio: le24 file arch/sparc/dev/if_le.c le attach ie at obio, vmes, vmel diff --git a/sys/arch/sparc/dev/if_le.c b/sys/arch/sparc/dev/if_le.c index cb695439433..0a9a891aa3e 100644 --- a/sys/arch/sparc/dev/if_le.c +++ b/sys/arch/sparc/dev/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.33 2012/07/30 16:58:19 miod Exp $ */ +/* $OpenBSD: if_le.c,v 1.34 2013/09/24 20:10:49 miod Exp $ */ /* $NetBSD: if_le.c,v 1.50 1997/09/09 20:54:48 pk Exp $ */ /*- @@ -71,6 +71,8 @@ #include <sparc/dev/dmavar.h> #include <sparc/dev/lebuffervar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -89,15 +91,31 @@ void leattach(struct device *, struct device *, void *); /* * ifmedia interfaces */ -int lemediachange(struct ifnet *); -void lemediastatus(struct ifnet *, struct ifmediareq *); +int lemediachange(struct lance_softc *); +void lemediastatus(struct lance_softc *, struct ifmediareq *); + +#if defined(SUN4C) || defined(SUN4D) || defined(SUN4E) || defined(SUN4M) +static int lebufmedia[] = { + IFM_ETHER | IFM_10_T +}; +#endif +#if defined(SUN4M) +static int ledmamedia[] = { + IFM_ETHER | IFM_10_T, + IFM_ETHER | IFM_10_5, + IFM_ETHER | IFM_AUTO +}; +#endif +static int lebaremedia[] = { + IFM_ETHER | IFM_10_5 +}; #if defined(SUN4M) /* * media change methods (only for sun4m) */ -void lesetutp(struct am7990_softc *); -void lesetaui(struct am7990_softc *); +void lesetutp(struct lance_softc *); +void lesetaui(struct lance_softc *); #endif /* SUN4M */ #if defined(SUN4M) /* XXX */ @@ -105,10 +123,9 @@ int myleintr(void *); int ledmaintr(struct dma_softc *); int -myleintr(arg) - void *arg; +myleintr(void *arg) { - register struct le_softc *lesc = arg; + struct le_softc *lesc = arg; static int dodrain=0; if (lesc->sc_dma->sc_regs->csr & D_ERR_PEND) { @@ -130,26 +147,24 @@ struct cfattach le_ca = { sizeof(struct le_softc), lematch, leattach }; -hide void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -hide u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); -hide void lehwreset(struct am7990_softc *); -hide void lehwinit(struct am7990_softc *); +void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t lerdcsr(struct lance_softc *, uint16_t); +void lehwreset(struct lance_softc *); +void lehwinit(struct lance_softc *); #if defined(SUN4M) -hide void lenocarrier(struct am7990_softc *); +void lenocarrier(struct lance_softc *); #endif #if defined(solbourne) -hide void kap_copytobuf(struct am7990_softc *, void *, int, int); -hide void kap_copyfrombuf(struct am7990_softc *, void *, int, int); +void kap_copytobuf(struct lance_softc *, void *, int, int); +void kap_copyfrombuf(struct lance_softc *, void *, int, int); #endif -hide void -lewrcsr(sc, port, val) - struct am7990_softc *sc; - u_int16_t port, val; +void +lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { - register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; + struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; #if defined(SUN4M) - volatile u_int16_t discard; + volatile uint16_t discard; #endif ler1->ler1_rap = port; @@ -165,13 +180,11 @@ lewrcsr(sc, port, val) #endif } -hide u_int16_t -lerdcsr(sc, port) - struct am7990_softc *sc; - u_int16_t port; +uint16_t +lerdcsr(struct lance_softc *sc, uint16_t port) { - register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; - u_int16_t val; + struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; + uint16_t val; ler1->ler1_rap = port; val = ler1->ler1_rdp; @@ -180,8 +193,7 @@ lerdcsr(sc, port) #if defined(SUN4M) void -lesetutp(sc) - struct am7990_softc *sc; +lesetutp(struct lance_softc *sc) { struct le_softc *lesc = (struct le_softc *)sc; u_int32_t csr; @@ -198,8 +210,7 @@ lesetutp(sc) } void -lesetaui(sc) - struct am7990_softc *sc; +lesetaui(struct lance_softc *sc) { struct le_softc *lesc = (struct le_softc *)sc; u_int32_t csr; @@ -217,10 +228,8 @@ lesetaui(sc) #endif int -lemediachange(ifp) - struct ifnet *ifp; +lemediachange(struct lance_softc *sc) { - struct am7990_softc *sc = ifp->if_softc; struct ifmedia *ifm = &sc->sc_ifmedia; #if defined(SUN4M) struct le_softc *lesc = (struct le_softc *)sc; @@ -270,12 +279,9 @@ lemediachange(ifp) } void -lemediastatus(ifp, ifmr) - struct ifnet *ifp; - struct ifmediareq *ifmr; +lemediastatus(struct lance_softc *sc, struct ifmediareq *ifmr) { #if defined(SUN4M) - struct am7990_softc *sc = ifp->if_softc; struct le_softc *lesc = (struct le_softc *)sc; if (lesc->sc_dma == NULL) { @@ -294,17 +300,15 @@ lemediastatus(ifp, ifmr) ifmr->ifm_active = IFM_ETHER | IFM_10_T; else ifmr->ifm_active = IFM_ETHER | IFM_10_5; - } - else + } else ifmr->ifm_active = IFM_ETHER | IFM_10_5; #else ifmr->ifm_active = IFM_ETHER | IFM_10_5; #endif } -hide void -lehwreset(sc) - struct am7990_softc *sc; +void +lehwreset(struct lance_softc *sc) { #if defined(SUN4M) struct le_softc *lesc = (struct le_softc *)sc; @@ -327,9 +331,8 @@ lehwreset(sc) #endif } -hide void -lehwinit(sc) - struct am7990_softc *sc; +void +lehwinit(struct lance_softc *sc) { #if defined(SUN4M) struct le_softc *lesc = (struct le_softc *)sc; @@ -357,9 +360,8 @@ lehwinit(sc) } #if defined(SUN4M) -hide void -lenocarrier(sc) - struct am7990_softc *sc; +void +lenocarrier(struct lance_softc *sc) { struct le_softc *lesc = (struct le_softc *)sc; @@ -392,13 +394,11 @@ lenocarrier(sc) #endif int -lematch(parent, vcf, aux) - struct device *parent; - void *vcf, *aux; +lematch(struct device *parent, void *vcf, void *aux) { struct cfdata *cf = vcf; struct confargs *ca = aux; - register struct romaux *ra = &ca->ca_ra; + struct romaux *ra = &ca->ca_ra; if (strcmp(cf->cf_driver->cd_name, ra->ra_name)) return (0); @@ -419,12 +419,10 @@ lematch(parent, vcf, aux) } void -leattach(parent, self, aux) - struct device *parent, *self; - void *aux; +leattach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct confargs *ca = aux; int pri; struct bootpath *bp; @@ -445,7 +443,6 @@ leattach(parent, self, aux) pri = ca->ca_ra.ra_intr[0].int_pri; printf(" pri %d", pri); - sc->sc_hasifmedia = 1; #if defined(SUN4C) || defined(SUN4D) || defined(SUN4E) || defined(SUN4M) lesc->sc_lebufchild = lebufchild; #endif @@ -565,11 +562,11 @@ leattach(parent, self, aux) myetheraddr(sc->sc_arpcom.ac_enaddr); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = lerdcsr; sc->sc_wrcsr = lewrcsr; @@ -580,27 +577,27 @@ leattach(parent, self, aux) #endif sc->sc_hwreset = lehwreset; - ifmedia_init(&sc->sc_ifmedia, 0, lemediachange, lemediastatus); + sc->sc_mediachange = lemediachange; + sc->sc_mediastatus = lemediastatus; #if defined(SUN4C) || defined(SUN4D) || defined(SUN4E) || defined(SUN4M) if (lebufchild) { - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); - ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T); + sc->sc_supmedia = lebufmedia; + sc->sc_nsupmedia = nitems(lebufmedia); } else #endif #if defined(SUN4M) if (CPU_ISSUN4M && lesc->sc_dma) { - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_5, 0, NULL); - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL); - ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO); + sc->sc_supmedia = ledmamedia; + sc->sc_nsupmedia = nitems(ledmamedia); } else #endif { - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_5, 0, NULL); - ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_10_5); + sc->sc_supmedia = lebaremedia; + sc->sc_nsupmedia = nitems(lebaremedia); } + sc->sc_defaultmedia = sc->sc_supmedia[sc->sc_nsupmedia - 1]; - am7990_config(sc); + am7990_config(&lesc->sc_am7990); #if defined(solbourne) if (CPU_ISKAP && ca->ca_bustype == BUS_OBIO) { @@ -626,14 +623,14 @@ leattach(parent, self, aux) } #if defined(solbourne) -hide void -kap_copytobuf(struct am7990_softc *sc, void *to, int boff, int len) +void +kap_copytobuf(struct lance_softc *sc, void *to, int boff, int len) { - return (am7990_copytobuf_contig(sc, to, boff & ~(1 << 23), len)); + return (lance_copytobuf_contig(sc, to, boff & ~(1 << 23), len)); } -hide void -kap_copyfrombuf(struct am7990_softc *sc, void *from, int boff, int len) +void +kap_copyfrombuf(struct lance_softc *sc, void *from, int boff, int len) { - return (am7990_copyfrombuf_contig(sc, from, boff & ~(1 << 23), len)); + return (lance_copyfrombuf_contig(sc, from, boff & ~(1 << 23), len)); } #endif diff --git a/sys/arch/vax/conf/files.vax b/sys/arch/vax/conf/files.vax index 5b8b0fdcc6c..f34e4813649 100644 --- a/sys/arch/vax/conf/files.vax +++ b/sys/arch/vax/conf/files.vax @@ -1,4 +1,4 @@ -# $OpenBSD: files.vax,v 1.56 2011/09/04 08:03:32 miod Exp $ +# $OpenBSD: files.vax,v 1.57 2013/09/24 20:10:50 miod Exp $ # $NetBSD: files.vax,v 1.60 1999/08/27 20:04:32 ragge Exp $ # # new style config file for vax architecture @@ -42,7 +42,7 @@ file arch/vax/vsa/if_ze_vsbus.c ze_vsbus attach ze at vxtbus with ze_vxtbus file arch/vax/vxt/if_ze_vxtbus.c ze_vxtbus -attach le at ibus with le_ibus +attach le at ibus with le_ibus: le24 file arch/vax/if/if_le.c le_ibus # MSCP device drivers @@ -109,7 +109,7 @@ attach ncr at vsbus file arch/vax/vsa/ncr.c ncr needs-flag # LANCE ethernet controller on VAXstation -attach le at vsbus with le_vsbus +attach le at vsbus with le_vsbus: le24 file arch/vax/vsa/if_le_vsbus.c le_vsbus # Monochrome (on-board) framebuffer on VS3100 diff --git a/sys/arch/vax/if/if_le.c b/sys/arch/vax/if/if_le.c index 9a1f4a18ea8..6d639c4c81c 100644 --- a/sys/arch/vax/if/if_le.c +++ b/sys/arch/vax/if/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.17 2010/09/20 06:33:47 matthew Exp $ */ +/* $OpenBSD: if_le.c,v 1.18 2013/09/24 20:10:51 miod Exp $ */ /* $NetBSD: if_le.c,v 1.14 1999/08/14 18:40:23 ragge Exp $ */ /*- @@ -87,6 +87,8 @@ #include <machine/nexus.h> #include <machine/scb.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -97,26 +99,24 @@ struct le_softc { struct am7990_softc sc_am7990; /* Must be first */ struct evcount sc_intrcnt; int sc_vec; - volatile u_short *sc_rap; - volatile u_short *sc_rdp; + volatile uint16_t *sc_rap; + volatile uint16_t *sc_rdp; }; int le_ibus_match(struct device *, void *, void *); void le_ibus_attach(struct device *, struct device *, void *); -void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); -void lance_copytobuf_gap2(struct am7990_softc *, void *, int, int); -void lance_copyfrombuf_gap2(struct am7990_softc *, void *, int, int); -void lance_zerobuf_gap2(struct am7990_softc *, int, int); +void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t lerdcsr(struct lance_softc *, uint16_t); +void lance_copytobuf_gap2(struct lance_softc *, void *, int, int); +void lance_copyfrombuf_gap2(struct lance_softc *, void *, int, int); +void lance_zerobuf_gap2(struct lance_softc *, int, int); struct cfattach le_ibus_ca = { sizeof(struct le_softc), le_ibus_match, le_ibus_attach }; void -lewrcsr(ls, port, val) - struct am7990_softc *ls; - u_int16_t port, val; +lewrcsr(struct lance_softc *ls, uint16_t port, uint16_t val) { struct le_softc *sc = (void *)ls; @@ -124,10 +124,8 @@ lewrcsr(ls, port, val) *sc->sc_rdp = val; } -u_int16_t -lerdcsr(ls, port) - struct am7990_softc *ls; - u_int16_t port; +uint16_t +lerdcsr(struct lance_softc *ls, uint16_t port) { struct le_softc *sc = (void *)ls; @@ -136,10 +134,7 @@ lerdcsr(ls, port) } int -le_ibus_match(parent, cf, aux) - struct device *parent; - void *cf; - void *aux; +le_ibus_match(struct device *parent, void *cf, void *aux) { struct bp_conf *bp = aux; @@ -149,70 +144,64 @@ le_ibus_match(parent, cf, aux) } void -le_ibus_attach(parent, self, aux) - struct device *parent, *self; - void *aux; +le_ibus_attach(struct device *parent, struct device *self, void *aux) { - struct le_softc *sc = (void *)self; + struct le_softc *lesc = (void *)self; + struct lance_softc *sc = &lesc->sc_am7990.lsc; int *lance_addr; int i, br; - sc->sc_rdp = (short *)vax_map_physmem(0x20084400, 1); - sc->sc_rap = sc->sc_rdp + 2; + lesc->sc_rdp = (short *)vax_map_physmem(0x20084400, 1); + lesc->sc_rap = lesc->sc_rdp + 2; /* * Set interrupt vector, by forcing an interrupt. */ scb_vecref(0, 0); /* Clear vector ref */ - *sc->sc_rap = LE_CSR0; - *sc->sc_rdp = LE_C0_STOP; + *lesc->sc_rap = LE_CSR0; + *lesc->sc_rdp = LE_C0_STOP; DELAY(100); - *sc->sc_rdp = LE_C0_INIT|LE_C0_INEA; + *lesc->sc_rdp = LE_C0_INIT|LE_C0_INEA; DELAY(100000); - i = scb_vecref(&sc->sc_vec, &br); - if (i == 0 || sc->sc_vec == 0) + i = scb_vecref(&lesc->sc_vec, &br); + if (i == 0 || lesc->sc_vec == 0) return; - scb_vecalloc(sc->sc_vec, (void *)am7990_intr, sc, - SCB_ISTACK, &sc->sc_intrcnt); - evcount_attach(&sc->sc_intrcnt, self->dv_xname, &sc->sc_vec); + scb_vecalloc(lesc->sc_vec, (void *)am7990_intr, sc, + SCB_ISTACK, &lesc->sc_intrcnt); + evcount_attach(&lesc->sc_intrcnt, self->dv_xname, &lesc->sc_vec); - printf(": vec %d ipl %x\n%s", sc->sc_vec, br, self->dv_xname); + printf(": vec %d ipl %x\n%s", lesc->sc_vec, br, self->dv_xname); /* * MD functions. */ - sc->sc_am7990.sc_rdcsr = lerdcsr; - sc->sc_am7990.sc_wrcsr = lewrcsr; - sc->sc_am7990.sc_nocarrier = NULL; + sc->sc_rdcsr = lerdcsr; + sc->sc_wrcsr = lewrcsr; + sc->sc_nocarrier = NULL; - sc->sc_am7990.sc_mem = - (void *)uvm_km_valloc(kernel_map, (128 * 1024)); - if (sc->sc_am7990.sc_mem == 0) + sc->sc_mem = (void *)uvm_km_valloc(kernel_map, (128 * 1024)); + if (sc->sc_mem == 0) return; - ioaccess((vaddr_t)sc->sc_am7990.sc_mem, 0x20120000, - (128 * 1024) >> VAX_PGSHIFT); + ioaccess((vaddr_t)sc->sc_mem, 0x20120000, (128 * 1024) >> VAX_PGSHIFT); - - sc->sc_am7990.sc_addr = 0; - sc->sc_am7990.sc_memsize = (64 * 1024); + sc->sc_addr = 0; + sc->sc_memsize = (64 * 1024); - sc->sc_am7990.sc_copytodesc = lance_copytobuf_gap2; - sc->sc_am7990.sc_copyfromdesc = lance_copyfrombuf_gap2; - sc->sc_am7990.sc_copytobuf = lance_copytobuf_gap2; - sc->sc_am7990.sc_copyfrombuf = lance_copyfrombuf_gap2; - sc->sc_am7990.sc_zerobuf = lance_zerobuf_gap2; + sc->sc_copytodesc = lance_copytobuf_gap2; + sc->sc_copyfromdesc = lance_copyfrombuf_gap2; + sc->sc_copytobuf = lance_copytobuf_gap2; + sc->sc_copyfrombuf = lance_copyfrombuf_gap2; + sc->sc_zerobuf = lance_zerobuf_gap2; /* * Get the ethernet address out of rom */ lance_addr = (int *)vax_map_physmem(0x20084200, 1); for (i = 0; i < 6; i++) - sc->sc_am7990.sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i]; + sc->sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i]; vax_unmap_physmem((vaddr_t)lance_addr, 1); - bcopy(self->dv_xname, sc->sc_am7990.sc_arpcom.ac_if.if_xname, - IFNAMSIZ); - am7990_config(&sc->sc_am7990); + am7990_config(&lesc->sc_am7990); } /* @@ -223,24 +212,20 @@ le_ibus_attach(parent, self, aux) */ void -lance_copytobuf_gap2(sc, fromv, boff, len) - struct am7990_softc *sc; - void *fromv; - int boff; - register int len; +lance_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len) { volatile caddr_t buf = sc->sc_mem; - register caddr_t from = fromv; - register volatile u_int16_t *bptr; + caddr_t from = fromv; + volatile uint16_t *bptr; if (boff & 0x1) { /* handle unaligned first byte */ - bptr = ((volatile u_int16_t *)buf) + (boff - 1); + bptr = ((volatile uint16_t *)buf) + (boff - 1); *bptr = (*from++ << 8) | (*bptr & 0xff); bptr += 2; len--; } else - bptr = ((volatile u_int16_t *)buf) + boff; + bptr = ((volatile uint16_t *)buf) + boff; while (len > 1) { *bptr = (from[1] << 8) | (from[0] & 0xff); bptr += 2; @@ -248,28 +233,25 @@ lance_copytobuf_gap2(sc, fromv, boff, len) len -= 2; } if (len == 1) - *bptr = (u_int16_t)*from; + *bptr = (uint16_t)*from; } void -lance_copyfrombuf_gap2(sc, tov, boff, len) - struct am7990_softc *sc; - void *tov; - int boff, len; +lance_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len) { volatile caddr_t buf = sc->sc_mem; - register caddr_t to = tov; - register volatile u_int16_t *bptr; - register u_int16_t tmp; + caddr_t to = tov; + volatile uint16_t *bptr; + uint16_t tmp; if (boff & 0x1) { /* handle unaligned first byte */ - bptr = ((volatile u_int16_t *)buf) + (boff - 1); + bptr = ((volatile uint16_t *)buf) + (boff - 1); *to++ = (*bptr >> 8) & 0xff; bptr += 2; len--; } else - bptr = ((volatile u_int16_t *)buf) + boff; + bptr = ((volatile uint16_t *)buf) + boff; while (len > 1) { tmp = *bptr; *to++ = tmp & 0xff; @@ -282,20 +264,18 @@ lance_copyfrombuf_gap2(sc, tov, boff, len) } void -lance_zerobuf_gap2(sc, boff, len) - struct am7990_softc *sc; - int boff, len; +lance_zerobuf_gap2(struct lance_softc *sc, int boff, int len) { volatile caddr_t buf = sc->sc_mem; - register volatile u_int16_t *bptr; + volatile uint16_t *bptr; if ((unsigned)boff & 0x1) { - bptr = ((volatile u_int16_t *)buf) + (boff - 1); + bptr = ((volatile uint16_t *)buf) + (boff - 1); *bptr &= 0xff; bptr += 2; len--; } else - bptr = ((volatile u_int16_t *)buf) + boff; + bptr = ((volatile uint16_t *)buf) + boff; while (len > 0) { *bptr = 0; bptr += 2; diff --git a/sys/arch/vax/mbus/files.mbus b/sys/arch/vax/mbus/files.mbus index 88d0de15eea..c177328494a 100644 --- a/sys/arch/vax/mbus/files.mbus +++ b/sys/arch/vax/mbus/files.mbus @@ -1,4 +1,4 @@ -# $OpenBSD: files.mbus,v 1.2 2008/08/20 19:00:01 miod Exp $ +# $OpenBSD: files.mbus,v 1.3 2013/09/24 20:10:52 miod Exp $ # VAXstation 3[58][24]0 internal bus device mbus { [mid = -1] } @@ -13,7 +13,7 @@ file arch/vax/mbus/fwio.c fwio attach dz at fwio with dz_fwio: dzcons file arch/vax/mbus/dz_fwio.c dz_fwio -attach le at fwio with le_fwio +attach le at fwio with le_fwio: le24 file arch/vax/mbus/if_le_fwio.c le_fwio attach sii at fwio with sii_fwio diff --git a/sys/arch/vax/mbus/if_le_fwio.c b/sys/arch/vax/mbus/if_le_fwio.c index 67adf19d662..36c9975b496 100644 --- a/sys/arch/vax/mbus/if_le_fwio.c +++ b/sys/arch/vax/mbus/if_le_fwio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_fwio.c,v 1.2 2008/10/22 23:04:45 mpf Exp $ */ +/* $OpenBSD: if_le_fwio.c,v 1.3 2013/09/24 20:10:52 miod Exp $ */ /* * Copyright (c) 2008 Miodrag Vallat. @@ -103,6 +103,8 @@ #include <vax/mbus/fwioreg.h> #include <vax/mbus/fwiovar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -120,9 +122,9 @@ struct cfattach le_fwio_ca = { }; int le_fwio_intr(void *); -uint16_t le_fwio_rdcsr(struct am7990_softc *, uint16_t); -void le_fwio_wrcsr(struct am7990_softc *, uint16_t, uint16_t); -void le_fwio_wrcsr_interrupt(struct am7990_softc *, uint16_t, uint16_t); +uint16_t le_fwio_rdcsr(struct lance_softc *, uint16_t); +void le_fwio_wrcsr(struct lance_softc *, uint16_t, uint16_t); +void le_fwio_wrcsr_interrupt(struct lance_softc *, uint16_t, uint16_t); int le_fwio_match(struct device *parent, void *vcf, void *aux) @@ -136,7 +138,8 @@ void le_fwio_attach(struct device *parent, struct device *self, void *aux) { struct fwio_attach_args *faa = (struct fwio_attach_args *)aux; - struct le_fwio_softc *sc = (struct le_fwio_softc *)self; + struct le_fwio_softc *lsc = (struct le_fwio_softc *)self; + struct lance_softc *sc = &lsc->sc_am7990.lsc; unsigned int vec; uint32_t *esar; int i; @@ -148,41 +151,40 @@ le_fwio_attach(struct device *parent, struct device *self, void *aux) * Map registers. */ - sc->sc_rdp = (volatile uint16_t *) + lsc->sc_rdp = (volatile uint16_t *) vax_map_physmem(faa->faa_base + FWIO_LANCE_REG_OFFSET, 1); - sc->sc_rap = sc->sc_rdp + 2; + lsc->sc_rap = lsc->sc_rdp + 2; /* * Register access functions. */ - sc->sc_am7990.sc_rdcsr = le_fwio_rdcsr; - sc->sc_am7990.sc_wrcsr = le_fwio_wrcsr; + sc->sc_rdcsr = le_fwio_rdcsr; + sc->sc_wrcsr = le_fwio_wrcsr; /* * Map buffers. */ - sc->sc_am7990.sc_mem = - (void *)uvm_km_valloc(kernel_map, FWIO_LANCE_BUF_SIZE); - if (sc->sc_am7990.sc_mem == NULL) { + sc->sc_mem = (void *)uvm_km_valloc(kernel_map, FWIO_LANCE_BUF_SIZE); + if (sc->sc_mem == NULL) { vax_unmap_physmem(faa->faa_base + FWIO_LANCE_REG_OFFSET, 1); printf(": can't map buffers\n"); return; } - ioaccess((vaddr_t)sc->sc_am7990.sc_mem, faa->faa_base + + ioaccess((vaddr_t)sc->sc_mem, faa->faa_base + FWIO_LANCE_BUF_OFFSET, FWIO_LANCE_BUF_SIZE >> VAX_PGSHIFT); - sc->sc_am7990.sc_addr = FWIO_LANCE_BUF_OFFSET; - sc->sc_am7990.sc_memsize = FWIO_LANCE_BUF_SIZE; - sc->sc_am7990.sc_conf3 = 0; + sc->sc_addr = FWIO_LANCE_BUF_OFFSET; + sc->sc_memsize = FWIO_LANCE_BUF_SIZE; + sc->sc_conf3 = 0; - sc->sc_am7990.sc_copytodesc = am7990_copytobuf_contig; - sc->sc_am7990.sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_am7990.sc_copytobuf = am7990_copytobuf_contig; - sc->sc_am7990.sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_am7990.sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; /* * Get the Ethernet address from the Station Address ROM. @@ -190,10 +192,9 @@ le_fwio_attach(struct device *parent, struct device *self, void *aux) esar = (uint32_t *)vax_map_physmem(faa->faa_base + FWIO_ESAR_OFFSET, 1); for (i = 0; i < 6; i++) - sc->sc_am7990.sc_arpcom.ac_enaddr[i] = + sc->sc_arpcom.ac_enaddr[i] = (esar[i] & FWIO_ESAR_MASK) >> FWIO_ESAR_SHIFT; vax_unmap_physmem((vaddr_t)esar, 1); - bcopy(self->dv_xname, sc->sc_am7990.sc_arpcom.ac_if.if_xname, IFNAMSIZ); /* * Register interrupt handler. @@ -202,7 +203,7 @@ le_fwio_attach(struct device *parent, struct device *self, void *aux) if (mbus_intr_establish(vec, IPL_NET, le_fwio_intr, sc, self->dv_xname) != 0) { vax_unmap_physmem(faa->faa_base + FWIO_LANCE_REG_OFFSET, 1); - uvm_km_free(kernel_map, (vaddr_t)sc->sc_am7990.sc_mem, + uvm_km_free(kernel_map, (vaddr_t)sc->sc_mem, FWIO_LANCE_BUF_SIZE); printf(": can't establish interrupt\n"); return; @@ -212,13 +213,14 @@ le_fwio_attach(struct device *parent, struct device *self, void *aux) * Complete attachment. */ - am7990_config(&sc->sc_am7990); + am7990_config(&lsc->sc_am7990); } int le_fwio_intr(void *v) { struct le_fwio_softc *lsc = (struct le_fwio_softc *)v; + struct lance_softc *sc = &lsc->sc_am7990.lsc; int rc; /* @@ -230,22 +232,21 @@ le_fwio_intr(void *v) * itself; we override wrcsr with a specific version during * servicing, so as not to reenable interrupts accidentally... */ - lsc->sc_am7990.sc_wrcsr = le_fwio_wrcsr_interrupt; + sc->sc_wrcsr = le_fwio_wrcsr_interrupt; rc = am7990_intr(v); - lsc->sc_am7990.sc_wrcsr = le_fwio_wrcsr; + sc->sc_wrcsr = le_fwio_wrcsr; /* * ...but we should not forget to reenable interrupts at this point! */ - le_fwio_wrcsr(&lsc->sc_am7990, LE_CSR0, LE_C0_INEA | - le_fwio_rdcsr(&lsc->sc_am7990, LE_CSR0)); + le_fwio_wrcsr(sc, LE_CSR0, LE_C0_INEA | le_fwio_rdcsr(sc, LE_CSR0)); return rc; } uint16_t -le_fwio_rdcsr(struct am7990_softc *sc, uint16_t port) +le_fwio_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_fwio_softc *lsc = (struct le_fwio_softc *)sc; @@ -254,7 +255,7 @@ le_fwio_rdcsr(struct am7990_softc *sc, uint16_t port) } void -le_fwio_wrcsr(struct am7990_softc *sc, uint16_t port, uint16_t val) +le_fwio_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_fwio_softc *lsc = (struct le_fwio_softc *)sc; @@ -263,7 +264,7 @@ le_fwio_wrcsr(struct am7990_softc *sc, uint16_t port, uint16_t val) } void -le_fwio_wrcsr_interrupt(struct am7990_softc *sc, uint16_t port, uint16_t val) +le_fwio_wrcsr_interrupt(struct lance_softc *sc, uint16_t port, uint16_t val) { if (port == LE_CSR0) val &= ~LE_C0_INEA; diff --git a/sys/arch/vax/vsa/if_le_vsbus.c b/sys/arch/vax/vsa/if_le_vsbus.c index 909bd74b397..fd4692d4113 100644 --- a/sys/arch/vax/vsa/if_le_vsbus.c +++ b/sys/arch/vax/vsa/if_le_vsbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_vsbus.c,v 1.13 2011/08/26 21:52:22 miod Exp $ */ +/* $OpenBSD: if_le_vsbus.c,v 1.14 2013/09/24 20:10:53 miod Exp $ */ /* $NetBSD: if_le_vsbus.c,v 1.10 2000/06/29 07:14:18 mrg Exp $ */ /*- @@ -88,6 +88,8 @@ #include <machine/bus.h> #include <machine/vsbus.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -101,17 +103,15 @@ struct le_softc { static int le_vsbus_match(struct device *, struct cfdata *, void *); static void le_vsbus_attach(struct device *, struct device *, void *); -static void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -static u_int16_t lerdcsr(struct am7990_softc *, u_int16_t); +static void lewrcsr(struct lance_softc *, uint16_t, uint16_t); +static uint16_t lerdcsr(struct lance_softc *, uint16_t); struct cfattach le_vsbus_ca = { sizeof(struct le_softc), (cfmatch_t)le_vsbus_match, le_vsbus_attach }; static void -lewrcsr(ls, port, val) - struct am7990_softc *ls; - u_int16_t port, val; +lewrcsr(struct lance_softc *ls, uint16_t port, uint16_t val) { struct le_softc *sc = (void *)ls; @@ -119,10 +119,8 @@ lewrcsr(ls, port, val) *sc->sc_rdp = val; } -static u_int16_t -lerdcsr(ls, port) - struct am7990_softc *ls; - u_int16_t port; +static uint16_t +lerdcsr(struct lance_softc *ls, uint16_t port) { struct le_softc *sc = (void *)ls; @@ -131,10 +129,7 @@ lerdcsr(ls, port) } static int -le_vsbus_match(parent, cf, aux) - struct device *parent; - struct cfdata *cf; - void *aux; +le_vsbus_match(struct device *parent, struct cfdata *cf, void *aux) { struct vsbus_attach_args *va = aux; volatile short *rdp, *rap; @@ -193,31 +188,30 @@ le_vsbus_match(parent, cf, aux) } static void -le_vsbus_attach(parent, self, aux) - struct device *parent, *self; - void *aux; +le_vsbus_attach(struct device *parent, struct device *self, void *aux) { struct vsbus_attach_args *va = aux; - struct le_softc *sc = (void *)self; + struct le_softc *lesc = (void *)self; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_dma_segment_t seg; int *lance_addr; int i, err, rseg; static int cvec; - sc->sc_rdp = (short *)vax_map_physmem(NI_BASE, 1); - sc->sc_rap = sc->sc_rdp + 2; + lesc->sc_rdp = (short *)vax_map_physmem(NI_BASE, 1); + lesc->sc_rap = lesc->sc_rdp + 2; /* * MD functions. */ - sc->sc_am7990.sc_rdcsr = lerdcsr; - sc->sc_am7990.sc_wrcsr = lewrcsr; - sc->sc_am7990.sc_nocarrier = NULL; + sc->sc_rdcsr = lerdcsr; + sc->sc_wrcsr = lewrcsr; + sc->sc_nocarrier = NULL; - scb_vecalloc(va->va_cvec, (void (*)(void *)) am7990_intr, sc, - SCB_ISTACK, &sc->sc_intrcnt); + scb_vecalloc(va->va_cvec, (void (*)(void *))am7990_intr, sc, + SCB_ISTACK, &lesc->sc_intrcnt); cvec = va->va_cvec; - evcount_attach(&sc->sc_intrcnt, self->dv_xname, &cvec); + evcount_attach(&lesc->sc_intrcnt, self->dv_xname, &cvec); /* * Allocate a (DMA-safe) block for all descriptors and buffers. @@ -231,54 +225,51 @@ le_vsbus_attach(parent, self, aux) return; } err = bus_dmamem_map(va->va_dmat, &seg, rseg, ALLOCSIZ, - (caddr_t *)&sc->sc_am7990.sc_mem, - BUS_DMA_NOWAIT|BUS_DMA_COHERENT); + (caddr_t *)&sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT); if (err) { printf(": unable to map buffer block: err %d\n", err); bus_dmamem_free(va->va_dmat, &seg, rseg); return; } err = bus_dmamap_create(va->va_dmat, ALLOCSIZ, rseg, ALLOCSIZ, - 0, BUS_DMA_NOWAIT, &sc->sc_dm); + 0, BUS_DMA_NOWAIT, &lesc->sc_dm); if (err) { printf(": unable to create dma map: err %d\n", err); bus_dmamem_free(va->va_dmat, &seg, rseg); return; } - err = bus_dmamap_load(va->va_dmat, sc->sc_dm, sc->sc_am7990.sc_mem, + err = bus_dmamap_load(va->va_dmat, lesc->sc_dm, sc->sc_mem, ALLOCSIZ, NULL, BUS_DMA_NOWAIT); if (err) { printf(": unable to load dma map: err %d\n", err); - bus_dmamap_destroy(va->va_dmat, sc->sc_dm); + bus_dmamap_destroy(va->va_dmat, lesc->sc_dm); bus_dmamem_free(va->va_dmat, &seg, rseg); return; } - printf(" buf 0x%lx-0x%lx", sc->sc_dm->dm_segs->ds_addr, - sc->sc_dm->dm_segs->ds_addr + sc->sc_dm->dm_segs->ds_len - 1); - sc->sc_am7990.sc_addr = sc->sc_dm->dm_segs->ds_addr & 0xffffff; - sc->sc_am7990.sc_memsize = sc->sc_dm->dm_segs->ds_len; + printf(" buf 0x%lx-0x%lx", lesc->sc_dm->dm_segs->ds_addr, + lesc->sc_dm->dm_segs->ds_addr + lesc->sc_dm->dm_segs->ds_len - 1); + sc->sc_addr = lesc->sc_dm->dm_segs->ds_addr & 0xffffff; + sc->sc_memsize = lesc->sc_dm->dm_segs->ds_len; - sc->sc_am7990.sc_copytodesc = am7990_copytobuf_contig; - sc->sc_am7990.sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_am7990.sc_copytobuf = am7990_copytobuf_contig; - sc->sc_am7990.sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_am7990.sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; #ifdef LEDEBUG - sc->sc_am7990.sc_debug = 1; + sc->sc_debug = 1; #endif /* * Get the ethernet address out of rom */ lance_addr = (int *)vax_map_physmem(NI_ADDR, 1); for (i = 0; i < 6; i++) - sc->sc_am7990.sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i]; + sc->sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i]; vax_unmap_physmem((vaddr_t)lance_addr, 1); - bcopy(self->dv_xname, sc->sc_am7990.sc_arpcom.ac_if.if_xname, - IFNAMSIZ); /* Prettier printout */ printf("\n%s", self->dv_xname); - am7990_config(&sc->sc_am7990); + am7990_config(&lesc->sc_am7990); } diff --git a/sys/conf/files b/sys/conf/files index f97c6c4c068..c78cd0aa4d3 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.553 2013/09/24 09:20:11 espie Exp $ +# $OpenBSD: files,v 1.554 2013/09/24 20:10:53 miod Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -262,7 +262,11 @@ file dev/ic/an.c an # LANCE and PCnet Ethernet controllers device le: ether, ifnet, ifmedia -file dev/ic/am7990.c le +define le24 +define le32 +file dev/ic/am7990.c le24 +file dev/ic/am79900.c le32 +file dev/ic/lance.c le24 | le32 # 3Com 3c9xx device xl: ether, ifnet, ifmedia, mii diff --git a/sys/dev/dec/if_le_dec.c b/sys/dev/dec/if_le_dec.c index 22e411f89fa..4afa0c528af 100644 --- a/sys/dev/dec/if_le_dec.c +++ b/sys/dev/dec/if_le_dec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_dec.c,v 1.4 2007/06/18 21:24:43 jasper Exp $ */ +/* $OpenBSD: if_le_dec.c,v 1.5 2013/09/24 20:10:54 miod Exp $ */ /* $NetBSD: if_le_dec.c,v 1.12 2001/11/13 12:49:45 lukem Exp $ */ /*- @@ -52,6 +52,8 @@ #include <netinet/if_ether.h> #endif +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -65,27 +67,28 @@ void le_dec_writereg(volatile u_short *regptr, u_short val); #define LERDWR(cntl, src, dst) { (dst) = (src); tc_mb(); } #define LEWREG(src, dst) le_dec_writereg(&(dst), (src)) -void le_dec_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t le_dec_rdcsr(struct am7990_softc *, u_int16_t); +void le_dec_wrcsr(struct lance_softc *, u_int16_t, u_int16_t); +u_int16_t le_dec_rdcsr(struct lance_softc *, u_int16_t); void dec_le_common_attach(struct am7990_softc *sc, u_char *eap) { + struct lance_softc *lsc = &sc->lsc; int i; - sc->sc_rdcsr = le_dec_rdcsr; - sc->sc_wrcsr = le_dec_wrcsr; - sc->sc_hwinit = NULL; + lsc->sc_rdcsr = le_dec_rdcsr; + lsc->sc_wrcsr = le_dec_wrcsr; + lsc->sc_hwinit = NULL; - sc->sc_conf3 = 0; - sc->sc_addr = 0; - sc->sc_memsize = 65536; + lsc->sc_conf3 = 0; + lsc->sc_addr = 0; + lsc->sc_memsize = 65536; /* * Get the ethernet address out of rom */ - for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) { - sc->sc_arpcom.ac_enaddr[i] = *eap; + for (i = 0; i < sizeof(lsc->sc_arpcom.ac_enaddr); i++) { + lsc->sc_arpcom.ac_enaddr[i] = *eap; eap += 4; } @@ -93,7 +96,7 @@ dec_le_common_attach(struct am7990_softc *sc, u_char *eap) } void -le_dec_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) +le_dec_wrcsr(struct lance_softc *sc, u_int16_t port, u_int16_t val) { struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; @@ -102,7 +105,7 @@ le_dec_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) } u_int16_t -le_dec_rdcsr(struct am7990_softc *sc, u_int16_t port) +le_dec_rdcsr(struct lance_softc *sc, u_int16_t port) { struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; u_int16_t val; @@ -136,7 +139,7 @@ le_dec_writereg(volatile u_short *regptr, u_short val) /* * Routines for accessing the transmit and receive buffers are provided - * by am7990.c, because of the LE_NEED_BUF_* macros defined above. + * by lance.c, because of the LE_NEED_BUF_* macros defined above. * Unfortunately, CPU addressing of these buffers is done in one of * 3 ways: * - contiguous (for the 3max and turbochannel option card) diff --git a/sys/dev/ic/am7990.c b/sys/dev/ic/am7990.c index 0ef2a94e81b..137592a9860 100644 --- a/sys/dev/ic/am7990.c +++ b/sys/dev/ic/am7990.c @@ -1,8 +1,37 @@ -/* $OpenBSD: am7990.c,v 1.46 2013/08/07 01:06:27 bluhm Exp $ */ -/* $NetBSD: am7990.c,v 1.22 1996/10/13 01:37:19 christos Exp $ */ +/* $OpenBSD: am7990.c,v 1.47 2013/09/24 20:10:55 miod Exp $ */ +/* $NetBSD: am7990.c,v 1.74 2012/02/02 19:43:02 tls Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /*- - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -40,7 +69,7 @@ #include <sys/param.h> #include <sys/systm.h> -#include <sys/mbuf.h> +#include <sys/mbuf.h> #include <sys/syslog.h> #include <sys/socket.h> #include <sys/device.h> @@ -62,183 +91,85 @@ #include <net/bpf.h> #endif +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> -#ifdef LEDEBUG -void am7990_recv_print(struct am7990_softc *, int); -void am7990_xmit_print(struct am7990_softc *, int); -#endif - -integrate void am7990_rint(struct am7990_softc *); -integrate void am7990_tint(struct am7990_softc *); - -integrate int am7990_put(struct am7990_softc *, int, struct mbuf *); -integrate struct mbuf *am7990_get(struct am7990_softc *, int, int); -integrate void am7990_read(struct am7990_softc *, int, int); - -#define ifp (&sc->sc_arpcom.ac_if) - -#if 0 /* XXX what do we do about this?! --thorpej */ -static inline u_int16_t ether_cmp(void *, void *); - -/* - * Compare two Ether/802 addresses for equality, inlined and - * unrolled for speed. I'd love to have an inline assembler - * version of this... XXX: Who wanted that? mycroft? - * I wrote one, but the following is just as efficient. - * This expands to 10 short m68k instructions! -gwr - * Note: use this like bcmp() - */ -static inline u_short -ether_cmp(one, two) - void *one, *two; -{ - register u_int16_t *a = (u_short *) one; - register u_int16_t *b = (u_short *) two; - register u_int16_t diff; - - diff = *a++ - *b++; - diff |= *a++ - *b++; - diff |= *a++ - *b++; - - return (diff); -} +void am7990_meminit(struct lance_softc *); +void am7990_start(struct ifnet *); -#define ETHER_CMP ether_cmp -#endif /* XXX */ +void am7990_rint(struct lance_softc *); +void am7990_tint(struct lance_softc *); -#ifndef ETHER_CMP -#define ETHER_CMP(a, b) bcmp((a), (b), ETHER_ADDR_LEN) +#ifdef LEDEBUG +void am7990_recv_print(struct lance_softc *, int); +void am7990_xmit_print(struct lance_softc *, int); #endif /* * am7990 configuration driver. Attachments are provided by * machine-dependent driver front-ends. */ -struct cfdriver le_cd = { - NULL, "le", DV_IFNET -}; - void -am7990_config(sc) - struct am7990_softc *sc; +am7990_config(struct am7990_softc *sc) { - int mem; - - /* Make sure the chip is stopped. */ - am7990_stop(sc); - - /* Initialize ifnet structure. */ - bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); - ifp->if_softc = sc; - ifp->if_start = am7990_start; - ifp->if_ioctl = am7990_ioctl; - ifp->if_watchdog = am7990_watchdog; - ifp->if_flags = - IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; -#ifdef LANCE_REVC_BUG - ifp->if_flags &= ~IFF_MULTICAST; -#endif - ifp->if_baudrate = IF_Mbps(10); - IFQ_SET_READY(&ifp->if_snd); - - ifp->if_capabilities = IFCAP_VLAN_MTU; - - /* Attach the interface. */ - if_attach(ifp); - ether_ifattach(ifp); - - if (sc->sc_memsize > 262144) - sc->sc_memsize = 262144; - - switch (sc->sc_memsize) { - case 8192: - sc->sc_nrbuf = 4; - sc->sc_ntbuf = 1; - break; - case 16384: - sc->sc_nrbuf = 8; - sc->sc_ntbuf = 2; - break; - case 32768: - sc->sc_nrbuf = 16; - sc->sc_ntbuf = 4; - break; - case 65536: - sc->sc_nrbuf = 32; - sc->sc_ntbuf = 8; - break; - case 131072: - sc->sc_nrbuf = 64; - sc->sc_ntbuf = 16; - break; - case 262144: - sc->sc_nrbuf = 128; - sc->sc_ntbuf = 32; - break; - default: - panic("am7990_config: weird memory size %lu", sc->sc_memsize); - } + int mem, i; + + sc->lsc.sc_meminit = am7990_meminit; + sc->lsc.sc_start = am7990_start; - printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); - printf("%s: %d receive buffers, %d transmit buffers\n", - sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf); + lance_config(&sc->lsc); mem = 0; - sc->sc_initaddr = mem; + sc->lsc.sc_initaddr = mem; mem += sizeof(struct leinit); - sc->sc_rmdaddr = mem; - mem += sizeof(struct lermd) * sc->sc_nrbuf; - sc->sc_tmdaddr = mem; - mem += sizeof(struct letmd) * sc->sc_ntbuf; - sc->sc_rbufaddr = mem; - mem += ETHER_MAX_DIX_LEN * sc->sc_nrbuf; - sc->sc_tbufaddr = mem; - mem += ETHER_MAX_DIX_LEN * sc->sc_ntbuf; + sc->lsc.sc_rmdaddr = mem; + mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; + sc->lsc.sc_tmdaddr = mem; + mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; + for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN) + sc->lsc.sc_rbufaddr[i] = mem; + for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN) + sc->lsc.sc_tbufaddr[i] = mem; #ifdef notyet if (mem > ...) panic(...); #endif } -void -am7990_reset(sc) - struct am7990_softc *sc; -{ - int s; - - s = splnet(); - am7990_init(sc); - splx(s); -} - /* * Set up the initialization block and the descriptor rings. */ void -am7990_meminit(sc) - register struct am7990_softc *sc; +am7990_meminit(struct lance_softc *sc) { + struct ifnet *ifp = &sc->sc_arpcom.ac_if; u_long a; int bix; struct leinit init; struct lermd rmd; struct letmd tmd; + uint8_t *myaddr; -#if NBPFILTER > 0 if (ifp->if_flags & IFF_PROMISC) init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; else -#endif init.init_mode = LE_MODE_NORMAL; - init.init_padr[0] = - (sc->sc_arpcom.ac_enaddr[1] << 8) | sc->sc_arpcom.ac_enaddr[0]; - init.init_padr[1] = - (sc->sc_arpcom.ac_enaddr[3] << 8) | sc->sc_arpcom.ac_enaddr[2]; - init.init_padr[2] = - (sc->sc_arpcom.ac_enaddr[5] << 8) | sc->sc_arpcom.ac_enaddr[4]; - am7990_setladrf(&sc->sc_arpcom, init.init_ladrf); + if (sc->sc_initmodemedia == 1) + init.init_mode |= LE_MODE_PSEL0; + + /* + * Update our private copy of the Ethernet address. + * We NEED the copy so we can ensure its alignment! + */ + memcpy(sc->sc_enaddr, sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN); + myaddr = sc->sc_enaddr; + + init.init_padr[0] = (myaddr[1] << 8) | myaddr[0]; + init.init_padr[1] = (myaddr[3] << 8) | myaddr[2]; + init.init_padr[2] = (myaddr[5] << 8) | myaddr[4]; + lance_setladrf(&sc->sc_arpcom, init.init_ladrf); sc->sc_last_rd = 0; sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; @@ -261,7 +192,7 @@ am7990_meminit(sc) rmd.rmd0 = a; rmd.rmd1_hadr = a >> 16; rmd.rmd1_bits = LE_R1_OWN; - rmd.rmd2 = -ETHER_MAX_DIX_LEN | LE_XMD2_ONES; + rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), sizeof(rmd)); @@ -283,218 +214,10 @@ am7990_meminit(sc) } void -am7990_stop(sc) - struct am7990_softc *sc; +am7990_rint(struct lance_softc *sc) { - - (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); -} - -/* - * Initialization of interface; set up initialization block - * and transmit/receive descriptor rings. - */ -void -am7990_init(sc) - register struct am7990_softc *sc; -{ - register int timo; - u_long a; - - (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); - DELAY(100); - - /* Newer LANCE chips have a reset register */ - if (sc->sc_hwreset) - (*sc->sc_hwreset)(sc); - - /* Set the correct byte swapping mode, etc. */ - (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3); - - /* Set up LANCE init block. */ - am7990_meminit(sc); - - /* Give LANCE the physical address of its init block. */ - a = sc->sc_addr + LE_INITADDR(sc); - (*sc->sc_wrcsr)(sc, LE_CSR1, a); - (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16); - - /* Try to initialize the LANCE. */ - DELAY(100); - (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT); - - /* Wait for initialization to finish. */ - for (timo = 100000; timo; timo--) - if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) - break; - - if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) { - /* Start the LANCE. */ - (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT | - LE_C0_IDON); - ifp->if_flags |= IFF_RUNNING; - ifp->if_flags &= ~IFF_OACTIVE; - ifp->if_timer = 0; - am7990_start(ifp); - } else - printf("%s: controller failed to initialize\n", sc->sc_dev.dv_xname); - if (sc->sc_hwinit) - (*sc->sc_hwinit)(sc); -} - -/* - * Routine to copy from mbuf chain to transmit buffer in - * network buffer memory. - */ -integrate int -am7990_put(sc, boff, m) - struct am7990_softc *sc; - int boff; - register struct mbuf *m; -{ - register struct mbuf *n; - register int len, tlen = 0; - - for (; m; m = n) { - len = m->m_len; - if (len == 0) { - MFREE(m, n); - continue; - } - (*sc->sc_copytobuf)(sc, mtod(m, caddr_t), boff, len); - boff += len; - tlen += len; - MFREE(m, n); - } - if (tlen < LEMINSIZE) { - (*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen); - tlen = LEMINSIZE; - } - return (tlen); -} - -/* - * Pull data off an interface. - * Len is length of data, with local net header stripped. - * We copy the data into mbufs. When full cluster sized units are present - * we copy into clusters. - */ -integrate struct mbuf * -am7990_get(sc, boff, totlen) - struct am7990_softc *sc; - int boff, totlen; -{ - register struct mbuf *m; - struct mbuf *top, **mp; - int len, pad; - - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return (0); - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; - pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header); - m->m_data += pad; - len = MHLEN - pad; - top = 0; - mp = ⊤ - - while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return 0; - } - len = MLEN; - } - if (totlen >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if (m->m_flags & M_EXT) { - len = MCLBYTES; - if (!top) { - m->m_data += pad; - len -= pad; - } - } - } - m->m_len = len = min(totlen, len); - (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len); - boff += len; - totlen -= len; - *mp = m; - mp = &m->m_next; - } - - return (top); -} - -/* - * Pass a packet to the higher levels. - */ -integrate void -am7990_read(sc, boff, len) - register struct am7990_softc *sc; - int boff, len; -{ - struct mbuf *m; -#ifdef LANCE_REVC_BUG - struct ether_header *eh; -#endif - - if (len <= sizeof(struct ether_header) || - len > ETHERMTU + ETHER_VLAN_ENCAP_LEN + sizeof(struct ether_header)) { -#ifdef LEDEBUG - printf("%s: invalid packet size %d; dropping\n", - sc->sc_dev.dv_xname, len); -#endif - ifp->if_ierrors++; - return; - } - - /* Pull packet off interface. */ - m = am7990_get(sc, boff, len); - if (m == 0) { - ifp->if_ierrors++; - return; - } - - ifp->if_ipackets++; - -#if NBPFILTER > 0 - /* - * Check if there's a BPF listener on this interface. - * If so, hand off the raw packet to BPF. - */ - if (ifp->if_bpf) - bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_IN); -#endif - -#ifdef LANCE_REVC_BUG - /* - * The old LANCE (Rev. C) chips have a bug which causes - * garbage to be inserted in front of the received packet. - * The work-around is to ignore packets with an invalid - * destination address (garbage will usually not match). - * Of course, this precludes multicast support... - */ - eh = mtod(m, struct ether_header *); - if (ETHER_CMP(eh->ether_dhost, sc->sc_arpcom.ac_enaddr) && - ETHER_CMP(eh->ether_dhost, etherbroadcastaddr)) { - m_freem(m); - return; - } -#endif - - /* Pass the packet up. */ - ether_input_mbuf(ifp, m); -} - -integrate void -am7990_rint(sc) - struct am7990_softc *sc; -{ - register int bix; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + int bix; int rp; struct lermd rmd; @@ -535,20 +258,20 @@ am7990_rint(sc) sc->sc_dev.dv_xname); ifp->if_ierrors++; } else { -#ifdef LEDEBUG1 - if (sc->sc_debug) +#ifdef LEDEBUG + if (sc->sc_debug > 1) am7990_recv_print(sc, sc->sc_last_rd); #endif - am7990_read(sc, LE_RBUFADDR(sc, bix), + lance_read(sc, LE_RBUFADDR(sc, bix), (int)rmd.rmd3 - 4); } rmd.rmd1_bits = LE_R1_OWN; - rmd.rmd2 = -ETHER_MAX_DIX_LEN | LE_XMD2_ONES; + rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; rmd.rmd3 = 0; (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); -#ifdef LEDEBUG1 +#ifdef LEDEBUG if (sc->sc_debug) printf("sc->sc_last_rd = %x, rmd: " "ladr %04x, hadr %02x, flags %02x, " @@ -565,11 +288,11 @@ am7990_rint(sc) sc->sc_last_rd = bix; } -integrate void -am7990_tint(sc) - register struct am7990_softc *sc; +void +am7990_tint(struct lance_softc *sc) { - register int bix; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + int bix; struct letmd tmd; bix = sc->sc_first_td; @@ -602,19 +325,25 @@ am7990_tint(sc) else if (tmd.tmd3 & LE_T3_UFLO) printf("%s: underflow\n", sc->sc_dev.dv_xname); if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { - am7990_reset(sc); + lance_reset(sc); return; } if (tmd.tmd3 & LE_T3_LCAR) { + sc->sc_havecarrier = 0; if (sc->sc_nocarrier) (*sc->sc_nocarrier)(sc); + else + printf("%s: lost carrier\n", + sc->sc_dev.dv_xname); } if (tmd.tmd3 & LE_T3_LCOL) ifp->if_collisions++; if (tmd.tmd3 & LE_T3_RTRY) { +#ifdef LEDEBUG printf("%s: excessive collisions, tdr %d\n", sc->sc_dev.dv_xname, tmd.tmd3 & LE_T3_TDR_MASK); +#endif ifp->if_collisions += 16; } ifp->if_oerrors++; @@ -645,19 +374,18 @@ am7990_tint(sc) * Controller interrupt. */ int -am7990_intr(arg) - register void *arg; +am7990_intr(void *arg) { - register struct am7990_softc *sc = arg; - register u_int16_t isr; - - isr = (*sc->sc_rdcsr)(sc, LE_CSR0); -#ifdef LEDEBUG - if (sc->sc_debug){ + struct lance_softc *sc = arg; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + uint16_t isr; + + isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0; + sc->sc_saved_csr0 = 0; +#if defined(LEDEBUG) && LEDEBUG > 1 + if (sc->sc_debug) printf("%s: am7990_intr entering with isr=%04x\n", sc->sc_dev.dv_xname, isr); - printf(" isr: 0x%b\n", isr, LE_C0_BITS); - } #endif if ((isr & LE_C0_INTR) == 0) return (0); @@ -691,7 +419,7 @@ am7990_intr(arg) } if (isr & LE_C0_MERR) { printf("%s: memory error\n", sc->sc_dev.dv_xname); - am7990_reset(sc); + lance_reset(sc); return (1); } } @@ -699,16 +427,22 @@ am7990_intr(arg) if ((isr & LE_C0_RXON) == 0) { printf("%s: receiver disabled\n", sc->sc_dev.dv_xname); ifp->if_ierrors++; - am7990_reset(sc); + lance_reset(sc); return (1); } if ((isr & LE_C0_TXON) == 0) { printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname); ifp->if_oerrors++; - am7990_reset(sc); + lance_reset(sc); return (1); } + /* + * Pretend we have carrier; if we don't this will be cleared + * shortly. + */ + sc->sc_havecarrier = 1; + if (isr & LE_C0_RINT) am7990_rint(sc); if (isr & LE_C0_TINT) @@ -717,20 +451,6 @@ am7990_intr(arg) return (1); } -#undef ifp - -void -am7990_watchdog(ifp) - struct ifnet *ifp; -{ - struct am7990_softc *sc = ifp->if_softc; - - log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); - ++ifp->if_oerrors; - - am7990_reset(sc); -} - /* * Setup output on interface. * Get another datagram to send off of the interface queue, and map it to the @@ -738,12 +458,11 @@ am7990_watchdog(ifp) * Called only at splnet or interrupt level. */ void -am7990_start(ifp) - register struct ifnet *ifp; +am7990_start(struct ifnet *ifp) { - register struct am7990_softc *sc = ifp->if_softc; - register int bix; - register struct mbuf *m; + struct lance_softc *sc = ifp->if_softc; + int bix; + struct mbuf *m; struct letmd tmd; int rp; int len; @@ -779,7 +498,7 @@ am7990_start(ifp) /* * Copy the mbuf chain into the transmit buffer. */ - len = am7990_put(sc, LE_TBUFADDR(sc, bix), m); + len = lance_put(sc, LE_TBUFADDR(sc, bix), m); #ifdef LEDEBUG if (len > ETHERMTU + sizeof(struct ether_header)) @@ -798,7 +517,7 @@ am7990_start(ifp) (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); #ifdef LEDEBUG - if (sc->sc_debug) + if (sc->sc_debug > 1) am7990_xmit_print(sc, sc->sc_last_td); #endif @@ -808,9 +527,6 @@ am7990_start(ifp) bix = 0; if (++sc->sc_no_td == sc->sc_ntbuf) { -#ifdef LEDEBUG - printf("\nequal!\n"); -#endif ifp->if_flags |= IFF_OACTIVE; break; } @@ -820,90 +536,18 @@ am7990_start(ifp) sc->sc_last_td = bix; } -/* - * Process an ioctl request. - */ -int -am7990_ioctl(ifp, cmd, data) - register struct ifnet *ifp; - u_long cmd; - caddr_t data; -{ - register struct am7990_softc *sc = ifp->if_softc; - struct ifaddr *ifa = (struct ifaddr *)data; - struct ifreq *ifr = (struct ifreq *)data; - int s, error = 0; - - s = splnet(); - - switch (cmd) { - case SIOCSIFADDR: - ifp->if_flags |= IFF_UP; - if (!(ifp->if_flags & IFF_RUNNING)) - am7990_init(sc); -#ifdef INET - if (ifa->ifa_addr->sa_family == AF_INET) - arp_ifinit(&sc->sc_arpcom, ifa); -#endif - break; - - case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (ifp->if_flags & IFF_RUNNING) - error = ENETRESET; - else - am7990_init(sc); - } else { - if (ifp->if_flags & IFF_RUNNING) { - am7990_stop(sc); - ifp->if_flags &= ~IFF_RUNNING; - } - } - -#ifdef LEDEBUG - if (ifp->if_flags & IFF_DEBUG) - sc->sc_debug = 1; - else - sc->sc_debug = 0; -#endif - break; - - case SIOCGIFMEDIA: - case SIOCSIFMEDIA: - if (sc->sc_hasifmedia) - error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd); - else - error = EINVAL; - break; - - default: - error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data); - } - - if (error == ENETRESET) { - if (ifp->if_flags & IFF_RUNNING) - am7990_reset(sc); - error = 0; - } - - splx(s); - return (error); -} - #ifdef LEDEBUG void -am7990_recv_print(sc, no) - struct am7990_softc *sc; - int no; +am7990_recv_print(struct lance_softc *sc, int no) { struct lermd rmd; - u_int16_t len; + uint16_t len; struct ether_header eh; (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); len = rmd.rmd3; - printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no, - len); + printf("%s: receive buffer %d, len = %d\n", + sc->sc_dev.dv_xname, no, len); printf("%s: status %04x\n", sc->sc_dev.dv_xname, (*sc->sc_rdcsr)(sc, LE_CSR0)); printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", @@ -919,18 +563,16 @@ am7990_recv_print(sc, no) } void -am7990_xmit_print(sc, no) - struct am7990_softc *sc; - int no; +am7990_xmit_print(struct lance_softc *sc, int no) { struct letmd tmd; - u_int16_t len; + uint16_t len; struct ether_header eh; (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); len = -tmd.tmd2; - printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no, - len); + printf("%s: transmit buffer %d, len = %d\n", + sc->sc_dev.dv_xname, no, len); printf("%s: status %04x\n", sc->sc_dev.dv_xname, (*sc->sc_rdcsr)(sc, LE_CSR0)); printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", @@ -945,286 +587,3 @@ am7990_xmit_print(sc, no) } } #endif /* LEDEBUG */ - -/* - * Set up the logical address filter. - */ -void -am7990_setladrf(ac, af) - struct arpcom *ac; - u_int16_t *af; -{ - struct ifnet *ifp = &ac->ac_if; - struct ether_multi *enm; - register u_int32_t crc; - struct ether_multistep step; - - /* - * Set up multicast address filter by passing all multicast addresses - * through a crc generator, and then using the high order 6 bits as an - * index into the 64 bit logical address filter. The high order bit - * selects the word, while the rest of the bits select the bit within - * the word. - */ - - if (ifp->if_flags & IFF_PROMISC) - goto allmulti; - - af[0] = af[1] = af[2] = af[3] = 0x0000; - ETHER_FIRST_MULTI(step, ac, enm); - while (enm != NULL) { - if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) { - /* - * We must listen to a range of multicast addresses. - * For now, just accept all multicasts, rather than - * trying to set only those filter bits needed to match - * the range. (At this time, the only use of address - * ranges is for IP multicast routing, for which the - * range is big enough to require all bits set.) - */ - goto allmulti; - } - - crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26; - - /* Set the corresponding bit in the filter. */ - af[crc >> 4] |= 1 << (crc & 0xf); - - ETHER_NEXT_MULTI(step, enm); - } - ifp->if_flags &= ~IFF_ALLMULTI; - return; - -allmulti: - ifp->if_flags |= IFF_ALLMULTI; - af[0] = af[1] = af[2] = af[3] = 0xffff; -} - - -/* - * Routines for accessing the transmit and receive buffers. - * The various CPU and adapter configurations supported by this - * driver require three different access methods for buffers - * and descriptors: - * (1) contig (contiguous data; no padding), - * (2) gap2 (two bytes of data followed by two bytes of padding), - * (3) gap16 (16 bytes of data followed by 16 bytes of padding). - */ - -/* - * contig: contiguous data with no padding. - * - * Buffers may have any alignment. - */ - -void -am7990_copytobuf_contig(sc, from, boff, len) - struct am7990_softc *sc; - void *from; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - - /* - * Just call bcopy() to do the work. - */ - bcopy(from, buf + boff, len); -} - -void -am7990_copyfrombuf_contig(sc, to, boff, len) - struct am7990_softc *sc; - void *to; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - - /* - * Just call bcopy() to do the work. - */ - bcopy(buf + boff, to, len); -} - -void -am7990_zerobuf_contig(sc, boff, len) - struct am7990_softc *sc; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - - /* - * Just let bzero() do the work - */ - bzero(buf + boff, len); -} - -#if 0 -/* - * Examples only; duplicate these and tweak (if necessary) in - * machine-specific front-ends. - */ - -/* - * gap2: two bytes of data followed by two bytes of pad. - * - * Buffers must be 4-byte aligned. The code doesn't worry about - * doing an extra byte. - */ - -void -am7990_copytobuf_gap2(sc, fromv, boff, len) - struct am7990_softc *sc; - void *fromv; - int boff; - register int len; -{ - volatile caddr_t buf = sc->sc_mem; - register caddr_t from = fromv; - register volatile u_int16_t *bptr; - - if (boff & 0x1) { - /* handle unaligned first byte */ - bptr = ((volatile u_int16_t *)buf) + (boff - 1); - *bptr = (*from++ << 8) | (*bptr & 0xff); - bptr += 2; - len--; - } else - bptr = ((volatile u_int16_t *)buf) + boff; - while (len > 1) { - *bptr = (from[1] << 8) | (from[0] & 0xff); - bptr += 2; - from += 2; - len -= 2; - } - if (len == 1) - *bptr = (u_int16_t)*from; -} - -void -am7990_copyfrombuf_gap2(sc, tov, boff, len) - struct am7990_softc *sc; - void *tov; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - register caddr_t to = tov; - register volatile u_int16_t *bptr; - register u_int16_t tmp; - - if (boff & 0x1) { - /* handle unaligned first byte */ - bptr = ((volatile u_int16_t *)buf) + (boff - 1); - *to++ = (*bptr >> 8) & 0xff; - bptr += 2; - len--; - } else - bptr = ((volatile u_int16_t *)buf) + boff; - while (len > 1) { - tmp = *bptr; - *to++ = tmp & 0xff; - *to++ = (tmp >> 8) & 0xff; - bptr += 2; - len -= 2; - } - if (len == 1) - *to = *bptr & 0xff; -} - -void -am7990_zerobuf_gap2(sc, boff, len) - struct am7990_softc *sc; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - register volatile u_int16_t *bptr; - - if ((unsigned)boff & 0x1) { - bptr = ((volatile u_int16_t *)buf) + (boff - 1); - *bptr &= 0xff; - bptr += 2; - len--; - } else - bptr = ((volatile u_int16_t *)buf) + boff; - while (len > 0) { - *bptr = 0; - bptr += 2; - len -= 2; - } -} - -/* - * gap16: 16 bytes of data followed by 16 bytes of pad. - * - * Buffers must be 32-byte aligned. - */ - -void -am7990_copytobuf_gap16(sc, fromv, boff, len) - struct am7990_softc *sc; - void *fromv; - int boff; - register int len; -{ - volatile caddr_t buf = sc->sc_mem; - register caddr_t from = fromv; - register caddr_t bptr; - register int xfer; - - bptr = buf + ((boff << 1) & ~0x1f); - boff &= 0xf; - xfer = min(len, 16 - boff); - while (len > 0) { - bcopy(from, bptr + boff, xfer); - from += xfer; - bptr += 32; - boff = 0; - len -= xfer; - xfer = min(len, 16); - } -} - -void -am7990_copyfrombuf_gap16(sc, tov, boff, len) - struct am7990_softc *sc; - void *tov; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - register caddr_t to = tov; - register caddr_t bptr; - register int xfer; - - bptr = buf + ((boff << 1) & ~0x1f); - boff &= 0xf; - xfer = min(len, 16 - boff); - while (len > 0) { - bcopy(bptr + boff, to, xfer); - to += xfer; - bptr += 32; - boff = 0; - len -= xfer; - xfer = min(len, 16); - } -} - -void -am7990_zerobuf_gap16(sc, boff, len) - struct am7990_softc *sc; - int boff, len; -{ - volatile caddr_t buf = sc->sc_mem; - register caddr_t bptr; - register int xfer; - - bptr = buf + ((boff << 1) & ~0x1f); - boff &= 0xf; - xfer = min(len, 16 - boff); - while (len > 0) { - bzero(bptr + boff, xfer); - bptr += 32; - boff = 0; - len -= xfer; - xfer = min(len, 16); - } -} -#endif /* Example only */ diff --git a/sys/dev/ic/am79900.c b/sys/dev/ic/am79900.c new file mode 100644 index 00000000000..5541f187cda --- /dev/null +++ b/sys/dev/ic/am79900.c @@ -0,0 +1,611 @@ +/* $OpenBSD: am79900.c,v 1.1 2013/09/24 20:10:55 miod Exp $ */ +/* $NetBSD: am79900.c,v 1.23 2012/02/02 19:43:02 tls Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +/*- + * Copyright (c) 1998 + * Matthias Drochner. All rights reserved. + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +#include "bpfilter.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/mbuf.h> +#include <sys/syslog.h> +#include <sys/socket.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/ioctl.h> +#include <sys/errno.h> + +#include <net/if.h> +#include <net/if_media.h> + +#ifdef INET +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#endif + +#if NBPFILTER > 0 +#include <net/bpf.h> +#endif + +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> +#include <dev/ic/am79900reg.h> +#include <dev/ic/am79900var.h> + +void am79900_meminit(struct lance_softc *); +void am79900_start(struct ifnet *); + +void am79900_rint(struct lance_softc *); +void am79900_tint(struct lance_softc *); + +#ifdef LEDEBUG +void am79900_recv_print(struct lance_softc *, int); +void am79900_xmit_print(struct lance_softc *, int); +#endif + +void +am79900_config(struct am79900_softc *sc) +{ + int mem, i; + + sc->lsc.sc_meminit = am79900_meminit; + sc->lsc.sc_start = am79900_start; + + lance_config(&sc->lsc); + + mem = 0; + sc->lsc.sc_initaddr = mem; + mem += sizeof(struct leinit); + sc->lsc.sc_rmdaddr = mem; + mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; + sc->lsc.sc_tmdaddr = mem; + mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; + for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN) + sc->lsc.sc_rbufaddr[i] = mem; + for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN) + sc->lsc.sc_tbufaddr[i] = mem; + + if (mem > sc->lsc.sc_memsize) + panic("%s: memsize", sc->lsc.sc_dev.dv_xname); +} + +/* + * Set up the initialization block and the descriptor rings. + */ +void +am79900_meminit(struct lance_softc *sc) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + u_long a; + int bix; + struct leinit init; + struct lermd rmd; + struct letmd tmd; + uint8_t *myaddr; + + if (ifp->if_flags & IFF_PROMISC) + init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; + else + init.init_mode = LE_MODE_NORMAL; + if (sc->sc_initmodemedia == 1) + init.init_mode |= LE_MODE_PSEL0; + + init.init_mode |= ((ffs(sc->sc_ntbuf) - 1) << 28) | + ((ffs(sc->sc_nrbuf) - 1) << 20); + + /* + * Update our private copy of the Ethernet address. + * We NEED the copy so we can ensure its alignment! + */ + memcpy(sc->sc_enaddr, sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN); + myaddr = sc->sc_enaddr; + + init.init_padr[0] = myaddr[0] | (myaddr[1] << 8) | + (myaddr[2] << 16) | (myaddr[3] << 24); + init.init_padr[1] = myaddr[4] | (myaddr[5] << 8); + lance_setladrf(&sc->sc_arpcom, init.init_ladrf); + + sc->sc_last_rd = 0; + sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; + + a = sc->sc_addr + LE_RMDADDR(sc, 0); + init.init_rdra = a; + + a = sc->sc_addr + LE_TMDADDR(sc, 0); + init.init_tdra = a; + + (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); + + /* + * Set up receive ring descriptors. + */ + for (bix = 0; bix < sc->sc_nrbuf; bix++) { + a = sc->sc_addr + LE_RBUFADDR(sc, bix); + rmd.rmd0 = a; + rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff); + rmd.rmd2 = 0; + rmd.rmd3 = 0; + (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), + sizeof(rmd)); + } + + /* + * Set up transmit ring descriptors. + */ + for (bix = 0; bix < sc->sc_ntbuf; bix++) { + a = sc->sc_addr + LE_TBUFADDR(sc, bix); + tmd.tmd0 = a; + tmd.tmd1 = LE_T1_ONES; + tmd.tmd2 = 0; + tmd.tmd3 = 0; + (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), + sizeof(tmd)); + } +} + +void +am79900_rint(struct lance_softc *sc) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + int bix; + int rp; + struct lermd rmd; + + bix = sc->sc_last_rd; + + /* Process all buffers with valid data. */ + for (;;) { + rp = LE_RMDADDR(sc, bix); + (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); + + if (rmd.rmd1 & LE_R1_OWN) + break; + + if (rmd.rmd1 & LE_R1_ERR) { + if (rmd.rmd1 & LE_R1_ENP) { +#ifdef LEDEBUG + if ((rmd.rmd1 & LE_R1_OFLO) == 0) { + if (rmd.rmd1 & LE_R1_FRAM) + printf("%s: framing error\n", + sc->sc_dev.dv_xname); + if (rmd.rmd1 & LE_R1_CRC) + printf("%s: crc mismatch\n", + sc->sc_dev.dv_xname); + } +#endif + } else { + if (rmd.rmd1 & LE_R1_OFLO) + printf("%s: overflow\n", + sc->sc_dev.dv_xname); + } + if (rmd.rmd1 & LE_R1_BUFF) + printf("%s: receive buffer error\n", + sc->sc_dev.dv_xname); + ifp->if_ierrors++; + } else if ((rmd.rmd1 & (LE_R1_STP | LE_R1_ENP)) != + (LE_R1_STP | LE_R1_ENP)) { + printf("%s: dropping chained buffer\n", + sc->sc_dev.dv_xname); + ifp->if_ierrors++; + } else { +#ifdef LEDEBUG + if (sc->sc_debug > 1) + am79900_recv_print(sc, sc->sc_last_rd); +#endif + lance_read(sc, LE_RBUFADDR(sc, bix), + (rmd.rmd2 & 0xfff) - 4); + } + + rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff); + rmd.rmd2 = 0; + rmd.rmd3 = 0; + (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); + +#ifdef LEDEBUG + if (sc->sc_debug) + printf("sc->sc_last_rd = %x, rmd: " + "adr %08x, flags/blen %08x\n", + sc->sc_last_rd, + rmd.rmd0, rmd.rmd1); +#endif + + if (++bix == sc->sc_nrbuf) + bix = 0; + } + + sc->sc_last_rd = bix; +} + +void +am79900_tint(struct lance_softc *sc) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + int bix; + struct letmd tmd; + + bix = sc->sc_first_td; + + for (;;) { + if (sc->sc_no_td <= 0) + break; + + (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), + sizeof(tmd)); + +#ifdef LEDEBUG + if (sc->sc_debug) + printf("trans tmd: " + "adr %08x, flags/blen %08x\n", + tmd.tmd0, tmd.tmd1); +#endif + + if (tmd.tmd1 & LE_T1_OWN) + break; + + ifp->if_flags &= ~IFF_OACTIVE; + + if (tmd.tmd1 & LE_T1_ERR) { + if (tmd.tmd2 & LE_T2_BUFF) + printf("%s: transmit buffer error\n", + sc->sc_dev.dv_xname); + else if (tmd.tmd2 & LE_T2_UFLO) + printf("%s: underflow\n", sc->sc_dev.dv_xname); + if (tmd.tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { + lance_reset(sc); + return; + } + if (tmd.tmd2 & LE_T2_LCAR) { + sc->sc_havecarrier = 0; + if (sc->sc_nocarrier) + (*sc->sc_nocarrier)(sc); + else + printf("%s: lost carrier\n", + sc->sc_dev.dv_xname); + } + if (tmd.tmd2 & LE_T2_LCOL) + ifp->if_collisions++; + if (tmd.tmd2 & LE_T2_RTRY) { +#ifdef LEDEBUG + printf("%s: excessive collisions\n", + sc->sc_dev.dv_xname); +#endif + ifp->if_collisions += 16; + } + ifp->if_oerrors++; + } else { + if (tmd.tmd1 & LE_T1_ONE) + ifp->if_collisions++; + else if (tmd.tmd1 & LE_T1_MORE) + /* Real number is unknown. */ + ifp->if_collisions += 2; + ifp->if_opackets++; + } + + if (++bix == sc->sc_ntbuf) + bix = 0; + + --sc->sc_no_td; + } + + sc->sc_first_td = bix; + + am79900_start(ifp); + + if (sc->sc_no_td == 0) + ifp->if_timer = 0; +} + +/* + * Controller interrupt. + */ +int +am79900_intr(void *arg) +{ + struct lance_softc *sc = arg; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + uint16_t isr; + + isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0; + sc->sc_saved_csr0 = 0; +#if defined(LEDEBUG) && LEDEBUG > 1 + if (sc->sc_debug) + printf("%s: am79900_intr entering with isr=%04x\n", + sc->sc_dev.dv_xname, isr); +#endif + if ((isr & LE_C0_INTR) == 0) + return (0); + + (*sc->sc_wrcsr)(sc, LE_CSR0, + isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR | + LE_C0_RINT | LE_C0_TINT | LE_C0_IDON)); + if (isr & LE_C0_ERR) { + if (isr & LE_C0_BABL) { +#ifdef LEDEBUG + printf("%s: babble\n", sc->sc_dev.dv_xname); +#endif + ifp->if_oerrors++; + } +#if 0 + if (isr & LE_C0_CERR) { + printf("%s: collision error\n", + sc->sc_dev.dv_xname); + ifp->if_collisions++; + } +#endif + if (isr & LE_C0_MISS) { +#ifdef LEDEBUG + printf("%s: missed packet\n", sc->sc_dev.dv_xname); +#endif + ifp->if_ierrors++; + } + if (isr & LE_C0_MERR) { + printf("%s: memory error\n", sc->sc_dev.dv_xname); + lance_reset(sc); + return (1); + } + } + + if ((isr & LE_C0_RXON) == 0) { + printf("%s: receiver disabled\n", sc->sc_dev.dv_xname); + ifp->if_ierrors++; + lance_reset(sc); + return (1); + } + if ((isr & LE_C0_TXON) == 0) { + printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname); + ifp->if_oerrors++; + lance_reset(sc); + return (1); + } + + /* + * Pretend we have carrier; if we don't this will be cleared + * shortly. + */ + sc->sc_havecarrier = 1; + + if (isr & LE_C0_RINT) + am79900_rint(sc); + if (isr & LE_C0_TINT) + am79900_tint(sc); + + return (1); +} + +/* + * Setup output on interface. + * Get another datagram to send off of the interface queue, and map it to the + * interface before starting the output. + * Called only at splnet or interrupt level. + */ +void +am79900_start(struct ifnet *ifp) +{ + struct lance_softc *sc = ifp->if_softc; + int bix; + struct mbuf *m; + struct letmd tmd; + int rp; + int len; + + if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) + return; + + bix = sc->sc_last_td; + + for (;;) { + rp = LE_TMDADDR(sc, bix); + (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); + + if (tmd.tmd1 & LE_T1_OWN) { + ifp->if_flags |= IFF_OACTIVE; + printf("missing buffer, no_td = %d, last_td = %d\n", + sc->sc_no_td, sc->sc_last_td); + } + + IFQ_DEQUEUE(&ifp->if_snd, m); + if (m == 0) + break; + +#if NBPFILTER > 0 + /* + * If BPF is listening on this interface, let it see the packet + * before we commit it to the wire. + */ + if (ifp->if_bpf) + bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT); +#endif + + /* + * Copy the mbuf chain into the transmit buffer. + */ + len = lance_put(sc, LE_TBUFADDR(sc, bix), m); + +#ifdef LEDEBUG + if (len > ETHERMTU + sizeof(struct ether_header)) + printf("packet length %d\n", len); +#endif + + ifp->if_timer = 5; + + /* + * Init transmit registers, and set transmit start flag. + */ + tmd.tmd1 = LE_T1_OWN | LE_T1_STP | LE_T1_ENP | LE_T1_ONES | + (-len & 0xfff); + tmd.tmd2 = 0; + tmd.tmd3 = 0; + + (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); + +#ifdef LEDEBUG + if (sc->sc_debug > 1) + am79900_xmit_print(sc, sc->sc_last_td); +#endif + + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); + + if (++bix == sc->sc_ntbuf) + bix = 0; + + if (++sc->sc_no_td == sc->sc_ntbuf) { + ifp->if_flags |= IFF_OACTIVE; + break; + } + + } + + sc->sc_last_td = bix; +} + +#ifdef LEDEBUG +void +am79900_recv_print(struct lance_softc *sc, int no) +{ + struct lermd rmd; + uint16_t len; + struct ether_header eh; + + (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); + len = (rmd.rmd2 & 0xfff) - 4; + printf("%s: receive buffer %d, len = %d\n", + sc->sc_dev.dv_xname, no, len); + printf("%s: status %04x\n", sc->sc_dev.dv_xname, + (*sc->sc_rdcsr)(sc, LE_CSR0)); + printf("%s: adr %08x, flags/blen %08x\n", + sc->sc_dev.dv_xname, rmd.rmd0, rmd.rmd1); + if (len >= sizeof(eh)) { + (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); + printf("%s: dst %s", sc->sc_dev.dv_xname, + ether_sprintf(eh.ether_dhost)); + printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), + ntohs(eh.ether_type)); + } +} + +void +am79900_xmit_print(struct lance_softc *sc, int no) +{ + struct letmd tmd; + uint16_t len; + struct ether_header eh; + + (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); + len = -(tmd.tmd1 & 0xfff); + printf("%s: transmit buffer %d, len = %d\n", + sc->sc_dev.dv_xname, no, len); + printf("%s: status %04x\n", sc->sc_dev.dv_xname, + (*sc->sc_rdcsr)(sc, LE_CSR0)); + printf("%s: adr %08x, flags/blen %08x\n", + sc->sc_dev.dv_xname, tmd.tmd0, tmd.tmd1); + if (len >= sizeof(eh)) { + (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); + printf("%s: dst %s", sc->sc_dev.dv_xname, + ether_sprintf(eh.ether_dhost)); + printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), + ntohs(eh.ether_type)); + } +} +#endif /* LEDEBUG */ diff --git a/sys/dev/ic/am79900var.h b/sys/dev/ic/am79900var.h new file mode 100644 index 00000000000..9f789433a56 --- /dev/null +++ b/sys/dev/ic/am79900var.h @@ -0,0 +1,53 @@ +/* $OpenBSD: am79900var.h,v 1.1 2013/09/24 20:10:56 miod Exp $ */ +/* $NetBSD: am79900var.h,v 1.5 2008/04/28 20:23:49 martin Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEV_IC_AM79900VAR_H_ +#define _DEV_IC_AM79900VAR_H_ + +/* + * Ethernet software status per device. + * + * NOTE: this structure MUST be the first element in machine-dependent + * le_softc structures! This is designed SPECIFICALLY to make it possible + * to simply cast a "void *" to "struct le_softc *" or to + * "struct am79900_softc *". Among other things, this saves a lot of hair + * in the interrupt handlers. + */ +struct am79900_softc { + struct lance_softc lsc; +}; + +void am79900_config(struct am79900_softc *); +int am79900_intr(void *); + +#endif /* _DEV_IC_AM79900VAR_H_ */ diff --git a/sys/dev/ic/am7990reg.h b/sys/dev/ic/am7990reg.h index ff97c0d604d..14e43479b21 100644 --- a/sys/dev/ic/am7990reg.h +++ b/sys/dev/ic/am7990reg.h @@ -1,8 +1,36 @@ -/* $OpenBSD: am7990reg.h,v 1.8 2007/05/23 09:00:17 jmc Exp $ */ -/* $NetBSD: am7990reg.h,v 1.1 1995/04/11 04:17:50 mycroft Exp $ */ +/* $OpenBSD: am7990reg.h,v 1.9 2013/09/24 20:10:57 miod Exp $ */ +/* $NetBSD: am7990reg.h,v 1.13 2008/04/28 20:23:49 martin Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /*- - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -37,14 +65,6 @@ */ /* - * Documentation for this chip: - * Am79C90 CMOS Local Area Network Controller for Ethernet - * AMD Publication #: 17881, Rev C, Jan 1997 - */ - -#define LEMINSIZE 60 /* should be 64 if mode DTCR is set */ - -/* * Receive message descriptor */ struct lermd { @@ -58,7 +78,7 @@ struct lermd { #endif int16_t rmd2; u_int16_t rmd3; -}; +} __packed; /* * Transmit message descriptor @@ -74,7 +94,7 @@ struct letmd { #endif int16_t tmd2; u_int16_t tmd3; -}; +} __packed; /* * Initialization block @@ -88,60 +108,9 @@ struct leinit { u_int16_t init_tdra; /* +0x0014 */ u_int16_t init_tlen; /* +0x0016 */ int16_t pad0[4]; /* Pad to 16 shorts */ -}; - -#define LE_INITADDR(sc) (sc->sc_initaddr) -#define LE_RMDADDR(sc, bix) (sc->sc_rmdaddr + sizeof(struct lermd) * (bix)) -#define LE_TMDADDR(sc, bix) (sc->sc_tmdaddr + sizeof(struct letmd) * (bix)) -#define LE_RBUFADDR(sc, bix) (sc->sc_rbufaddr + ETHER_MAX_DIX_LEN * (bix)) -#define LE_TBUFADDR(sc, bix) (sc->sc_tbufaddr + ETHER_MAX_DIX_LEN * (bix)) - -/* register addresses */ -#define LE_CSR0 0x0000 /* Control and status register */ -#define LE_CSR1 0x0001 /* low address of init block */ -#define LE_CSR2 0x0002 /* high address of init block */ -#define LE_CSR3 0x0003 /* Bus master and control */ - -/* Control and status register 0 (csr0) */ -#define LE_C0_ERR 0x8000 /* error summary */ -#define LE_C0_BABL 0x4000 /* transmitter timeout error */ -#define LE_C0_CERR 0x2000 /* collision */ -#define LE_C0_MISS 0x1000 /* missed a packet */ -#define LE_C0_MERR 0x0800 /* memory error */ -#define LE_C0_RINT 0x0400 /* receiver interrupt */ -#define LE_C0_TINT 0x0200 /* transmitter interrupt */ -#define LE_C0_IDON 0x0100 /* initialization done */ -#define LE_C0_INTR 0x0080 /* interrupt condition */ -#define LE_C0_INEA 0x0040 /* interrupt enable */ -#define LE_C0_RXON 0x0020 /* receiver on */ -#define LE_C0_TXON 0x0010 /* transmitter on */ -#define LE_C0_TDMD 0x0008 /* transmit demand */ -#define LE_C0_STOP 0x0004 /* disable all external activity */ -#define LE_C0_STRT 0x0002 /* enable external activity */ -#define LE_C0_INIT 0x0001 /* begin initialization */ - -#define LE_C0_BITS \ - "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\ -\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT" - -/* Control and status register 3 (csr3) */ -#define LE_C3_BSWP 0x0004 /* byte swap */ -#define LE_C3_ACON 0x0002 /* ALE control, eh? */ -#define LE_C3_BCON 0x0001 /* byte control */ - -/* Initialization block (mode) */ -#define LE_MODE_PROM 0x8000 /* promiscuous mode */ -/* 0x7f80 reserved, must be zero */ -#define LE_MODE_INTL 0x0040 /* internal loopback */ -#define LE_MODE_DRTY 0x0020 /* disable retry */ -#define LE_MODE_COLL 0x0010 /* force a collision */ -#define LE_MODE_DTCR 0x0008 /* disable transmit CRC */ -#define LE_MODE_LOOP 0x0004 /* loopback mode */ -#define LE_MODE_DTX 0x0002 /* disable transmitter */ -#define LE_MODE_DRX 0x0001 /* disable receiver */ -#define LE_MODE_NORMAL 0 /* none of the above */ - -/* Receive message descriptor 1 (rmd1_bits) */ +} __packed; + +/* Receive message descriptor 1 (rmd1_bits) */ #define LE_R1_OWN 0x80 /* LANCE owns the packet */ #define LE_R1_ERR 0x40 /* error summary */ #define LE_R1_FRAM 0x20 /* framing error */ @@ -154,7 +123,7 @@ struct leinit { #define LE_R1_BITS \ "\20\10OWN\7ERR\6FRAM\5OFLO\4CRC\3BUFF\2STP\1ENP" -/* Transmit message descriptor 1 (tmd1_bits) */ +/* Transmit message descriptor 1 (tmd1_bits) */ #define LE_T1_OWN 0x80 /* LANCE owns the packet */ #define LE_T1_ERR 0x40 /* error summary */ #define LE_T1_MORE 0x10 /* multiple collisions */ @@ -166,7 +135,7 @@ struct leinit { #define LE_T1_BITS \ "\20\10OWN\7ERR\6RES\5MORE\4ONE\3DEF\2STP\1ENP" -/* Transmit message descriptor 3 (tmd3) */ +/* Transmit message descriptor 3 (tmd3) */ #define LE_T3_BUFF 0x8000 /* buffer error */ #define LE_T3_UFLO 0x4000 /* underflow error */ #define LE_T3_LCOL 0x1000 /* late collision */ @@ -178,3 +147,30 @@ struct leinit { #define LE_T3_BITS \ "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY" + +/* + * PCnet-ISA defines which are not available on LANCE 7990 + */ + +/* (ISA) Bus Configuration Registers */ +#define LE_BCR_MSRDA 0x0000 +#define LE_BCR_MSWRA 0x0001 +#define LE_BCR_MC 0x0002 +#define LE_BCR_LED1 0x0005 +#define LE_BCR_LED2 0x0006 +#define LE_BCR_LED3 0x0007 + +/* Bus configurations bits (MC) */ +#define LE_MC_EADISEL 0x0008 /* EADI selection */ +#define LE_MC_AWAKE 0x0004 /* auto-wake */ +#define LE_MC_ASEL 0x0002 /* auto selection */ +#define LE_MC_XMAUSEL 0x0001 /* external MAU selection */ + +/* LED bis (LED[123]) */ +#define LE_LED_LEDOUT 0x8000 +#define LE_LED_PSE 0x0080 +#define LE_LED_XMTE 0x0010 +#define LE_LED_PVPE 0x0008 +#define LE_LED_PCVE 0x0004 +#define LE_LED_JABE 0x0002 +#define LE_LED_COLE 0x0001 diff --git a/sys/dev/ic/am7990var.h b/sys/dev/ic/am7990var.h index ca58e7b6116..4d853a9cab9 100644 --- a/sys/dev/ic/am7990var.h +++ b/sys/dev/ic/am7990var.h @@ -1,8 +1,13 @@ -/* $OpenBSD: am7990var.h,v 1.10 2009/08/10 20:29:54 deraadt Exp $ */ -/* $NetBSD: am7990var.h,v 1.8 1996/07/05 23:57:01 abrown Exp $ */ +/* $OpenBSD: am7990var.h,v 1.11 2013/09/24 20:10:57 miod Exp $ */ +/* $NetBSD: am7990var.h,v 1.24 2008/04/28 20:23:49 martin Exp $ */ -/* - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,39 +17,26 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Charles M. Hannum. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#ifdef DDB -#define integrate -#define hide -#else -#define integrate static __inline -#define hide static -#endif +#ifndef _DEV_IC_AM7990VAR_H_ +#define _DEV_IC_AM7990VAR_H_ /* * Ethernet software status per device. * - * Each interface is referenced by a network interface structure, - * arpcom.ac_if, which the routing code uses to locate the interface. - * This structure contains the output queue for the interface, its address, ... - * * NOTE: this structure MUST be the first element in machine-dependent * le_softc structures! This is designed SPECIFICALLY to make it possible * to simply cast a "void *" to "struct le_softc *" or to @@ -52,92 +44,10 @@ * in the interrupt handlers. */ struct am7990_softc { - struct device sc_dev; /* base device glue */ - struct arpcom sc_arpcom; /* Ethernet common part */ - - /* - * Memory functions: - * - * copy to/from descriptor - * copy to/from buffer - * zero bytes in buffer - */ - void (*sc_copytodesc)(struct am7990_softc *, void *, int, int); - void (*sc_copyfromdesc)(struct am7990_softc *, void *, int, int); - void (*sc_copytobuf)(struct am7990_softc *, void *, int, int); - void (*sc_copyfrombuf)(struct am7990_softc *, void *, int, int); - void (*sc_zerobuf)(struct am7990_softc *, int, int); - - /* - * Machine-dependent functions: - * - * read/write CSR - * hardware reset hook - may be NULL - * hardware init hook - may be NULL - * no carrier hook - may be NULL - */ - u_int16_t (*sc_rdcsr)(struct am7990_softc *, u_int16_t); - void (*sc_wrcsr)(struct am7990_softc *, u_int16_t, u_int16_t); - void (*sc_hwreset)(struct am7990_softc *); - void (*sc_hwinit)(struct am7990_softc *); - void (*sc_nocarrier)(struct am7990_softc *); - - int sc_hasifmedia; - struct ifmedia sc_ifmedia; - - u_int16_t sc_conf3; /* CSR3 value */ - - void *sc_mem; /* base address of RAM -- CPU's view */ - u_long sc_addr; /* base address of RAM -- LANCE's view */ - - u_long sc_memsize; /* size of RAM */ - - int sc_nrbuf; /* number of receive buffers */ - int sc_ntbuf; /* number of transmit buffers */ - int sc_last_rd; - int sc_first_td, sc_last_td, sc_no_td; - - int sc_initaddr; - int sc_rmdaddr; - int sc_tmdaddr; - int sc_rbufaddr; - int sc_tbufaddr; - -#ifdef LEDEBUG - int sc_debug; -#endif + struct lance_softc lsc; }; -/* Export this to machine-dependent drivers. */ -extern struct cfdriver le_cd; - -void am7990_config(struct am7990_softc *); -void am7990_init(struct am7990_softc *); -int am7990_ioctl(struct ifnet *, u_long, caddr_t); -void am7990_meminit(struct am7990_softc *); -void am7990_reset(struct am7990_softc *); -void am7990_setladrf(struct arpcom *, u_int16_t *); -void am7990_start(struct ifnet *); -void am7990_stop(struct am7990_softc *); -void am7990_watchdog(struct ifnet *); -int am7990_intr(void *); - -/* - * The following functions are only useful on certain cpu/bus - * combinations. They should be written in assembly language for - * maximum efficiency, but machine-independent versions are provided - * for drivers that have not yet been optimized. - */ -void am7990_copytobuf_contig(struct am7990_softc *, void *, int, int); -void am7990_copyfrombuf_contig(struct am7990_softc *, void *, int, int); -void am7990_zerobuf_contig(struct am7990_softc *, int, int); - -#if 0 /* Example only - see am7990.c */ -void am7990_copytobuf_gap2(struct am7990_softc *, void *, int, int); -void am7990_copyfrombuf_gap2(struct am7990_softc *, void *, int, int); -void am7990_zerobuf_gap2(struct am7990_softc *, int, int); +void am7990_config(struct am7990_softc *); +int am7990_intr(void *); -void am7990_copytobuf_gap16(struct am7990_softc *, void *, int, int); -void am7990_copyfrombuf_gap16(struct am7990_softc *, void *, int, int); -void am7990_zerobuf_gap16(struct am7990_softc *, int, int); -#endif /* Example only */ +#endif /* _DEV_IC_AM7990VAR_H_ */ diff --git a/sys/dev/ic/lance.c b/sys/dev/ic/lance.c new file mode 100644 index 00000000000..731cf8a5980 --- /dev/null +++ b/sys/dev/ic/lance.c @@ -0,0 +1,842 @@ +/* $OpenBSD: lance.c,v 1.1 2013/09/24 20:10:58 miod Exp $ */ +/* $NetBSD: lance.c,v 1.46 2012/02/02 19:43:03 tls Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +#include "bpfilter.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/mbuf.h> +#include <sys/syslog.h> +#include <sys/socket.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/ioctl.h> +#include <sys/errno.h> + +#include <net/if.h> +#include <net/if_media.h> + +#ifdef INET +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#endif + +#if NBPFILTER > 0 +#include <net/bpf.h> +#endif + +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> + +#ifdef DDB +#define integrate +#define hide +#else +#define integrate static inline +#define hide static +#endif + +integrate struct mbuf *lance_get(struct lance_softc *, int, int); + +int lance_mediachange(struct ifnet *); +void lance_mediastatus(struct ifnet *, struct ifmediareq *); + +static inline u_int16_t ether_cmp(void *, void *); + +void lance_stop(struct ifnet *, int); +int lance_ioctl(struct ifnet *, u_long, caddr_t); +void lance_watchdog(struct ifnet *); + +struct cfdriver le_cd = { + NULL, "le", DV_IFNET +}; + +/* + * Compare two Ether/802 addresses for equality, inlined and + * unrolled for speed. Use this like memcmp(). + * + * XXX: Add <machine/inlines.h> for stuff like this? + * XXX: or maybe add it to libkern.h instead? + * + * "I'd love to have an inline assembler version of this." + * XXX: Who wanted that? mycroft? I wrote one, but this + * version in C is as good as hand-coded assembly. -gwr + * + * Please do NOT tweak this without looking at the actual + * assembly code generated before and after your tweaks! + */ +static inline uint16_t +ether_cmp(void *one, void *two) +{ + uint16_t *a = (uint16_t *)one; + uint16_t *b = (uint16_t *)two; + uint16_t diff; + +#ifdef __m68k__ + /* + * The post-increment-pointer form produces the best + * machine code for m68k. This was carefully tuned + * so it compiles to just 8 short (2-byte) op-codes! + */ + diff = *a++ - *b++; + diff |= *a++ - *b++; + diff |= *a++ - *b++; +#else + /* + * Most modern CPUs do better with a single expresion. + * Note that short-cut evaluation is NOT helpful here, + * because it just makes the code longer, not faster! + */ + diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]); +#endif + + return (diff); +} + +#define ETHER_CMP ether_cmp + +#ifdef LANCE_REVC_BUG +/* Make sure this is short-aligned, for ether_cmp(). */ +static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 }; +#endif + +void +lance_config(struct lance_softc *sc) +{ + int i, nbuf; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + + /* Initialize ifnet structure. */ + strlcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ); + ifp->if_softc = sc; + ifp->if_start = sc->sc_start; + ifp->if_ioctl = lance_ioctl; + ifp->if_watchdog = lance_watchdog; + ifp->if_flags = + IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; +#ifdef LANCE_REVC_BUG + ifp->if_flags &= ~IFF_MULTICAST; +#endif + ifp->if_baudrate = IF_Mbps(10); + IFQ_SET_READY(&ifp->if_snd); + + /* Initialize ifmedia structures. */ + ifmedia_init(&sc->sc_ifmedia, 0, lance_mediachange, lance_mediastatus); + if (sc->sc_supmedia != NULL) { + for (i = 0; i < sc->sc_nsupmedia; i++) + ifmedia_add(&sc->sc_ifmedia, sc->sc_supmedia[i], + 0, NULL); + ifmedia_set(&sc->sc_ifmedia, sc->sc_defaultmedia); + } else { + ifmedia_add(&sc->sc_ifmedia, IFM_ETHER|IFM_MANUAL, 0, NULL); + ifmedia_set(&sc->sc_ifmedia, IFM_ETHER|IFM_MANUAL); + } + + if (sc->sc_memsize > 262144) + sc->sc_memsize = 262144; + + switch (sc->sc_memsize) { + case 8192: + sc->sc_nrbuf = 4; + sc->sc_ntbuf = 1; + break; + case 16384: + sc->sc_nrbuf = 8; + sc->sc_ntbuf = 2; + break; + case 32768: + sc->sc_nrbuf = 16; + sc->sc_ntbuf = 4; + break; + case 65536: + sc->sc_nrbuf = 32; + sc->sc_ntbuf = 8; + break; + case 131072: + sc->sc_nrbuf = 64; + sc->sc_ntbuf = 16; + break; + case 262144: + sc->sc_nrbuf = 128; + sc->sc_ntbuf = 32; + break; + default: + /* weird memory size; cope with it */ + nbuf = sc->sc_memsize / LEBLEN; + sc->sc_ntbuf = nbuf / 5; + sc->sc_nrbuf = nbuf - sc->sc_ntbuf; + } + + printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); + printf("%s: %d receive buffers, %d transmit buffers\n", + sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf); + + /* Make sure the chip is stopped. */ + lance_stop(ifp, 0); + + /* claim 802.1q capability */ + ifp->if_capabilities = IFCAP_VLAN_MTU; + + /* Attach the interface. */ + if_attach(ifp); + ether_ifattach(ifp); + + sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF, + M_WAITOK); + sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF, + M_WAITOK); +} + +void +lance_reset(struct lance_softc *sc) +{ + int s; + + s = splnet(); + lance_init(sc); + splx(s); +} + +void +lance_stop(struct ifnet *ifp, int disable) +{ + struct lance_softc *sc = ifp->if_softc; + + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); +} + +/* + * Initialization of interface; set up initialization block + * and transmit/receive descriptor rings. + */ +int +lance_init(struct lance_softc *sc) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + int timo; + u_long a; + + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP); + DELAY(100); + + /* Newer LANCE chips have a reset register */ + if (sc->sc_hwreset) + (*sc->sc_hwreset)(sc); + + /* Set the correct byte swapping mode, etc. */ + (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3); + + /* Set up LANCE init block. */ + (*sc->sc_meminit)(sc); + + /* Give LANCE the physical address of its init block. */ + a = sc->sc_addr + LE_INITADDR(sc); + (*sc->sc_wrcsr)(sc, LE_CSR1, a); + (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16); + + /* Try to initialize the LANCE. */ + DELAY(100); + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT); + + /* Wait for initialization to finish. */ + for (timo = 100000; timo; timo--) + if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) + break; + + if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) { + /* Start the LANCE. */ + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT); + ifp->if_flags |= IFF_RUNNING; + ifp->if_flags &= ~IFF_OACTIVE; + ifp->if_timer = 0; + (*sc->sc_start)(ifp); + } else + printf("%s: controller failed to initialize\n", + sc->sc_dev.dv_xname); + if (sc->sc_hwinit) + (*sc->sc_hwinit)(sc); + + return (0); +} + +/* + * Routine to copy from mbuf chain to transmit buffer in + * network buffer memory. + */ +int +lance_put(struct lance_softc *sc, int boff, struct mbuf *m) +{ + struct mbuf *n; + int len, tlen = 0; + + for (; m; m = n) { + len = m->m_len; + if (len == 0) { + MFREE(m, n); + continue; + } + (*sc->sc_copytobuf)(sc, mtod(m, void *), boff, len); + boff += len; + tlen += len; + MFREE(m, n); + } + if (tlen < LEMINSIZE) { + (*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen); + tlen = LEMINSIZE; + } + return (tlen); +} + +/* + * Pull data off an interface. + * Len is length of data, with local net header stripped. + * We copy the data into mbufs. When full cluster sized units are present + * we copy into clusters. + */ +integrate struct mbuf * +lance_get(struct lance_softc *sc, int boff, int totlen) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct mbuf *m, *top, **mp; + int len, pad; + + MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == NULL) + return (NULL); + m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.len = totlen; + pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header); + m->m_data += pad; + len = MHLEN - pad; + top = NULL; + mp = ⊤ + + while (totlen > 0) { + if (top) { + MGET(m, M_DONTWAIT, MT_DATA); + if (m == NULL) { + m_freem(top); + return NULL; + } + len = MLEN; + } + if (totlen >= MINCLSIZE) { + MCLGET(m, M_DONTWAIT); + if (m->m_flags & M_EXT) { + len = MCLBYTES; + if (!top) { + m->m_data += pad; + len -= pad; + } + } + } + m->m_len = len = min(totlen, len); + (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len); + boff += len; + totlen -= len; + *mp = m; + mp = &m->m_next; + } + + return (top); +} + +/* + * Pass a packet to the higher levels. + */ +void +lance_read(struct lance_softc *sc, int boff, int len) +{ + struct mbuf *m; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ether_header *eh; + + if (len <= sizeof(struct ether_header) || + len > ((ifp->if_capabilities & IFCAP_VLAN_MTU) ? + ETHER_VLAN_ENCAP_LEN + ETHERMTU + sizeof(struct ether_header) : + ETHERMTU + sizeof(struct ether_header))) { +#ifdef LEDEBUG + printf("%s: invalid packet size %d; dropping\n", + sc->sc_dev.dv_xnam, len); +#endif + ifp->if_ierrors++; + return; + } + + /* Pull packet off interface. */ + m = lance_get(sc, boff, len); + if (m == NULL) { + ifp->if_ierrors++; + return; + } + + ifp->if_ipackets++; + + eh = mtod(m, struct ether_header *); + +#ifdef LANCE_REVC_BUG + /* + * The old LANCE (Rev. C) chips have a bug which causes + * garbage to be inserted in front of the received packet. + * The work-around is to ignore packets with an invalid + * destination address (garbage will usually not match). + * Of course, this precludes multicast support... + */ + if (ETHER_CMP(eh->ether_dhost, sc->sc_arpcom.ac_enaddr) && + ETHER_CMP(eh->ether_dhost, bcast_enaddr)) { + m_freem(m); + return; + } +#endif + + /* + * Some lance device does not present IFF_SIMPLEX behavior on multicast + * packets. Make sure to drop it if it is from ourselves. + */ + if (!ETHER_CMP(eh->ether_shost, sc->sc_arpcom.ac_enaddr)) { + m_freem(m); + return; + } + +#if NBPFILTER > 0 + /* + * Check if there's a BPF listener on this interface. + * If so, hand off the raw packet to BPF. + */ + if (ifp->if_bpf) + bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_IN); +#endif + + /* Pass the packet up. */ + ether_input_mbuf(ifp, m); +} + +void +lance_watchdog(struct ifnet *ifp) +{ + struct lance_softc *sc = ifp->if_softc; + + log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); + ++ifp->if_oerrors; + + lance_reset(sc); +} + +int +lance_mediachange(struct ifnet *ifp) +{ + struct lance_softc *sc = ifp->if_softc; + + if (sc->sc_mediachange) + return ((*sc->sc_mediachange)(sc)); + return (0); +} + +void +lance_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) +{ + struct lance_softc *sc = ifp->if_softc; + + if ((ifp->if_flags & IFF_UP) == 0) + return; + + ifmr->ifm_status = IFM_AVALID; + if (sc->sc_havecarrier) + ifmr->ifm_status |= IFM_ACTIVE; + + if (sc->sc_mediastatus) + (*sc->sc_mediastatus)(sc, ifmr); +} + +/* + * Process an ioctl request. + */ +int +lance_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +{ + struct lance_softc *sc = ifp->if_softc; + struct ifaddr *ifa = (struct ifaddr *)data; + struct ifreq *ifr = (struct ifreq *)data; + int s, error = 0; + + s = splnet(); + + switch (cmd) { + case SIOCSIFADDR: + ifp->if_flags |= IFF_UP; + if (!(ifp->if_flags & IFF_RUNNING)) + lance_init(sc); +#ifdef INET + if (ifa->ifa_addr->sa_family == AF_INET) + arp_ifinit(&sc->sc_arpcom, ifa); +#endif + break; + + case SIOCSIFFLAGS: + if (ifp->if_flags & IFF_UP) { + if (ifp->if_flags & IFF_RUNNING) + error = ENETRESET; + else + lance_init(sc); + } else { + if (ifp->if_flags & IFF_RUNNING) { + lance_stop(ifp, 0); + ifp->if_flags &= ~IFF_RUNNING; + } + } + +#ifdef LEDEBUG + if (ifp->if_flags & IFF_DEBUG) + sc->sc_debug = 1; + else + sc->sc_debug = 0; +#endif + break; + + case SIOCGIFMEDIA: + case SIOCSIFMEDIA: + error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd); + break; + + default: + error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data); + break; + } + + if (error == ENETRESET) { + if (ifp->if_flags & IFF_RUNNING) { + /* + * Multicast list has changed; set the hardware filter + * accordingly. + */ + lance_reset(sc); + } + error = 0; + } + + splx(s); + return (error); +} + +/* + * Set up the logical address filter. + */ +void +lance_setladrf(struct arpcom *ac, uint16_t *af) +{ + struct ifnet *ifp = &ac->ac_if; + struct ether_multi *enm; + uint32_t crc; + struct ether_multistep step; + + /* + * Set up multicast address filter by passing all multicast addresses + * through a crc generator, and then using the high order 6 bits as an + * index into the 64 bit logical address filter. The high order bit + * selects the word, while the rest of the bits select the bit within + * the word. + */ + + if (ifp->if_flags & IFF_PROMISC) + goto allmulti; + + af[0] = af[1] = af[2] = af[3] = 0x0000; + ETHER_FIRST_MULTI(step, ac, enm); + while (enm != NULL) { + if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) { + /* + * We must listen to a range of multicast addresses. + * For now, just accept all multicasts, rather than + * trying to set only those filter bits needed to match + * the range. (At this time, the only use of address + * ranges is for IP multicast routing, for which the + * range is big enough to require all bits set.) + */ + goto allmulti; + } + + crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN); + + /* Just want the 6 most significant bits. */ + crc >>= 26; + + /* Set the corresponding bit in the filter. */ + af[crc >> 4] |= 1 << (crc & 0xf); + + ETHER_NEXT_MULTI(step, enm); + } + ifp->if_flags &= ~IFF_ALLMULTI; + return; + +allmulti: + ifp->if_flags |= IFF_ALLMULTI; + af[0] = af[1] = af[2] = af[3] = 0xffff; +} + +/* + * Routines for accessing the transmit and receive buffers. + * The various CPU and adapter configurations supported by this + * driver require three different access methods for buffers + * and descriptors: + * (1) contig (contiguous data; no padding), + * (2) gap2 (two bytes of data followed by two bytes of padding), + * (3) gap16 (16 bytes of data followed by 16 bytes of padding). + */ + +/* + * contig: contiguous data with no padding. + * + * Buffers may have any alignment. + */ + +void +lance_copytobuf_contig(struct lance_softc *sc, void *from, int boff, int len) +{ + uint8_t *buf = sc->sc_mem; + + /* + * Just call memcpy() to do the work. + */ + memcpy(buf + boff, from, len); +} + +void +lance_copyfrombuf_contig(struct lance_softc *sc, void *to, int boff, int len) +{ + uint8_t *buf = sc->sc_mem; + + /* + * Just call memcpy() to do the work. + */ + memcpy(to, buf + boff, len); +} + +void +lance_zerobuf_contig(struct lance_softc *sc, int boff, int len) +{ + uint8_t *buf = sc->sc_mem; + + /* + * Just let memset() do the work + */ + memset(buf + boff, 0, len); +} + +#if 0 +/* + * Examples only; duplicate these and tweak (if necessary) in + * machine-specific front-ends. + */ + +/* + * gap2: two bytes of data followed by two bytes of pad. + * + * Buffers must be 4-byte aligned. The code doesn't worry about + * doing an extra byte. + */ + +void +lance_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len) +{ + volatile void *buf = sc->sc_mem; + void *from = fromv; + volatile uint16_t *bptr; + + if (boff & 0x1) { + /* handle unaligned first byte */ + bptr = ((volatile uint16_t *)buf) + (boff - 1); + *bptr = (*from++ << 8) | (*bptr & 0xff); + bptr += 2; + len--; + } else + bptr = ((volatile uint16_t *)buf) + boff; + while (len > 1) { + *bptr = (from[1] << 8) | (from[0] & 0xff); + bptr += 2; + from += 2; + len -= 2; + } + if (len == 1) + *bptr = (uint16_t)*from; +} + +void +lance_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len) +{ + volatile void *buf = sc->sc_mem; + void *to = tov; + volatile uint16_t *bptr; + uint16_t tmp; + + if (boff & 0x1) { + /* handle unaligned first byte */ + bptr = ((volatile uint16_t *)buf) + (boff - 1); + *to++ = (*bptr >> 8) & 0xff; + bptr += 2; + len--; + } else + bptr = ((volatile uint16_t *)buf) + boff; + while (len > 1) { + tmp = *bptr; + *to++ = tmp & 0xff; + *to++ = (tmp >> 8) & 0xff; + bptr += 2; + len -= 2; + } + if (len == 1) + *to = *bptr & 0xff; +} + +void +lance_zerobuf_gap2(struct lance_softc *sc, int boff, int len) +{ + volatile void *buf = sc->sc_mem; + volatile uint16_t *bptr; + + if ((unsigned int)boff & 0x1) { + bptr = ((volatile uint16_t *)buf) + (boff - 1); + *bptr &= 0xff; + bptr += 2; + len--; + } else + bptr = ((volatile uint16_t *)buf) + boff; + while (len > 0) { + *bptr = 0; + bptr += 2; + len -= 2; + } +} + +/* + * gap16: 16 bytes of data followed by 16 bytes of pad. + * + * Buffers must be 32-byte aligned. + */ + +void +lance_copytobuf_gap16(struct lance_softc *sc, void *fromv, int boff, int len) +{ + volatile uint8_t *buf = sc->sc_mem; + void *from = fromv; + uint8_t *bptr; + int xfer; + + bptr = buf + ((boff << 1) & ~0x1f); + boff &= 0xf; + xfer = min(len, 16 - boff); + while (len > 0) { + memcpy(bptr + boff, from, xfer); + from += xfer; + bptr += 32; + boff = 0; + len -= xfer; + xfer = min(len, 16); + } +} + +void +lance_copyfrombuf_gap16(struct lance_softc *sc, void *tov, int boff, int len) +{ + volatile uint8_t *buf = sc->sc_mem; + void *to = tov; + uint8_t *bptr; + int xfer; + + bptr = buf + ((boff << 1) & ~0x1f); + boff &= 0xf; + xfer = min(len, 16 - boff); + while (len > 0) { + memcpy(to, bptr + boff, xfer); + to += xfer; + bptr += 32; + boff = 0; + len -= xfer; + xfer = min(len, 16); + } +} + +void +lance_zerobuf_gap16(struct lance_softc *sc, int boff, int len) +{ + volatile uint8_t *buf = sc->sc_mem; + uint8_t *bptr; + int xfer; + + bptr = buf + ((boff << 1) & ~0x1f); + boff &= 0xf; + xfer = min(len, 16 - boff); + while (len > 0) { + memset(bptr + boff, 0, xfer); + bptr += 32; + boff = 0; + len -= xfer; + xfer = min(len, 16); + } +} +#endif /* Example only */ diff --git a/sys/dev/ic/lancevar.h b/sys/dev/ic/lancevar.h new file mode 100644 index 00000000000..3cf4c373e60 --- /dev/null +++ b/sys/dev/ic/lancevar.h @@ -0,0 +1,137 @@ +/* $OpenBSD: lancevar.h,v 1.1 2013/09/24 20:10:58 miod Exp $ */ +/* $NetBSD: lancevar.h,v 1.15 2012/02/02 19:43:03 tls Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +struct lance_softc { + struct device sc_dev; /* base device glue */ + struct arpcom sc_arpcom; /* Ethernet common part */ + struct ifmedia sc_ifmedia; /* our supported media */ + + /* + * Memory functions: + * + * copy to/from descriptor + * copy to/from buffer + * zero bytes in buffer + */ + void (*sc_copytodesc)(struct lance_softc *, void *, int, int); + void (*sc_copyfromdesc)(struct lance_softc *, void *, int, int); + void (*sc_copytobuf)(struct lance_softc *, void *, int, int); + void (*sc_copyfrombuf)(struct lance_softc *, void *, int, int); + void (*sc_zerobuf)(struct lance_softc *, int, int); + + /* + * Machine-dependent functions: + * + * read/write CSR + * hardware reset hook - may be NULL + * hardware init hook - may be NULL + * no carrier hook - may be NULL + * media change hook - may be NULL + */ + uint16_t (*sc_rdcsr)(struct lance_softc *, uint16_t); + void (*sc_wrcsr)(struct lance_softc *, uint16_t, uint16_t); + void (*sc_hwreset)(struct lance_softc *); + void (*sc_hwinit)(struct lance_softc *); + void (*sc_nocarrier)(struct lance_softc *); + int (*sc_mediachange)(struct lance_softc *); + void (*sc_mediastatus)(struct lance_softc *, struct ifmediareq *); + + /* + * Media-supported by this interface. If this is NULL, + * the only supported media is assumed to be "manual". + */ + const int *sc_supmedia; + int sc_nsupmedia; + int sc_defaultmedia; + + /* PCnet bit to use software selection of a port */ + int sc_initmodemedia; + + int sc_havecarrier; /* carrier status */ + + uint16_t sc_conf3; /* CSR3 value */ + uint16_t sc_saved_csr0;/* Value of csr0 at time of interrupt */ + + void *sc_mem; /* base address of RAM -- CPU's view */ + u_long sc_addr; /* base address of RAM -- LANCE's view */ + + u_long sc_memsize; /* size of RAM */ + + int sc_nrbuf; /* number of receive buffers */ + int sc_ntbuf; /* number of transmit buffers */ + int sc_last_rd; + int sc_first_td, sc_last_td, sc_no_td; + + int sc_initaddr; + int sc_rmdaddr; + int sc_tmdaddr; + int *sc_rbufaddr; + int *sc_tbufaddr; + +#ifdef LEDEBUG + int sc_debug; +#endif + uint8_t sc_enaddr[ETHER_ADDR_LEN]; + + void (*sc_meminit)(struct lance_softc *); + void (*sc_start)(struct ifnet *); +}; + +extern struct cfdriver le_cd; + +void lance_config(struct lance_softc *); +void lance_reset(struct lance_softc *); +int lance_init(struct lance_softc *); +int lance_put(struct lance_softc *, int, struct mbuf *); +void lance_read(struct lance_softc *, int, int); +void lance_setladrf(struct arpcom *, uint16_t *); + +/* + * The following functions are only useful on certain CPU/bus + * combinations. They should be written in assembly language for + * maximum efficiency, but machine-independent versions are provided + * for drivers that have not yet been optimized. + */ +void lance_copytobuf_contig(struct lance_softc *, void *, int, int); +void lance_copyfrombuf_contig(struct lance_softc *, void *, int, int); +void lance_zerobuf_contig(struct lance_softc *, int, int); + +#if 0 /* Example only - see lance.c */ +void lance_copytobuf_gap2(struct lance_softc *, void *, int, int); +void lance_copyfrombuf_gap2(struct lance_softc *, void *, int, int); +void lance_zerobuf_gap2(struct lance_softc *, int, int); + +void lance_copytobuf_gap16(struct lance_softc *, void *, int, int); +void lance_copyfrombuf_gap16(struct lance_softc *, void *, int, int); +void lance_zerobuf_gap16(struct lance_softc *, int, int); +#endif /* Example only */ diff --git a/sys/dev/isa/files.isa b/sys/dev/isa/files.isa index 9792a41c117..eb939e41c50 100644 --- a/sys/dev/isa/files.isa +++ b/sys/dev/isa/files.isa @@ -1,4 +1,4 @@ -# $OpenBSD: files.isa,v 1.112 2013/04/05 07:25:26 tedu Exp $ +# $OpenBSD: files.isa,v 1.113 2013/09/24 20:10:59 miod Exp $ # $NetBSD: files.isa,v 1.21 1996/05/16 03:45:55 mycroft Exp $ # # Config file and device description for machine-independent ISA code. @@ -186,8 +186,8 @@ file dev/isa/if_ex.c ex needs-flag # AMD am7990 (Lance) -based boards # (BICC Isolan, NE2100, DEPCA) # device declaration in sys/conf/files -attach le at isa with le_isa -file dev/isa/if_le.c le_isa | le_pci +attach le at isa with le_isa: le24 +file dev/isa/if_le.c le_isa file dev/isa/if_le_isa.c le_isa # SMC91Cxx Ethernet Controllers diff --git a/sys/dev/isa/files.isapnp b/sys/dev/isa/files.isapnp index dd9813ff623..a9c25c915a3 100644 --- a/sys/dev/isa/files.isapnp +++ b/sys/dev/isa/files.isapnp @@ -1,4 +1,4 @@ -# $OpenBSD: files.isapnp,v 1.30 2011/06/05 20:57:16 deraadt Exp $ +# $OpenBSD: files.isapnp,v 1.31 2013/09/24 20:11:00 miod Exp $ # $NetBSD: files.isapnp,v 1.7 1997/10/16 17:16:36 matt Exp $ # # Config file and device description for machine-independent ISAPnP code. @@ -45,7 +45,7 @@ file dev/isa/gus_isapnp.c gus_isapnp needs-flag attach an at isapnp with an_isapnp file dev/isa/if_an_isapnp.c an_isapnp -attach le at isapnp with le_isapnp +attach le at isapnp with le_isapnp: le24 file dev/isa/if_le_isapnp.c le_isapnp attach ep at isapnp with ep_isapnp diff --git a/sys/dev/isa/if_le.c b/sys/dev/isa/if_le.c index ca01cb2266e..ef4ce843a66 100644 --- a/sys/dev/isa/if_le.c +++ b/sys/dev/isa/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.18 2007/06/17 21:20:47 jasper Exp $ */ +/* $OpenBSD: if_le.c,v 1.19 2013/09/24 20:11:00 miod Exp $ */ /* $NetBSD: if_le_isa.c,v 1.2 1996/05/12 23:52:56 mycroft Exp $ */ /*- @@ -61,13 +61,15 @@ #include <dev/isa/isavar.h> #include <dev/isa/isadmavar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> #include <dev/isa/if_levar.h> void -le_isa_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) +le_isa_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_softc *lesc = (struct le_softc *)sc; bus_space_tag_t iot = lesc->sc_iot; @@ -77,13 +79,13 @@ le_isa_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) bus_space_write_2(iot, ioh, lesc->sc_rdp, val); } -u_int16_t -le_isa_rdcsr(struct am7990_softc *sc, u_int16_t port) +uint16_t +le_isa_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_softc *lesc = (struct le_softc *)sc; bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; - u_int16_t val; + uint16_t val; bus_space_write_2(iot, ioh, lesc->sc_rap, port); val = bus_space_read_2(iot, ioh, lesc->sc_rdp); diff --git a/sys/dev/isa/if_le_isa.c b/sys/dev/isa/if_le_isa.c index 84b4f0a52ba..146adcabb90 100644 --- a/sys/dev/isa/if_le_isa.c +++ b/sys/dev/isa/if_le_isa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_isa.c,v 1.20 2009/03/29 21:53:52 sthen Exp $ */ +/* $OpenBSD: if_le_isa.c,v 1.21 2013/09/24 20:11:01 miod Exp $ */ /* $NetBSD: if_le_isa.c,v 1.2 1996/05/12 23:52:56 mycroft Exp $ */ /*- @@ -61,6 +61,8 @@ #include <dev/isa/isavar.h> #include <dev/isa/isadmavar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -79,7 +81,7 @@ struct cfattach le_isa_ca = { int depca_isa_probe(struct le_softc *, struct isa_attach_args *); int ne2100_isa_probe(struct le_softc *, struct isa_attach_args *); int bicc_isa_probe(struct le_softc *, struct isa_attach_args *); -int lance_isa_probe(struct am7990_softc *); +int lance_isa_probe(struct lance_softc *); int le_isa_probe(struct device *parent, void *match, void *aux) @@ -99,7 +101,7 @@ le_isa_probe(struct device *parent, void *match, void *aux) depca_isa_probe(lesc, ia) == 0) return (0); - if (bcmp(lesc->sc_am7990.sc_arpcom.ac_enaddr, bogusether, + if (bcmp(lesc->sc_am7990.lsc.sc_arpcom.ac_enaddr, bogusether, sizeof(bogusether)) == 0) return (0); @@ -109,7 +111,7 @@ le_isa_probe(struct device *parent, void *match, void *aux) int depca_isa_probe(struct le_softc *lesc, struct isa_attach_args *ia) { - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; int iosize = 16; @@ -211,7 +213,7 @@ found: int ne2100_isa_probe(struct le_softc *lesc, struct isa_attach_args *ia) { - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; int iosize = 24; @@ -244,7 +246,7 @@ ne2100_isa_probe(struct le_softc *lesc, struct isa_attach_args *ia) int bicc_isa_probe(struct le_softc *lesc, struct isa_attach_args *ia) { - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_space_handle_t ioh; bus_space_tag_t iot = ia->ia_iot; int iosize = 16; @@ -278,7 +280,7 @@ bicc_isa_probe(struct le_softc *lesc, struct isa_attach_args *ia) * Determine which chip is present on the card. */ int -lance_isa_probe(struct am7990_softc *sc) +lance_isa_probe(struct lance_softc *sc) { /* Stop the LANCE chip and put it in a known state. */ @@ -297,7 +299,7 @@ le_isa_attach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (void *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct isa_attach_args *ia = aux; bus_space_tag_t iot = ia->ia_iot; bus_space_handle_t ioh; @@ -346,11 +348,11 @@ le_isa_attach(struct device *parent, struct device *self, sc->sc_memsize = 16384; } - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = le_isa_rdcsr; sc->sc_wrcsr = le_isa_wrcsr; @@ -358,7 +360,7 @@ le_isa_attach(struct device *parent, struct device *self, sc->sc_hwinit = NULL; printf("%s", sc->sc_dev.dv_xname); - am7990_config(sc); + am7990_config(&lesc->sc_am7990); #if NISADMA > 0 if (ia->ia_drq != DRQUNK) diff --git a/sys/dev/isa/if_le_isapnp.c b/sys/dev/isa/if_le_isapnp.c index 2defed5b878..fae3d9b158a 100644 --- a/sys/dev/isa/if_le_isapnp.c +++ b/sys/dev/isa/if_le_isapnp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_isapnp.c,v 1.12 2007/06/17 21:20:47 jasper Exp $ */ +/* $OpenBSD: if_le_isapnp.c,v 1.13 2013/09/24 20:11:01 miod Exp $ */ /* $NetBSD: if_le_isa.c,v 1.2 1996/05/12 23:52:56 mycroft Exp $ */ /*- @@ -61,6 +61,8 @@ #include <dev/isa/isavar.h> #include <dev/isa/isadmavar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -84,7 +86,7 @@ le_isapnp_attach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (void *)self; struct isa_attach_args *ia = aux; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; int i; @@ -111,18 +113,18 @@ le_isapnp_attach(struct device *parent, struct device *self, void *aux) sc->sc_addr = kvtop(sc->sc_mem); sc->sc_memsize = 16384; - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = le_isa_rdcsr; sc->sc_wrcsr = le_isa_wrcsr; sc->sc_hwreset = NULL; sc->sc_hwinit = NULL; - am7990_config(sc); + am7990_config(&lesc->sc_am7990); #if NISADMA > 0 if (ia->ia_drq != DRQUNK) diff --git a/sys/dev/isa/if_levar.h b/sys/dev/isa/if_levar.h index 8027ebf72ba..e016e55ecc3 100644 --- a/sys/dev/isa/if_levar.h +++ b/sys/dev/isa/if_levar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_levar.h,v 1.9 2007/06/17 21:20:47 jasper Exp $ */ +/* $OpenBSD: if_levar.h,v 1.10 2013/09/24 20:11:01 miod Exp $ */ /* $NetBSD: if_levar.h,v 1.5 1996/05/07 01:50:07 thorpej Exp $ */ /* @@ -55,6 +55,6 @@ struct le_softc { bus_space_handle_t sc_ioh; }; -void le_isa_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t le_isa_rdcsr(struct am7990_softc *, u_int16_t); +void le_isa_wrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t le_isa_rdcsr(struct lance_softc *, uint16_t); int le_isa_intredge(void *); diff --git a/sys/dev/sbus/files.sbus b/sys/dev/sbus/files.sbus index b6aec778c4b..7184d70ca0f 100644 --- a/sys/dev/sbus/files.sbus +++ b/sys/dev/sbus/files.sbus @@ -1,4 +1,4 @@ -# $OpenBSD: files.sbus,v 1.38 2009/09/01 14:45:44 kettenis Exp $ +# $OpenBSD: files.sbus,v 1.39 2013/09/24 20:11:02 miod Exp $ # $NetBSD: files.sbus,v 1.16 2000/12/08 17:29:12 martin Exp $ # # Config file and device description for machine-independent SBUS code. @@ -19,9 +19,9 @@ attach lebuffer at sbus file dev/sbus/lebuffer.c lebuffer # device definition in sys/conf/files -attach le at sbus with le_sbus -attach le at lebuffer with le_lebuffer -attach le at ledma with le_ledma +attach le at sbus with le_sbus: le24 +attach le at lebuffer with le_lebuffer: le24 +attach le at ledma with le_ledma: le24 file dev/sbus/if_le.c le_sbus file dev/sbus/if_le_lebuffer.c le_lebuffer file dev/sbus/if_le_ledma.c le_ledma diff --git a/sys/dev/sbus/if_le.c b/sys/dev/sbus/if_le.c index 2fd65446955..7910b8fd149 100644 --- a/sys/dev/sbus/if_le.c +++ b/sys/dev/sbus/if_le.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le.c,v 1.14 2008/06/26 05:42:18 ray Exp $ */ +/* $OpenBSD: if_le.c,v 1.15 2013/09/24 20:11:02 miod Exp $ */ /* $NetBSD: if_le.c,v 1.17 2001/05/30 11:46:35 mrg Exp $ */ /*- @@ -56,6 +56,8 @@ #include <dev/sbus/sbusvar.h> #include <dev/sbus/lebuffervar.h> /*XXX*/ +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -81,15 +83,19 @@ void leattach_sbus(struct device *, struct device *, void *); /* * Media types supported. */ +static int lemedia[] = { + IFM_ETHER | IFM_10_5 +}; + struct cfattach le_sbus_ca = { sizeof(struct le_softc), lematch_sbus, leattach_sbus }; -void le_sbus_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t le_sbus_rdcsr(struct am7990_softc *, u_int16_t); +void le_sbus_wrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t le_sbus_rdcsr(struct lance_softc *, uint16_t); void -le_sbus_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) +le_sbus_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_softc *lesc = (struct le_softc *)sc; @@ -107,15 +113,15 @@ le_sbus_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) * just wrote (thanks to Chris Torek for this solution). */ if (CPU_ISSUN4M) { - volatile u_int16_t discard; + volatile uint16_t discard; discard = bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP); } #endif } -u_int16_t -le_sbus_rdcsr(struct am7990_softc *sc, u_int16_t port) +uint16_t +le_sbus_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_softc *lesc = (struct le_softc *)sc; @@ -140,7 +146,7 @@ leattach_sbus(struct device *parent, struct device *self, void *aux) { struct sbus_attach_args *sa = aux; struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_dma_tag_t dmatag; /* XXX the following declarations should be elsewhere */ extern void myetheraddr(u_char *); @@ -228,11 +234,15 @@ leattach_sbus(struct device *parent, struct device *self, void *aux) myetheraddr(sc->sc_arpcom.ac_enaddr); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_supmedia = lemedia; + sc->sc_nsupmedia = nitems(lemedia); + sc->sc_defaultmedia = sc->sc_supmedia[sc->sc_nsupmedia - 1]; + + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = le_sbus_rdcsr; sc->sc_wrcsr = le_sbus_wrcsr; diff --git a/sys/dev/sbus/if_le_lebuffer.c b/sys/dev/sbus/if_le_lebuffer.c index 0d5b06a377f..5662bd9017f 100644 --- a/sys/dev/sbus/if_le_lebuffer.c +++ b/sys/dev/sbus/if_le_lebuffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_lebuffer.c,v 1.10 2012/12/05 23:20:21 deraadt Exp $ */ +/* $OpenBSD: if_le_lebuffer.c,v 1.11 2013/09/24 20:11:03 miod Exp $ */ /* $NetBSD: if_le_lebuffer.c,v 1.10 2002/03/11 16:00:56 pk Exp $ */ /*- @@ -56,6 +56,8 @@ #include <dev/sbus/sbusvar.h> #include <dev/sbus/lebuffervar.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -76,6 +78,13 @@ struct le_softc { int lematch_lebuffer(struct device *, void *, void *); void leattach_lebuffer(struct device *, struct device *, void *); +/* + * Media types supported. + */ +static int lemedia[] = { + IFM_ETHER | IFM_10_T +}; + struct cfattach le_lebuffer_ca = { sizeof(struct le_softc), lematch_lebuffer, leattach_lebuffer }; @@ -86,11 +95,11 @@ struct cfdriver lebuffer_cd = { NULL, "lebuffer", DV_DULL }; -void le_lebuffer_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t le_lebuffer_rdcsr(struct am7990_softc *, u_int16_t); +void le_lebuffer_wrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t le_lebuffer_rdcsr(struct lance_softc *, uint16_t); void -le_lebuffer_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) +le_lebuffer_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_softc *lesc = (struct le_softc *)sc; @@ -108,15 +117,15 @@ le_lebuffer_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) * just wrote (thanks to Chris Torek for this solution). */ if (CPU_ISSUN4M) { - volatile u_int16_t discard; + volatile uint16_t discard; discard = bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP); } #endif } -u_int16_t -le_lebuffer_rdcsr(struct am7990_softc *sc, u_int16_t port) +uint16_t +le_lebuffer_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_softc *lesc = (struct le_softc *)sc; @@ -141,7 +150,7 @@ leattach_lebuffer(struct device *parent, struct device *self, void *aux) { struct sbus_attach_args *sa = aux; struct le_softc *lesc = (struct le_softc *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct lebuf_softc *lebuf = (struct lebuf_softc *)parent; /* XXX the following declarations should be elsewhere */ extern void myetheraddr(u_char *); @@ -167,11 +176,15 @@ leattach_lebuffer(struct device *parent, struct device *self, void *aux) myetheraddr(sc->sc_arpcom.ac_enaddr); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_supmedia = lemedia; + sc->sc_nsupmedia = nitems(lemedia); + sc->sc_defaultmedia = sc->sc_supmedia[sc->sc_nsupmedia - 1]; + + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = le_lebuffer_rdcsr; sc->sc_wrcsr = le_lebuffer_wrcsr; diff --git a/sys/dev/sbus/if_le_ledma.c b/sys/dev/sbus/if_le_ledma.c index 1fe567b9ea5..8d0cc142575 100644 --- a/sys/dev/sbus/if_le_ledma.c +++ b/sys/dev/sbus/if_le_ledma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_ledma.c,v 1.16 2012/07/30 16:58:19 miod Exp $ */ +/* $OpenBSD: if_le_ledma.c,v 1.17 2013/09/24 20:11:04 miod Exp $ */ /* $NetBSD: if_le_ledma.c,v 1.14 2001/05/30 11:46:35 mrg Exp $ */ /*- @@ -58,6 +58,8 @@ #include <dev/ic/lsi64854reg.h> #include <dev/ic/lsi64854var.h> +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -85,25 +87,30 @@ void leattach_ledma(struct device *, struct device *, void *); /* * Media types supported by the Sun4m. */ +static int lemedia[] = { + IFM_ETHER | IFM_10_T, + IFM_ETHER | IFM_10_5, + IFM_ETHER | IFM_AUTO +}; -void le_ledma_setutp(struct am7990_softc *); -void le_ledma_setaui(struct am7990_softc *); +void le_ledma_setutp(struct lance_softc *); +void le_ledma_setaui(struct lance_softc *); -int lemediachange(struct ifnet *); -void lemediastatus(struct ifnet *, struct ifmediareq *); +int lemediachange(struct lance_softc *); +void lemediastatus(struct lance_softc *, struct ifmediareq *); struct cfattach le_ledma_ca = { sizeof(struct le_softc), lematch_ledma, leattach_ledma }; -void le_ledma_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t); -u_int16_t le_ledma_rdcsr(struct am7990_softc *, u_int16_t); -void le_ledma_hwreset(struct am7990_softc *); -void le_ledma_hwinit(struct am7990_softc *); -void le_ledma_nocarrier(struct am7990_softc *); +void le_ledma_wrcsr(struct lance_softc *, uint16_t, uint16_t); +uint16_t le_ledma_rdcsr(struct lance_softc *, uint16_t); +void le_ledma_hwreset(struct lance_softc *); +void le_ledma_hwinit(struct lance_softc *); +void le_ledma_nocarrier(struct lance_softc *); void -le_ledma_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) +le_ledma_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_softc *lesc = (struct le_softc *)sc; @@ -121,15 +128,15 @@ le_ledma_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val) * just wrote (thanks to Chris Torek for this solution). */ if (CPU_ISSUN4M) { - volatile u_int16_t discard; + volatile uint16_t discard; discard = bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP); } #endif } -u_int16_t -le_ledma_rdcsr(struct am7990_softc *sc, u_int16_t port) +uint16_t +le_ledma_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_softc *lesc = (struct le_softc *)sc; @@ -140,7 +147,7 @@ le_ledma_rdcsr(struct am7990_softc *sc, u_int16_t port) } void -le_ledma_setutp(struct am7990_softc *sc) +le_ledma_setutp(struct lance_softc *sc) { struct lsi64854_softc *dma = ((struct le_softc *)sc)->sc_dma; u_int32_t csr; @@ -152,7 +159,7 @@ le_ledma_setutp(struct am7990_softc *sc) } void -le_ledma_setaui(struct am7990_softc *sc) +le_ledma_setaui(struct lance_softc *sc) { struct lsi64854_softc *dma = ((struct le_softc *)sc)->sc_dma; u_int32_t csr; @@ -164,9 +171,8 @@ le_ledma_setaui(struct am7990_softc *sc) } int -lemediachange(struct ifnet *ifp) +lemediachange(struct lance_softc *sc) { - struct am7990_softc *sc = ifp->if_softc; struct ifmedia *ifm = &sc->sc_ifmedia; if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) @@ -198,9 +204,8 @@ lemediachange(struct ifnet *ifp) } void -lemediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) +lemediastatus(struct lance_softc *sc, struct ifmediareq *ifmr) { - struct am7990_softc *sc = ifp->if_softc; struct lsi64854_softc *dma = ((struct le_softc *)sc)->sc_dma; /* @@ -213,7 +218,7 @@ lemediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) } void -le_ledma_hwreset(struct am7990_softc *sc) +le_ledma_hwreset(struct lance_softc *sc) { struct le_softc *lesc = (struct le_softc *)sc; struct lsi64854_softc *dma = lesc->sc_dma; @@ -244,7 +249,7 @@ le_ledma_hwreset(struct am7990_softc *sc) } void -le_ledma_hwinit(struct am7990_softc *sc) +le_ledma_hwinit(struct lance_softc *sc) { /* @@ -263,7 +268,7 @@ le_ledma_hwinit(struct am7990_softc *sc) } void -le_ledma_nocarrier(struct am7990_softc *sc) +le_ledma_nocarrier(struct lance_softc *sc) { struct le_softc *lesc = (struct le_softc *)sc; @@ -307,7 +312,7 @@ leattach_ledma(struct device *parent, struct device *self, void *aux) struct sbus_attach_args *sa = aux; struct le_softc *lesc = (struct le_softc *)self; struct lsi64854_softc *lsi = (struct lsi64854_softc *)parent; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; bus_dma_tag_t dmatag = sa->sa_dmatag; bus_dma_segment_t seg; int rseg, error; @@ -374,20 +379,19 @@ leattach_ledma(struct device *parent, struct device *self, void *aux) sc->sc_addr = lesc->sc_laddr & 0xffffff; sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON; - ifmedia_init(&sc->sc_ifmedia, 0, lemediachange, lemediastatus); - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_5, 0, NULL); - ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL); - ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO); - sc->sc_hasifmedia = 1; - myetheraddr(sc->sc_arpcom.ac_enaddr); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_mediachange = lemediachange; + sc->sc_mediastatus = lemediastatus; + sc->sc_supmedia = lemedia; + sc->sc_nsupmedia = nitems(lemedia); + sc->sc_defaultmedia = sc->sc_supmedia[sc->sc_nsupmedia - 1]; + + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; sc->sc_rdcsr = le_ledma_rdcsr; sc->sc_wrcsr = le_ledma_wrcsr; diff --git a/sys/dev/tc/files.tc b/sys/dev/tc/files.tc index 86ab00bf4f6..4487b0db9f8 100644 --- a/sys/dev/tc/files.tc +++ b/sys/dev/tc/files.tc @@ -1,4 +1,4 @@ -# $OpenBSD: files.tc,v 1.9 2011/09/04 20:10:18 miod Exp $ +# $OpenBSD: files.tc,v 1.10 2013/09/24 20:11:05 miod Exp $ # $NetBSD: files.tc,v 1.26 2001/11/28 10:21:24 lukem Exp $ # # Config file and device description for machine-independent @@ -17,10 +17,10 @@ file dev/tc/ioasic_subr.c ioasic # lance device defined in sys/conf/files # le_dec_subr attribute defined in sys/dev/dec/files.dec -attach le at ioasic with le_ioasic: le_dec_subr +attach le at ioasic with le_ioasic: le24, le_dec_subr file dev/tc/if_le_ioasic.c le_ioasic -attach le at tc with le_tc: le_dec_subr +attach le at tc with le_tc: le24, le_dec_subr file dev/tc/if_le_tc.c le_tc # baseboard audio diff --git a/sys/dev/tc/if_le_ioasic.c b/sys/dev/tc/if_le_ioasic.c index fd1d021b5b4..8f12e7bc385 100644 --- a/sys/dev/tc/if_le_ioasic.c +++ b/sys/dev/tc/if_le_ioasic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_ioasic.c,v 1.15 2008/08/09 16:42:30 miod Exp $ */ +/* $OpenBSD: if_le_ioasic.c,v 1.16 2013/09/24 20:11:05 miod Exp $ */ /* $NetBSD: if_le_ioasic.c,v 1.18 2001/11/13 06:26:10 lukem Exp $ */ /* @@ -47,6 +47,8 @@ #include <netinet/if_ether.h> #endif +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -71,15 +73,11 @@ struct cfattach le_ioasic_ca = { sizeof(struct le_softc), le_ioasic_match, le_ioasic_attach }; -void le_ioasic_copytobuf_gap2(struct am7990_softc *, void *, - int, int); -void le_ioasic_copyfrombuf_gap2(struct am7990_softc *, void *, - int, int); -void le_ioasic_copytobuf_gap16(struct am7990_softc *, void *, - int, int); -void le_ioasic_copyfrombuf_gap16(struct am7990_softc *, void *, - int, int); -void le_ioasic_zerobuf_gap16(struct am7990_softc *, int, int); +void le_ioasic_copytobuf_gap2(struct lance_softc *, void *, int, int); +void le_ioasic_copyfrombuf_gap2(struct lance_softc *, void *, int, int); +void le_ioasic_copytobuf_gap16(struct lance_softc *, void *, int, int); +void le_ioasic_copyfrombuf_gap16(struct lance_softc *, void *, int, int); +void le_ioasic_zerobuf_gap16(struct lance_softc *, int, int); int le_ioasic_match(struct device *parent, void *match, void *aux) @@ -101,7 +99,7 @@ le_ioasic_attach(struct device *parent, struct device *self, void *aux) { struct le_ioasic_softc *sc = (void *)self; struct ioasicdev_attach_args *d = aux; - struct am7990_softc *le = &sc->sc_am7990; + struct lance_softc *le = &sc->sc_am7990.lsc; bus_space_tag_t ioasic_bst; bus_space_handle_t ioasic_bsh; bus_dma_tag_t dmat; @@ -185,7 +183,7 @@ le_ioasic_attach(struct device *parent, struct device *self, void *aux) */ void -le_ioasic_copytobuf_gap2(struct am7990_softc *sc, void *fromv, +le_ioasic_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len) { volatile caddr_t buf = sc->sc_mem; @@ -211,7 +209,7 @@ le_ioasic_copytobuf_gap2(struct am7990_softc *sc, void *fromv, } void -le_ioasic_copyfrombuf_gap2(struct am7990_softc *sc, void *tov, +le_ioasic_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len) { volatile caddr_t buf = sc->sc_mem; @@ -245,7 +243,7 @@ le_ioasic_copyfrombuf_gap2(struct am7990_softc *sc, void *tov, */ void -le_ioasic_copytobuf_gap16(struct am7990_softc *sc, void *fromv, +le_ioasic_copytobuf_gap16(struct lance_softc *sc, void *fromv, int boff, int len) { volatile caddr_t buf = sc->sc_mem; @@ -327,7 +325,7 @@ le_ioasic_copytobuf_gap16(struct am7990_softc *sc, void *fromv, } void -le_ioasic_copyfrombuf_gap16(struct am7990_softc *sc, void *tov, +le_ioasic_copyfrombuf_gap16(struct lance_softc *sc, void *tov, int boff, int len) { volatile caddr_t buf = sc->sc_mem; @@ -401,7 +399,7 @@ le_ioasic_copyfrombuf_gap16(struct am7990_softc *sc, void *tov, } void -le_ioasic_zerobuf_gap16(struct am7990_softc *sc, int boff, int len) +le_ioasic_zerobuf_gap16(struct lance_softc *sc, int boff, int len) { volatile caddr_t buf = sc->sc_mem; caddr_t bptr; diff --git a/sys/dev/tc/if_le_tc.c b/sys/dev/tc/if_le_tc.c index f3df7ea9aa9..81e660e8144 100644 --- a/sys/dev/tc/if_le_tc.c +++ b/sys/dev/tc/if_le_tc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_le_tc.c,v 1.10 2008/08/09 16:42:30 miod Exp $ */ +/* $OpenBSD: if_le_tc.c,v 1.11 2013/09/24 20:11:05 miod Exp $ */ /* $NetBSD: if_le_tc.c,v 1.12 2001/11/13 06:26:10 lukem Exp $ */ /* @@ -47,6 +47,8 @@ #include <netinet/if_ether.h> #endif +#include <dev/ic/lancereg.h> +#include <dev/ic/lancevar.h> #include <dev/ic/am7990reg.h> #include <dev/ic/am7990var.h> @@ -79,7 +81,7 @@ void le_tc_attach(struct device *parent, struct device *self, void *aux) { struct le_softc *lesc = (void *)self; - struct am7990_softc *sc = &lesc->sc_am7990; + struct lance_softc *sc = &lesc->sc_am7990.lsc; struct tc_attach_args *d = aux; /* @@ -90,11 +92,11 @@ le_tc_attach(struct device *parent, struct device *self, void *aux) TC_DENSE_TO_SPARSE(TC_PHYS_TO_UNCACHED(d->ta_addr + LE_OFFSET_LANCE)); sc->sc_mem = (void *)(d->ta_addr + LE_OFFSET_RAM); - sc->sc_copytodesc = am7990_copytobuf_contig; - sc->sc_copyfromdesc = am7990_copyfrombuf_contig; - sc->sc_copytobuf = am7990_copytobuf_contig; - sc->sc_copyfrombuf = am7990_copyfrombuf_contig; - sc->sc_zerobuf = am7990_zerobuf_contig; + sc->sc_copytodesc = lance_copytobuf_contig; + sc->sc_copyfromdesc = lance_copyfrombuf_contig; + sc->sc_copytobuf = lance_copytobuf_contig; + sc->sc_copyfrombuf = lance_copyfrombuf_contig; + sc->sc_zerobuf = lance_zerobuf_contig; /* * TC lance boards have onboard SRAM buffers. DMA @@ -103,7 +105,7 @@ le_tc_attach(struct device *parent, struct device *self, void *aux) */ dec_le_common_attach(&lesc->sc_am7990, - (u_char *)(d->ta_addr + LE_OFFSET_ROM + 2)); + (u_char *)(d->ta_addr + LE_OFFSET_ROM + 2)); tc_intr_establish(parent, d->ta_cookie, IPL_NET, am7990_intr, sc, self->dv_xname); |