Merge from vendor branch GCC:
[dragonfly.git] / sys / dev / netif / gx / if_gxvar.h
1 /*-
2  * Copyright (c) 1999,2000,2001 Jonathan Lemon
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *      $FreeBSD: src/sys/dev/gx/if_gxvar.h,v 1.1.2.1 2001/11/15 03:09:23 jlemon Exp $
30  *      $DragonFly: src/sys/dev/netif/gx/Attic/if_gxvar.h,v 1.3 2004/02/13 02:44:48 joerg Exp $
31  */
32
33 #if defined(__DragonFly__) || __FreeBSD_version < 500000
34 #define GX_LOCK(gx)             
35 #define GX_UNLOCK(gx)           
36 #define mtx_init(a, b, c)
37 #define mtx_destroy(a)
38 struct mtx { int filler; };
39 #else
40 #define GX_LOCK(gx)             mtx_lock(&(gx)->gx_mtx)
41 #define GX_UNLOCK(gx)           mtx_unlock(&(gx)->gx_mtx)
42 #endif
43
44 #ifdef __alpha__
45 #undef vtophys
46 #define vtophys(va)             alpha_XXX_dmamap((vm_offset_t)va)
47 #endif
48
49 #ifndef PCIM_CMD_MWIEN
50 #define PCIM_CMD_MWIEN          0x0010
51 #endif
52
53 #define ETHER_ALIGN     2
54
55 /* CSR_WRITE_8 assumes the register is in low/high order */
56 #define CSR_WRITE_8(gx, reg, val) do { \
57         bus_space_write_4(gx->gx_btag, gx->gx_bhandle, reg, val & 0xffffffff); \
58         bus_space_write_4(gx->gx_btag, gx->gx_bhandle, reg + 4, val >> 32); \
59 } while (0)
60 #define CSR_WRITE_4(gx, reg, val) \
61         bus_space_write_4(gx->gx_btag, gx->gx_bhandle, reg, val)
62 #define CSR_WRITE_2(gx, reg, val) \
63         bus_space_write_2(gx->gx_btag, gx->gx_bhandle, reg, val)
64 #define CSR_WRITE_1(gx, reg, val) \
65         bus_space_write_1(gx->gx_btag, gx->gx_bhandle, reg, val)
66
67 #define CSR_READ_4(gx, reg) \
68         bus_space_read_4(gx->gx_btag, gx->gx_bhandle, reg)
69 #define CSR_READ_2(gx, reg) \
70         bus_space_read_2(gx->gx_btag, gx->gx_bhandle, reg)
71 #define CSR_READ_1(gx, reg) \
72         bus_space_read_1(gx->gx_btag, gx->gx_bhandle, reg)
73
74 #define GX_SETBIT(gx, reg, x) \
75         CSR_WRITE_4(gx, reg, (CSR_READ_4(gx, reg) | (x)))
76 #define GX_CLRBIT(gx, reg, x) \
77         CSR_WRITE_4(gx, reg, (CSR_READ_4(gx, reg) & ~(x)))
78
79 /*
80  * In theory, these can go up to 64K each, but due to chip bugs, 
81  * they are limited to 256 max.  Descriptor counts should be a 
82  * multiple of 8.
83  */
84 #define GX_TX_RING_CNT          256
85 #define GX_RX_RING_CNT          256
86
87 #define GX_INC(x, y)            (x) = (x + 1) % y
88 #define GX_PREV(x, y)           (x == 0 ? y - 1 : x - 1)
89
90 #define GX_MAX_MTU              (16 * 1024)
91
92 struct gx_ring_data {
93         struct  gx_rx_desc gx_rx_ring[GX_RX_RING_CNT];
94         struct  gx_tx_desc gx_tx_ring[GX_TX_RING_CNT];
95 };
96
97 struct gx_chain_data {
98         struct  mbuf *gx_rx_chain[GX_RX_RING_CNT];
99         struct  mbuf *gx_tx_chain[GX_TX_RING_CNT];
100 };
101
102 struct gx_regs {
103         int     r_rx_base;
104         int     r_rx_length;
105         int     r_rx_head;
106         int     r_rx_tail;
107         int     r_rx_delay;
108         int     r_rx_dma_ctrl;
109
110         int     r_tx_base;
111         int     r_tx_length;
112         int     r_tx_head;
113         int     r_tx_tail;
114         int     r_tx_delay;
115         int     r_tx_dma_ctrl;
116 };
117
118 struct gx_softc {
119         struct arpcom           arpcom;         /* interface info */
120         struct ifmedia          gx_media;       /* media info */
121         bus_space_handle_t      gx_bhandle;     /* bus space handle */
122         bus_space_tag_t         gx_btag;        /* bus space tag */
123         void                    *gx_intrhand;   /* irq handler handle */
124         struct resource         *gx_irq;        /* IRQ resource handle */
125         struct resource         *gx_res;        /* I/O or shared mem handle */
126         device_t                gx_dev;
127         device_t                gx_miibus;
128         u_int8_t                gx_unit;        /* controller number */
129         u_int8_t                gx_tbimode;     /* transceiver flag */
130         int                     gx_vflags;      /* version-specific flags */
131         u_int32_t               gx_ipg;         /* version-specific IPG */
132         struct gx_ring_data     *gx_rdata;
133         struct gx_chain_data    gx_cdata;
134         int                     gx_if_flags;
135         struct mbuf             *gx_pkthdr;
136         struct mbuf             **gx_pktnextp;
137         int                     gx_rx_tail_idx; /* receive ring tail index */
138         int                     gx_tx_tail_idx; /* transmit ring tail index */
139         int                     gx_tx_head_idx; /* transmit ring tail index */
140         int                     gx_txcnt;
141         int                     gx_txcontext;   /* current TX context */
142         struct gx_regs          gx_reg;
143         struct mtx              gx_mtx;
144
145 /* tunables */
146         int                     gx_tx_intr_delay;
147         int                     gx_rx_intr_delay;
148         
149 /* statistics */
150         int                     gx_tx_interrupts;
151         int                     gx_rx_interrupts;
152         int                     gx_interrupts;
153 };
154
155 /*
156  * flags to compensate for differing chip variants
157  */
158 #define GXF_FORCE_TBI           0x0001  /* force TBI mode on */
159 #define GXF_DMA                 0x0002  /* has DMA control registers */
160 #define GXF_ENABLE_MWI          0x0004  /* supports MWI burst mode */
161 #define GXF_OLD_REGS            0x0008  /* use old register mapping */
162 #define GXF_CSUM                0x0010  /* hardware checksum offload */
163
164 /*
165  * TX Context definitions.
166  */
167 #define GX_TXCONTEXT_NONE       0
168 #define GX_TXCONTEXT_TCPIP      1
169 #define GX_TXCONTEXT_UDPIP      2