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

Annotation of sys/arch/hp300/dev/if_le.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: if_le.c,v 1.17 2005/01/15 21:13:08 miod Exp $ */
                      2: /*     $NetBSD: if_le.c,v 1.43 1997/05/05 21:05:32 thorpej Exp $       */
                      3:
                      4: /*-
                      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. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  *
                     36:  *     @(#)if_le.c     8.2 (Berkeley) 11/16/93
                     37:  */
                     38:
                     39: #include "bpfilter.h"
                     40:
                     41: #include <sys/param.h>
                     42: #include <sys/systm.h>
                     43: #include <sys/mbuf.h>
                     44: #include <sys/syslog.h>
                     45: #include <sys/socket.h>
                     46: #include <sys/device.h>
                     47:
                     48: #include <net/if.h>
                     49:
                     50: #ifdef INET
                     51: #include <netinet/in.h>
                     52: #include <netinet/if_ether.h>
                     53: #endif
                     54:
                     55: #include <net/if_media.h>
                     56:
                     57: #include <machine/autoconf.h>
                     58: #include <machine/cpu.h>
                     59: #include <machine/intr.h>
                     60:
                     61: #include <dev/ic/am7990reg.h>
                     62: #include <dev/ic/am7990var.h>
                     63:
                     64: #include <hp300/dev/dioreg.h>
                     65: #include <hp300/dev/diovar.h>
                     66: #include <hp300/dev/diodevs.h>
                     67: #include <hp300/dev/if_lereg.h>
                     68: #include <hp300/dev/if_levar.h>
                     69:
                     70: #ifdef USELEDS
                     71: #include <hp300/hp300/leds.h>
                     72: #endif
                     73:
                     74: int    lematch(struct device *, void *, void *);
                     75: void   leattach(struct device *, struct device *, void *);
                     76:
                     77: struct cfattach le_ca = {
                     78:        sizeof(struct le_softc), lematch, leattach
                     79: };
                     80:
                     81: int    leintr(void *);
                     82:
                     83: /* offsets for:           ID,   REGS,    MEM,  NVRAM */
                     84: int    lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
                     85:
                     86: hide void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
                     87: hide u_int16_t lerdcsr(struct am7990_softc *, u_int16_t);
                     88:
                     89: hide void
                     90: lewrcsr(sc, port, val)
                     91:        struct am7990_softc *sc;
                     92:        u_int16_t port, val;
                     93: {
                     94:        struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
                     95:        struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
                     96:
                     97:        do {
                     98:                ler1->ler1_rap = port;
                     99:        } while ((ler0->ler0_status & LE_ACK) == 0);
                    100:        do {
                    101:                ler1->ler1_rdp = val;
                    102:        } while ((ler0->ler0_status & LE_ACK) == 0);
                    103: }
                    104:
                    105: hide u_int16_t
                    106: lerdcsr(sc, port)
                    107:        struct am7990_softc *sc;
                    108:        u_int16_t port;
                    109: {
                    110:        struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
                    111:        struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
                    112:        u_int16_t val;
                    113:
                    114:        do {
                    115:                ler1->ler1_rap = port;
                    116:        } while ((ler0->ler0_status & LE_ACK) == 0);
                    117:        do {
                    118:                val = ler1->ler1_rdp;
                    119:        } while ((ler0->ler0_status & LE_ACK) == 0);
                    120:        return (val);
                    121: }
                    122:
                    123: int
                    124: lematch(parent, match, aux)
                    125:        struct device *parent;
                    126:        void *match, *aux;
                    127: {
                    128:        struct dio_attach_args *da = aux;
                    129:
                    130:        if ((da->da_id == DIO_DEVICE_ID_LAN) ||
                    131:            (da->da_id == DIO_DEVICE_ID_LANREM))
                    132:                return (1);
                    133:        return (0);
                    134: }
                    135:
                    136: /*
                    137:  * Interface exists: make available by filling in network interface
                    138:  * record.  System will initialize the interface when it is ready
                    139:  * to accept packets.
                    140:  */
                    141: void
                    142: leattach(parent, self, aux)
                    143:        struct device *parent, *self;
                    144:        void *aux;
                    145: {
                    146:        struct lereg0 *ler0;
                    147:        struct dio_attach_args *da = aux;
                    148:        struct le_softc *lesc = (struct le_softc *)self;
                    149:        caddr_t addr;
                    150:        struct am7990_softc *sc = &lesc->sc_am7990;
                    151:        char *cp;
                    152:        int i, ipl;
                    153:
                    154:        addr = iomap(dio_scodetopa(da->da_scode), da->da_size);
                    155:        if (addr == 0) {
                    156:                printf("\n%s: can't map LANCE registers\n",
                    157:                    sc->sc_dev.dv_xname);
                    158:                return;
                    159:        }
                    160:
                    161:        ler0 = lesc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)addr);
                    162:        ler0->ler0_id = 0xFF;
                    163:        DELAY(100);
                    164:
                    165:        ipl = DIO_IPL(addr);
                    166:        printf(" ipl %d", ipl);
                    167:
                    168:        lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)addr);
                    169:        sc->sc_mem = (void *)(lestd[2] + (int)addr);
                    170:        sc->sc_conf3 = LE_C3_BSWP;
                    171:        sc->sc_addr = 0;
                    172:        sc->sc_memsize = 16384;
                    173:
                    174:        /*
                    175:         * Read the ethernet address off the board, one nibble at a time.
                    176:         */
                    177:        cp = (char *)(lestd[3] + (int)addr);
                    178:        for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
                    179:                sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
                    180:                cp++;
                    181:                sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
                    182:                cp++;
                    183:        }
                    184:
                    185:        sc->sc_copytodesc = am7990_copytobuf_contig;
                    186:        sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
                    187:        sc->sc_copytobuf = am7990_copytobuf_contig;
                    188:        sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
                    189:        sc->sc_zerobuf = am7990_zerobuf_contig;
                    190:
                    191:        sc->sc_rdcsr = lerdcsr;
                    192:        sc->sc_wrcsr = lewrcsr;
                    193:        sc->sc_hwreset = NULL;
                    194:        sc->sc_hwinit = NULL;
                    195:
                    196:        am7990_config(sc);
                    197:
                    198:        /* Establish the interrupt handler. */
                    199:        lesc->sc_isr.isr_func = leintr;
                    200:        lesc->sc_isr.isr_arg = lesc;
                    201:        lesc->sc_isr.isr_ipl = ipl;
                    202:        lesc->sc_isr.isr_priority = IPL_NET;
                    203:        dio_intr_establish(&lesc->sc_isr, self->dv_xname);
                    204:        ler0->ler0_status = LE_IE;
                    205: }
                    206:
                    207: int
                    208: leintr(arg)
                    209:        void *arg;
                    210: {
                    211:        struct le_softc *lesc = (struct le_softc *)arg;
                    212:        struct am7990_softc *sc = &lesc->sc_am7990;
                    213: #ifdef USELEDS
                    214:        u_int16_t isr;
                    215:
                    216:        isr = lerdcsr(sc, LE_CSR0);
                    217:
                    218:        if ((isr & LE_C0_INTR) == 0)
                    219:                return (0);
                    220:
                    221:        if (isr & LE_C0_RINT)
                    222:                ledcontrol(0, 0, LED_LANRCV);
                    223:
                    224:        if (isr & LE_C0_TINT)
                    225:                ledcontrol(0, 0, LED_LANXMT);
                    226: #endif /* USELEDS */
                    227:
                    228:        return am7990_intr(sc);
                    229: }

CVSweb