Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.7
      1 /*	$NetBSD: if_sn_nubus.c,v 1.7 1997/04/14 00:44:01 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                 return;
    190         }
    191 
    192 	if (!success) {
    193 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    194 		return;
    195 	}
    196 
    197 	/* Regs are addressed as words, big endian. */
    198 	for (i = 0; i < SN_NREGS; i++) {
    199 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
    200 	}
    201 
    202 	/* snsetup returns 1 if something fails */
    203 	if (snsetup(sc, myaddr)) {
    204 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    205 		return;
    206 	}
    207 
    208 	add_nubus_intr(sc->slotno, snintr, (void *)sc);
    209 
    210 	return;
    211 }
    212 
    213 static int
    214 sn_nb_card_vendor(na)
    215 	struct nubus_attach_args *na;
    216 {
    217 	int vendor;
    218 
    219 	switch (na->drsw) {
    220 	case NUBUS_DRSW_3COM:
    221 		switch (na->drhw) {
    222 		case NUBUS_DRHW_APPLE_SN:
    223 			vendor = AE_VENDOR_APPLE;
    224 			break;
    225 		default:
    226 			vendor = AE_VENDOR_UNKNOWN;
    227 			break;
    228 		}
    229 		break;
    230 	case NUBUS_DRSW_APPLE:
    231 	case NUBUS_DRSW_TECHWORKS:
    232 		vendor = AE_VENDOR_APPLE;
    233 		break;
    234 	case NUBUS_DRSW_ASANTE:
    235 		vendor = AE_VENDOR_ASANTE;
    236 		break;
    237 	case NUBUS_DRSW_FARALLON:
    238 		vendor = AE_VENDOR_FARALLON;
    239 		break;
    240 	case NUBUS_DRSW_FOCUS:
    241 		vendor = AE_VENDOR_FOCUS;
    242 		break;
    243 	case NUBUS_DRSW_GATOR:
    244 		switch (na->drhw) {
    245 		default:
    246 		case NUBUS_DRHW_INTERLAN:
    247 			vendor = AE_VENDOR_INTERLAN;
    248 			break;
    249 		case NUBUS_DRHW_KINETICS:
    250 			if (strncmp(
    251 			    nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
    252 				vendor = AE_VENDOR_KINETICS;
    253 			else
    254 				vendor = AE_VENDOR_DAYNA;
    255 			break;
    256 		}
    257 		break;
    258 	case NUBUS_DRSW_DAYNA:
    259 		vendor = AE_VENDOR_DAYNA;
    260 		break;
    261 	default:
    262 #ifdef DIAGNOSTIC
    263 		printf("Unknown ethernet drsw: %x\n", na->drsw);
    264 #endif
    265 		vendor = AE_VENDOR_UNKNOWN;
    266 	}
    267 	return vendor;
    268 }
    269