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

Annotation of sys/arch/mac68k/dev/if_sn_obio.c, Revision 1.1

1.1     ! nbrk        1: /*    $OpenBSD: if_sn_obio.c,v 1.23 2006/03/23 04:17:23 brad Exp $    */
        !             2: /*    $NetBSD: if_sn_obio.c,v 1.9 1997/04/22 20:56:15 scottr Exp $    */
        !             3:
        !             4: /*
        !             5:  * Copyright (C) 1997 Allen Briggs
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. All advertising materials mentioning features or use of this software
        !            17:  *    must display the following acknowledgement:
        !            18:  *      This product includes software developed by Allen Briggs
        !            19:  * 4. The name of the author may not be used to endorse or promote products
        !            20:  *    derived from this software without specific prior written permission.
        !            21:  *
        !            22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            25:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            26:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            27:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            28:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            29:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            30:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            31:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            32:  */
        !            33:
        !            34: #include <sys/param.h>
        !            35: #include <sys/device.h>
        !            36: #include <sys/errno.h>
        !            37: #include <sys/ioctl.h>
        !            38: #include <sys/socket.h>
        !            39: #include <sys/syslog.h>
        !            40: #include <sys/systm.h>
        !            41:
        !            42: #include <uvm/uvm_extern.h>
        !            43:
        !            44: #include <net/if.h>
        !            45: #include <netinet/in.h>
        !            46: #include <netinet/if_ether.h>
        !            47:
        !            48: #include <machine/bus.h>
        !            49: #include <machine/cpu.h>
        !            50: #include <machine/viareg.h>
        !            51:
        !            52: #include <mac68k/dev/obiovar.h>
        !            53: #include <mac68k/dev/if_snreg.h>
        !            54: #include <mac68k/dev/if_snvar.h>
        !            55:
        !            56: #define SONIC_REG_BASE 0x50F0A000
        !            57: #define SONIC_PROM_BASE        0x50F08000
        !            58:
        !            59: static int     sn_obio_match(struct device *, void *, void *);
        !            60: static void    sn_obio_attach(struct device *, struct device *, void *);
        !            61: static int     sn_obio_getaddr(struct sn_softc *, u_int8_t *);
        !            62: static int     sn_obio_getaddr_kludge(struct sn_softc *, u_int8_t *);
        !            63:
        !            64: struct cfattach sn_obio_ca = {
        !            65:        sizeof(struct sn_softc), sn_obio_match, sn_obio_attach
        !            66: };
        !            67:
        !            68: static int
        !            69: sn_obio_match(struct device *parent, void *cf, void *aux)
        !            70: {
        !            71:        struct obio_attach_args *oa = (struct obio_attach_args *)aux;
        !            72:        bus_space_handle_t bsh;
        !            73:        int found = 0;
        !            74:
        !            75:        if (!mac68k_machine.sonic)
        !            76:                return 0;
        !            77:
        !            78:        if (bus_space_map(oa->oa_tag,
        !            79:            SONIC_REG_BASE, SN_REGSIZE, 0, &bsh))
        !            80:                return 0;
        !            81:
        !            82:        if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0, 4))
        !            83:                found = 1;
        !            84:
        !            85:        bus_space_unmap(oa->oa_tag, bsh, SN_REGSIZE);
        !            86:
        !            87:        return found;
        !            88: }
        !            89:
        !            90: /*
        !            91:  * Install interface into kernel networking data structures
        !            92:  */
        !            93: static void
        !            94: sn_obio_attach(struct device *parent, struct device *self, void *aux)
        !            95: {
        !            96:        struct obio_attach_args *oa = (struct obio_attach_args *)aux;
        !            97:        struct sn_softc *sc = (void *)self;
        !            98:        u_int8_t myaddr[ETHER_ADDR_LEN];
        !            99:        int i;
        !           100:
        !           101:        sc->snr_dcr = DCR_WAIT0 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
        !           102:        sc->snr_dcr2 = 0;
        !           103:
        !           104:        sc->slotno = 9;
        !           105:
        !           106:        switch (current_mac_model->machineid) {
        !           107:        case MACH_MACC610:
        !           108:        case MACH_MACC650:
        !           109:        case MACH_MACQ610:
        !           110:        case MACH_MACQ650:
        !           111:        case MACH_MACQ700:
        !           112:        case MACH_MACQ800:
        !           113:        case MACH_MACQ900:
        !           114:        case MACH_MACQ950:
        !           115:                sc->snr_dcr |= DCR_EXBUS;
        !           116:                sc->bitmode = 1;
        !           117:                break;
        !           118:
        !           119:        case MACH_MACLC575:
        !           120:        case MACH_MACP580:
        !           121:        case MACH_MACQ630:
        !           122:                break;
        !           123:
        !           124:        case MACH_MACPB500:
        !           125:                sc->snr_dcr |= DCR_SYNC | DCR_LBR;
        !           126:                sc->bitmode = 0;        /* 16 bit interface */
        !           127:                break;
        !           128:
        !           129:        default:
        !           130:                printf(": unsupported machine type\n");
        !           131:                return;
        !           132:        }
        !           133:
        !           134:        sc->sc_regt = oa->oa_tag;
        !           135:
        !           136:        if (bus_space_map(sc->sc_regt,
        !           137:            SONIC_REG_BASE, SN_REGSIZE, 0, &sc->sc_regh)) {
        !           138:                printf(": failed to map space for SONIC regs.\n");
        !           139:                return;
        !           140:        }
        !           141:
        !           142:        /* regs are addressed as words, big-endian. */
        !           143:        for (i = 0; i < SN_NREGS; i++) {
        !           144:                sc->sc_reg_map[i] = (bus_size_t)((i * 4) + 2);
        !           145:        }
        !           146:
        !           147:        /*
        !           148:         * Kind of kludge this.  Comm-slot cards do not really
        !           149:         * have a visible type, as far as I can tell at this time,
        !           150:         * so assume that MacOS had it properly configured and use
        !           151:         * that configuration.
        !           152:         */
        !           153:        switch (current_mac_model->machineid) {
        !           154:        case MACH_MACLC575:
        !           155:        case MACH_MACP580:
        !           156:        case MACH_MACQ630:
        !           157:                NIC_PUT(sc, SNR_CR, CR_RST);    wbflush();
        !           158:                i = NIC_GET(sc, SNR_DCR);
        !           159:                sc->snr_dcr |= (i & 0xfff0);
        !           160:                sc->bitmode = (i & DCR_DW) ? 1 : 0;
        !           161:                break;
        !           162:        default:
        !           163:                break;
        !           164:        }
        !           165:
        !           166:        if (sn_obio_getaddr(sc, myaddr) &&
        !           167:            sn_obio_getaddr_kludge(sc, myaddr)) { /* XXX kludge for PB */
        !           168:                printf(": failed to get MAC address.\n");
        !           169:                bus_space_unmap(sc->sc_regt, sc->sc_regh, SN_REGSIZE);
        !           170:                return;
        !           171:        }
        !           172:
        !           173:        printf(": integrated ethernet adapter, ");
        !           174:
        !           175:        /* snsetup returns 1 if something fails */
        !           176:        if (snsetup(sc, myaddr)) {
        !           177:                bus_space_unmap(sc->sc_regt, sc->sc_regh, SN_REGSIZE);
        !           178:                return;
        !           179:        }
        !           180:
        !           181:        if (mac68k_machine.aux_interrupts)
        !           182:                intr_establish(snintr, sc, 3, sc->sc_dev.dv_xname);
        !           183:        else
        !           184:                add_nubus_intr(sc->slotno, snintr, sc, sc->sc_dev.dv_xname);
        !           185: }
        !           186:
        !           187: static int
        !           188: sn_obio_getaddr(struct sn_softc *sc, u_int8_t *lladdr)
        !           189: {
        !           190:        bus_space_handle_t bsh;
        !           191:
        !           192:        if (bus_space_map(sc->sc_regt, SONIC_PROM_BASE, PAGE_SIZE, 0, &bsh)) {
        !           193:                printf(": failed to map space to read SONIC address.\n%s",
        !           194:                    sc->sc_dev.dv_xname);
        !           195:                return (-1);
        !           196:        }
        !           197:
        !           198:        if (!mac68k_bus_space_probe(sc->sc_regt, bsh, 0, 1)) {
        !           199:                bus_space_unmap(sc->sc_regt, bsh, PAGE_SIZE);
        !           200:                return (-1);
        !           201:        }
        !           202:
        !           203:        sn_get_enaddr(sc->sc_regt, bsh, 0, lladdr);
        !           204:
        !           205:        bus_space_unmap(sc->sc_regt, bsh, PAGE_SIZE);
        !           206:
        !           207:        return (0);
        !           208: }
        !           209:
        !           210: /*
        !           211:  * Assume that the SONIC was initialized in MacOS.  This should go away
        !           212:  * when we can properly get the MAC address on the PBs.
        !           213:  */
        !           214: static int
        !           215: sn_obio_getaddr_kludge(struct sn_softc *sc, u_int8_t *lladdr)
        !           216: {
        !           217:        int i, ors = 0;
        !           218:
        !           219:        /* Shut down NIC */
        !           220:        NIC_PUT(sc, SNR_CR, CR_RST);
        !           221:        wbflush();
        !           222:
        !           223:        NIC_PUT(sc, SNR_CEP, 15); /* For some reason, Apple fills top first. */
        !           224:        wbflush();
        !           225:        i = NIC_GET(sc, SNR_CAP2);
        !           226:        wbflush();
        !           227:
        !           228:        ors |= i;
        !           229:        lladdr[5] = i >> 8;
        !           230:        lladdr[4] = i;
        !           231:
        !           232:        i = NIC_GET(sc, SNR_CAP1);
        !           233:        wbflush();
        !           234:
        !           235:        ors |= i;
        !           236:        lladdr[3] = i >> 8;
        !           237:        lladdr[2] = i;
        !           238:
        !           239:        i = NIC_GET(sc, SNR_CAP0);
        !           240:        wbflush();
        !           241:
        !           242:        ors |= i;
        !           243:        lladdr[1] = i >> 8;
        !           244:        lladdr[0] = i;
        !           245:
        !           246:        NIC_PUT(sc, SNR_CR, 0);
        !           247:        wbflush();
        !           248:
        !           249:        if (ors == 0)
        !           250:                return (-1);
        !           251:
        !           252:        return (0);
        !           253: }

CVSweb