1 /* $NetBSD: mb8795.c,v 1.48 2010/04/05 07:19:31 joerg Exp $ */ 2 /* 3 * Copyright (c) 1998 Darrin B. Jewell 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Darrin B. Jewell 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: mb8795.c,v 1.48 2010/04/05 07:19:31 joerg Exp $"); 34 35 #include "opt_inet.h" 36 #include "rnd.h" 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/mbuf.h> 41 #include <sys/syslog.h> 42 #include <sys/socket.h> 43 #include <sys/device.h> 44 #include <sys/malloc.h> 45 #include <sys/ioctl.h> 46 #include <sys/errno.h> 47 #if NRND > 0 48 #include <sys/rnd.h> 49 #endif 50 51 #include <net/if.h> 52 #include <net/if_dl.h> 53 #include <net/if_ether.h> 54 55 #include <net/if_media.h> 56 57 #ifdef INET 58 #include <netinet/in.h> 59 #include <netinet/if_inarp.h> 60 #include <netinet/in_systm.h> 61 #include <netinet/in_var.h> 62 #include <netinet/ip.h> 63 #endif 64 65 66 67 #include <net/bpf.h> 68 #include <net/bpfdesc.h> 69 70 #include <machine/cpu.h> 71 #include <machine/bus.h> 72 #include <machine/intr.h> 73 74 /* @@@ this is here for the REALIGN_DMABUF hack below */ 75 #include "nextdmareg.h" 76 #include "nextdmavar.h" 77 78 #include "mb8795reg.h" 79 #include "mb8795var.h" 80 81 #include "bmapreg.h" 82 83 #ifdef DEBUG 84 #define MB8795_DEBUG 85 #endif 86 87 #define PRINTF(x) printf x; 88 #ifdef MB8795_DEBUG 89 int mb8795_debug = 0; 90 #define DPRINTF(x) if (mb8795_debug) printf x; 91 #else 92 #define DPRINTF(x) 93 #endif 94 95 extern int turbo; 96 97 /* 98 * Support for 99 * Fujitsu Ethernet Data Link Controller (MB8795) 100 * and the Fujitsu Manchester Encoder/Decoder (MB502). 101 */ 102 103 void mb8795_shutdown(void *); 104 105 bus_dmamap_t mb8795_txdma_restart(bus_dmamap_t, void *); 106 void mb8795_start_dma(struct mb8795_softc *); 107 108 int mb8795_mediachange(struct ifnet *); 109 void mb8795_mediastatus(struct ifnet *, struct ifmediareq *); 110 111 void 112 mb8795_config(struct mb8795_softc *sc, int *media, int nmedia, int defmedia) 113 { 114 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 115 116 DPRINTF(("%s: mb8795_config()\n",sc->sc_dev.dv_xname)); 117 118 /* Initialize ifnet structure. */ 119 memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ); 120 ifp->if_softc = sc; 121 ifp->if_start = mb8795_start; 122 ifp->if_ioctl = mb8795_ioctl; 123 ifp->if_watchdog = mb8795_watchdog; 124 ifp->if_flags = 125 IFF_BROADCAST | IFF_NOTRAILERS; 126 127 /* Initialize media goo. */ 128 ifmedia_init(&sc->sc_media, 0, mb8795_mediachange, 129 mb8795_mediastatus); 130 if (media != NULL) { 131 int i; 132 for (i = 0; i < nmedia; i++) 133 ifmedia_add(&sc->sc_media, media[i], 0, NULL); 134 ifmedia_set(&sc->sc_media, defmedia); 135 } else { 136 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); 137 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL); 138 } 139 140 /* Attach the interface. */ 141 if_attach(ifp); 142 ether_ifattach(ifp, sc->sc_enaddr); 143 144 sc->sc_sh = shutdownhook_establish(mb8795_shutdown, sc); 145 if (sc->sc_sh == NULL) 146 panic("mb8795_config: can't establish shutdownhook"); 147 148 #if NRND > 0 149 rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname, 150 RND_TYPE_NET, 0); 151 #endif 152 153 DPRINTF(("%s: leaving mb8795_config()\n",sc->sc_dev.dv_xname)); 154 } 155 156 /* 157 * Media change callback. 158 */ 159 int 160 mb8795_mediachange(struct ifnet *ifp) 161 { 162 struct mb8795_softc *sc = ifp->if_softc; 163 int data; 164 165 if (turbo) 166 return (0); 167 168 switch IFM_SUBTYPE(sc->sc_media.ifm_media) { 169 case IFM_AUTO: 170 if ((bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) & 171 BMAP_DATA_UTPENABLED_MASK) || 172 !(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) & 173 BMAP_DATA_UTPCARRIER_MASK)) { 174 data = BMAP_DATA_UTPENABLE; 175 sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_T; 176 } else { 177 data = BMAP_DATA_BNCENABLE; 178 sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_2; 179 } 180 break; 181 case IFM_10_T: 182 data = BMAP_DATA_UTPENABLE; 183 break; 184 case IFM_10_2: 185 data = BMAP_DATA_BNCENABLE; 186 break; 187 default: 188 return (1); 189 break; 190 } 191 192 bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, 193 BMAP_DDIR, BMAP_DDIR_UTPENABLE_MASK); 194 bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, 195 BMAP_DATA, data); 196 197 return (0); 198 } 199 200 /* 201 * Media status callback. 202 */ 203 void 204 mb8795_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) 205 { 206 struct mb8795_softc *sc = ifp->if_softc; 207 208 if (turbo) 209 return; 210 211 if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_AUTO) { 212 ifmr->ifm_active = sc->sc_media.ifm_cur->ifm_data; 213 } 214 if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_10_T) { 215 ifmr->ifm_status = IFM_AVALID; 216 if (!(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) & 217 BMAP_DATA_UTPCARRIER_MASK)) 218 ifmr->ifm_status |= IFM_ACTIVE; 219 } else { 220 ifmr->ifm_status &= ~IFM_AVALID; /* don't know for 10_2 */ 221 } 222 return; 223 } 224 225 /****************************************************************/ 226 #ifdef MB8795_DEBUG 227 #define XCHR(x) hexdigits[(x) & 0xf] 228 static void 229 mb8795_hex_dump(unsigned char *pkt, size_t len) 230 { 231 size_t i, j; 232 233 printf("00000000 "); 234 for(i=0; i<len; i++) { 235 printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i])); 236 if ((i+1) % 16 == 8) { 237 printf(" "); 238 } 239 if ((i+1) % 16 == 0) { 240 printf(" %c", '|'); 241 for(j=0; j<16; j++) { 242 printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.'); 243 } 244 printf("%c\n%c%c%c%c%c%c%c%c ", '|', 245 XCHR((i+1)>>28),XCHR((i+1)>>24),XCHR((i+1)>>20),XCHR((i+1)>>16), 246 XCHR((i+1)>>12), XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1)); 247 } 248 } 249 printf("\n"); 250 } 251 #undef XCHR 252 #endif 253 254 /* 255 * Controller receive interrupt. 256 */ 257 void 258 mb8795_rint(struct mb8795_softc *sc) 259 { 260 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 261 int error = 0; 262 u_char rxstat; 263 u_char rxmask; 264 265 rxstat = MB_READ_REG(sc, MB8795_RXSTAT); 266 rxmask = MB_READ_REG(sc, MB8795_RXMASK); 267 268 MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR); 269 270 if (rxstat & MB8795_RXSTAT_RESET) { 271 DPRINTF(("%s: rx reset packet\n", 272 sc->sc_dev.dv_xname)); 273 error++; 274 } 275 if (rxstat & MB8795_RXSTAT_SHORT) { 276 DPRINTF(("%s: rx short packet\n", 277 sc->sc_dev.dv_xname)); 278 error++; 279 } 280 if (rxstat & MB8795_RXSTAT_ALIGNERR) { 281 DPRINTF(("%s: rx alignment error\n", 282 sc->sc_dev.dv_xname)); 283 #if 0 284 error++; 285 #endif 286 } 287 if (rxstat & MB8795_RXSTAT_CRCERR) { 288 DPRINTF(("%s: rx CRC error\n", 289 sc->sc_dev.dv_xname)); 290 #if 0 291 error++; 292 #endif 293 } 294 if (rxstat & MB8795_RXSTAT_OVERFLOW) { 295 DPRINTF(("%s: rx overflow error\n", 296 sc->sc_dev.dv_xname)); 297 #if 0 298 error++; 299 #endif 300 } 301 302 if (error) { 303 ifp->if_ierrors++; 304 /* @@@ handle more gracefully, free memory, etc. */ 305 } 306 307 if (rxstat & MB8795_RXSTAT_OK) { 308 struct mbuf *m; 309 int s; 310 s = spldma(); 311 312 while ((m = MBDMA_RX_MBUF (sc))) { 313 /* CRC is included with the packet; trim it. */ 314 m->m_pkthdr.len = m->m_len = m->m_len - ETHER_CRC_LEN; 315 m->m_pkthdr.rcvif = ifp; 316 317 /* Find receive length, keep crc */ 318 /* enable DMA interrupts while we process the packet */ 319 splx(s); 320 321 #if defined(MB8795_DEBUG) 322 /* Peek at the packet */ 323 DPRINTF(("%s: received packet, at VA %p-%p,len %d\n", 324 sc->sc_dev.dv_xname,mtod(m,u_char *),mtod(m,u_char *)+m->m_len,m->m_len)); 325 if (mb8795_debug > 3) { 326 mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len); 327 } else if (mb8795_debug > 2) { 328 mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len < 255 ? m->m_pkthdr.len : 128 ); 329 } 330 #endif 331 332 /* 333 * Pass packet to bpf if there is a listener. 334 */ 335 bpf_mtap(ifp, m); 336 337 ifp->if_ipackets++; 338 339 /* Pass the packet up. */ 340 (*ifp->if_input)(ifp, m); 341 342 s = spldma(); 343 344 } 345 346 splx(s); 347 348 } 349 350 #ifdef MB8795_DEBUG 351 if (mb8795_debug) { 352 char sbuf[256]; 353 354 snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS, rxstat); 355 printf("%s: rx interrupt, rxstat = %s\n", 356 sc->sc_dev.dv_xname, sbuf); 357 358 snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS, 359 MB_READ_REG(sc, MB8795_RXSTAT)); 360 361 printf("rxstat = 0x%s\n", sbuf); 362 363 snprintb(sbuf, sizeof(sbuf), MB8795_RXMASK_BITS, 364 MB_READ_REG(sc, MB8795_RXMASK)); 365 printf("rxmask = 0x%s\n", sbuf); 366 367 snprintb(sbuf, sizeof(sbuf), MB8795_RXMODE_BITS, 368 MB_READ_REG(sc, MB8795_RXMODE)); 369 printf("rxmode = 0x%s\n", sbuf); 370 } 371 #endif 372 373 return; 374 } 375 376 /* 377 * Controller transmit interrupt. 378 */ 379 void 380 mb8795_tint(struct mb8795_softc *sc) 381 { 382 u_char txstat; 383 u_char txmask; 384 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 385 386 panic ("tint"); 387 txstat = MB_READ_REG(sc, MB8795_TXSTAT); 388 txmask = MB_READ_REG(sc, MB8795_TXMASK); 389 390 if ((txstat & MB8795_TXSTAT_READY) || 391 (txstat & MB8795_TXSTAT_TXRECV)) { 392 /* printf("X"); */ 393 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR); 394 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE); */ 395 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_TXRXIE); */ 396 MB_WRITE_REG(sc, MB8795_TXMASK, 0); 397 if ((ifp->if_flags & IFF_RUNNING) && !IF_IS_EMPTY(&sc->sc_tx_snd)) { 398 void mb8795_start_dma(struct mb8795_softc *); /* XXXX */ 399 /* printf ("Z"); */ 400 mb8795_start_dma(sc); 401 } 402 return; 403 } 404 405 if (txstat & MB8795_TXSTAT_SHORTED) { 406 printf("%s: tx cable shorted\n", sc->sc_dev.dv_xname); 407 ifp->if_oerrors++; 408 } 409 if (txstat & MB8795_TXSTAT_UNDERFLOW) { 410 printf("%s: tx underflow\n", sc->sc_dev.dv_xname); 411 ifp->if_oerrors++; 412 } 413 if (txstat & MB8795_TXSTAT_COLLERR) { 414 DPRINTF(("%s: tx collision\n", sc->sc_dev.dv_xname)); 415 ifp->if_collisions++; 416 } 417 if (txstat & MB8795_TXSTAT_COLLERR16) { 418 printf("%s: tx 16th collision\n", sc->sc_dev.dv_xname); 419 ifp->if_oerrors++; 420 ifp->if_collisions += 16; 421 } 422 423 #if 0 424 if (txstat & MB8795_TXSTAT_READY) { 425 char sbuf[256]; 426 427 snprintb(sbuf, sizeof(sbuf), MB8795_TXSTAT_BITS, txstat); 428 panic("%s: unexpected tx interrupt %s", 429 sc->sc_dev.dv_xname, sbuf); 430 431 /* turn interrupt off */ 432 MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE); 433 } 434 #endif 435 436 return; 437 } 438 439 /****************************************************************/ 440 441 void 442 mb8795_reset(struct mb8795_softc *sc) 443 { 444 int s; 445 int i; 446 447 s = splnet(); 448 449 DPRINTF (("%s: mb8795_reset()\n",sc->sc_dev.dv_xname)); 450 451 sc->sc_ethercom.ec_if.if_flags &= ~(IFF_RUNNING|IFF_OACTIVE); 452 sc->sc_ethercom.ec_if.if_timer = 0; 453 454 MBDMA_RESET(sc); 455 456 MB_WRITE_REG(sc, MB8795_RESET, MB8795_RESET_MODE); 457 458 mb8795_mediachange(&sc->sc_ethercom.ec_if); 459 460 #if 0 /* This interrupt was sometimes failing to ack correctly 461 * causing a loop @@@ 462 */ 463 MB_WRITE_REG(sc, MB8795_TXMASK, 464 MB8795_TXMASK_UNDERFLOWIE | MB8795_TXMASK_COLLIE | MB8795_TXMASK_COLL16IE 465 | MB8795_TXMASK_PARERRIE); 466 #else 467 MB_WRITE_REG(sc, MB8795_TXMASK, 0); 468 #endif 469 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR); 470 471 #if 0 472 MB_WRITE_REG(sc, MB8795_RXMASK, 473 MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE | 474 MB8795_RXMASK_ALIGNERRIE | MB8795_RXMASK_CRCERRIE | MB8795_RXMASK_OVERFLOWIE); 475 #else 476 MB_WRITE_REG(sc, MB8795_RXMASK, 477 MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE); 478 #endif 479 480 MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR); 481 482 for(i=0;i<sizeof(sc->sc_enaddr);i++) { 483 MB_WRITE_REG(sc, MB8795_ENADDR+i, sc->sc_enaddr[i]); 484 } 485 486 DPRINTF(("%s: initializing ethernet %02x:%02x:%02x:%02x:%02x:%02x, size=%d\n", 487 sc->sc_dev.dv_xname, 488 sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2], 489 sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5], 490 sizeof(sc->sc_enaddr))); 491 492 MB_WRITE_REG(sc, MB8795_RESET, 0); 493 494 splx(s); 495 } 496 497 void 498 mb8795_watchdog(struct ifnet *ifp) 499 { 500 struct mb8795_softc *sc = ifp->if_softc; 501 502 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); 503 ++ifp->if_oerrors; 504 505 DPRINTF(("%s: %lld input errors, %lld input packets\n", 506 sc->sc_dev.dv_xname, ifp->if_ierrors, ifp->if_ipackets)); 507 508 ifp->if_flags &= ~IFF_RUNNING; 509 mb8795_init(sc); 510 } 511 512 /* 513 * Initialization of interface; set up initialization block 514 * and transmit/receive descriptor rings. 515 */ 516 void 517 mb8795_init(struct mb8795_softc *sc) 518 { 519 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 520 int s; 521 522 DPRINTF (("%s: mb8795_init()\n",sc->sc_dev.dv_xname)); 523 524 if (ifp->if_flags & IFF_UP) { 525 int rxmode; 526 527 s = spldma(); 528 if ((ifp->if_flags & IFF_RUNNING) == 0) 529 mb8795_reset(sc); 530 531 if (ifp->if_flags & IFF_PROMISC) 532 rxmode = MB8795_RXMODE_PROMISCUOUS; 533 else 534 rxmode = MB8795_RXMODE_NORMAL; 535 /* XXX add support for multicast */ 536 if (turbo) 537 rxmode |= MB8795_RXMODE_TEST; 538 539 /* switching mode probably borken now with turbo */ 540 MB_WRITE_REG(sc, MB8795_TXMODE, 541 turbo ? MB8795_TXMODE_TURBO1 : MB8795_TXMODE_LB_DISABLE); 542 MB_WRITE_REG(sc, MB8795_RXMODE, rxmode); 543 544 if ((ifp->if_flags & IFF_RUNNING) == 0) { 545 MBDMA_RX_SETUP(sc); 546 MBDMA_TX_SETUP(sc); 547 548 ifp->if_flags |= IFF_RUNNING; 549 ifp->if_flags &= ~IFF_OACTIVE; 550 ifp->if_timer = 0; 551 552 MBDMA_RX_GO(sc); 553 } 554 splx(s); 555 #if 0 556 s = spldma(); 557 if (! IF_IS_EMPTY(&sc->sc_tx_snd)) { 558 mb8795_start_dma(ifp); 559 } 560 splx(s); 561 #endif 562 } else { 563 mb8795_reset(sc); 564 } 565 } 566 567 void 568 mb8795_shutdown(void *arg) 569 { 570 struct mb8795_softc *sc = (struct mb8795_softc *)arg; 571 572 DPRINTF(("%s: mb8795_shutdown()\n",sc->sc_dev.dv_xname)); 573 574 mb8795_reset(sc); 575 } 576 577 /****************************************************************/ 578 int 579 mb8795_ioctl(struct ifnet *ifp, u_long cmd, void *data) 580 { 581 struct mb8795_softc *sc = ifp->if_softc; 582 struct ifaddr *ifa = (struct ifaddr *)data; 583 struct ifreq *ifr = (struct ifreq *)data; 584 int s, error = 0; 585 586 s = splnet(); 587 588 DPRINTF(("%s: mb8795_ioctl()\n",sc->sc_dev.dv_xname)); 589 590 switch (cmd) { 591 592 case SIOCINITIFADDR: 593 DPRINTF(("%s: mb8795_ioctl() SIOCINITIFADDR\n",sc->sc_dev.dv_xname)); 594 ifp->if_flags |= IFF_UP; 595 596 mb8795_init(sc); 597 switch (ifa->ifa_addr->sa_family) { 598 #ifdef INET 599 case AF_INET: 600 arp_ifinit(ifp, ifa); 601 break; 602 #endif 603 default: 604 break; 605 } 606 break; 607 608 609 case SIOCSIFFLAGS: 610 DPRINTF(("%s: mb8795_ioctl() SIOCSIFFLAGS\n",sc->sc_dev.dv_xname)); 611 if ((error = ifioctl_common(ifp, cmd, data)) != 0) 612 break; 613 switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { 614 case IFF_RUNNING: 615 /* 616 * If interface is marked down and it is running, then 617 * stop it. 618 */ 619 /* ifp->if_flags &= ~IFF_RUNNING; */ 620 mb8795_reset(sc); 621 break; 622 case IFF_UP: 623 /* 624 * If interface is marked up and it is stopped, then 625 * start it. 626 */ 627 mb8795_init(sc); 628 break; 629 default: 630 /* 631 * Reset the interface to pick up changes in any other 632 * flags that affect hardware registers. 633 */ 634 mb8795_init(sc); 635 break; 636 } 637 #ifdef MB8795_DEBUG 638 if (ifp->if_flags & IFF_DEBUG) 639 sc->sc_debug = 1; 640 else 641 sc->sc_debug = 0; 642 #endif 643 break; 644 645 case SIOCADDMULTI: 646 case SIOCDELMULTI: 647 DPRINTF(("%s: mb8795_ioctl() SIOCADDMULTI\n", 648 sc->sc_dev.dv_xname)); 649 if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) { 650 /* 651 * Multicast list has changed; set the hardware filter 652 * accordingly. 653 */ 654 if (ifp->if_flags & IFF_RUNNING) 655 mb8795_init(sc); 656 error = 0; 657 } 658 break; 659 660 case SIOCGIFMEDIA: 661 case SIOCSIFMEDIA: 662 DPRINTF(("%s: mb8795_ioctl() SIOCSIFMEDIA\n",sc->sc_dev.dv_xname)); 663 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd); 664 break; 665 666 default: 667 error = ether_ioctl(ifp, cmd, data); 668 break; 669 } 670 671 splx(s); 672 673 #if 0 674 DPRINTF(("DEBUG: mb8795_ioctl(0x%lx) returning %d\n", 675 cmd,error)); 676 #endif 677 678 return (error); 679 } 680 681 /* 682 * Setup output on interface. 683 * Get another datagram to send off of the interface queue, and map it to the 684 * interface before starting the output. 685 * Called only at splnet or interrupt level. 686 */ 687 void 688 mb8795_start(struct ifnet *ifp) 689 { 690 struct mb8795_softc *sc = ifp->if_softc; 691 struct mbuf *m; 692 int s; 693 694 DPRINTF(("%s: mb8795_start()\n",sc->sc_dev.dv_xname)); 695 696 #ifdef DIAGNOSTIC 697 IFQ_POLL(&ifp->if_snd, m); 698 if (m == 0) { 699 panic("%s: No packet to start", 700 sc->sc_dev.dv_xname); 701 } 702 #endif 703 704 while (1) { 705 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) 706 return; 707 708 #if 0 709 return; /* @@@ Turn off xmit for debugging */ 710 #endif 711 712 ifp->if_flags |= IFF_OACTIVE; 713 714 IFQ_DEQUEUE(&ifp->if_snd, m); 715 if (m == 0) { 716 ifp->if_flags &= ~IFF_OACTIVE; 717 return; 718 } 719 720 /* 721 * Pass packet to bpf if there is a listener. 722 */ 723 bpf_mtap(ifp, m); 724 725 s = spldma(); 726 IF_ENQUEUE(&sc->sc_tx_snd, m); 727 if (!MBDMA_TX_ISACTIVE(sc)) 728 mb8795_start_dma(sc); 729 splx(s); 730 731 ifp->if_flags &= ~IFF_OACTIVE; 732 } 733 734 } 735 736 void 737 mb8795_start_dma(struct mb8795_softc *sc) 738 { 739 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 740 struct mbuf *m; 741 u_char txmask; 742 743 DPRINTF(("%s: mb8795_start_dma()\n",sc->sc_dev.dv_xname)); 744 745 #if (defined(DIAGNOSTIC)) 746 { 747 u_char txstat; 748 txstat = MB_READ_REG(sc, MB8795_TXSTAT); 749 if (!turbo && !(txstat & MB8795_TXSTAT_READY)) { 750 /* @@@ I used to panic here, but then it paniced once. 751 * Let's see if I can just reset instead. [ dbj 980706.1900 ] 752 */ 753 printf("%s: transmitter not ready\n", 754 sc->sc_dev.dv_xname); 755 ifp->if_flags &= ~IFF_RUNNING; 756 mb8795_init(sc); 757 return; 758 } 759 } 760 #endif 761 762 #if 0 763 return; /* @@@ Turn off xmit for debugging */ 764 #endif 765 766 IF_DEQUEUE(&sc->sc_tx_snd, m); 767 if (m == 0) { 768 #ifdef DIAGNOSTIC 769 panic("%s: No packet to start_dma", 770 sc->sc_dev.dv_xname); 771 #endif 772 return; 773 } 774 775 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR); 776 txmask = MB_READ_REG(sc, MB8795_TXMASK); 777 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_READYIE); */ 778 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_TXRXIE); */ 779 780 ifp->if_timer = 5; 781 782 if (MBDMA_TX_MBUF(sc, m)) 783 return; 784 785 MBDMA_TX_GO(sc); 786 if (turbo) 787 MB_WRITE_REG(sc, MB8795_TXMODE, MB8795_TXMODE_TURBO1 | MB8795_TXMODE_TURBOSTART); 788 789 ifp->if_opackets++; 790 } 791 792 /****************************************************************/ 793