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