Annotation of sys/arch/mvme88k/dev/if_le.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_le.c,v 1.15 2006/05/08 14:36:10 miod Exp $ */
! 2:
! 3: /*-
! 4: * Copyright (c) 1982, 1992, 1993
! 5: * The Regents of the University of California. All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: * 3. Neither the name of the University nor the names of its contributors
! 16: * may be used to endorse or promote products derived from this software
! 17: * without specific prior written permission.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 29: * SUCH DAMAGE.
! 30: *
! 31: * @(#)if_le.c 8.2 (Berkeley) 10/30/93
! 32: */
! 33:
! 34: #include <sys/param.h>
! 35: #include <sys/systm.h>
! 36: #include <sys/mbuf.h>
! 37: #include <sys/syslog.h>
! 38: #include <sys/socket.h>
! 39: #include <sys/device.h>
! 40: #include <sys/malloc.h>
! 41:
! 42: #include <net/if.h>
! 43:
! 44: #ifdef INET
! 45: #include <netinet/in.h>
! 46: #include <netinet/if_ether.h>
! 47: #endif
! 48:
! 49: #include <net/if_media.h>
! 50:
! 51: #include <machine/autoconf.h>
! 52: #include <machine/cpu.h>
! 53:
! 54: #include <dev/ic/am7990reg.h>
! 55: #include <dev/ic/am7990var.h>
! 56:
! 57: #include <mvme88k/dev/if_lereg.h>
! 58: #include <mvme88k/dev/if_levar.h>
! 59: #include <mvme88k/dev/vme.h>
! 60:
! 61: /* autoconfiguration driver */
! 62: void leattach(struct device *, struct device *, void *);
! 63: int lematch(struct device *, void *, void *);
! 64:
! 65: struct cfattach le_ca = {
! 66: sizeof(struct le_softc), lematch, leattach
! 67: };
! 68:
! 69: void vlewrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
! 70: u_int16_t vlerdcsr(struct am7990_softc *, u_int16_t);
! 71: void nvram_cmd(struct am7990_softc *, u_char, u_short);
! 72: u_int16_t nvram_read(struct am7990_softc *, u_char);
! 73: void vleetheraddr(struct am7990_softc *);
! 74: void vleinit(struct am7990_softc *);
! 75: void vlereset(struct am7990_softc *);
! 76: int vle_intr(void *);
! 77:
! 78: /* send command to the nvram controller */
! 79: void
! 80: nvram_cmd(sc, cmd, addr)
! 81: struct am7990_softc *sc;
! 82: u_char cmd;
! 83: u_short addr;
! 84: {
! 85: struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 86: int i;
! 87:
! 88: for (i = 0; i < 8; i++) {
! 89: reg1->ler1_ear = ((cmd | (addr << 1)) >> i);
! 90: CDELAY;
! 91: }
! 92: }
! 93:
! 94: /* read nvram one bit at a time */
! 95: u_int16_t
! 96: nvram_read(sc, nvram_addr)
! 97: struct am7990_softc *sc;
! 98: u_char nvram_addr;
! 99: {
! 100: u_short val = 0, mask = 0x04000;
! 101: u_int16_t wbit;
! 102: struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 103:
! 104: ((struct le_softc *)sc)->sc_csr = 0x4f;
! 105: ENABLE_NVRAM;
! 106: nvram_cmd(sc, NVRAM_RCL, 0);
! 107: DISABLE_NVRAM;
! 108: CDELAY;
! 109: ENABLE_NVRAM;
! 110: nvram_cmd(sc, NVRAM_READ, nvram_addr);
! 111: for (wbit = 0; wbit < 15; wbit++) {
! 112: if (reg1->ler1_ear & 0x01)
! 113: val |= mask;
! 114: else
! 115: val &= ~mask;
! 116: mask = mask >> 1;
! 117: CDELAY;
! 118: }
! 119: if (reg1->ler1_ear & 0x01)
! 120: val |= 0x8000;
! 121: else
! 122: val &= 0x7fff;
! 123: CDELAY;
! 124: DISABLE_NVRAM;
! 125: return (val);
! 126: }
! 127:
! 128: void
! 129: vleetheraddr(sc)
! 130: struct am7990_softc *sc;
! 131: {
! 132: u_char *cp = sc->sc_arpcom.ac_enaddr;
! 133: u_int16_t ival[3];
! 134: int i;
! 135:
! 136: for (i = 0; i < 3; i++) {
! 137: ival[i] = nvram_read(sc, i);
! 138: }
! 139: memcpy(cp, &ival[0], 6);
! 140: }
! 141:
! 142: void
! 143: vlewrcsr(sc, port, val)
! 144: struct am7990_softc *sc;
! 145: u_int16_t port, val;
! 146: {
! 147: struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 148:
! 149: ler1->ler1_rap = port;
! 150: ler1->ler1_rdp = val;
! 151: }
! 152:
! 153: u_int16_t
! 154: vlerdcsr(sc, port)
! 155: struct am7990_softc *sc;
! 156: u_int16_t port;
! 157: {
! 158: struct vlereg1 *ler1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 159: u_int16_t val;
! 160:
! 161: ler1->ler1_rap = port;
! 162: val = ler1->ler1_rdp;
! 163: return (val);
! 164: }
! 165:
! 166: /* init MVME376, set ipl and vec */
! 167: void
! 168: vleinit(sc)
! 169: struct am7990_softc *sc;
! 170: {
! 171: struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 172: u_char vec = ((struct le_softc *)sc)->sc_vec;
! 173: u_char ipl = ((struct le_softc *)sc)->sc_ipl;
! 174:
! 175: ((struct le_softc *)sc)->sc_csr = 0x4f;
! 176: WRITE_CSR_AND(ipl);
! 177: SET_VEC(vec);
! 178: return;
! 179: }
! 180:
! 181: /* MVME376 hardware reset */
! 182: void
! 183: vlereset(sc)
! 184: struct am7990_softc *sc;
! 185: {
! 186: struct vlereg1 *reg1 = (struct vlereg1 *)((struct le_softc *)sc)->sc_r1;
! 187:
! 188: RESET_HW;
! 189: #ifdef LEDEBUG
! 190: if (sc->sc_debug) {
! 191: printf("%s: hardware reset\n", sc->sc_dev.dv_xname);
! 192: }
! 193: #endif
! 194: SYSFAIL_CL;
! 195: }
! 196:
! 197: int
! 198: vle_intr(sc)
! 199: void *sc;
! 200: {
! 201: struct le_softc *lesc = (struct le_softc *)sc;
! 202: struct vlereg1 *reg1 = (struct vlereg1 *)lesc->sc_r1;
! 203: int rc;
! 204:
! 205: rc = am7990_intr(sc);
! 206: ENABLE_INTR;
! 207: return (rc);
! 208: }
! 209:
! 210: int
! 211: lematch(parent, vcf, args)
! 212: struct device *parent;
! 213: void *vcf, *args;
! 214: {
! 215: struct confargs *ca = args;
! 216: bus_space_tag_t iot = ca->ca_iot;
! 217: bus_space_handle_t ioh;
! 218: int rc;
! 219:
! 220: if (bus_space_map(iot, ca->ca_paddr, PAGE_SIZE, 0, &ioh) != 0)
! 221: return 0;
! 222: rc = badaddr((vaddr_t)bus_space_vaddr(iot, ioh), 2);
! 223: bus_space_unmap(iot, ioh, PAGE_SIZE);
! 224:
! 225: return rc == 0;
! 226: }
! 227:
! 228: /*
! 229: * Interface exists: make available by filling in network interface
! 230: * record. System will initialize the interface when it is ready
! 231: * to accept packets.
! 232: */
! 233: void
! 234: leattach(parent, self, aux)
! 235: struct device *parent;
! 236: struct device *self;
! 237: void *aux;
! 238: {
! 239: struct le_softc *lesc = (struct le_softc *)self;
! 240: struct am7990_softc *sc = &lesc->sc_am7990;
! 241: struct confargs *ca = aux;
! 242: paddr_t paddr;
! 243: int card;
! 244: bus_space_tag_t iot = ca->ca_iot;
! 245: bus_space_handle_t ioh, memh;
! 246:
! 247: if (ca->ca_vec < 0) {
! 248: printf(": no more interrupts!\n");
! 249: return;
! 250: }
! 251: if (ca->ca_ipl < 0)
! 252: ca->ca_ipl = IPL_NET;
! 253:
! 254: /*
! 255: * get the first available etherbuf. MVME376 uses its own dual-ported
! 256: * RAM for etherbuf. It is set by dip switches on board. We support
! 257: * the six Motorola address locations, however, the board can be set up
! 258: * at any other address.
! 259: * XXX These physical addresses should be mapped in extio!!!
! 260: */
! 261: switch (ca->ca_paddr) {
! 262: case 0xffff1200:
! 263: card = 0;
! 264: break;
! 265: case 0xffff1400:
! 266: card = 1;
! 267: break;
! 268: case 0xffff1600:
! 269: card = 2;
! 270: break;
! 271: case 0xffff5400:
! 272: card = 3;
! 273: break;
! 274: case 0xffff5600:
! 275: card = 4;
! 276: break;
! 277: case 0xffffa400:
! 278: card = 5;
! 279: break;
! 280: default:
! 281: printf(": unsupported address\n");
! 282: return;
! 283: }
! 284:
! 285: if (bus_space_map(iot, ca->ca_paddr, PAGE_SIZE, 0, &ioh) != 0) {
! 286: printf(": can't map registers!\n");
! 287: return;
! 288: }
! 289:
! 290: paddr = VLEMEMBASE - (card * VLEMEMSIZE);
! 291: if (bus_space_map(iot, paddr, VLEMEMSIZE, BUS_SPACE_MAP_LINEAR,
! 292: &memh) != 0) {
! 293: printf(": can't map buffers!\n");
! 294: bus_space_unmap(iot, ioh, PAGE_SIZE);
! 295: return;
! 296: }
! 297: lesc->sc_r1 = (void *)bus_space_vaddr(iot, ioh);
! 298: lesc->sc_ipl = ca->ca_ipl;
! 299: lesc->sc_vec = ca->ca_vec;
! 300:
! 301: sc->sc_mem = (void *)bus_space_vaddr(iot, memh);
! 302: sc->sc_memsize = VLEMEMSIZE;
! 303: sc->sc_addr = paddr & 0x00ffffff;
! 304: sc->sc_conf3 = LE_C3_BSWP;
! 305: sc->sc_hwreset = vlereset;
! 306: sc->sc_rdcsr = vlerdcsr;
! 307: sc->sc_wrcsr = vlewrcsr;
! 308: sc->sc_hwinit = vleinit;
! 309: sc->sc_copytodesc = am7990_copytobuf_contig;
! 310: sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
! 311: sc->sc_copytobuf = am7990_copytobuf_contig;
! 312: sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
! 313: sc->sc_zerobuf = am7990_zerobuf_contig;
! 314:
! 315: /* get Ethernet address */
! 316: vleetheraddr(sc);
! 317:
! 318: am7990_config(sc);
! 319:
! 320: /* connect the interrupt */
! 321: lesc->sc_ih.ih_fn = vle_intr;
! 322: lesc->sc_ih.ih_arg = sc;
! 323: lesc->sc_ih.ih_wantframe = 0;
! 324: lesc->sc_ih.ih_ipl = ca->ca_ipl;
! 325: vmeintr_establish(ca->ca_vec, &lesc->sc_ih, self->dv_xname);
! 326: }
CVSweb