Home | History | Annotate | Line # | Download | only in nubus
if_ae_nubus.c revision 1.3
      1  1.3  scottr /*	$NetBSD: if_ae_nubus.c,v 1.3 1997/02/25 06:36:06 scottr Exp $	*/
      2  1.1  scottr 
      3  1.1  scottr /*
      4  1.1  scottr  * Copyright (C) 1997 Scott Reynolds
      5  1.1  scottr  * All rights reserved.
      6  1.1  scottr  *
      7  1.1  scottr  * Redistribution and use in source and binary forms, with or without
      8  1.1  scottr  * modification, are permitted provided that the following conditions
      9  1.1  scottr  * are met:
     10  1.1  scottr  * 1. Redistributions of source code must retain the above copyright
     11  1.1  scottr  *    notice, this list of conditions and the following disclaimer.
     12  1.1  scottr  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  scottr  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  scottr  *    documentation and/or other materials provided with the distribution.
     15  1.1  scottr  * 3. All advertising materials mentioning features or use of this software
     16  1.1  scottr  *    must display the following acknowledgement:
     17  1.1  scottr  *      This product includes software developed by Scott Reynolds for
     18  1.1  scottr  *      the NetBSD Project.
     19  1.1  scottr  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  scottr  *    derived from this software without specific prior written permission.
     21  1.1  scottr  *
     22  1.1  scottr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  scottr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  scottr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  scottr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  scottr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  scottr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  scottr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  scottr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  scottr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  scottr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  scottr  */
     33  1.1  scottr 
     34  1.1  scottr #include <sys/param.h>
     35  1.1  scottr #include <sys/device.h>
     36  1.1  scottr #include <sys/errno.h>
     37  1.1  scottr #include <sys/ioctl.h>
     38  1.1  scottr #include <sys/socket.h>
     39  1.1  scottr #include <sys/systm.h>
     40  1.1  scottr 
     41  1.1  scottr #include <net/if.h>
     42  1.1  scottr 
     43  1.1  scottr #ifdef INET
     44  1.1  scottr #include <netinet/in.h>
     45  1.1  scottr #include <netinet/if_ether.h>
     46  1.1  scottr #endif
     47  1.1  scottr 
     48  1.1  scottr #include <machine/bus.h>
     49  1.1  scottr #include <machine/viareg.h>
     50  1.1  scottr 
     51  1.1  scottr #include "nubus.h"
     52  1.1  scottr #include <dev/ic/dp8390reg.h>
     53  1.1  scottr #include "if_aereg.h"
     54  1.1  scottr #include "if_aevar.h"
     55  1.1  scottr 
     56  1.1  scottr static int	ae_nubus_match __P((struct device *, struct cfdata *, void *));
     57  1.1  scottr static void	ae_nubus_attach __P((struct device *, struct device *, void *));
     58  1.1  scottr static int	ae_card_vendor __P((struct nubus_attach_args *na));
     59  1.3  scottr static int	ae_get_enaddr __P((struct nubus_attach_args *na, u_int8_t *ep));
     60  1.1  scottr 
     61  1.1  scottr struct cfattach ae_nubus_ca = {
     62  1.1  scottr 	sizeof(struct ae_softc), ae_nubus_match, ae_nubus_attach
     63  1.1  scottr };
     64  1.1  scottr 
     65  1.1  scottr static int
     66  1.1  scottr ae_nubus_match(parent, cf, aux)
     67  1.1  scottr 	struct device *parent;
     68  1.1  scottr 	struct cfdata *cf;
     69  1.1  scottr 	void *aux;
     70  1.1  scottr {
     71  1.1  scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
     72  1.1  scottr 	bus_space_handle_t bsh;
     73  1.1  scottr 	int rv;
     74  1.1  scottr 
     75  1.1  scottr 	if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
     76  1.1  scottr 	    0, &bsh))
     77  1.1  scottr 		return (0);
     78  1.1  scottr 
     79  1.1  scottr 	rv = 0;
     80  1.1  scottr 
     81  1.1  scottr 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     82  1.1  scottr 	    na->type == NUBUS_TYPE_ETHERNET) {
     83  1.1  scottr 		switch (ae_card_vendor(na)) {
     84  1.1  scottr 		case AE_VENDOR_APPLE:
     85  1.1  scottr 		case AE_VENDOR_ASANTE:
     86  1.1  scottr 		case AE_VENDOR_FARALLON:
     87  1.1  scottr 		case AE_VENDOR_INTERLAN:
     88  1.2  scottr 		case AE_VENDOR_KINETICS:
     89  1.1  scottr 			rv = 1;
     90  1.1  scottr 			break;
     91  1.1  scottr 		case AE_VENDOR_DAYNA:
     92  1.1  scottr 		case AE_VENDOR_FOCUS:
     93  1.1  scottr 			rv = UNSUPP;
     94  1.1  scottr 			break;
     95  1.1  scottr 		default:
     96  1.1  scottr 			break;
     97  1.1  scottr 		}
     98  1.1  scottr 	}
     99  1.1  scottr 
    100  1.1  scottr 	bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
    101  1.1  scottr 
    102  1.1  scottr 	return rv;
    103  1.1  scottr }
    104  1.1  scottr 
    105  1.1  scottr /*
    106  1.1  scottr  * Install interface into kernel networking data structures
    107  1.1  scottr  */
    108  1.1  scottr static void
    109  1.1  scottr ae_nubus_attach(parent, self, aux)
    110  1.1  scottr 	struct device *parent, *self;
    111  1.1  scottr 	void   *aux;
    112  1.1  scottr {
    113  1.1  scottr 	struct ae_softc *sc = (struct ae_softc *) self;
    114  1.1  scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
    115  1.1  scottr 	bus_space_tag_t bst;
    116  1.1  scottr 	bus_space_handle_t bsh;
    117  1.3  scottr 	int success;
    118  1.3  scottr #ifdef AE_OLD_GET_ENADDR
    119  1.3  scottr 	int i;
    120  1.3  scottr #endif
    121  1.1  scottr 
    122  1.1  scottr 	bst = na->na_tag;
    123  1.1  scottr 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
    124  1.1  scottr 	    0, &bsh)) {
    125  1.1  scottr 		printf(": can't map memory space\n");
    126  1.1  scottr 		return;
    127  1.1  scottr 	}
    128  1.1  scottr 
    129  1.3  scottr 	sc->sc_reg_tag = sc->sc_buf_tag = bst;
    130  1.3  scottr 	sc->sc_flags = self->dv_cfdata->cf_flags;
    131  1.1  scottr 	sc->regs_rev = 0;
    132  1.2  scottr 	sc->use16bit = 1;
    133  1.1  scottr 	sc->vendor = ae_card_vendor(na);
    134  1.1  scottr 	strncpy(sc->type_str, nubus_get_card_name(na->fmt),
    135  1.1  scottr 	    INTERFACE_NAME_LEN);
    136  1.1  scottr 	sc->type_str[INTERFACE_NAME_LEN-1] = '\0';
    137  1.1  scottr 	sc->mem_size = 0;
    138  1.1  scottr 
    139  1.1  scottr 	success = 0;
    140  1.1  scottr 
    141  1.1  scottr 	switch (sc->vendor) {
    142  1.3  scottr 	case AE_VENDOR_APPLE:	/* Apple-compatible cards */
    143  1.1  scottr 	case AE_VENDOR_ASANTE:
    144  1.1  scottr 		sc->regs_rev = 1;
    145  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    146  1.1  scottr 		    AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
    147  1.1  scottr 			printf(": failed to map register space\n");
    148  1.1  scottr 			break;
    149  1.1  scottr 		}
    150  1.1  scottr 		if ((sc->mem_size = ae_size_card_memory(bst, bsh,
    151  1.1  scottr 		    AE_DATA_OFFSET)) == 0) {
    152  1.1  scottr 			printf(": failed to determine size of RAM.\n");
    153  1.1  scottr 			break;
    154  1.1  scottr 		}
    155  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    156  1.1  scottr 		    AE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
    157  1.1  scottr 			printf(": failed to map register space\n");
    158  1.1  scottr 			break;
    159  1.1  scottr 		}
    160  1.3  scottr #ifdef AE_OLD_GET_ENADDR
    161  1.1  scottr 		/* Get station address from on-board ROM */
    162  1.1  scottr 		for (i = 0; i < ETHER_ADDR_LEN; ++i)
    163  1.1  scottr 			sc->sc_arpcom.ac_enaddr[i] =
    164  1.1  scottr 			    bus_space_read_1(bst, bsh, (AE_ROM_OFFSET + i * 2));
    165  1.3  scottr #else
    166  1.3  scottr 		if (ae_get_enaddr(na, sc->sc_arpcom.ac_enaddr)) {
    167  1.3  scottr 			printf(": can't find MAC address\n");
    168  1.3  scottr 			break;
    169  1.3  scottr 		}
    170  1.3  scottr #endif
    171  1.1  scottr 
    172  1.1  scottr 		success = 1;
    173  1.1  scottr 		break;
    174  1.1  scottr 
    175  1.1  scottr 	case AE_VENDOR_DAYNA:
    176  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    177  1.1  scottr 		    DP_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
    178  1.1  scottr 			printf(": failed to map register space\n");
    179  1.1  scottr 			break;
    180  1.1  scottr 		}
    181  1.1  scottr 		sc->mem_size = 8192;
    182  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    183  1.1  scottr 		    DP_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
    184  1.1  scottr 			printf(": failed to map register space\n");
    185  1.1  scottr 			break;
    186  1.1  scottr 		}
    187  1.3  scottr #ifdef AE_OLD_GET_ENADDR
    188  1.1  scottr 		/* Get station address from on-board ROM */
    189  1.1  scottr 		for (i = 0; i < ETHER_ADDR_LEN; ++i)
    190  1.1  scottr 			sc->sc_arpcom.ac_enaddr[i] =
    191  1.1  scottr 			    bus_space_read_1(bst, bsh, (DP_ROM_OFFSET + i * 2));
    192  1.3  scottr #else
    193  1.3  scottr 		if (ae_get_enaddr(na, sc->sc_arpcom.ac_enaddr)) {
    194  1.3  scottr 			printf(": can't find MAC address\n");
    195  1.3  scottr 			break;
    196  1.3  scottr 		}
    197  1.3  scottr #endif
    198  1.1  scottr 
    199  1.1  scottr 		printf(": unsupported Dayna hardware\n");
    200  1.1  scottr 		break;
    201  1.1  scottr 
    202  1.1  scottr 	case AE_VENDOR_FARALLON:
    203  1.1  scottr 		sc->regs_rev = 1;
    204  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    205  1.1  scottr 		    AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
    206  1.1  scottr 			printf(": failed to map register space\n");
    207  1.1  scottr 			break;
    208  1.1  scottr 		}
    209  1.1  scottr 		if ((sc->mem_size = ae_size_card_memory(bst, bsh,
    210  1.1  scottr 		    AE_DATA_OFFSET)) == 0) {
    211  1.1  scottr 			printf(": failed to determine size of RAM.\n");
    212  1.1  scottr 			break;
    213  1.1  scottr 		}
    214  1.1  scottr 		if (bus_space_subregion(bst, bsh,
    215  1.1  scottr 		    AE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
    216  1.1  scottr 			printf(": failed to map register space\n");
    217  1.1  scottr 			break;
    218  1.1  scottr 		}
    219  1.3  scottr #ifdef AE_OLD_GET_ENADDR
    220  1.1  scottr 		/* Get station address from on-board ROM */
    221  1.1  scottr 		for (i = 0; i < ETHER_ADDR_LEN; ++i)
    222  1.1  scottr 			sc->sc_arpcom.ac_enaddr[i] =
    223  1.1  scottr 			    bus_space_read_1(bst, bsh, (FE_ROM_OFFSET + i));
    224  1.3  scottr #endif
    225  1.1  scottr 
    226  1.1  scottr 		success = 1;
    227  1.1  scottr 		break;
    228  1.1  scottr 
    229  1.1  scottr 	case AE_VENDOR_FOCUS:
    230  1.1  scottr 		printf(": unsupported Focus hardware\n");
    231  1.1  scottr 		break;
    232  1.1  scottr 
    233  1.3  scottr 	case AE_VENDOR_INTERLAN:
    234  1.2  scottr 		if (bus_space_subregion(bst, bsh,
    235  1.3  scottr 		    GC_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
    236  1.2  scottr 			printf(": failed to map register space\n");
    237  1.2  scottr 			break;
    238  1.2  scottr 		}
    239  1.2  scottr 		if ((sc->mem_size = ae_size_card_memory(bst, bsh,
    240  1.3  scottr 		    GC_DATA_OFFSET)) == 0) {
    241  1.2  scottr 			printf(": failed to determine size of RAM.\n");
    242  1.2  scottr 			break;
    243  1.2  scottr 		}
    244  1.2  scottr 		if (bus_space_subregion(bst, bsh,
    245  1.3  scottr 		    GC_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
    246  1.2  scottr 			printf(": failed to map register space\n");
    247  1.2  scottr 			break;
    248  1.2  scottr 		}
    249  1.2  scottr 
    250  1.3  scottr 		/* reset the NIC chip */
    251  1.3  scottr 		bus_space_write_1(bst, bsh, GC_RESET_OFFSET, 0);
    252  1.3  scottr 
    253  1.3  scottr #ifdef AE_OLD_GET_ENADDR
    254  1.2  scottr 		/* Get station address from on-board ROM */
    255  1.2  scottr 		for (i = 0; i < ETHER_ADDR_LEN; ++i)
    256  1.2  scottr 			sc->sc_arpcom.ac_enaddr[i] =
    257  1.3  scottr 			    bus_space_read_1(bst, bsh, (GC_ROM_OFFSET + i * 4));
    258  1.2  scottr #else
    259  1.3  scottr 		if (ae_get_enaddr(na, sc->sc_arpcom.ac_enaddr)) {
    260  1.3  scottr 			printf(": can't find MAC address\n");
    261  1.3  scottr 			break;
    262  1.2  scottr 		}
    263  1.2  scottr #endif
    264  1.2  scottr 
    265  1.2  scottr 		success = 1;
    266  1.2  scottr 		break;
    267  1.2  scottr 
    268  1.3  scottr 	case AE_VENDOR_KINETICS:
    269  1.3  scottr 		sc->use16bit = 0;
    270  1.3  scottr 		if (bus_space_subregion(bst, bsh,
    271  1.3  scottr 		    KE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
    272  1.3  scottr 			printf(": failed to map register space\n");
    273  1.3  scottr 			break;
    274  1.3  scottr 		}
    275  1.3  scottr 		if ((sc->mem_size = ae_size_card_memory(bst, bsh,
    276  1.3  scottr 		    KE_DATA_OFFSET)) == 0) {
    277  1.3  scottr 			printf(": failed to determine size of RAM.\n");
    278  1.3  scottr 			break;
    279  1.3  scottr 		}
    280  1.3  scottr 		if (bus_space_subregion(bst, bsh,
    281  1.3  scottr 		    KE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
    282  1.3  scottr 			printf(": failed to map register space\n");
    283  1.3  scottr 			break;
    284  1.3  scottr 		}
    285  1.3  scottr 		if (ae_get_enaddr(na, sc->sc_arpcom.ac_enaddr)) {
    286  1.3  scottr 			printf(": can't find MAC address\n");
    287  1.3  scottr 			break;
    288  1.3  scottr 		}
    289  1.3  scottr 
    290  1.3  scottr 		success = 1;
    291  1.3  scottr 		break;
    292  1.3  scottr 
    293  1.1  scottr 	default:
    294  1.1  scottr 		break;
    295  1.1  scottr 	}
    296  1.1  scottr 
    297  1.1  scottr 	if (!success) {
    298  1.1  scottr 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    299  1.1  scottr 		return;
    300  1.1  scottr 	}
    301  1.1  scottr 
    302  1.3  scottr 	aesetup(sc);
    303  1.1  scottr 
    304  1.1  scottr 	/* make sure interrupts are vectored to us */
    305  1.1  scottr 	add_nubus_intr(na->slot, aeintr, sc);
    306  1.1  scottr 
    307  1.1  scottr 	/*
    308  1.1  scottr 	 * XXX -- enable nubus interrupts here.  Should be done elsewhere,
    309  1.1  scottr 	 *        but that currently breaks with some nubus video cards'
    310  1.1  scottr 	 *	  interrupts.  So we only enable nubus interrupts if we
    311  1.1  scottr 	 *	  have an ethernet card...  i.e., we do it here.
    312  1.1  scottr 	 */
    313  1.1  scottr 	enable_nubus_intr();
    314  1.1  scottr }
    315  1.1  scottr 
    316  1.1  scottr static int
    317  1.1  scottr ae_card_vendor(na)
    318  1.1  scottr 	struct nubus_attach_args *na;
    319  1.1  scottr {
    320  1.1  scottr 	int vendor;
    321  1.1  scottr 
    322  1.1  scottr 	switch (na->drsw) {
    323  1.1  scottr 	case NUBUS_DRSW_3COM:
    324  1.1  scottr 	case NUBUS_DRSW_APPLE:
    325  1.1  scottr 	case NUBUS_DRSW_TECHWORKS:
    326  1.1  scottr 		vendor = AE_VENDOR_APPLE;
    327  1.1  scottr 		break;
    328  1.1  scottr 	case NUBUS_DRSW_ASANTE:
    329  1.1  scottr 		vendor = AE_VENDOR_ASANTE;
    330  1.1  scottr 		break;
    331  1.1  scottr 	case NUBUS_DRSW_FARALLON:
    332  1.1  scottr 		vendor = AE_VENDOR_FARALLON;
    333  1.1  scottr 		break;
    334  1.1  scottr 	case NUBUS_DRSW_FOCUS:
    335  1.1  scottr 		vendor = AE_VENDOR_FOCUS;
    336  1.1  scottr 		break;
    337  1.1  scottr 	case NUBUS_DRSW_GATOR:
    338  1.1  scottr 		switch (na->drhw) {
    339  1.1  scottr 		default:
    340  1.1  scottr 		case NUBUS_DRHW_INTERLAN:
    341  1.1  scottr 			vendor = AE_VENDOR_INTERLAN;
    342  1.1  scottr 			break;
    343  1.1  scottr 		case NUBUS_DRHW_KINETICS:
    344  1.2  scottr 			if (strncmp(
    345  1.2  scottr 			    nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
    346  1.2  scottr 				vendor = AE_VENDOR_KINETICS;
    347  1.2  scottr 			else
    348  1.2  scottr 				vendor = AE_VENDOR_DAYNA;
    349  1.1  scottr 			break;
    350  1.1  scottr 		}
    351  1.1  scottr 		break;
    352  1.1  scottr 	default:
    353  1.1  scottr #ifdef AE_DEBUG
    354  1.1  scottr 		printf("Unknown ethernet drsw: %x\n", na->drsw);
    355  1.1  scottr #endif
    356  1.1  scottr 		vendor = AE_VENDOR_UNKNOWN;
    357  1.1  scottr 	}
    358  1.1  scottr 	return vendor;
    359  1.3  scottr }
    360  1.3  scottr 
    361  1.3  scottr static int
    362  1.3  scottr ae_get_enaddr(na, ep)
    363  1.3  scottr 	struct nubus_attach_args *na;
    364  1.3  scottr 	u_int8_t *ep;
    365  1.3  scottr {
    366  1.3  scottr 	nubus_dir dir;
    367  1.3  scottr 	nubus_dirent dirent;
    368  1.3  scottr 
    369  1.3  scottr 	/*
    370  1.3  scottr 	 * XXX - note hardwired resource IDs here (0x80); these are
    371  1.3  scottr 	 * assumed to be used by all cards, but should be fixed when
    372  1.3  scottr 	 * we find out more about Ethernet card resources.
    373  1.3  scottr 	 */
    374  1.3  scottr 	nubus_get_main_dir(na->fmt, &dir);
    375  1.3  scottr 	if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
    376  1.3  scottr 		return 1;
    377  1.3  scottr 	nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
    378  1.3  scottr 	if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
    379  1.3  scottr 		return 1;
    380  1.3  scottr 	if (nubus_get_ind_data(na->fmt, &dirent, ep, ETHER_ADDR_LEN) <= 0)
    381  1.3  scottr 		return 1;
    382  1.3  scottr 
    383  1.3  scottr 	return 0;
    384  1.1  scottr }
    385