xref: /openbsd-src/sys/dev/pci/if_iwnvar.h (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: if_iwnvar.h,v 1.35 2019/07/29 10:50:08 stsp Exp $	*/
2 
3 /*-
4  * Copyright (c) 2007, 2008
5  *	Damien Bergamini <damien.bergamini@free.fr>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 struct iwn_rx_radiotap_header {
21 	struct ieee80211_radiotap_header wr_ihdr;
22 	uint64_t	wr_tsft;
23 	uint8_t		wr_flags;
24 	uint8_t		wr_rate;
25 	uint16_t	wr_chan_freq;
26 	uint16_t	wr_chan_flags;
27 	int8_t		wr_dbm_antsignal;
28 	int8_t		wr_dbm_antnoise;
29 } __packed;
30 
31 #define IWN_RX_RADIOTAP_PRESENT						\
32 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
33 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
34 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
35 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
36 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
37 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
38 
39 struct iwn_tx_radiotap_header {
40 	struct ieee80211_radiotap_header wt_ihdr;
41 	uint8_t		wt_flags;
42 	uint8_t		wt_rate;
43 	uint16_t	wt_chan_freq;
44 	uint16_t	wt_chan_flags;
45 	uint8_t		wt_hwqueue;
46 } __packed;
47 
48 #define IWN_TX_RADIOTAP_PRESENT						\
49 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
50 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
51 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
52 	 (1 << IEEE80211_RADIOTAP_HWQUEUE))
53 
54 struct iwn_dma_info {
55 	bus_dma_tag_t		tag;
56 	bus_dmamap_t		map;
57 	bus_dma_segment_t	seg;
58 	bus_addr_t		paddr;
59 	caddr_t			vaddr;
60 	bus_size_t		size;
61 };
62 
63 struct iwn_tx_data {
64 	bus_dmamap_t		map;
65 	bus_addr_t		cmd_paddr;
66 	bus_addr_t		scratch_paddr;
67 	struct mbuf		*m;
68 	struct ieee80211_node	*ni;
69 	int totlen;
70 };
71 
72 struct iwn_tx_ring {
73 	struct iwn_dma_info	desc_dma;
74 	struct iwn_dma_info	cmd_dma;
75 	struct iwn_tx_desc	*desc;
76 	struct iwn_tx_cmd	*cmd;
77 	struct iwn_tx_data	data[IWN_TX_RING_COUNT];
78 	int			qid;
79 	int			queued;
80 	int			cur;
81 	int			read;
82 };
83 
84 struct iwn_softc;
85 
86 struct iwn_rx_data {
87 	struct mbuf	*m;
88 	bus_dmamap_t	map;
89 };
90 
91 struct iwn_rx_ring {
92 	struct iwn_dma_info	desc_dma;
93 	struct iwn_dma_info	stat_dma;
94 	uint32_t		*desc;
95 	struct iwn_rx_status	*stat;
96 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
97 	int			cur;
98 };
99 
100 struct iwn_node {
101 	struct	ieee80211_node		ni;	/* must be the first */
102 	struct	ieee80211_amrr_node	amn;
103 	struct	ieee80211_mira_node	mn;
104 	uint16_t			disable_tid;
105 	uint8_t				id;
106 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
107 };
108 
109 struct iwn_calib_state {
110 	uint8_t		state;
111 #define IWN_CALIB_STATE_INIT	0
112 #define IWN_CALIB_STATE_ASSOC	1
113 #define IWN_CALIB_STATE_RUN	2
114 
115 	u_int		nbeacons;
116 	uint32_t	noise[3];
117 	uint32_t	rssi[3];
118 	uint32_t	ofdm_x1;
119 	uint32_t	ofdm_mrc_x1;
120 	uint32_t	ofdm_x4;
121 	uint32_t	ofdm_mrc_x4;
122 	uint32_t	cck_x4;
123 	uint32_t	cck_mrc_x4;
124 	uint32_t	bad_plcp_ofdm;
125 	uint32_t	fa_ofdm;
126 	uint32_t	bad_plcp_cck;
127 	uint32_t	fa_cck;
128 	uint32_t	low_fa;
129 	uint8_t		cck_state;
130 #define IWN_CCK_STATE_INIT	0
131 #define IWN_CCK_STATE_LOFA	1
132 #define IWN_CCK_STATE_HIFA	2
133 
134 	uint8_t		noise_samples[20];
135 	u_int		cur_noise_sample;
136 	uint8_t		noise_ref;
137 	uint32_t	energy_samples[10];
138 	u_int		cur_energy_sample;
139 	uint32_t	energy_cck;
140 };
141 
142 struct iwn_calib_info {
143 	uint8_t		*buf;
144 	u_int		len;
145 };
146 
147 struct iwn_fw_part {
148 	const uint8_t	*text;
149 	uint32_t	textsz;
150 	const uint8_t	*data;
151 	uint32_t	datasz;
152 };
153 
154 struct iwn_fw_info {
155 	u_char			*data;
156 	size_t			size;
157 	struct iwn_fw_part	init;
158 	struct iwn_fw_part	main;
159 	struct iwn_fw_part	boot;
160 };
161 
162 struct iwn_ops {
163 	int		(*load_firmware)(struct iwn_softc *);
164 	void		(*read_eeprom)(struct iwn_softc *);
165 	int		(*post_alive)(struct iwn_softc *);
166 	int		(*nic_config)(struct iwn_softc *);
167 	void		(*reset_sched)(struct iwn_softc *, int, int);
168 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
169 			    uint16_t);
170 	int		(*get_temperature)(struct iwn_softc *);
171 	int		(*get_rssi)(const struct iwn_rx_stat *);
172 	int		(*set_txpower)(struct iwn_softc *, int);
173 	int		(*init_gains)(struct iwn_softc *);
174 	int		(*set_gains)(struct iwn_softc *);
175 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
176 			    int);
177 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
178 			    struct iwn_rx_data *);
179 	void		(*ampdu_tx_start)(struct iwn_softc *,
180 			    struct ieee80211_node *, uint8_t, uint16_t);
181 	void		(*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
182 			    uint16_t);
183 };
184 
185 struct iwn_tx_ba {
186 	struct iwn_node *	wn;
187 };
188 
189 struct iwn_softc {
190 	struct device		sc_dev;
191 
192 	struct ieee80211com	sc_ic;
193 	int			(*sc_newstate)(struct ieee80211com *,
194 				    enum ieee80211_state, int);
195 
196 	struct ieee80211_amrr	amrr;
197 	uint8_t			fixed_ridx;
198 
199 	bus_dma_tag_t		sc_dmat;
200 
201 	struct rwlock		sc_rwlock;
202 	u_int			sc_flags;
203 #define IWN_FLAG_HAS_5GHZ	(1 << 0)
204 #define IWN_FLAG_HAS_OTPROM	(1 << 1)
205 #define IWN_FLAG_CALIB_DONE	(1 << 2)
206 #define IWN_FLAG_USE_ICT	(1 << 3)
207 #define IWN_FLAG_INTERNAL_PA	(1 << 4)
208 #define IWN_FLAG_HAS_11N	(1 << 6)
209 #define IWN_FLAG_ENH_SENS	(1 << 7)
210 #define IWN_FLAG_ADV_BT_COEX	(1 << 8)
211 #define IWN_FLAG_BGSCAN		(1 << 9)
212 #define IWN_FLAG_SCANNING	(1 << 10)
213 
214 	uint8_t 		hw_type;
215 
216 	struct iwn_ops		ops;
217 	const char		*fwname;
218 	const struct iwn_sensitivity_limits
219 				*limits;
220 	int			ntxqs;
221 	int			first_agg_txq;
222 	int			agg_queue_mask;
223 	int			ndmachnls;
224 	uint8_t			broadcast_id;
225 	int			rxonsz;
226 	int			schedsz;
227 	uint32_t		fw_text_maxsz;
228 	uint32_t		fw_data_maxsz;
229 	uint32_t		fwsz;
230 	bus_size_t		sched_txfact_addr;
231 
232 	/* TX scheduler rings. */
233 	struct iwn_dma_info	sched_dma;
234 	uint16_t		*sched;
235 	uint32_t		sched_base;
236 
237 	/* "Keep Warm" page. */
238 	struct iwn_dma_info	kw_dma;
239 
240 	/* Firmware DMA transfer. */
241 	struct iwn_dma_info	fw_dma;
242 
243 	/* ICT table. */
244 	struct iwn_dma_info	ict_dma;
245 	uint32_t		*ict;
246 	int			ict_cur;
247 
248 	/* TX/RX rings. */
249 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
250 	struct iwn_rx_ring	rxq;
251 
252 	bus_space_tag_t		sc_st;
253 	bus_space_handle_t	sc_sh;
254 	void 			*sc_ih;
255 	pci_chipset_tag_t	sc_pct;
256 	pcitag_t		sc_pcitag;
257 	bus_size_t		sc_sz;
258 	int			sc_cap_off;	/* PCIe Capabilities. */
259 
260 	struct timeout		calib_to;
261 	int			calib_cnt;
262 	struct iwn_calib_state	calib;
263 
264 	struct task		init_task;
265 
266 	struct iwn_fw_info	fw;
267 	struct iwn_calib_info	calibcmd[5];
268 	uint32_t		errptr;
269 
270 	uint8_t			bss_node_addr[IEEE80211_ADDR_LEN];
271 
272 	struct iwn_rx_stat	last_rx_stat;
273 	int			last_rx_valid;
274 #define IWN_LAST_RX_VALID	0x01
275 #define IWN_LAST_RX_AMPDU	0x02
276 	struct iwn_ucode_info	ucode_info;
277 	struct iwn_rxon		rxon;
278 	uint32_t		rawtemp;
279 	int			temp;
280 	int			noise;
281 	uint32_t		qfullmsk;
282 
283 	uint32_t		prom_base;
284 	struct iwn4965_eeprom_band
285 				bands[IWN_NBANDS];
286 	uint16_t		rfcfg;
287 	uint8_t			calib_ver;
288 	char			eeprom_domain[4];
289 	uint32_t		eeprom_crystal;
290 	int16_t			eeprom_temp;
291 	int16_t			eeprom_voltage;
292 	int16_t			eeprom_rawtemp;
293 	int8_t			maxpwr2GHz;
294 	int8_t			maxpwr5GHz;
295 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
296 	int8_t			enh_maxpwr[35];
297 
298 	uint8_t			reset_noise_gain;
299 	uint8_t			noise_gain;
300 
301 	uint32_t		tlv_feature_flags;
302 
303 	int32_t			temp_off;
304 	uint32_t		int_mask;
305 	uint8_t			ntxchains;
306 	uint8_t			nrxchains;
307 	uint8_t			txchainmask;
308 	uint8_t			rxchainmask;
309 	uint8_t			chainmask;
310 
311 	int			sc_tx_timer;
312 
313 	struct iwn_tx_ba	sc_tx_ba[IEEE80211_NUM_TID];
314 
315 #if NBPFILTER > 0
316 	caddr_t			sc_drvbpf;
317 
318 	union {
319 		struct iwn_rx_radiotap_header th;
320 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
321 	} sc_rxtapu;
322 #define sc_rxtap	sc_rxtapu.th
323 	int			sc_rxtap_len;
324 
325 	union {
326 		struct iwn_tx_radiotap_header th;
327 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
328 	} sc_txtapu;
329 #define sc_txtap	sc_txtapu.th
330 	int			sc_txtap_len;
331 #endif
332 };
333