[BACK]Return to if_le.c CVS log [TXT][DIR] Up to [local] / sys / arch / vax / if

Annotation of sys/arch/vax/if/if_le.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: if_le.c,v 1.13 2005/07/02 09:28:40 miod Exp $ */
                      2: /*     $NetBSD: if_le.c,v 1.14 1999/08/14 18:40:23 ragge Exp $ */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
                     10:  * Simulation Facility, NASA Ames Research Center.
                     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 NetBSD
                     23:  *       Foundation, Inc. and its contributors.
                     24:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     25:  *    contributors may be used to endorse or promote products derived
                     26:  *    from this software without specific prior written permission.
                     27:  *
                     28:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     29:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     30:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     31:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     32:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     33:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     34:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     35:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     36:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     37:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     38:  * POSSIBILITY OF SUCH DAMAGE.
                     39:  */
                     40:
                     41: /*-
                     42:  * Copyright (c) 1992, 1993
                     43:  *     The Regents of the University of California.  All rights reserved.
                     44:  *
                     45:  * This code is derived from software contributed to Berkeley by
                     46:  * Ralph Campbell and Rick Macklem.
                     47:  *
                     48:  * Redistribution and use in source and binary forms, with or without
                     49:  * modification, are permitted provided that the following conditions
                     50:  * are met:
                     51:  * 1. Redistributions of source code must retain the above copyright
                     52:  *    notice, this list of conditions and the following disclaimer.
                     53:  * 2. Redistributions in binary form must reproduce the above copyright
                     54:  *    notice, this list of conditions and the following disclaimer in the
                     55:  *    documentation and/or other materials provided with the distribution.
                     56:  * 3. Neither the name of the University nor the names of its contributors
                     57:  *    may be used to endorse or promote products derived from this software
                     58:  *    without specific prior written permission.
                     59:  *
                     60:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     61:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     62:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     63:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     64:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     65:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     66:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     67:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     68:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     69:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     70:  * SUCH DAMAGE.
                     71:  *
                     72:  *     @(#)if_le.c     8.2 (Berkeley) 11/16/93
                     73:  */
                     74:
                     75: #include "bpfilter.h"
                     76:
                     77: #include <sys/param.h>
                     78: #include <sys/syslog.h>
                     79: #include <sys/socket.h>
                     80: #include <sys/device.h>
                     81: #include <sys/reboot.h>
                     82:
                     83: #include <uvm/uvm_extern.h>
                     84:
                     85: #include <net/if.h>
                     86: #include <net/if_media.h>
                     87:
                     88: #if INET
                     89: #include <netinet/in.h>
                     90: #endif
                     91: #include <netinet/if_ether.h>
                     92:
                     93: #include <machine/cpu.h>
                     94: #include <machine/nexus.h>
                     95: #include <machine/rpb.h>
                     96: #include <machine/scb.h>
                     97:
                     98: #include <dev/ic/am7990reg.h>
                     99: #include <dev/ic/am7990var.h>
                    100:
                    101: #define ETHER_MIN_LEN   64      /* minimum frame length, including CRC */
                    102: #define        LEVEC   0xd4    /* Interrupt vector on 3300/3400 */
                    103:
                    104: struct le_softc {
                    105:        struct  am7990_softc sc_am7990; /* Must be first */
                    106:        struct  evcount sc_intrcnt;
                    107:        int     sc_vec;
                    108:        volatile u_short *sc_rap;
                    109:        volatile u_short *sc_rdp;
                    110: };
                    111:
                    112: int    le_ibus_match(struct device *, void *, void *);
                    113: void   le_ibus_attach(struct device *, struct device *, void *);
                    114: void   lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
                    115: u_int16_t lerdcsr(struct am7990_softc *, u_int16_t);
                    116: void   lance_copytobuf_gap2(struct am7990_softc *, void *, int, int);
                    117: void   lance_copyfrombuf_gap2(struct am7990_softc *, void *, int, int);
                    118: void   lance_zerobuf_gap2(struct am7990_softc *, int, int);
                    119:
                    120: struct cfattach le_ibus_ca = {
                    121:        sizeof(struct le_softc), le_ibus_match, le_ibus_attach
                    122: };
                    123:
                    124: void
                    125: lewrcsr(ls, port, val)
                    126:        struct am7990_softc *ls;
                    127:        u_int16_t port, val;
                    128: {
                    129:        struct le_softc *sc = (void *)ls;
                    130:
                    131:        *sc->sc_rap = port;
                    132:        *sc->sc_rdp = val;
                    133: }
                    134:
                    135: u_int16_t
                    136: lerdcsr(ls, port)
                    137:        struct am7990_softc *ls;
                    138:        u_int16_t port;
                    139: {
                    140:        struct le_softc *sc = (void *)ls;
                    141:
                    142:        *sc->sc_rap = port;
                    143:        return *sc->sc_rdp;
                    144: }
                    145:
                    146: int
                    147: le_ibus_match(parent, cf, aux)
                    148:        struct device *parent;
                    149:        void *cf;
                    150:        void *aux;
                    151: {
                    152:        struct bp_conf *bp = aux;
                    153:
                    154:        if (strcmp("lance", bp->type))
                    155:                return 0;
                    156:        return 1;
                    157: }
                    158:
                    159: void
                    160: le_ibus_attach(parent, self, aux)
                    161:        struct device *parent, *self;
                    162:        void *aux;
                    163: {
                    164:        struct le_softc *sc = (void *)self;
                    165:        int *lance_addr;
                    166:        int i, br;
                    167:
                    168:        sc->sc_rdp = (short *)vax_map_physmem(0x20084400, 1);
                    169:        sc->sc_rap = sc->sc_rdp + 2;
                    170:
                    171:        /*
                    172:         * Set interrupt vector, by forcing an interrupt.
                    173:         */
                    174:        scb_vecref(0, 0); /* Clear vector ref */
                    175:        *sc->sc_rap = LE_CSR0;
                    176:        *sc->sc_rdp = LE_C0_STOP;
                    177:        DELAY(100);
                    178:        *sc->sc_rdp = LE_C0_INIT|LE_C0_INEA;
                    179:        DELAY(100000);
                    180:        i = scb_vecref(&sc->sc_vec, &br);
                    181:        if (i == 0 || sc->sc_vec == 0)
                    182:                return;
                    183:        scb_vecalloc(sc->sc_vec, (void *)am7990_intr, sc,
                    184:             SCB_ISTACK, &sc->sc_intrcnt);
                    185:        evcount_attach(&sc->sc_intrcnt, self->dv_xname,
                    186:            (void *)&sc->sc_vec, &evcount_intr);
                    187:
                    188:        printf(": vec %d ipl %x\n%s", sc->sc_vec, br, self->dv_xname);
                    189:        /*
                    190:         * MD functions.
                    191:         */
                    192:        sc->sc_am7990.sc_rdcsr = lerdcsr;
                    193:        sc->sc_am7990.sc_wrcsr = lewrcsr;
                    194:        sc->sc_am7990.sc_nocarrier = NULL;
                    195:
                    196:        sc->sc_am7990.sc_mem =
                    197:            (void *)uvm_km_valloc(kernel_map, (128 * 1024));
                    198:        if (sc->sc_am7990.sc_mem == 0)
                    199:                return;
                    200:
                    201:        ioaccess((vaddr_t)sc->sc_am7990.sc_mem, 0x20120000,
                    202:            (128 * 1024) >> VAX_PGSHIFT);
                    203:
                    204:
                    205:        sc->sc_am7990.sc_addr = 0;
                    206:        sc->sc_am7990.sc_memsize = (64 * 1024);
                    207:
                    208:        sc->sc_am7990.sc_copytodesc = lance_copytobuf_gap2;
                    209:        sc->sc_am7990.sc_copyfromdesc = lance_copyfrombuf_gap2;
                    210:        sc->sc_am7990.sc_copytobuf = lance_copytobuf_gap2;
                    211:        sc->sc_am7990.sc_copyfrombuf = lance_copyfrombuf_gap2;
                    212:        sc->sc_am7990.sc_zerobuf = lance_zerobuf_gap2;
                    213:
                    214:        /*
                    215:         * Get the ethernet address out of rom
                    216:         */
                    217:        lance_addr = (int *)vax_map_physmem(0x20084200, 1);
                    218:        for (i = 0; i < 6; i++)
                    219:                sc->sc_am7990.sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i];
                    220:        vax_unmap_physmem((vaddr_t)lance_addr, 1);
                    221:
                    222:        bcopy(self->dv_xname, sc->sc_am7990.sc_arpcom.ac_if.if_xname,
                    223:            IFNAMSIZ);
                    224:        am7990_config(&sc->sc_am7990);
                    225: }
                    226:
                    227: /*
                    228:  * gap2: two bytes of data followed by two bytes of pad.
                    229:  *
                    230:  * Buffers must be 4-byte aligned.  The code doesn't worry about
                    231:  * doing an extra byte.
                    232:  */
                    233:
                    234: void
                    235: lance_copytobuf_gap2(sc, fromv, boff, len)
                    236:        struct am7990_softc *sc;
                    237:        void *fromv;
                    238:        int boff;
                    239:        register int len;
                    240: {
                    241:        volatile caddr_t buf = sc->sc_mem;
                    242:        register caddr_t from = fromv;
                    243:        register volatile u_int16_t *bptr;
                    244:
                    245:        if (boff & 0x1) {
                    246:                /* handle unaligned first byte */
                    247:                bptr = ((volatile u_int16_t *)buf) + (boff - 1);
                    248:                *bptr = (*from++ << 8) | (*bptr & 0xff);
                    249:                bptr += 2;
                    250:                len--;
                    251:        } else
                    252:                bptr = ((volatile u_int16_t *)buf) + boff;
                    253:        while (len > 1) {
                    254:                *bptr = (from[1] << 8) | (from[0] & 0xff);
                    255:                bptr += 2;
                    256:                from += 2;
                    257:                len -= 2;
                    258:        }
                    259:        if (len == 1)
                    260:                *bptr = (u_int16_t)*from;
                    261: }
                    262:
                    263: void
                    264: lance_copyfrombuf_gap2(sc, tov, boff, len)
                    265:        struct am7990_softc *sc;
                    266:        void *tov;
                    267:        int boff, len;
                    268: {
                    269:        volatile caddr_t buf = sc->sc_mem;
                    270:        register caddr_t to = tov;
                    271:        register volatile u_int16_t *bptr;
                    272:        register u_int16_t tmp;
                    273:
                    274:        if (boff & 0x1) {
                    275:                /* handle unaligned first byte */
                    276:                bptr = ((volatile u_int16_t *)buf) + (boff - 1);
                    277:                *to++ = (*bptr >> 8) & 0xff;
                    278:                bptr += 2;
                    279:                len--;
                    280:        } else
                    281:                bptr = ((volatile u_int16_t *)buf) + boff;
                    282:        while (len > 1) {
                    283:                tmp = *bptr;
                    284:                *to++ = tmp & 0xff;
                    285:                *to++ = (tmp >> 8) & 0xff;
                    286:                bptr += 2;
                    287:                len -= 2;
                    288:        }
                    289:        if (len == 1)
                    290:                *to = *bptr & 0xff;
                    291: }
                    292:
                    293: void
                    294: lance_zerobuf_gap2(sc, boff, len)
                    295:        struct am7990_softc *sc;
                    296:        int boff, len;
                    297: {
                    298:        volatile caddr_t buf = sc->sc_mem;
                    299:        register volatile u_int16_t *bptr;
                    300:
                    301:        if ((unsigned)boff & 0x1) {
                    302:                bptr = ((volatile u_int16_t *)buf) + (boff - 1);
                    303:                *bptr &= 0xff;
                    304:                bptr += 2;
                    305:                len--;
                    306:        } else
                    307:                bptr = ((volatile u_int16_t *)buf) + boff;
                    308:        while (len > 0) {
                    309:                *bptr = 0;
                    310:                bptr += 2;
                    311:                len -= 2;
                    312:        }
                    313: }

CVSweb