1 /* $NetBSD: smc90cx6.c,v 1.71 2017/10/23 09:22:24 msaitoh Exp $ */ 2 3 /*- 4 * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Ignatios Souvatzis. 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 * Chip core driver for the SMC90c26 / SMC90c56 (and SMC90c66 in '56 34 * compatibility mode) boards 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: smc90cx6.c,v 1.71 2017/10/23 09:22:24 msaitoh Exp $"); 39 40 /* #define BAHSOFTCOPY */ 41 #define BAHRETRANSMIT /**/ 42 43 #include "opt_inet.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/mbuf.h> 48 #include <sys/buf.h> 49 #include <sys/device.h> 50 #include <sys/protosw.h> 51 #include <sys/socket.h> 52 #include <sys/syslog.h> 53 #include <sys/ioctl.h> 54 #include <sys/errno.h> 55 #include <sys/kernel.h> 56 #include <sys/intr.h> 57 58 #include <net/if.h> 59 #include <net/if_dl.h> 60 #include <net/if_ether.h> 61 #include <net/if_types.h> 62 #include <net/if_arc.h> 63 64 #ifdef INET 65 #include <netinet/in.h> 66 #include <netinet/in_systm.h> 67 #include <netinet/in_var.h> 68 #include <netinet/ip.h> 69 #include <netinet/if_inarp.h> 70 #endif 71 72 #include <net/bpf.h> 73 #include <net/bpfdesc.h> 74 75 #include <sys/bus.h> 76 #include <sys/cpu.h> 77 78 #include <dev/ic/smc90cx6reg.h> 79 #include <dev/ic/smc90cx6var.h> 80 81 /* these should be elsewhere */ 82 83 #define ARC_MIN_LEN 1 84 #define ARC_MIN_FORBID_LEN 254 85 #define ARC_MAX_FORBID_LEN 256 86 #define ARC_MAX_LEN 508 87 #define ARC_ADDR_LEN 1 88 89 /* for watchdog timer. This should be more than enough. */ 90 #define ARCTIMEOUT (5*IFNET_SLOWHZ) 91 92 /* 93 * This currently uses 2 bufs for tx, 2 for rx 94 * 95 * New rx protocol: 96 * 97 * rx has a fillcount variable. If fillcount > (NRXBUF-1), 98 * rx can be switched off from rx hard int. 99 * Else rx is restarted on the other receiver. 100 * rx soft int counts down. if it is == (NRXBUF-1), it restarts 101 * the receiver. 102 * To ensure packet ordering (we need that for 1201 later), we have a counter 103 * which is incremented modulo 256 on each receive and a per buffer 104 * variable, which is set to the counter on filling. The soft int can 105 * compare both values to determine the older packet. 106 * 107 * Transmit direction: 108 * 109 * bah_start checks tx_fillcount 110 * case 2: return 111 * 112 * else fill tx_act ^ 1 && inc tx_fillcount 113 * 114 * check tx_fillcount again. 115 * case 2: set IFF_OACTIVE to stop arc_output from filling us. 116 * case 1: start tx 117 * 118 * tint clears IFF_OCATIVE, decrements and checks tx_fillcount 119 * case 1: start tx on tx_act ^ 1, softcall bah_start 120 * case 0: softcall bah_start 121 * 122 * #define fill(i) get mbuf && copy mbuf to chip(i) 123 */ 124 125 void bah_init(struct bah_softc *); 126 void bah_reset(struct bah_softc *); 127 void bah_stop(struct bah_softc *); 128 void bah_start(struct ifnet *); 129 int bahintr(void *); 130 int bah_ioctl(struct ifnet *, unsigned long, void *); 131 void bah_watchdog(struct ifnet *); 132 void bah_srint(void *vsc); 133 static void bah_tint(struct bah_softc *, int); 134 void bah_reconwatch(void *); 135 136 /* short notation */ 137 138 #define GETREG(off) bus_space_read_1(bst_r, regs, (off)) 139 #define PUTREG(off, v) bus_space_write_1(bst_r, regs, (off), (v)) 140 #define GETMEM(off) bus_space_read_1(bst_m, mem, (off)) 141 #define PUTMEM(off, v) bus_space_write_1(bst_m, mem, (off), (v)) 142 143 int 144 bah_attach_subr(struct bah_softc *sc) 145 { 146 struct ifnet *ifp = &sc->sc_arccom.ac_if; 147 int s, rv; 148 u_int8_t linkaddress; 149 150 bus_space_tag_t bst_r = sc->sc_bst_r; 151 bus_space_tag_t bst_m = sc->sc_bst_m; 152 bus_space_handle_t regs = sc->sc_regs; 153 bus_space_handle_t mem = sc->sc_mem; 154 155 s = splhigh(); 156 157 /* 158 * read the arcnet address from the board 159 */ 160 161 (*sc->sc_reset)(sc, 1); 162 163 do { 164 delay(200); 165 } while (!(GETREG(BAHSTAT) & BAH_POR)); 166 167 linkaddress = GETMEM(BAHMACOFF); 168 169 printf(": link addr 0x%02x(%d)\n", linkaddress, linkaddress); 170 171 /* clear the int mask... */ 172 173 sc->sc_intmask = 0; 174 PUTREG(BAHSTAT, 0); 175 176 PUTREG(BAHCMD, BAH_CONF(CONF_LONG)); 177 PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG)); 178 sc->sc_recontime = sc->sc_reconcount = 0; 179 180 /* and reenable kernel int level */ 181 splx(s); 182 183 /* 184 * set interface to stopped condition (reset) 185 */ 186 bah_stop(sc); 187 188 strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); 189 ifp->if_softc = sc; 190 ifp->if_start = bah_start; 191 ifp->if_ioctl = bah_ioctl; 192 ifp->if_timer = 0; 193 ifp->if_watchdog = bah_watchdog; 194 IFQ_SET_READY(&ifp->if_snd); 195 196 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS; 197 198 ifp->if_mtu = ARCMTU; 199 200 rv = arc_ifattach(ifp, linkaddress); 201 if (rv != 0) 202 return rv; 203 if_deferred_start_init(ifp, NULL); 204 205 #ifdef BAHSOFTCOPY 206 sc->sc_rxcookie = softint_establish(SOFTINT_NET, bah_srint, sc); 207 sc->sc_txcookie = softint_establish(SOFTINT_NET, 208 (void (*)(void *))bah_start, ifp); 209 #endif 210 211 callout_init(&sc->sc_recon_ch, 0); 212 return 0; 213 } 214 215 /* 216 * Initialize device 217 * 218 */ 219 void 220 bah_init(struct bah_softc *sc) 221 { 222 struct ifnet *ifp; 223 int s; 224 225 ifp = &sc->sc_arccom.ac_if; 226 227 if ((ifp->if_flags & IFF_RUNNING) == 0) { 228 s = splnet(); 229 ifp->if_flags |= IFF_RUNNING; 230 bah_reset(sc); 231 bah_start(ifp); 232 splx(s); 233 } 234 } 235 236 /* 237 * Reset the interface... 238 * 239 * this assumes that it is called inside a critical section... 240 * 241 */ 242 void 243 bah_reset(struct bah_softc *sc) 244 { 245 struct ifnet *ifp; 246 uint8_t linkaddress; 247 248 bus_space_tag_t bst_r = sc->sc_bst_r; 249 bus_space_tag_t bst_m = sc->sc_bst_m; 250 bus_space_handle_t regs = sc->sc_regs; 251 bus_space_handle_t mem = sc->sc_mem; 252 253 ifp = &sc->sc_arccom.ac_if; 254 255 #ifdef BAH_DEBUG 256 printf("%s: reset\n", device_xname(sc->sc_dev)); 257 #endif 258 /* stop and restart hardware */ 259 260 (*sc->sc_reset)(sc, 1); 261 do { 262 DELAY(200); 263 } while (!(GETREG(BAHSTAT) & BAH_POR)); 264 265 linkaddress = GETMEM(BAHMACOFF); 266 267 #if defined(BAH_DEBUG) && (BAH_DEBUG > 2) 268 printf("%s: reset: card reset, link addr = 0x%02x (%u)\n", 269 device_xname(sc->sc_dev), linkaddress, linkaddress); 270 #endif 271 272 /* tell the routing level about the (possibly changed) link address */ 273 if_set_sadl(ifp, &linkaddress, sizeof(linkaddress), false); 274 275 /* POR is NMI, but we need it below: */ 276 sc->sc_intmask = BAH_RECON|BAH_POR; 277 PUTREG(BAHSTAT, sc->sc_intmask); 278 PUTREG(BAHCMD, BAH_CONF(CONF_LONG)); 279 280 #ifdef BAH_DEBUG 281 printf("%s: reset: chip configured, status=0x%02x\n", 282 device_xname(sc->sc_dev), GETREG(BAHSTAT)); 283 #endif 284 PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG)); 285 286 #ifdef BAH_DEBUG 287 printf("%s: reset: bits cleared, status=0x%02x\n", 288 device_xname(sc->sc_dev), GETREG(BAHSTAT)); 289 #endif 290 291 sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS; 292 293 /* start receiver */ 294 295 sc->sc_intmask |= BAH_RI; 296 sc->sc_rx_fillcount = 0; 297 sc->sc_rx_act = 2; 298 299 PUTREG(BAHCMD, BAH_RXBC(2)); 300 PUTREG(BAHSTAT, sc->sc_intmask); 301 302 #ifdef BAH_DEBUG 303 printf("%s: reset: started receiver, status=0x%02x\n", 304 device_xname(sc->sc_dev), GETREG(BAHSTAT)); 305 #endif 306 307 /* and init transmitter status */ 308 sc->sc_tx_act = 0; 309 sc->sc_tx_fillcount = 0; 310 311 ifp->if_flags |= IFF_RUNNING; 312 ifp->if_flags &= ~IFF_OACTIVE; 313 314 bah_start(ifp); 315 } 316 317 /* 318 * Take interface offline 319 */ 320 void 321 bah_stop(struct bah_softc *sc) 322 { 323 bus_space_tag_t bst_r = sc->sc_bst_r; 324 bus_space_handle_t regs = sc->sc_regs; 325 326 /* Stop the interrupts */ 327 PUTREG(BAHSTAT, 0); 328 329 /* Stop the interface */ 330 (*sc->sc_reset)(sc, 0); 331 332 /* Stop watchdog timer */ 333 sc->sc_arccom.ac_if.if_timer = 0; 334 } 335 336 /* 337 * Start output on interface. Get another datagram to send 338 * off the interface queue, and copy it to the 339 * interface before starting the output 340 * 341 * this assumes that it is called inside a critical section... 342 * XXX hm... does it still? 343 * 344 */ 345 void 346 bah_start(struct ifnet *ifp) 347 { 348 struct bah_softc *sc = ifp->if_softc; 349 struct mbuf *m,*mp; 350 351 bus_space_tag_t bst_r = sc->sc_bst_r; 352 bus_space_handle_t regs = sc->sc_regs; 353 bus_space_tag_t bst_m = sc->sc_bst_m; 354 bus_space_handle_t mem = sc->sc_mem; 355 356 int bah_ram_ptr; 357 int len, tlen, offset, s, buffer; 358 #ifdef BAHTIMINGS 359 u_long copystart, lencopy, perbyte; 360 #endif 361 362 #if defined(BAH_DEBUG) && (BAH_DEBUG > 3) 363 printf("%s: start(0x%x)\n", device_xname(sc->sc_dev), ifp); 364 #endif 365 366 if ((ifp->if_flags & IFF_RUNNING) == 0) 367 return; 368 369 s = splnet(); 370 371 if (sc->sc_tx_fillcount >= 2) { 372 splx(s); 373 return; 374 } 375 376 IFQ_DEQUEUE(&ifp->if_snd, m); 377 buffer = sc->sc_tx_act ^ 1; 378 379 splx(s); 380 381 if (m == 0) 382 return; 383 384 /* 385 * If bpf is listening on this interface, let it 386 * see the packet before we commit it to the wire 387 * 388 * (can't give the copy in A2060 card RAM to bpf, because 389 * that RAM is just accessed as on every other byte) 390 */ 391 bpf_mtap(ifp, m); 392 393 #ifdef BAH_DEBUG 394 if (m->m_len < ARC_HDRLEN) 395 m = m_pullup(m, ARC_HDRLEN);/* gcc does structure padding */ 396 printf("%s: start: filling %d from %u to %u type %u\n", 397 device_xname(sc->sc_dev), buffer, mtod(m, u_char *)[0], 398 mtod(m, u_char *)[1], mtod(m, u_char *)[2]); 399 #else 400 if (m->m_len < 2) 401 m = m_pullup(m, 2); 402 #endif 403 bah_ram_ptr = buffer*512; 404 405 if (m == 0) 406 return; 407 408 /* write the addresses to RAM and throw them away */ 409 410 /* 411 * Hardware does this: Yet Another Microsecond Saved. 412 * (btw, timing code says usually 2 microseconds) 413 * PUTMEM(bah_ram_ptr + 0, mtod(m, u_char *)[0]); 414 */ 415 416 PUTMEM(bah_ram_ptr + 1, mtod(m, u_char *)[1]); 417 m_adj(m, 2); 418 419 /* get total length left at this point */ 420 tlen = m->m_pkthdr.len; 421 if (tlen < ARC_MIN_FORBID_LEN) { 422 offset = 256 - tlen; 423 PUTMEM(bah_ram_ptr + 2, offset); 424 } else { 425 PUTMEM(bah_ram_ptr + 2, 0); 426 if (tlen <= ARC_MAX_FORBID_LEN) 427 offset = 255; /* !!! */ 428 else { 429 if (tlen > ARC_MAX_LEN) 430 tlen = ARC_MAX_LEN; 431 offset = 512 - tlen; 432 } 433 PUTMEM(bah_ram_ptr + 3, offset); 434 435 } 436 bah_ram_ptr += offset; 437 438 /* lets loop through the mbuf chain */ 439 440 for (mp = m; mp; mp = mp->m_next) { 441 if ((len = mp->m_len)) { /* YAMS */ 442 bus_space_write_region_1(bst_m, mem, bah_ram_ptr, 443 mtod(mp, void *), len); 444 445 bah_ram_ptr += len; 446 } 447 } 448 449 sc->sc_broadcast[buffer] = (m->m_flags & M_BCAST) != 0; 450 sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5; 451 452 /* actually transmit the packet */ 453 s = splnet(); 454 455 if (++sc->sc_tx_fillcount > 1) { 456 /* 457 * We are filled up to the rim. No more bufs for the moment, 458 * please. 459 */ 460 ifp->if_flags |= IFF_OACTIVE; 461 } else { 462 #ifdef BAH_DEBUG 463 printf("%s: start: starting transmitter on buffer %d\n", 464 device_xname(sc->sc_dev), buffer); 465 #endif 466 /* Transmitter was off, start it */ 467 sc->sc_tx_act = buffer; 468 469 /* 470 * We still can accept another buf, so don't: 471 * ifp->if_flags |= IFF_OACTIVE; 472 */ 473 sc->sc_intmask |= BAH_TA; 474 PUTREG(BAHCMD, BAH_TX(buffer)); 475 PUTREG(BAHSTAT, sc->sc_intmask); 476 477 sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT; 478 } 479 splx(s); 480 m_freem(m); 481 482 /* 483 * After 10 times reading the docs, I realized 484 * that in the case the receiver NAKs the buffer request, 485 * the hardware retries till shutdown. 486 * This is integrated now in the code above. 487 */ 488 489 return; 490 } 491 492 /* 493 * Arcnet interface receiver soft interrupt: 494 * get the stuff out of any filled buffer we find. 495 */ 496 void 497 bah_srint(void *vsc) 498 { 499 struct bah_softc *sc = (struct bah_softc *)vsc; 500 int buffer, len, len1, amount, offset, s, type; 501 int bah_ram_ptr; 502 struct mbuf *m, *dst, *head; 503 struct arc_header *ah; 504 struct ifnet *ifp; 505 506 bus_space_tag_t bst_r = sc->sc_bst_r; 507 bus_space_tag_t bst_m = sc->sc_bst_m; 508 bus_space_handle_t regs = sc->sc_regs; 509 bus_space_handle_t mem = sc->sc_mem; 510 511 ifp = &sc->sc_arccom.ac_if; 512 head = 0; 513 514 s = splnet(); 515 buffer = sc->sc_rx_act ^ 1; 516 splx(s); 517 518 /* Allocate header mbuf */ 519 MGETHDR(m, M_DONTWAIT, MT_DATA); 520 521 if (m == 0) { 522 /* 523 * in case s.th. goes wrong with mem, drop it 524 * to make sure the receiver can be started again 525 * count it as input error (we dont have any other 526 * detectable) 527 */ 528 ifp->if_ierrors++; 529 goto cleanup; 530 } 531 532 m_set_rcvif(m, ifp); 533 534 /* 535 * Align so that IP packet will be longword aligned. Here we 536 * assume that m_data of new packet is longword aligned. 537 * When implementing PHDS, we might have to change it to 2, 538 * (2*sizeof(ulong) - ARC_HDRNEWLEN)), packet type dependent. 539 */ 540 541 bah_ram_ptr = buffer*512; 542 offset = GETMEM(bah_ram_ptr + 2); 543 if (offset) 544 len = 256 - offset; 545 else { 546 offset = GETMEM(bah_ram_ptr + 3); 547 len = 512 - offset; 548 } 549 if (len+2 >= MINCLSIZE) 550 MCLGET(m, M_DONTWAIT); 551 552 if (m == 0) { 553 ifp->if_ierrors++; 554 goto cleanup; 555 } 556 557 type = GETMEM(bah_ram_ptr + offset); 558 m->m_data += 1 + arc_isphds(type); 559 560 head = m; 561 ah = mtod(head, struct arc_header *); 562 563 ah->arc_shost = GETMEM(bah_ram_ptr + 0); 564 ah->arc_dhost = GETMEM(bah_ram_ptr + 1); 565 566 m->m_pkthdr.len = len+2; /* whole packet length */ 567 m->m_len = 2; /* mbuf filled with ARCnet addresses */ 568 bah_ram_ptr += offset; /* ram buffer continues there */ 569 570 while (len > 0) { 571 572 len1 = len; 573 amount = M_TRAILINGSPACE(m); 574 575 if (amount == 0) { 576 dst = m; 577 MGET(m, M_DONTWAIT, MT_DATA); 578 579 if (m == 0) { 580 ifp->if_ierrors++; 581 goto cleanup; 582 } 583 584 if (len1 >= MINCLSIZE) 585 MCLGET(m, M_DONTWAIT); 586 587 m->m_len = 0; 588 dst->m_next = m; 589 amount = M_TRAILINGSPACE(m); 590 } 591 592 if (amount < len1) 593 len1 = amount; 594 595 bus_space_read_region_1(bst_m, mem, bah_ram_ptr, 596 mtod(m, u_char *) + m->m_len, len1); 597 598 m->m_len += len1; 599 bah_ram_ptr += len1; 600 len -= len1; 601 } 602 603 if_percpuq_enqueue((&sc->sc_arccom.ac_if)->if_percpuq, head); 604 605 head = NULL; 606 607 cleanup: 608 609 if (head != NULL) 610 m_freem(head); 611 612 /* mark buffer as invalid by source id 0 */ 613 bus_space_write_1(bst_m, mem, buffer*512, 0); 614 s = splnet(); 615 616 if (--sc->sc_rx_fillcount == 2 - 1) { 617 618 /* was off, restart it on buffer just emptied */ 619 sc->sc_rx_act = buffer; 620 sc->sc_intmask |= BAH_RI; 621 622 /* this also clears the RI flag interrupt: */ 623 PUTREG(BAHCMD, BAH_RXBC(buffer)); 624 PUTREG(BAHSTAT, sc->sc_intmask); 625 626 #ifdef BAH_DEBUG 627 printf("%s: srint: restarted rx on buf %d\n", 628 device_xname(sc->sc_dev), buffer); 629 #endif 630 } 631 splx(s); 632 } 633 634 inline static void 635 bah_tint(struct bah_softc *sc, int isr) 636 { 637 struct ifnet *ifp; 638 639 bus_space_tag_t bst_r = sc->sc_bst_r; 640 bus_space_handle_t regs = sc->sc_regs; 641 642 643 int buffer; 644 #ifdef BAHTIMINGS 645 int clknow; 646 #endif 647 648 ifp = &(sc->sc_arccom.ac_if); 649 buffer = sc->sc_tx_act; 650 651 /* 652 * retransmit code: 653 * Normal situations first for fast path: 654 * If acknowledgement received ok or broadcast, we're ok. 655 * else if 656 */ 657 658 if (isr & BAH_TMA || sc->sc_broadcast[buffer]) 659 sc->sc_arccom.ac_if.if_opackets++; 660 #ifdef BAHRETRANSMIT 661 else if (ifp->if_flags & IFF_LINK2 && ifp->if_timer > 0 662 && --sc->sc_retransmits[buffer] > 0) { 663 /* retransmit same buffer */ 664 PUTREG(BAHCMD, BAH_TX(buffer)); 665 return; 666 } 667 #endif 668 else 669 ifp->if_oerrors++; 670 671 672 /* We know we can accept another buffer at this point. */ 673 ifp->if_flags &= ~IFF_OACTIVE; 674 675 if (--sc->sc_tx_fillcount > 0) { 676 677 /* 678 * start tx on other buffer. 679 * This also clears the int flag 680 */ 681 buffer ^= 1; 682 sc->sc_tx_act = buffer; 683 684 /* 685 * already given: 686 * sc->sc_intmask |= BAH_TA; 687 * PUTREG(BAHSTAT, sc->sc_intmask); 688 */ 689 PUTREG(BAHCMD, BAH_TX(buffer)); 690 /* init watchdog timer */ 691 ifp->if_timer = ARCTIMEOUT; 692 693 #if defined(BAH_DEBUG) && (BAH_DEBUG > 1) 694 printf("%s: tint: starting tx on buffer %d, status 0x%02x\n", 695 device_xname(sc->sc_dev), buffer, GETREG(BAHSTAT)); 696 #endif 697 } else { 698 /* have to disable TX interrupt */ 699 sc->sc_intmask &= ~BAH_TA; 700 PUTREG(BAHSTAT, sc->sc_intmask); 701 /* ... and watchdog timer */ 702 ifp->if_timer = 0; 703 704 #ifdef BAH_DEBUG 705 printf("%s: tint: no more buffers to send, status 0x%02x\n", 706 device_xname(sc->sc_dev), GETREG(BAHSTAT)); 707 #endif 708 } 709 710 /* XXXX TODO */ 711 #ifdef BAHSOFTCOPY 712 /* schedule soft int to fill a new buffer for us */ 713 softint_schedule(sc->sc_txcookie); 714 #else 715 if_schedule_deferred_start(ifp); 716 #endif 717 } 718 719 /* 720 * Our interrupt routine 721 */ 722 int 723 bahintr(void *arg) 724 { 725 struct bah_softc *sc = arg; 726 727 bus_space_tag_t bst_r = sc->sc_bst_r; 728 bus_space_tag_t bst_m = sc->sc_bst_m; 729 bus_space_handle_t regs = sc->sc_regs; 730 bus_space_handle_t mem = sc->sc_mem; 731 732 u_char isr, maskedisr; 733 int buffer; 734 u_long newsec; 735 736 isr = GETREG(BAHSTAT); 737 maskedisr = isr & sc->sc_intmask; 738 if (!maskedisr) 739 return (0); 740 do { 741 742 #if defined(BAH_DEBUG) && (BAH_DEBUG>1) 743 printf("%s: intr: status 0x%02x, intmask 0x%02x\n", 744 device_xname(sc->sc_dev), isr, sc->sc_intmask); 745 #endif 746 747 if (maskedisr & BAH_POR) { 748 /* 749 * XXX We should never see this. Don't bother to store 750 * the address. 751 * sc->sc_arccom.ac_anaddr = GETMEM(BAHMACOFF); 752 */ 753 PUTREG(BAHCMD, BAH_CLR(CLR_POR)); 754 log(LOG_WARNING, 755 "%s: intr: got spurious power on reset int\n", 756 device_xname(sc->sc_dev)); 757 } 758 759 if (maskedisr & BAH_RECON) { 760 /* 761 * we dont need to: 762 * PUTREG(BAHCMD, BAH_CONF(CONF_LONG)); 763 */ 764 PUTREG(BAHCMD, BAH_CLR(CLR_RECONFIG)); 765 sc->sc_arccom.ac_if.if_collisions++; 766 767 /* 768 * If less than 2 seconds per reconfig: 769 * If ARC_EXCESSIVE_RECONFIGS 770 * since last burst, complain and set threshold for 771 * warnings to ARC_EXCESSIVE_RECONS_REWARN. 772 * 773 * This allows for, e.g., new stations on the cable, or 774 * cable switching as long as it is over after 775 * (normally) 16 seconds. 776 * 777 * XXX TODO: check timeout bits in status word and 778 * double time if necessary. 779 */ 780 781 callout_stop(&sc->sc_recon_ch); 782 newsec = time_second; 783 if ((newsec - sc->sc_recontime <= 2) && 784 (++sc->sc_reconcount == ARC_EXCESSIVE_RECONS)) { 785 log(LOG_WARNING, 786 "%s: excessive token losses, " 787 "cable problem?\n", device_xname(sc->sc_dev)); 788 } 789 sc->sc_recontime = newsec; 790 callout_reset(&sc->sc_recon_ch, 15 * hz, 791 bah_reconwatch, (void *)sc); 792 } 793 794 if (maskedisr & BAH_RI) { 795 #if defined(BAH_DEBUG) && (BAH_DEBUG > 1) 796 printf("%s: intr: hard rint, act %d\n", 797 device_xname(sc->sc_dev), sc->sc_rx_act); 798 #endif 799 800 buffer = sc->sc_rx_act; 801 /* look if buffer is marked invalid: */ 802 if (GETMEM(buffer*512) == 0) { 803 /* 804 * invalid marked buffer (or illegally 805 * configured sender) 806 */ 807 log(LOG_WARNING, 808 "%s: spurious RX interrupt or sender 0 " 809 " (ignored)\n", device_xname(sc->sc_dev)); 810 /* 811 * restart receiver on same buffer. 812 * XXX maybe better reset interface? 813 */ 814 PUTREG(BAHCMD, BAH_RXBC(buffer)); 815 } else { 816 if (++sc->sc_rx_fillcount > 1) { 817 sc->sc_intmask &= ~BAH_RI; 818 PUTREG(BAHSTAT, sc->sc_intmask); 819 } else { 820 buffer ^= 1; 821 sc->sc_rx_act = buffer; 822 823 /* 824 * Start receiver on other receive 825 * buffer. This also clears the RI 826 * interrupt flag. 827 */ 828 PUTREG(BAHCMD, BAH_RXBC(buffer)); 829 /* in RX intr, so mask is ok for RX */ 830 831 #ifdef BAH_DEBUG 832 printf("%s: strt rx for buf %u, " 833 "stat 0x%02x\n", 834 device_xname(sc->sc_dev), sc->sc_rx_act, 835 GETREG(BAHSTAT)); 836 #endif 837 } 838 839 #ifdef BAHSOFTCOPY 840 /* 841 * this one starts a soft int to copy out 842 * of the hw 843 */ 844 softint_schedule(sc->sc_rxcookie); 845 #else 846 /* this one does the copy here */ 847 bah_srint(sc); 848 #endif 849 } 850 } 851 if (maskedisr & BAH_TA) { 852 bah_tint(sc, isr); 853 } 854 isr = GETREG(BAHSTAT); 855 maskedisr = isr & sc->sc_intmask; 856 } while (maskedisr); 857 858 return (1); 859 } 860 861 void 862 bah_reconwatch(void *arg) 863 { 864 struct bah_softc *sc = arg; 865 866 if (sc->sc_reconcount >= ARC_EXCESSIVE_RECONS) { 867 sc->sc_reconcount = 0; 868 log(LOG_WARNING, "%s: token valid again.\n", 869 device_xname(sc->sc_dev)); 870 } 871 sc->sc_reconcount = 0; 872 } 873 874 875 /* 876 * Process an ioctl request. 877 * This code needs some work - it looks pretty ugly. 878 */ 879 int 880 bah_ioctl(struct ifnet *ifp, u_long cmd, void *data) 881 { 882 struct bah_softc *sc; 883 struct ifaddr *ifa; 884 struct ifreq *ifr; 885 int s, error; 886 887 error = 0; 888 sc = ifp->if_softc; 889 ifa = (struct ifaddr *)data; 890 ifr = (struct ifreq *)data; 891 s = splnet(); 892 893 #if defined(BAH_DEBUG) && (BAH_DEBUG > 2) 894 printf("%s: ioctl() called, cmd = 0x%lx\n", 895 device_xname(sc->sc_dev), cmd); 896 #endif 897 898 switch (cmd) { 899 case SIOCINITIFADDR: 900 ifp->if_flags |= IFF_UP; 901 bah_init(sc); 902 switch (ifa->ifa_addr->sa_family) { 903 #ifdef INET 904 case AF_INET: 905 arp_ifinit(ifp, ifa); 906 break; 907 #endif 908 default: 909 break; 910 } 911 912 case SIOCSIFFLAGS: 913 if ((error = ifioctl_common(ifp, cmd, data)) != 0) 914 break; 915 /* XXX re-use ether_ioctl() */ 916 switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { 917 case IFF_RUNNING: 918 /* 919 * If interface is marked down and it is running, 920 * then stop it. 921 */ 922 bah_stop(sc); 923 ifp->if_flags &= ~IFF_RUNNING; 924 break; 925 case IFF_UP: 926 /* 927 * If interface is marked up and it is stopped, then 928 * start it. 929 */ 930 bah_init(sc); 931 break; 932 } 933 break; 934 935 case SIOCADDMULTI: 936 case SIOCDELMULTI: 937 switch (ifreq_getaddr(cmd, ifr)->sa_family) { 938 case AF_INET: 939 case AF_INET6: 940 error = 0; 941 break; 942 default: 943 error = EAFNOSUPPORT; 944 break; 945 } 946 break; 947 948 default: 949 error = ether_ioctl(ifp, cmd, data); 950 } 951 952 splx(s); 953 return (error); 954 } 955 956 /* 957 * watchdog routine for transmitter. 958 * 959 * We need this, because else a receiver whose hardware is alive, but whose 960 * software has not enabled the Receiver, would make our hardware wait forever 961 * Discovered this after 20 times reading the docs. 962 * 963 * Only thing we do is disable transmitter. We'll get an transmit timeout, 964 * and the int handler will have to decide not to retransmit (in case 965 * retransmission is implemented). 966 * 967 * This one assumes being called inside splnet() 968 */ 969 970 void 971 bah_watchdog(struct ifnet *ifp) 972 { 973 struct bah_softc *sc = ifp->if_softc; 974 975 bus_space_tag_t bst_r = sc->sc_bst_r; 976 bus_space_handle_t regs = sc->sc_regs; 977 978 PUTREG(BAHCMD, BAH_TXDIS); 979 return; 980 } 981 982