1 1.37 andvar /* $NetBSD: if_il.c,v 1.37 2021/08/01 15:29:30 andvar Exp $ */ 2 1.1 ragge /* 3 1.1 ragge * Copyright (c) 1982, 1986 Regents of the University of California. 4 1.1 ragge * All rights reserved. 5 1.1 ragge * 6 1.1 ragge * Redistribution and use in source and binary forms, with or without 7 1.1 ragge * modification, are permitted provided that the following conditions 8 1.1 ragge * are met: 9 1.1 ragge * 1. Redistributions of source code must retain the above copyright 10 1.1 ragge * notice, this list of conditions and the following disclaimer. 11 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 ragge * notice, this list of conditions and the following disclaimer in the 13 1.1 ragge * documentation and/or other materials provided with the distribution. 14 1.10 agc * 3. Neither the name of the University nor the names of its contributors 15 1.1 ragge * may be used to endorse or promote products derived from this software 16 1.1 ragge * without specific prior written permission. 17 1.1 ragge * 18 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 1.1 ragge * SUCH DAMAGE. 29 1.1 ragge * 30 1.1 ragge * @(#)if_il.c 7.8 (Berkeley) 12/16/90 31 1.1 ragge */ 32 1.1 ragge 33 1.1 ragge /* 34 1.1 ragge * Interlan Ethernet Communications Controller interface 35 1.1 ragge */ 36 1.2 lukem 37 1.2 lukem #include <sys/cdefs.h> 38 1.37 andvar __KERNEL_RCSID(0, "$NetBSD: if_il.c,v 1.37 2021/08/01 15:29:30 andvar Exp $"); 39 1.2 lukem 40 1.1 ragge #include "opt_inet.h" 41 1.1 ragge 42 1.1 ragge #include <sys/param.h> 43 1.1 ragge #include <sys/systm.h> 44 1.1 ragge #include <sys/mbuf.h> 45 1.1 ragge #include <sys/buf.h> 46 1.1 ragge #include <sys/protosw.h> 47 1.1 ragge #include <sys/socket.h> 48 1.1 ragge #include <sys/ioctl.h> 49 1.1 ragge #include <sys/errno.h> 50 1.1 ragge #include <sys/syslog.h> 51 1.1 ragge #include <sys/device.h> 52 1.1 ragge 53 1.1 ragge #include <net/if.h> 54 1.1 ragge #include <net/if_ether.h> 55 1.1 ragge #include <net/if_dl.h> 56 1.1 ragge 57 1.1 ragge #ifdef INET 58 1.1 ragge #include <netinet/in.h> 59 1.1 ragge #endif 60 1.1 ragge 61 1.1 ragge 62 1.18 ad #include <sys/bus.h> 63 1.1 ragge 64 1.1 ragge #include <dev/qbus/ubareg.h> 65 1.1 ragge #include <dev/qbus/ubavar.h> 66 1.1 ragge #include <dev/qbus/if_uba.h> 67 1.1 ragge 68 1.1 ragge #include <dev/qbus/if_il.h> 69 1.1 ragge #include <dev/qbus/if_ilreg.h> 70 1.1 ragge 71 1.1 ragge /* 72 1.1 ragge * Ethernet software status per interface. 73 1.1 ragge * 74 1.1 ragge * Each interface is referenced by a network interface structure, 75 1.1 ragge * is_if, which the routing code uses to locate the interface. 76 1.1 ragge * This structure contains the output queue for the interface, its address, ... 77 1.1 ragge * We also have, for each interface, a UBA interface structure, which 78 1.1 ragge * contains information about the UNIBUS resources held by the interface: 79 1.1 ragge * map registers, buffered data paths, etc. Information is cached in this 80 1.1 ragge * structure for use by the if_uba.c routines in running the interface 81 1.1 ragge * efficiently. 82 1.1 ragge */ 83 1.1 ragge 84 1.1 ragge struct il_softc { 85 1.26 chs device_t sc_dev; /* Configuration common part */ 86 1.31 msaitoh struct ethercom sc_ec; /* Ethernet common part */ 87 1.1 ragge #define sc_if sc_ec.ec_if /* network-visible interface */ 88 1.31 msaitoh struct evcnt sc_cintrcnt; /* Command interrupts */ 89 1.31 msaitoh struct evcnt sc_rintrcnt; /* Receive interrupts */ 90 1.1 ragge bus_space_tag_t sc_iot; 91 1.1 ragge bus_addr_t sc_ioh; 92 1.1 ragge bus_dma_tag_t sc_dmat; 93 1.1 ragge struct ubinfo sc_ui; 94 1.1 ragge 95 1.1 ragge struct ifuba sc_ifuba; /* UNIBUS resources */ 96 1.1 ragge int sc_flags; 97 1.1 ragge #define ILF_RCVPENDING 0x2 /* start rcv in ilcint */ 98 1.1 ragge #define ILF_STATPENDING 0x4 /* stat cmd pending */ 99 1.1 ragge #define ILF_RUNNING 0x8 /* board is running */ 100 1.1 ragge #define ILF_SETADDR 0x10 /* physical address is changed */ 101 1.1 ragge short sc_lastcmd; /* can't read csr, so must save it */ 102 1.1 ragge short sc_scaninterval; /* interval of stat collection */ 103 1.1 ragge #define ILWATCHINTERVAL 60 /* once every 60 seconds */ 104 1.1 ragge union { 105 1.1 ragge struct il_stats isu_stats; /* holds on-board statistics */ 106 1.1 ragge struct ether_addr isu_maddrs[63]; /* multicast addrs */ 107 1.1 ragge } sc_isu; 108 1.1 ragge #define sc_stats sc_isu.isu_stats 109 1.1 ragge #define sc_maddrs sc_isu.isu_maddrs 110 1.1 ragge struct il_stats sc_sum; /* summation over time */ 111 1.1 ragge int sc_ubaddr; /* mapping registers of is_stats */ 112 1.1 ragge }; 113 1.1 ragge 114 1.24 cegger static int ilmatch(device_t, cfdata_t, void *); 115 1.24 cegger static void ilattach(device_t, device_t, void *); 116 1.1 ragge static void ilcint(void *); 117 1.1 ragge static void ilrint(void *); 118 1.24 cegger static void ilreset(device_t); 119 1.34 msaitoh static int ilwait(struct il_softc *, const char *); 120 1.1 ragge static int ilinit(struct ifnet *); 121 1.1 ragge static void ilstart(struct ifnet *); 122 1.1 ragge static void ilwatch(struct ifnet *); 123 1.1 ragge static void iltotal(struct il_softc *); 124 1.1 ragge static void ilstop(struct ifnet *, int); 125 1.1 ragge 126 1.26 chs CFATTACH_DECL_NEW(il, sizeof(struct il_softc), 127 1.8 thorpej ilmatch, ilattach, NULL, NULL); 128 1.1 ragge 129 1.1 ragge #define IL_WCSR(csr, val) \ 130 1.1 ragge bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val) 131 1.1 ragge #define IL_RCSR(csr) \ 132 1.1 ragge bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr) 133 1.1 ragge #define LOWORD(x) ((int)(x) & 0xffff) 134 1.1 ragge #define HIWORD(x) (((int)(x) >> 16) & 0x3) 135 1.1 ragge 136 1.1 ragge int 137 1.24 cegger ilmatch(device_t parent, cfdata_t cf, void *aux) 138 1.1 ragge { 139 1.1 ragge struct uba_attach_args *ua = aux; 140 1.1 ragge 141 1.30 msaitoh bus_space_write_2(ua->ua_iot, ua->ua_ioh, IL_CSR, 142 1.30 msaitoh ILC_OFFLINE | IL_CIE); 143 1.1 ragge DELAY(100000); 144 1.34 msaitoh bus_space_read_2(ua->ua_iot, ua->ua_ioh, IL_CSR); /* clear CDONE */ 145 1.1 ragge 146 1.1 ragge return 1; 147 1.1 ragge } 148 1.1 ragge 149 1.1 ragge /* 150 1.1 ragge * Interface exists: make available by filling in network interface 151 1.1 ragge * record. System will initialize the interface when it is ready 152 1.1 ragge * to accept packets. A STATUS command is done to get the ethernet 153 1.1 ragge * address and other interesting data. 154 1.1 ragge */ 155 1.1 ragge void 156 1.24 cegger ilattach(device_t parent, device_t self, void *aux) 157 1.1 ragge { 158 1.1 ragge struct uba_attach_args *ua = aux; 159 1.14 thorpej struct il_softc *sc = device_private(self); 160 1.1 ragge struct ifnet *ifp = &sc->sc_if; 161 1.1 ragge int error; 162 1.1 ragge 163 1.26 chs sc->sc_dev = self; 164 1.1 ragge sc->sc_iot = ua->ua_iot; 165 1.1 ragge sc->sc_ioh = ua->ua_ioh; 166 1.1 ragge sc->sc_dmat = ua->ua_dmat; 167 1.1 ragge 168 1.1 ragge /* 169 1.1 ragge * Map interrupt vectors and reset function. 170 1.1 ragge */ 171 1.1 ragge uba_intr_establish(ua->ua_icookie, ua->ua_cvec, ilcint, 172 1.1 ragge sc, &sc->sc_cintrcnt); 173 1.1 ragge evcnt_attach_dynamic(&sc->sc_cintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, 174 1.26 chs device_xname(sc->sc_dev), "intr"); 175 1.1 ragge uba_intr_establish(ua->ua_icookie, ua->ua_cvec-4, ilrint, 176 1.1 ragge sc, &sc->sc_rintrcnt); 177 1.1 ragge evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, 178 1.26 chs device_xname(sc->sc_dev), "intr"); 179 1.26 chs uba_reset_establish(ilreset, sc->sc_dev); 180 1.1 ragge 181 1.1 ragge /* 182 1.1 ragge * Reset the board and map the statistics 183 1.1 ragge * buffer onto the Unibus. 184 1.1 ragge */ 185 1.1 ragge IL_WCSR(IL_CSR, ILC_RESET); 186 1.1 ragge (void)ilwait(sc, "reset"); 187 1.1 ragge sc->sc_ui.ui_size = sizeof(struct il_stats); 188 1.16 christos sc->sc_ui.ui_vaddr = (void *)&sc->sc_stats; 189 1.26 chs if ((error = uballoc(device_private(parent), &sc->sc_ui, 0))) 190 1.1 ragge return printf(": failed uballoc, error = %d\n", error); 191 1.1 ragge 192 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); 193 1.1 ragge IL_WCSR(IL_BCR, sizeof(struct il_stats)); 194 1.30 msaitoh IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA) | ILC_STAT); 195 1.1 ragge (void)ilwait(sc, "status"); 196 1.26 chs ubfree(device_private(parent), &sc->sc_ui); 197 1.26 chs printf("%s: module=%s firmware=%s\n", device_xname(sc->sc_dev), 198 1.1 ragge sc->sc_stats.ils_module, sc->sc_stats.ils_firmware); 199 1.26 chs printf("%s: hardware address %s\n", device_xname(sc->sc_dev), 200 1.1 ragge ether_sprintf(sc->sc_stats.ils_addr)); 201 1.1 ragge 202 1.26 chs strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); 203 1.1 ragge ifp->if_softc = sc; 204 1.34 msaitoh ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 205 1.1 ragge ifp->if_init = ilinit; 206 1.1 ragge ifp->if_stop = ilstop; 207 1.1 ragge ifp->if_ioctl = ether_ioctl; 208 1.1 ragge ifp->if_start = ilstart; 209 1.1 ragge ifp->if_watchdog = ilwatch; 210 1.4 itojun IFQ_SET_READY(&ifp->if_snd); 211 1.1 ragge 212 1.1 ragge if_attach(ifp); 213 1.1 ragge ether_ifattach(ifp, sc->sc_stats.ils_addr); 214 1.1 ragge } 215 1.1 ragge 216 1.1 ragge void 217 1.1 ragge ilstop(struct ifnet *ifp, int a) 218 1.1 ragge { 219 1.1 ragge struct il_softc *sc = ifp->if_softc; 220 1.1 ragge 221 1.1 ragge IL_WCSR(IL_CSR, ILC_RESET); 222 1.1 ragge } 223 1.1 ragge 224 1.1 ragge 225 1.1 ragge int 226 1.34 msaitoh ilwait(struct il_softc *sc, const char *op) 227 1.1 ragge { 228 1.1 ragge 229 1.1 ragge while ((IL_RCSR(IL_CSR)&IL_CDONE) == 0) 230 1.1 ragge ; 231 1.1 ragge if (IL_RCSR(IL_CSR)&IL_STATUS) { 232 1.1 ragge char bits[64]; 233 1.1 ragge 234 1.20 christos snprintb(bits, sizeof(bits), IL_BITS, IL_RCSR(IL_CSR)); 235 1.26 chs aprint_error_dev(sc->sc_dev, "%s failed, csr=%s\n", op, bits); 236 1.30 msaitoh return -1; 237 1.1 ragge } 238 1.30 msaitoh return 0; 239 1.1 ragge } 240 1.1 ragge 241 1.1 ragge /* 242 1.1 ragge * Reset of interface after UNIBUS reset. 243 1.1 ragge * If interface is on specified uba, reset its state. 244 1.1 ragge */ 245 1.1 ragge void 246 1.24 cegger ilreset(device_t dev) 247 1.1 ragge { 248 1.1 ragge struct il_softc *sc = (void *)dev; 249 1.1 ragge 250 1.26 chs printf(" %s", device_xname(sc->sc_dev)); 251 1.1 ragge sc->sc_if.if_flags &= ~IFF_RUNNING; 252 1.1 ragge sc->sc_flags &= ~ILF_RUNNING; 253 1.1 ragge ilinit(&sc->sc_if); 254 1.1 ragge } 255 1.1 ragge 256 1.1 ragge /* 257 1.1 ragge * Initialization of interface; clear recorded pending 258 1.1 ragge * operations, and reinitialize UNIBUS usage. 259 1.1 ragge */ 260 1.1 ragge int 261 1.1 ragge ilinit(struct ifnet *ifp) 262 1.1 ragge { 263 1.1 ragge struct il_softc *sc = ifp->if_softc; 264 1.1 ragge int s; 265 1.1 ragge 266 1.1 ragge if (sc->sc_flags & ILF_RUNNING) 267 1.1 ragge return 0; 268 1.1 ragge 269 1.1 ragge if ((ifp->if_flags & IFF_RUNNING) == 0) { 270 1.13 thorpej if (if_ubainit(&sc->sc_ifuba, 271 1.26 chs device_private(device_parent(sc->sc_dev)), 272 1.1 ragge ETHER_MAX_LEN)) { 273 1.26 chs aprint_error_dev(sc->sc_dev, "can't initialize\n"); 274 1.1 ragge sc->sc_if.if_flags &= ~IFF_UP; 275 1.1 ragge return 0; 276 1.1 ragge } 277 1.1 ragge sc->sc_ui.ui_size = sizeof(sc->sc_isu); 278 1.16 christos sc->sc_ui.ui_vaddr = (void *)&sc->sc_isu; 279 1.30 msaitoh uballoc(device_private(device_parent(sc->sc_dev)), 280 1.30 msaitoh &sc->sc_ui, 0); 281 1.1 ragge } 282 1.1 ragge sc->sc_scaninterval = ILWATCHINTERVAL; 283 1.1 ragge ifp->if_timer = sc->sc_scaninterval; 284 1.1 ragge 285 1.1 ragge /* 286 1.1 ragge * Turn off source address insertion (it's faster this way), 287 1.1 ragge * and set board online. Former doesn't work if board is 288 1.1 ragge * already online (happens on ubareset), so we put it offline 289 1.1 ragge * first. 290 1.1 ragge */ 291 1.1 ragge s = splnet(); 292 1.1 ragge IL_WCSR(IL_CSR, ILC_RESET); 293 1.1 ragge if (ilwait(sc, "hardware diag")) { 294 1.11 simonb sc->sc_if.if_flags &= ~IFF_UP; 295 1.28 christos goto out; 296 1.11 simonb } 297 1.1 ragge IL_WCSR(IL_CSR, ILC_CISA); 298 1.1 ragge while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) 299 1.1 ragge ; 300 1.1 ragge /* 301 1.1 ragge * If we must reprogram this board's physical ethernet 302 1.1 ragge * address (as for secondary XNS interfaces), we do so 303 1.1 ragge * before putting it on line, and starting receive requests. 304 1.1 ragge * If you try this on an older 1010 board, it will total 305 1.1 ragge * wedge the board. 306 1.1 ragge */ 307 1.1 ragge if (sc->sc_flags & ILF_SETADDR) { 308 1.22 tsutsui memcpy(&sc->sc_isu, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN); 309 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); 310 1.1 ragge IL_WCSR(IL_BCR, ETHER_ADDR_LEN); 311 1.30 msaitoh IL_WCSR(IL_CSR, 312 1.30 msaitoh ((sc->sc_ui.ui_baddr >> 2) & IL_EUA) | ILC_LDPA); 313 1.1 ragge if (ilwait(sc, "setaddr")) 314 1.28 christos goto out; 315 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); 316 1.1 ragge IL_WCSR(IL_BCR, sizeof (struct il_stats)); 317 1.30 msaitoh IL_WCSR(IL_CSR, 318 1.30 msaitoh ((sc->sc_ui.ui_baddr >> 2) & IL_EUA) | ILC_STAT); 319 1.1 ragge if (ilwait(sc, "verifying setaddr")) 320 1.28 christos goto out; 321 1.17 dyoung if (memcmp(sc->sc_stats.ils_addr, 322 1.17 dyoung CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) { 323 1.26 chs aprint_error_dev(sc->sc_dev, "setaddr didn't work\n"); 324 1.28 christos goto out; 325 1.1 ragge } 326 1.1 ragge } 327 1.34 msaitoh if (sc->sc_if.if_flags & IFF_PROMISC) { 328 1.34 msaitoh IL_WCSR(IL_CSR, ILC_PRMSC); 329 1.34 msaitoh if (ilwait(sc, "all multi")) 330 1.28 christos goto out; 331 1.34 msaitoh } else if (sc->sc_if.if_flags & IFF_ALLMULTI) { 332 1.34 msaitoh too_many_multis: 333 1.34 msaitoh IL_WCSR(IL_CSR, ILC_ALLMC); 334 1.34 msaitoh if (ilwait(sc, "all multi")) 335 1.28 christos goto out; 336 1.27 wiz } else { 337 1.1 ragge int i; 338 1.35 msaitoh struct ethercom *ec = &sc->sc_ec; 339 1.34 msaitoh register struct ether_addr *ep = sc->sc_maddrs; 340 1.1 ragge struct ether_multi *enm; 341 1.1 ragge struct ether_multistep step; 342 1.1 ragge /* 343 1.1 ragge * Step through our list of multicast addresses. If we have 344 1.1 ragge * too many multicast addresses, or if we have to listen to 345 1.1 ragge * a range of multicast addresses, turn on reception of all 346 1.1 ragge * multicasts. 347 1.1 ragge */ 348 1.1 ragge i = 0; 349 1.35 msaitoh ETHER_LOCK(ec); 350 1.35 msaitoh ETHER_FIRST_MULTI(step, ec, enm); 351 1.1 ragge while (enm != NULL) { 352 1.34 msaitoh if (++i > 63 /* && k != 0 */) { 353 1.1 ragge break; 354 1.1 ragge } 355 1.1 ragge *ep++ = *(struct ether_addr *)enm->enm_addrlo; 356 1.1 ragge ETHER_NEXT_MULTI(step, enm); 357 1.1 ragge } 358 1.35 msaitoh ETHER_UNLOCK(ec); 359 1.34 msaitoh if (i == 0) { 360 1.1 ragge /* no multicasts! */ 361 1.1 ragge } else if (i <= 63) { 362 1.34 msaitoh IL_WCSR(IL_BAR, sc->sc_ubaddr & 0xffff); 363 1.34 msaitoh IL_WCSR(IL_BCR, i * sizeof(struct ether_addr)); 364 1.34 msaitoh IL_WCSR(IL_CSR, 365 1.34 msaitoh ((sc->sc_ubaddr >> 2) & IL_EUA) | ILC_LDGRPS); 366 1.34 msaitoh if (ilwait(sc, "load multi")) 367 1.28 christos goto out; 368 1.1 ragge } else { 369 1.34 msaitoh sc->sc_if.if_flags |= IFF_ALLMULTI; 370 1.34 msaitoh goto too_many_multis; 371 1.1 ragge } 372 1.1 ragge } 373 1.1 ragge /* 374 1.1 ragge * Set board online. 375 1.1 ragge * Hang receive buffer and start any pending 376 1.1 ragge * writes by faking a transmit complete. 377 1.1 ragge * Receive bcr is not a multiple of 8 so buffer 378 1.1 ragge * chaining can't happen. 379 1.1 ragge */ 380 1.1 ragge IL_WCSR(IL_CSR, ILC_ONLINE); 381 1.1 ragge while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) 382 1.1 ragge ; 383 1.1 ragge 384 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info)); 385 1.1 ragge IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6); 386 1.1 ragge IL_WCSR(IL_CSR, 387 1.30 msaitoh ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA) | ILC_RCV | IL_RIE); 388 1.1 ragge while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) 389 1.1 ragge ; 390 1.1 ragge ifp->if_flags |= IFF_RUNNING | IFF_OACTIVE; 391 1.1 ragge sc->sc_flags |= ILF_RUNNING; 392 1.1 ragge sc->sc_lastcmd = 0; 393 1.1 ragge ilcint(sc); 394 1.28 christos out: 395 1.1 ragge splx(s); 396 1.1 ragge return 0; 397 1.1 ragge } 398 1.1 ragge 399 1.1 ragge /* 400 1.1 ragge * Start output on interface. 401 1.1 ragge * Get another datagram to send off of the interface queue, 402 1.1 ragge * and map it to the interface before starting the output. 403 1.1 ragge */ 404 1.1 ragge void 405 1.1 ragge ilstart(struct ifnet *ifp) 406 1.1 ragge { 407 1.1 ragge struct il_softc *sc = ifp->if_softc; 408 1.11 simonb int len; 409 1.1 ragge struct mbuf *m; 410 1.1 ragge short csr; 411 1.1 ragge 412 1.4 itojun IFQ_DEQUEUE(&ifp->if_snd, m); 413 1.1 ragge if (m == 0) { 414 1.1 ragge if ((sc->sc_flags & ILF_STATPENDING) == 0) 415 1.1 ragge return; 416 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); 417 1.1 ragge IL_WCSR(IL_BCR, sizeof (struct il_stats)); 418 1.30 msaitoh csr = ((sc->sc_ui.ui_baddr >> 2) & IL_EUA) 419 1.30 msaitoh | ILC_STAT | IL_RIE | IL_CIE; 420 1.1 ragge sc->sc_flags &= ~ILF_STATPENDING; 421 1.1 ragge goto startcmd; 422 1.1 ragge } 423 1.1 ragge len = if_wubaput(&sc->sc_ifuba, m); 424 1.1 ragge #ifdef notdef 425 1.1 ragge if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP) 426 1.1 ragge UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 427 1.1 ragge #endif 428 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_w.ifrw_info)); 429 1.1 ragge IL_WCSR(IL_BCR, len); 430 1.30 msaitoh csr = ((sc->sc_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA) 431 1.30 msaitoh | ILC_XMIT | IL_CIE | IL_RIE; 432 1.1 ragge 433 1.1 ragge startcmd: 434 1.1 ragge sc->sc_lastcmd = csr & IL_CMD; 435 1.1 ragge IL_WCSR(IL_CSR, csr); 436 1.1 ragge ifp->if_flags |= IFF_OACTIVE; 437 1.1 ragge return; 438 1.1 ragge } 439 1.1 ragge 440 1.1 ragge /* 441 1.1 ragge * Command done interrupt. 442 1.1 ragge */ 443 1.1 ragge void 444 1.1 ragge ilcint(void *arg) 445 1.1 ragge { 446 1.1 ragge struct il_softc *sc = arg; 447 1.1 ragge short csr; 448 1.1 ragge 449 1.1 ragge if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) { 450 1.1 ragge char bits[64]; 451 1.1 ragge 452 1.20 christos snprintb(bits, sizeof(bits), IL_BITS, IL_RCSR(IL_CSR)); 453 1.26 chs aprint_error_dev(sc->sc_dev, 454 1.25 wiz "stray xmit interrupt, csr=%s\n", bits); 455 1.1 ragge return; 456 1.1 ragge } 457 1.1 ragge 458 1.1 ragge csr = IL_RCSR(IL_CSR); 459 1.1 ragge /* 460 1.1 ragge * Hang receive buffer if it couldn't 461 1.1 ragge * be done earlier (in ilrint). 462 1.1 ragge */ 463 1.1 ragge if (sc->sc_flags & ILF_RCVPENDING) { 464 1.1 ragge int s; 465 1.1 ragge 466 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info)); 467 1.1 ragge IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6); 468 1.30 msaitoh IL_WCSR(IL_CSR, ((sc->sc_ifuba.ifu_r.ifrw_info>>2) & IL_EUA) 469 1.30 msaitoh | ILC_RCV | IL_RIE); 470 1.1 ragge s = splhigh(); 471 1.1 ragge while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) 472 1.1 ragge ; 473 1.1 ragge splx(s); 474 1.1 ragge sc->sc_flags &= ~ILF_RCVPENDING; 475 1.1 ragge } 476 1.1 ragge sc->sc_if.if_flags &= ~IFF_OACTIVE; 477 1.1 ragge csr &= IL_STATUS; 478 1.1 ragge switch (sc->sc_lastcmd) { 479 1.1 ragge 480 1.1 ragge case ILC_XMIT: 481 1.1 ragge sc->sc_if.if_opackets++; 482 1.1 ragge if (csr > ILERR_RETRIES) 483 1.1 ragge sc->sc_if.if_oerrors++; 484 1.1 ragge break; 485 1.1 ragge 486 1.1 ragge case ILC_STAT: 487 1.1 ragge if (csr == ILERR_SUCCESS) 488 1.1 ragge iltotal(sc); 489 1.1 ragge break; 490 1.1 ragge } 491 1.1 ragge if_wubaend(&sc->sc_ifuba); 492 1.1 ragge ilstart(&sc->sc_if); 493 1.1 ragge } 494 1.1 ragge 495 1.1 ragge /* 496 1.1 ragge * Ethernet interface receiver interrupt. 497 1.1 ragge * If input error just drop packet. 498 1.11 simonb * Otherwise purge input buffered data path and examine 499 1.1 ragge * packet to determine type. If can't determine length 500 1.37 andvar * from type, then have to drop packet. Otherwise decapsulate 501 1.1 ragge * packet based on type and pass to type specific higher-level 502 1.1 ragge * input routine. 503 1.1 ragge */ 504 1.1 ragge void 505 1.1 ragge ilrint(void *arg) 506 1.1 ragge { 507 1.1 ragge struct il_softc *sc = arg; 508 1.1 ragge struct il_rheader *il; 509 1.11 simonb struct mbuf *m; 510 1.1 ragge int len, s; 511 1.1 ragge 512 1.1 ragge #ifdef notyet 513 1.1 ragge if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP) 514 1.1 ragge UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 515 1.1 ragge #endif 516 1.1 ragge il = (struct il_rheader *)(sc->sc_ifuba.ifu_r.ifrw_addr); 517 1.1 ragge len = il->ilr_length - sizeof(struct il_rheader); 518 1.30 msaitoh if ((il->ilr_status&(ILFSTAT_A | ILFSTAT_C)) || len < 46 || 519 1.1 ragge len > ETHERMTU) { 520 1.1 ragge sc->sc_if.if_ierrors++; 521 1.1 ragge #ifdef notdef 522 1.1 ragge if (sc->sc_if.if_ierrors % 100 == 0) 523 1.1 ragge printf("il%d: += 100 input errors\n", unit); 524 1.1 ragge #endif 525 1.1 ragge goto setup; 526 1.1 ragge } 527 1.1 ragge 528 1.1 ragge if (len == 0) 529 1.1 ragge goto setup; 530 1.1 ragge 531 1.1 ragge /* 532 1.1 ragge * Pull packet off interface. 533 1.1 ragge */ 534 1.1 ragge m = if_rubaget(&sc->sc_ifuba, &sc->sc_if, len); 535 1.1 ragge if (m == NULL) 536 1.1 ragge goto setup; 537 1.1 ragge 538 1.1 ragge /* Shave off status hdr */ 539 1.1 ragge m_adj(m, 4); 540 1.29 ozaki if_percpuq_enqueue((&sc->sc_if)->if_percpuq, m); 541 1.1 ragge setup: 542 1.1 ragge /* 543 1.1 ragge * Reset for next packet if possible. 544 1.1 ragge * If waiting for transmit command completion, set flag 545 1.1 ragge * and wait until command completes. 546 1.1 ragge */ 547 1.1 ragge if (sc->sc_if.if_flags & IFF_OACTIVE) { 548 1.1 ragge sc->sc_flags |= ILF_RCVPENDING; 549 1.1 ragge return; 550 1.1 ragge } 551 1.1 ragge IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info)); 552 1.1 ragge IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6); 553 1.1 ragge IL_WCSR(IL_CSR, 554 1.30 msaitoh ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA) | ILC_RCV | IL_RIE); 555 1.1 ragge s = splhigh(); 556 1.1 ragge while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) 557 1.1 ragge ; 558 1.1 ragge splx(s); 559 1.1 ragge } 560 1.1 ragge /* 561 1.1 ragge * Watchdog routine, request statistics from board. 562 1.1 ragge */ 563 1.1 ragge void 564 1.1 ragge ilwatch(struct ifnet *ifp) 565 1.1 ragge { 566 1.1 ragge struct il_softc *sc = ifp->if_softc; 567 1.1 ragge int s; 568 1.1 ragge 569 1.1 ragge if (sc->sc_flags & ILF_STATPENDING) { 570 1.1 ragge ifp->if_timer = sc->sc_scaninterval; 571 1.1 ragge return; 572 1.1 ragge } 573 1.1 ragge s = splnet(); 574 1.1 ragge sc->sc_flags |= ILF_STATPENDING; 575 1.1 ragge if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) 576 1.1 ragge ilstart(ifp); 577 1.1 ragge splx(s); 578 1.1 ragge ifp->if_timer = sc->sc_scaninterval; 579 1.1 ragge } 580 1.1 ragge 581 1.1 ragge /* 582 1.1 ragge * Total up the on-board statistics. 583 1.1 ragge */ 584 1.1 ragge void 585 1.1 ragge iltotal(struct il_softc *sc) 586 1.1 ragge { 587 1.1 ragge struct ifnet *ifp = &sc->sc_if; 588 1.1 ragge u_short *interval, *sum, *end; 589 1.1 ragge 590 1.1 ragge interval = &sc->sc_stats.ils_frames; 591 1.1 ragge sum = &sc->sc_sum.ils_frames; 592 1.1 ragge end = sc->sc_sum.ils_fill2; 593 1.1 ragge while (sum < end) 594 1.1 ragge *sum++ += *interval++; 595 1.1 ragge sc->sc_if.if_collisions = sc->sc_sum.ils_collis; 596 1.1 ragge if ((sc->sc_flags & ILF_SETADDR) && 597 1.17 dyoung (memcmp(sc->sc_stats.ils_addr, CLLADDR(ifp->if_sadl), 598 1.5 wiz ETHER_ADDR_LEN) != 0)) { 599 1.30 msaitoh log(LOG_ERR, "%s: physaddr reverted\n", 600 1.30 msaitoh device_xname(sc->sc_dev)); 601 1.1 ragge sc->sc_flags &= ~ILF_RUNNING; 602 1.1 ragge ilinit(&sc->sc_if); 603 1.1 ragge } 604 1.1 ragge } 605 1.1 ragge 606 1.1 ragge #ifdef notyet 607 1.1 ragge /* 608 1.1 ragge * set ethernet address for unit 609 1.1 ragge */ 610 1.1 ragge void 611 1.1 ragge il_setaddr(u_char *physaddr, struct il_softc *sc) 612 1.1 ragge { 613 1.1 ragge if (! (sc->sc_flags & ILF_RUNNING)) 614 1.1 ragge return; 615 1.11 simonb 616 1.22 tsutsui memcpy((void *)is->is_addr, (void *)physaddr, sizeof is->is_addr); 617 1.1 ragge sc->sc_flags &= ~ILF_RUNNING; 618 1.1 ragge sc->sc_flags |= ILF_SETADDR; 619 1.1 ragge ilinit(&sc->sc_if); 620 1.1 ragge } 621 1.1 ragge #endif 622