rtl81x9var.h revision 1.31 1 1.31 tsutsui /* $NetBSD: rtl81x9var.h,v 1.31 2006/11/05 15:49:41 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*
4 1.1 tsutsui * Copyright (c) 1997, 1998
5 1.1 tsutsui * Bill Paul <wpaul (at) ctr.columbia.edu>. All rights reserved.
6 1.1 tsutsui *
7 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
8 1.1 tsutsui * modification, are permitted provided that the following conditions
9 1.1 tsutsui * are met:
10 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
11 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
12 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
14 1.1 tsutsui * documentation and/or other materials provided with the distribution.
15 1.1 tsutsui * 3. All advertising materials mentioning features or use of this software
16 1.1 tsutsui * must display the following acknowledgement:
17 1.1 tsutsui * This product includes software developed by Bill Paul.
18 1.1 tsutsui * 4. Neither the name of the author nor the names of any co-contributors
19 1.1 tsutsui * may be used to endorse or promote products derived from this software
20 1.1 tsutsui * without specific prior written permission.
21 1.1 tsutsui *
22 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 1.1 tsutsui * THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 tsutsui *
34 1.1 tsutsui * FreeBSD Id: if_rlreg.h,v 1.9 1999/06/20 18:56:09 wpaul Exp
35 1.1 tsutsui */
36 1.1 tsutsui
37 1.16 dan #include "rnd.h"
38 1.16 dan
39 1.16 dan #if NRND > 0
40 1.16 dan #include <sys/rnd.h>
41 1.16 dan #endif
42 1.16 dan
43 1.22 tsutsui #ifdef __NO_STRICT_ALIGNMENT
44 1.29 tsutsui #define RTK_ETHER_ALIGN 0
45 1.21 christos #else
46 1.5 tsutsui #define RTK_ETHER_ALIGN 2
47 1.21 christos #endif
48 1.6 tsutsui #define RTK_RXSTAT_LEN 4
49 1.1 tsutsui
50 1.4 thorpej struct rtk_type {
51 1.24 tsutsui uint16_t rtk_vid;
52 1.24 tsutsui uint16_t rtk_did;
53 1.11 fvdl int rtk_basetype;
54 1.4 thorpej const char *rtk_name;
55 1.11 fvdl };
56 1.11 fvdl
57 1.11 fvdl struct rtk_hwrev {
58 1.11 fvdl uint32_t rtk_rev;
59 1.4 thorpej int rtk_type;
60 1.19 christos const char *rtk_desc;
61 1.1 tsutsui };
62 1.1 tsutsui
63 1.30 tsutsui #define RTK_8129 1
64 1.30 tsutsui #define RTK_8139 2
65 1.30 tsutsui #define RTK_8139CPLUS 3
66 1.30 tsutsui #define RTK_8169 4
67 1.30 tsutsui
68 1.30 tsutsui #define RTK_ISCPLUS(x) ((x)->rtk_type == RTK_8139CPLUS || \
69 1.30 tsutsui (x)->rtk_type == RTK_8169)
70 1.30 tsutsui
71 1.30 tsutsui
72 1.4 thorpej struct rtk_mii_frame {
73 1.24 tsutsui uint8_t mii_stdelim;
74 1.24 tsutsui uint8_t mii_opcode;
75 1.24 tsutsui uint8_t mii_phyaddr;
76 1.24 tsutsui uint8_t mii_regaddr;
77 1.24 tsutsui uint8_t mii_turnaround;
78 1.24 tsutsui uint16_t mii_data;
79 1.1 tsutsui };
80 1.1 tsutsui
81 1.1 tsutsui /*
82 1.1 tsutsui * MII constants
83 1.1 tsutsui */
84 1.5 tsutsui #define RTK_MII_STARTDELIM 0x01
85 1.5 tsutsui #define RTK_MII_READOP 0x02
86 1.5 tsutsui #define RTK_MII_WRITEOP 0x01
87 1.5 tsutsui #define RTK_MII_TURNAROUND 0x02
88 1.1 tsutsui
89 1.11 fvdl
90 1.30 tsutsui /*
91 1.30 tsutsui * The RealTek doesn't use a fragment-based descriptor mechanism.
92 1.30 tsutsui * Instead, there are only four register sets, each or which represents
93 1.30 tsutsui * one 'descriptor.' Basically, each TX descriptor is just a contiguous
94 1.30 tsutsui * packet buffer (32-bit aligned!) and we place the buffer addresses in
95 1.30 tsutsui * the registers so the chip knows where they are.
96 1.30 tsutsui *
97 1.30 tsutsui * We can sort of kludge together the same kind of buffer management
98 1.30 tsutsui * used in previous drivers, but we have to do buffer copies almost all
99 1.30 tsutsui * the time, so it doesn't really buy us much.
100 1.30 tsutsui *
101 1.30 tsutsui * For reception, there's just one large buffer where the chip stores
102 1.30 tsutsui * all received packets.
103 1.30 tsutsui */
104 1.1 tsutsui
105 1.30 tsutsui #ifdef dreamcast
106 1.30 tsutsui #define RTK_RX_BUF_SZ RTK_RXBUF_16
107 1.30 tsutsui #else
108 1.30 tsutsui #define RTK_RX_BUF_SZ RTK_RXBUF_64
109 1.30 tsutsui #endif
110 1.30 tsutsui #define RTK_RXBUFLEN RTK_RXBUF_LEN(RTK_RX_BUF_SZ)
111 1.30 tsutsui #define RTK_TX_LIST_CNT 4
112 1.18 yamt
113 1.12 toshii /*
114 1.30 tsutsui * The 8139C+ and 8169 gigE chips support descriptor-based TX
115 1.12 toshii * and RX. In fact, they even support TCP large send. Descriptors
116 1.12 toshii * must be allocated in contiguous blocks that are aligned on a
117 1.30 tsutsui * 256-byte boundary. The RX rings can hold a maximum of 64 descriptors.
118 1.30 tsutsui * The TX rings can hold upto 64 descriptors on 8139C+, and
119 1.30 tsutsui * 1024 descriptors on 8169 gigE chips.
120 1.12 toshii */
121 1.30 tsutsui #define RTK_RING_ALIGN 256
122 1.30 tsutsui
123 1.30 tsutsui #define RTK_RX_DESC_CNT 64
124 1.30 tsutsui #define RTK_TX_DESC_CNT_8139 64
125 1.30 tsutsui #define RTK_TX_DESC_CNT_8169 1024
126 1.30 tsutsui #define RTK_TX_QLEN 64
127 1.12 toshii
128 1.28 tsutsui struct rtk_rxsoft {
129 1.28 tsutsui struct mbuf *rxs_mbuf;
130 1.28 tsutsui bus_dmamap_t rxs_dmamap;
131 1.28 tsutsui };
132 1.28 tsutsui
133 1.12 toshii struct rtk_list_data {
134 1.18 yamt struct rtk_txq {
135 1.18 yamt struct mbuf *txq_mbuf;
136 1.18 yamt bus_dmamap_t txq_dmamap;
137 1.18 yamt int txq_descidx;
138 1.18 yamt } rtk_txq[RTK_TX_QLEN];
139 1.18 yamt int rtk_txq_considx;
140 1.18 yamt int rtk_txq_prodidx;
141 1.18 yamt bus_dmamap_t rtk_tx_list_map;
142 1.18 yamt struct rtk_desc *rtk_tx_list;
143 1.18 yamt bus_dma_segment_t rtk_tx_listseg;
144 1.18 yamt int rtk_tx_free; /* # of free descriptors */
145 1.18 yamt int rtk_tx_nextfree; /* next descriptor to use */
146 1.18 yamt int rtk_tx_desc_cnt; /* # of descriptors */
147 1.18 yamt int rtk_tx_listnseg;
148 1.18 yamt
149 1.28 tsutsui struct rtk_rxsoft rtk_rxsoft[RTK_RX_DESC_CNT];
150 1.12 toshii bus_dmamap_t rtk_rx_list_map;
151 1.12 toshii struct rtk_desc *rtk_rx_list;
152 1.12 toshii bus_dma_segment_t rtk_rx_listseg;
153 1.18 yamt int rtk_rx_prodidx;
154 1.15 kanaoka int rtk_rx_listnseg;
155 1.12 toshii };
156 1.9 thorpej struct rtk_tx_desc {
157 1.9 thorpej SIMPLEQ_ENTRY(rtk_tx_desc) txd_q;
158 1.9 thorpej struct mbuf *txd_mbuf;
159 1.9 thorpej bus_dmamap_t txd_dmamap;
160 1.9 thorpej bus_addr_t txd_txaddr;
161 1.9 thorpej bus_addr_t txd_txstat;
162 1.9 thorpej };
163 1.9 thorpej
164 1.4 thorpej struct rtk_softc {
165 1.1 tsutsui struct device sc_dev; /* generic device structures */
166 1.5 tsutsui struct ethercom ethercom; /* interface info */
167 1.1 tsutsui struct mii_data mii;
168 1.4 thorpej struct callout rtk_tick_ch; /* tick callout */
169 1.4 thorpej bus_space_handle_t rtk_bhandle; /* bus space handle */
170 1.4 thorpej bus_space_tag_t rtk_btag; /* bus space tag */
171 1.7 tsutsui int rtk_type;
172 1.5 tsutsui bus_dma_tag_t sc_dmat;
173 1.5 tsutsui bus_dma_segment_t sc_dmaseg;
174 1.5 tsutsui int sc_dmanseg;
175 1.8 thorpej
176 1.8 thorpej bus_dmamap_t recv_dmamap;
177 1.8 thorpej caddr_t rtk_rx_buf;
178 1.8 thorpej
179 1.9 thorpej struct rtk_tx_desc rtk_tx_descs[RTK_TX_LIST_CNT];
180 1.9 thorpej SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_free;
181 1.9 thorpej SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_dirty;
182 1.12 toshii struct rtk_list_data rtk_ldata;
183 1.12 toshii struct mbuf *rtk_head;
184 1.12 toshii struct mbuf *rtk_tail;
185 1.24 tsutsui uint32_t rtk_rxlenmask;
186 1.12 toshii int rtk_testmode;
187 1.5 tsutsui
188 1.5 tsutsui int sc_flags; /* misc flags */
189 1.10 kanaoka int sc_txthresh; /* Early tx threshold */
190 1.14 jonathan int sc_rev; /* revision within rtk_type */
191 1.10 kanaoka
192 1.5 tsutsui void *sc_sdhook; /* shutdown hook */
193 1.5 tsutsui void *sc_powerhook; /* power management hook */
194 1.5 tsutsui
195 1.5 tsutsui /* Power management hooks. */
196 1.17 perry int (*sc_enable) (struct rtk_softc *);
197 1.17 perry void (*sc_disable) (struct rtk_softc *);
198 1.17 perry void (*sc_power) (struct rtk_softc *, int);
199 1.16 dan #if NRND > 0
200 1.16 dan rndsource_element_t rnd_source;
201 1.16 dan #endif
202 1.1 tsutsui };
203 1.1 tsutsui
204 1.30 tsutsui #define RTK_TX_DESC_CNT(sc) ((sc)->rtk_ldata.rtk_tx_desc_cnt)
205 1.30 tsutsui #define RTK_TX_LIST_SZ(sc) (RTK_TX_DESC_CNT(sc) * sizeof(struct rtk_desc))
206 1.30 tsutsui #define RTK_NEXT_TX_DESC(sc, x) (((x) + 1) % RTK_TX_DESC_CNT(sc))
207 1.30 tsutsui
208 1.30 tsutsui #define RTK_RX_LIST_SZ (RTK_RX_DESC_CNT * sizeof(struct rtk_desc))
209 1.30 tsutsui #define RTK_NEXT_RX_DESC(sc, x) (((x) + 1) % RTK_RX_DESC_CNT)
210 1.30 tsutsui
211 1.30 tsutsui #define RTK_NEXT_TXQ(sc, x) (((x) + 1) % RTK_TX_QLEN)
212 1.18 yamt
213 1.29 tsutsui #define RTK_TXDESCSYNC(sc, idx, ops) \
214 1.23 tsutsui bus_dmamap_sync((sc)->sc_dmat, \
215 1.23 tsutsui (sc)->rtk_ldata.rtk_tx_list_map, \
216 1.23 tsutsui sizeof(struct rtk_desc) * (idx), \
217 1.23 tsutsui sizeof(struct rtk_desc), \
218 1.23 tsutsui (ops))
219 1.29 tsutsui #define RTK_RXDESCSYNC(sc, idx, ops) \
220 1.23 tsutsui bus_dmamap_sync((sc)->sc_dmat, \
221 1.23 tsutsui (sc)->rtk_ldata.rtk_rx_list_map, \
222 1.23 tsutsui sizeof(struct rtk_desc) * (idx), \
223 1.23 tsutsui sizeof(struct rtk_desc), \
224 1.23 tsutsui (ops))
225 1.23 tsutsui
226 1.5 tsutsui #define RTK_ATTACHED 0x00000001 /* attach has succeeded */
227 1.5 tsutsui #define RTK_ENABLED 0x00000002 /* chip is enabled */
228 1.5 tsutsui
229 1.5 tsutsui #define RTK_IS_ENABLED(sc) ((sc)->sc_flags & RTK_ENABLED)
230 1.10 kanaoka
231 1.31 tsutsui #define RTK_TXTH_MAX RTK_TXTH_1536
232 1.10 kanaoka
233 1.1 tsutsui /*
234 1.1 tsutsui * register space access macros
235 1.1 tsutsui */
236 1.1 tsutsui #define CSR_WRITE_4(sc, reg, val) \
237 1.4 thorpej bus_space_write_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
238 1.1 tsutsui #define CSR_WRITE_2(sc, reg, val) \
239 1.4 thorpej bus_space_write_2(sc->rtk_btag, sc->rtk_bhandle, reg, val)
240 1.1 tsutsui #define CSR_WRITE_1(sc, reg, val) \
241 1.4 thorpej bus_space_write_1(sc->rtk_btag, sc->rtk_bhandle, reg, val)
242 1.1 tsutsui
243 1.1 tsutsui #define CSR_READ_4(sc, reg) \
244 1.4 thorpej bus_space_read_4(sc->rtk_btag, sc->rtk_bhandle, reg)
245 1.1 tsutsui #define CSR_READ_2(sc, reg) \
246 1.4 thorpej bus_space_read_2(sc->rtk_btag, sc->rtk_bhandle, reg)
247 1.1 tsutsui #define CSR_READ_1(sc, reg) \
248 1.4 thorpej bus_space_read_1(sc->rtk_btag, sc->rtk_bhandle, reg)
249 1.1 tsutsui
250 1.5 tsutsui #define RTK_TIMEOUT 1000
251 1.1 tsutsui
252 1.1 tsutsui /*
253 1.26 tsutsui * PCI low memory base and low I/O base registers
254 1.1 tsutsui */
255 1.1 tsutsui
256 1.5 tsutsui #define RTK_PCI_LOIO 0x10
257 1.5 tsutsui #define RTK_PCI_LOMEM 0x14
258 1.1 tsutsui
259 1.1 tsutsui #ifdef _KERNEL
260 1.24 tsutsui uint16_t rtk_read_eeprom(struct rtk_softc *, int, int);
261 1.17 perry void rtk_setmulti(struct rtk_softc *);
262 1.17 perry void rtk_attach(struct rtk_softc *);
263 1.17 perry int rtk_detach(struct rtk_softc *);
264 1.17 perry int rtk_activate(struct device *, enum devact);
265 1.17 perry int rtk_intr(void *);
266 1.1 tsutsui #endif /* _KERNEL */
267