1 /* $OpenBSD: if_le.c,v 1.13 2024/11/28 13:13:04 aoyama Exp $ */ 2 /* $NetBSD: if_le.c,v 1.33 1996/11/20 18:56:52 gwr Exp $ */ 3 4 /*- 5 * Copyright (c) 1996 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Adam Glass and Gordon W. Ross. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* based on OpenBSD: sys/arch/sun3/dev/if_le.c */ 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/mbuf.h> 38 #include <sys/syslog.h> 39 #include <sys/socket.h> 40 #include <sys/device.h> 41 42 #include <net/if.h> 43 44 #include <netinet/in.h> 45 #include <netinet/if_ether.h> 46 47 #include <net/if_media.h> 48 49 #include <machine/autoconf.h> 50 #include <machine/board.h> 51 #include <machine/cpu.h> 52 53 #include <dev/ic/lancereg.h> 54 #include <dev/ic/lancevar.h> 55 #include <dev/ic/am7990reg.h> 56 #include <dev/ic/am7990var.h> 57 58 #include <luna88k/luna88k/isr.h> 59 60 #define TRI_PORT_RAM_LANCE_OFFSET 0x10000 /* first 64KB is used by XP */ 61 62 #ifndef TRI_PORT_RAM_LANCE_SIZE 63 #define TRI_PORT_RAM_LANCE_SIZE 0x10000 /* 64KB is the default */ 64 #endif 65 66 /* 67 * LANCE registers. 68 * The real stuff is in dev/ic/am7990reg.h 69 */ 70 struct lereg1 { 71 volatile uint16_t ler1_rdp; /* data port */ 72 volatile unsigned :16 ; /* 16bit gap */ 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 int le_match(struct device *, void *, void *); 87 void le_attach(struct device *, struct device *, void *); 88 89 const struct cfattach le_ca = { 90 sizeof(struct le_softc), le_match, le_attach 91 }; 92 93 void lewrcsr(struct lance_softc *, uint16_t, uint16_t); 94 uint16_t lerdcsr(struct lance_softc *, uint16_t); 95 void myetheraddr(uint8_t *); 96 97 void 98 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 99 { 100 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 101 102 ler1->ler1_rap = port; 103 ler1->ler1_rdp = val; 104 } 105 106 uint16_t 107 lerdcsr(struct lance_softc *sc, uint16_t port) 108 { 109 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 110 uint16_t val; 111 112 ler1->ler1_rap = port; 113 val = ler1->ler1_rdp; 114 return (val); 115 } 116 117 int 118 le_match(struct device *parent, void *cf, void *aux) 119 { 120 struct mainbus_attach_args *ma = aux; 121 122 if (strcmp(ma->ma_name, le_cd.cd_name)) 123 return (0); 124 125 return (1); 126 } 127 128 void 129 le_attach(struct device *parent, struct device *self, void *aux) 130 { 131 struct le_softc *lesc = (struct le_softc *)self; 132 struct lance_softc *sc = &lesc->sc_am7990.lsc; 133 struct mainbus_attach_args *ma = aux; 134 135 lesc->sc_r1 = (struct lereg1 *)ma->ma_addr; /* LANCE */ 136 137 sc->sc_mem = (void *)(TRI_PORT_RAM + TRI_PORT_RAM_LANCE_OFFSET); 138 sc->sc_conf3 = LE_C3_BSWP; 139 sc->sc_addr = (u_long)sc->sc_mem & 0xffffff; 140 sc->sc_memsize = TRI_PORT_RAM_LANCE_SIZE; 141 142 myetheraddr(sc->sc_arpcom.ac_enaddr); 143 144 sc->sc_copytodesc = lance_copytobuf_contig; 145 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 146 sc->sc_copytobuf = lance_copytobuf_contig; 147 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 148 sc->sc_zerobuf = lance_zerobuf_contig; 149 150 sc->sc_rdcsr = lerdcsr; 151 sc->sc_wrcsr = lewrcsr; 152 sc->sc_hwreset = NULL; 153 sc->sc_hwinit = NULL; 154 155 am7990_config(&lesc->sc_am7990); 156 157 isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET, 158 self->dv_xname); 159 } 160 161 /* 162 * Partially taken from NetBSD/luna68k 163 * 164 * LUNA-88K has FUSE ROM, which contains MAC address. The FUSE ROM 165 * contents are stored in fuse_rom_data[] during cpu_startup(). 166 * 167 * LUNA-88K2 has 16Kbit NVSRAM on its ethercard, whose contents are 168 * accessible 4bit-wise by ctl register operation. The register is 169 * mapped at 0xF1000008. 170 */ 171 172 extern int machtype; 173 extern char fuse_rom_data[]; 174 175 void 176 myetheraddr(uint8_t *ether) 177 { 178 unsigned i, loc; 179 volatile struct { uint32_t ctl; } *ds1220; 180 181 switch (machtype) { 182 case LUNA_88K: 183 /* 184 * fuse_rom_data[] begins with "ENADDR=00000Axxxxxx" 185 */ 186 loc = 7; 187 for (i = 0; i < 6; i++) { 188 int u, l; 189 190 u = fuse_rom_data[loc]; 191 u = (u < 'A') ? u & 0xf : u - 'A' + 10; 192 l = fuse_rom_data[loc + 1]; 193 l = (l < 'A') ? l & 0xf : l - 'A' + 10; 194 195 ether[i] = l | (u << 4); 196 loc += 2; 197 } 198 break; 199 case LUNA_88K2: 200 ds1220 = (void *)(LANCE_ADDR + 8); 201 loc = 12; 202 for (i = 0; i < 6; i++) { 203 unsigned u, l, hex; 204 205 ds1220->ctl = (loc) << 16; 206 u = 0xf0 & (ds1220->ctl >> 12); 207 ds1220->ctl = (loc + 1) << 16; 208 l = 0x0f & (ds1220->ctl >> 16); 209 hex = (u < '9') ? l : l + 9; 210 211 ds1220->ctl = (loc + 2) << 16; 212 u = 0xf0 & (ds1220->ctl >> 12); 213 ds1220->ctl = (loc + 3) << 16; 214 l = 0x0f & (ds1220->ctl >> 16); 215 216 ether[i] = ((u < '9') ? l : l + 9) | (hex << 4); 217 loc += 4; 218 } 219 break; 220 default: 221 ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a; 222 ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00; 223 break; 224 } 225 } 226