1 /* $FreeBSD: src/sys/pci/if_wxvar.h,v 1.4.2.6 2001/10/20 17:44:12 mjacob Exp $ */
2 /* $DragonFly: src/sys/dev/netif/wx/Attic/if_wxvar.h,v 1.2 2003/06/17 04:28:57 dillon Exp $ */
4 * Principal Author: Matthew Jacob
5 * Copyright (c) 1999, 2001 by Traakan Software
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Additional Copyright (c) 2001 by Parag Patel
31 * under same licence for MII PHY code.
35 * Softc definitions for the Intel Gigabit Ethernet driver.
37 * Guidance and inspiration from David Greenman's
38 * if_fxp driver gratefully acknowledged here.
42 * Platform specific defines and inline functions go here.
43 * Look further below for more generic structures.
47 * Enable for FreeBSD 5.0 SMP code
51 #include <sys/param.h>
52 #include <sys/systm.h>
54 #include <sys/protosw.h>
55 #include <sys/socket.h>
56 #include <sys/malloc.h>
57 #include <sys/kernel.h>
59 #include <net/if_dl.h>
60 #include <net/if_media.h>
63 #include <netns/ns_if.h>
66 #include <sys/sockio.h>
68 #include <machine/bus.h>
70 #include <machine/resource.h>
71 #include <net/ethernet.h>
72 #include <net/if_arp.h>
75 #include <machine/clock.h>
76 #include <pci/pcivar.h>
77 #include <pci/pcireg.h>
78 #include <pci/if_wxreg.h>
79 #include <dev/mii/mii.h>
80 #include <dev/mii/miivar.h>
81 #include <sys/sysctl.h>
85 MODULE_DEPEND(wx, miibus, 1, 1, 1);
86 #include "miibus_if.h"
90 #include <net/if_types.h>
91 #include <net/bridge.h>
96 * arpcom must be first
98 struct arpcom arpcom; /* per-interface network data */
99 struct device * dev; /* backpointer to device */
100 struct resource * mem; /* resource descriptor for registers */
101 struct resource * irq; /* resource descriptor for interrupt */
102 void * ih; /* interrupt handler cookie */
104 struct callout_handle sch; /* handle for timeouts */
106 bus_space_tag_t st; /* bus space tag */
107 bus_space_handle_t sh; /* bus space handle */
110 struct wx_softc * next;
118 #define wx_enaddr w.arpcom.ac_enaddr
119 #define wx_cmdw w.cmdw
120 #define wx_media w.ifm
121 #define wx_next w.next
123 #define wx_if w.arpcom.ac_if
124 #define wx_name w.name
125 #define wx_mtx w.wxmtx
127 #define IOCTL_CMD_TYPE u_long
128 #define WXMALLOC(len) malloc(len, M_DEVBUF, M_NOWAIT)
129 #define WXFREE(ptr) free(ptr, M_DEVBUF)
130 #define SOFTC_IFP(ifp) ifp->if_softc
131 #define WX_BPFTAP_ARG(ifp) ifp
132 #define VTIMEOUT(sc, func, arg, time) (void) timeout(func, arg, time)
133 #define TIMEOUT(sc, func, arg, time) (sc)->w.sch = timeout(func, arg, time)
134 #define UNTIMEOUT(f, arg, sc) untimeout(f, arg, (sc)->w.sch)
135 #define INLINE __inline
137 #define WX_LOCK(_sc) mtx_lock(&(_sc)->wx_mtx)
138 #define WX_UNLOCK(_sc) mtx_unlock(&(_sc)->wx_mtx)
139 #define WX_ILOCK(_sc) mtx_lock(&(_sc)->wx_mtx)
140 #define WX_IUNLK(_sc) mtx_unlock(&(_sc)->wx_mtx)
142 #define WX_LOCK(_sc) _sc->w.spl = splimp()
143 #define WX_UNLOCK(_sc) splx(_sc->w.spl)
144 #define WX_ILOCK(_sc)
145 #define WX_IUNLK(_sc)
147 #define WX_SOFTC_FROM_MII_ARG(x) device_get_softc(x)
148 #define WX_MII_FROM_SOFTC(x) device_get_softc((x)->w.miibus)
151 #define READ_CSR(sc, reg) \
152 bus_space_read_4((sc)->w.st, (sc)->w.sh, (reg))
153 #define WRITE_CSR(sc, reg, val) \
154 bus_space_write_4((sc)->w.st, (sc)->w.sh, (reg), (val))
157 * Transmit soft descriptor, used to manage packets as they come in.
159 typedef struct rxpkt {
160 struct mbuf *dptr; /* pointer to receive frame */
161 u_int32_t dma_addr; /* dma address */
166 * Transmit soft descriptor, used to manage packets as they are transmitted.
168 typedef struct txpkt {
169 struct txpkt *next; /* next in a chain */
170 struct mbuf *dptr; /* pointer to mbuf being sent */
171 u_int32_t sidx; /* start index */
172 u_int32_t eidx; /* end index */
176 typedef struct wx_softc {
178 * OS dependent storage... must be first...
187 wx_mii : 1, /* non-zero if we have a PHY */
196 u_int32_t wx_idnrev; /* chip revision && PCI ID */
199 u_int32_t wx_ienable; /* current ienable to use */
200 u_int32_t wx_dcr; /* dcr used */
201 u_int32_t wx_icr; /* last icr */
204 * Statistics, soft && hard
207 u_int32_t wx_linkintr;
211 u_int32_t wx_xmitpullup;
212 u_int32_t wx_xmitcluster;
213 u_int32_t wx_xmitputback;
214 u_int32_t wx_xmitwanted;
215 u_int32_t wx_xmitblocked;
216 u_int32_t wx_xmitrunt;
217 u_int32_t wx_rxnobuf;
221 * Soft copies of multicast addresses. We're only
222 * using (right now) the rest of the receive address
223 * registers- not the hashed multicast table.
225 u_int8_t wx_mcaddr[WX_RAL_TAB_SIZE-1][6];
226 u_int8_t wx_nmca; /* # active multicast addrs */
231 * We have software and shared memory rings in a buddy store format.
233 wxrd_t *rdescriptors; /* receive descriptor ring */
234 rxpkt_t *rbase; /* base of soft rdesc list */
235 u_int16_t rnxt; /* next descriptor to check */
237 struct mbuf *rpending; /* pending partial packet */
240 * Transmit Management
241 * We have software and shared memory rings in a buddy store format.
243 txpkt_t *tbase; /* base of soft soft management */
244 txpkt_t *tbsyf, *tbsyl; /* linked busy list */
245 wxtd_t *tdescriptors; /* transmit descriptor ring */
246 u_int16_t tnxtfree; /* next free index (circular) */
247 u_int16_t tactive; /* # active */
251 * We offset the the receive frame header by two bytes so that the actual
252 * payload is 32 bit aligned. On platforms that require strict structure
253 * alignment, this means that the ethernet frame header may have to be shifted
254 * to align it at interrupt time, but because it's such a small amount
255 * (fourteen bytes) and processors have gotten pretty fast, that's okay.
256 * It may even turn out on some platforms that this doesn't have to happen.
258 #define WX_RX_OFFSET_VALUE 2
261 * Tunable Parameters.
263 * Descriptor lengths must be in multiples of 8.
265 #define WX_MAX_TDESC 256 /* number of transmit descriptors */
266 #define T_NXT_IDX(x) ((x + 1) & (WX_MAX_TDESC - 1))
267 #define T_PREV_IDX(x) ((x - 1) & (WX_MAX_TDESC - 1))
268 #define WX_MAX_RDESC 256 /* number of receive descriptors */
274 #define R_NXT_IDX(x) ((x + RXINCR) & (WX_MAX_RDESC - 1))
275 #define R_PREV_IDX(x) ((x - RXINCR) & (WX_MAX_RDESC - 1))
278 * Link Up timeout, in milliseconds.
281 #define WX_LINK_UP_TIMEOUT 500