rtwvar.h revision 1.43 1 1.43 dyoung /* $NetBSD: rtwvar.h,v 1.43 2010/03/15 23:21:08 dyoung Exp $ */
2 1.1 dyoung /*-
3 1.1 dyoung * Copyright (c) 2004, 2005 David Young. All rights reserved.
4 1.1 dyoung *
5 1.1 dyoung * Driver for the Realtek RTL8180 802.11 MAC/BBP by David Young.
6 1.1 dyoung *
7 1.1 dyoung * Redistribution and use in source and binary forms, with or without
8 1.1 dyoung * modification, are permitted provided that the following conditions
9 1.1 dyoung * are met:
10 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
11 1.1 dyoung * notice, this list of conditions and the following disclaimer.
12 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
14 1.1 dyoung * documentation and/or other materials provided with the distribution.
15 1.1 dyoung *
16 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
17 1.1 dyoung * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 1.1 dyoung * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 1.1 dyoung * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David
20 1.1 dyoung * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 1.1 dyoung * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 1.1 dyoung * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 dyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 1.1 dyoung * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 1.1 dyoung * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 dyoung * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 1.1 dyoung * OF SUCH DAMAGE.
28 1.1 dyoung */
29 1.1 dyoung
30 1.1 dyoung #ifndef _DEV_IC_RTWVAR_H_
31 1.1 dyoung #define _DEV_IC_RTWVAR_H_
32 1.1 dyoung
33 1.1 dyoung #include <sys/queue.h>
34 1.1 dyoung #include <sys/callout.h>
35 1.1 dyoung
36 1.1 dyoung #ifdef RTW_DEBUG
37 1.25 dyoung #define RTW_DEBUG_TUNE 0x0000001
38 1.25 dyoung #define RTW_DEBUG_PKTFILT 0x0000002
39 1.25 dyoung #define RTW_DEBUG_XMIT 0x0000004
40 1.25 dyoung #define RTW_DEBUG_XMIT_DESC 0x0000008
41 1.25 dyoung #define RTW_DEBUG_NODE 0x0000010
42 1.25 dyoung #define RTW_DEBUG_PWR 0x0000020
43 1.25 dyoung #define RTW_DEBUG_ATTACH 0x0000040
44 1.25 dyoung #define RTW_DEBUG_REGDUMP 0x0000080
45 1.25 dyoung #define RTW_DEBUG_ACCESS 0x0000100
46 1.25 dyoung #define RTW_DEBUG_RESET 0x0000200
47 1.25 dyoung #define RTW_DEBUG_INIT 0x0000400
48 1.25 dyoung #define RTW_DEBUG_IOSTATE 0x0000800
49 1.25 dyoung #define RTW_DEBUG_RECV 0x0001000
50 1.25 dyoung #define RTW_DEBUG_RECV_DESC 0x0002000
51 1.25 dyoung #define RTW_DEBUG_IO_KICK 0x0004000
52 1.25 dyoung #define RTW_DEBUG_INTR 0x0008000
53 1.25 dyoung #define RTW_DEBUG_PHY 0x0010000
54 1.25 dyoung #define RTW_DEBUG_PHYIO 0x0020000
55 1.25 dyoung #define RTW_DEBUG_PHYBITIO 0x0040000
56 1.25 dyoung #define RTW_DEBUG_TIMEOUT 0x0080000
57 1.25 dyoung #define RTW_DEBUG_BUGS 0x0100000
58 1.25 dyoung #define RTW_DEBUG_BEACON 0x0200000
59 1.25 dyoung #define RTW_DEBUG_LED 0x0400000
60 1.25 dyoung #define RTW_DEBUG_KEY 0x0800000
61 1.25 dyoung #define RTW_DEBUG_XMIT_RSRC 0x1000000
62 1.25 dyoung #define RTW_DEBUG_OACTIVE 0x2000000
63 1.25 dyoung #define RTW_DEBUG_MAX 0x3ffffff
64 1.8 dyoung
65 1.1 dyoung extern int rtw_debug;
66 1.8 dyoung #define RTW_DPRINTF(__flags, __x) \
67 1.8 dyoung if ((rtw_debug & (__flags)) != 0) printf __x
68 1.8 dyoung #define DPRINTF(__sc, __flags, __x) \
69 1.23 dyoung if (((__sc)->sc_if.if_flags & IFF_DEBUG) != 0) \
70 1.8 dyoung RTW_DPRINTF(__flags, __x)
71 1.18 dyoung #define RTW_PRINT_REGS(__regs, __dvname, __where) \
72 1.18 dyoung rtw_print_regs((__regs), (__dvname), (__where))
73 1.1 dyoung #else /* RTW_DEBUG */
74 1.10 mycroft #define RTW_DPRINTF(__flags, __x)
75 1.10 mycroft #define DPRINTF(__sc, __flags, __x)
76 1.18 dyoung #define RTW_PRINT_REGS(__regs, __dvname, __where)
77 1.1 dyoung #endif /* RTW_DEBUG */
78 1.1 dyoung
79 1.1 dyoung enum rtw_locale {
80 1.1 dyoung RTW_LOCALE_USA = 0,
81 1.1 dyoung RTW_LOCALE_EUROPE,
82 1.1 dyoung RTW_LOCALE_JAPAN,
83 1.1 dyoung RTW_LOCALE_UNKNOWN
84 1.1 dyoung };
85 1.1 dyoung
86 1.1 dyoung enum rtw_rfchipid {
87 1.1 dyoung RTW_RFCHIPID_RESERVED = 0,
88 1.1 dyoung RTW_RFCHIPID_INTERSIL = 1,
89 1.1 dyoung RTW_RFCHIPID_RFMD = 2,
90 1.1 dyoung RTW_RFCHIPID_PHILIPS = 3,
91 1.1 dyoung RTW_RFCHIPID_MAXIM = 4,
92 1.1 dyoung RTW_RFCHIPID_GCT = 5
93 1.21 perry };
94 1.1 dyoung /* sc_flags */
95 1.1 dyoung #define RTW_F_DIGPHY 0x00000002 /* digital PHY */
96 1.1 dyoung #define RTW_F_DFLANTB 0x00000004 /* B antenna is default */
97 1.1 dyoung #define RTW_F_ANTDIV 0x00000010 /* h/w antenna diversity */
98 1.1 dyoung #define RTW_F_9356SROM 0x00000020 /* 93c56 SROM */
99 1.37 dyoung #define RTW_F_DK_VALID 0x00000040 /* keys in DK0-DK3 are valid */
100 1.37 dyoung #define RTW_C_RXWEP_40 0x00000080 /* h/w decrypts 40-bit WEP */
101 1.37 dyoung #define RTW_C_RXWEP_104 0x00000100 /* h/w decrypts 104-bit WEP */
102 1.1 dyoung /* all PHY flags */
103 1.1 dyoung #define RTW_F_ALLPHY (RTW_F_DIGPHY|RTW_F_DFLANTB|RTW_F_ANTDIV)
104 1.19 dyoung enum rtw_access {RTW_ACCESS_NONE = 0,
105 1.19 dyoung RTW_ACCESS_CONFIG = 1,
106 1.19 dyoung RTW_ACCESS_ANAPARM = 2};
107 1.19 dyoung
108 1.1 dyoung struct rtw_regs {
109 1.1 dyoung bus_space_tag_t r_bt;
110 1.1 dyoung bus_space_handle_t r_bh;
111 1.37 dyoung bus_size_t r_sz;
112 1.19 dyoung enum rtw_access r_access;
113 1.1 dyoung };
114 1.1 dyoung
115 1.43 dyoung /*
116 1.43 dyoung * Bus barrier
117 1.43 dyoung *
118 1.43 dyoung * Complete outstanding read and/or write ops on [reg0, reg1]
119 1.43 dyoung * ([reg1, reg0]) before starting new ops on the same region. See
120 1.43 dyoung * acceptable bus_space_barrier(9) for the flag definitions.
121 1.43 dyoung */
122 1.43 dyoung static inline void
123 1.43 dyoung rtw_barrier(const struct rtw_regs *r, int reg0, int reg1, int flags)
124 1.43 dyoung {
125 1.43 dyoung bus_space_barrier(r->r_bt, r->r_bh, MIN(reg0, reg1),
126 1.43 dyoung MAX(reg0, reg1) - MIN(reg0, reg1) + 4, flags);
127 1.43 dyoung }
128 1.43 dyoung
129 1.43 dyoung /*
130 1.43 dyoung * Barrier convenience macros.
131 1.43 dyoung */
132 1.43 dyoung /* sync */
133 1.43 dyoung #define RTW_SYNC(regs, reg0, reg1) \
134 1.43 dyoung rtw_barrier(regs, reg0, reg1, BUS_SPACE_BARRIER_SYNC)
135 1.43 dyoung
136 1.43 dyoung /* write-before-write */
137 1.43 dyoung #define RTW_WBW(regs, reg0, reg1) \
138 1.43 dyoung rtw_barrier(regs, reg0, reg1, BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE)
139 1.43 dyoung
140 1.43 dyoung /* write-before-read */
141 1.43 dyoung #define RTW_WBR(regs, reg0, reg1) \
142 1.43 dyoung rtw_barrier(regs, reg0, reg1, BUS_SPACE_BARRIER_WRITE_BEFORE_READ)
143 1.43 dyoung
144 1.43 dyoung /* read-before-read */
145 1.43 dyoung #define RTW_RBR(regs, reg0, reg1) \
146 1.43 dyoung rtw_barrier(regs, reg0, reg1, BUS_SPACE_BARRIER_READ_BEFORE_READ)
147 1.43 dyoung
148 1.43 dyoung /* read-before-write */
149 1.43 dyoung #define RTW_RBW(regs, reg0, reg1) \
150 1.43 dyoung rtw_barrier(regs, reg0, reg1, BUS_SPACE_BARRIER_READ_BEFORE_WRITE)
151 1.43 dyoung
152 1.43 dyoung #define RTW_WBRW(regs, reg0, reg1) \
153 1.43 dyoung rtw_barrier(regs, reg0, reg1, \
154 1.43 dyoung BUS_SPACE_BARRIER_WRITE_BEFORE_READ | \
155 1.43 dyoung BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE)
156 1.43 dyoung
157 1.1 dyoung #define RTW_SR_GET(sr, ofs) \
158 1.1 dyoung (((sr)->sr_content[(ofs)/2] >> (((ofs) % 2 == 0) ? 0 : 8)) & 0xff)
159 1.1 dyoung
160 1.1 dyoung #define RTW_SR_GET16(sr, ofs) \
161 1.1 dyoung (RTW_SR_GET((sr), (ofs)) | (RTW_SR_GET((sr), (ofs) + 1) << 8))
162 1.1 dyoung
163 1.1 dyoung struct rtw_srom {
164 1.17 dyoung uint16_t *sr_content;
165 1.17 dyoung uint16_t sr_size;
166 1.1 dyoung };
167 1.1 dyoung
168 1.15 dyoung struct rtw_rxsoft {
169 1.15 dyoung struct mbuf *rs_mbuf;
170 1.15 dyoung bus_dmamap_t rs_dmamap;
171 1.1 dyoung };
172 1.1 dyoung
173 1.15 dyoung struct rtw_txsoft {
174 1.15 dyoung SIMPLEQ_ENTRY(rtw_txsoft) ts_q;
175 1.15 dyoung struct mbuf *ts_mbuf;
176 1.15 dyoung bus_dmamap_t ts_dmamap;
177 1.15 dyoung struct ieee80211_node *ts_ni; /* destination node */
178 1.15 dyoung u_int ts_first; /* 1st hw descriptor */
179 1.15 dyoung u_int ts_last; /* last hw descriptor */
180 1.15 dyoung struct ieee80211_duration ts_d0;
181 1.15 dyoung struct ieee80211_duration ts_dn;
182 1.1 dyoung };
183 1.1 dyoung
184 1.1 dyoung #define RTW_NTXPRI 4 /* number of Tx priorities */
185 1.1 dyoung #define RTW_TXPRILO 0
186 1.1 dyoung #define RTW_TXPRIMD 1
187 1.1 dyoung #define RTW_TXPRIHI 2
188 1.1 dyoung #define RTW_TXPRIBCN 3 /* beacon priority */
189 1.1 dyoung
190 1.8 dyoung #define RTW_MAXPKTSEGS 64 /* Max 64 segments per Tx packet */
191 1.1 dyoung
192 1.1 dyoung #define CASSERT(cond, complaint) complaint[(cond) ? 0 : -1] = complaint[(cond) ? 0 : -1]
193 1.1 dyoung
194 1.8 dyoung /* Note well: the descriptor rings must begin on RTW_DESC_ALIGNMENT
195 1.8 dyoung * boundaries. I allocate them consecutively from one buffer, so
196 1.8 dyoung * just round up.
197 1.1 dyoung */
198 1.8 dyoung #define RTW_TXQLENLO 64 /* low-priority queue length */
199 1.8 dyoung #define RTW_TXQLENMD 64 /* medium-priority */
200 1.8 dyoung #define RTW_TXQLENHI 64 /* high-priority */
201 1.25 dyoung #define RTW_TXQLENBCN 8 /* beacon */
202 1.8 dyoung
203 1.8 dyoung #define RTW_NTXDESCLO RTW_TXQLENLO
204 1.8 dyoung #define RTW_NTXDESCMD RTW_TXQLENMD
205 1.8 dyoung #define RTW_NTXDESCHI RTW_TXQLENHI
206 1.8 dyoung #define RTW_NTXDESCBCN RTW_TXQLENBCN
207 1.1 dyoung
208 1.1 dyoung #define RTW_NTXDESCTOTAL (RTW_NTXDESCLO + RTW_NTXDESCMD + \
209 1.1 dyoung RTW_NTXDESCHI + RTW_NTXDESCBCN)
210 1.1 dyoung
211 1.8 dyoung #define RTW_RXQLEN 64
212 1.1 dyoung
213 1.14 dyoung struct rtw_rxdesc_blk {
214 1.30 dyoung u_int rdb_ndesc;
215 1.15 dyoung u_int rdb_next;
216 1.15 dyoung bus_dma_tag_t rdb_dmat;
217 1.15 dyoung bus_dmamap_t rdb_dmamap;
218 1.30 dyoung struct rtw_rxdesc *rdb_desc;
219 1.14 dyoung };
220 1.14 dyoung
221 1.1 dyoung struct rtw_txdesc_blk {
222 1.15 dyoung u_int tdb_ndesc;
223 1.15 dyoung u_int tdb_next;
224 1.15 dyoung u_int tdb_nfree;
225 1.15 dyoung bus_dma_tag_t tdb_dmat;
226 1.15 dyoung bus_dmamap_t tdb_dmamap;
227 1.15 dyoung bus_addr_t tdb_physbase;
228 1.15 dyoung bus_addr_t tdb_ofs;
229 1.25 dyoung bus_size_t tdb_basereg;
230 1.25 dyoung uint32_t tdb_base;
231 1.15 dyoung struct rtw_txdesc *tdb_desc;
232 1.1 dyoung };
233 1.1 dyoung
234 1.15 dyoung #define RTW_NEXT_IDX(__htc, __idx) (((__idx) + 1) % (__htc)->tdb_ndesc)
235 1.5 dyoung
236 1.5 dyoung #define RTW_NEXT_DESC(__htc, __idx) \
237 1.15 dyoung ((__htc)->tdb_physbase + \
238 1.5 dyoung sizeof(struct rtw_txdesc) * RTW_NEXT_IDX((__htc), (__idx)))
239 1.1 dyoung
240 1.15 dyoung SIMPLEQ_HEAD(rtw_txq, rtw_txsoft);
241 1.1 dyoung
242 1.15 dyoung struct rtw_txsoft_blk {
243 1.1 dyoung /* dirty/free s/w descriptors */
244 1.15 dyoung struct rtw_txq tsb_dirtyq;
245 1.15 dyoung struct rtw_txq tsb_freeq;
246 1.15 dyoung u_int tsb_ndesc;
247 1.15 dyoung int tsb_tx_timer;
248 1.15 dyoung struct rtw_txsoft *tsb_desc;
249 1.19 dyoung uint8_t tsb_poll;
250 1.1 dyoung };
251 1.1 dyoung
252 1.1 dyoung struct rtw_descs {
253 1.1 dyoung struct rtw_txdesc hd_txlo[RTW_NTXDESCLO];
254 1.1 dyoung struct rtw_txdesc hd_txmd[RTW_NTXDESCMD];
255 1.1 dyoung struct rtw_txdesc hd_txhi[RTW_NTXDESCMD];
256 1.8 dyoung struct rtw_rxdesc hd_rx[RTW_RXQLEN];
257 1.1 dyoung struct rtw_txdesc hd_bcn[RTW_NTXDESCBCN];
258 1.1 dyoung };
259 1.1 dyoung #define RTW_DESC_OFFSET(ring, i) offsetof(struct rtw_descs, ring[i])
260 1.1 dyoung #define RTW_RING_OFFSET(ring) RTW_DESC_OFFSET(ring, 0)
261 1.1 dyoung #define RTW_RING_BASE(sc, ring) ((sc)->sc_desc_physaddr + \
262 1.1 dyoung RTW_RING_OFFSET(ring))
263 1.1 dyoung
264 1.1 dyoung /* Radio capture format for RTL8180. */
265 1.1 dyoung
266 1.13 dyoung #define RTW_RX_RADIOTAP_PRESENT \
267 1.13 dyoung ((1 << IEEE80211_RADIOTAP_TSFT) | \
268 1.13 dyoung (1 << IEEE80211_RADIOTAP_FLAGS) | \
269 1.13 dyoung (1 << IEEE80211_RADIOTAP_RATE) | \
270 1.13 dyoung (1 << IEEE80211_RADIOTAP_CHANNEL) | \
271 1.13 dyoung (1 << IEEE80211_RADIOTAP_LOCK_QUALITY) | \
272 1.13 dyoung (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
273 1.13 dyoung 0)
274 1.1 dyoung
275 1.32 dyoung #define RTW_PHILIPS_RX_RADIOTAP_PRESENT \
276 1.32 dyoung ((1 << IEEE80211_RADIOTAP_TSFT) | \
277 1.32 dyoung (1 << IEEE80211_RADIOTAP_FLAGS) | \
278 1.32 dyoung (1 << IEEE80211_RADIOTAP_RATE) | \
279 1.32 dyoung (1 << IEEE80211_RADIOTAP_CHANNEL) | \
280 1.32 dyoung (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
281 1.32 dyoung 0)
282 1.32 dyoung
283 1.1 dyoung struct rtw_rx_radiotap_header {
284 1.1 dyoung struct ieee80211_radiotap_header rr_ihdr;
285 1.13 dyoung uint64_t rr_tsft;
286 1.32 dyoung uint8_t rr_flags;
287 1.32 dyoung uint8_t rr_rate;
288 1.17 dyoung uint16_t rr_chan_freq;
289 1.17 dyoung uint16_t rr_chan_flags;
290 1.32 dyoung union {
291 1.32 dyoung struct {
292 1.32 dyoung uint16_t o_barker_lock;
293 1.32 dyoung uint8_t o_antsignal;
294 1.32 dyoung } u_other;
295 1.32 dyoung struct {
296 1.32 dyoung uint8_t p_antsignal;
297 1.32 dyoung } u_philips;
298 1.32 dyoung } rr_u;
299 1.36 perry } __packed;
300 1.1 dyoung
301 1.13 dyoung #define RTW_TX_RADIOTAP_PRESENT \
302 1.32 dyoung ((1 << IEEE80211_RADIOTAP_RATE) | \
303 1.13 dyoung (1 << IEEE80211_RADIOTAP_CHANNEL) | \
304 1.13 dyoung 0)
305 1.1 dyoung
306 1.1 dyoung struct rtw_tx_radiotap_header {
307 1.1 dyoung struct ieee80211_radiotap_header rt_ihdr;
308 1.32 dyoung uint8_t rt_rate;
309 1.32 dyoung uint8_t rt_pad;
310 1.17 dyoung uint16_t rt_chan_freq;
311 1.17 dyoung uint16_t rt_chan_flags;
312 1.36 perry } __packed;
313 1.1 dyoung
314 1.1 dyoung enum rtw_attach_state {FINISHED, FINISH_DESCMAP_LOAD, FINISH_DESCMAP_CREATE,
315 1.1 dyoung FINISH_DESC_MAP, FINISH_DESC_ALLOC, FINISH_RXMAPS_CREATE,
316 1.1 dyoung FINISH_TXMAPS_CREATE, FINISH_RESET, FINISH_READ_SROM, FINISH_PARSE_SROM,
317 1.1 dyoung FINISH_RF_ATTACH, FINISH_ID_STA, FINISH_TXDESCBLK_SETUP,
318 1.1 dyoung FINISH_TXCTLBLK_SETUP, DETACHED};
319 1.1 dyoung
320 1.1 dyoung struct rtw_mtbl {
321 1.1 dyoung int (*mt_newstate)(struct ieee80211com *,
322 1.1 dyoung enum ieee80211_state, int);
323 1.1 dyoung void (*mt_recv_mgmt)(struct ieee80211com *,
324 1.1 dyoung struct mbuf *, struct ieee80211_node *,
325 1.17 dyoung int, int, uint32_t);
326 1.23 dyoung struct ieee80211_node *(*mt_node_alloc)(struct ieee80211_node_table*);
327 1.23 dyoung void (*mt_node_free)(struct ieee80211_node *);
328 1.1 dyoung };
329 1.1 dyoung
330 1.1 dyoung enum rtw_pwrstate { RTW_OFF = 0, RTW_SLEEP, RTW_ON };
331 1.1 dyoung
332 1.1 dyoung typedef void (*rtw_continuous_tx_cb_t)(void *arg, int);
333 1.1 dyoung
334 1.1 dyoung struct rtw_phy {
335 1.1 dyoung struct rtw_rf *p_rf;
336 1.1 dyoung struct rtw_regs *p_regs;
337 1.1 dyoung };
338 1.1 dyoung
339 1.1 dyoung struct rtw_bbpset {
340 1.1 dyoung u_int bb_antatten;
341 1.1 dyoung u_int bb_chestlim;
342 1.1 dyoung u_int bb_chsqlim;
343 1.1 dyoung u_int bb_ifagcdet;
344 1.1 dyoung u_int bb_ifagcini;
345 1.1 dyoung u_int bb_ifagclimit;
346 1.1 dyoung u_int bb_lnadet;
347 1.1 dyoung u_int bb_sys1;
348 1.1 dyoung u_int bb_sys2;
349 1.1 dyoung u_int bb_sys3;
350 1.1 dyoung u_int bb_trl;
351 1.1 dyoung u_int bb_txagc;
352 1.1 dyoung };
353 1.1 dyoung
354 1.1 dyoung struct rtw_rf {
355 1.1 dyoung void (*rf_destroy)(struct rtw_rf *);
356 1.1 dyoung /* args: frequency, txpower, power state */
357 1.17 dyoung int (*rf_init)(struct rtw_rf *, u_int, uint8_t,
358 1.1 dyoung enum rtw_pwrstate);
359 1.1 dyoung /* arg: power state */
360 1.1 dyoung int (*rf_pwrstate)(struct rtw_rf *, enum rtw_pwrstate);
361 1.1 dyoung /* arg: frequency */
362 1.1 dyoung int (*rf_tune)(struct rtw_rf *, u_int);
363 1.1 dyoung /* arg: txpower */
364 1.17 dyoung int (*rf_txpower)(struct rtw_rf *, uint8_t);
365 1.1 dyoung rtw_continuous_tx_cb_t rf_continuous_tx_cb;
366 1.1 dyoung void *rf_continuous_tx_arg;
367 1.1 dyoung struct rtw_bbpset rf_bbpset;
368 1.1 dyoung };
369 1.1 dyoung
370 1.28 perry static __inline void
371 1.1 dyoung rtw_rf_destroy(struct rtw_rf *rf)
372 1.1 dyoung {
373 1.1 dyoung (*rf->rf_destroy)(rf);
374 1.1 dyoung }
375 1.1 dyoung
376 1.28 perry static __inline int
377 1.17 dyoung rtw_rf_init(struct rtw_rf *rf, u_int freq, uint8_t opaque_txpower,
378 1.1 dyoung enum rtw_pwrstate power)
379 1.1 dyoung {
380 1.1 dyoung return (*rf->rf_init)(rf, freq, opaque_txpower, power);
381 1.1 dyoung }
382 1.1 dyoung
383 1.28 perry static __inline int
384 1.1 dyoung rtw_rf_pwrstate(struct rtw_rf *rf, enum rtw_pwrstate power)
385 1.1 dyoung {
386 1.1 dyoung return (*rf->rf_pwrstate)(rf, power);
387 1.1 dyoung }
388 1.1 dyoung
389 1.28 perry static __inline int
390 1.1 dyoung rtw_rf_tune(struct rtw_rf *rf, u_int freq)
391 1.1 dyoung {
392 1.1 dyoung return (*rf->rf_tune)(rf, freq);
393 1.1 dyoung }
394 1.1 dyoung
395 1.28 perry static __inline int
396 1.17 dyoung rtw_rf_txpower(struct rtw_rf *rf, uint8_t opaque_txpower)
397 1.1 dyoung {
398 1.1 dyoung return (*rf->rf_txpower)(rf, opaque_txpower);
399 1.1 dyoung }
400 1.1 dyoung
401 1.1 dyoung typedef int (*rtw_rf_write_t)(struct rtw_regs *, enum rtw_rfchipid, u_int,
402 1.17 dyoung uint32_t);
403 1.1 dyoung
404 1.1 dyoung struct rtw_rfbus {
405 1.1 dyoung struct rtw_regs *b_regs;
406 1.1 dyoung rtw_rf_write_t b_write;
407 1.1 dyoung };
408 1.1 dyoung
409 1.28 perry static __inline int
410 1.1 dyoung rtw_rfbus_write(struct rtw_rfbus *bus, enum rtw_rfchipid rfchipid, u_int addr,
411 1.17 dyoung uint32_t val)
412 1.1 dyoung {
413 1.1 dyoung return (*bus->b_write)(bus->b_regs, rfchipid, addr, val);
414 1.1 dyoung }
415 1.1 dyoung
416 1.1 dyoung struct rtw_max2820 {
417 1.1 dyoung struct rtw_rf mx_rf;
418 1.1 dyoung struct rtw_rfbus mx_bus;
419 1.1 dyoung int mx_is_a; /* 1: MAX2820A/MAX2821A */
420 1.1 dyoung };
421 1.1 dyoung
422 1.27 dyoung struct rtw_grf5101 {
423 1.27 dyoung struct rtw_rf gr_rf;
424 1.27 dyoung struct rtw_rfbus gr_bus;
425 1.27 dyoung };
426 1.27 dyoung
427 1.1 dyoung struct rtw_sa2400 {
428 1.1 dyoung struct rtw_rf sa_rf;
429 1.1 dyoung struct rtw_rfbus sa_bus;
430 1.1 dyoung int sa_digphy; /* 1: digital PHY */
431 1.1 dyoung };
432 1.1 dyoung
433 1.6 dyoung typedef void (*rtw_pwrstate_t)(struct rtw_regs *, enum rtw_pwrstate, int, int);
434 1.1 dyoung
435 1.19 dyoung union rtw_keys {
436 1.19 dyoung uint8_t rk_keys[4][16];
437 1.19 dyoung uint32_t rk_words[16];
438 1.19 dyoung };
439 1.19 dyoung
440 1.19 dyoung #define RTW_LED_SLOW_TICKS MAX(1, hz/2)
441 1.19 dyoung #define RTW_LED_FAST_TICKS MAX(1, hz/10)
442 1.19 dyoung
443 1.19 dyoung struct rtw_led_state {
444 1.19 dyoung #define RTW_LED0 0x1
445 1.19 dyoung #define RTW_LED1 0x2
446 1.19 dyoung uint8_t ls_slowblink:2;
447 1.19 dyoung uint8_t ls_actblink:2;
448 1.19 dyoung uint8_t ls_default:2;
449 1.19 dyoung uint8_t ls_state;
450 1.19 dyoung uint8_t ls_event;
451 1.19 dyoung #define RTW_LED_S_RX 0x1
452 1.19 dyoung #define RTW_LED_S_TX 0x2
453 1.19 dyoung #define RTW_LED_S_SLOW 0x4
454 1.19 dyoung struct callout ls_slow_ch;
455 1.19 dyoung struct callout ls_fast_ch;
456 1.19 dyoung };
457 1.2 dyoung
458 1.1 dyoung struct rtw_softc {
459 1.35 dyoung device_t sc_dev;
460 1.42 dyoung device_suspensor_t sc_suspensor;
461 1.42 dyoung pmf_qual_t sc_qual;
462 1.38 dyoung
463 1.23 dyoung struct ethercom sc_ec;
464 1.1 dyoung struct ieee80211com sc_ic;
465 1.1 dyoung struct rtw_regs sc_regs;
466 1.1 dyoung bus_dma_tag_t sc_dmat;
467 1.17 dyoung uint32_t sc_flags;
468 1.1 dyoung
469 1.1 dyoung enum rtw_attach_state sc_attach_state;
470 1.1 dyoung enum rtw_rfchipid sc_rfchipid;
471 1.1 dyoung enum rtw_locale sc_locale;
472 1.17 dyoung uint8_t sc_phydelay;
473 1.1 dyoung
474 1.1 dyoung /* s/w Tx/Rx descriptors */
475 1.15 dyoung struct rtw_txsoft_blk sc_txsoft_blk[RTW_NTXPRI];
476 1.14 dyoung struct rtw_txdesc_blk sc_txdesc_blk[RTW_NTXPRI];
477 1.1 dyoung
478 1.15 dyoung struct rtw_rxsoft sc_rxsoft[RTW_RXQLEN];
479 1.14 dyoung struct rtw_rxdesc_blk sc_rxdesc_blk;
480 1.1 dyoung
481 1.1 dyoung struct rtw_descs *sc_descs;
482 1.1 dyoung
483 1.1 dyoung bus_dma_segment_t sc_desc_segs;
484 1.1 dyoung int sc_desc_nsegs;
485 1.1 dyoung bus_dmamap_t sc_desc_dmamap;
486 1.1 dyoung #define sc_desc_physaddr sc_desc_dmamap->dm_segs[0].ds_addr
487 1.1 dyoung
488 1.1 dyoung struct rtw_srom sc_srom;
489 1.1 dyoung
490 1.1 dyoung enum rtw_pwrstate sc_pwrstate;
491 1.1 dyoung
492 1.1 dyoung rtw_pwrstate_t sc_pwrstate_cb;
493 1.1 dyoung
494 1.1 dyoung struct rtw_rf *sc_rf;
495 1.1 dyoung
496 1.17 dyoung uint16_t sc_inten;
497 1.1 dyoung
498 1.1 dyoung /* interrupt acknowledge hook */
499 1.20 perry void (*sc_intr_ack)(struct rtw_regs *);
500 1.1 dyoung
501 1.1 dyoung struct rtw_mtbl sc_mtbl;
502 1.1 dyoung
503 1.41 pooka struct bpf_if * sc_radiobpf;
504 1.1 dyoung
505 1.1 dyoung struct callout sc_scan_ch;
506 1.1 dyoung u_int sc_cur_chan;
507 1.1 dyoung
508 1.17 dyoung uint32_t sc_tsfth; /* most significant TSFT bits */
509 1.17 dyoung uint32_t sc_rcr; /* RTW_RCR */
510 1.17 dyoung uint8_t sc_csthr; /* carrier-sense threshold */
511 1.1 dyoung
512 1.1 dyoung int sc_do_tick; /* indicate 1s ticks */
513 1.1 dyoung struct timeval sc_tick0; /* first tick */
514 1.1 dyoung
515 1.3 dyoung uint8_t sc_rev; /* PCI/Cardbus revision */
516 1.3 dyoung
517 1.3 dyoung uint32_t sc_anaparm; /* register RTW_ANAPARM */
518 1.1 dyoung
519 1.1 dyoung union {
520 1.1 dyoung struct rtw_rx_radiotap_header tap;
521 1.17 dyoung uint8_t pad[64];
522 1.1 dyoung } sc_rxtapu;
523 1.1 dyoung union {
524 1.1 dyoung struct rtw_tx_radiotap_header tap;
525 1.17 dyoung uint8_t pad[64];
526 1.1 dyoung } sc_txtapu;
527 1.19 dyoung union rtw_keys sc_keys;
528 1.19 dyoung struct ifqueue sc_beaconq;
529 1.19 dyoung struct rtw_led_state sc_led_state;
530 1.19 dyoung int sc_hwverid;
531 1.1 dyoung };
532 1.1 dyoung
533 1.23 dyoung #define sc_if sc_ec.ec_if
534 1.1 dyoung #define sc_rxtap sc_rxtapu.tap
535 1.1 dyoung #define sc_txtap sc_txtapu.tap
536 1.1 dyoung
537 1.3 dyoung void rtw_txdac_enable(struct rtw_softc *, int);
538 1.1 dyoung void rtw_anaparm_enable(struct rtw_regs *, int);
539 1.1 dyoung void rtw_config0123_enable(struct rtw_regs *, int);
540 1.2 dyoung void rtw_continuous_tx_enable(struct rtw_softc *, int);
541 1.19 dyoung void rtw_set_access(struct rtw_regs *, enum rtw_access);
542 1.1 dyoung
543 1.1 dyoung void rtw_attach(struct rtw_softc *);
544 1.1 dyoung int rtw_detach(struct rtw_softc *);
545 1.1 dyoung int rtw_intr(void *);
546 1.1 dyoung
547 1.42 dyoung bool rtw_suspend(device_t, const pmf_qual_t *);
548 1.42 dyoung bool rtw_resume(device_t, const pmf_qual_t *);
549 1.1 dyoung
550 1.35 dyoung int rtw_activate(device_t, enum devact);
551 1.1 dyoung
552 1.1 dyoung const char *rtw_pwrstate_string(enum rtw_pwrstate);
553 1.1 dyoung
554 1.1 dyoung #endif /* _DEV_IC_RTWVAR_H_ */
555