Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.19.8.1
      1  1.19.8.1    scottr /*	$NetBSD: if_sn_nubus.c,v 1.19.8.1 1999/11/01 06:19:15 scottr Exp $	*/
      2       1.1    briggs 
      3       1.1    briggs /*
      4       1.1    briggs  * Copyright (C) 1997 Allen Briggs
      5       1.1    briggs  * All rights reserved.
      6       1.1    briggs  *
      7       1.1    briggs  * Redistribution and use in source and binary forms, with or without
      8       1.1    briggs  * modification, are permitted provided that the following conditions
      9       1.1    briggs  * are met:
     10       1.1    briggs  * 1. Redistributions of source code must retain the above copyright
     11       1.1    briggs  *    notice, this list of conditions and the following disclaimer.
     12       1.1    briggs  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    briggs  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    briggs  *    documentation and/or other materials provided with the distribution.
     15       1.1    briggs  * 3. All advertising materials mentioning features or use of this software
     16       1.1    briggs  *    must display the following acknowledgement:
     17       1.1    briggs  *      This product includes software developed by Allen Briggs
     18       1.1    briggs  * 4. The name of the author may not be used to endorse or promote products
     19       1.1    briggs  *    derived from this software without specific prior written permission.
     20       1.1    briggs  *
     21       1.1    briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1    briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1    briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1    briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1    briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1    briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1    briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1    briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1    briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1    briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1    briggs  */
     32      1.19  jonathan 
     33      1.19  jonathan #include "opt_inet.h"
     34       1.1    briggs 
     35       1.1    briggs #include <sys/param.h>
     36       1.1    briggs #include <sys/device.h>
     37       1.1    briggs #include <sys/errno.h>
     38       1.1    briggs #include <sys/ioctl.h>
     39       1.1    briggs #include <sys/socket.h>
     40       1.1    briggs #include <sys/syslog.h>
     41       1.1    briggs #include <sys/systm.h>
     42       1.1    briggs 
     43       1.1    briggs #include <net/if.h>
     44       1.2        is #include <net/if_ether.h>
     45       1.1    briggs 
     46       1.2        is #if 0 /* XXX this shouldn't be necessary; else reinsert */
     47       1.1    briggs #ifdef INET
     48       1.1    briggs #include <netinet/in.h>
     49       1.2        is #include <netinet/if_inarp.h>
     50       1.2        is #endif
     51       1.1    briggs #endif
     52       1.1    briggs 
     53       1.1    briggs #include <machine/bus.h>
     54       1.1    briggs #include <machine/viareg.h>
     55       1.1    briggs 
     56      1.18    scottr #include <mac68k/nubus/nubus.h>
     57      1.16    scottr #include <mac68k/dev/if_snreg.h>
     58      1.16    scottr #include <mac68k/dev/if_snvar.h>
     59       1.1    briggs 
     60       1.1    briggs static int	sn_nubus_match __P((struct device *, struct cfdata *, void *));
     61       1.1    briggs static void	sn_nubus_attach __P((struct device *, struct device *, void *));
     62      1.13    scottr static int	sn_nb_card_vendor __P((bus_space_tag_t, bus_space_handle_t,
     63      1.13    scottr 		    struct nubus_attach_args *));
     64       1.1    briggs 
     65       1.1    briggs struct cfattach sn_nubus_ca = {
     66       1.1    briggs 	sizeof(struct sn_softc), sn_nubus_match, sn_nubus_attach
     67       1.1    briggs };
     68       1.1    briggs 
     69       1.2        is 
     70       1.1    briggs static int
     71       1.1    briggs sn_nubus_match(parent, cf, aux)
     72       1.1    briggs 	struct device *parent;
     73       1.1    briggs 	struct cfdata *cf;
     74       1.1    briggs 	void *aux;
     75       1.1    briggs {
     76       1.1    briggs 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
     77       1.1    briggs 	bus_space_handle_t bsh;
     78       1.1    briggs 	int rv;
     79       1.1    briggs 
     80      1.10    scottr 	if (bus_space_map(na->na_tag,
     81      1.10    scottr 	    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
     82       1.1    briggs 		return (0);
     83       1.1    briggs 
     84       1.1    briggs 	rv = 0;
     85       1.1    briggs 
     86       1.1    briggs 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     87       1.1    briggs 	    na->type == NUBUS_TYPE_ETHERNET) {
     88      1.13    scottr 		switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
     89       1.1    briggs 		default:
     90       1.1    briggs 			break;
     91       1.1    briggs 
     92      1.11    scottr 		case SN_VENDOR_APPLE:
     93      1.15    scottr 		case SN_VENDOR_APPLE16:
     94  1.19.8.1    scottr 		case SN_VENDOR_ASANTELC:
     95      1.11    scottr 		case SN_VENDOR_DAYNA:
     96       1.1    briggs 			rv = 1;
     97       1.1    briggs 			break;
     98       1.1    briggs 		}
     99       1.1    briggs 	}
    100       1.1    briggs 
    101       1.1    briggs 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
    102       1.1    briggs 
    103       1.1    briggs 	return rv;
    104       1.1    briggs }
    105       1.1    briggs 
    106       1.1    briggs /*
    107       1.1    briggs  * Install interface into kernel networking data structures
    108       1.1    briggs  */
    109       1.1    briggs static void
    110       1.1    briggs sn_nubus_attach(parent, self, aux)
    111       1.1    briggs 	struct device *parent, *self;
    112       1.1    briggs 	void   *aux;
    113       1.1    briggs {
    114      1.10    scottr 	struct sn_softc *sc = (void *)self;
    115      1.10    scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    116      1.10    scottr 	int i, success, offset;
    117       1.1    briggs 	bus_space_tag_t	bst;
    118      1.10    scottr 	bus_space_handle_t bsh, tmp_bsh;
    119       1.2        is 	u_int8_t myaddr[ETHER_ADDR_LEN];
    120  1.19.8.1    scottr 	char *cardtype;
    121       1.1    briggs 
    122      1.10    scottr 	(void)(&offset);	/* Work around lame gcc initialization bug */
    123      1.10    scottr 
    124       1.1    briggs 	bst = na->na_tag;
    125       1.1    briggs 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    126       1.1    briggs 		printf(": failed to map memory space.\n");
    127       1.1    briggs 		return;
    128       1.1    briggs 	}
    129       1.1    briggs 
    130       1.1    briggs 	sc->sc_regt = bst;
    131       1.1    briggs 
    132  1.19.8.1    scottr 	cardtype = nubus_get_card_name(bst, bsh, na->fmt);
    133  1.19.8.1    scottr 
    134       1.1    briggs 	success = 0;
    135       1.1    briggs 
    136      1.10    scottr 	sc->slotno = na->slot;
    137       1.1    briggs 
    138      1.13    scottr 	switch (sn_nb_card_vendor(bst, bsh, na)) {
    139      1.11    scottr 	case SN_VENDOR_DAYNA:
    140      1.14    scottr 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
    141      1.10    scottr 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    142       1.3    briggs 		sc->snr_dcr2 = 0;
    143      1.14    scottr 		sc->bitmode = 1;	/* 32 bit card */
    144       1.1    briggs 
    145      1.10    scottr 		if (bus_space_subregion(bst, bsh,
    146      1.10    scottr 		    0x00180000, SN_REGSIZE, &sc->sc_regh)) {
    147       1.1    briggs 			printf(": failed to map register space.\n");
    148       1.1    briggs 			break;
    149       1.1    briggs 		}
    150       1.1    briggs 
    151      1.10    scottr 		if (bus_space_subregion(bst, bsh,
    152      1.10    scottr 		    0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
    153       1.1    briggs 			printf(": failed to map ROM space.\n");
    154       1.1    briggs 			break;
    155       1.1    briggs 		}
    156       1.1    briggs 
    157       1.5    briggs 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    158       1.5    briggs 
    159       1.7    briggs 		offset = 2;
    160       1.1    briggs 		success = 1;
    161      1.10    scottr 		break;
    162       1.1    briggs 
    163      1.11    scottr 	case SN_VENDOR_APPLE:
    164      1.14    scottr 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
    165      1.10    scottr 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    166       1.4    briggs 		sc->snr_dcr2 = 0;
    167      1.14    scottr 		sc->bitmode = 1; /* 32 bit card */
    168       1.4    briggs 
    169      1.10    scottr 		if (bus_space_subregion(bst, bsh,
    170      1.10    scottr 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    171       1.4    briggs 			printf(": failed to map register space.\n");
    172       1.4    briggs 			break;
    173       1.4    briggs 		}
    174       1.4    briggs 
    175      1.10    scottr 		if (bus_space_subregion(bst, bsh,
    176      1.10    scottr 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    177       1.5    briggs 			printf(": failed to map ROM space.\n");
    178       1.5    briggs 			break;
    179       1.5    briggs 		}
    180       1.5    briggs 
    181       1.5    briggs 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    182       1.5    briggs 
    183       1.7    briggs 		offset = 0;
    184       1.5    briggs 		success = 1;
    185      1.10    scottr 		break;
    186      1.15    scottr 
    187      1.15    scottr 	case SN_VENDOR_APPLE16:
    188      1.17    briggs 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
    189      1.15    scottr 		    DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
    190      1.15    scottr 		sc->snr_dcr2 = 0;
    191      1.15    scottr 		sc->bitmode = 0; /* 16 bit card */
    192      1.15    scottr 
    193      1.15    scottr 		if (bus_space_subregion(bst, bsh,
    194      1.15    scottr 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    195      1.15    scottr 			printf(": failed to map register space.\n");
    196      1.15    scottr 			break;
    197      1.15    scottr 		}
    198      1.15    scottr 
    199      1.15    scottr 		if (bus_space_subregion(bst, bsh,
    200      1.15    scottr 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    201      1.15    scottr 			printf(": failed to map ROM space.\n");
    202      1.15    scottr 			break;
    203      1.15    scottr 		}
    204      1.15    scottr 
    205      1.15    scottr 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    206      1.15    scottr 
    207      1.15    scottr 		offset = 0;
    208      1.15    scottr 		success = 1;
    209      1.15    scottr 		break;
    210       1.4    briggs 
    211  1.19.8.1    scottr 	case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
    212  1.19.8.1    scottr 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
    213  1.19.8.1    scottr 		    DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
    214  1.19.8.1    scottr 		sc->snr_dcr2 = 0;
    215  1.19.8.1    scottr 		sc->bitmode = 0; /* 16 bit card */
    216  1.19.8.1    scottr 
    217  1.19.8.1    scottr 		if (bus_space_subregion(bst, bsh,
    218  1.19.8.1    scottr 		    0x0, SN_REGSIZE, &sc->sc_regh)) {
    219  1.19.8.1    scottr 			printf(": failed to map register space.\n");
    220  1.19.8.1    scottr 			break;
    221  1.19.8.1    scottr 		}
    222  1.19.8.1    scottr 
    223  1.19.8.1    scottr 		if (bus_space_subregion(bst, bsh,
    224  1.19.8.1    scottr 		    0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
    225  1.19.8.1    scottr 			printf(": failed to map ROM space.\n");
    226  1.19.8.1    scottr 			break;
    227  1.19.8.1    scottr 		}
    228  1.19.8.1    scottr 
    229  1.19.8.1    scottr 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    230  1.19.8.1    scottr 
    231  1.19.8.1    scottr 		offset = 0;
    232  1.19.8.1    scottr 		success = 1;
    233  1.19.8.1    scottr 		break;
    234  1.19.8.1    scottr 
    235      1.10    scottr 	default:
    236      1.10    scottr 		/*
    237      1.10    scottr 		 * You can't actually get this default, the snmatch
    238      1.10    scottr 		 * will fail for unknown hardware. If you're adding support
    239      1.10    scottr 		 * for a new card, the following defaults are a
    240      1.10    scottr 		 * good starting point.
    241      1.10    scottr 		 */
    242      1.10    scottr 		sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
    243      1.10    scottr 		    DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    244       1.3    briggs 		sc->snr_dcr2 = 0;
    245       1.8    briggs 		success = 0;
    246       1.9    briggs 		printf(": unknown card: attachment incomplete.\n");
    247      1.10    scottr 	}
    248       1.1    briggs 
    249       1.1    briggs 	if (!success) {
    250       1.1    briggs 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    251       1.1    briggs 		return;
    252       1.1    briggs 	}
    253       1.1    briggs 
    254       1.3    briggs 	/* Regs are addressed as words, big endian. */
    255       1.3    briggs 	for (i = 0; i < SN_NREGS; i++) {
    256       1.7    briggs 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
    257       1.3    briggs 	}
    258       1.3    briggs 
    259  1.19.8.1    scottr 	printf(": %s\n", cardtype);
    260  1.19.8.1    scottr 
    261       1.3    briggs 	/* snsetup returns 1 if something fails */
    262       1.3    briggs 	if (snsetup(sc, myaddr)) {
    263       1.3    briggs 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    264       1.3    briggs 		return;
    265       1.3    briggs 	}
    266       1.3    briggs 
    267       1.3    briggs 	add_nubus_intr(sc->slotno, snintr, (void *)sc);
    268       1.3    briggs 
    269       1.3    briggs 	return;
    270       1.1    briggs }
    271       1.1    briggs 
    272       1.1    briggs static int
    273      1.13    scottr sn_nb_card_vendor(bst, bsh, na)
    274      1.13    scottr 	bus_space_tag_t bst;
    275      1.13    scottr 	bus_space_handle_t bsh;
    276       1.1    briggs 	struct nubus_attach_args *na;
    277       1.1    briggs {
    278      1.11    scottr 	int vendor = SN_VENDOR_UNKNOWN;
    279       1.1    briggs 
    280       1.1    briggs 	switch (na->drsw) {
    281       1.1    briggs 	case NUBUS_DRSW_3COM:
    282      1.17    briggs 		if (na->drhw == NUBUS_DRHW_APPLE_SNT)
    283      1.11    scottr 			vendor = SN_VENDOR_APPLE;
    284      1.17    briggs 		else if (na->drhw == NUBUS_DRHW_APPLE_SN)
    285      1.15    scottr 			vendor = SN_VENDOR_APPLE16;
    286       1.4    briggs 		break;
    287       1.1    briggs 	case NUBUS_DRSW_APPLE:
    288  1.19.8.1    scottr 		if (na->drhw == NUBUS_DRHW_ASANTE_LC)
    289  1.19.8.1    scottr 			vendor = SN_VENDOR_ASANTELC;
    290  1.19.8.1    scottr 		else
    291  1.19.8.1    scottr 			vendor = SN_VENDOR_APPLE;
    292  1.19.8.1    scottr 		break;
    293       1.1    briggs 	case NUBUS_DRSW_TECHWORKS:
    294      1.11    scottr 		vendor = SN_VENDOR_APPLE;
    295       1.1    briggs 		break;
    296       1.1    briggs 	case NUBUS_DRSW_GATOR:
    297      1.11    scottr 		if (na->drhw == NUBUS_DRHW_KINETICS &&
    298      1.13    scottr 		    strncmp(nubus_get_card_name(bst, bsh, na->fmt),
    299      1.13    scottr 		    "EtherPort", 9) != 0)
    300      1.11    scottr 			vendor = SN_VENDOR_DAYNA;
    301       1.3    briggs 		break;
    302       1.3    briggs 	case NUBUS_DRSW_DAYNA:
    303      1.11    scottr 		vendor = SN_VENDOR_DAYNA;
    304       1.1    briggs 		break;
    305       1.1    briggs 	}
    306      1.11    scottr 
    307       1.1    briggs 	return vendor;
    308       1.1    briggs }
    309