xref: /titanic_50/usr/src/uts/common/io/wpi/wpivar.h (revision a60fc142342386d0b786e65fba901234400d7020)
1 /*
2  * Copyright 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifdef WPI_BPF
31 typedef struct wpi_rx_radiotap_header {
32 	struct ieee80211_radiotap_header wr_ihdr;
33 	uint64_t	wr_tsft;
34 	uint8_t		wr_flags;
35 	uint8_t		wr_rate;
36 	uint16_t	wr_chan_freq;
37 	uint16_t	wr_chan_flags;
38 	int8_t		wr_dbm_antsignal;
39 	int8_t		wr_dbm_antnoise;
40 	uint8_t		wr_antenna;
41 } wpi_rx_radiotap_header_t;
42 
43 #define	WPI_RX_RADIOTAP_PRESENT						\
44 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
45 	(1 << IEEE80211_RADIOTAP_FLAGS) |				\
46 	(1 << IEEE80211_RADIOTAP_RATE) |				\
47 	(1 << IEEE80211_RADIOTAP_CHANNEL) |				\
48 	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
49 	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
50 	(1 << IEEE80211_RADIOTAP_ANTENNA))
51 
52 typedef struct wpi_tx_radiotap_header {
53 	struct ieee80211_radiotap_header wt_ihdr;
54 	uint8_t		wt_flags;
55 	uint8_t		wt_rate;
56 	uint16_t	wt_chan_freq;
57 	uint16_t	wt_chan_flags;
58 } wpi_tx_radiotap_header_t;
59 
60 #define	WPI_TX_RADIOTAP_PRESENT						\
61 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
62 	(1 << IEEE80211_RADIOTAP_RATE) |				\
63 	(1 << IEEE80211_RADIOTAP_CHANNEL))
64 #endif
65 
66 #define	WPI_DMA_SYNC(area, flag) \
67 	(void) ddi_dma_sync((area).dma_hdl, (area).offset, \
68 	(area).alength, (flag))
69 
70 typedef struct wpi_dma_area {
71 	ddi_acc_handle_t	acc_hdl; /* handle for memory */
72 	caddr_t			mem_va; /* CPU VA of memory */
73 	uint32_t		nslots; /* number of slots */
74 	uint32_t		size;   /* size per slot */
75 	size_t			alength; /* allocated size */
76 					/* >= product of above */
77 	ddi_dma_handle_t	dma_hdl; /* DMA handle */
78 	offset_t		offset;  /* relative to handle */
79 	ddi_dma_cookie_t	cookie; /* associated cookie */
80 	uint32_t		ncookies;
81 	uint32_t		token; /* arbitrary identifier */
82 } wpi_dma_t;
83 
84 typedef struct wpi_tx_data {
85 	wpi_dma_t		dma_data;
86 	wpi_tx_desc_t		*desc;
87 	uint32_t		paddr_desc;
88 	wpi_tx_cmd_t		*cmd;
89 	uint32_t		paddr_cmd;
90 } wpi_tx_data_t;
91 
92 typedef struct wpi_tx_ring {
93 	wpi_dma_t		dma_desc;
94 	wpi_dma_t		dma_cmd;
95 	wpi_tx_data_t		*data;
96 	int			qid;
97 	int			count;
98 	int			queued;
99 	int			cur;
100 } wpi_tx_ring_t;
101 
102 typedef struct wpi_rx_data {
103 	wpi_dma_t		dma_data;
104 } wpi_rx_data_t;
105 
106 typedef struct wpi_rx_ring {
107 	wpi_dma_t		dma_desc;
108 	uint32_t 		*desc;
109 	wpi_rx_data_t		data[WPI_RX_RING_COUNT];
110 	int			cur;
111 } wpi_rx_ring_t;
112 
113 typedef struct wpi_amrr {
114 	ieee80211_node_t in;	/* must be the first */
115 	int	txcnt;
116 	int	retrycnt;
117 	int	success;
118 	int	success_threshold;
119 	int	recovery;
120 } wpi_amrr_t;
121 
122 typedef struct wpi_softc {
123 	struct ieee80211com	sc_ic;
124 	dev_info_t		*sc_dip;
125 	int			(*sc_newstate)(struct ieee80211com *,
126 				    enum ieee80211_state, int);
127 	enum ieee80211_state	sc_ostate;
128 	kmutex_t		sc_glock;
129 	kmutex_t		sc_mt_lock;
130 	kmutex_t		sc_tx_lock;
131 	kcondvar_t		sc_mt_cv;
132 	kcondvar_t		sc_tx_cv;
133 	kcondvar_t		sc_cmd_cv;
134 	kcondvar_t		sc_fw_cv;
135 
136 	kthread_t		*sc_mf_thread;
137 	uint32_t		sc_mf_thread_switch;
138 
139 	uint32_t		sc_flags;
140 	uint32_t		sc_dmabuf_sz;
141 	uint16_t		sc_clsz;
142 	uint8_t			sc_rev;
143 	uint8_t			sc_resv;
144 
145 	/* shared area */
146 	wpi_dma_t		sc_dma_sh;
147 	wpi_shared_t		*sc_shared;
148 
149 	wpi_tx_ring_t		sc_txq[4];
150 	wpi_tx_ring_t		sc_cmdq;
151 	wpi_tx_ring_t		sc_svcq;
152 	wpi_rx_ring_t		sc_rxq;
153 
154 	/* dma */
155 	const wpi_firmware_hdr_t *sc_hdr;
156 	const char		*sc_boot;
157 	const char		*sc_text;
158 	const char		*sc_data;
159 	wpi_dma_t		sc_dma_fw_text;
160 	ddi_dma_cookie_t	sc_fw_text_cookie[4];
161 	wpi_dma_t		sc_dma_fw_data;
162 	ddi_dma_cookie_t	sc_fw_data_cookie[4];
163 
164 	ddi_acc_handle_t	sc_handle;
165 	caddr_t			sc_base;
166 	ddi_iblock_cookie_t	sc_iblk;
167 
168 	wpi_config_t		sc_config;
169 	uint16_t		sc_pwr1[14];
170 	uint16_t		sc_pwr2[14];
171 
172 	uint32_t		sc_tx_timer;
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 #ifdef WPI_BPF
188 	struct bpf_if		*sc_drvbpf;
189 
190 	union {
191 		struct wpi_rx_radiotap_header th;
192 		uint8_t	pad[64];
193 	} sc_rxtapu;
194 #define	sc_rxtap	sc_rxtapu.th
195 	int			sc_rxtap_len;
196 
197 	union {
198 		struct wpi_tx_radiotap_header th;
199 		uint8_t	pad[64];
200 	} sc_txtapu;
201 #define	sc_txtap	sc_txtapu.th
202 	int			sc_txtap_len;
203 #endif
204 } wpi_sc_t;
205 
206 #define	WPI_F_ATTACHED		(1 << 0)
207 #define	WPI_F_CMD_DONE		(1 << 1)
208 #define	WPI_F_FW_INIT		(1 << 2)
209 #define	WPI_F_HW_ERR_RECOVER	(1 << 3)
210 #define	WPI_F_RATE_AUTO_CTL	(1 << 4)
211 #define	WPI_F_RUNNING		(1 << 5)
212 
213 #define	WPI_SUCCESS		0
214 #define	WPI_FAIL		1
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* _WPIVAR_H */
220