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