xref: /illumos-gate/usr/src/uts/common/io/wpi/wpivar.h (revision 50981ffc7e4c5048d14890df805afee6ec113991)
1 /*
2  * Copyright 2008 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 typedef struct wpi_dma_area {
69 	ddi_acc_handle_t	acc_hdl; /* handle for memory */
70 	caddr_t			mem_va; /* CPU VA of memory */
71 	uint32_t		nslots; /* number of slots */
72 	uint32_t		size;   /* size per slot */
73 	size_t			alength; /* allocated size */
74 					/* >= product of above */
75 	ddi_dma_handle_t	dma_hdl; /* DMA handle */
76 	offset_t		offset;  /* relative to handle */
77 	ddi_dma_cookie_t	cookie; /* associated cookie */
78 	uint32_t		ncookies;
79 	uint32_t		token; /* arbitrary identifier */
80 } wpi_dma_t;
81 
82 typedef struct wpi_tx_data {
83 	wpi_dma_t		dma_data;
84 	wpi_tx_desc_t		*desc;
85 	uint32_t		paddr_desc;
86 	wpi_tx_cmd_t		*cmd;
87 	uint32_t		paddr_cmd;
88 } wpi_tx_data_t;
89 
90 typedef struct wpi_tx_ring {
91 	wpi_dma_t		dma_desc;
92 	wpi_dma_t		dma_cmd;
93 	wpi_tx_data_t		*data;
94 	int			qid;
95 	int			count;
96 	int			queued;
97 	int			cur;
98 } wpi_tx_ring_t;
99 
100 typedef struct wpi_rx_data {
101 	wpi_dma_t		dma_data;
102 } wpi_rx_data_t;
103 
104 typedef struct wpi_rx_ring {
105 	wpi_dma_t		dma_desc;
106 	uint32_t 		*desc;
107 	wpi_rx_data_t		data[WPI_RX_RING_COUNT];
108 	int			cur;
109 } wpi_rx_ring_t;
110 
111 typedef struct wpi_amrr {
112 	ieee80211_node_t in;	/* must be the first */
113 	int	txcnt;
114 	int	retrycnt;
115 	int	success;
116 	int	success_threshold;
117 	int	recovery;
118 } wpi_amrr_t;
119 
120 typedef struct wpi_softc {
121 	struct ieee80211com	sc_ic;
122 	dev_info_t		*sc_dip;
123 	int			(*sc_newstate)(struct ieee80211com *,
124 				    enum ieee80211_state, int);
125 	enum ieee80211_state	sc_ostate;
126 	kmutex_t		sc_glock;
127 	kmutex_t		sc_mt_lock;
128 	kmutex_t		sc_tx_lock;
129 	kcondvar_t		sc_mt_cv;
130 	kcondvar_t		sc_tx_cv;
131 	kcondvar_t		sc_cmd_cv;
132 	kcondvar_t		sc_fw_cv;
133 
134 	kthread_t		*sc_mf_thread;
135 	uint32_t		sc_mf_thread_switch;
136 
137 	uint32_t		sc_flags;
138 	uint32_t		sc_dmabuf_sz;
139 	uint16_t		sc_clsz;
140 	uint8_t			sc_rev;
141 	uint8_t			sc_resv;
142 
143 	/* shared area */
144 	wpi_dma_t		sc_dma_sh;
145 	wpi_shared_t		*sc_shared;
146 
147 	wpi_tx_ring_t		sc_txq[4];
148 	wpi_tx_ring_t		sc_cmdq;
149 	wpi_tx_ring_t		sc_svcq;
150 	wpi_rx_ring_t		sc_rxq;
151 
152 	/* dma */
153 	const wpi_firmware_hdr_t *sc_hdr;
154 	const char		*sc_boot;
155 	const char		*sc_text;
156 	const char		*sc_data;
157 	wpi_dma_t		sc_dma_fw_text;
158 	ddi_dma_cookie_t	sc_fw_text_cookie[4];
159 	wpi_dma_t		sc_dma_fw_data;
160 	ddi_dma_cookie_t	sc_fw_data_cookie[4];
161 
162 	ddi_acc_handle_t	sc_handle;
163 	caddr_t			sc_base;
164 	ddi_iblock_cookie_t	sc_iblk;
165 
166 	wpi_config_t		sc_config;
167 	uint16_t		sc_pwr1[14];
168 	uint16_t		sc_pwr2[14];
169 
170 	uint32_t		sc_tx_timer;
171 	uint32_t		sc_scan_next;
172 	uint32_t		sc_scan_pending;
173 	uint8_t			*sc_fw_bin;
174 
175 	ddi_softintr_t		sc_notif_softint_id;
176 	uint32_t		sc_notif_softint_pending;
177 	uint32_t		sc_need_reschedule;
178 
179 	clock_t			sc_clk;
180 
181 	/* kstats */
182 	uint32_t		sc_tx_nobuf;
183 	uint32_t		sc_rx_nobuf;
184 	uint32_t		sc_tx_err;
185 	uint32_t		sc_rx_err;
186 	uint32_t		sc_tx_retries;
187 
188 #ifdef WPI_BPF
189 	struct bpf_if		*sc_drvbpf;
190 
191 	union {
192 		struct wpi_rx_radiotap_header th;
193 		uint8_t	pad[64];
194 	} sc_rxtapu;
195 #define	sc_rxtap	sc_rxtapu.th
196 	int			sc_rxtap_len;
197 
198 	union {
199 		struct wpi_tx_radiotap_header th;
200 		uint8_t	pad[64];
201 	} sc_txtapu;
202 #define	sc_txtap	sc_txtapu.th
203 	int			sc_txtap_len;
204 #endif
205 } wpi_sc_t;
206 
207 #define	WPI_F_ATTACHED		(1 << 0)
208 #define	WPI_F_CMD_DONE		(1 << 1)
209 #define	WPI_F_FW_INIT		(1 << 2)
210 #define	WPI_F_HW_ERR_RECOVER	(1 << 3)
211 #define	WPI_F_RATE_AUTO_CTL	(1 << 4)
212 #define	WPI_F_RUNNING		(1 << 5)
213 #define	WPI_F_SUSPEND		(1 << 6)
214 #define	WPI_F_RADIO_OFF		(1 << 7)
215 #define	WPI_F_SCANNING		(1 << 8)
216 #define	WPI_F_QUIESCED		(1 << 9)
217 #define	WPI_F_LAZY_RESUME	(1 << 10)
218 
219 #define	WPI_SUCCESS		0
220 #define	WPI_FAIL		(EIO)
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #endif /* _WPIVAR_H */
226