1 /* $NetBSD: if_sm_nubus.c,v 1.2 2000/08/01 13:08:39 briggs 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 struct cfattach sm_nubus_ca = { 59 sizeof(struct smc91cxx_softc), sm_nubus_match, sm_nubus_attach 60 }; 61 62 static int 63 sm_nubus_match(parent, cf, aux) 64 struct device *parent; 65 struct cfdata *cf; 66 void *aux; 67 { 68 struct nubus_attach_args *na = (struct nubus_attach_args *) aux; 69 bus_space_handle_t bsh; 70 int rv; 71 72 if (bus_space_map(na->na_tag, 73 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) 74 return (0); 75 76 rv = 0; 77 78 if (na->category == NUBUS_CATEGORY_NETWORK && 79 na->type == NUBUS_TYPE_ETHERNET) { 80 switch (na->drsw) { 81 case NUBUS_DRSW_FOCUS: 82 case NUBUS_DRSW_ASANTEF: 83 rv = 1; 84 break; 85 default: 86 rv = 0; 87 break; 88 } 89 } 90 91 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE); 92 93 return rv; 94 } 95 96 /* 97 * Install interface into kernel networking data structures 98 */ 99 static void 100 sm_nubus_attach(parent, self, aux) 101 struct device *parent, *self; 102 void *aux; 103 { 104 struct smc91cxx_softc *smc = (struct smc91cxx_softc *) self; 105 struct nubus_attach_args *na = (struct nubus_attach_args *)aux; 106 bus_space_tag_t bst = na->na_tag; 107 bus_space_handle_t bsh, prom_bsh; 108 u_int8_t myaddr[ETHER_ADDR_LEN]; 109 int i, success; 110 char *cardtype; 111 112 bst = na->na_tag; 113 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) { 114 printf(": failed to map memory space.\n"); 115 return; 116 } 117 118 mac68k_bus_space_handle_swapped(bst, &bsh); 119 120 smc->sc_bst = bst; 121 smc->sc_bsh = bsh; 122 123 cardtype = nubus_get_card_name(bst, bsh, na->fmt); 124 125 success = 0; 126 127 switch (na->drsw) { 128 case NUBUS_DRSW_FOCUS: 129 if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) { 130 printf(": failed to map EEPROM space.\n"); 131 break; 132 } 133 134 success = 1; 135 break; 136 case NUBUS_DRSW_ASANTEF: 137 if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) { 138 printf(": failed to map EEPROM space.\n"); 139 break; 140 } 141 142 success = 1; 143 break; 144 } 145 146 if (!success) { 147 bus_space_unmap(bst, bsh, NBMEMSIZE); 148 return; 149 } 150 for (i=0 ; i<6 ; i++) { 151 myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4); 152 } 153 154 smc->sc_flags |= SMC_FLAGS_ENABLED; 155 156 printf(": %s\n", cardtype); 157 158 smc91cxx_attach(smc, myaddr); 159 160 add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc); 161 } 162