1 1.7 tsutsui /* $NetBSD: if_le.c,v 1.7 2008/04/04 12:25:06 tsutsui Exp $ */ 2 1.1 drochner 3 1.1 drochner /* 4 1.1 drochner * Copyright (c) 1997, 1999 5 1.1 drochner * Matthias Drochner. All rights reserved. 6 1.1 drochner * 7 1.1 drochner * Redistribution and use in source and binary forms, with or without 8 1.1 drochner * modification, are permitted provided that the following conditions 9 1.1 drochner * are met: 10 1.1 drochner * 1. Redistributions of source code must retain the above copyright 11 1.1 drochner * notice, this list of conditions and the following disclaimer. 12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 drochner * notice, this list of conditions and the following disclaimer in the 14 1.1 drochner * documentation and/or other materials provided with the distribution. 15 1.1 drochner * 16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 1.1 drochner * 27 1.1 drochner */ 28 1.4 lukem 29 1.4 lukem #include <sys/cdefs.h> 30 1.7 tsutsui __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.7 2008/04/04 12:25:06 tsutsui Exp $"); 31 1.1 drochner 32 1.1 drochner #include "opt_inet.h" 33 1.1 drochner 34 1.1 drochner #include <sys/param.h> 35 1.1 drochner #include <sys/systm.h> 36 1.1 drochner #include <sys/socket.h> 37 1.1 drochner #include <sys/device.h> 38 1.1 drochner 39 1.1 drochner #include <net/if.h> 40 1.1 drochner #include <net/if_ether.h> 41 1.1 drochner #include <net/if_media.h> 42 1.1 drochner 43 1.1 drochner #ifdef INET 44 1.1 drochner #include <netinet/in.h> 45 1.1 drochner #include <netinet/if_inarp.h> 46 1.1 drochner #endif 47 1.1 drochner 48 1.1 drochner #include <machine/cpu.h> 49 1.1 drochner #include <machine/pte.h> 50 1.1 drochner 51 1.1 drochner #include <machine/autoconf.h> 52 1.1 drochner 53 1.1 drochner #include <dev/ic/lancereg.h> 54 1.1 drochner #include <dev/ic/lancevar.h> 55 1.1 drochner #include <dev/ic/am79900reg.h> 56 1.1 drochner #include <dev/ic/am79900var.h> 57 1.1 drochner 58 1.1 drochner #include <cesfic/cesfic/isr.h> 59 1.1 drochner 60 1.7 tsutsui int lematch(device_t, cfdata_t, void *); 61 1.7 tsutsui void leattach(device_t, device_t, void *); 62 1.1 drochner 63 1.7 tsutsui CFATTACH_DECL_NEW(le, sizeof(struct am79900_softc), 64 1.3 thorpej lematch, leattach, NULL, NULL); 65 1.1 drochner 66 1.7 tsutsui int leintr(void *); 67 1.1 drochner 68 1.7 tsutsui void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 69 1.7 tsutsui uint16_t lerdcsr(struct lance_softc *, uint16_t); 70 1.1 drochner 71 1.1 drochner static char *lebase, *lemembase; 72 1.1 drochner 73 1.1 drochner void 74 1.7 tsutsui lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 75 1.1 drochner { 76 1.7 tsutsui 77 1.1 drochner *(volatile int *)(lebase + 4) = port; 78 1.1 drochner *(volatile int *)(lebase + 0) = val; 79 1.1 drochner } 80 1.1 drochner 81 1.7 tsutsui uint16_t 82 1.7 tsutsui lerdcsr(struct lance_softc *sc, uint16_t port) 83 1.1 drochner { 84 1.7 tsutsui uint16_t val; 85 1.1 drochner 86 1.1 drochner *(volatile int *)(lebase + 4) = port; 87 1.1 drochner val = *(volatile int *)(lebase + 0); 88 1.1 drochner return (val); 89 1.1 drochner } 90 1.1 drochner 91 1.1 drochner int 92 1.7 tsutsui lematch(device_t parent, cfdata_t cf, void *aux) 93 1.1 drochner { 94 1.7 tsutsui 95 1.1 drochner return (1); 96 1.1 drochner } 97 1.1 drochner 98 1.1 drochner /* 99 1.1 drochner * Interface exists: make available by filling in network interface 100 1.1 drochner * record. System will initialize the interface when it is ready 101 1.1 drochner * to accept packets. 102 1.1 drochner */ 103 1.7 tsutsui extern void sic_enable_int(int, int, int, int, int); 104 1.1 drochner static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23}; 105 1.1 drochner void 106 1.7 tsutsui leattach(device_t parent, device_t self, void *aux) 107 1.1 drochner { 108 1.7 tsutsui struct lance_softc *sc = device_private(self); 109 1.1 drochner int i; 110 1.1 drochner 111 1.5 cl mainbus_map(0x4c000000, 0x10000, 0, (void *)&lemembase); 112 1.5 cl mainbus_map(0x48000000, 0x1000, 0, (void *)&lebase); 113 1.1 drochner 114 1.7 tsutsui sc->sc_dev = self; 115 1.1 drochner sc->sc_mem = lemembase; 116 1.1 drochner sc->sc_conf3 = LE_C3_BSWP; 117 1.1 drochner sc->sc_addr = 0x4c000000; 118 1.1 drochner sc->sc_memsize = 64 * 1024; 119 1.1 drochner 120 1.1 drochner if (cesfic_getetheraddr(sc->sc_enaddr)) { 121 1.1 drochner /* fallback */ 122 1.1 drochner for (i = 0; i < sizeof(sc->sc_enaddr); i++) { 123 1.1 drochner sc->sc_enaddr[i] = hwa[i]; 124 1.1 drochner } 125 1.1 drochner } 126 1.1 drochner 127 1.1 drochner sc->sc_copytodesc = lance_copytobuf_contig; 128 1.1 drochner sc->sc_copyfromdesc = lance_copyfrombuf_contig; 129 1.1 drochner sc->sc_copytobuf = lance_copytobuf_contig; 130 1.1 drochner sc->sc_copyfrombuf = lance_copyfrombuf_contig; 131 1.1 drochner sc->sc_zerobuf = lance_zerobuf_contig; 132 1.1 drochner 133 1.1 drochner sc->sc_rdcsr = lerdcsr; 134 1.1 drochner sc->sc_wrcsr = lewrcsr; 135 1.1 drochner sc->sc_hwinit = NULL; 136 1.1 drochner 137 1.1 drochner lewrcsr(sc, 4, 0x44); 138 1.1 drochner am79900_config((struct am79900_softc *)sc); 139 1.1 drochner 140 1.1 drochner /* Establish the interrupt handler. */ 141 1.1 drochner (void) isrlink(leintr, sc, 3, ISRPRI_NET); 142 1.1 drochner sic_enable_int(17, 0, 1, 3, 0); 143 1.1 drochner } 144 1.1 drochner 145 1.1 drochner int 146 1.7 tsutsui leintr(void *arg) 147 1.1 drochner { 148 1.1 drochner struct lance_softc *sc = arg; 149 1.7 tsutsui uint16_t isr4; 150 1.1 drochner 151 1.1 drochner isr4 = lerdcsr(sc, 4); 152 1.1 drochner if (isr4 & 0x08) { 153 1.1 drochner lewrcsr(sc, 4, isr4); 154 1.1 drochner return (1); 155 1.1 drochner } 156 1.1 drochner 157 1.1 drochner return (am79900_intr(sc)); 158 1.1 drochner } 159