1 1.35 tsutsui /* $NetBSD: if_le_vme.c,v 1.35 2023/01/06 10:28:28 tsutsui Exp $ */ 2 1.18 agc 3 1.18 agc /*- 4 1.20 wiz * Copyright (c) 1998 maximum entropy. All rights reserved. 5 1.19 leo * Copyright (c) 1997 Leo Weppelman. All rights reserved. 6 1.18 agc * Copyright (c) 1992, 1993 7 1.18 agc * The Regents of the University of California. All rights reserved. 8 1.18 agc * 9 1.18 agc * This code is derived from software contributed to Berkeley by 10 1.18 agc * Ralph Campbell and Rick Macklem. 11 1.18 agc * 12 1.18 agc * Redistribution and use in source and binary forms, with or without 13 1.18 agc * modification, are permitted provided that the following conditions 14 1.18 agc * are met: 15 1.18 agc * 1. Redistributions of source code must retain the above copyright 16 1.18 agc * notice, this list of conditions and the following disclaimer. 17 1.18 agc * 2. Redistributions in binary form must reproduce the above copyright 18 1.18 agc * notice, this list of conditions and the following disclaimer in the 19 1.18 agc * documentation and/or other materials provided with the distribution. 20 1.18 agc * 3. Neither the name of the University nor the names of its contributors 21 1.18 agc * may be used to endorse or promote products derived from this software 22 1.18 agc * without specific prior written permission. 23 1.18 agc * 24 1.18 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 1.18 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 1.18 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 1.18 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 1.18 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 1.18 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 1.18 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 1.18 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 1.18 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 1.18 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 1.18 agc * SUCH DAMAGE. 35 1.18 agc * 36 1.18 agc * @(#)if_le.c 8.2 (Berkeley) 11/16/93 37 1.18 agc */ 38 1.1 leo 39 1.1 leo /*- 40 1.1 leo * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 41 1.1 leo * 42 1.1 leo * This code is derived from software contributed to Berkeley by 43 1.1 leo * Ralph Campbell and Rick Macklem. 44 1.1 leo * 45 1.1 leo * Redistribution and use in source and binary forms, with or without 46 1.1 leo * modification, are permitted provided that the following conditions 47 1.1 leo * are met: 48 1.1 leo * 1. Redistributions of source code must retain the above copyright 49 1.1 leo * notice, this list of conditions and the following disclaimer. 50 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright 51 1.1 leo * notice, this list of conditions and the following disclaimer in the 52 1.1 leo * documentation and/or other materials provided with the distribution. 53 1.1 leo * 3. All advertising materials mentioning features or use of this software 54 1.1 leo * must display the following acknowledgement: 55 1.1 leo * This product includes software developed by the University of 56 1.1 leo * California, Berkeley and its contributors. 57 1.1 leo * 4. Neither the name of the University nor the names of its contributors 58 1.1 leo * may be used to endorse or promote products derived from this software 59 1.1 leo * without specific prior written permission. 60 1.1 leo * 61 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 62 1.1 leo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 63 1.1 leo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 1.1 leo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 65 1.1 leo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 66 1.1 leo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 67 1.1 leo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 68 1.1 leo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 69 1.1 leo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 70 1.1 leo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 71 1.1 leo * SUCH DAMAGE. 72 1.1 leo * 73 1.1 leo * @(#)if_le.c 8.2 (Berkeley) 11/16/93 74 1.1 leo */ 75 1.17 lukem 76 1.17 lukem #include <sys/cdefs.h> 77 1.35 tsutsui __KERNEL_RCSID(0, "$NetBSD: if_le_vme.c,v 1.35 2023/01/06 10:28:28 tsutsui Exp $"); 78 1.1 leo 79 1.5 jonathan #include "opt_inet.h" 80 1.1 leo 81 1.1 leo #include <sys/param.h> 82 1.1 leo #include <sys/systm.h> 83 1.1 leo #include <sys/mbuf.h> 84 1.1 leo #include <sys/syslog.h> 85 1.1 leo #include <sys/socket.h> 86 1.1 leo #include <sys/device.h> 87 1.1 leo 88 1.1 leo #include <net/if.h> 89 1.3 thorpej #include <net/if_media.h> 90 1.4 leo #include <net/if_ether.h> 91 1.1 leo 92 1.1 leo #ifdef INET 93 1.1 leo #include <netinet/in.h> 94 1.4 leo #include <netinet/if_inarp.h> 95 1.1 leo #endif 96 1.1 leo 97 1.1 leo #include <machine/cpu.h> 98 1.31 dyoung #include <sys/bus.h> 99 1.1 leo #include <machine/iomap.h> 100 1.1 leo #include <machine/scu.h> 101 1.26 tsutsui #include <machine/intr.h> 102 1.1 leo 103 1.1 leo #include <atari/atari/device.h> 104 1.1 leo 105 1.6 drochner #include <dev/ic/lancereg.h> 106 1.6 drochner #include <dev/ic/lancevar.h> 107 1.1 leo #include <dev/ic/am7990reg.h> 108 1.1 leo #include <dev/ic/am7990var.h> 109 1.1 leo 110 1.1 leo #include <atari/vme/vmevar.h> 111 1.1 leo #include <atari/vme/if_levar.h> 112 1.1 leo 113 1.7 leo /* 114 1.32 tsutsui * All cards except BVME410 have 64KB RAM. However, 115 1.32 tsutsui * - On the Riebl cards the area between the offsets 0xee70-0xeec0 is used 116 1.32 tsutsui * to store config data. 117 1.32 tsutsui * - On PAM and ROTHRON, mem_addr cannot be mapped if reg_addr is already 118 1.32 tsutsui * mapped because they are overwrapped. Just use 32KB as Linux does. 119 1.7 leo */ 120 1.34 tsutsui static struct le_addresses { 121 1.1 leo u_long reg_addr; 122 1.1 leo u_long mem_addr; 123 1.1 leo int irq; 124 1.7 leo int reg_size; 125 1.7 leo int mem_size; 126 1.8 leo int type_hint; 127 1.1 leo } lestd[] = { 128 1.8 leo { 0xfe00fff0, 0xfe010000, IRQUNK, 16, 64*1024, 129 1.8 leo LE_OLD_RIEBL|LE_NEW_RIEBL }, /* Riebl */ 130 1.32 tsutsui { 0xfecffff0, 0xfecf0000, 5, 16, 32*1024, 131 1.8 leo LE_PAM }, /* PAM */ 132 1.32 tsutsui { 0xfecffff0, 0xfecf0000, 5, 16, 32*1024, 133 1.8 leo LE_ROTHRON }, /* Rhotron */ 134 1.8 leo { 0xfeff4100, 0xfe000000, 4, 8, VMECF_MEMSIZ_DEFAULT, 135 1.8 leo LE_BVME410 } /* BVME410 */ 136 1.1 leo }; 137 1.1 leo 138 1.23 tsutsui #define NLESTD __arraycount(lestd) 139 1.1 leo 140 1.1 leo /* 141 1.1 leo * Default mac for RIEBL cards without a (working) battery. The first 4 bytes 142 1.1 leo * are the manufacturer id. 143 1.1 leo */ 144 1.34 tsutsui static const uint8_t riebl_def_mac[] = { 145 1.1 leo 0x00, 0x00, 0x36, 0x04, 0x00, 0x00 146 1.1 leo }; 147 1.1 leo 148 1.23 tsutsui static int le_intr(struct le_softc *, int); 149 1.23 tsutsui static void lepseudointr(struct le_softc *, void *); 150 1.23 tsutsui static int le_vme_match(device_t, cfdata_t, void *); 151 1.23 tsutsui static void le_vme_attach(device_t, device_t, void *); 152 1.23 tsutsui static int probe_addresses(bus_space_tag_t *, bus_space_tag_t *, 153 1.23 tsutsui bus_space_handle_t *, bus_space_handle_t *); 154 1.23 tsutsui static void riebl_skip_reserved_area(struct lance_softc *); 155 1.23 tsutsui static int nm93c06_read(bus_space_tag_t, bus_space_handle_t, int); 156 1.23 tsutsui static int bvme410_probe(bus_space_tag_t, bus_space_handle_t); 157 1.23 tsutsui static int bvme410_mem_size(bus_space_tag_t, u_long); 158 1.23 tsutsui static void bvme410_copytobuf(struct lance_softc *, void *, int, int); 159 1.23 tsutsui static void bvme410_zerobuf(struct lance_softc *, int, int); 160 1.1 leo 161 1.23 tsutsui CFATTACH_DECL_NEW(le_vme, sizeof(struct le_softc), 162 1.16 thorpej le_vme_match, le_vme_attach, NULL, NULL); 163 1.1 leo 164 1.12 mrg #if defined(_KERNEL_OPT) 165 1.6 drochner #include "opt_ddb.h" 166 1.6 drochner #endif 167 1.6 drochner 168 1.34 tsutsui static void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 169 1.34 tsutsui static uint16_t lerdcsr(struct lance_softc *, uint16_t); 170 1.6 drochner 171 1.34 tsutsui static void 172 1.23 tsutsui lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 173 1.1 leo { 174 1.34 tsutsui struct le_softc *lesc = (struct le_softc *)sc; 175 1.34 tsutsui int s; 176 1.1 leo 177 1.1 leo s = splhigh(); 178 1.1 leo bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RAP, port); 179 1.1 leo bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RDP, val); 180 1.1 leo splx(s); 181 1.1 leo } 182 1.1 leo 183 1.34 tsutsui static uint16_t 184 1.23 tsutsui lerdcsr(struct lance_softc *sc, uint16_t port) 185 1.1 leo { 186 1.34 tsutsui struct le_softc *lesc = (struct le_softc *)sc; 187 1.34 tsutsui uint16_t val; 188 1.34 tsutsui int s; 189 1.1 leo 190 1.1 leo s = splhigh(); 191 1.1 leo bus_space_write_2(lesc->sc_iot, lesc->sc_ioh, LER_RAP, port); 192 1.35 tsutsui val = bus_space_read_2(lesc->sc_iot, lesc->sc_ioh, LER_RDP); 193 1.1 leo splx(s); 194 1.1 leo 195 1.30 tsutsui return val; 196 1.1 leo } 197 1.1 leo 198 1.1 leo static int 199 1.23 tsutsui le_vme_match(device_t parent, cfdata_t cfp, void *aux) 200 1.1 leo { 201 1.34 tsutsui struct vme_attach_args *va = aux; 202 1.34 tsutsui int i; 203 1.34 tsutsui bus_space_tag_t iot, memt; 204 1.34 tsutsui bus_space_handle_t ioh, memh; 205 1.1 leo 206 1.1 leo iot = va->va_iot; 207 1.1 leo memt = va->va_memt; 208 1.1 leo 209 1.1 leo for (i = 0; i < NLESTD; i++) { 210 1.34 tsutsui struct le_addresses *le_ap = &lestd[i]; 211 1.34 tsutsui int found; 212 1.1 leo 213 1.1 leo if ((va->va_iobase != IOBASEUNK) 214 1.1 leo && (va->va_iobase != le_ap->reg_addr)) 215 1.1 leo continue; 216 1.1 leo 217 1.1 leo if ((va->va_maddr != MADDRUNK) 218 1.1 leo && (va->va_maddr != le_ap->mem_addr)) 219 1.1 leo continue; 220 1.1 leo 221 1.1 leo if ((le_ap->irq != IRQUNK) && (va->va_irq != le_ap->irq)) 222 1.1 leo continue; 223 1.1 leo 224 1.30 tsutsui if (bus_space_map(iot, le_ap->reg_addr, le_ap->reg_size, 0, 225 1.30 tsutsui &ioh)) { 226 1.33 tsutsui continue; 227 1.1 leo } 228 1.7 leo if (le_ap->mem_size == VMECF_MEMSIZ_DEFAULT) { 229 1.9 leo if (bvme410_probe(iot, ioh)) { 230 1.30 tsutsui bus_space_write_2(iot, ioh, 231 1.30 tsutsui BVME410_BAR, 0x1); /* XXX */ 232 1.30 tsutsui le_ap->mem_size = 233 1.30 tsutsui bvme410_mem_size(memt, le_ap->mem_addr); 234 1.7 leo } 235 1.7 leo } 236 1.7 leo if (le_ap->mem_size == VMECF_MEMSIZ_DEFAULT) { 237 1.11 leo bus_space_unmap(iot, ioh, le_ap->reg_size); 238 1.7 leo continue; 239 1.7 leo } 240 1.7 leo 241 1.30 tsutsui if (bus_space_map(memt, le_ap->mem_addr, le_ap->mem_size, 0, 242 1.30 tsutsui &memh)) { 243 1.11 leo bus_space_unmap(iot, ioh, le_ap->reg_size); 244 1.33 tsutsui continue; 245 1.1 leo } 246 1.1 leo found = probe_addresses(&iot, &memt, &ioh, &memh); 247 1.11 leo bus_space_unmap(iot, ioh, le_ap->reg_size); 248 1.11 leo bus_space_unmap(memt, memh, le_ap->mem_size); 249 1.1 leo 250 1.1 leo if (found) { 251 1.1 leo va->va_iobase = le_ap->reg_addr; 252 1.7 leo va->va_iosize = le_ap->reg_size; 253 1.1 leo va->va_maddr = le_ap->mem_addr; 254 1.7 leo va->va_msize = le_ap->mem_size; 255 1.8 leo va->va_aux = le_ap; 256 1.1 leo if (va->va_irq == IRQUNK) 257 1.1 leo va->va_irq = le_ap->irq; 258 1.1 leo return 1; 259 1.1 leo } 260 1.30 tsutsui } 261 1.30 tsutsui return 0; 262 1.1 leo } 263 1.1 leo 264 1.1 leo static int 265 1.23 tsutsui probe_addresses(bus_space_tag_t *iot, bus_space_tag_t *memt, 266 1.23 tsutsui bus_space_handle_t *ioh, bus_space_handle_t *memh) 267 1.1 leo { 268 1.23 tsutsui 269 1.1 leo /* 270 1.1 leo * Test accesibility of register and memory area 271 1.1 leo */ 272 1.23 tsutsui if (!bus_space_peek_2(*iot, *ioh, LER_RDP)) 273 1.1 leo return 0; 274 1.23 tsutsui if (!bus_space_peek_1(*memt, *memh, 0)) 275 1.1 leo return 0; 276 1.1 leo 277 1.1 leo /* 278 1.1 leo * Test for writable memory 279 1.1 leo */ 280 1.1 leo bus_space_write_2(*memt, *memh, 0, 0xa5a5); 281 1.1 leo if (bus_space_read_2(*memt, *memh, 0) != 0xa5a5) 282 1.1 leo return 0; 283 1.1 leo 284 1.1 leo /* 285 1.1 leo * Test writability of selector port. 286 1.1 leo */ 287 1.1 leo bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR1); 288 1.1 leo if (bus_space_read_2(*iot, *ioh, LER_RAP) != LE_CSR1) 289 1.1 leo return 0; 290 1.1 leo 291 1.1 leo /* 292 1.1 leo * Do a small register test 293 1.1 leo */ 294 1.1 leo bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR0); 295 1.1 leo bus_space_write_2(*iot, *ioh, LER_RDP, LE_C0_INIT | LE_C0_STOP); 296 1.1 leo if (bus_space_read_2(*iot, *ioh, LER_RDP) != LE_C0_STOP) 297 1.1 leo return 0; 298 1.1 leo 299 1.1 leo bus_space_write_2(*iot, *ioh, LER_RDP, LE_C0_STOP); 300 1.1 leo if (bus_space_read_2(*iot, *ioh, LER_RDP) != LE_C0_STOP) 301 1.1 leo return 0; 302 1.1 leo 303 1.1 leo return 1; 304 1.1 leo } 305 1.1 leo 306 1.1 leo /* 307 1.1 leo * Interrupt mess. Because the card's interrupt is hardwired to either 308 1.1 leo * ipl5 or ipl3 (mostly on ipl5) and raising splnet to spl5() just won't do 309 1.13 wiz * (it kills the serial at the least), we use a 2-level interrupt scheme. The 310 1.1 leo * card interrupt is routed to 'le_intr'. If the previous ipl was below 311 1.1 leo * splnet, just call the mi-function. If not, save the interrupt status, 312 1.1 leo * turn off card interrupts (the card is *very* persistent) and arrange 313 1.1 leo * for a softint 'callback' through 'lepseudointr'. 314 1.1 leo */ 315 1.1 leo static int 316 1.23 tsutsui le_intr(struct le_softc *lesc, int sr) 317 1.1 leo { 318 1.34 tsutsui struct lance_softc *sc = &lesc->sc_am7990.lsc; 319 1.34 tsutsui uint16_t csr0; 320 1.1 leo 321 1.24 isaki if ((sr & PSL_IPL) < (ipl2psl_table[IPL_NET] & PSL_IPL)) 322 1.1 leo am7990_intr(sc); 323 1.1 leo else { 324 1.1 leo sc->sc_saved_csr0 = csr0 = lerdcsr(sc, LE_CSR0); 325 1.1 leo lewrcsr(sc, LE_CSR0, csr0 & ~LE_C0_INEA); 326 1.1 leo add_sicallback((si_farg)lepseudointr, lesc, sc); 327 1.1 leo } 328 1.1 leo return 1; 329 1.1 leo } 330 1.1 leo 331 1.1 leo 332 1.1 leo static void 333 1.23 tsutsui lepseudointr(struct le_softc *lesc, void *sc) 334 1.1 leo { 335 1.34 tsutsui int s; 336 1.1 leo 337 1.1 leo s = splx(lesc->sc_splval); 338 1.1 leo am7990_intr(sc); 339 1.1 leo splx(s); 340 1.1 leo } 341 1.1 leo 342 1.1 leo static void 343 1.23 tsutsui le_vme_attach(device_t parent, device_t self, void *aux) 344 1.1 leo { 345 1.34 tsutsui struct le_softc *lesc = device_private(self); 346 1.34 tsutsui struct lance_softc *sc = &lesc->sc_am7990.lsc; 347 1.34 tsutsui struct vme_attach_args *va = aux; 348 1.34 tsutsui bus_space_tag_t iot, memt; 349 1.34 tsutsui bus_space_handle_t ioh, memh; 350 1.34 tsutsui struct le_addresses *le_ap; 351 1.34 tsutsui int i; 352 1.1 leo 353 1.23 tsutsui sc->sc_dev = self; 354 1.23 tsutsui aprint_normal("\n%s: ", device_xname(self)); 355 1.1 leo 356 1.34 tsutsui iot = va->va_iot; 357 1.34 tsutsui memt = va->va_memt; 358 1.34 tsutsui if (bus_space_map(iot, va->va_iobase, va->va_iosize, 0, &ioh)) 359 1.34 tsutsui panic("%s: cannot map io-area", __func__); 360 1.34 tsutsui if (bus_space_map(memt, va->va_maddr, va->va_msize, 0, &memh)) 361 1.34 tsutsui panic("%s: cannot map mem-area", __func__); 362 1.1 leo 363 1.34 tsutsui lesc->sc_iot = iot; 364 1.1 leo lesc->sc_ioh = ioh; 365 1.34 tsutsui lesc->sc_memt = memt; 366 1.1 leo lesc->sc_memh = memh; 367 1.1 leo lesc->sc_splval = (va->va_irq << 8) | PSL_S; /* XXX */ 368 1.8 leo le_ap = (struct le_addresses *)va->va_aux; 369 1.1 leo 370 1.1 leo /* 371 1.1 leo * Go on to find board type 372 1.1 leo */ 373 1.34 tsutsui if ((le_ap->type_hint & LE_PAM) != 0 && 374 1.34 tsutsui bus_space_peek_1(iot, ioh, LER_EEPROM)) { 375 1.23 tsutsui aprint_normal("PAM card"); 376 1.1 leo lesc->sc_type = LE_PAM; 377 1.34 tsutsui bus_space_read_1(iot, ioh, LER_MEME); 378 1.34 tsutsui } else if ((le_ap->type_hint & LE_BVME410) != 0 && 379 1.34 tsutsui bvme410_probe(iot, ioh)) { 380 1.23 tsutsui aprint_normal("BVME410"); 381 1.7 leo lesc->sc_type = LE_BVME410; 382 1.34 tsutsui } else if ((le_ap->type_hint & (LE_NEW_RIEBL|LE_OLD_RIEBL)) != 0) { 383 1.23 tsutsui aprint_normal("Riebl card"); 384 1.34 tsutsui if (bus_space_read_4(memt, memh, RIEBL_MAGIC_ADDR) == 385 1.30 tsutsui RIEBL_MAGIC) 386 1.1 leo lesc->sc_type = LE_NEW_RIEBL; 387 1.1 leo else { 388 1.23 tsutsui aprint_normal("(without battery) "); 389 1.1 leo lesc->sc_type = LE_OLD_RIEBL; 390 1.1 leo } 391 1.34 tsutsui } else { 392 1.34 tsutsui aprint_error("Unsupported card!\n"); 393 1.34 tsutsui return; 394 1.34 tsutsui } 395 1.1 leo 396 1.7 leo switch (lesc->sc_type) { 397 1.30 tsutsui case LE_BVME410: 398 1.7 leo sc->sc_copytodesc = bvme410_copytobuf; 399 1.7 leo sc->sc_copyfromdesc = lance_copyfrombuf_contig; 400 1.7 leo sc->sc_copytobuf = bvme410_copytobuf; 401 1.7 leo sc->sc_copyfrombuf = lance_copyfrombuf_contig; 402 1.7 leo sc->sc_zerobuf = bvme410_zerobuf; 403 1.7 leo break; 404 1.30 tsutsui default: 405 1.7 leo sc->sc_copytodesc = lance_copytobuf_contig; 406 1.7 leo sc->sc_copyfromdesc = lance_copyfrombuf_contig; 407 1.7 leo sc->sc_copytobuf = lance_copytobuf_contig; 408 1.7 leo sc->sc_copyfrombuf = lance_copyfrombuf_contig; 409 1.7 leo sc->sc_zerobuf = lance_zerobuf_contig; 410 1.7 leo break; 411 1.7 leo } 412 1.1 leo 413 1.1 leo sc->sc_rdcsr = lerdcsr; 414 1.1 leo sc->sc_wrcsr = lewrcsr; 415 1.1 leo sc->sc_hwinit = NULL; 416 1.1 leo sc->sc_conf3 = LE_C3_BSWP; 417 1.1 leo sc->sc_addr = 0; 418 1.1 leo sc->sc_memsize = va->va_msize; 419 1.1 leo sc->sc_mem = (void *)memh; /* XXX */ 420 1.1 leo 421 1.1 leo /* 422 1.1 leo * Get MAC address 423 1.1 leo */ 424 1.1 leo switch (lesc->sc_type) { 425 1.30 tsutsui case LE_OLD_RIEBL: 426 1.34 tsutsui memcpy(sc->sc_enaddr, riebl_def_mac, sizeof(sc->sc_enaddr)); 427 1.1 leo break; 428 1.30 tsutsui case LE_NEW_RIEBL: 429 1.4 leo for (i = 0; i < sizeof(sc->sc_enaddr); i++) 430 1.34 tsutsui sc->sc_enaddr[i] = 431 1.34 tsutsui bus_space_read_1(memt, memh, i + RIEBL_MAC_ADDR); 432 1.34 tsutsui break; 433 1.30 tsutsui case LE_PAM: 434 1.34 tsutsui i = bus_space_read_1(iot, ioh, LER_EEPROM); 435 1.4 leo for (i = 0; i < sizeof(sc->sc_enaddr); i++) { 436 1.34 tsutsui sc->sc_enaddr[i] = 437 1.34 tsutsui (bus_space_read_2(memt, memh, 2 * i) << 4) | 438 1.34 tsutsui (bus_space_read_2(memt, memh, 2 * i + 1) & 0xf); 439 1.1 leo } 440 1.34 tsutsui i = bus_space_read_1(iot, ioh, LER_MEME); 441 1.1 leo break; 442 1.30 tsutsui case LE_BVME410: 443 1.7 leo for (i = 0; i < (sizeof(sc->sc_enaddr) >> 1); i++) { 444 1.34 tsutsui uint16_t tmp; 445 1.7 leo 446 1.34 tsutsui tmp = nm93c06_read(iot, ioh, i); 447 1.34 tsutsui sc->sc_enaddr[2 * i] = (tmp >> 8) & 0xff; 448 1.34 tsutsui sc->sc_enaddr[2 * i + 1] = tmp & 0xff; 449 1.7 leo } 450 1.34 tsutsui bus_space_write_2(iot, ioh, BVME410_BAR, 0x1); /* XXX */ 451 1.1 leo } 452 1.1 leo 453 1.6 drochner am7990_config(&lesc->sc_am7990); 454 1.1 leo 455 1.1 leo if ((lesc->sc_type == LE_OLD_RIEBL) || (lesc->sc_type == LE_NEW_RIEBL)) 456 1.1 leo riebl_skip_reserved_area(sc); 457 1.1 leo 458 1.1 leo /* 459 1.1 leo * XXX: We always use uservector 64.... 460 1.1 leo */ 461 1.35 tsutsui if ((lesc->sc_intr = intr_establish(64, USER_VEC, 0, 462 1.30 tsutsui (hw_ifun_t)le_intr, lesc)) == NULL) { 463 1.23 tsutsui aprint_error("le_vme_attach: Can't establish interrupt\n"); 464 1.1 leo return; 465 1.1 leo } 466 1.1 leo 467 1.1 leo /* 468 1.1 leo * Notify the card of the vector 469 1.1 leo */ 470 1.1 leo switch (lesc->sc_type) { 471 1.34 tsutsui case LE_OLD_RIEBL: 472 1.34 tsutsui case LE_NEW_RIEBL: 473 1.34 tsutsui bus_space_write_2(memt, memh, RIEBL_IVEC_ADDR, 64 + 64); 474 1.34 tsutsui break; 475 1.34 tsutsui case LE_PAM: 476 1.34 tsutsui bus_space_write_1(iot, ioh, LER_IVEC, 64 + 64); 477 1.34 tsutsui break; 478 1.34 tsutsui case LE_BVME410: 479 1.34 tsutsui bus_space_write_2(iot, ioh, BVME410_IVEC, 64 + 64); 480 1.34 tsutsui break; 481 1.1 leo } 482 1.1 leo 483 1.1 leo /* 484 1.1 leo * Unmask the VME-interrupt we're on 485 1.1 leo */ 486 1.34 tsutsui if ((machineid & ATARI_TT) != 0) 487 1.1 leo SCU->vme_mask |= 1 << va->va_irq; 488 1.1 leo } 489 1.1 leo 490 1.1 leo /* 491 1.1 leo * True if 'addr' containe within [start,len] 492 1.1 leo */ 493 1.1 leo #define WITHIN(start, len, addr) \ 494 1.1 leo ((addr >= start) && ((addr) <= ((start) + (len)))) 495 1.1 leo static void 496 1.23 tsutsui riebl_skip_reserved_area(struct lance_softc *sc) 497 1.1 leo { 498 1.34 tsutsui int offset = 0; 499 1.34 tsutsui int i; 500 1.1 leo 501 1.30 tsutsui for (i = 0; i < sc->sc_nrbuf; i++) { 502 1.30 tsutsui if (WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_START) || 503 1.30 tsutsui WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_END)) { 504 1.1 leo offset = RIEBL_RES_END - sc->sc_rbufaddr[i]; 505 1.1 leo } 506 1.1 leo sc->sc_rbufaddr[i] += offset; 507 1.1 leo } 508 1.1 leo 509 1.30 tsutsui for (i = 0; i < sc->sc_ntbuf; i++) { 510 1.30 tsutsui if (WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_START) || 511 1.30 tsutsui WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_END)) { 512 1.1 leo offset = RIEBL_RES_END - sc->sc_tbufaddr[i]; 513 1.1 leo } 514 1.1 leo sc->sc_tbufaddr[i] += offset; 515 1.1 leo } 516 1.1 leo } 517 1.7 leo 518 1.7 leo static int 519 1.23 tsutsui nm93c06_read(bus_space_tag_t iot, bus_space_handle_t ioh, int nm93c06reg) 520 1.7 leo { 521 1.7 leo int bar; 522 1.7 leo int shift; 523 1.7 leo int bits = 0x180 | (nm93c06reg & 0xf); 524 1.7 leo int data = 0; 525 1.7 leo 526 1.23 tsutsui bar = 1 << BVME410_CS_SHIFT; 527 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 528 1.7 leo delay(1); /* tCSS = 1 us */ 529 1.7 leo for (shift = 9; shift >= 0; shift--) { 530 1.7 leo if (((bits >> shift) & 1) == 1) 531 1.23 tsutsui bar |= 1 << BVME410_DIN_SHIFT; 532 1.7 leo else 533 1.23 tsutsui bar &= ~(1 << BVME410_DIN_SHIFT); 534 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 535 1.7 leo delay(1); /* tDIS = 0.4 us */ 536 1.23 tsutsui bar |= 1 << BVME410_CLK_SHIFT; 537 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 538 1.7 leo delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */ 539 1.23 tsutsui bar &= ~(1 << BVME410_CLK_SHIFT); 540 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 541 1.7 leo delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */ 542 1.7 leo } 543 1.23 tsutsui bar &= ~(1 << BVME410_DIN_SHIFT); 544 1.7 leo for (shift = 15; shift >= 0; shift--) { 545 1.7 leo delay(1); /* tDIS = 100 ns, BVM manual says 0.4 us */ 546 1.23 tsutsui bar |= 1 << BVME410_CLK_SHIFT; 547 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 548 1.7 leo delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */ 549 1.7 leo data |= (bus_space_read_2(iot, ioh, BVME410_BAR) & 1) << shift; 550 1.23 tsutsui bar &= ~(1 << BVME410_CLK_SHIFT); 551 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 552 1.7 leo delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */ 553 1.7 leo } 554 1.23 tsutsui bar &= ~(1 << BVME410_CS_SHIFT); 555 1.7 leo bus_space_write_2(iot, ioh, BVME410_BAR, bar); 556 1.7 leo delay(1); /* tCS = 1 us */ 557 1.7 leo return data; 558 1.7 leo } 559 1.7 leo 560 1.7 leo static int 561 1.23 tsutsui bvme410_probe(bus_space_tag_t iot, bus_space_handle_t ioh) 562 1.9 leo { 563 1.23 tsutsui 564 1.9 leo if (!bus_space_peek_2(iot, ioh, BVME410_IVEC)) 565 1.9 leo return 0; 566 1.9 leo 567 1.9 leo bus_space_write_2(iot, ioh, BVME410_IVEC, 0x0000); 568 1.9 leo if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xff00) 569 1.9 leo return 0; 570 1.35 tsutsui 571 1.9 leo bus_space_write_2(iot, ioh, BVME410_IVEC, 0xffff); 572 1.9 leo if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xffff) 573 1.9 leo return 0; 574 1.9 leo 575 1.9 leo bus_space_write_2(iot, ioh, BVME410_IVEC, 0xa5a5); 576 1.9 leo if (bus_space_read_2(iot, ioh, BVME410_IVEC) != 0xffa5) 577 1.9 leo return 0; 578 1.9 leo 579 1.9 leo return 1; 580 1.9 leo } 581 1.9 leo 582 1.9 leo static int 583 1.23 tsutsui bvme410_mem_size(bus_space_tag_t memt, u_long mem_addr) 584 1.7 leo { 585 1.7 leo bus_space_handle_t memh; 586 1.7 leo int r; 587 1.7 leo 588 1.23 tsutsui if (bus_space_map(memt, mem_addr, 256 * 1024, 0, &memh)) 589 1.7 leo return VMECF_MEMSIZ_DEFAULT; 590 1.7 leo if (!bus_space_peek_1(memt, memh, 0)) { 591 1.23 tsutsui bus_space_unmap(memt, memh, 256 * 1024); 592 1.7 leo return VMECF_MEMSIZ_DEFAULT; 593 1.7 leo } 594 1.7 leo bus_space_write_1(memt, memh, 0, 128); 595 1.23 tsutsui bus_space_write_1(memt, memh, 64 * 1024, 32); 596 1.23 tsutsui bus_space_write_1(memt, memh, 32 * 1024, 8); 597 1.7 leo r = (int)(bus_space_read_1(memt, memh, 0) * 2048); 598 1.23 tsutsui bus_space_unmap(memt, memh, 256 * 1024); 599 1.7 leo return r; 600 1.7 leo } 601 1.7 leo 602 1.7 leo /* 603 1.7 leo * Need to be careful when writing to the bvme410 dual port memory. 604 1.7 leo * Continue writing each byte until it reads back the same. 605 1.7 leo */ 606 1.7 leo 607 1.7 leo static void 608 1.23 tsutsui bvme410_copytobuf(struct lance_softc *sc, void *from, int boff, int len) 609 1.7 leo { 610 1.34 tsutsui volatile uint8_t *buf = (volatile uint8_t *)sc->sc_mem; 611 1.34 tsutsui uint8_t *f = (uint8_t *)from; 612 1.7 leo 613 1.34 tsutsui for (buf += boff; len != 0; buf++, f++, len--) { 614 1.9 leo do { 615 1.35 tsutsui *buf = *f; 616 1.9 leo } while (*buf != *f); 617 1.34 tsutsui } 618 1.7 leo } 619 1.7 leo 620 1.7 leo static void 621 1.23 tsutsui bvme410_zerobuf(struct lance_softc *sc, int boff, int len) 622 1.7 leo { 623 1.34 tsutsui volatile uint8_t *buf = (volatile uint8_t *)sc->sc_mem; 624 1.7 leo 625 1.34 tsutsui for (buf += boff; len != 0; buf++, len--) { 626 1.9 leo do { 627 1.35 tsutsui *buf = '\0'; 628 1.9 leo } while (*buf != '\0'); 629 1.34 tsutsui } 630 1.7 leo } 631