2 * Copyright (c) 2004, 2005 David Young. All rights reserved.
4 * Driver for the Realtek RTL8180 802.11 MAC/BBP by David Young.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of David Young may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David
22 * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 * $NetBSD: rtwvar.h,v 1.28 2006/02/16 20:17:16 perry Exp $
32 * $DragonFly: src/sys/dev/netif/rtw/rtwvar.h,v 1.4 2007/02/07 15:52:42 sephe Exp $
35 #ifndef _DEV_IC_RTWVAR_H_
36 #define _DEV_IC_RTWVAR_H_
39 * 802.11 frame duration definitions.
46 uint8_t d_residue
; /* unused octets in time slot */
50 #define RTW_DEBUG_TUNE 0x0000001
51 #define RTW_DEBUG_PKTFILT 0x0000002
52 #define RTW_DEBUG_XMIT 0x0000004
53 #define RTW_DEBUG_XMIT_DESC 0x0000008
54 #define RTW_DEBUG_NODE 0x0000010
55 #define RTW_DEBUG_PWR 0x0000020
56 #define RTW_DEBUG_ATTACH 0x0000040
57 #define RTW_DEBUG_REGDUMP 0x0000080
58 #define RTW_DEBUG_ACCESS 0x0000100
59 #define RTW_DEBUG_RESET 0x0000200
60 #define RTW_DEBUG_INIT 0x0000400
61 #define RTW_DEBUG_IOSTATE 0x0000800
62 #define RTW_DEBUG_RECV 0x0001000
63 #define RTW_DEBUG_RECV_DESC 0x0002000
64 #define RTW_DEBUG_IO_KICK 0x0004000
65 #define RTW_DEBUG_INTR 0x0008000
66 #define RTW_DEBUG_PHY 0x0010000
67 #define RTW_DEBUG_PHYIO 0x0020000
68 #define RTW_DEBUG_PHYBITIO 0x0040000
69 #define RTW_DEBUG_TIMEOUT 0x0080000
70 #define RTW_DEBUG_BUGS 0x0100000
71 #define RTW_DEBUG_BEACON 0x0200000
72 #define RTW_DEBUG_LED 0x0400000
73 #define RTW_DEBUG_KEY 0x0800000
74 #define RTW_DEBUG_XMIT_RSRC 0x1000000
75 #define RTW_DEBUG_OACTIVE 0x2000000
76 #define RTW_DEBUG_MAX 0x3ffffff
79 #define RTW_DPRINTF(__flags, __x) \
80 if ((rtw_debug & (__flags)) != 0) kprintf __x
81 #define DPRINTF(__sc, __flags, __x) \
82 if (((__sc)->sc_if.if_flags & IFF_DEBUG) != 0) \
83 RTW_DPRINTF(__flags, __x)
84 #define RTW_PRINT_REGS(__regs, __dvname, __where) \
85 rtw_print_regs((__regs), (__dvname), (__where))
87 #define RTW_DPRINTF(__flags, __x)
88 #define DPRINTF(__sc, __flags, __x)
89 #define RTW_PRINT_REGS(__regs, __dvname, __where)
90 #endif /* RTW_DEBUG */
100 RTW_RFCHIPID_RESERVED
= 0,
101 RTW_RFCHIPID_INTERSIL
= 1,
102 RTW_RFCHIPID_RFMD
= 2,
103 RTW_RFCHIPID_PHILIPS
= 3,
104 RTW_RFCHIPID_MAXIM
= 4,
109 #define RTW_F_ENABLED 0x00000001 /* chip is enabled */
110 #define RTW_F_DIGPHY 0x00000002 /* digital PHY */
111 #define RTW_F_DFLANTB 0x00000004 /* B antenna is default */
112 #define RTW_F_ANTDIV 0x00000010 /* h/w antenna diversity */
113 #define RTW_F_9356SROM 0x00000020 /* 93c56 SROM */
114 #define RTW_F_SLEEP 0x00000040 /* chip is asleep */
115 #define RTW_F_INVALID 0x00000080 /* chip is absent */
116 #define RTW_F_DK_VALID 0x00000100 /* keys in DK0-DK3 are valid */
117 #define RTW_C_RXWEP_40 0x00000200 /* h/w decrypts 40-bit WEP */
118 #define RTW_C_RXWEP_104 0x00000400 /* h/w decrypts 104-bit WEP */
120 #define RTW_F_ALLPHY (RTW_F_DIGPHY|RTW_F_DFLANTB|RTW_F_ANTDIV)
124 RTW_ACCESS_CONFIG
= 1,
125 RTW_ACCESS_ANAPARM
= 2
129 bus_space_tag_t r_bt
;
130 bus_space_handle_t r_bh
;
131 enum rtw_access r_access
;
134 struct resource
*r_res
;
137 #define RTW_SR_GET(sr, ofs) \
138 (((sr)->sr_content[(ofs)/2] >> (((ofs) % 2 == 0) ? 0 : 8)) & 0xff)
140 #define RTW_SR_GET16(sr, ofs) \
141 (RTW_SR_GET((sr), (ofs)) | (RTW_SR_GET((sr), (ofs) + 1) << 8))
144 uint16_t *sr_content
;
149 struct mbuf
*rs_mbuf
;
150 bus_dmamap_t rs_dmamap
;
151 bus_addr_t rs_phyaddr
;
155 STAILQ_ENTRY(rtw_txsoft
) ts_q
;
156 struct mbuf
*ts_mbuf
;
157 bus_dmamap_t ts_dmamap
;
158 struct ieee80211_node
*ts_ni
; /* destination node */
161 u_int ts_first
; /* 1st hw descriptor */
162 u_int ts_last
; /* last hw descriptor */
163 struct rtw_duration ts_d0
;
164 struct rtw_duration ts_dn
;
167 #define RTW_NTXPRI 4 /* number of Tx priorities */
168 #define RTW_TXPRILO 0
169 #define RTW_TXPRIMD 1
170 #define RTW_TXPRIHI 2
171 #define RTW_TXPRIBCN 3 /* beacon priority */
173 #define RTW_MAXPKTSEGS 64 /* Max 64 segments per Tx packet */
175 #define CASSERT(cond, complaint) \
176 complaint[(cond) ? 0 : -1] = complaint[(cond) ? 0 : -1]
179 * Note well: the descriptor rings must begin on RTW_DESC_ALIGNMENT
180 * boundaries. I allocate them consecutively from one buffer, so
183 #define RTW_TXQLENLO 64 /* low-priority queue length */
184 #define RTW_TXQLENMD 64 /* medium-priority */
185 #define RTW_TXQLENHI 64 /* high-priority */
186 #define RTW_TXQLENBCN 8 /* beacon */
188 #define RTW_NTXDESCLO RTW_TXQLENLO
189 #define RTW_NTXDESCMD RTW_TXQLENMD
190 #define RTW_NTXDESCHI RTW_TXQLENHI
191 #define RTW_NTXDESCBCN RTW_TXQLENBCN
193 #define RTW_NTXDESCTOTAL (RTW_NTXDESCLO + RTW_NTXDESCMD + \
194 RTW_NTXDESCHI + RTW_NTXDESCBCN)
196 #define RTW_RXQLEN 64
198 struct rtw_rxdesc_blk
{
202 bus_dma_tag_t rdb_dmat
;
203 bus_dmamap_t rdb_dmamap
;
204 struct rtw_rxdesc
*rdb_desc
;
206 uint32_t rdb_base
; /* XXX bus_addr_t */
209 struct rtw_txdesc_blk
{
214 bus_dma_tag_t tdb_dmat
;
215 bus_dmamap_t tdb_dmamap
;
216 struct rtw_txdesc
*tdb_desc
;
218 bus_size_t tdb_basereg
;
219 uint32_t tdb_base
; /* XXX bus_addr_t */
222 #define RTW_NEXT_IDX(__htc, __idx) (((__idx) + 1) % (__htc)->tdb_ndesc)
224 #define RTW_NEXT_DESC(__htc, __idx) \
225 ((__htc)->tdb_base + \
226 sizeof(struct rtw_txdesc) * RTW_NEXT_IDX((__htc), (__idx)))
228 STAILQ_HEAD(rtw_txq
, rtw_txsoft
);
230 struct rtw_txsoft_blk
{
231 /* dirty/free s/w descriptors */
232 struct rtw_txq tsb_dirtyq
;
233 struct rtw_txq tsb_freeq
;
236 struct rtw_txsoft
*tsb_desc
;
241 struct rtw_txdesc hd_txlo
[RTW_NTXDESCLO
];
242 struct rtw_txdesc hd_txmd
[RTW_NTXDESCMD
];
243 struct rtw_txdesc hd_txhi
[RTW_NTXDESCMD
];
244 struct rtw_rxdesc hd_rx
[RTW_RXQLEN
];
245 struct rtw_txdesc hd_bcn
[RTW_NTXDESCBCN
];
247 #define RTW_DESC_OFFSET(ring, i) offsetof(struct rtw_descs, ring[i])
248 #define RTW_RING_OFFSET(ring) RTW_DESC_OFFSET(ring, 0)
249 #define RTW_RING_BASE(sc, ring) ((sc)->sc_desc_physaddr + \
250 RTW_RING_OFFSET(ring))
252 /* Radio capture format for RTL8180. */
254 #define RTW_RX_RADIOTAP_PRESENT \
255 ((1 << IEEE80211_RADIOTAP_TSFT) | \
256 (1 << IEEE80211_RADIOTAP_FLAGS) | \
257 (1 << IEEE80211_RADIOTAP_RATE) | \
258 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
259 (1 << IEEE80211_RADIOTAP_LOCK_QUALITY) | \
260 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
263 struct rtw_rx_radiotap_header
{
264 struct ieee80211_radiotap_header rr_ihdr
;
268 uint16_t rr_chan_freq
;
269 uint16_t rr_chan_flags
;
270 uint16_t rr_barker_lock
;
271 uint8_t rr_antsignal
;
274 #define RTW_TX_RADIOTAP_PRESENT \
275 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
276 (1 << IEEE80211_RADIOTAP_RATE) | \
277 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
280 struct rtw_tx_radiotap_header
{
281 struct ieee80211_radiotap_header rt_ihdr
;
284 uint16_t rt_chan_freq
;
285 uint16_t rt_chan_flags
;
288 enum rtw_attach_state
{FINISHED
, FINISH_DESCMAP_LOAD
, FINISH_DESCMAP_CREATE
,
289 FINISH_DESC_MAP
, FINISH_DESC_ALLOC
, FINISH_RXMAPS_CREATE
,
290 FINISH_TXMAPS_CREATE
, FINISH_RESET
, FINISH_READ_SROM
, FINISH_PARSE_SROM
,
291 FINISH_RF_ATTACH
, FINISH_ID_STA
, FINISH_TXDESCBLK_SETUP
,
292 FINISH_TXCTLBLK_SETUP
, DETACHED
};
295 void *rh_shutdown
; /* shutdown hook */
296 void *rh_power
; /* power management hook */
300 int (*mt_newstate
)(struct ieee80211com
*,
301 enum ieee80211_state
, int);
302 void (*mt_recv_mgmt
)(struct ieee80211com
*,
304 struct ieee80211_node
*,
306 struct ieee80211_node
*(*mt_node_alloc
)(struct ieee80211_node_table
*);
307 void (*mt_node_free
)(struct ieee80211_node
*);
310 enum rtw_pwrstate
{ RTW_OFF
= 0, RTW_SLEEP
, RTW_ON
};
312 typedef void (*rtw_continuous_tx_cb_t
)(void *arg
, int);
316 struct rtw_regs
*p_regs
;
335 void (*rf_destroy
)(struct rtw_rf
*);
336 /* args: frequency, txpower, power state */
337 int (*rf_init
)(struct rtw_rf
*, u_int
, uint8_t,
339 /* arg: power state */
340 int (*rf_pwrstate
)(struct rtw_rf
*,
343 int (*rf_tune
)(struct rtw_rf
*, u_int
);
345 int (*rf_txpower
)(struct rtw_rf
*, uint8_t);
346 rtw_continuous_tx_cb_t rf_continuous_tx_cb
;
347 void *rf_continuous_tx_arg
;
348 struct rtw_bbpset rf_bbpset
;
352 rtw_rf_destroy(struct rtw_rf
*rf
)
358 rtw_rf_init(struct rtw_rf
*rf
, u_int freq
, uint8_t opaque_txpower
,
359 enum rtw_pwrstate power
)
361 return rf
->rf_init(rf
, freq
, opaque_txpower
, power
);
365 rtw_rf_pwrstate(struct rtw_rf
*rf
, enum rtw_pwrstate power
)
367 return rf
->rf_pwrstate(rf
, power
);
371 rtw_rf_tune(struct rtw_rf
*rf
, u_int freq
)
373 return rf
->rf_tune(rf
, freq
);
377 rtw_rf_txpower(struct rtw_rf
*rf
, uint8_t opaque_txpower
)
379 return rf
->rf_txpower(rf
, opaque_txpower
);
382 typedef int (*rtw_rf_write_t
)(struct rtw_regs
*, enum rtw_rfchipid
, u_int
,
386 struct rtw_regs
*b_regs
;
387 rtw_rf_write_t b_write
;
391 rtw_rfbus_write(struct rtw_rfbus
*bus
, enum rtw_rfchipid rfchipid
, u_int addr
,
394 return bus
->b_write(bus
->b_regs
, rfchipid
, addr
, val
);
399 struct rtw_rfbus mx_bus
;
400 int mx_is_a
; /* 1: MAX2820A/MAX2821A */
405 struct rtw_rfbus gr_bus
;
410 struct rtw_rfbus sa_bus
;
411 int sa_digphy
; /* 1: digital PHY */
415 uint8_t rk_keys
[4][16];
416 uint32_t rk_words
[16];
419 #define RTW_LED_SLOW_TICKS MAX(1, hz/2)
420 #define RTW_LED_FAST_TICKS MAX(1, hz/10)
422 struct rtw_led_state
{
425 uint8_t ls_slowblink
:2;
426 uint8_t ls_actblink
:2;
427 uint8_t ls_default
:2;
430 #define RTW_LED_S_RX 0x1
431 #define RTW_LED_S_TX 0x2
432 #define RTW_LED_S_SLOW 0x4
433 struct callout ls_slow_ch
;
434 struct callout ls_fast_ch
;
438 struct ieee80211com sc_ic
;
439 struct rtw_regs sc_regs
;
442 struct resource
*sc_irq_res
;
446 enum rtw_rfchipid sc_rfchipid
;
447 enum rtw_locale sc_locale
;
450 /* s/w Tx/Rx descriptors */
451 bus_dma_tag_t sc_txsoft_dmat
;
452 struct rtw_txsoft_blk sc_txsoft_blk
[RTW_NTXPRI
];
453 struct rtw_txdesc_blk sc_txdesc_blk
[RTW_NTXPRI
];
456 bus_dmamap_t sc_rxsoft_dmamap
;
457 bus_dma_tag_t sc_rxsoft_dmat
;
458 struct rtw_rxsoft sc_rxsoft
[RTW_RXQLEN
];
459 struct rtw_rxdesc_blk sc_rxdesc_blk
;
461 struct rtw_srom sc_srom
;
463 enum rtw_pwrstate sc_pwrstate
;
465 void (*sc_pwrstate_cb
)
466 (struct rtw_regs
*, enum rtw_pwrstate
,
469 int (*sc_getrssi
)(uint8_t, uint8_t);
471 struct rtw_rf
*sc_rf
;
475 /* interrupt acknowledge hook */
476 void (*sc_intr_ack
)(struct rtw_regs
*);
478 void (*sc_power
)(struct rtw_softc
*, int);
479 struct rtw_mtbl sc_mtbl
;
480 struct rtw_hooks sc_hooks
;
482 struct bpf_if
*sc_radiobpf
;
484 struct callout sc_scan_ch
;
487 uint32_t sc_tsfth
; /* most significant TSFT bits */
488 uint32_t sc_rcr
; /* RTW_RCR */
489 uint8_t sc_csthr
; /* carrier-sense threshold */
491 int sc_do_tick
; /* indicate 1s ticks */
492 struct timeval sc_tick0
; /* first tick */
494 uint8_t sc_rev
; /* PCI/Cardbus revision */
496 uint32_t sc_anaparm
; /* register RTW_ANAPARM */
499 struct rtw_rx_radiotap_header tap
;
503 struct rtw_tx_radiotap_header tap
;
506 union rtw_keys sc_keys
;
507 struct ifqueue sc_beaconq
;
508 struct rtw_led_state sc_led_state
;
512 #define sc_if sc_ic.ic_if
513 #define sc_rxtap sc_rxtapu.tap
514 #define sc_txtap sc_txtapu.tap
516 extern devclass_t rtw_devclass
;
519 void rtw_txdac_enable(struct rtw_softc
*, int);
520 void rtw_anaparm_enable(struct rtw_regs
*, int);
521 void rtw_config0123_enable(struct rtw_regs
*, int);
522 void rtw_continuous_tx_enable(struct rtw_softc
*, int);
523 void rtw_set_access(struct rtw_regs
*, enum rtw_access
);
526 int rtw_attach(device_t
);
527 int rtw_detach(device_t
);
528 void rtw_stop(struct rtw_softc
*, int);
530 const char *rtw_pwrstate_string(enum rtw_pwrstate
);
533 #endif /* _DEV_IC_RTWVAR_H_ */