xref: /titanic_41/usr/src/uts/common/io/wpi/wpivar.h (revision c037192b037119c9fd354732fc29b38ce097d356)
1 /*
2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 /*
6  * Copyright (c) 2006
7  *	Damien Bergamini <damien.bergamini@free.fr>
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 #ifndef _WPIVAR_H
22 #define	_WPIVAR_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #ifdef WPI_BPF
29 typedef struct wpi_rx_radiotap_header {
30 	struct ieee80211_radiotap_header wr_ihdr;
31 	uint64_t	wr_tsft;
32 	uint8_t		wr_flags;
33 	uint8_t		wr_rate;
34 	uint16_t	wr_chan_freq;
35 	uint16_t	wr_chan_flags;
36 	int8_t		wr_dbm_antsignal;
37 	int8_t		wr_dbm_antnoise;
38 	uint8_t		wr_antenna;
39 } wpi_rx_radiotap_header_t;
40 
41 #define	WPI_RX_RADIOTAP_PRESENT						\
42 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
43 	(1 << IEEE80211_RADIOTAP_FLAGS) |				\
44 	(1 << IEEE80211_RADIOTAP_RATE) |				\
45 	(1 << IEEE80211_RADIOTAP_CHANNEL) |				\
46 	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
47 	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
48 	(1 << IEEE80211_RADIOTAP_ANTENNA))
49 
50 typedef struct wpi_tx_radiotap_header {
51 	struct ieee80211_radiotap_header wt_ihdr;
52 	uint8_t		wt_flags;
53 	uint8_t		wt_rate;
54 	uint16_t	wt_chan_freq;
55 	uint16_t	wt_chan_flags;
56 } wpi_tx_radiotap_header_t;
57 
58 #define	WPI_TX_RADIOTAP_PRESENT						\
59 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
60 	(1 << IEEE80211_RADIOTAP_RATE) |				\
61 	(1 << IEEE80211_RADIOTAP_CHANNEL))
62 #endif
63 
64 #define	WPI_DMA_SYNC(area, flag) \
65 	(void) ddi_dma_sync((area).dma_hdl, (area).offset, \
66 	(area).alength, (flag))
67 
68 #define	WPI_CHK_FAST_RECOVER(sc) \
69 	(sc->sc_ic.ic_state == IEEE80211_S_RUN && \
70 	sc->sc_ic.ic_opmode == IEEE80211_M_STA)
71 
72 typedef struct wpi_dma_area {
73 	ddi_acc_handle_t	acc_hdl; /* handle for memory */
74 	caddr_t			mem_va; /* CPU VA of memory */
75 	uint32_t		nslots; /* number of slots */
76 	uint32_t		size;   /* size per slot */
77 	size_t			alength; /* allocated size */
78 					/* >= product of above */
79 	ddi_dma_handle_t	dma_hdl; /* DMA handle */
80 	offset_t		offset;  /* relative to handle */
81 	ddi_dma_cookie_t	cookie; /* associated cookie */
82 	uint32_t		ncookies;
83 	uint32_t		token; /* arbitrary identifier */
84 } wpi_dma_t;
85 
86 typedef struct wpi_tx_data {
87 	wpi_dma_t		dma_data;
88 	wpi_tx_desc_t		*desc;
89 	uint32_t		paddr_desc;
90 	wpi_tx_cmd_t		*cmd;
91 	uint32_t		paddr_cmd;
92 } wpi_tx_data_t;
93 
94 typedef struct wpi_tx_ring {
95 	wpi_dma_t		dma_desc;
96 	wpi_dma_t		dma_cmd;
97 	wpi_tx_data_t		*data;
98 	int			qid;
99 	int			count;
100 	int			queued;
101 	int			cur;
102 } wpi_tx_ring_t;
103 
104 typedef struct wpi_rx_data {
105 	wpi_dma_t		dma_data;
106 } wpi_rx_data_t;
107 
108 typedef struct wpi_rx_ring {
109 	wpi_dma_t		dma_desc;
110 	uint32_t 		*desc;
111 	wpi_rx_data_t		data[WPI_RX_RING_COUNT];
112 	int			cur;
113 } wpi_rx_ring_t;
114 
115 typedef struct wpi_amrr {
116 	ieee80211_node_t in;	/* must be the first */
117 	int	txcnt;
118 	int	retrycnt;
119 	int	success;
120 	int	success_threshold;
121 	int	recovery;
122 } wpi_amrr_t;
123 
124 typedef struct wpi_softc {
125 	struct ieee80211com	sc_ic;
126 	dev_info_t		*sc_dip;
127 	int			(*sc_newstate)(struct ieee80211com *,
128 				    enum ieee80211_state, int);
129 	enum ieee80211_state	sc_ostate;
130 	kmutex_t		sc_glock;
131 	kmutex_t		sc_mt_lock;
132 	kmutex_t		sc_tx_lock;
133 	kcondvar_t		sc_mt_cv;
134 	kcondvar_t		sc_tx_cv;
135 	kcondvar_t		sc_cmd_cv;
136 	kcondvar_t		sc_fw_cv;
137 
138 	kthread_t		*sc_mf_thread;
139 	uint32_t		sc_mf_thread_switch;
140 
141 	uint32_t		sc_flags;
142 	uint32_t		sc_dmabuf_sz;
143 	uint16_t		sc_clsz;
144 	uint8_t			sc_rev;
145 	uint8_t			sc_resv;
146 
147 	/* shared area */
148 	wpi_dma_t		sc_dma_sh;
149 	wpi_shared_t		*sc_shared;
150 
151 	wpi_tx_ring_t		sc_txq[4];
152 	wpi_tx_ring_t		sc_cmdq;
153 	wpi_tx_ring_t		sc_svcq;
154 	wpi_rx_ring_t		sc_rxq;
155 
156 	/* dma */
157 	const wpi_firmware_hdr_t *sc_hdr;
158 	const char		*sc_boot;
159 	const char		*sc_text;
160 	const char		*sc_data;
161 	wpi_dma_t		sc_dma_fw_text;
162 	ddi_dma_cookie_t	sc_fw_text_cookie[4];
163 	wpi_dma_t		sc_dma_fw_data;
164 	ddi_dma_cookie_t	sc_fw_data_cookie[4];
165 
166 	ddi_acc_handle_t	sc_handle;
167 	caddr_t			sc_base;
168 	ddi_iblock_cookie_t	sc_iblk;
169 
170 	wpi_config_t		sc_config;
171 	wpi_config_t		sc_config_save;
172 
173 	uint16_t		sc_pwr1[14];
174 	uint16_t		sc_pwr2[14];
175 
176 	uint32_t		sc_tx_timer;
177 	uint32_t		sc_scan_next;
178 	uint32_t		sc_scan_pending;
179 	uint8_t			*sc_fw_bin;
180 
181 	ddi_softintr_t		sc_notif_softint_id;
182 	uint32_t		sc_notif_softint_pending;
183 	uint32_t		sc_need_reschedule;
184 
185 	clock_t			sc_clk;
186 
187 	/* kstats */
188 	uint32_t		sc_tx_nobuf;
189 	uint32_t		sc_rx_nobuf;
190 	uint32_t		sc_tx_err;
191 	uint32_t		sc_rx_err;
192 	uint32_t		sc_tx_retries;
193 
194 #ifdef WPI_BPF
195 	struct bpf_if		*sc_drvbpf;
196 
197 	union {
198 		struct wpi_rx_radiotap_header th;
199 		uint8_t	pad[64];
200 	} sc_rxtapu;
201 #define	sc_rxtap	sc_rxtapu.th
202 	int			sc_rxtap_len;
203 
204 	union {
205 		struct wpi_tx_radiotap_header th;
206 		uint8_t	pad[64];
207 	} sc_txtapu;
208 #define	sc_txtap	sc_txtapu.th
209 	int			sc_txtap_len;
210 #endif
211 } wpi_sc_t;
212 
213 #define	WPI_F_ATTACHED		(1 << 0)
214 #define	WPI_F_CMD_DONE		(1 << 1)
215 #define	WPI_F_FW_INIT		(1 << 2)
216 #define	WPI_F_HW_ERR_RECOVER	(1 << 3)
217 #define	WPI_F_RATE_AUTO_CTL	(1 << 4)
218 #define	WPI_F_RUNNING		(1 << 5)
219 #define	WPI_F_SUSPEND		(1 << 6)
220 #define	WPI_F_RADIO_OFF		(1 << 7)
221 #define	WPI_F_SCANNING		(1 << 8)
222 #define	WPI_F_QUIESCED		(1 << 9)
223 #define	WPI_F_LAZY_RESUME	(1 << 10)
224 
225 #define	WPI_SUCCESS		0
226 #define	WPI_FAIL		(EIO)
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif /* _WPIVAR_H */
232