Annotation of sys/arch/aviion/dev/if_le_vme.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_le_vme.c,v 1.1.1.1 2006/05/09 18:24:32 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/bus.h>
! 53: #include <machine/cpu.h>
! 54:
! 55: #include <dev/ic/am7990reg.h>
! 56: #include <dev/ic/am7990var.h>
! 57:
! 58: #include <aviion/dev/if_le_vmereg.h>
! 59: #include <aviion/dev/vmevar.h>
! 60:
! 61: struct le_softc {
! 62: struct am7990_softc sc_am7990; /* glue to MI code */
! 63:
! 64: bus_space_tag_t sc_memt; /* dual-ported memory access */
! 65: bus_space_handle_t sc_memh;
! 66:
! 67: bus_space_tag_t sc_iot; /* short io access */
! 68: bus_space_handle_t sc_ioh;
! 69:
! 70: struct intrhand sc_ih; /* interrupt vectoring */
! 71: u_int sc_csr; /* CSR image */
! 72: u_int sc_ipl;
! 73: u_int sc_vec;
! 74: };
! 75:
! 76: void le_vme_attach(struct device *, struct device *, void *);
! 77: int le_vme_match(struct device *, void *, void *);
! 78:
! 79: struct cfattach le_vme_ca = {
! 80: sizeof(struct le_softc), le_vme_match, le_vme_attach
! 81: };
! 82:
! 83: void le_vme_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
! 84: u_int16_t le_vme_rdcsr(struct am7990_softc *, u_int16_t);
! 85: void nvram_cmd(struct am7990_softc *, u_int, u_int);
! 86: u_int16_t nvram_read(struct am7990_softc *, u_int);
! 87: void le_vme_etheraddr(struct am7990_softc *);
! 88: void le_vme_init(struct am7990_softc *);
! 89: void le_vme_reset(struct am7990_softc *);
! 90: int le_vme_intr(void *);
! 91: #if 0
! 92: void le_vme_copyfrombuf_contig(struct am7990_softc *, void *, int, int);
! 93: void le_vme_copytobuf_contig(struct am7990_softc *, void *, int, int);
! 94: void le_vme_zerobuf_contig(struct am7990_softc *, int, int);
! 95: #endif
! 96:
! 97: /* send command to the nvram controller */
! 98: void
! 99: nvram_cmd(sc, cmd, addr)
! 100: struct am7990_softc *sc;
! 101: u_int cmd;
! 102: u_int addr;
! 103: {
! 104: struct le_softc *lesc = (void *)sc;
! 105: int i;
! 106:
! 107: for (i = 0; i < 8; i++) {
! 108: bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LEREG_EAR,
! 109: (cmd | (addr << 1)) >> i);
! 110: CDELAY;
! 111: }
! 112: }
! 113:
! 114: /* read nvram one bit at a time */
! 115: u_int16_t
! 116: nvram_read(sc, nvram_addr)
! 117: struct am7990_softc *sc;
! 118: u_int nvram_addr;
! 119: {
! 120: struct le_softc *lesc = (void *)sc;
! 121: u_int val = 0, mask = 0x04000;
! 122: u_int16_t wbit;
! 123:
! 124: lesc->sc_csr = HW_RS | NVRAM_EN | 0x07;
! 125: ENABLE_NVRAM;
! 126: nvram_cmd(sc, NVRAM_RCL, 0);
! 127: DISABLE_NVRAM;
! 128: CDELAY;
! 129: ENABLE_NVRAM;
! 130: nvram_cmd(sc, NVRAM_READ, nvram_addr);
! 131: for (wbit = 0; wbit < 15; wbit++) {
! 132: if (bus_space_read_2(lesc->sc_iot, lesc->sc_ioh,
! 133: LEREG_EAR) & 0x01)
! 134: val |= mask;
! 135: else
! 136: val &= ~mask;
! 137: mask = mask >> 1;
! 138: CDELAY;
! 139: }
! 140: if (bus_space_read_2(lesc->sc_iot, lesc->sc_ioh, LEREG_EAR) & 0x01)
! 141: val |= 0x8000;
! 142: else
! 143: val &= 0x7fff;
! 144: CDELAY;
! 145: DISABLE_NVRAM;
! 146: return (val);
! 147: }
! 148:
! 149: void
! 150: le_vme_etheraddr(sc)
! 151: struct am7990_softc *sc;
! 152: {
! 153: u_char *cp = sc->sc_arpcom.ac_enaddr;
! 154: u_int16_t ival[3];
! 155: int i;
! 156:
! 157: for (i = 0; i < 3; i++) {
! 158: ival[i] = nvram_read(sc, i);
! 159: }
! 160: memcpy(cp, &ival[0], 6);
! 161: }
! 162:
! 163: void
! 164: le_vme_wrcsr(sc, port, val)
! 165: struct am7990_softc *sc;
! 166: u_int16_t port, val;
! 167: {
! 168: struct le_softc *lesc = (void *)sc;
! 169:
! 170: bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LEREG_RAP, port);
! 171: bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LEREG_RDP, val);
! 172: }
! 173:
! 174: u_int16_t
! 175: le_vme_rdcsr(sc, port)
! 176: struct am7990_softc *sc;
! 177: u_int16_t port;
! 178: {
! 179: struct le_softc *lesc = (void *)sc;
! 180:
! 181: bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LEREG_RAP, port);
! 182: return (bus_space_read_2(lesc->sc_iot, lesc->sc_ioh, LEREG_RDP));
! 183: }
! 184:
! 185: /* init board, set ipl and vec */
! 186: void
! 187: le_vme_init(sc)
! 188: struct am7990_softc *sc;
! 189: {
! 190: struct le_softc *lesc = (void *)sc;
! 191:
! 192: lesc->sc_csr = 0x4f;
! 193: WRITE_CSR_AND(lesc->sc_ipl);
! 194: SET_VEC(lesc->sc_vec);
! 195: return;
! 196: }
! 197:
! 198: /* board reset */
! 199: void
! 200: le_vme_reset(sc)
! 201: struct am7990_softc *sc;
! 202: {
! 203: struct le_softc *lesc = (void *)sc;
! 204:
! 205: RESET_HW;
! 206: #ifdef LEDEBUG
! 207: if (sc->sc_debug)
! 208: printf("%s: hardware reset\n", sc->sc_dev.dv_xname);
! 209: #endif
! 210: SYSFAIL_CL;
! 211: }
! 212:
! 213: int
! 214: le_vme_intr(sc)
! 215: void *sc;
! 216: {
! 217: struct le_softc *lesc = (void *)sc;
! 218: int rc;
! 219:
! 220: rc = am7990_intr(sc);
! 221: ENABLE_INTR;
! 222: return (rc);
! 223: }
! 224:
! 225: #if 0
! 226: void
! 227: le_vme_copytobuf_contig(sc, from, boff, len)
! 228: struct am7990_softc *sc;
! 229: void *from;
! 230: int boff, len;
! 231: {
! 232: struct le_softc *lesc = (void *)sc;
! 233:
! 234: bus_space_write_region_1(lesc->sc_memt, lesc->sc_memh, boff, from, len);
! 235: }
! 236:
! 237: void
! 238: le_vme_copyfrombuf_contig(sc, to, boff, len)
! 239: struct am7990_softc *sc;
! 240: void *to;
! 241: int boff, len;
! 242: {
! 243: struct le_softc *lesc = (void *)sc;
! 244:
! 245: bus_space_read_region_1(lesc->sc_memt, lesc->sc_memh, boff, to, len);
! 246: }
! 247:
! 248: void
! 249: le_vme_zerobuf_contig(sc, boff, len)
! 250: struct am7990_softc *sc;
! 251: int boff, len;
! 252: {
! 253: struct le_softc *lesc = (void *)sc;
! 254:
! 255: bus_space_set_region_1(lesc->sc_memt, lesc->sc_memh, boff, 0, len);
! 256: }
! 257: #endif
! 258:
! 259: int
! 260: le_vme_match(parent, vcf, args)
! 261: struct device *parent;
! 262: void *vcf, *args;
! 263: {
! 264: struct vme_attach_args *vaa = args;
! 265: bus_space_tag_t iot, memt;
! 266: bus_space_handle_t ioh;
! 267: int rc;
! 268:
! 269: /* we expect a32 and a16 locators */
! 270: if (vaa->vaa_addr_a16 == (vme_addr_t)-1 ||
! 271: vaa->vaa_addr_a32 == (vme_addr_t)-1)
! 272: return (0);
! 273:
! 274: /* check the dual ported memory */
! 275: if (vmebus_get_bst(parent, VME_A32, VME_D32, &memt) != 0)
! 276: return (0);
! 277: if (bus_space_map(memt, vaa->vaa_addr_a32, PAGE_SIZE, 0, &ioh) != 0)
! 278: return (0);
! 279: rc = badaddr((vaddr_t)bus_space_vaddr(memt, ioh), 2);
! 280: bus_space_unmap(memt, ioh, PAGE_SIZE);
! 281: vmebus_release_bst(parent, memt);
! 282:
! 283: /* check the control space */
! 284: if (vmebus_get_bst(parent, VME_A16, VME_D16, &iot) != 0)
! 285: return (0);
! 286: if (bus_space_map(iot, vaa->vaa_addr_a16, PAGE_SIZE, 0, &ioh) != 0)
! 287: return (0);
! 288: rc |= badaddr((vaddr_t)bus_space_vaddr(iot, ioh), 2);
! 289: bus_space_unmap(iot, ioh, PAGE_SIZE);
! 290: vmebus_release_bst(parent, iot);
! 291:
! 292: return (rc == 0);
! 293: }
! 294:
! 295: void
! 296: le_vme_attach(parent, self, aux)
! 297: struct device *parent;
! 298: struct device *self;
! 299: void *aux;
! 300: {
! 301: struct le_softc *lesc = (struct le_softc *)self;
! 302: struct am7990_softc *sc = &lesc->sc_am7990;
! 303: struct vme_attach_args *vaa = aux;
! 304:
! 305: /*
! 306: * Allocate an interrupt vector.
! 307: */
! 308: if (vmeintr_allocate(1, VMEINTR_ANY, &lesc->sc_vec) != 0) {
! 309: printf(": no more interrupts!\n");
! 310: return;
! 311: }
! 312: lesc->sc_ipl = vaa->vaa_ipl == 0 ? IPL_NET : vaa->vaa_ipl;
! 313:
! 314: /*
! 315: * Map the dual-ported memory.
! 316: */
! 317: if (vmebus_get_bst(parent, VME_A32, VME_D32, &lesc->sc_memt) != 0) {
! 318: printf(": can't map memory\n");
! 319: return;
! 320: }
! 321: if (bus_space_map(lesc->sc_memt, vaa->vaa_addr_a32, VLEMEMSIZE,
! 322: BUS_SPACE_MAP_LINEAR, &lesc->sc_memh) != 0) {
! 323: printf(": can't map memory\n");
! 324: goto fail3;
! 325: }
! 326:
! 327: /*
! 328: * Map the control space.
! 329: */
! 330: if (vmebus_get_bst(parent, VME_A16, VME_D16, &lesc->sc_iot) != 0) {
! 331: printf(": can't map registers\n");
! 332: goto fail2;
! 333: }
! 334: if (bus_space_map(lesc->sc_iot, vaa->vaa_addr_a16, PAGE_SIZE,
! 335: 0, &lesc->sc_ioh) != 0) {
! 336: printf(": can't map registers\n");
! 337: goto fail1;
! 338: }
! 339:
! 340: sc->sc_mem = (void *)bus_space_vaddr(lesc->sc_memt, lesc->sc_memh);
! 341: sc->sc_memsize = VLEMEMSIZE;
! 342: sc->sc_addr = vaa->vaa_addr_a32 & 0x00ffffff;
! 343: sc->sc_conf3 = LE_C3_BSWP;
! 344: sc->sc_hwreset = le_vme_reset;
! 345: sc->sc_rdcsr = le_vme_rdcsr;
! 346: sc->sc_wrcsr = le_vme_wrcsr;
! 347: sc->sc_hwinit = le_vme_init;
! 348: #if 0
! 349: sc->sc_copytodesc = le_vme_copytobuf_contig;
! 350: sc->sc_copyfromdesc = le_vme_copyfrombuf_contig;
! 351: sc->sc_copytobuf = le_vme_copytobuf_contig;
! 352: sc->sc_copyfrombuf = le_vme_copyfrombuf_contig;
! 353: sc->sc_zerobuf = le_vme_zerobuf_contig;
! 354: #else
! 355: sc->sc_copytodesc = am7990_copytobuf_contig;
! 356: sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
! 357: sc->sc_copytobuf = am7990_copytobuf_contig;
! 358: sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
! 359: sc->sc_zerobuf = am7990_zerobuf_contig;
! 360: #endif
! 361:
! 362: /* get Ethernet address */
! 363: le_vme_etheraddr(sc);
! 364:
! 365: am7990_config(sc);
! 366:
! 367: /* connect the interrupt */
! 368: lesc->sc_ih.ih_fn = le_vme_intr;
! 369: lesc->sc_ih.ih_arg = sc;
! 370: lesc->sc_ih.ih_wantframe = 0;
! 371: lesc->sc_ih.ih_ipl = lesc->sc_ipl;
! 372: vmeintr_establish(lesc->sc_vec, &lesc->sc_ih, self->dv_xname);
! 373:
! 374: return;
! 375:
! 376: fail1:
! 377: vmebus_release_bst(parent, lesc->sc_iot);
! 378: fail2:
! 379: bus_space_unmap(lesc->sc_memt, lesc->sc_memh, VLEMEMSIZE);
! 380: fail3:
! 381: vmebus_release_bst(parent, lesc->sc_memt);
! 382: }
CVSweb