1 /* $NetBSD: if_sm_nubus.c,v 1.4 2002/10/02 05:36:38 thorpej 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 "opt_inet.h" 31 32 #include <sys/param.h> 33 #include <sys/device.h> 34 #include <sys/errno.h> 35 #include <sys/ioctl.h> 36 #include <sys/socket.h> 37 #include <sys/syslog.h> 38 #include <sys/systm.h> 39 40 #include <net/if.h> 41 #include <net/if_ether.h> 42 #include <net/if_media.h> 43 44 #include <machine/bus.h> 45 #include <machine/viareg.h> 46 47 #include <dev/mii/mii.h> 48 #include <dev/mii/miivar.h> 49 50 #include <dev/ic/smc91cxxreg.h> 51 #include <dev/ic/smc91cxxvar.h> 52 53 #include <mac68k/nubus/nubus.h> 54 55 static int sm_nubus_match __P((struct device *, struct cfdata *, void *)); 56 static void sm_nubus_attach __P((struct device *, struct device *, void *)); 57 58 CFATTACH_DECL(sm_nubus, sizeof(struct smc91cxx_softc), 59 sm_nubus_match, sm_nubus_attach, NULL, NULL); 60 61 static int 62 sm_nubus_match(parent, cf, aux) 63 struct device *parent; 64 struct cfdata *cf; 65 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(parent, self, aux) 100 struct device *parent, *self; 101 void *aux; 102 { 103 struct smc91cxx_softc *smc = (struct smc91cxx_softc *) self; 104 struct nubus_attach_args *na = (struct nubus_attach_args *)aux; 105 bus_space_tag_t bst = na->na_tag; 106 bus_space_handle_t bsh, prom_bsh; 107 u_int8_t myaddr[ETHER_ADDR_LEN]; 108 int i, success; 109 char *cardtype; 110 111 bst = na->na_tag; 112 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) { 113 printf(": failed to map memory space.\n"); 114 return; 115 } 116 117 mac68k_bus_space_handle_swapped(bst, &bsh); 118 119 smc->sc_bst = bst; 120 smc->sc_bsh = bsh; 121 122 cardtype = nubus_get_card_name(bst, bsh, na->fmt); 123 124 success = 0; 125 126 switch (na->drsw) { 127 case NUBUS_DRSW_FOCUS: 128 if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) { 129 printf(": failed to map EEPROM space.\n"); 130 break; 131 } 132 133 success = 1; 134 break; 135 case NUBUS_DRSW_ASANTEF: 136 if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) { 137 printf(": failed to map EEPROM space.\n"); 138 break; 139 } 140 141 success = 1; 142 break; 143 } 144 145 if (!success) { 146 bus_space_unmap(bst, bsh, NBMEMSIZE); 147 return; 148 } 149 for (i=0 ; i<6 ; i++) { 150 myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4); 151 } 152 153 smc->sc_flags |= SMC_FLAGS_ENABLED; 154 155 printf(": %s\n", cardtype); 156 157 smc91cxx_attach(smc, myaddr); 158 159 add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc); 160 } 161