1 /* $NetBSD: if_ze.c,v 1.16 2010/01/19 22:06:23 pooka Exp $ */ 2 /* 3 * Copyright (c) 1999 Ludd, University of Lule}, Sweden. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed at Ludd, University of 16 * Lule}, Sweden and its contributors. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: if_ze.c,v 1.16 2010/01/19 22:06:23 pooka Exp $"); 34 35 #include "opt_cputype.h" 36 37 #include <sys/param.h> 38 #include <sys/socket.h> 39 #include <sys/device.h> 40 #include <sys/systm.h> 41 #include <sys/sockio.h> 42 43 #include <net/if.h> 44 #include <net/if_ether.h> 45 #include <net/if_dl.h> 46 47 #include <netinet/in.h> 48 #include <netinet/if_inarp.h> 49 50 #include <machine/bus.h> 51 #include <machine/nexus.h> 52 #include <machine/cpu.h> 53 #include <machine/scb.h> 54 #include <machine/sid.h> 55 #include <machine/mainbus.h> 56 57 #include <dev/ic/sgecreg.h> 58 #include <dev/ic/sgecvar.h> 59 60 #include "ioconf.h" 61 62 /* 63 * Addresses. 64 */ 65 #define SGECADDR 0x20008000 66 #define NISA_ROM 0x20084000 67 #define NISA_ROM_VXT 0x200c4000 68 #define NISA_ROM_VSBUS 0x27800000 69 #define SGECVEC 0x108 70 71 static int ze_mainbus_match(device_t, cfdata_t, void *); 72 static void ze_mainbus_attach(device_t, device_t, void *); 73 74 static const struct sgec_data { 75 uint32_t sd_boardtype; 76 bus_addr_t sd_addr; 77 bus_addr_t sd_rom; 78 uint16_t sd_intvec; 79 uint8_t sd_romshift; 80 } sgec_data[] = { 81 { VAX_BTYP_660, SGECADDR, NISA_ROM, SGECVEC, 24, }, 82 #if VXT2000 || VAXANY 83 { VAX_BTYP_VXT, SGECADDR, NISA_ROM_VXT, 0x200, 0, }, 84 #endif 85 { VAX_BTYP_670, SGECADDR, NISA_ROM, SGECVEC, 8, }, 86 { VAX_BTYP_680, SGECADDR, NISA_ROM, SGECVEC, 8, }, 87 { VAX_BTYP_681, SGECADDR, NISA_ROM, SGECVEC, 8, }, 88 { VAX_BTYP_48, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, }, 89 { VAX_BTYP_49, SGECADDR, NISA_ROM_VSBUS, SGECVEC, 0, }, 90 { VAX_BTYP_53, SGECADDR, NISA_ROM, SGECVEC, 8, }, 91 }; 92 93 static const struct sgec_data * 94 ze_find(void) 95 { 96 size_t i; 97 const struct sgec_data *sd; 98 for (i = 0, sd = sgec_data; i < __arraycount(sgec_data); i++, sd++) { 99 if (vax_boardtype == sd->sd_boardtype) 100 return sd; 101 } 102 103 return NULL; 104 } 105 106 CFATTACH_DECL_NEW(ze_mainbus, sizeof(struct ze_softc), 107 ze_mainbus_match, ze_mainbus_attach, NULL, NULL); 108 109 /* 110 * Check for present SGEC. 111 */ 112 int 113 ze_mainbus_match(device_t parent, cfdata_t cf, void *aux) 114 { 115 struct mainbus_attach_args * const ma = aux; 116 117 /* 118 * Should some more intelligent checking be done??? 119 */ 120 if (strcmp(ma->ma_type, "sgec")) 121 return 0; 122 123 return ze_find() != NULL; 124 } 125 126 /* 127 * Interface exists: make available by filling in network interface 128 * record. System will initialize the interface when it is ready 129 * to accept packets. 130 */ 131 void 132 ze_mainbus_attach(device_t parent, device_t self, void *aux) 133 { 134 struct mainbus_attach_args * const ma = aux; 135 struct ze_softc * const sc = device_private(self); 136 const struct sgec_data * const sd = ze_find(); 137 const uint32_t *ea; 138 size_t i; 139 int error; 140 141 sc->sc_dev = self; 142 143 /* 144 * Map in SGEC registers. 145 */ 146 sc->sc_dmat = ma->ma_dmat; 147 sc->sc_iot = ma->ma_iot; 148 sc->sc_intvec = sd->sd_intvec; 149 error = bus_space_map(sc->sc_iot, sd->sd_addr, PAGE_SIZE, 0, 150 &sc->sc_ioh); 151 if (error) { 152 aprint_error(": failed to map %#lx: %d\n", sd->sd_addr, error); 153 return; 154 } 155 156 /* 157 * Map in, read and release ethernet rom address. 158 */ 159 ea = (uint32_t *)vax_map_physmem(sd->sd_rom, 1); 160 for (i = 0; i < ETHER_ADDR_LEN; i++) 161 sc->sc_enaddr[i] = (ea[i] >> sd->sd_romshift) & 0377; 162 vax_unmap_physmem((vaddr_t)ea, 1); 163 164 scb_vecalloc(sc->sc_intvec, (void (*)(void *)) sgec_intr, sc, 165 SCB_ISTACK, &sc->sc_intrcnt); 166 167 sgec_attach(sc); 168 } 169