Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / next68k / dev / mb8795.c
blob45fbceb4f413151248d418c30cbb56404d1a5e3c
1 /* $NetBSD: mb8795.c,v 1.45 2009/03/18 17:06:46 cegger Exp $ */
2 /*
3 * Copyright (c) 1998 Darrin B. Jewell
4 * All rights reserved.
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
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mb8795.c,v 1.45 2009/03/18 17:06:46 cegger Exp $");
35 #include "opt_inet.h"
36 #include "bpfilter.h"
37 #include "rnd.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/syslog.h>
43 #include <sys/socket.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46 #include <sys/ioctl.h>
47 #include <sys/errno.h>
48 #if NRND > 0
49 #include <sys/rnd.h>
50 #endif
52 #include <net/if.h>
53 #include <net/if_dl.h>
54 #include <net/if_ether.h>
56 #include <net/if_media.h>
58 #ifdef INET
59 #include <netinet/in.h>
60 #include <netinet/if_inarp.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #endif
68 #if NBPFILTER > 0
69 #include <net/bpf.h>
70 #include <net/bpfdesc.h>
71 #endif
73 #include <machine/cpu.h>
74 #include <machine/bus.h>
75 #include <machine/intr.h>
77 /* @@@ this is here for the REALIGN_DMABUF hack below */
78 #include "nextdmareg.h"
79 #include "nextdmavar.h"
81 #include "mb8795reg.h"
82 #include "mb8795var.h"
84 #include "bmapreg.h"
86 #ifdef DEBUG
87 #define MB8795_DEBUG
88 #endif
90 #define PRINTF(x) printf x;
91 #ifdef MB8795_DEBUG
92 int mb8795_debug = 0;
93 #define DPRINTF(x) if (mb8795_debug) printf x;
94 #else
95 #define DPRINTF(x)
96 #endif
98 extern int turbo;
101 * Support for
102 * Fujitsu Ethernet Data Link Controller (MB8795)
103 * and the Fujitsu Manchester Encoder/Decoder (MB502).
106 void mb8795_shutdown(void *);
108 bus_dmamap_t mb8795_txdma_restart(bus_dmamap_t, void *);
109 void mb8795_start_dma(struct mb8795_softc *);
111 int mb8795_mediachange(struct ifnet *);
112 void mb8795_mediastatus(struct ifnet *, struct ifmediareq *);
114 void
115 mb8795_config(struct mb8795_softc *sc, int *media, int nmedia, int defmedia)
117 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
119 DPRINTF(("%s: mb8795_config()\n",sc->sc_dev.dv_xname));
121 /* Initialize ifnet structure. */
122 memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
123 ifp->if_softc = sc;
124 ifp->if_start = mb8795_start;
125 ifp->if_ioctl = mb8795_ioctl;
126 ifp->if_watchdog = mb8795_watchdog;
127 ifp->if_flags =
128 IFF_BROADCAST | IFF_NOTRAILERS;
130 /* Initialize media goo. */
131 ifmedia_init(&sc->sc_media, 0, mb8795_mediachange,
132 mb8795_mediastatus);
133 if (media != NULL) {
134 int i;
135 for (i = 0; i < nmedia; i++)
136 ifmedia_add(&sc->sc_media, media[i], 0, NULL);
137 ifmedia_set(&sc->sc_media, defmedia);
138 } else {
139 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
140 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
143 /* Attach the interface. */
144 if_attach(ifp);
145 ether_ifattach(ifp, sc->sc_enaddr);
147 sc->sc_sh = shutdownhook_establish(mb8795_shutdown, sc);
148 if (sc->sc_sh == NULL)
149 panic("mb8795_config: can't establish shutdownhook");
151 #if NRND > 0
152 rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
153 RND_TYPE_NET, 0);
154 #endif
156 DPRINTF(("%s: leaving mb8795_config()\n",sc->sc_dev.dv_xname));
160 * Media change callback.
163 mb8795_mediachange(struct ifnet *ifp)
165 struct mb8795_softc *sc = ifp->if_softc;
166 int data;
168 if (turbo)
169 return (0);
171 switch IFM_SUBTYPE(sc->sc_media.ifm_media) {
172 case IFM_AUTO:
173 if ((bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
174 BMAP_DATA_UTPENABLED_MASK) ||
175 !(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
176 BMAP_DATA_UTPCARRIER_MASK)) {
177 data = BMAP_DATA_UTPENABLE;
178 sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_T;
179 } else {
180 data = BMAP_DATA_BNCENABLE;
181 sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_2;
183 break;
184 case IFM_10_T:
185 data = BMAP_DATA_UTPENABLE;
186 break;
187 case IFM_10_2:
188 data = BMAP_DATA_BNCENABLE;
189 break;
190 default:
191 return (1);
192 break;
195 bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh,
196 BMAP_DDIR, BMAP_DDIR_UTPENABLE_MASK);
197 bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh,
198 BMAP_DATA, data);
200 return (0);
204 * Media status callback.
206 void
207 mb8795_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
209 struct mb8795_softc *sc = ifp->if_softc;
211 if (turbo)
212 return;
214 if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_AUTO) {
215 ifmr->ifm_active = sc->sc_media.ifm_cur->ifm_data;
217 if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_10_T) {
218 ifmr->ifm_status = IFM_AVALID;
219 if (!(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
220 BMAP_DATA_UTPCARRIER_MASK))
221 ifmr->ifm_status |= IFM_ACTIVE;
222 } else {
223 ifmr->ifm_status &= ~IFM_AVALID; /* don't know for 10_2 */
225 return;
228 /****************************************************************/
229 #ifdef MB8795_DEBUG
230 #define XCHR(x) hexdigits[(x) & 0xf]
231 static void
232 mb8795_hex_dump(unsigned char *pkt, size_t len)
234 size_t i, j;
236 printf("00000000 ");
237 for(i=0; i<len; i++) {
238 printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i]));
239 if ((i+1) % 16 == 8) {
240 printf(" ");
242 if ((i+1) % 16 == 0) {
243 printf(" %c", '|');
244 for(j=0; j<16; j++) {
245 printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.');
247 printf("%c\n%c%c%c%c%c%c%c%c ", '|',
248 XCHR((i+1)>>28),XCHR((i+1)>>24),XCHR((i+1)>>20),XCHR((i+1)>>16),
249 XCHR((i+1)>>12), XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1));
252 printf("\n");
254 #undef XCHR
255 #endif
258 * Controller receive interrupt.
260 void
261 mb8795_rint(struct mb8795_softc *sc)
263 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
264 int error = 0;
265 u_char rxstat;
266 u_char rxmask;
268 rxstat = MB_READ_REG(sc, MB8795_RXSTAT);
269 rxmask = MB_READ_REG(sc, MB8795_RXMASK);
271 MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR);
273 if (rxstat & MB8795_RXSTAT_RESET) {
274 DPRINTF(("%s: rx reset packet\n",
275 sc->sc_dev.dv_xname));
276 error++;
278 if (rxstat & MB8795_RXSTAT_SHORT) {
279 DPRINTF(("%s: rx short packet\n",
280 sc->sc_dev.dv_xname));
281 error++;
283 if (rxstat & MB8795_RXSTAT_ALIGNERR) {
284 DPRINTF(("%s: rx alignment error\n",
285 sc->sc_dev.dv_xname));
286 #if 0
287 error++;
288 #endif
290 if (rxstat & MB8795_RXSTAT_CRCERR) {
291 DPRINTF(("%s: rx CRC error\n",
292 sc->sc_dev.dv_xname));
293 #if 0
294 error++;
295 #endif
297 if (rxstat & MB8795_RXSTAT_OVERFLOW) {
298 DPRINTF(("%s: rx overflow error\n",
299 sc->sc_dev.dv_xname));
300 #if 0
301 error++;
302 #endif
305 if (error) {
306 ifp->if_ierrors++;
307 /* @@@ handle more gracefully, free memory, etc. */
310 if (rxstat & MB8795_RXSTAT_OK) {
311 struct mbuf *m;
312 int s;
313 s = spldma();
315 while ((m = MBDMA_RX_MBUF (sc))) {
316 /* CRC is included with the packet; trim it. */
317 m->m_pkthdr.len = m->m_len = m->m_len - ETHER_CRC_LEN;
318 m->m_pkthdr.rcvif = ifp;
320 /* Find receive length, keep crc */
321 /* enable DMA interrupts while we process the packet */
322 splx(s);
324 #if defined(MB8795_DEBUG)
325 /* Peek at the packet */
326 DPRINTF(("%s: received packet, at VA %p-%p,len %d\n",
327 sc->sc_dev.dv_xname,mtod(m,u_char *),mtod(m,u_char *)+m->m_len,m->m_len));
328 if (mb8795_debug > 3) {
329 mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len);
330 } else if (mb8795_debug > 2) {
331 mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len < 255 ? m->m_pkthdr.len : 128 );
333 #endif
335 #if NBPFILTER > 0
337 * Pass packet to bpf if there is a listener.
339 if (ifp->if_bpf)
340 bpf_mtap(ifp->if_bpf, m);
341 #endif
344 ifp->if_ipackets++;
346 /* Pass the packet up. */
347 (*ifp->if_input)(ifp, m);
350 s = spldma();
354 splx(s);
358 #ifdef MB8795_DEBUG
359 if (mb8795_debug) {
360 char sbuf[256];
362 snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS, rxstat);
363 printf("%s: rx interrupt, rxstat = %s\n",
364 sc->sc_dev.dv_xname, sbuf);
366 snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS,
367 MB_READ_REG(sc, MB8795_RXSTAT));
369 printf("rxstat = 0x%s\n", sbuf);
371 snprintb(sbuf, sizeof(sbuf), MB8795_RXMASK_BITS,
372 MB_READ_REG(sc, MB8795_RXMASK));
373 printf("rxmask = 0x%s\n", sbuf);
375 snprintb(sbuf, sizeof(sbuf), MB8795_RXMODE_BITS,
376 MB_READ_REG(sc, MB8795_RXMODE));
377 printf("rxmode = 0x%s\n", sbuf);
379 #endif
381 return;
385 * Controller transmit interrupt.
387 void
388 mb8795_tint(struct mb8795_softc *sc)
390 u_char txstat;
391 u_char txmask;
392 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
394 panic ("tint");
395 txstat = MB_READ_REG(sc, MB8795_TXSTAT);
396 txmask = MB_READ_REG(sc, MB8795_TXMASK);
398 if ((txstat & MB8795_TXSTAT_READY) ||
399 (txstat & MB8795_TXSTAT_TXRECV)) {
400 /* printf("X"); */
401 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
402 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE); */
403 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_TXRXIE); */
404 MB_WRITE_REG(sc, MB8795_TXMASK, 0);
405 if ((ifp->if_flags & IFF_RUNNING) && !IF_IS_EMPTY(&sc->sc_tx_snd)) {
406 void mb8795_start_dma(struct mb8795_softc *); /* XXXX */
407 /* printf ("Z"); */
408 mb8795_start_dma(sc);
410 return;
413 if (txstat & MB8795_TXSTAT_SHORTED) {
414 printf("%s: tx cable shorted\n", sc->sc_dev.dv_xname);
415 ifp->if_oerrors++;
417 if (txstat & MB8795_TXSTAT_UNDERFLOW) {
418 printf("%s: tx underflow\n", sc->sc_dev.dv_xname);
419 ifp->if_oerrors++;
421 if (txstat & MB8795_TXSTAT_COLLERR) {
422 DPRINTF(("%s: tx collision\n", sc->sc_dev.dv_xname));
423 ifp->if_collisions++;
425 if (txstat & MB8795_TXSTAT_COLLERR16) {
426 printf("%s: tx 16th collision\n", sc->sc_dev.dv_xname);
427 ifp->if_oerrors++;
428 ifp->if_collisions += 16;
431 #if 0
432 if (txstat & MB8795_TXSTAT_READY) {
433 char sbuf[256];
435 snprintb(sbuf, sizeof(sbuf), MB8795_TXSTAT_BITS, txstat);
436 panic("%s: unexpected tx interrupt %s",
437 sc->sc_dev.dv_xname, sbuf);
439 /* turn interrupt off */
440 MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE);
442 #endif
444 return;
447 /****************************************************************/
449 void
450 mb8795_reset(struct mb8795_softc *sc)
452 int s;
453 int i;
455 s = splnet();
457 DPRINTF (("%s: mb8795_reset()\n",sc->sc_dev.dv_xname));
459 sc->sc_ethercom.ec_if.if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
460 sc->sc_ethercom.ec_if.if_timer = 0;
462 MBDMA_RESET(sc);
464 MB_WRITE_REG(sc, MB8795_RESET, MB8795_RESET_MODE);
466 mb8795_mediachange(&sc->sc_ethercom.ec_if);
468 #if 0 /* This interrupt was sometimes failing to ack correctly
469 * causing a loop @@@
471 MB_WRITE_REG(sc, MB8795_TXMASK,
472 MB8795_TXMASK_UNDERFLOWIE | MB8795_TXMASK_COLLIE | MB8795_TXMASK_COLL16IE
473 | MB8795_TXMASK_PARERRIE);
474 #else
475 MB_WRITE_REG(sc, MB8795_TXMASK, 0);
476 #endif
477 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
479 #if 0
480 MB_WRITE_REG(sc, MB8795_RXMASK,
481 MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE |
482 MB8795_RXMASK_ALIGNERRIE | MB8795_RXMASK_CRCERRIE | MB8795_RXMASK_OVERFLOWIE);
483 #else
484 MB_WRITE_REG(sc, MB8795_RXMASK,
485 MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE);
486 #endif
488 MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR);
490 for(i=0;i<sizeof(sc->sc_enaddr);i++) {
491 MB_WRITE_REG(sc, MB8795_ENADDR+i, sc->sc_enaddr[i]);
494 DPRINTF(("%s: initializing ethernet %02x:%02x:%02x:%02x:%02x:%02x, size=%d\n",
495 sc->sc_dev.dv_xname,
496 sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
497 sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5],
498 sizeof(sc->sc_enaddr)));
500 MB_WRITE_REG(sc, MB8795_RESET, 0);
502 splx(s);
505 void
506 mb8795_watchdog(struct ifnet *ifp)
508 struct mb8795_softc *sc = ifp->if_softc;
510 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
511 ++ifp->if_oerrors;
513 DPRINTF(("%s: %lld input errors, %lld input packets\n",
514 sc->sc_dev.dv_xname, ifp->if_ierrors, ifp->if_ipackets));
516 ifp->if_flags &= ~IFF_RUNNING;
517 mb8795_init(sc);
521 * Initialization of interface; set up initialization block
522 * and transmit/receive descriptor rings.
524 void
525 mb8795_init(struct mb8795_softc *sc)
527 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
528 int s;
530 DPRINTF (("%s: mb8795_init()\n",sc->sc_dev.dv_xname));
532 if (ifp->if_flags & IFF_UP) {
533 int rxmode;
535 s = spldma();
536 if ((ifp->if_flags & IFF_RUNNING) == 0)
537 mb8795_reset(sc);
539 if (ifp->if_flags & IFF_PROMISC)
540 rxmode = MB8795_RXMODE_PROMISCUOUS;
541 else
542 rxmode = MB8795_RXMODE_NORMAL;
543 /* XXX add support for multicast */
544 if (turbo)
545 rxmode |= MB8795_RXMODE_TEST;
547 /* switching mode probably borken now with turbo */
548 MB_WRITE_REG(sc, MB8795_TXMODE,
549 turbo ? MB8795_TXMODE_TURBO1 : MB8795_TXMODE_LB_DISABLE);
550 MB_WRITE_REG(sc, MB8795_RXMODE, rxmode);
552 if ((ifp->if_flags & IFF_RUNNING) == 0) {
553 MBDMA_RX_SETUP(sc);
554 MBDMA_TX_SETUP(sc);
556 ifp->if_flags |= IFF_RUNNING;
557 ifp->if_flags &= ~IFF_OACTIVE;
558 ifp->if_timer = 0;
560 MBDMA_RX_GO(sc);
562 splx(s);
563 #if 0
564 s = spldma();
565 if (! IF_IS_EMPTY(&sc->sc_tx_snd)) {
566 mb8795_start_dma(ifp);
568 splx(s);
569 #endif
570 } else {
571 mb8795_reset(sc);
575 void
576 mb8795_shutdown(void *arg)
578 struct mb8795_softc *sc = (struct mb8795_softc *)arg;
580 DPRINTF(("%s: mb8795_shutdown()\n",sc->sc_dev.dv_xname));
582 mb8795_reset(sc);
585 /****************************************************************/
587 mb8795_ioctl(struct ifnet *ifp, u_long cmd, void *data)
589 struct mb8795_softc *sc = ifp->if_softc;
590 struct ifaddr *ifa = (struct ifaddr *)data;
591 struct ifreq *ifr = (struct ifreq *)data;
592 int s, error = 0;
594 s = splnet();
596 DPRINTF(("%s: mb8795_ioctl()\n",sc->sc_dev.dv_xname));
598 switch (cmd) {
600 case SIOCINITIFADDR:
601 DPRINTF(("%s: mb8795_ioctl() SIOCINITIFADDR\n",sc->sc_dev.dv_xname));
602 ifp->if_flags |= IFF_UP;
604 mb8795_init(sc);
605 switch (ifa->ifa_addr->sa_family) {
606 #ifdef INET
607 case AF_INET:
608 arp_ifinit(ifp, ifa);
609 break;
610 #endif
611 default:
612 break;
614 break;
617 case SIOCSIFFLAGS:
618 DPRINTF(("%s: mb8795_ioctl() SIOCSIFFLAGS\n",sc->sc_dev.dv_xname));
619 if ((error = ifioctl_common(ifp, cmd, data)) != 0)
620 break;
621 switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
622 case IFF_RUNNING:
624 * If interface is marked down and it is running, then
625 * stop it.
627 /* ifp->if_flags &= ~IFF_RUNNING; */
628 mb8795_reset(sc);
629 break;
630 case IFF_UP:
632 * If interface is marked up and it is stopped, then
633 * start it.
635 mb8795_init(sc);
636 break;
637 default:
639 * Reset the interface to pick up changes in any other
640 * flags that affect hardware registers.
642 mb8795_init(sc);
643 break;
645 #ifdef MB8795_DEBUG
646 if (ifp->if_flags & IFF_DEBUG)
647 sc->sc_debug = 1;
648 else
649 sc->sc_debug = 0;
650 #endif
651 break;
653 case SIOCADDMULTI:
654 case SIOCDELMULTI:
655 DPRINTF(("%s: mb8795_ioctl() SIOCADDMULTI\n",
656 sc->sc_dev.dv_xname));
657 if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
659 * Multicast list has changed; set the hardware filter
660 * accordingly.
662 if (ifp->if_flags & IFF_RUNNING)
663 mb8795_init(sc);
664 error = 0;
666 break;
668 case SIOCGIFMEDIA:
669 case SIOCSIFMEDIA:
670 DPRINTF(("%s: mb8795_ioctl() SIOCSIFMEDIA\n",sc->sc_dev.dv_xname));
671 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
672 break;
674 default:
675 error = ether_ioctl(ifp, cmd, data);
676 break;
679 splx(s);
681 #if 0
682 DPRINTF(("DEBUG: mb8795_ioctl(0x%lx) returning %d\n",
683 cmd,error));
684 #endif
686 return (error);
690 * Setup output on interface.
691 * Get another datagram to send off of the interface queue, and map it to the
692 * interface before starting the output.
693 * Called only at splnet or interrupt level.
695 void
696 mb8795_start(struct ifnet *ifp)
698 struct mb8795_softc *sc = ifp->if_softc;
699 struct mbuf *m;
700 int s;
702 DPRINTF(("%s: mb8795_start()\n",sc->sc_dev.dv_xname));
704 #ifdef DIAGNOSTIC
705 IFQ_POLL(&ifp->if_snd, m);
706 if (m == 0) {
707 panic("%s: No packet to start",
708 sc->sc_dev.dv_xname);
710 #endif
712 while (1) {
713 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
714 return;
716 #if 0
717 return; /* @@@ Turn off xmit for debugging */
718 #endif
720 ifp->if_flags |= IFF_OACTIVE;
722 IFQ_DEQUEUE(&ifp->if_snd, m);
723 if (m == 0) {
724 ifp->if_flags &= ~IFF_OACTIVE;
725 return;
728 #if NBPFILTER > 0
730 * Pass packet to bpf if there is a listener.
732 if (ifp->if_bpf)
733 bpf_mtap(ifp->if_bpf, m);
734 #endif
736 s = spldma();
737 IF_ENQUEUE(&sc->sc_tx_snd, m);
738 if (!MBDMA_TX_ISACTIVE(sc))
739 mb8795_start_dma(sc);
740 splx(s);
742 ifp->if_flags &= ~IFF_OACTIVE;
747 void
748 mb8795_start_dma(struct mb8795_softc *sc)
750 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
751 struct mbuf *m;
752 u_char txmask;
754 DPRINTF(("%s: mb8795_start_dma()\n",sc->sc_dev.dv_xname));
756 #if (defined(DIAGNOSTIC))
758 u_char txstat;
759 txstat = MB_READ_REG(sc, MB8795_TXSTAT);
760 if (!turbo && !(txstat & MB8795_TXSTAT_READY)) {
761 /* @@@ I used to panic here, but then it paniced once.
762 * Let's see if I can just reset instead. [ dbj 980706.1900 ]
764 printf("%s: transmitter not ready\n",
765 sc->sc_dev.dv_xname);
766 ifp->if_flags &= ~IFF_RUNNING;
767 mb8795_init(sc);
768 return;
771 #endif
773 #if 0
774 return; /* @@@ Turn off xmit for debugging */
775 #endif
777 IF_DEQUEUE(&sc->sc_tx_snd, m);
778 if (m == 0) {
779 #ifdef DIAGNOSTIC
780 panic("%s: No packet to start_dma",
781 sc->sc_dev.dv_xname);
782 #endif
783 return;
786 MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
787 txmask = MB_READ_REG(sc, MB8795_TXMASK);
788 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_READYIE); */
789 /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_TXRXIE); */
791 ifp->if_timer = 5;
793 if (MBDMA_TX_MBUF(sc, m))
794 return;
796 MBDMA_TX_GO(sc);
797 if (turbo)
798 MB_WRITE_REG(sc, MB8795_TXMODE, MB8795_TXMODE_TURBO1 | MB8795_TXMODE_TURBOSTART);
800 ifp->if_opackets++;
803 /****************************************************************/