Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.2
      1 /*	$NetBSD: if_sn_nubus.c,v 1.2 1997/03/16 13:41:15 is 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 		/* This is it for now... */
     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;
    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->s_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_USR1 |
    134                          DCR_DW32 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    135 
    136 		if (bus_space_subregion(bst, bsh, 0x00180000, SN_REGSIZE,
    137 					&sc->sc_regh)) {
    138 			printf(": failed to map register space.\n");
    139 			break;
    140 		}
    141 
    142 		if (bus_space_subregion(bst, bsh, 0x00ffe004, ETHER_ADDR_LEN,
    143 					&tmp_bsh)) {
    144 			printf(": failed to map ROM space.\n");
    145 			break;
    146 		}
    147 
    148 		/*
    149 		 * Copy out the ethernet address from the card's ROM
    150 		 */
    151 		for (i = 0; i < ETHER_ADDR_LEN; ++i)
    152 			myaddr[i] = bus_space_read_1(bst, tmp_bsh, i);
    153 
    154 		success = 1;
    155                 break;
    156 
    157         default:
    158                 /*
    159                  * You can't actually get this default, the snmatch
    160                  * will fail for unknown hardware. If you're adding support
    161                  * for a new card, the following defaults are a
    162                  * good starting point.
    163                  */
    164                 sc->s_dcr = DCR_LBR | DCR_SYNC | DCR_WAIT0 |
    165                          DCR_DW32 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    166                 return;
    167         }
    168 
    169 	if (!success) {
    170 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    171 		return;
    172 	}
    173 
    174 	snsetup(sc, myaddr);
    175 }
    176 
    177 static int
    178 sn_nb_card_vendor(na)
    179 	struct nubus_attach_args *na;
    180 {
    181 	int vendor;
    182 
    183 	switch (na->drsw) {
    184 	case NUBUS_DRSW_3COM:
    185 	case NUBUS_DRSW_APPLE:
    186 	case NUBUS_DRSW_TECHWORKS:
    187 		vendor = AE_VENDOR_APPLE;
    188 		break;
    189 	case NUBUS_DRSW_ASANTE:
    190 		vendor = AE_VENDOR_ASANTE;
    191 		break;
    192 	case NUBUS_DRSW_FARALLON:
    193 		vendor = AE_VENDOR_FARALLON;
    194 		break;
    195 	case NUBUS_DRSW_FOCUS:
    196 		vendor = AE_VENDOR_FOCUS;
    197 		break;
    198 	case NUBUS_DRSW_GATOR:
    199 		switch (na->drhw) {
    200 		default:
    201 		case NUBUS_DRHW_INTERLAN:
    202 			vendor = AE_VENDOR_INTERLAN;
    203 			break;
    204 		case NUBUS_DRHW_KINETICS:
    205 			if (strncmp(
    206 			    nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
    207 				vendor = AE_VENDOR_KINETICS;
    208 			else
    209 				vendor = AE_VENDOR_DAYNA;
    210 			break;
    211 		}
    212 		break;
    213 	default:
    214 #ifdef DIAGNOSTIC
    215 		printf("Unknown ethernet drsw: %x\n", na->drsw);
    216 #endif
    217 		vendor = AE_VENDOR_UNKNOWN;
    218 	}
    219 	return vendor;
    220 }
    221