2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/dev/vx/if_vx.c,v 1.25.2.6 2002/02/13 00:43:10 dillon Exp $
34 * Created from if_ep.c driver by Fred Gray (fgray@rice.edu) to support
39 * Modified from the FreeBSD 1.1.5.1 version by:
41 * INRIA - Sophia Antipolis, France
42 * avega@sophia.inria.fr
46 * Promiscuous mode added and interrupt logic slightly changed
47 * to reduce the number of adapter failures. Transceiver select
48 * logic changed to use value from EEPROM. Autoconfiguration
52 * Chelindbank (Chelyabinsk, Russia)
53 * babkin@hq.icb.chel.su
56 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/sockio.h>
60 #include <sys/malloc.h>
62 #include <sys/socket.h>
63 #include <sys/linker_set.h>
64 #include <sys/module.h>
65 #include <sys/serialize.h>
66 #include <sys/thread2.h>
69 #include <net/ifq_var.h>
70 #include <net/ethernet.h>
71 #include <net/if_arp.h>
77 DECLARE_DUMMY_MODULE(if_vx
);
79 static struct connector_entry
{
82 } conn_tab
[VX_CONNECTORS
] = {
83 #define CONNECTOR_UTP 0
85 #define CONNECTOR_AUI 1
89 #define CONNECTOR_BNC 3
91 #define CONNECTOR_TX 4
93 #define CONNECTOR_FX 5
95 #define CONNECTOR_MII 6
100 /* int vxattach (struct vx_softc *); */
101 static void vxtxstat (struct vx_softc
*);
102 static int vxstatus (struct vx_softc
*);
103 static void vxinit (void *);
104 static int vxioctl (struct ifnet
*, u_long
, caddr_t
, struct ucred
*);
105 static void vxstart (struct ifnet
*ifp
, struct ifaltq_subque
*);
106 static void vxwatchdog (struct ifnet
*);
107 static void vxreset (struct vx_softc
*);
108 /* void vxstop (struct vx_softc *); */
109 static void vxread (struct vx_softc
*);
110 static struct mbuf
*vxget (struct vx_softc
*, u_int
);
111 static void vxmbuffill (void *);
112 static void vxmbuffill_serialized (void *);
113 static void vxmbufempty (struct vx_softc
*);
114 static void vxsetfilter (struct vx_softc
*);
115 static void vxgetlink (struct vx_softc
*);
116 static void vxsetlink (struct vx_softc
*);
117 /* int vxbusyeeprom (struct vx_softc *); */
120 vxattach(device_t dev
)
124 uint8_t eaddr
[ETHER_ADDR_LEN
];
127 sc
= device_get_softc(dev
);
129 callout_init(&sc
->vx_timer
);
131 CSR_WRITE_2(sc
, VX_COMMAND
, GLOBAL_RESET
);
134 ifp
= &sc
->arpcom
.ac_if
;
135 if_initname(ifp
, device_get_name(dev
), device_get_unit(dev
));
140 * Read the station address from the eeprom
143 for (i
= 0; i
< 3; i
++) {
145 if (vxbusyeeprom(sc
))
147 CSR_WRITE_2(sc
, VX_W0_EEPROM_COMMAND
, EEPROM_CMD_RD
148 | (EEPROM_OEM_ADDR_0
+ i
));
149 if (vxbusyeeprom(sc
))
151 x
= CSR_READ_2(sc
, VX_W0_EEPROM_DATA
);
152 eaddr
[(i
<< 1)] = x
>> 8;
153 eaddr
[(i
<< 1) + 1] = x
;
156 ifp
->if_mtu
= ETHERMTU
;
157 ifq_set_maxlen(&ifp
->if_snd
, IFQ_MAXLEN
);
158 ifq_set_ready(&ifp
->if_snd
);
159 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
160 ifp
->if_start
= vxstart
;
161 ifp
->if_ioctl
= vxioctl
;
162 ifp
->if_init
= vxinit
;
163 ifp
->if_watchdog
= vxwatchdog
;
166 ether_ifattach(ifp
, eaddr
, NULL
);
168 sc
->tx_start_thresh
= 20; /* probably a good starting point. */
178 * The order in here seems important. Otherwise we may not receive
184 struct vx_softc
*sc
= (struct vx_softc
*) xsc
;
185 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
192 for (i
= 0; i
< 6; i
++) /* Reload the ether_addr. */
193 CSR_WRITE_1(sc
, VX_W2_ADDR_0
+ i
, sc
->arpcom
.ac_enaddr
[i
]);
195 CSR_WRITE_2(sc
, VX_COMMAND
, RX_RESET
);
197 CSR_WRITE_2(sc
, VX_COMMAND
, TX_RESET
);
200 GO_WINDOW(1); /* Window 1 is operating window */
201 for (i
= 0; i
< 31; i
++)
202 CSR_READ_1(sc
, VX_W1_TX_STATUS
);
204 CSR_WRITE_2(sc
, VX_COMMAND
,SET_RD_0_MASK
| S_CARD_FAILURE
|
205 S_RX_COMPLETE
| S_TX_COMPLETE
| S_TX_AVAIL
);
206 CSR_WRITE_2(sc
, VX_COMMAND
,SET_INTR_MASK
| S_CARD_FAILURE
|
207 S_RX_COMPLETE
| S_TX_COMPLETE
| S_TX_AVAIL
);
210 * Attempt to get rid of any stray interrupts that occured during
211 * configuration. On the i386 this isn't possible because one may
212 * already be queued. However, a single stray interrupt is
215 CSR_WRITE_2(sc
, VX_COMMAND
, ACK_INTR
| 0xff);
220 CSR_WRITE_2(sc
, VX_COMMAND
, RX_ENABLE
);
221 CSR_WRITE_2(sc
, VX_COMMAND
, TX_ENABLE
);
223 vxmbuffill_serialized((caddr_t
) sc
);
225 /* Interface is now `running', with no output active. */
226 ifp
->if_flags
|= IFF_RUNNING
;
227 ifq_clr_oactive(&ifp
->if_snd
);
229 /* Attempt to start output, if any. */
234 vxsetfilter(struct vx_softc
*sc
)
236 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
238 GO_WINDOW(1); /* Window 1 is operating window */
239 CSR_WRITE_2(sc
, VX_COMMAND
, SET_RX_FILTER
| FIL_INDIVIDUAL
| FIL_BRDCST
|
241 ((ifp
->if_flags
& IFF_PROMISC
) ? FIL_PROMISC
: 0 ));
245 vxgetlink(struct vx_softc
*sc
)
250 sc
->vx_connectors
= CSR_READ_2(sc
, VX_W3_RESET_OPT
) & 0x7f;
251 for (n
= 0, k
= 0; k
< VX_CONNECTORS
; k
++) {
252 if (sc
->vx_connectors
& conn_tab
[k
].bit
) {
254 if_printf(&sc
->arpcom
.ac_if
, "%s", conn_tab
[k
].name
);
256 kprintf("/%s", conn_tab
[k
].name
);
261 if_printf(&sc
->arpcom
.ac_if
, "no connectors!\n");
265 sc
->vx_connector
= (CSR_READ_4(sc
, VX_W3_INTERNAL_CFG
)
266 & INTERNAL_CONNECTOR_MASK
)
267 >> INTERNAL_CONNECTOR_BITS
;
268 if (sc
->vx_connector
& 0x10) {
269 sc
->vx_connector
&= 0x0f;
270 kprintf("[*%s*]", conn_tab
[(int)sc
->vx_connector
].name
);
271 kprintf(": disable 'auto select' with DOS util!\n");
273 kprintf("[*%s*]\n", conn_tab
[(int)sc
->vx_connector
].name
);
278 vxsetlink(struct vx_softc
*sc
)
280 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
282 const char *reason
, *warning
;
283 static short prev_flags
;
284 static char prev_conn
= -1;
286 if (prev_conn
== -1) {
287 prev_conn
= sc
->vx_connector
;
293 * Now behavior was slightly changed:
295 * if any of flags link[0-2] is used and its connector is
296 * physically present the following connectors are used:
298 * link0 - AUI * highest precedence
300 * link2 - UTP * lowest precedence
302 * If none of them is specified then
303 * connector specified in the EEPROM is used
304 * (if present on card or UTP if not).
307 i
= sc
->vx_connector
; /* default in EEPROM */
311 if (ifp
->if_flags
& IFF_LINK0
) {
312 if (sc
->vx_connectors
& conn_tab
[CONNECTOR_AUI
].bit
) {
316 warning
= "aui not present! (link0)";
318 } else if (ifp
->if_flags
& IFF_LINK1
) {
319 if (sc
->vx_connectors
& conn_tab
[CONNECTOR_BNC
].bit
) {
323 warning
= "bnc not present! (link1)";
325 } else if (ifp
->if_flags
& IFF_LINK2
) {
326 if (sc
->vx_connectors
& conn_tab
[CONNECTOR_UTP
].bit
) {
330 warning
= "utp not present! (link2)";
332 } else if ((sc
->vx_connectors
& conn_tab
[(int)sc
->vx_connector
].bit
) == 0) {
333 warning
= "strange connector type in EEPROM.";
338 /* Avoid unnecessary message. */
339 k
= (prev_flags
^ ifp
->if_flags
) & (IFF_LINK0
| IFF_LINK1
| IFF_LINK2
);
340 if ((k
!= 0) || (prev_conn
!= i
)) {
341 if (warning
!= NULL
) {
342 if_printf(ifp
, "warning: %s\n", warning
);
344 if_printf(ifp
, "selected %s. (%s)\n", conn_tab
[i
].name
, reason
);
347 /* Set the selected connector. */
349 j
= CSR_READ_4(sc
, VX_W3_INTERNAL_CFG
) & ~INTERNAL_CONNECTOR_MASK
;
350 CSR_WRITE_4(sc
, VX_W3_INTERNAL_CFG
, j
| (i
<<INTERNAL_CONNECTOR_BITS
));
352 /* First, disable all. */
353 CSR_WRITE_2(sc
,VX_COMMAND
, STOP_TRANSCEIVER
);
356 CSR_WRITE_2(sc
, VX_W4_MEDIA_TYPE
, 0);
358 /* Second, enable the selected one. */
362 CSR_WRITE_2(sc
, VX_W4_MEDIA_TYPE
, ENABLE_UTP
);
365 CSR_WRITE_2(sc
, VX_COMMAND
, START_TRANSCEIVER
);
371 CSR_WRITE_2(sc
, VX_W4_MEDIA_TYPE
, LINKBEAT_ENABLE
);
373 default: /* AUI and MII fall here */
378 prev_flags
= ifp
->if_flags
;
383 vxstart(struct ifnet
*ifp
, struct ifaltq_subque
*ifsq
)
385 struct vx_softc
*sc
= ifp
->if_softc
;
389 ASSERT_ALTQ_SQ_DEFAULT(ifp
, ifsq
);
391 /* Don't transmit if interface is busy or not running */
392 if ((ifp
->if_flags
& IFF_RUNNING
) == 0 || ifq_is_oactive(&ifp
->if_snd
))
396 /* Sneak a peek at the next packet */
397 m0
= ifq_dequeue(&ifp
->if_snd
);
401 /* We need to use m->m_pkthdr.len, so require the header */
403 len
= m0
->m_pkthdr
.len
;
408 * The 3c509 automatically pads short packets to minimum ethernet length,
409 * but we drop packets that are too large. Perhaps we should truncate
412 if (len
+ pad
> ETHER_MAX_LEN
) {
413 /* packet is obviously too large: toss it */
414 IFNET_STAT_INC(ifp
, oerrors
, 1);
419 if (CSR_READ_2(sc
, VX_W1_FREE_TX
) < len
+ pad
+ 4) {
420 CSR_WRITE_2(sc
, VX_COMMAND
, SET_TX_AVAIL_THRESH
| ((len
+ pad
+ 4) >> 2));
421 /* not enough room in FIFO */
422 if (CSR_READ_2(sc
, VX_W1_FREE_TX
) < len
+ pad
+ 4) { /* make sure */
423 ifq_set_oactive(&ifp
->if_snd
);
425 ifq_prepend(&ifp
->if_snd
, m0
);
429 CSR_WRITE_2(sc
, VX_COMMAND
, SET_TX_AVAIL_THRESH
| (8188 >> 2));
432 CSR_WRITE_2(sc
, VX_COMMAND
, SET_TX_START_THRESH
|
433 ((len
/ 4 + sc
->tx_start_thresh
) >> 2));
438 * Do the output in a critical section so that an interrupt from
439 * another device won't cause a FIFO underrun.
443 CSR_WRITE_4(sc
, VX_W1_TX_PIO_WR_1
, len
| TX_INDICATE
);
447 bus_space_write_multi_4(sc
->vx_btag
, sc
->vx_bhandle
,
449 (u_int32_t
*)mtod(m0
, caddr_t
), m0
->m_len
/ 4);
451 bus_space_write_multi_1(sc
->vx_btag
, sc
->vx_bhandle
,
453 mtod(m0
, caddr_t
) + (m0
->m_len
& ~3), m0
->m_len
& 3);
457 CSR_WRITE_1(sc
, VX_W1_TX_PIO_WR_1
, 0); /* Padding */
461 IFNET_STAT_INC(ifp
, opackets
, 1);
465 if ((CSR_READ_2(sc
, VX_W1_RX_STATUS
) & ERR_INCOMPLETE
) == 0) {
466 /* We received a complete packet. */
468 if ((CSR_READ_2(sc
, VX_STATUS
) & S_INTR_LATCH
) != 0) {
469 /* Got an interrupt, return so that it gets serviced. */
473 * No interrupt, read the packet and continue
474 * Is this supposed to happen? Is my motherboard
479 /* Check if we are stuck and reset [see XXX comment] */
481 if (ifp
->if_flags
& IFF_DEBUG
)
482 if_printf(ifp
, "adapter reset\n");
491 * XXX: The 3c509 card can get in a mode where both the fifo status bit
492 * FIFOS_RX_OVERRUN and the status bit ERR_INCOMPLETE are set
493 * We detect this situation and we reset the adapter.
494 * It happens at times when there is a lot of broadcast traffic
495 * on the cable (once in a blue moon).
498 vxstatus(struct vx_softc
*sc
)
501 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
504 * Check the FIFO status and act accordingly
507 fifost
= CSR_READ_2(sc
, VX_W4_FIFO_DIAG
);
510 if (fifost
& FIFOS_RX_UNDERRUN
) {
511 if (ifp
->if_flags
& IFF_DEBUG
)
512 if_printf(ifp
, "RX underrun\n");
517 if (fifost
& FIFOS_RX_STATUS_OVERRUN
) {
518 if (ifp
->if_flags
& IFF_DEBUG
)
519 if_printf(ifp
, "RX Status overrun\n");
523 if (fifost
& FIFOS_RX_OVERRUN
) {
524 if (ifp
->if_flags
& IFF_DEBUG
)
525 if_printf(ifp
, "RX overrun\n");
529 if (fifost
& FIFOS_TX_OVERRUN
) {
530 if (ifp
->if_flags
& IFF_DEBUG
)
531 if_printf(ifp
, "TX overrun\n");
539 vxtxstat(struct vx_softc
*sc
)
542 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
545 * We need to read+write TX_STATUS until we get a 0 status
546 * in order to turn off the interrupt flag.
548 while ((i
= CSR_READ_1(sc
, VX_W1_TX_STATUS
)) & TXS_COMPLETE
) {
549 CSR_WRITE_1(sc
, VX_W1_TX_STATUS
, 0x0);
551 if (i
& TXS_JABBER
) {
552 IFNET_STAT_INC(ifp
, oerrors
, 1);
553 if (ifp
->if_flags
& IFF_DEBUG
)
554 if_printf(ifp
, "jabber (%x)\n", i
);
556 } else if (i
& TXS_UNDERRUN
) {
557 IFNET_STAT_INC(ifp
, oerrors
, 1);
558 if (ifp
->if_flags
& IFF_DEBUG
) {
559 if_printf(ifp
, "fifo underrun (%x) @%d\n",
560 i
, sc
->tx_start_thresh
);
562 if (sc
->tx_succ_ok
< 100) {
563 sc
->tx_start_thresh
= min(
564 ETHER_MAX_LEN
, sc
->tx_start_thresh
+ 20);
568 } else if (i
& TXS_MAX_COLLISION
) {
569 IFNET_STAT_INC(ifp
, collisions
, 1);
570 CSR_WRITE_2(sc
, VX_COMMAND
, TX_ENABLE
);
571 ifq_clr_oactive(&ifp
->if_snd
);
573 sc
->tx_succ_ok
= (sc
->tx_succ_ok
+1) & 127;
582 struct vx_softc
*sc
= voidsc
;
583 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
586 CSR_WRITE_2(sc
, VX_COMMAND
, C_INTR_LATCH
);
588 status
= CSR_READ_2(sc
, VX_STATUS
);
590 if ((status
& (S_TX_COMPLETE
| S_TX_AVAIL
|
591 S_RX_COMPLETE
| S_CARD_FAILURE
)) == 0)
595 * Acknowledge any interrupts. It's important that we do this
596 * first, since there would otherwise be a race condition.
597 * Due to the i386 interrupt queueing, we may get spurious
598 * interrupts occasionally.
600 CSR_WRITE_2(sc
, VX_COMMAND
, ACK_INTR
| status
);
602 if (status
& S_RX_COMPLETE
)
604 if (status
& S_TX_AVAIL
) {
606 ifq_clr_oactive(&ifp
->if_snd
);
609 if (status
& S_CARD_FAILURE
) {
610 if_printf(ifp
, "adapter failure (%x)\n", status
);
615 if (status
& S_TX_COMPLETE
) {
621 /* no more interrupts */
625 vxread(struct vx_softc
*sc
)
627 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
629 struct ether_header
*eh
;
632 len
= CSR_READ_2(sc
, VX_W1_RX_STATUS
);
636 if (ifp
->if_flags
& IFF_DEBUG
) {
637 int err
= len
& ERR_MASK
;
638 const char *s
= NULL
;
640 if (len
& ERR_INCOMPLETE
)
641 s
= "incomplete packet";
642 else if (err
== ERR_OVERRUN
)
643 s
= "packet overrun";
644 else if (err
== ERR_RUNT
)
646 else if (err
== ERR_ALIGNMENT
)
648 else if (err
== ERR_CRC
)
650 else if (err
== ERR_OVERSIZE
)
651 s
= "oversized packet";
652 else if (err
== ERR_DRIBBLE
)
656 if_printf(ifp
, "%s\n", s
);
659 if (len
& ERR_INCOMPLETE
)
663 IFNET_STAT_INC(ifp
, ierrors
, 1);
667 len
&= RX_BYTES_MASK
; /* Lower 11 bits = RX bytes. */
669 /* Pull packet off interface. */
672 IFNET_STAT_INC(ifp
, ierrors
, 1);
676 IFNET_STAT_INC(ifp
, ipackets
, 1);
678 /* We assume the header fit entirely in one mbuf. */
679 eh
= mtod(m
, struct ether_header
*);
682 * XXX: Some cards seem to be in promiscous mode all the time.
683 * we need to make sure we only get our own stuff always.
687 if ((eh
->ether_dhost
[0] & 1) == 0 /* !mcast and !bcast */
688 && bcmp(eh
->ether_dhost
, sc
->arpcom
.ac_enaddr
, ETHER_ADDR_LEN
) != 0) {
693 ifp
->if_input(ifp
, m
, NULL
, -1);
696 * In periods of high traffic we can actually receive enough
697 * packets so that the fifo overrun bit will be set at this point,
698 * even though we just read a packet. In this case we
699 * are not going to receive any more interrupts. We check for
700 * this condition and read again until the fifo is not full.
701 * We could simplify this test by not using vxstatus(), but
702 * rechecking the RX_STATUS register directly. This test could
703 * result in unnecessary looping in cases where there is a new
704 * packet but the fifo is not full, but it will not fix the
707 * Even with this improvement, we still get packet overrun errors
708 * which are hurting performance. Maybe when I get some more time
709 * I'll modify vxread() so that it can handle RX_EARLY interrupts.
712 len
= CSR_READ_2(sc
, VX_W1_RX_STATUS
);
713 /* Check if we are stuck and reset [see XXX comment] */
714 if (len
& ERR_INCOMPLETE
) {
715 if (ifp
->if_flags
& IFF_DEBUG
)
716 if_printf(ifp
, "adapter reset\n");
726 CSR_WRITE_2(sc
, VX_COMMAND
, RX_DISCARD_TOP_PACK
);
730 vxget(struct vx_softc
*sc
, u_int totlen
)
732 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
733 struct mbuf
*top
, **mp
, *m
;
736 m
= sc
->mb
[sc
->next_mb
];
737 sc
->mb
[sc
->next_mb
] = NULL
;
739 MGETHDR(m
, M_NOWAIT
, MT_DATA
);
743 /* If the queue is no longer full, refill. */
744 if (sc
->last_mb
== sc
->next_mb
&& sc
->buffill_pending
== 0) {
745 callout_reset(&sc
->vx_timer
, 1, vxmbuffill
, sc
);
746 sc
->buffill_pending
= 1;
748 /* Convert one of our saved mbuf's. */
749 sc
->next_mb
= (sc
->next_mb
+ 1) % MAX_MBS
;
750 m
->m_data
= m
->m_pktdat
;
751 m
->m_flags
= M_PKTHDR
;
752 bzero(&m
->m_pkthdr
, sizeof(m
->m_pkthdr
));
754 m
->m_pkthdr
.rcvif
= ifp
;
755 m
->m_pkthdr
.len
= totlen
;
761 * We read the packet in a critical section so that an interrupt
762 * from another device doesn't cause the card's buffer to overflow
763 * while we're reading it. We may still lose packets at other times.
768 * Since we don't set allowLargePackets bit in MacControl register,
769 * we can assume that totlen <= 1500bytes.
770 * The while loop will be performed if we have a packet with
771 * MLEN < m_len < MINCLSIZE.
775 m
= sc
->mb
[sc
->next_mb
];
776 sc
->mb
[sc
->next_mb
] = NULL
;
778 MGET(m
, M_NOWAIT
, MT_DATA
);
785 sc
->next_mb
= (sc
->next_mb
+ 1) % MAX_MBS
;
789 if (totlen
>= MINCLSIZE
) {
791 if (m
->m_flags
& M_EXT
)
794 len
= min(totlen
, len
);
796 bus_space_read_multi_4(sc
->vx_btag
, sc
->vx_bhandle
,
797 VX_W1_RX_PIO_RD_1
, mtod(m
, u_int32_t
*), len
/ 4);
799 bus_space_read_multi_1(sc
->vx_btag
, sc
->vx_bhandle
,
800 VX_W1_RX_PIO_RD_1
, mtod(m
, u_int8_t
*) + (len
& ~3),
809 CSR_WRITE_2(sc
, VX_COMMAND
, RX_DISCARD_TOP_PACK
);
818 vxioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct ucred
*cr
)
820 struct vx_softc
*sc
= ifp
->if_softc
;
821 struct ifreq
*ifr
= (struct ifreq
*) data
;
826 if ((ifp
->if_flags
& IFF_UP
) == 0 &&
827 (ifp
->if_flags
& IFF_RUNNING
) != 0) {
829 * If interface is marked up and it is stopped, then
833 ifp
->if_flags
&= ~IFF_RUNNING
;
834 } else if ((ifp
->if_flags
& IFF_UP
) != 0 &&
835 (ifp
->if_flags
& IFF_RUNNING
) == 0) {
837 * If interface is marked up and it is stopped, then
843 * deal with flags changes:
844 * IFF_MULTICAST, IFF_PROMISC,
845 * IFF_LINK0, IFF_LINK1,
854 * Set the interface MTU.
856 if (ifr
->ifr_mtu
> ETHERMTU
) {
859 ifp
->if_mtu
= ifr
->ifr_mtu
;
866 * Multicast list has changed; set the hardware filter
875 ether_ioctl(ifp
, cmd
, data
);
882 vxreset(struct vx_softc
*sc
)
889 vxwatchdog(struct ifnet
*ifp
)
891 struct vx_softc
*sc
= ifp
->if_softc
;
893 if (ifp
->if_flags
& IFF_DEBUG
)
894 if_printf(ifp
, "device timeout\n");
895 ifq_clr_oactive(&ifp
->if_snd
);
901 vxstop(struct vx_softc
*sc
)
903 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
907 CSR_WRITE_2(sc
, VX_COMMAND
, RX_DISABLE
);
908 CSR_WRITE_2(sc
, VX_COMMAND
, RX_DISCARD_TOP_PACK
);
910 CSR_WRITE_2(sc
, VX_COMMAND
, TX_DISABLE
);
911 CSR_WRITE_2(sc
, VX_COMMAND
, STOP_TRANSCEIVER
);
913 CSR_WRITE_2(sc
, VX_COMMAND
, RX_RESET
);
915 CSR_WRITE_2(sc
, VX_COMMAND
, TX_RESET
);
917 CSR_WRITE_2(sc
, VX_COMMAND
, C_INTR_LATCH
);
918 CSR_WRITE_2(sc
, VX_COMMAND
, SET_RD_0_MASK
);
919 CSR_WRITE_2(sc
, VX_COMMAND
, SET_INTR_MASK
);
920 CSR_WRITE_2(sc
, VX_COMMAND
, SET_RX_FILTER
);
926 vxbusyeeprom(struct vx_softc
*sc
)
931 j
= CSR_READ_2(sc
, VX_W0_EEPROM_COMMAND
);
938 if_printf(&sc
->arpcom
.ac_if
, "eeprom failed to come ready\n");
947 struct vx_softc
*sc
= (struct vx_softc
*) sp
;
948 struct ifnet
*ifp
= &sc
->arpcom
.ac_if
;
950 lwkt_serialize_enter(ifp
->if_serializer
);
951 vxmbuffill_serialized(sp
);
952 lwkt_serialize_exit(ifp
->if_serializer
);
956 vxmbuffill_serialized(void *sp
)
958 struct vx_softc
*sc
= (struct vx_softc
*) sp
;
963 if (sc
->mb
[i
] == NULL
)
964 MGET(sc
->mb
[i
], M_NOWAIT
, MT_DATA
);
965 if (sc
->mb
[i
] == NULL
)
967 i
= (i
+ 1) % MAX_MBS
;
968 } while (i
!= sc
->next_mb
);
970 /* If the queue was not filled, try again. */
971 if (sc
->last_mb
!= sc
->next_mb
) {
972 callout_reset(&sc
->vx_timer
, 1, vxmbuffill
, sc
);
973 sc
->buffill_pending
= 1;
975 sc
->buffill_pending
= 0;
980 vxmbufempty(struct vx_softc
*sc
)
984 for (i
= 0; i
< MAX_MBS
; i
++) {
990 sc
->last_mb
= sc
->next_mb
= 0;
991 if (sc
->buffill_pending
!= 0)
992 callout_stop(&sc
->vx_timer
);