Home | History | Annotate | Line # | Download | only in nubus
if_sm_nubus.c revision 1.4
      1  1.4  thorpej /*	$NetBSD: if_sm_nubus.c,v 1.4 2002/10/02 05:36:38 thorpej Exp $	*/
      2  1.1   briggs 
      3  1.1   briggs /*
      4  1.1   briggs  * Copyright (c) 2000 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. The name of the author may not be used to endorse or promote products
     16  1.1   briggs  *    derived from this software without specific prior written permission.
     17  1.1   briggs  *
     18  1.1   briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1   briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1   briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1   briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1   briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1   briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1   briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1   briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1   briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1   briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1   briggs  */
     29  1.1   briggs 
     30  1.1   briggs #include "opt_inet.h"
     31  1.1   briggs 
     32  1.1   briggs #include <sys/param.h>
     33  1.1   briggs #include <sys/device.h>
     34  1.1   briggs #include <sys/errno.h>
     35  1.1   briggs #include <sys/ioctl.h>
     36  1.1   briggs #include <sys/socket.h>
     37  1.1   briggs #include <sys/syslog.h>
     38  1.1   briggs #include <sys/systm.h>
     39  1.1   briggs 
     40  1.1   briggs #include <net/if.h>
     41  1.1   briggs #include <net/if_ether.h>
     42  1.1   briggs #include <net/if_media.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.1   briggs #include <dev/mii/mii.h>
     48  1.1   briggs #include <dev/mii/miivar.h>
     49  1.1   briggs 
     50  1.1   briggs #include <dev/ic/smc91cxxreg.h>
     51  1.1   briggs #include <dev/ic/smc91cxxvar.h>
     52  1.1   briggs 
     53  1.1   briggs #include <mac68k/nubus/nubus.h>
     54  1.1   briggs 
     55  1.1   briggs static int	sm_nubus_match __P((struct device *, struct cfdata *, void *));
     56  1.1   briggs static void	sm_nubus_attach __P((struct device *, struct device *, void *));
     57  1.1   briggs 
     58  1.4  thorpej CFATTACH_DECL(sm_nubus, sizeof(struct smc91cxx_softc),
     59  1.4  thorpej     sm_nubus_match, sm_nubus_attach, NULL, NULL);
     60  1.1   briggs 
     61  1.1   briggs static int
     62  1.1   briggs sm_nubus_match(parent, cf, aux)
     63  1.1   briggs 	struct device *parent;
     64  1.1   briggs 	struct cfdata *cf;
     65  1.1   briggs 	void *aux;
     66  1.1   briggs {
     67  1.1   briggs 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
     68  1.1   briggs 	bus_space_handle_t bsh;
     69  1.1   briggs 	int rv;
     70  1.1   briggs 
     71  1.1   briggs 	if (bus_space_map(na->na_tag,
     72  1.1   briggs 	    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
     73  1.1   briggs 		return (0);
     74  1.1   briggs 
     75  1.1   briggs 	rv = 0;
     76  1.1   briggs 
     77  1.1   briggs 	if (na->category == NUBUS_CATEGORY_NETWORK &&
     78  1.1   briggs 	    na->type == NUBUS_TYPE_ETHERNET) {
     79  1.1   briggs 		switch (na->drsw) {
     80  1.1   briggs 	    	case NUBUS_DRSW_FOCUS:
     81  1.1   briggs 	    	case NUBUS_DRSW_ASANTEF:
     82  1.1   briggs 			rv = 1;
     83  1.1   briggs 			break;
     84  1.1   briggs 		default:
     85  1.1   briggs 			rv = 0;
     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.1   briggs sm_nubus_attach(parent, self, aux)
    100  1.1   briggs 	struct device *parent, *self;
    101  1.1   briggs 	void   *aux;
    102  1.1   briggs {
    103  1.1   briggs 	struct smc91cxx_softc *smc = (struct smc91cxx_softc *) self;
    104  1.1   briggs 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    105  1.1   briggs 	bus_space_tag_t	bst = na->na_tag;
    106  1.1   briggs 	bus_space_handle_t bsh, prom_bsh;
    107  1.1   briggs 	u_int8_t myaddr[ETHER_ADDR_LEN];
    108  1.1   briggs 	int i, success;
    109  1.1   briggs 	char *cardtype;
    110  1.1   briggs 
    111  1.1   briggs 	bst = na->na_tag;
    112  1.1   briggs 	if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
    113  1.1   briggs 		printf(": failed to map memory space.\n");
    114  1.1   briggs 		return;
    115  1.1   briggs 	}
    116  1.1   briggs 
    117  1.1   briggs 	mac68k_bus_space_handle_swapped(bst, &bsh);
    118  1.1   briggs 
    119  1.1   briggs 	smc->sc_bst = bst;
    120  1.1   briggs 	smc->sc_bsh = bsh;
    121  1.1   briggs 
    122  1.1   briggs 	cardtype = nubus_get_card_name(bst, bsh, na->fmt);
    123  1.1   briggs 
    124  1.1   briggs 	success = 0;
    125  1.1   briggs 
    126  1.1   briggs 	switch (na->drsw) {
    127  1.1   briggs 	case NUBUS_DRSW_FOCUS:
    128  1.1   briggs 		if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) {
    129  1.1   briggs 			printf(": failed to map EEPROM space.\n");
    130  1.1   briggs 			break;
    131  1.1   briggs 		}
    132  1.1   briggs 
    133  1.1   briggs 		success = 1;
    134  1.1   briggs 		break;
    135  1.1   briggs 	case NUBUS_DRSW_ASANTEF:
    136  1.1   briggs 		if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) {
    137  1.1   briggs 			printf(": failed to map EEPROM space.\n");
    138  1.1   briggs 			break;
    139  1.1   briggs 		}
    140  1.1   briggs 
    141  1.1   briggs 		success = 1;
    142  1.1   briggs 		break;
    143  1.1   briggs 	}
    144  1.1   briggs 
    145  1.1   briggs 	if (!success) {
    146  1.1   briggs 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    147  1.1   briggs 		return;
    148  1.1   briggs 	}
    149  1.1   briggs 	for (i=0 ; i<6 ; i++) {
    150  1.1   briggs 		myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4);
    151  1.1   briggs 	}
    152  1.1   briggs 
    153  1.1   briggs 	smc->sc_flags |= SMC_FLAGS_ENABLED;
    154  1.1   briggs 
    155  1.1   briggs 	printf(": %s\n", cardtype);
    156  1.1   briggs 
    157  1.1   briggs 	smc91cxx_attach(smc, myaddr);
    158  1.1   briggs 
    159  1.1   briggs 	add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc);
    160  1.1   briggs }
    161