Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.8
      1 /*	$NetBSD: if_sn_nubus.c,v 1.8 1997/04/22 03:04:33 briggs 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 "nubus.h"
     55 #include "if_aereg.h"	/* For AE_VENDOR values */
     56 #include "if_snreg.h"
     57 #include "if_snvar.h"
     58 
     59 static int	sn_nubus_match __P((struct device *, struct cfdata *, void *));
     60 static void	sn_nubus_attach __P((struct device *, struct device *, void *));
     61 static int	sn_nb_card_vendor __P((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, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
     79 	    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)) {
     87 		default:
     88 			break;
     89 
     90 		case AE_VENDOR_APPLE:
     91 		case AE_VENDOR_DAYNA:
     92 			rv = 1;
     93 			break;
     94 		}
     95 	}
     96 
     97 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
     98 
     99 	return rv;
    100 }
    101 
    102 /*
    103  * Install interface into kernel networking data structures
    104  */
    105 static void
    106 sn_nubus_attach(parent, self, aux)
    107 	struct device *parent, *self;
    108 	void   *aux;
    109 {
    110         struct sn_softc *sc = (void *)self;
    111         struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    112 	int		i, success, offset;
    113 	bus_space_tag_t	bst;
    114 	bus_space_handle_t	bsh, tmp_bsh;
    115 	u_int8_t myaddr[ETHER_ADDR_LEN];
    116 
    117 	bst = na->na_tag;
    118 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    119 		printf(": failed to map memory space.\n");
    120 		return;
    121 	}
    122 
    123 	sc->sc_regt = bst;
    124 	sc->bitmode = 1;
    125 
    126 	success = 0;
    127 
    128         sc->bitmode = 1;		/* 32-bit card */
    129         sc->slotno = na->slot;
    130 
    131         switch (sn_nb_card_vendor(na)) {
    132 	case AE_VENDOR_DAYNA:
    133                 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
    134 			DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    135 		sc->snr_dcr2 = 0;
    136 
    137 		if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
    138 					&sc->sc_regh)) {
    139 			printf(": failed to map register space.\n");
    140 			break;
    141 		}
    142 
    143 		if (bus_space_subregion(bst, bsh, 0x00ffe004, ETHER_ADDR_LEN,
    144 					&tmp_bsh)) {
    145 			printf(": failed to map ROM space.\n");
    146 			break;
    147 		}
    148 
    149 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    150 
    151 		offset = 2;
    152 		success = 1;
    153                 break;
    154 
    155 	case AE_VENDOR_APPLE:
    156                 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
    157 			DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    158 		sc->snr_dcr2 = 0;
    159 
    160 		if (bus_space_subregion(bst, bsh, 0x0, SN_REGSIZE,
    161 					&sc->sc_regh)) {
    162 			printf(": failed to map register space.\n");
    163 			break;
    164 		}
    165 
    166 		if (bus_space_subregion(bst, bsh, 0x40000, ETHER_ADDR_LEN,
    167 					&tmp_bsh)) {
    168 			printf(": failed to map ROM space.\n");
    169 			break;
    170 		}
    171 
    172 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    173 
    174 		offset = 0;
    175 		success = 1;
    176                 break;
    177 
    178         default:
    179                 /*
    180                  * You can't actually get this default, the snmatch
    181                  * will fail for unknown hardware. If you're adding support
    182                  * for a new card, the following defaults are a
    183                  * good starting point.
    184                  */
    185                 sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
    186 			DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    187 		sc->snr_dcr2 = 0;
    188 		printf(": attachment incomplete.\n");
    189 		offset = 0;
    190 		success = 0;
    191                 return;
    192         }
    193 
    194 	if (!success) {
    195 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    196 		return;
    197 	}
    198 
    199 	/* Regs are addressed as words, big endian. */
    200 	for (i = 0; i < SN_NREGS; i++) {
    201 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
    202 	}
    203 
    204 	/* snsetup returns 1 if something fails */
    205 	if (snsetup(sc, myaddr)) {
    206 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    207 		return;
    208 	}
    209 
    210 	add_nubus_intr(sc->slotno, snintr, (void *)sc);
    211 
    212 	return;
    213 }
    214 
    215 static int
    216 sn_nb_card_vendor(na)
    217 	struct nubus_attach_args *na;
    218 {
    219 	int vendor;
    220 
    221 	switch (na->drsw) {
    222 	case NUBUS_DRSW_3COM:
    223 		switch (na->drhw) {
    224 		case NUBUS_DRHW_APPLE_SN:
    225 			vendor = AE_VENDOR_APPLE;
    226 			break;
    227 		default:
    228 			vendor = AE_VENDOR_UNKNOWN;
    229 			break;
    230 		}
    231 		break;
    232 	case NUBUS_DRSW_APPLE:
    233 	case NUBUS_DRSW_TECHWORKS:
    234 		vendor = AE_VENDOR_APPLE;
    235 		break;
    236 	case NUBUS_DRSW_ASANTE:
    237 		vendor = AE_VENDOR_ASANTE;
    238 		break;
    239 	case NUBUS_DRSW_FARALLON:
    240 		vendor = AE_VENDOR_FARALLON;
    241 		break;
    242 	case NUBUS_DRSW_FOCUS:
    243 		vendor = AE_VENDOR_FOCUS;
    244 		break;
    245 	case NUBUS_DRSW_GATOR:
    246 		switch (na->drhw) {
    247 		default:
    248 		case NUBUS_DRHW_INTERLAN:
    249 			vendor = AE_VENDOR_INTERLAN;
    250 			break;
    251 		case NUBUS_DRHW_KINETICS:
    252 			if (strncmp(
    253 			    nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
    254 				vendor = AE_VENDOR_KINETICS;
    255 			else
    256 				vendor = AE_VENDOR_DAYNA;
    257 			break;
    258 		}
    259 		break;
    260 	case NUBUS_DRSW_DAYNA:
    261 		vendor = AE_VENDOR_DAYNA;
    262 		break;
    263 	default:
    264 #ifdef DIAGNOSTIC
    265 		printf("Unknown ethernet drsw: %x\n", na->drsw);
    266 #endif
    267 		vendor = AE_VENDOR_UNKNOWN;
    268 	}
    269 	return vendor;
    270 }
    271