1 /* $NetBSD: if_le_dec.c,v 1.8 1997/07/22 04:32:21 jonathan Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 Jonathan Stone. All rights reserved. 5 * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 6 * Copyright (c) 1992, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * Ralph Campbell and Rick Macklem. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 41 */ 42 43 #include "bpfilter.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/mbuf.h> 48 #include <sys/syslog.h> 49 #include <sys/socket.h> 50 #include <sys/device.h> 51 52 #include <net/if.h> 53 #include <net/if_ether.h> 54 #include <net/if_media.h> 55 56 #ifdef INET 57 #include <netinet/in.h> 58 #include <netinet/if_inarp.h> 59 #endif 60 61 #include <dev/ic/am7990reg.h> 62 #include <dev/ic/am7990var.h> 63 64 #include <dev/tc/if_levar.h> 65 #include <dev/tc/tcvar.h> 66 67 #include <machine/bus.h> 68 69 /* access LANCE registers */ 70 void le_dec_writereg __P((volatile u_short *regptr, u_short val)); 71 #define LERDWR(cntl, src, dst) { (dst) = (src); tc_mb(); } 72 #define LEWREG(src, dst) le_dec_writereg(&(dst), (src)) 73 74 hide void le_dec_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t)); 75 hide u_int16_t le_dec_rdcsr __P((struct am7990_softc *, u_int16_t)); 76 77 void 78 dec_le_common_attach(sc, eap) 79 struct am7990_softc *sc; 80 u_char *eap; 81 { 82 int i; 83 84 sc->sc_rdcsr = le_dec_rdcsr; 85 sc->sc_wrcsr = le_dec_wrcsr; 86 sc->sc_hwinit = NULL; 87 88 sc->sc_conf3 = 0; 89 sc->sc_addr = 0; 90 sc->sc_memsize = 65536; 91 92 /* 93 * Get the ethernet address out of rom 94 */ 95 for (i = 0; i < sizeof(sc->sc_enaddr); i++) { 96 sc->sc_enaddr[i] = *eap; 97 eap += 4; 98 } 99 100 am7990_config(sc); 101 } 102 103 hide void 104 le_dec_wrcsr(sc, port, val) 105 struct am7990_softc *sc; 106 u_int16_t port, val; 107 { 108 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 109 110 LEWREG(port, ler1->ler1_rap); 111 LERDWR(port, val, ler1->ler1_rdp); 112 } 113 114 hide u_int16_t 115 le_dec_rdcsr(sc, port) 116 struct am7990_softc *sc; 117 u_int16_t port; 118 { 119 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 120 u_int16_t val; 121 122 LEWREG(port, ler1->ler1_rap); 123 LERDWR(0, ler1->ler1_rdp, val); 124 return (val); 125 } 126 127 /* 128 * Write a lance register port, reading it back to ensure success. This seems 129 * to be necessary during initialization, since the chip appears to be a bit 130 * pokey sometimes. 131 */ 132 void 133 le_dec_writereg(regptr, val) 134 register volatile u_short *regptr; 135 register u_short val; 136 { 137 register int i = 0; 138 139 while (*regptr != val) { 140 *regptr = val; 141 tc_mb(); 142 if (++i > 10000) { 143 printf("le: Reg did not settle (to x%x): x%x\n", val, 144 *regptr); 145 return; 146 } 147 DELAY(100); 148 } 149 } 150 151 /* 152 * Routines for accessing the transmit and receive buffers are provided 153 * by am7990.c, because of the LE_NEED_BUF_* macros defined above. 154 * Unfortunately, CPU addressing of these buffers is done in one of 155 * 3 ways: 156 * - contiguous (for the 3max and turbochannel option card) 157 * - gap2, which means shorts (2 bytes) interspersed with short (2 byte) 158 * spaces (for the pmax, vax 3400, and ioasic LANCE descriptors) 159 * - gap16, which means 16bytes interspersed with 16byte spaces 160 * for buffers which must begin on a 32byte boundary (for 3min, maxine, 161 * and alpha) 162 * The buffer offset is the logical byte offset, assuming contiguous storage. 163 */ 164