1 /* $NetBSD: if_le.c,v 1.18 2010/01/19 22:06:21 pooka Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass and Gordon W. Ross. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * news68k/dev/if_le.c - based on newsmips/dev/if_le.c 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.18 2010/01/19 22:06:21 pooka Exp $"); 38 39 #include "opt_inet.h" 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/mbuf.h> 44 #include <sys/socket.h> 45 #include <sys/device.h> 46 47 #include <net/if.h> 48 #include <net/if_ether.h> 49 #include <net/if_media.h> 50 51 #ifdef INET 52 #include <netinet/in.h> 53 #include <netinet/if_inarp.h> 54 #endif 55 56 #include <machine/cpu.h> 57 58 #include <news68k/dev/hbvar.h> 59 60 #include <dev/ic/lancereg.h> 61 #include <dev/ic/lancevar.h> 62 #include <dev/ic/am7990reg.h> 63 #include <dev/ic/am7990var.h> 64 65 #include "ioconf.h" 66 67 /* 68 * LANCE registers. 69 * The real stuff is in dev/ic/am7990reg.h 70 */ 71 struct lereg1 { 72 volatile uint16_t ler1_rdp; /* data port */ 73 volatile uint16_t ler1_rap; /* register select port */ 74 }; 75 76 /* 77 * Ethernet software status per interface. 78 * The real stuff is in dev/ic/am7990var.h 79 */ 80 struct le_softc { 81 struct am7990_softc sc_am7990; /* glue to MI code */ 82 83 struct lereg1 *sc_r1; /* LANCE registers */ 84 }; 85 86 static int le_match(device_t, cfdata_t, void *); 87 static void le_attach(device_t, device_t, void *); 88 89 CFATTACH_DECL_NEW(le, sizeof(struct le_softc), 90 le_match, le_attach, NULL, NULL); 91 92 extern const uint8_t *idrom_addr; 93 extern uint32_t lance_mem_phys; 94 95 #if defined(_KERNEL_OPT) 96 #include "opt_ddb.h" 97 #endif 98 99 #ifdef DDB 100 #define integrate 101 #define hide 102 #else 103 #define integrate static inline 104 #define hide static 105 #endif 106 107 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 108 hide uint16_t lerdcsr(struct lance_softc *, uint16_t); 109 int leintr(int); 110 111 hide void 112 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 113 { 114 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 115 116 ler1->ler1_rap = port; 117 ler1->ler1_rdp = val; 118 } 119 120 hide uint16_t 121 lerdcsr(struct lance_softc *sc, uint16_t port) 122 { 123 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 124 uint16_t val; 125 126 ler1->ler1_rap = port; 127 val = ler1->ler1_rdp; 128 return val; 129 } 130 131 int 132 le_match(device_t parent, cfdata_t cf, void *aux) 133 { 134 struct hb_attach_args *ha = aux; 135 int addr; 136 137 if (strcmp(ha->ha_name, "le")) 138 return 0; 139 140 addr = IIOV(ha->ha_address); 141 142 if (badaddr((void *)addr, 1)) 143 return 0; 144 145 return 1; 146 } 147 148 void 149 le_attach(device_t parent, device_t self, void *aux) 150 { 151 struct le_softc *lesc = device_private(self); 152 struct lance_softc *sc = &lesc->sc_am7990.lsc; 153 struct hb_attach_args *ha = aux; 154 const uint8_t *p; 155 156 sc->sc_dev = self; 157 lesc->sc_r1 = (void *)IIOV(ha->ha_address); 158 159 if (ISIIOPA(ha->ha_address)) { 160 sc->sc_mem = (u_char *)IIOV(lance_mem_phys); 161 p = idrom_addr + 0x10; 162 } else { 163 sc->sc_mem = lesc->sc_r1 - 0x10000; 164 p = (const uint8_t *)(lesc->sc_r1 + 0x8010); 165 } 166 167 sc->sc_memsize = 0x4000; /* 16K */ 168 sc->sc_addr = lance_mem_phys & 0x00ffffff; 169 sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON; 170 171 sc->sc_enaddr[0] = (*p++ << 4); 172 sc->sc_enaddr[0] |= *p++ & 0x0f; 173 sc->sc_enaddr[1] = (*p++ << 4); 174 sc->sc_enaddr[1] |= *p++ & 0x0f; 175 sc->sc_enaddr[2] = (*p++ << 4); 176 sc->sc_enaddr[2] |= *p++ & 0x0f; 177 sc->sc_enaddr[3] = (*p++ << 4); 178 sc->sc_enaddr[3] |= *p++ & 0x0f; 179 sc->sc_enaddr[4] = (*p++ << 4); 180 sc->sc_enaddr[4] |= *p++ & 0x0f; 181 sc->sc_enaddr[5] = (*p++ << 4); 182 sc->sc_enaddr[5] |= *p++ & 0x0f; 183 184 sc->sc_copytodesc = lance_copytobuf_contig; 185 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 186 sc->sc_copytobuf = lance_copytobuf_contig; 187 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 188 sc->sc_zerobuf = lance_zerobuf_contig; 189 190 sc->sc_rdcsr = lerdcsr; 191 sc->sc_wrcsr = lewrcsr; 192 sc->sc_hwinit = NULL; 193 194 am7990_config(&lesc->sc_am7990); 195 } 196 197 int 198 leintr(int unit) 199 { 200 struct am7990_softc *sc; 201 202 if (unit >= le_cd.cd_ndevs) /* XXX */ 203 return 0; 204 205 sc = device_lookup_private(&le_cd, unit); 206 return am7990_intr(sc); 207 } 208