From 2d3bb76a104cccecb76fe9326520afa50265ce13 Mon Sep 17 00:00:00 2001 From: mycroft Date: Wed, 17 Mar 2004 23:47:16 +0000 Subject: [PATCH] A random patch that's been in my source tree... Figure out whether the shared memory region is word-accessible in the same place we figure out its size, and store this in the softc, rather than using a series of comparisons later. --- sys/dev/ic/ne2000.c | 69 ++++++++++++++++++++---------------------- sys/dev/ic/ne2000var.h | 28 +++++++---------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/sys/dev/ic/ne2000.c b/sys/dev/ic/ne2000.c index 507d67f84126..ec9a0180709a 100644 --- a/sys/dev/ic/ne2000.c +++ b/sys/dev/ic/ne2000.c @@ -1,4 +1,4 @@ -/* $NetBSD: ne2000.c,v 1.41 2003/11/02 11:07:45 wiz Exp $ */ +/* $NetBSD: ne2000.c,v 1.42 2004/03/17 23:47:16 mycroft Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ne2000.c,v 1.41 2003/11/02 11:07:45 wiz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ne2000.c,v 1.42 2004/03/17 23:47:16 mycroft Exp $"); #include "opt_ipkdb.h" @@ -126,16 +126,36 @@ ne2000_attach(nsc, myea) * Detect it again unless caller specified it; this gives us * the memory size. */ - if (nsc->sc_type == 0) { + if (nsc->sc_type == NE2000_TYPE_UNKNOWN) nsc->sc_type = ne2000_detect(nict, nich, asict, asich); - if (nsc->sc_type == 0) { - printf("%s: where did the card go?\n", - dsc->sc_dev.dv_xname); - return (1); - } + + /* + * 8k of memory for NE1000, 16k for NE2000 and 24k for the + * card uses DL10019. + */ + switch (nsc->sc_type) { + case NE2000_TYPE_UNKNOWN: + default: + printf("%s: where did the card go?\n", dsc->sc_dev.dv_xname); + return (1); + case NE2000_TYPE_NE1000: + memsize = 8192; + useword = 0; + break; + case NE2000_TYPE_NE2000: + case NE2000_TYPE_AX88190: /* XXX really? */ + case NE2000_TYPE_AX88790: + memsize = 8192 * 2; + useword = 1; + break; + case NE2000_TYPE_DL10019: + case NE2000_TYPE_DL10022: + memsize = 8192 * 3; + useword = 1; + break; } - useword = NE2000_USE_WORD(nsc); + nsc->sc_useword = useword; dsc->cr_proto = ED_CR_RD2; if (nsc->sc_type == NE2000_TYPE_AX88190 || @@ -164,28 +184,6 @@ ne2000_attach(nsc, myea) for (i = 0; i < 16; i++) dsc->sc_reg_map[i] = i; - /* - * 8k of memory for NE1000, 16k for NE2000 and 24k for the - * card uses DL10019. - */ - switch (nsc->sc_type) { - case NE2000_TYPE_NE1000: - memsize = 8192; - break; - case NE2000_TYPE_NE2000: - case NE2000_TYPE_AX88190: /* XXX really? */ - case NE2000_TYPE_AX88790: - memsize = 8192 * 2; - break; - case NE2000_TYPE_DL10019: - case NE2000_TYPE_DL10022: - memsize = 8192 * 3; - break; - default: - memsize = 0; - break; - } - /* * NIC memory doens't start at zero on an NE board. * The start address is tied to the bus width. @@ -668,7 +666,7 @@ ne2000_ring_copy(sc, src, dst, amount) bus_space_tag_t asict = nsc->sc_asict; bus_space_handle_t asich = nsc->sc_asich; u_short tmp_amount; - int useword = NE2000_USE_WORD(nsc); + int useword = nsc->sc_useword; /* Does copy wrap to lower addr in ring buffer? */ if (src + amount > sc->mem_end) { @@ -699,7 +697,7 @@ ne2000_read_hdr(sc, buf, hdr) ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich, buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring), - NE2000_USE_WORD(nsc)); + nsc->sc_useword); #if BYTE_ORDER == BIG_ENDIAN hdr->count = bswap16(hdr->count); #endif @@ -864,7 +862,7 @@ ne2000_ipkdb_attach(kip) if (np->sc_type == 0) return -1; - useword = NE2000_USE_WORD(np); + useword = np->sc_useword; dp->cr_proto = ED_CR_RD2; dp->dcr_reg = ED_DCR_FT1 | ED_DCR_LS | (useword ? ED_DCR_WTS : 0); @@ -927,9 +925,8 @@ ne2000_ipkdb_attach(kip) } else { ne2000_readmem(nict, nich, np->sc_asict, np->sc_asich, 0, romdata, sizeof romdata, useword); - useword = useword ? 2 : 1; for (i = 0; i < ETHER_ADDR_LEN; i++) - kip->myenetaddr[i] = romdata[i * useword]; + kip->myenetaddr[i] = romdata[i << useword]; } kip->flags |= IPKDB_MYHW; diff --git a/sys/dev/ic/ne2000var.h b/sys/dev/ic/ne2000var.h index 9905a1ec254f..532c664ee5d8 100644 --- a/sys/dev/ic/ne2000var.h +++ b/sys/dev/ic/ne2000var.h @@ -1,4 +1,4 @@ -/* $NetBSD: ne2000var.h,v 1.14 2003/10/22 00:12:36 christos Exp $ */ +/* $NetBSD: ne2000var.h,v 1.15 2004/03/17 23:47:16 mycroft Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -46,24 +46,18 @@ struct ne2000_softc { bus_space_tag_t sc_asict; /* space tag for ASIC */ bus_space_handle_t sc_asich; /* space handle for ASIC */ - int sc_type; + enum { + NE2000_TYPE_UNKNOWN = 0, + NE2000_TYPE_NE1000, + NE2000_TYPE_NE2000, + NE2000_TYPE_DL10019, + NE2000_TYPE_DL10022, + NE2000_TYPE_AX88190, + NE2000_TYPE_AX88790 + } sc_type; + int sc_useword; }; -/* sc_type */ -#define NE2000_TYPE_NE1000 1 -#define NE2000_TYPE_NE2000 2 -#define NE2000_TYPE_DL10019 3 -#define NE2000_TYPE_DL10022 4 -#define NE2000_TYPE_AX88190 5 -#define NE2000_TYPE_AX88790 6 - -#define NE2000_USE_WORD(sc) \ - (((sc)->sc_type == NE2000_TYPE_NE2000) || \ - ((sc)->sc_type == NE2000_TYPE_DL10019) || \ - ((sc)->sc_type == NE2000_TYPE_DL10022) || \ - ((sc)->sc_type == NE2000_TYPE_AX88190) || \ - ((sc)->sc_type == NE2000_TYPE_AX88790)) - int ne2000_attach __P((struct ne2000_softc *, u_int8_t *)); int ne2000_detect __P((bus_space_tag_t, bus_space_handle_t, bus_space_tag_t, bus_space_handle_t));