Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.11
      1 /*	$NetBSD: if_sn_nubus.c,v 1.11 1997/04/30 19:47:11 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((struct nubus_attach_args *));
     61 
     62 struct cfattach sn_nubus_ca = {
     63 	sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
     64 };
     65 
     66 
     67 static int
     68 sn_nubus_match(parent, cf, aux)
     69 	struct device *parent;
     70 	struct cfdata *cf;
     71 	void *aux;
     72 {
     73 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
     74 	bus_space_handle_t bsh;
     75 	int rv;
     76 
     77 	if (bus_space_map(na->na_tag,
     78 	    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
     79 		return (0);
     80 
     81 	rv = 0;
     82 
     83 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     84 	    na->type == NUBUS_TYPE_ETHERNET) {
     85 		switch (sn_nb_card_vendor(na)) {
     86 		default:
     87 			break;
     88 
     89 		case SN_VENDOR_APPLE:
     90 		case SN_VENDOR_DAYNA:
     91 			rv = 1;
     92 			break;
     93 		}
     94 	}
     95 
     96 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
     97 
     98 	return rv;
     99 }
    100 
    101 /*
    102  * Install interface into kernel networking data structures
    103  */
    104 static void
    105 sn_nubus_attach(parent, self, aux)
    106 	struct device *parent, *self;
    107 	void   *aux;
    108 {
    109 	struct sn_softc *sc = (void *)self;
    110 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    111 	int i, success, offset;
    112 	bus_space_tag_t	bst;
    113 	bus_space_handle_t bsh, tmp_bsh;
    114 	u_int8_t myaddr[ETHER_ADDR_LEN];
    115 
    116 	(void)(&offset);	/* Work around lame gcc initialization bug */
    117 
    118 	bst = na->na_tag;
    119 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    120 		printf(": failed to map memory space.\n");
    121 		return;
    122 	}
    123 
    124 	sc->sc_regt = bst;
    125 	sc->bitmode = 1;
    126 
    127 	success = 0;
    128 
    129 	sc->bitmode = 1;		/* 32-bit card */
    130 	sc->slotno = na->slot;
    131 
    132 	switch (sn_nb_card_vendor(na)) {
    133 	case SN_VENDOR_DAYNA:
    134 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_DW32 |
    135 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    136 		sc->snr_dcr2 = 0;
    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 | DCR_DW32 |
    158 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    159 		sc->snr_dcr2 = 0;
    160 
    161 		if (bus_space_subregion(bst, bsh,
    162 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    163 			printf(": failed to map register space.\n");
    164 			break;
    165 		}
    166 
    167 		if (bus_space_subregion(bst, bsh,
    168 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    169 			printf(": failed to map ROM space.\n");
    170 			break;
    171 		}
    172 
    173 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    174 
    175 		offset = 0;
    176 		success = 1;
    177 		break;
    178 
    179 	default:
    180 		/*
    181 		 * You can't actually get this default, the snmatch
    182 		 * will fail for unknown hardware. If you're adding support
    183 		 * for a new card, the following defaults are a
    184 		 * good starting point.
    185 		 */
    186 		sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
    187 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    188 		sc->snr_dcr2 = 0;
    189 		success = 0;
    190 		printf(": unknown card: attachment incomplete.\n");
    191 	}
    192 
    193 	if (!success) {
    194 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    195 		return;
    196 	}
    197 
    198 	/* Regs are addressed as words, big endian. */
    199 	for (i = 0; i < SN_NREGS; i++) {
    200 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
    201 	}
    202 
    203 	/* snsetup returns 1 if something fails */
    204 	if (snsetup(sc, myaddr)) {
    205 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    206 		return;
    207 	}
    208 
    209 	add_nubus_intr(sc->slotno, snintr, (void *)sc);
    210 
    211 	return;
    212 }
    213 
    214 static int
    215 sn_nb_card_vendor(na)
    216 	struct nubus_attach_args *na;
    217 {
    218 	int vendor = SN_VENDOR_UNKNOWN;
    219 
    220 	switch (na->drsw) {
    221 	case NUBUS_DRSW_3COM:
    222 		if (na->drhw == NUBUS_DRHW_APPLE_SN)
    223 			vendor = SN_VENDOR_APPLE;
    224 		break;
    225 	case NUBUS_DRSW_APPLE:
    226 	case NUBUS_DRSW_TECHWORKS:
    227 		vendor = SN_VENDOR_APPLE;
    228 		break;
    229 	case NUBUS_DRSW_GATOR:
    230 		if (na->drhw == NUBUS_DRHW_KINETICS &&
    231 		    strncmp(nubus_get_card_name(na->fmt), "EtherPort", 9) != 0)
    232 			vendor = SN_VENDOR_DAYNA;
    233 		break;
    234 	case NUBUS_DRSW_DAYNA:
    235 		vendor = SN_VENDOR_DAYNA;
    236 		break;
    237 	}
    238 
    239 	return vendor;
    240 }
    241