Home | History | Annotate | Line # | Download | only in nubus
if_sn_nubus.c revision 1.28.16.1
      1  1.28.16.1      mjf /*	$NetBSD: if_sn_nubus.c,v 1.28.16.1 2008/06/02 13:22:22 mjf 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.23    lukem 
     33       1.23    lukem #include <sys/cdefs.h>
     34  1.28.16.1      mjf __KERNEL_RCSID(0, "$NetBSD: if_sn_nubus.c,v 1.28.16.1 2008/06/02 13:22:22 mjf Exp $");
     35        1.1   briggs 
     36        1.1   briggs #include <sys/param.h>
     37       1.27  tsutsui #include <sys/systm.h>
     38        1.1   briggs #include <sys/device.h>
     39        1.1   briggs #include <sys/ioctl.h>
     40        1.1   briggs 
     41        1.1   briggs #include <net/if.h>
     42        1.2       is #include <net/if_ether.h>
     43        1.1   briggs 
     44        1.1   briggs #include <machine/bus.h>
     45        1.1   briggs #include <machine/viareg.h>
     46        1.1   briggs 
     47       1.27  tsutsui #include <dev/ic/dp83932reg.h>
     48       1.27  tsutsui #include <dev/ic/dp83932var.h>
     49       1.27  tsutsui 
     50       1.18   scottr #include <mac68k/nubus/nubus.h>
     51       1.16   scottr #include <mac68k/dev/if_snvar.h>
     52        1.1   briggs 
     53  1.28.16.1      mjf static int	sn_nubus_match(device_t, cfdata_t, void *);
     54  1.28.16.1      mjf static void	sn_nubus_attach(device_t, device_t, void *);
     55       1.24      chs static int	sn_nb_card_vendor(bus_space_tag_t, bus_space_handle_t,
     56       1.24      chs 		    struct nubus_attach_args *);
     57        1.1   briggs 
     58  1.28.16.1      mjf CFATTACH_DECL_NEW(sn_nubus, sizeof(struct sonic_softc),
     59       1.22  thorpej     sn_nubus_match, sn_nubus_attach, NULL, NULL);
     60        1.1   briggs 
     61        1.2       is 
     62        1.1   briggs static int
     63  1.28.16.1      mjf sn_nubus_match(device_t parent, cfdata_t cf, void *aux)
     64        1.1   briggs {
     65  1.28.16.1      mjf 	struct nubus_attach_args *na = aux;
     66        1.1   briggs 	bus_space_handle_t bsh;
     67        1.1   briggs 	int rv;
     68        1.1   briggs 
     69       1.10   scottr 	if (bus_space_map(na->na_tag,
     70       1.10   scottr 	    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
     71  1.28.16.1      mjf 		return 0;
     72        1.1   briggs 
     73        1.1   briggs 	rv = 0;
     74        1.1   briggs 
     75        1.1   briggs 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     76        1.1   briggs 	    na->type == NUBUS_TYPE_ETHERNET) {
     77       1.13   scottr 		switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
     78        1.1   briggs 		default:
     79        1.1   briggs 			break;
     80        1.1   briggs 
     81       1.11   scottr 		case SN_VENDOR_APPLE:
     82       1.15   scottr 		case SN_VENDOR_APPLE16:
     83       1.20   scottr 		case SN_VENDOR_ASANTELC:
     84       1.11   scottr 		case SN_VENDOR_DAYNA:
     85        1.1   briggs 			rv = 1;
     86        1.1   briggs 			break;
     87        1.1   briggs 		}
     88        1.1   briggs 	}
     89        1.1   briggs 
     90        1.1   briggs 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
     91        1.1   briggs 
     92        1.1   briggs 	return rv;
     93        1.1   briggs }
     94        1.1   briggs 
     95        1.1   briggs /*
     96        1.1   briggs  * Install interface into kernel networking data structures
     97        1.1   briggs  */
     98        1.1   briggs static void
     99  1.28.16.1      mjf sn_nubus_attach(device_t parent, device_t self, void *aux)
    100        1.1   briggs {
    101  1.28.16.1      mjf 	struct sonic_softc *sc = device_private(self);
    102       1.27  tsutsui 	struct nubus_attach_args *na = aux;
    103       1.10   scottr 	int i, success, offset;
    104        1.1   briggs 	bus_space_tag_t	bst;
    105       1.10   scottr 	bus_space_handle_t bsh, tmp_bsh;
    106       1.27  tsutsui 	uint8_t myaddr[ETHER_ADDR_LEN];
    107       1.25      rjs 	const char *cardtype;
    108        1.1   briggs 
    109        1.1   briggs 	bst = na->na_tag;
    110        1.1   briggs 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    111  1.28.16.1      mjf 		aprint_error(": failed to map memory space.\n");
    112        1.1   briggs 		return;
    113        1.1   briggs 	}
    114        1.1   briggs 
    115  1.28.16.1      mjf 	sc->sc_dev = self;
    116       1.27  tsutsui 	sc->sc_st = bst;
    117       1.27  tsutsui 	sc->sc_dmat = na->na_dmat;
    118        1.1   briggs 
    119       1.20   scottr 	cardtype = nubus_get_card_name(bst, bsh, na->fmt);
    120       1.20   scottr 
    121        1.1   briggs 	success = 0;
    122       1.27  tsutsui 	offset = 0;
    123        1.1   briggs 
    124       1.13   scottr 	switch (sn_nb_card_vendor(bst, bsh, na)) {
    125       1.11   scottr 	case SN_VENDOR_DAYNA:
    126       1.27  tsutsui 		sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0;
    127       1.27  tsutsui 		sc->sc_dcr2 = 0;
    128       1.27  tsutsui 		sc->sc_32bit = 1;	/* 32 bit card */
    129        1.1   briggs 
    130       1.10   scottr 		if (bus_space_subregion(bst, bsh,
    131       1.27  tsutsui 		    0x00180000, SONIC_NREGS * 4, &sc->sc_sh)) {
    132  1.28.16.1      mjf 			aprint_error(": failed to map register space.\n");
    133        1.1   briggs 			break;
    134        1.1   briggs 		}
    135        1.1   briggs 
    136       1.10   scottr 		if (bus_space_subregion(bst, bsh,
    137       1.10   scottr 		    0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
    138  1.28.16.1      mjf 			aprint_error(": failed to map ROM space.\n");
    139        1.1   briggs 			break;
    140        1.1   briggs 		}
    141        1.1   briggs 
    142        1.5   briggs 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    143        1.5   briggs 
    144        1.7   briggs 		offset = 2;
    145        1.1   briggs 		success = 1;
    146       1.10   scottr 		break;
    147        1.1   briggs 
    148       1.11   scottr 	case SN_VENDOR_APPLE:
    149       1.27  tsutsui 		sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0;
    150       1.27  tsutsui 		sc->sc_dcr2 = 0;
    151       1.27  tsutsui 		sc->sc_32bit = 1; /* 32 bit card */
    152        1.4   briggs 
    153       1.10   scottr 		if (bus_space_subregion(bst, bsh,
    154       1.27  tsutsui 		    0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
    155  1.28.16.1      mjf 			aprint_error(": failed to map register space.\n");
    156        1.4   briggs 			break;
    157        1.4   briggs 		}
    158        1.4   briggs 
    159       1.10   scottr 		if (bus_space_subregion(bst, bsh,
    160       1.10   scottr 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    161  1.28.16.1      mjf 			aprint_error(": failed to map ROM space.\n");
    162        1.5   briggs 			break;
    163        1.5   briggs 		}
    164        1.5   briggs 
    165        1.5   briggs 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    166        1.5   briggs 
    167        1.7   briggs 		offset = 0;
    168        1.5   briggs 		success = 1;
    169       1.10   scottr 		break;
    170       1.15   scottr 
    171       1.15   scottr 	case SN_VENDOR_APPLE16:
    172       1.27  tsutsui 		sc->sc_dcr = DCR_EXBUS | DCR_BMS | DCR_PO1 |
    173       1.27  tsutsui 		    DCR_RFT1 | DCR_TFT0;
    174       1.27  tsutsui 		sc->sc_dcr2 = 0;
    175       1.27  tsutsui 		sc->sc_32bit = 0; /* 16 bit card */
    176       1.15   scottr 
    177       1.15   scottr 		if (bus_space_subregion(bst, bsh,
    178       1.27  tsutsui 		    0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
    179  1.28.16.1      mjf 			aprint_error(": failed to map register space.\n");
    180       1.15   scottr 			break;
    181       1.15   scottr 		}
    182       1.15   scottr 
    183       1.15   scottr 		if (bus_space_subregion(bst, bsh,
    184       1.15   scottr 		    0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
    185  1.28.16.1      mjf 			aprint_error(": failed to map ROM space.\n");
    186       1.15   scottr 			break;
    187       1.15   scottr 		}
    188       1.15   scottr 
    189       1.15   scottr 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    190       1.15   scottr 
    191       1.15   scottr 		offset = 0;
    192       1.15   scottr 		success = 1;
    193       1.15   scottr 		break;
    194        1.4   briggs 
    195       1.20   scottr 	case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
    196       1.27  tsutsui 		sc->sc_dcr = DCR_BMS | DCR_PO1 | DCR_RFT1 | DCR_TFT0;
    197       1.27  tsutsui 		sc->sc_dcr2 = 0;
    198       1.27  tsutsui 		sc->sc_32bit = 0; /* 16 bit card */
    199       1.20   scottr 
    200       1.20   scottr 		if (bus_space_subregion(bst, bsh,
    201       1.27  tsutsui 		    0x0, SONIC_NREGS * 4, &sc->sc_sh)) {
    202  1.28.16.1      mjf 			aprint_error(": failed to map register space.\n");
    203       1.20   scottr 			break;
    204       1.20   scottr 		}
    205       1.20   scottr 
    206       1.20   scottr 		if (bus_space_subregion(bst, bsh,
    207       1.20   scottr 		    0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
    208  1.28.16.1      mjf 			aprint_error(": failed to map ROM space.\n");
    209       1.20   scottr 			break;
    210       1.20   scottr 		}
    211       1.20   scottr 
    212       1.20   scottr 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
    213       1.20   scottr 
    214       1.20   scottr 		offset = 0;
    215       1.20   scottr 		success = 1;
    216       1.20   scottr 		break;
    217       1.20   scottr 
    218       1.10   scottr 	default:
    219       1.10   scottr 		/*
    220       1.10   scottr 		 * You can't actually get this default, the snmatch
    221       1.10   scottr 		 * will fail for unknown hardware. If you're adding support
    222       1.10   scottr 		 * for a new card, the following defaults are a
    223       1.10   scottr 		 * good starting point.
    224       1.10   scottr 		 */
    225       1.27  tsutsui 		sc->sc_dcr = DCR_SBUS | DCR_BMS | DCR_RFT1 | DCR_TFT0;
    226       1.27  tsutsui 		sc->sc_dcr2 = 0;
    227       1.27  tsutsui 		sc->sc_32bit = 1;
    228        1.8   briggs 		success = 0;
    229  1.28.16.1      mjf 		aprint_error(": unknown card: attachment incomplete.\n");
    230       1.10   scottr 	}
    231        1.1   briggs 
    232        1.1   briggs 	if (!success) {
    233        1.1   briggs 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    234        1.1   briggs 		return;
    235        1.1   briggs 	}
    236        1.1   briggs 
    237        1.3   briggs 	/* Regs are addressed as words, big endian. */
    238       1.27  tsutsui 	for (i = 0; i < SONIC_NREGS; i++) {
    239       1.27  tsutsui 		sc->sc_regmap[i] = (bus_size_t)((i * 4) + offset);
    240        1.3   briggs 	}
    241        1.3   briggs 
    242       1.27  tsutsui 	sc->sc_bigendian = 1;
    243       1.27  tsutsui 
    244  1.28.16.1      mjf 	aprint_error(": %s\n", cardtype);
    245       1.20   scottr 
    246       1.27  tsutsui 	add_nubus_intr(na->slot, (void (*)(void *))sonic_intr, (void *)sc);
    247        1.3   briggs 
    248       1.27  tsutsui 	sonic_attach(sc, myaddr);
    249        1.3   briggs 
    250        1.3   briggs 	return;
    251        1.1   briggs }
    252        1.1   briggs 
    253        1.1   briggs static int
    254       1.24      chs sn_nb_card_vendor(bus_space_tag_t bst, bus_space_handle_t bsh,
    255       1.24      chs     struct nubus_attach_args *na)
    256        1.1   briggs {
    257       1.11   scottr 	int vendor = SN_VENDOR_UNKNOWN;
    258        1.1   briggs 
    259        1.1   briggs 	switch (na->drsw) {
    260        1.1   briggs 	case NUBUS_DRSW_3COM:
    261       1.17   briggs 		if (na->drhw == NUBUS_DRHW_APPLE_SNT)
    262       1.11   scottr 			vendor = SN_VENDOR_APPLE;
    263       1.17   briggs 		else if (na->drhw == NUBUS_DRHW_APPLE_SN)
    264       1.15   scottr 			vendor = SN_VENDOR_APPLE16;
    265        1.4   briggs 		break;
    266        1.1   briggs 	case NUBUS_DRSW_APPLE:
    267       1.20   scottr 		if (na->drhw == NUBUS_DRHW_ASANTE_LC)
    268       1.20   scottr 			vendor = SN_VENDOR_ASANTELC;
    269       1.20   scottr 		else
    270       1.20   scottr 			vendor = SN_VENDOR_APPLE;
    271       1.20   scottr 		break;
    272        1.1   briggs 	case NUBUS_DRSW_TECHWORKS:
    273       1.11   scottr 		vendor = SN_VENDOR_APPLE;
    274        1.1   briggs 		break;
    275        1.1   briggs 	case NUBUS_DRSW_GATOR:
    276       1.11   scottr 		if (na->drhw == NUBUS_DRHW_KINETICS &&
    277       1.13   scottr 		    strncmp(nubus_get_card_name(bst, bsh, na->fmt),
    278       1.13   scottr 		    "EtherPort", 9) != 0)
    279       1.11   scottr 			vendor = SN_VENDOR_DAYNA;
    280        1.3   briggs 		break;
    281        1.3   briggs 	case NUBUS_DRSW_DAYNA:
    282       1.11   scottr 		vendor = SN_VENDOR_DAYNA;
    283        1.1   briggs 		break;
    284        1.1   briggs 	}
    285       1.11   scottr 
    286        1.1   briggs 	return vendor;
    287        1.1   briggs }
    288