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