xref: /titanic_41/usr/src/uts/common/io/ral/rt2560_var.h (revision c10c16dec587a0662068f6e2991c29ed3a9db943)
1 /*
2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 2005, 2006
8  *	Damien Bergamini <damien.bergamini@free.fr>
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 #ifndef	_RT2560_VAR_H
23 #define	_RT2560_VAR_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define	RAL_FLAG_RUNNING	(1<<0)
30 #define	RAL_FLAG_SUSPENDING	(1<<1)
31 
32 #define	RAL_RCR_PROMISC		(1<<0)
33 #define	RAL_RCR_MULTI		(2<<0)
34 
35 #ifndef	DDI_NT_NET_WIFI
36 #define	DDI_NT_NET_WIFI		"ddi_network:wifi"
37 #endif
38 
39 /*
40  * Bit flags in the ral_dbg_flags
41  */
42 #define	RAL_DBG_MSG		0x000001
43 #define	RAL_DBG_HW		0x000002
44 #define	RAL_DBG_DMA		0x000004
45 #define	RAL_DBG_INTR		0x000008
46 #define	RAL_DBG_TX		0x000010
47 #define	RAL_DBG_RX		0x000020
48 #define	RAL_DBG_CHAN		0x000040
49 #define	RAL_DBG_IOCTL		0x000080
50 #define	RAL_DBG_MGMT		0x000100
51 #define	RAL_DBG_STAT		0x000200
52 #define	RAL_DBG_GLD		0x000400
53 #define	RAL_DBG_80211		0x000800
54 #define	RAL_DBG_STATE		0x001000
55 #define	RAL_DBG_RXPACKET	0x002000
56 #define	RAL_DBG_TXPACKET	0x004000
57 #define	RAL_DBG_SUSPEND		0x008000
58 #define	RAL_DBG_ALL		0x00ffff
59 
60 #define	RT2560_RX_RADIOTAP_PRESENT					\
61 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
62 	(1 << IEEE80211_RADIOTAP_FLAGS) |				\
63 	(1 << IEEE80211_RADIOTAP_RATE) |				\
64 	(1 << IEEE80211_RADIOTAP_CHANNEL) |				\
65 	(1 << IEEE80211_RADIOTAP_ANTENNA) |				\
66 	(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
67 
68 #define	RT2560_TX_RADIOTAP_PRESENT					\
69 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
70 	(1 << IEEE80211_RADIOTAP_RATE) |				\
71 	(1 << IEEE80211_RADIOTAP_CHANNEL) |				\
72 	(1 << IEEE80211_RADIOTAP_ANTENNA))
73 
74 struct dma_region {
75 	ddi_dma_handle_t	dr_hnd;
76 	ddi_acc_handle_t	dr_acc;
77 	ddi_dma_cookie_t	dr_cookie;
78 	uint_t			dr_ccnt;
79 	uint32_t		dr_pbase;
80 	caddr_t			dr_base;
81 	size_t			dr_size;
82 };
83 
84 struct rt2560_tx_data {
85 	caddr_t			buf;
86 	struct ieee80211_node	*ni;
87 	struct ral_rssdesc	id;
88 };
89 
90 /*
91  * physaddr = dr_desc.dr_pbase
92  * desc = dr_desc.dr_base, desc[i].physaddr = dr_txbuf[i].dr_pbase
93  * data[i]->buf = dr_txbuf[i].dr_bas
94  */
95 struct rt2560_tx_ring {
96 	uint32_t		physaddr;
97 	struct rt2560_tx_desc	*desc;
98 	struct rt2560_tx_data	*data;
99 
100 	struct dma_region	dr_desc;
101 	struct dma_region	*dr_txbuf;
102 
103 	int			count;
104 	int			queued;
105 	int			cur;
106 	int			next;
107 	int			cur_encrypt;
108 	int			next_encrypt;
109 	kmutex_t		tx_lock;
110 };
111 
112 struct rt2560_rx_data {
113 	caddr_t			buf;
114 	int			drop;
115 };
116 
117 struct rt2560_rx_ring {
118 	uint32_t		physaddr;
119 	struct rt2560_rx_desc	*desc;
120 	struct rt2560_rx_data	*data;
121 
122 	struct dma_region	dr_desc;
123 	struct dma_region	*dr_rxbuf;
124 
125 	int			count;
126 	int			cur;
127 	int			next;
128 	int			cur_decrypt;
129 	kmutex_t		rx_lock;
130 };
131 
132 struct rt2560_node {
133 	struct ieee80211_node	ni;
134 	struct ral_rssadapt	rssadapt;
135 };
136 
137 struct rt2560_softc {
138 	struct ieee80211com	sc_ic;
139 	dev_info_t		*sc_dev;
140 
141 	/* ddi i/o handler */
142 	ddi_acc_handle_t	sc_ioh;
143 	caddr_t			sc_rbase;
144 
145 	/* interrupt */
146 	ddi_iblock_cookie_t	sc_iblock;
147 
148 	kmutex_t		sc_genlock;
149 
150 	timeout_id_t		sc_scan_id;
151 	timeout_id_t		sc_rssadapt_id;
152 
153 	enum ieee80211_state	sc_ostate;
154 	timeout_id_t		sc_state_id;
155 
156 	int			sc_tx_timer;
157 
158 	uint32_t		asic_rev;
159 	uint32_t		eeprom_rev;
160 	uint8_t			rf_rev;
161 
162 	struct rt2560_tx_ring	txq;
163 	struct rt2560_tx_ring	prioq;
164 	struct rt2560_rx_ring	rxq;
165 
166 	uint32_t		sc_need_sched;
167 	uint32_t		sc_flags;
168 	uint32_t		sc_rcr;		/* RAL RCR */
169 
170 	uint16_t		sc_cachelsz;
171 	ddi_softintr_t		sc_softint_id;
172 
173 	uint32_t		sc_rx_pend;
174 
175 	uint32_t		rf_regs[4];
176 	uint8_t			txpow[14];
177 
178 	struct {
179 		uint8_t	reg;
180 		uint8_t	val;
181 	}			bbp_prom[16];
182 
183 	int			led_mode;
184 	int			hw_radio;
185 	int			rx_ant;
186 	int			tx_ant;
187 	int			nb_ant;
188 
189 	int			dwelltime;
190 
191 	/* kstats */
192 	uint32_t		sc_tx_nobuf;
193 	uint32_t		sc_rx_nobuf;
194 	uint32_t		sc_tx_err;
195 	uint32_t		sc_rx_err;
196 	uint32_t		sc_tx_retries;
197 
198 	int			(*sc_newstate)(struct ieee80211com *,
199 				    enum ieee80211_state, int);
200 };
201 
202 #define	RAL_IS_RUNNING(_sc)	(((_sc)->sc_flags & RAL_FLAG_RUNNING) && \
203 	!((_sc)->sc_flags & RAL_FLAG_SUSPENDING))
204 #define	RAL_IS_INITED(_sc)	((_sc)->sc_flags & RAL_FLAG_RUNNING)
205 #define	RAL_LOCK(sc)		mutex_enter(&(sc)->sc_genlock)
206 #define	RAL_UNLOCK(sc)		mutex_exit(&(sc)->sc_genlock)
207 
208 #define	MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
209 #define	MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* _RT2560_VAR_H */
216