1 1.32 thorpej /* $NetBSD: am79900.c,v 1.32 2022/09/25 18:43:32 thorpej Exp $ */ 2 1.13 thorpej 3 1.13 thorpej /*- 4 1.13 thorpej * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 1.13 thorpej * All rights reserved. 6 1.13 thorpej * 7 1.13 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.13 thorpej * by Jason R. Thorpe. 9 1.13 thorpej * 10 1.13 thorpej * Redistribution and use in source and binary forms, with or without 11 1.13 thorpej * modification, are permitted provided that the following conditions 12 1.13 thorpej * are met: 13 1.13 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.13 thorpej * notice, this list of conditions and the following disclaimer. 15 1.13 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.13 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.13 thorpej * documentation and/or other materials provided with the distribution. 18 1.13 thorpej * 19 1.13 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.13 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.13 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.13 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.13 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.13 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.13 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.13 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.13 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.13 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.13 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.13 thorpej */ 31 1.12 agc 32 1.12 agc /*- 33 1.12 agc * Copyright (c) 1992, 1993 34 1.12 agc * The Regents of the University of California. All rights reserved. 35 1.12 agc * 36 1.12 agc * This code is derived from software contributed to Berkeley by 37 1.12 agc * Ralph Campbell and Rick Macklem. 38 1.12 agc * 39 1.12 agc * Redistribution and use in source and binary forms, with or without 40 1.12 agc * modification, are permitted provided that the following conditions 41 1.12 agc * are met: 42 1.12 agc * 1. Redistributions of source code must retain the above copyright 43 1.12 agc * notice, this list of conditions and the following disclaimer. 44 1.12 agc * 2. Redistributions in binary form must reproduce the above copyright 45 1.12 agc * notice, this list of conditions and the following disclaimer in the 46 1.12 agc * documentation and/or other materials provided with the distribution. 47 1.12 agc * 3. Neither the name of the University nor the names of its contributors 48 1.12 agc * may be used to endorse or promote products derived from this software 49 1.12 agc * without specific prior written permission. 50 1.12 agc * 51 1.12 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 52 1.12 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 1.12 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 1.12 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 55 1.12 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 1.12 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57 1.12 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 1.12 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 1.12 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 1.12 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 1.12 agc * SUCH DAMAGE. 62 1.12 agc * 63 1.12 agc * @(#)if_le.c 8.2 (Berkeley) 11/16/93 64 1.12 agc */ 65 1.1 drochner 66 1.1 drochner /*- 67 1.1 drochner * Copyright (c) 1998 68 1.1 drochner * Matthias Drochner. All rights reserved. 69 1.1 drochner * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 70 1.1 drochner * 71 1.1 drochner * This code is derived from software contributed to Berkeley by 72 1.1 drochner * Ralph Campbell and Rick Macklem. 73 1.1 drochner * 74 1.1 drochner * Redistribution and use in source and binary forms, with or without 75 1.1 drochner * modification, are permitted provided that the following conditions 76 1.1 drochner * are met: 77 1.1 drochner * 1. Redistributions of source code must retain the above copyright 78 1.1 drochner * notice, this list of conditions and the following disclaimer. 79 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright 80 1.1 drochner * notice, this list of conditions and the following disclaimer in the 81 1.1 drochner * documentation and/or other materials provided with the distribution. 82 1.1 drochner * 3. All advertising materials mentioning features or use of this software 83 1.1 drochner * must display the following acknowledgement: 84 1.1 drochner * This product includes software developed by the University of 85 1.1 drochner * California, Berkeley and its contributors. 86 1.1 drochner * 4. Neither the name of the University nor the names of its contributors 87 1.1 drochner * may be used to endorse or promote products derived from this software 88 1.1 drochner * without specific prior written permission. 89 1.1 drochner * 90 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 91 1.1 drochner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 92 1.1 drochner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 93 1.1 drochner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 94 1.1 drochner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 95 1.1 drochner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 96 1.1 drochner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 97 1.1 drochner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 98 1.1 drochner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 99 1.1 drochner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 100 1.1 drochner * SUCH DAMAGE. 101 1.1 drochner * 102 1.1 drochner * @(#)if_le.c 8.2 (Berkeley) 11/16/93 103 1.1 drochner */ 104 1.11 lukem 105 1.11 lukem #include <sys/cdefs.h> 106 1.32 thorpej __KERNEL_RCSID(0, "$NetBSD: am79900.c,v 1.32 2022/09/25 18:43:32 thorpej Exp $"); 107 1.1 drochner 108 1.1 drochner #include <sys/param.h> 109 1.1 drochner #include <sys/systm.h> 110 1.15 perry #include <sys/mbuf.h> 111 1.1 drochner #include <sys/syslog.h> 112 1.1 drochner #include <sys/socket.h> 113 1.1 drochner #include <sys/device.h> 114 1.1 drochner #include <sys/ioctl.h> 115 1.1 drochner #include <sys/errno.h> 116 1.24 riastrad #include <sys/rndsource.h> 117 1.1 drochner 118 1.1 drochner #include <net/if.h> 119 1.1 drochner #include <net/if_dl.h> 120 1.1 drochner #include <net/if_ether.h> 121 1.1 drochner #include <net/if_media.h> 122 1.1 drochner #include <net/bpf.h> 123 1.1 drochner 124 1.1 drochner #include <dev/ic/lancereg.h> 125 1.1 drochner #include <dev/ic/lancevar.h> 126 1.1 drochner #include <dev/ic/am79900reg.h> 127 1.1 drochner #include <dev/ic/am79900var.h> 128 1.1 drochner 129 1.14 thorpej static void am79900_meminit(struct lance_softc *); 130 1.14 thorpej static void am79900_start(struct ifnet *); 131 1.1 drochner 132 1.9 mrg #if defined(_KERNEL_OPT) 133 1.1 drochner #include "opt_ddb.h" 134 1.1 drochner #endif 135 1.1 drochner 136 1.1 drochner #ifdef LEDEBUG 137 1.14 thorpej static void am79900_recv_print(struct lance_softc *, int); 138 1.14 thorpej static void am79900_xmit_print(struct lance_softc *, int); 139 1.1 drochner #endif 140 1.1 drochner 141 1.1 drochner #define ifp (&sc->sc_ethercom.ec_if) 142 1.1 drochner 143 1.1 drochner void 144 1.14 thorpej am79900_config(struct am79900_softc *sc) 145 1.1 drochner { 146 1.1 drochner int mem, i; 147 1.1 drochner 148 1.1 drochner sc->lsc.sc_meminit = am79900_meminit; 149 1.1 drochner sc->lsc.sc_start = am79900_start; 150 1.1 drochner 151 1.1 drochner lance_config(&sc->lsc); 152 1.26 ozaki if_deferred_start_init(&sc->lsc.sc_ethercom.ec_if, NULL); 153 1.1 drochner 154 1.1 drochner mem = 0; 155 1.1 drochner sc->lsc.sc_initaddr = mem; 156 1.1 drochner mem += sizeof(struct leinit); 157 1.1 drochner sc->lsc.sc_rmdaddr = mem; 158 1.1 drochner mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; 159 1.1 drochner sc->lsc.sc_tmdaddr = mem; 160 1.1 drochner mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; 161 1.1 drochner for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN) 162 1.1 drochner sc->lsc.sc_rbufaddr[i] = mem; 163 1.1 drochner for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN) 164 1.1 drochner sc->lsc.sc_tbufaddr[i] = mem; 165 1.1 drochner 166 1.1 drochner if (mem > sc->lsc.sc_memsize) 167 1.19 tsutsui panic("%s: memsize", device_xname(sc->lsc.sc_dev)); 168 1.1 drochner } 169 1.1 drochner 170 1.1 drochner /* 171 1.1 drochner * Set up the initialization block and the descriptor rings. 172 1.1 drochner */ 173 1.14 thorpej static void 174 1.14 thorpej am79900_meminit(struct lance_softc *sc) 175 1.1 drochner { 176 1.1 drochner u_long a; 177 1.1 drochner int bix; 178 1.1 drochner struct leinit init; 179 1.1 drochner struct lermd rmd; 180 1.1 drochner struct letmd tmd; 181 1.19 tsutsui uint8_t *myaddr; 182 1.1 drochner 183 1.1 drochner if (ifp->if_flags & IFF_PROMISC) 184 1.1 drochner init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; 185 1.1 drochner else 186 1.1 drochner init.init_mode = LE_MODE_NORMAL; 187 1.1 drochner if (sc->sc_initmodemedia == 1) 188 1.1 drochner init.init_mode |= LE_MODE_PSEL0; 189 1.1 drochner 190 1.1 drochner init.init_mode |= ((ffs(sc->sc_ntbuf) - 1) << 28) 191 1.1 drochner | ((ffs(sc->sc_nrbuf) - 1) << 20); 192 1.1 drochner 193 1.1 drochner /* 194 1.1 drochner * Update our private copy of the Ethernet address. 195 1.1 drochner * We NEED the copy so we can ensure its alignment! 196 1.1 drochner */ 197 1.18 dyoung memcpy(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN); 198 1.1 drochner myaddr = sc->sc_enaddr; 199 1.1 drochner 200 1.1 drochner init.init_padr[0] = myaddr[0] | (myaddr[1] << 8) 201 1.1 drochner | (myaddr[2] << 16) | (myaddr[3] << 24); 202 1.1 drochner init.init_padr[1] = myaddr[4] | (myaddr[5] << 8); 203 1.1 drochner lance_setladrf(&sc->sc_ethercom, init.init_ladrf); 204 1.1 drochner 205 1.1 drochner sc->sc_last_rd = 0; 206 1.1 drochner sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; 207 1.1 drochner 208 1.1 drochner a = sc->sc_addr + LE_RMDADDR(sc, 0); 209 1.1 drochner init.init_rdra = a; 210 1.1 drochner 211 1.1 drochner a = sc->sc_addr + LE_TMDADDR(sc, 0); 212 1.1 drochner init.init_tdra = a; 213 1.1 drochner 214 1.1 drochner (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); 215 1.1 drochner 216 1.1 drochner /* 217 1.1 drochner * Set up receive ring descriptors. 218 1.1 drochner */ 219 1.1 drochner for (bix = 0; bix < sc->sc_nrbuf; bix++) { 220 1.1 drochner a = sc->sc_addr + LE_RBUFADDR(sc, bix); 221 1.1 drochner rmd.rmd0 = a; 222 1.1 drochner rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff); 223 1.1 drochner rmd.rmd2 = 0; 224 1.1 drochner rmd.rmd3 = 0; 225 1.1 drochner (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), 226 1.1 drochner sizeof(rmd)); 227 1.1 drochner } 228 1.1 drochner 229 1.1 drochner /* 230 1.1 drochner * Set up transmit ring descriptors. 231 1.1 drochner */ 232 1.1 drochner for (bix = 0; bix < sc->sc_ntbuf; bix++) { 233 1.1 drochner a = sc->sc_addr + LE_TBUFADDR(sc, bix); 234 1.1 drochner tmd.tmd0 = a; 235 1.1 drochner tmd.tmd1 = LE_T1_ONES; 236 1.1 drochner tmd.tmd2 = 0; 237 1.1 drochner tmd.tmd3 = 0; 238 1.1 drochner (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), 239 1.1 drochner sizeof(tmd)); 240 1.1 drochner } 241 1.1 drochner } 242 1.1 drochner 243 1.17 perry static inline void 244 1.14 thorpej am79900_rint(struct lance_softc *sc) 245 1.1 drochner { 246 1.5 augustss int bix; 247 1.1 drochner int rp; 248 1.1 drochner struct lermd rmd; 249 1.1 drochner 250 1.1 drochner bix = sc->sc_last_rd; 251 1.1 drochner 252 1.1 drochner /* Process all buffers with valid data. */ 253 1.1 drochner for (;;) { 254 1.1 drochner rp = LE_RMDADDR(sc, bix); 255 1.1 drochner (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); 256 1.1 drochner 257 1.1 drochner if (rmd.rmd1 & LE_R1_OWN) 258 1.1 drochner break; 259 1.1 drochner 260 1.1 drochner if (rmd.rmd1 & LE_R1_ERR) { 261 1.1 drochner if (rmd.rmd1 & LE_R1_ENP) { 262 1.1 drochner #ifdef LEDEBUG 263 1.1 drochner if ((rmd.rmd1 & LE_R1_OFLO) == 0) { 264 1.1 drochner if (rmd.rmd1 & LE_R1_FRAM) 265 1.1 drochner printf("%s: framing error\n", 266 1.19 tsutsui device_xname(sc->sc_dev)); 267 1.1 drochner if (rmd.rmd1 & LE_R1_CRC) 268 1.1 drochner printf("%s: crc mismatch\n", 269 1.19 tsutsui device_xname(sc->sc_dev)); 270 1.1 drochner } 271 1.1 drochner #endif 272 1.1 drochner } else { 273 1.1 drochner if (rmd.rmd1 & LE_R1_OFLO) 274 1.1 drochner printf("%s: overflow\n", 275 1.19 tsutsui device_xname(sc->sc_dev)); 276 1.1 drochner } 277 1.1 drochner if (rmd.rmd1 & LE_R1_BUFF) 278 1.1 drochner printf("%s: receive buffer error\n", 279 1.19 tsutsui device_xname(sc->sc_dev)); 280 1.29 skrll if_statinc(ifp, if_ierrors); 281 1.1 drochner } else if ((rmd.rmd1 & (LE_R1_STP | LE_R1_ENP)) != 282 1.1 drochner (LE_R1_STP | LE_R1_ENP)) { 283 1.1 drochner printf("%s: dropping chained buffer\n", 284 1.19 tsutsui device_xname(sc->sc_dev)); 285 1.29 skrll if_statinc(ifp, if_ierrors); 286 1.1 drochner } else { 287 1.1 drochner #ifdef LEDEBUG 288 1.1 drochner if (sc->sc_debug) 289 1.1 drochner am79900_recv_print(sc, sc->sc_last_rd); 290 1.1 drochner #endif 291 1.1 drochner lance_read(sc, LE_RBUFADDR(sc, bix), 292 1.1 drochner (rmd.rmd2 & 0xfff) - 4); 293 1.1 drochner } 294 1.1 drochner 295 1.1 drochner rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff); 296 1.1 drochner rmd.rmd2 = 0; 297 1.1 drochner rmd.rmd3 = 0; 298 1.1 drochner (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); 299 1.1 drochner 300 1.1 drochner #ifdef LEDEBUG 301 1.1 drochner if (sc->sc_debug) 302 1.1 drochner printf("sc->sc_last_rd = %x, rmd: " 303 1.1 drochner "adr %08x, flags/blen %08x\n", 304 1.1 drochner sc->sc_last_rd, 305 1.1 drochner rmd.rmd0, rmd.rmd1); 306 1.1 drochner #endif 307 1.1 drochner 308 1.1 drochner if (++bix == sc->sc_nrbuf) 309 1.1 drochner bix = 0; 310 1.1 drochner } 311 1.1 drochner 312 1.1 drochner sc->sc_last_rd = bix; 313 1.1 drochner } 314 1.1 drochner 315 1.17 perry static inline void 316 1.14 thorpej am79900_tint(struct lance_softc *sc) 317 1.1 drochner { 318 1.5 augustss int bix; 319 1.1 drochner struct letmd tmd; 320 1.1 drochner 321 1.1 drochner bix = sc->sc_first_td; 322 1.1 drochner 323 1.1 drochner for (;;) { 324 1.1 drochner if (sc->sc_no_td <= 0) 325 1.1 drochner break; 326 1.1 drochner 327 1.1 drochner (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), 328 1.1 drochner sizeof(tmd)); 329 1.1 drochner 330 1.1 drochner #ifdef LEDEBUG 331 1.1 drochner if (sc->sc_debug) 332 1.1 drochner printf("trans tmd: " 333 1.1 drochner "adr %08x, flags/blen %08x\n", 334 1.1 drochner tmd.tmd0, tmd.tmd1); 335 1.1 drochner #endif 336 1.1 drochner 337 1.1 drochner if (tmd.tmd1 & LE_T1_OWN) 338 1.1 drochner break; 339 1.1 drochner 340 1.1 drochner if (tmd.tmd1 & LE_T1_ERR) { 341 1.1 drochner if (tmd.tmd2 & LE_T2_BUFF) 342 1.1 drochner printf("%s: transmit buffer error\n", 343 1.19 tsutsui device_xname(sc->sc_dev)); 344 1.1 drochner else if (tmd.tmd2 & LE_T2_UFLO) 345 1.19 tsutsui printf("%s: underflow\n", 346 1.19 tsutsui device_xname(sc->sc_dev)); 347 1.1 drochner if (tmd.tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { 348 1.1 drochner lance_reset(sc); 349 1.1 drochner return; 350 1.1 drochner } 351 1.1 drochner if (tmd.tmd2 & LE_T2_LCAR) { 352 1.1 drochner sc->sc_havecarrier = 0; 353 1.1 drochner if (sc->sc_nocarrier) 354 1.1 drochner (*sc->sc_nocarrier)(sc); 355 1.1 drochner else 356 1.1 drochner printf("%s: lost carrier\n", 357 1.19 tsutsui device_xname(sc->sc_dev)); 358 1.1 drochner } 359 1.1 drochner if (tmd.tmd2 & LE_T2_LCOL) 360 1.29 skrll if_statinc(ifp, if_collisions); 361 1.1 drochner if (tmd.tmd2 & LE_T2_RTRY) { 362 1.4 thorpej #ifdef LEDEBUG 363 1.1 drochner printf("%s: excessive collisions\n", 364 1.19 tsutsui device_xname(sc->sc_dev)); 365 1.4 thorpej #endif 366 1.29 skrll if_statadd(ifp, if_collisions, 16); 367 1.1 drochner } 368 1.29 skrll if_statinc(ifp, if_oerrors); 369 1.1 drochner } else { 370 1.1 drochner if (tmd.tmd1 & LE_T1_ONE) 371 1.29 skrll if_statinc(ifp, if_collisions); 372 1.1 drochner else if (tmd.tmd1 & LE_T1_MORE) 373 1.1 drochner /* Real number is unknown. */ 374 1.29 skrll if_statadd(ifp, if_collisions, 2); 375 1.29 skrll if_statinc(ifp, if_opackets); 376 1.1 drochner } 377 1.1 drochner 378 1.1 drochner if (++bix == sc->sc_ntbuf) 379 1.1 drochner bix = 0; 380 1.1 drochner 381 1.1 drochner --sc->sc_no_td; 382 1.1 drochner } 383 1.1 drochner 384 1.1 drochner sc->sc_first_td = bix; 385 1.1 drochner 386 1.25 ozaki if_schedule_deferred_start(ifp); 387 1.1 drochner 388 1.1 drochner if (sc->sc_no_td == 0) 389 1.1 drochner ifp->if_timer = 0; 390 1.1 drochner } 391 1.1 drochner 392 1.1 drochner /* 393 1.1 drochner * Controller interrupt. 394 1.1 drochner */ 395 1.1 drochner int 396 1.14 thorpej am79900_intr(void *arg) 397 1.1 drochner { 398 1.5 augustss struct lance_softc *sc = arg; 399 1.19 tsutsui uint16_t isr; 400 1.1 drochner 401 1.1 drochner isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0; 402 1.1 drochner sc->sc_saved_csr0 = 0; 403 1.6 jdolecek #if defined(LEDEBUG) && LEDEBUG > 1 404 1.1 drochner if (sc->sc_debug) 405 1.1 drochner printf("%s: am79900_intr entering with isr=%04x\n", 406 1.19 tsutsui device_xname(sc->sc_dev), isr); 407 1.1 drochner #endif 408 1.1 drochner if ((isr & LE_C0_INTR) == 0) 409 1.1 drochner return (0); 410 1.1 drochner 411 1.1 drochner (*sc->sc_wrcsr)(sc, LE_CSR0, 412 1.1 drochner isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR | 413 1.1 drochner LE_C0_RINT | LE_C0_TINT | LE_C0_IDON)); 414 1.1 drochner if (isr & LE_C0_ERR) { 415 1.1 drochner if (isr & LE_C0_BABL) { 416 1.1 drochner #ifdef LEDEBUG 417 1.19 tsutsui printf("%s: babble\n", device_xname(sc->sc_dev)); 418 1.1 drochner #endif 419 1.29 skrll if_statinc(ifp, if_oerrors); 420 1.1 drochner } 421 1.1 drochner #if 0 422 1.1 drochner if (isr & LE_C0_CERR) { 423 1.19 tsutsui printf("%s: collision error\n", 424 1.19 tsutsui device_xname(sc->sc_dev)); 425 1.29 skrll if_statinc(ifp, if_collisions); 426 1.1 drochner } 427 1.1 drochner #endif 428 1.1 drochner if (isr & LE_C0_MISS) { 429 1.1 drochner #ifdef LEDEBUG 430 1.19 tsutsui printf("%s: missed packet\n", device_xname(sc->sc_dev)); 431 1.1 drochner #endif 432 1.29 skrll if_statinc(ifp, if_ierrors); 433 1.1 drochner } 434 1.1 drochner if (isr & LE_C0_MERR) { 435 1.19 tsutsui printf("%s: memory error\n", device_xname(sc->sc_dev)); 436 1.1 drochner lance_reset(sc); 437 1.1 drochner return (1); 438 1.1 drochner } 439 1.1 drochner } 440 1.1 drochner 441 1.1 drochner if ((isr & LE_C0_RXON) == 0) { 442 1.19 tsutsui printf("%s: receiver disabled\n", device_xname(sc->sc_dev)); 443 1.29 skrll if_statinc(ifp, if_ierrors); 444 1.1 drochner lance_reset(sc); 445 1.1 drochner return (1); 446 1.1 drochner } 447 1.1 drochner if ((isr & LE_C0_TXON) == 0) { 448 1.19 tsutsui printf("%s: transmitter disabled\n", device_xname(sc->sc_dev)); 449 1.29 skrll if_statinc(ifp, if_oerrors); 450 1.1 drochner lance_reset(sc); 451 1.1 drochner return (1); 452 1.1 drochner } 453 1.1 drochner 454 1.1 drochner /* 455 1.1 drochner * Pretend we have carrier; if we don't this will be cleared 456 1.1 drochner * shortly. 457 1.1 drochner */ 458 1.31 roy const int ocarrier = sc->sc_havecarrier; 459 1.1 drochner sc->sc_havecarrier = 1; 460 1.1 drochner 461 1.1 drochner if (isr & LE_C0_RINT) 462 1.1 drochner am79900_rint(sc); 463 1.1 drochner if (isr & LE_C0_TINT) 464 1.1 drochner am79900_tint(sc); 465 1.15 perry 466 1.31 roy if (sc->sc_havecarrier != ocarrier) 467 1.31 roy if_link_state_change(ifp, 468 1.31 roy sc->sc_havecarrier ? LINK_STATE_UP : LINK_STATE_DOWN); 469 1.31 roy 470 1.2 drochner rnd_add_uint32(&sc->rnd_source, isr); 471 1.1 drochner 472 1.1 drochner return (1); 473 1.1 drochner } 474 1.1 drochner 475 1.1 drochner #undef ifp 476 1.1 drochner 477 1.1 drochner /* 478 1.1 drochner * Setup output on interface. 479 1.1 drochner * Get another datagram to send off of the interface queue, and map it to the 480 1.1 drochner * interface before starting the output. 481 1.3 mycroft * Called only at splnet or interrupt level. 482 1.1 drochner */ 483 1.14 thorpej static void 484 1.14 thorpej am79900_start(struct ifnet *ifp) 485 1.1 drochner { 486 1.5 augustss struct lance_softc *sc = ifp->if_softc; 487 1.5 augustss int bix; 488 1.5 augustss struct mbuf *m; 489 1.1 drochner struct letmd tmd; 490 1.1 drochner int rp; 491 1.1 drochner int len; 492 1.1 drochner 493 1.30 thorpej if ((ifp->if_flags & IFF_RUNNING) != IFF_RUNNING) 494 1.1 drochner return; 495 1.1 drochner 496 1.1 drochner bix = sc->sc_last_td; 497 1.1 drochner 498 1.30 thorpej while (sc->sc_no_td < sc->sc_ntbuf) { 499 1.1 drochner rp = LE_TMDADDR(sc, bix); 500 1.1 drochner (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); 501 1.1 drochner 502 1.1 drochner if (tmd.tmd1 & LE_T1_OWN) { 503 1.30 thorpej printf("%s: missing buffer, no_td = %d, last_td = %d\n", 504 1.30 thorpej device_xname(sc->sc_dev), sc->sc_no_td, 505 1.30 thorpej sc->sc_last_td); 506 1.30 thorpej break; 507 1.1 drochner } 508 1.1 drochner 509 1.8 thorpej IFQ_DEQUEUE(&ifp->if_snd, m); 510 1.1 drochner if (m == 0) 511 1.1 drochner break; 512 1.1 drochner 513 1.1 drochner /* 514 1.1 drochner * If BPF is listening on this interface, let it see the packet 515 1.1 drochner * before we commit it to the wire. 516 1.1 drochner */ 517 1.28 msaitoh bpf_mtap(ifp, m, BPF_D_OUT); 518 1.1 drochner 519 1.1 drochner /* 520 1.1 drochner * Copy the mbuf chain into the transmit buffer. 521 1.1 drochner */ 522 1.1 drochner len = lance_put(sc, LE_TBUFADDR(sc, bix), m); 523 1.1 drochner 524 1.1 drochner #ifdef LEDEBUG 525 1.1 drochner if (len > ETHERMTU + sizeof(struct ether_header)) 526 1.1 drochner printf("packet length %d\n", len); 527 1.1 drochner #endif 528 1.1 drochner 529 1.1 drochner ifp->if_timer = 5; 530 1.1 drochner 531 1.1 drochner /* 532 1.1 drochner * Init transmit registers, and set transmit start flag. 533 1.1 drochner */ 534 1.1 drochner tmd.tmd1 = LE_T1_OWN | LE_T1_STP | LE_T1_ENP | LE_T1_ONES | (-len & 0xfff); 535 1.1 drochner tmd.tmd2 = 0; 536 1.1 drochner tmd.tmd3 = 0; 537 1.1 drochner 538 1.1 drochner (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); 539 1.1 drochner 540 1.1 drochner #ifdef LEDEBUG 541 1.1 drochner if (sc->sc_debug) 542 1.1 drochner am79900_xmit_print(sc, sc->sc_last_td); 543 1.1 drochner #endif 544 1.1 drochner 545 1.1 drochner (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); 546 1.1 drochner 547 1.1 drochner if (++bix == sc->sc_ntbuf) 548 1.1 drochner bix = 0; 549 1.1 drochner 550 1.30 thorpej sc->sc_no_td++; 551 1.1 drochner } 552 1.1 drochner 553 1.1 drochner sc->sc_last_td = bix; 554 1.1 drochner } 555 1.1 drochner 556 1.1 drochner #ifdef LEDEBUG 557 1.14 thorpej static void 558 1.14 thorpej am79900_recv_print(struct lance_softc *sc, int no) 559 1.1 drochner { 560 1.1 drochner struct lermd rmd; 561 1.19 tsutsui uint16_t len; 562 1.1 drochner struct ether_header eh; 563 1.1 drochner 564 1.1 drochner (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); 565 1.1 drochner len = (rmd.rmd2 & 0xfff) - 4; 566 1.19 tsutsui printf("%s: receive buffer %d, len = %d\n", 567 1.19 tsutsui device_xname(sc->sc_dev), no, len); 568 1.19 tsutsui printf("%s: status %04x\n", device_xname(sc->sc_dev), 569 1.1 drochner (*sc->sc_rdcsr)(sc, LE_CSR0)); 570 1.1 drochner printf("%s: adr %08x, flags/blen %08x\n", 571 1.19 tsutsui device_xname(sc->sc_dev), rmd.rmd0, rmd.rmd1); 572 1.1 drochner if (len >= sizeof(eh)) { 573 1.1 drochner (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); 574 1.19 tsutsui printf("%s: dst %s", device_xname(sc->sc_dev), 575 1.1 drochner ether_sprintf(eh.ether_dhost)); 576 1.1 drochner printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), 577 1.1 drochner ntohs(eh.ether_type)); 578 1.1 drochner } 579 1.1 drochner } 580 1.1 drochner 581 1.14 thorpej static void 582 1.14 thorpej am79900_xmit_print(struct lance_softc *sc, int no) 583 1.1 drochner { 584 1.1 drochner struct letmd tmd; 585 1.19 tsutsui uint16_t len; 586 1.1 drochner struct ether_header eh; 587 1.1 drochner 588 1.1 drochner (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); 589 1.1 drochner len = -(tmd.tmd1 & 0xfff); 590 1.19 tsutsui printf("%s: transmit buffer %d, len = %d\n", 591 1.19 tsutsui device_xname(sc->sc_dev), no, len); 592 1.19 tsutsui printf("%s: status %04x\n", device_xname(sc->sc_dev), 593 1.1 drochner (*sc->sc_rdcsr)(sc, LE_CSR0)); 594 1.1 drochner printf("%s: adr %08x, flags/blen %08x\n", 595 1.19 tsutsui device_xname(sc->sc_dev), tmd.tmd0, tmd.tmd1); 596 1.1 drochner if (len >= sizeof(eh)) { 597 1.1 drochner (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); 598 1.19 tsutsui printf("%s: dst %s", device_xname(sc->sc_dev), 599 1.1 drochner ether_sprintf(eh.ether_dhost)); 600 1.1 drochner printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), 601 1.1 drochner ntohs(eh.ether_type)); 602 1.1 drochner } 603 1.1 drochner } 604 1.1 drochner #endif /* LEDEBUG */ 605