Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.18
      1 /*	$NetBSD: if_sn_nubus.c,v 1.18 1998/05/02 16:45:30 scottr Exp $	*/
      2 
      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 #include <net/if_ether.h>
     43 
     44 #if 0 /* XXX this shouldn't be necessary; else reinsert */
     45 #ifdef INET
     46 #include <netinet/in.h>
     47 #include <netinet/if_inarp.h>
     48 #endif
     49 #endif
     50 
     51 #include <machine/bus.h>
     52 #include <machine/viareg.h>
     53 
     54 #include <mac68k/nubus/nubus.h>
     55 #include <mac68k/dev/if_snreg.h>
     56 #include <mac68k/dev/if_snvar.h>
     57 
     58 static int	sn_nubus_match __P((struct device *, struct cfdata *, void *));
     59 static void	sn_nubus_attach __P((struct device *, struct device *, void *));
     60 static int	sn_nb_card_vendor __P((bus_space_tag_t, bus_space_handle_t,
     61 		    struct nubus_attach_args *));
     62 
     63 struct cfattach sn_nubus_ca = {
     64 	sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
     65 };
     66 
     67 
     68 static int
     69 sn_nubus_match(parent, cf, aux)
     70 	struct device *parent;
     71 	struct cfdata *cf;
     72 	void *aux;
     73 {
     74 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
     75 	bus_space_handle_t bsh;
     76 	int rv;
     77 
     78 	if (bus_space_map(na->na_tag,
     79 	    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
     80 		return (0);
     81 
     82 	rv = 0;
     83 
     84 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     85 	    na->type == NUBUS_TYPE_ETHERNET) {
     86 		switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
     87 		default:
     88 			break;
     89 
     90 		case SN_VENDOR_APPLE:
     91 		case SN_VENDOR_APPLE16:
     92 		case SN_VENDOR_DAYNA:
     93 			rv = 1;
     94 			break;
     95 		}
     96 	}
     97 
     98 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
     99 
    100 	return rv;
    101 }
    102 
    103 /*
    104  * Install interface into kernel networking data structures
    105  */
    106 static void
    107 sn_nubus_attach(parent, self, aux)
    108 	struct device *parent, *self;
    109 	void   *aux;
    110 {
    111 	struct sn_softc *sc = (void *)self;
    112 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    113 	int i, success, offset;
    114 	bus_space_tag_t	bst;
    115 	bus_space_handle_t bsh, tmp_bsh;
    116 	u_int8_t myaddr[ETHER_ADDR_LEN];
    117 
    118 	(void)(&offset);	/* Work around lame gcc initialization bug */
    119 
    120 	bst = na->na_tag;
    121 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    122 		printf(": failed to map memory space.\n");
    123 		return;
    124 	}
    125 
    126 	sc->sc_regt = bst;
    127 
    128 	success = 0;
    129 
    130 	sc->slotno = na->slot;
    131 
    132 	switch (sn_nb_card_vendor(bst, bsh, na)) {
    133 	case SN_VENDOR_DAYNA:
    134 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
    135 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    136 		sc->snr_dcr2 = 0;
    137 		sc->bitmode = 1;	/* 32 bit card */
    138 
    139 		if (bus_space_subregion(bst, bsh,
    140 		    0x00180000, SN_REGSIZE, &sc->sc_regh)) {
    141 			printf(": failed to map register space.\n");
    142 			break;
    143 		}
    144 
    145 		if (bus_space_subregion(bst, bsh,
    146 		    0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
    147 			printf(": failed to map ROM space.\n");
    148 			break;
    149 		}
    150 
    151 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    152 
    153 		offset = 2;
    154 		success = 1;
    155 		break;
    156 
    157 	case SN_VENDOR_APPLE:
    158 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
    159 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    160 		sc->snr_dcr2 = 0;
    161 		sc->bitmode = 1; /* 32 bit card */
    162 
    163 		if (bus_space_subregion(bst, bsh,
    164 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    165 			printf(": failed to map register space.\n");
    166 			break;
    167 		}
    168 
    169 		if (bus_space_subregion(bst, bsh,
    170 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    171 			printf(": failed to map ROM space.\n");
    172 			break;
    173 		}
    174 
    175 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    176 
    177 		offset = 0;
    178 		success = 1;
    179 		break;
    180 
    181 	case SN_VENDOR_APPLE16:
    182 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
    183 		    DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
    184 		sc->snr_dcr2 = 0;
    185 		sc->bitmode = 0; /* 16 bit card */
    186 
    187 		if (bus_space_subregion(bst, bsh,
    188 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    189 			printf(": failed to map register space.\n");
    190 			break;
    191 		}
    192 
    193 		if (bus_space_subregion(bst, bsh,
    194 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    195 			printf(": failed to map ROM space.\n");
    196 			break;
    197 		}
    198 
    199 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    200 
    201 		offset = 0;
    202 		success = 1;
    203 		break;
    204 
    205 	default:
    206 		/*
    207 		 * You can't actually get this default, the snmatch
    208 		 * will fail for unknown hardware. If you're adding support
    209 		 * for a new card, the following defaults are a
    210 		 * good starting point.
    211 		 */
    212 		sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
    213 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    214 		sc->snr_dcr2 = 0;
    215 		success = 0;
    216 		printf(": unknown card: attachment incomplete.\n");
    217 	}
    218 
    219 	if (!success) {
    220 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    221 		return;
    222 	}
    223 
    224 	/* Regs are addressed as words, big endian. */
    225 	for (i = 0; i < SN_NREGS; i++) {
    226 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
    227 	}
    228 
    229 	/* snsetup returns 1 if something fails */
    230 	if (snsetup(sc, myaddr)) {
    231 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    232 		return;
    233 	}
    234 
    235 	add_nubus_intr(sc->slotno, snintr, (void *)sc);
    236 
    237 	return;
    238 }
    239 
    240 static int
    241 sn_nb_card_vendor(bst, bsh, na)
    242 	bus_space_tag_t bst;
    243 	bus_space_handle_t bsh;
    244 	struct nubus_attach_args *na;
    245 {
    246 	int vendor = SN_VENDOR_UNKNOWN;
    247 
    248 	switch (na->drsw) {
    249 	case NUBUS_DRSW_3COM:
    250 		if (na->drhw == NUBUS_DRHW_APPLE_SNT)
    251 			vendor = SN_VENDOR_APPLE;
    252 		else if (na->drhw == NUBUS_DRHW_APPLE_SN)
    253 			vendor = SN_VENDOR_APPLE16;
    254 		break;
    255 	case NUBUS_DRSW_APPLE:
    256 	case NUBUS_DRSW_TECHWORKS:
    257 		vendor = SN_VENDOR_APPLE;
    258 		break;
    259 	case NUBUS_DRSW_GATOR:
    260 		if (na->drhw == NUBUS_DRHW_KINETICS &&
    261 		    strncmp(nubus_get_card_name(bst, bsh, na->fmt),
    262 		    "EtherPort", 9) != 0)
    263 			vendor = SN_VENDOR_DAYNA;
    264 		break;
    265 	case NUBUS_DRSW_DAYNA:
    266 		vendor = SN_VENDOR_DAYNA;
    267 		break;
    268 	}
    269 
    270 	return vendor;
    271 }
    272