Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.14
      1 /*	$NetBSD: if_sn_nubus.c,v 1.14 1997/06/15 20:20:09 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 "nubus.h"
     55 #include "if_snreg.h"
     56 #include "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_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 	(void)(&offset);	/* Work around lame gcc initialization bug */
    118 
    119 	bst = na->na_tag;
    120 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    121 		printf(": failed to map memory space.\n");
    122 		return;
    123 	}
    124 
    125 	sc->sc_regt = bst;
    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 	default:
    181 		/*
    182 		 * You can't actually get this default, the snmatch
    183 		 * will fail for unknown hardware. If you're adding support
    184 		 * for a new card, the following defaults are a
    185 		 * good starting point.
    186 		 */
    187 		sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
    188 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    189 		sc->snr_dcr2 = 0;
    190 		success = 0;
    191 		printf(": unknown card: attachment incomplete.\n");
    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(bst, bsh, na)
    217 	bus_space_tag_t bst;
    218 	bus_space_handle_t bsh;
    219 	struct nubus_attach_args *na;
    220 {
    221 	int vendor = SN_VENDOR_UNKNOWN;
    222 
    223 	switch (na->drsw) {
    224 	case NUBUS_DRSW_3COM:
    225 		if (   (na->drhw == NUBUS_DRHW_APPLE_SN)
    226 		    || (na->drhw == NUBUS_DRHW_APPLE_SNT))
    227 			vendor = SN_VENDOR_APPLE;
    228 		break;
    229 	case NUBUS_DRSW_APPLE:
    230 	case NUBUS_DRSW_TECHWORKS:
    231 		vendor = SN_VENDOR_APPLE;
    232 		break;
    233 	case NUBUS_DRSW_GATOR:
    234 		if (na->drhw == NUBUS_DRHW_KINETICS &&
    235 		    strncmp(nubus_get_card_name(bst, bsh, na->fmt),
    236 		    "EtherPort", 9) != 0)
    237 			vendor = SN_VENDOR_DAYNA;
    238 		break;
    239 	case NUBUS_DRSW_DAYNA:
    240 		vendor = SN_VENDOR_DAYNA;
    241 		break;
    242 	}
    243 
    244 	return vendor;
    245 }
    246