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

Annotation of sys/arch/mac68k/dev/if_sn_nubus.c, Revision 1.1.1.1

1.1       nbrk        1: /*    $OpenBSD: if_sn_nubus.c,v 1.18 2006/03/23 04:10:13 brad Exp $  */
                      2: /*    $NetBSD: if_sn_nubus.c,v 1.13 1997/05/11 19:11:34 scottr Exp $  */
                      3: /*
                      4:  * Copyright (C) 1997 Allen Briggs
                      5:  * 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. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *      This product includes software developed by Allen Briggs
                     18:  * 4. The name of the author may not be used to endorse or promote products
                     19:  *    derived from this software without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31:  */
                     32:
                     33: #include <sys/param.h>
                     34: #include <sys/device.h>
                     35: #include <sys/errno.h>
                     36: #include <sys/ioctl.h>
                     37: #include <sys/socket.h>
                     38: #include <sys/syslog.h>
                     39: #include <sys/systm.h>
                     40:
                     41: #include <net/if.h>
                     42:
                     43: #ifdef INET
                     44: #include <netinet/in.h>
                     45: #include <netinet/if_ether.h>
                     46: #endif
                     47:
                     48: #include <machine/bus.h>
                     49: #include <machine/viareg.h>
                     50:
                     51: #include <mac68k/dev/nubus.h>
                     52: #include <mac68k/dev/if_snreg.h>
                     53: #include <mac68k/dev/if_snvar.h>
                     54:
                     55: #define        INTERFACE_NAME_LEN      32
                     56:
                     57: static int     sn_nubus_match(struct device *, void *, void *);
                     58: static void    sn_nubus_attach(struct device *, struct device *, void *);
                     59: static int     sn_nb_card_vendor(bus_space_tag_t, bus_space_handle_t,
                     60:                    struct nubus_attach_args *);
                     61:
                     62: struct cfattach sn_nubus_ca = {
                     63:        sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
                     64: };
                     65:
                     66:
                     67: static int
                     68: sn_nubus_match(struct device *parent, void *cf, void *aux)
                     69: {
                     70:        struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
                     71:        bus_space_handle_t bsh;
                     72:        int rv;
                     73:
                     74:        if (bus_space_map(na->na_tag,
                     75:            NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
                     76:                return (0);
                     77:
                     78:        rv = 0;
                     79:
                     80:        if (na->category == NUBUS_CATEGORY_NETWORK &&
                     81:            na->type == NUBUS_TYPE_ETHERNET) {
                     82:                switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
                     83:                default:
                     84:                        break;
                     85:
                     86:                case SN_VENDOR_APPLE:
                     87:                case SN_VENDOR_APPLE16:
                     88:                case SN_VENDOR_ASANTELC:
                     89:                case SN_VENDOR_DAYNA:
                     90:                        rv = 1;
                     91:                        break;
                     92:                }
                     93:        }
                     94:
                     95:        bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
                     96:
                     97:        return (rv);
                     98: }
                     99:
                    100: /*
                    101:  * Install interface into kernel networking data structures
                    102:  */
                    103: static void
                    104: sn_nubus_attach(struct device *parent, struct device *self, void *aux)
                    105: {
                    106:        struct sn_softc *sc = (void *)self;
                    107:        struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
                    108:        int i, success, offset;
                    109:        bus_space_tag_t bst;
                    110:        bus_space_handle_t bsh, tmp_bsh;
                    111:        u_int8_t myaddr[ETHER_ADDR_LEN];
                    112:        char cardtype[INTERFACE_NAME_LEN];      /* type string */
                    113:
                    114:        (void)(&offset);        /* Work around lame gcc initialization bug */
                    115:
                    116:        bst = na->na_tag;
                    117:        if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
                    118:                printf(": failed to map memory space.\n");
                    119:                return;
                    120:        }
                    121:
                    122:        sc->sc_regt = bst;
                    123:
                    124:        strncpy(cardtype, nubus_get_card_name(bst, bsh, na->fmt),
                    125:            INTERFACE_NAME_LEN);
                    126:
                    127:        success = 0;
                    128:
                    129:        sc->slotno = na->slot;
                    130:
                    131:        switch (sn_nb_card_vendor(bst, bsh, na)) {
                    132:        case SN_VENDOR_DAYNA:
                    133:                sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
                    134:                    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
                    135:                sc->snr_dcr2 = 0;
                    136:                sc->bitmode = 1;        /* 32 bit card */
                    137:
                    138:                if (bus_space_subregion(bst, bsh,
                    139:                    0x00180000, SN_REGSIZE, &sc->sc_regh)) {
                    140:                        printf(": failed to map register space.\n");
                    141:                        break;
                    142:                }
                    143:
                    144:                if (bus_space_subregion(bst, bsh,
                    145:                    0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
                    146:                        printf(": failed to map ROM space.\n");
                    147:                        break;
                    148:                }
                    149:
                    150:                sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
                    151:
                    152:                offset = 2;
                    153:                success = 1;
                    154:                break;
                    155:
                    156:        case SN_VENDOR_APPLE:
                    157:                sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
                    158:                    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
                    159:                sc->snr_dcr2 = 0;
                    160:                sc->bitmode = 1; /* 32 bit card */
                    161:
                    162:                if (bus_space_subregion(bst, bsh,
                    163:                    0x0, SN_REGSIZE, &sc->sc_regh)) {
                    164:                        printf(": failed to map register space.\n");
                    165:                        break;
                    166:                }
                    167:
                    168:                if (bus_space_subregion(bst, bsh,
                    169:                    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
                    170:                        printf(": failed to map ROM space.\n");
                    171:                        break;
                    172:                }
                    173:
                    174:                sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
                    175:
                    176:                offset = 0;
                    177:                success = 1;
                    178:                break;
                    179:
                    180:        case SN_VENDOR_APPLE16:
                    181:                sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
                    182:                        DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
                    183:                sc->snr_dcr2 = 0;
                    184:                sc->bitmode = 0; /* 16 bit card */
                    185:
                    186:                if (bus_space_subregion(bst, bsh,
                    187:                    0x0, SN_REGSIZE, &sc->sc_regh)) {
                    188:                        printf(": failed to map register space.\n");
                    189:                        break;
                    190:                }
                    191:
                    192:                if (bus_space_subregion(bst, bsh,
                    193:                    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
                    194:                        printf(": failed to map ROM space.\n");
                    195:                        break;
                    196:                }
                    197:
                    198:                sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
                    199:
                    200:                offset = 0;
                    201:                success = 1;
                    202:                break;
                    203:
                    204:        case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
                    205:                sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
                    206:                        DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
                    207:                sc->snr_dcr2 = 0;
                    208:                sc->bitmode = 0; /* 16 bit card */
                    209:
                    210:                if (bus_space_subregion(bst, bsh,
                    211:                    0x0, SN_REGSIZE, &sc->sc_regh)) {
                    212:                        printf(": failed to map register space.\n");
                    213:                        break;
                    214:                }
                    215:
                    216:                if (bus_space_subregion(bst, bsh,
                    217:                    0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
                    218:                        printf(": failed to map ROM space.\n");
                    219:                        break;
                    220:                }
                    221:
                    222:                sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
                    223:
                    224:                offset = 0;
                    225:                success = 1;
                    226:                break;
                    227:
                    228:        default:
                    229:                /*
                    230:                 * You can't actually get this default, the snmatch
                    231:                 * will fail for unknown hardware. If you're adding support
                    232:                 * for a new card, the following defaults are a
                    233:                 * good starting point.
                    234:                 */
                    235:                sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
                    236:                    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
                    237:                sc->snr_dcr2 = 0;
                    238:                success = 0;
                    239:                printf(": unknown card: attachment incomplete.\n");
                    240:        }
                    241:
                    242:        if (!success) {
                    243:                bus_space_unmap(bst, bsh, NBMEMSIZE);
                    244:                return;
                    245:        }
                    246:
                    247:        /* Regs are addressed as words, big endian. */
                    248:        for (i = 0; i < SN_NREGS; i++) {
                    249:                sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
                    250:        }
                    251:
                    252:        printf(": %s, ", cardtype);
                    253:
                    254:        /* snsetup returns 1 if something fails */
                    255:        if (snsetup(sc, myaddr)) {
                    256:                bus_space_unmap(bst, bsh, NBMEMSIZE);
                    257:                return;
                    258:        }
                    259:
                    260:        add_nubus_intr(sc->slotno, snintr, sc, sc->sc_dev.dv_xname);
                    261: }
                    262:
                    263: static int
                    264: sn_nb_card_vendor(bus_space_tag_t bst, bus_space_handle_t bsh,
                    265:     struct nubus_attach_args *na)
                    266: {
                    267:        int vendor = SN_VENDOR_UNKNOWN;
                    268:
                    269:        switch (na->drsw) {
                    270:        case NUBUS_DRSW_3COM:
                    271:                if (na->drhw == NUBUS_DRHW_APPLE_SNT)
                    272:                        vendor = SN_VENDOR_APPLE;
                    273:                else if (na->drhw == NUBUS_DRHW_APPLE_SN)
                    274:                        vendor = SN_VENDOR_APPLE16;
                    275:                break;
                    276:        case NUBUS_DRSW_APPLE:
                    277:                if (na->drhw == NUBUS_DRHW_ASANTE_LC)
                    278:                        vendor = SN_VENDOR_ASANTELC;
                    279:                else
                    280:                        vendor = SN_VENDOR_APPLE;
                    281:                break;
                    282:        case NUBUS_DRSW_TECHWORKS:
                    283:                vendor = SN_VENDOR_APPLE;
                    284:                break;
                    285:        case NUBUS_DRSW_GATOR:
                    286:                if (na->drhw == NUBUS_DRHW_KINETICS &&
                    287:                    strncmp(nubus_get_card_name(bst, bsh, na->fmt),
                    288:                    "EtherPort", 9) != 0)
                    289:                        vendor = SN_VENDOR_DAYNA;
                    290:                break;
                    291:        case NUBUS_DRSW_DAYNA:
                    292:                vendor = SN_VENDOR_DAYNA;
                    293:                break;
                    294:        }
                    295:
                    296:        return (vendor);
                    297: }

CVSweb