rtl81x9var.h revision 1.26 1 1.26 tsutsui /* $NetBSD: rtl81x9var.h,v 1.26 2006/10/27 09:57:26 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.21 christos #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.4 thorpej struct rtk_mii_frame {
64 1.24 tsutsui uint8_t mii_stdelim;
65 1.24 tsutsui uint8_t mii_opcode;
66 1.24 tsutsui uint8_t mii_phyaddr;
67 1.24 tsutsui uint8_t mii_regaddr;
68 1.24 tsutsui uint8_t mii_turnaround;
69 1.24 tsutsui uint16_t mii_data;
70 1.1 tsutsui };
71 1.1 tsutsui
72 1.1 tsutsui /*
73 1.1 tsutsui * MII constants
74 1.1 tsutsui */
75 1.5 tsutsui #define RTK_MII_STARTDELIM 0x01
76 1.5 tsutsui #define RTK_MII_READOP 0x02
77 1.5 tsutsui #define RTK_MII_WRITEOP 0x01
78 1.5 tsutsui #define RTK_MII_TURNAROUND 0x02
79 1.1 tsutsui
80 1.5 tsutsui #define RTK_8129 1
81 1.5 tsutsui #define RTK_8139 2
82 1.11 fvdl #define RTK_8139CPLUS 3
83 1.11 fvdl #define RTK_8169 4
84 1.11 fvdl
85 1.11 fvdl #define RTK_ISCPLUS(x) ((x)->rtk_type == RTK_8139CPLUS || \
86 1.11 fvdl (x)->rtk_type == RTK_8169)
87 1.1 tsutsui
88 1.18 yamt #define RTK_TX_QLEN 64
89 1.18 yamt
90 1.12 toshii /*
91 1.12 toshii * The 8139C+ and 8160 gigE chips support descriptor-based TX
92 1.12 toshii * and RX. In fact, they even support TCP large send. Descriptors
93 1.12 toshii * must be allocated in contiguous blocks that are aligned on a
94 1.12 toshii * 256-byte boundary. The rings can hold a maximum of 64 descriptors.
95 1.12 toshii */
96 1.12 toshii
97 1.12 toshii struct rtk_list_data {
98 1.18 yamt struct rtk_txq {
99 1.18 yamt struct mbuf *txq_mbuf;
100 1.18 yamt bus_dmamap_t txq_dmamap;
101 1.18 yamt int txq_descidx;
102 1.18 yamt } rtk_txq[RTK_TX_QLEN];
103 1.18 yamt int rtk_txq_considx;
104 1.18 yamt int rtk_txq_prodidx;
105 1.18 yamt bus_dmamap_t rtk_tx_list_map;
106 1.18 yamt struct rtk_desc *rtk_tx_list;
107 1.18 yamt bus_dma_segment_t rtk_tx_listseg;
108 1.18 yamt int rtk_tx_free; /* # of free descriptors */
109 1.18 yamt int rtk_tx_nextfree; /* next descriptor to use */
110 1.18 yamt int rtk_tx_desc_cnt; /* # of descriptors */
111 1.18 yamt int rtk_tx_listnseg;
112 1.18 yamt
113 1.13 toshii struct mbuf *rtk_rx_mbuf[RTK_RX_DESC_CNT];
114 1.12 toshii bus_dmamap_t rtk_rx_dmamap[RTK_RX_DESC_CNT];
115 1.12 toshii bus_dmamap_t rtk_rx_list_map;
116 1.12 toshii struct rtk_desc *rtk_rx_list;
117 1.12 toshii bus_dma_segment_t rtk_rx_listseg;
118 1.18 yamt int rtk_rx_prodidx;
119 1.15 kanaoka int rtk_rx_listnseg;
120 1.12 toshii };
121 1.9 thorpej struct rtk_tx_desc {
122 1.9 thorpej SIMPLEQ_ENTRY(rtk_tx_desc) txd_q;
123 1.9 thorpej struct mbuf *txd_mbuf;
124 1.9 thorpej bus_dmamap_t txd_dmamap;
125 1.9 thorpej bus_addr_t txd_txaddr;
126 1.9 thorpej bus_addr_t txd_txstat;
127 1.9 thorpej };
128 1.9 thorpej
129 1.4 thorpej struct rtk_softc {
130 1.1 tsutsui struct device sc_dev; /* generic device structures */
131 1.5 tsutsui struct ethercom ethercom; /* interface info */
132 1.1 tsutsui struct mii_data mii;
133 1.4 thorpej struct callout rtk_tick_ch; /* tick callout */
134 1.4 thorpej bus_space_handle_t rtk_bhandle; /* bus space handle */
135 1.4 thorpej bus_space_tag_t rtk_btag; /* bus space tag */
136 1.7 tsutsui int rtk_type;
137 1.5 tsutsui bus_dma_tag_t sc_dmat;
138 1.5 tsutsui bus_dma_segment_t sc_dmaseg;
139 1.5 tsutsui int sc_dmanseg;
140 1.8 thorpej
141 1.8 thorpej bus_dmamap_t recv_dmamap;
142 1.8 thorpej caddr_t rtk_rx_buf;
143 1.8 thorpej
144 1.9 thorpej struct rtk_tx_desc rtk_tx_descs[RTK_TX_LIST_CNT];
145 1.9 thorpej SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_free;
146 1.9 thorpej SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_dirty;
147 1.12 toshii struct rtk_list_data rtk_ldata;
148 1.12 toshii struct mbuf *rtk_head;
149 1.12 toshii struct mbuf *rtk_tail;
150 1.24 tsutsui uint32_t rtk_rxlenmask;
151 1.12 toshii int rtk_testmode;
152 1.5 tsutsui
153 1.5 tsutsui int sc_flags; /* misc flags */
154 1.10 kanaoka int sc_txthresh; /* Early tx threshold */
155 1.14 jonathan int sc_rev; /* revision within rtk_type */
156 1.10 kanaoka
157 1.5 tsutsui void *sc_sdhook; /* shutdown hook */
158 1.5 tsutsui void *sc_powerhook; /* power management hook */
159 1.5 tsutsui
160 1.5 tsutsui /* Power management hooks. */
161 1.17 perry int (*sc_enable) (struct rtk_softc *);
162 1.17 perry void (*sc_disable) (struct rtk_softc *);
163 1.17 perry void (*sc_power) (struct rtk_softc *, int);
164 1.16 dan #if NRND > 0
165 1.16 dan rndsource_element_t rnd_source;
166 1.16 dan #endif
167 1.1 tsutsui };
168 1.1 tsutsui
169 1.18 yamt #define RTK_TX_DESC_CNT(sc) \
170 1.18 yamt ((sc)->rtk_ldata.rtk_tx_desc_cnt)
171 1.18 yamt #define RTK_TX_LIST_SZ(sc) \
172 1.18 yamt (RTK_TX_DESC_CNT(sc) * sizeof(struct rtk_desc))
173 1.25 tsutsui #define RTK_NEXT_TX_DESC(sc, x) \
174 1.25 tsutsui (((x) + 1) % RTK_TX_DESC_CNT(sc))
175 1.25 tsutsui #define RTK_NEXT_RX_DESC(sc, x) \
176 1.25 tsutsui (((x) + 1) % RTK_RX_DESC_CNT)
177 1.25 tsutsui #define RTK_NEXT_TXQ(sc, x) \
178 1.25 tsutsui (((x) + 1) % RTK_TX_QLEN)
179 1.18 yamt
180 1.23 tsutsui #define RTK_TXDESCSYNC(sc, idx, ops) \
181 1.23 tsutsui bus_dmamap_sync((sc)->sc_dmat, \
182 1.23 tsutsui (sc)->rtk_ldata.rtk_tx_list_map, \
183 1.23 tsutsui sizeof(struct rtk_desc) * (idx), \
184 1.23 tsutsui sizeof(struct rtk_desc), \
185 1.23 tsutsui (ops))
186 1.23 tsutsui #define RTK_RXDESCSYNC(sc, idx, ops) \
187 1.23 tsutsui bus_dmamap_sync((sc)->sc_dmat, \
188 1.23 tsutsui (sc)->rtk_ldata.rtk_rx_list_map, \
189 1.23 tsutsui sizeof(struct rtk_desc) * (idx), \
190 1.23 tsutsui sizeof(struct rtk_desc), \
191 1.23 tsutsui (ops))
192 1.23 tsutsui
193 1.5 tsutsui #define RTK_ATTACHED 0x00000001 /* attach has succeeded */
194 1.5 tsutsui #define RTK_ENABLED 0x00000002 /* chip is enabled */
195 1.5 tsutsui
196 1.5 tsutsui #define RTK_IS_ENABLED(sc) ((sc)->sc_flags & RTK_ENABLED)
197 1.10 kanaoka #define RTK_TX_THRESH(sc) (((sc)->sc_txthresh << 16) & 0x003F0000)
198 1.10 kanaoka
199 1.10 kanaoka #define TXTH_256 8
200 1.10 kanaoka #define TXTH_MAX 48
201 1.10 kanaoka
202 1.1 tsutsui /*
203 1.1 tsutsui * register space access macros
204 1.1 tsutsui */
205 1.1 tsutsui #define CSR_WRITE_4(sc, reg, val) \
206 1.4 thorpej bus_space_write_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
207 1.1 tsutsui #define CSR_WRITE_2(sc, reg, val) \
208 1.4 thorpej bus_space_write_2(sc->rtk_btag, sc->rtk_bhandle, reg, val)
209 1.1 tsutsui #define CSR_WRITE_1(sc, reg, val) \
210 1.4 thorpej bus_space_write_1(sc->rtk_btag, sc->rtk_bhandle, reg, val)
211 1.11 fvdl #define CSR_WRITE_STREAM_4(sc, reg, val) \
212 1.11 fvdl bus_space_write_stream_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
213 1.11 fvdl
214 1.1 tsutsui
215 1.1 tsutsui #define CSR_READ_4(sc, reg) \
216 1.4 thorpej bus_space_read_4(sc->rtk_btag, sc->rtk_bhandle, reg)
217 1.1 tsutsui #define CSR_READ_2(sc, reg) \
218 1.4 thorpej bus_space_read_2(sc->rtk_btag, sc->rtk_bhandle, reg)
219 1.1 tsutsui #define CSR_READ_1(sc, reg) \
220 1.4 thorpej bus_space_read_1(sc->rtk_btag, sc->rtk_bhandle, reg)
221 1.1 tsutsui
222 1.5 tsutsui #define RTK_TIMEOUT 1000
223 1.1 tsutsui
224 1.1 tsutsui /*
225 1.26 tsutsui * PCI low memory base and low I/O base registers
226 1.1 tsutsui */
227 1.1 tsutsui
228 1.5 tsutsui #define RTK_PCI_LOIO 0x10
229 1.5 tsutsui #define RTK_PCI_LOMEM 0x14
230 1.1 tsutsui
231 1.1 tsutsui #ifdef _KERNEL
232 1.24 tsutsui uint16_t rtk_read_eeprom(struct rtk_softc *, int, int);
233 1.17 perry void rtk_setmulti(struct rtk_softc *);
234 1.17 perry void rtk_attach(struct rtk_softc *);
235 1.17 perry int rtk_detach(struct rtk_softc *);
236 1.17 perry int rtk_activate(struct device *, enum devact);
237 1.17 perry int rtk_intr(void *);
238 1.1 tsutsui #endif /* _KERNEL */
239