Annotation of sys/arch/luna88k/dev/if_le.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_le.c,v 1.4 2004/08/30 13:10:32 aoyama Exp $ */
! 2: /* $NetBSD: if_le.c,v 1.33 1996/11/20 18:56:52 gwr Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1996 The NetBSD Foundation, Inc.
! 6: * All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to The NetBSD Foundation
! 9: * by Adam Glass and Gordon W. Ross.
! 10: *
! 11: * Redistribution and use in source and binary forms, with or without
! 12: * modification, are permitted provided that the following conditions
! 13: * are met:
! 14: * 1. Redistributions of source code must retain the above copyright
! 15: * notice, this list of conditions and the following disclaimer.
! 16: * 2. Redistributions in binary form must reproduce the above copyright
! 17: * notice, this list of conditions and the following disclaimer in the
! 18: * documentation and/or other materials provided with the distribution.
! 19: * 3. All advertising materials mentioning features or use of this software
! 20: * must display the following acknowledgement:
! 21: * This product includes software developed by the NetBSD
! 22: * Foundation, Inc. and its contributors.
! 23: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 24: * contributors may be used to endorse or promote products derived
! 25: * from this software without specific prior written permission.
! 26: *
! 27: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 28: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 29: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 30: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
! 31: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 32: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 33: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 35: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 36: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 37: * POSSIBILITY OF SUCH DAMAGE.
! 38: */
! 39:
! 40: /* based on OpenBSD: sys/arch/sun3/dev/if_le.c */
! 41:
! 42: #include <sys/param.h>
! 43: #include <sys/systm.h>
! 44: #include <sys/mbuf.h>
! 45: #include <sys/syslog.h>
! 46: #include <sys/socket.h>
! 47: #include <sys/device.h>
! 48:
! 49: #include <net/if.h>
! 50:
! 51: #ifdef INET
! 52: #include <netinet/in.h>
! 53: #include <netinet/if_ether.h>
! 54: #endif
! 55:
! 56: #include <net/if_media.h>
! 57:
! 58: #include <machine/autoconf.h>
! 59: #include <machine/board.h>
! 60: #include <machine/cpu.h>
! 61:
! 62: #include <dev/ic/am7990reg.h>
! 63: #include <dev/ic/am7990var.h>
! 64:
! 65: #include <luna88k/luna88k/isr.h>
! 66:
! 67: /*
! 68: * LANCE registers.
! 69: * The real stuff is in dev/ic/am7990reg.h
! 70: */
! 71: struct lereg1 {
! 72: volatile u_int16_t ler1_rdp; /* data port */
! 73: volatile unsigned : 16 ; /* LUNA-88K2 has a 16 bit gap */
! 74: volatile u_int16_t ler1_rap; /* register select port */
! 75: };
! 76:
! 77: /*
! 78: * Ethernet software status per interface.
! 79: * The real stuff is in dev/ic/am7990var.h
! 80: */
! 81: struct le_softc {
! 82: struct am7990_softc sc_am7990; /* glue to MI code */
! 83:
! 84: struct lereg1 *sc_r1; /* LANCE registers */
! 85: };
! 86:
! 87: static int le_match(struct device *, void *, void *);
! 88: static void le_attach(struct device *, struct device *, void *);
! 89:
! 90: struct cfattach le_ca = {
! 91: sizeof(struct le_softc), le_match, le_attach
! 92: };
! 93:
! 94: hide void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
! 95: hide u_int16_t lerdcsr(struct am7990_softc *, u_int16_t);
! 96: hide void myetheraddr(u_int8_t *);
! 97:
! 98: hide void
! 99: lewrcsr(sc, port, val)
! 100: struct am7990_softc *sc;
! 101: u_int16_t port, val;
! 102: {
! 103: register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
! 104:
! 105: ler1->ler1_rap = port;
! 106: ler1->ler1_rdp = val;
! 107: }
! 108:
! 109: hide u_int16_t
! 110: lerdcsr(sc, port)
! 111: struct am7990_softc *sc;
! 112: u_int16_t port;
! 113: {
! 114: register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
! 115: u_int16_t val;
! 116:
! 117: ler1->ler1_rap = port;
! 118: val = ler1->ler1_rdp;
! 119: return (val);
! 120: }
! 121:
! 122: static int
! 123: le_match(parent, cf, aux)
! 124: struct device *parent;
! 125: void *cf, *aux;
! 126: {
! 127: struct mainbus_attach_args *ma = aux;
! 128:
! 129: if (strcmp(ma->ma_name, le_cd.cd_name))
! 130: return (0);
! 131:
! 132: return (1);
! 133: }
! 134:
! 135: void
! 136: le_attach(parent, self, aux)
! 137: struct device *parent, *self;
! 138: void *aux;
! 139: {
! 140: struct le_softc *lesc = (struct le_softc *)self;
! 141: struct am7990_softc *sc = &lesc->sc_am7990;
! 142: struct mainbus_attach_args *ma = aux;
! 143:
! 144: lesc->sc_r1 = (struct lereg1 *)ma->ma_addr; /* LANCE */
! 145:
! 146: sc->sc_mem = (void *)0x71000000; /* SRAM */
! 147: sc->sc_conf3 = LE_C3_BSWP;
! 148: sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
! 149: sc->sc_memsize = 64 * 1024; /* 64KB */
! 150:
! 151: myetheraddr(sc->sc_arpcom.ac_enaddr);
! 152:
! 153: sc->sc_copytodesc = am7990_copytobuf_contig;
! 154: sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
! 155: sc->sc_copytobuf = am7990_copytobuf_contig;
! 156: sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
! 157: sc->sc_zerobuf = am7990_zerobuf_contig;
! 158:
! 159: sc->sc_rdcsr = lerdcsr;
! 160: sc->sc_wrcsr = lewrcsr;
! 161: sc->sc_hwreset = NULL;
! 162: sc->sc_hwinit = NULL;
! 163:
! 164: am7990_config(sc);
! 165:
! 166: isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET,
! 167: self->dv_xname);
! 168: }
! 169:
! 170: /*
! 171: * Partially taken from NetBSD/luna68k
! 172: *
! 173: * LUNA-88K has FUSE ROM, which contains MAC address. The FUSE ROM
! 174: * contents are stored in fuse_rom_data[] during cpu_startup().
! 175: *
! 176: * LUNA-88K2 has 16Kbit NVSRAM on its ethercard, whose contents are
! 177: * accessible 4bit-wise by ctl register operation. The register is
! 178: * mapped at 0xF1000008.
! 179: */
! 180:
! 181: extern int machtype;
! 182: extern char fuse_rom_data[];
! 183:
! 184: hide void
! 185: myetheraddr(ether)
! 186: u_int8_t *ether;
! 187: {
! 188: unsigned i, loc;
! 189: volatile struct { u_int32_t ctl; } *ds1220;
! 190:
! 191: switch (machtype) {
! 192: case LUNA_88K:
! 193: /*
! 194: * fuse_rom_data[] begins with "ENADDR=00000Axxxxxx"
! 195: */
! 196: loc = 7;
! 197: for (i = 0; i < 6; i++) {
! 198: int u, l;
! 199:
! 200: u = fuse_rom_data[loc];
! 201: u = (u < 'A') ? u & 0xf : u - 'A' + 10;
! 202: l = fuse_rom_data[loc + 1];
! 203: l = (l < 'A') ? l & 0xf : l - 'A' + 10;
! 204:
! 205: ether[i] = l | (u << 4);
! 206: loc += 2;
! 207: }
! 208: break;
! 209: case LUNA_88K2:
! 210: ds1220 = (void *)0xF1000008;
! 211: loc = 12;
! 212: for (i = 0; i < 6; i++) {
! 213: unsigned u, l, hex;
! 214:
! 215: ds1220->ctl = (loc) << 16;
! 216: u = 0xf0 & (ds1220->ctl >> 12);
! 217: ds1220->ctl = (loc + 1) << 16;
! 218: l = 0x0f & (ds1220->ctl >> 16);
! 219: hex = (u < '9') ? l : l + 9;
! 220:
! 221: ds1220->ctl = (loc + 2) << 16;
! 222: u = 0xf0 & (ds1220->ctl >> 12);
! 223: ds1220->ctl = (loc + 3) << 16;
! 224: l = 0x0f & (ds1220->ctl >> 16);
! 225:
! 226: ether[i] = ((u < '9') ? l : l + 9) | (hex << 4);
! 227: loc += 4;
! 228: }
! 229: break;
! 230: default:
! 231: ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a;
! 232: ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00;
! 233: break;
! 234: }
! 235: }
CVSweb