xref: /freebsd/sys/dev/rtwn/if_rtwnvar.h (revision 006920b63c03528bae5abd273d57c8af63bdf68a)
1 /*-
2  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
3  * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
18  */
19 
20 #ifndef IF_RTWNVAR_H
21 #define IF_RTWNVAR_H
22 
23 #include "opt_rtwn.h"
24 
25 #define RTWN_TX_DESC_SIZE	64
26 
27 #define RTWN_BCN_MAX_SIZE	512
28 #define RTWN_CAM_ENTRY_LIMIT	64
29 
30 #define RTWN_MACID_BC		1	/* Broadcast. */
31 #define RTWN_MACID_UNDEFINED	0x7fff
32 #define RTWN_MACID_VALID 	0x8000
33 #define RTWN_MACID_LIMIT	128
34 
35 #define RTWN_TX_TIMEOUT		1000	/* ms */
36 #define RTWN_MAX_EPOUT		4
37 #define RTWN_PORT_COUNT		2
38 
39 #define RTWN_LED_LINK		0
40 #define RTWN_LED_DATA		1
41 
42 struct rtwn_rx_radiotap_header {
43 	struct ieee80211_radiotap_header wr_ihdr;
44 	uint64_t	wr_tsft;
45 	uint8_t		wr_flags;
46 	uint8_t		wr_rate;
47 	uint16_t	wr_chan_freq;
48 	uint16_t	wr_chan_flags;
49 	int8_t		wr_dbm_antsignal;
50 	int8_t		wr_dbm_antnoise;
51 } __packed __aligned(8);
52 
53 #define RTWN_RX_RADIOTAP_PRESENT			\
54 	(1 << IEEE80211_RADIOTAP_TSFT |			\
55 	 1 << IEEE80211_RADIOTAP_FLAGS |		\
56 	 1 << IEEE80211_RADIOTAP_RATE |			\
57 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
58 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
59 	 1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)
60 
61 struct rtwn_tx_radiotap_header {
62 	struct ieee80211_radiotap_header wt_ihdr;
63 	uint8_t		wt_flags;
64 	uint8_t		wt_pad;
65 	uint16_t	wt_chan_freq;
66 	uint16_t	wt_chan_flags;
67 } __packed;
68 
69 #define RTWN_TX_RADIOTAP_PRESENT			\
70 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
71 	 1 << IEEE80211_RADIOTAP_CHANNEL)
72 
73 struct rtwn_tx_buf {
74 	uint8_t		txd[RTWN_TX_DESC_SIZE];
75 } __attribute__((aligned(4)));
76 
77 #define RTWN_PHY_STATUS_SIZE	32
78 struct rtwn_tx_phystat {
79 	uint32_t	phydw[RTWN_PHY_STATUS_SIZE / sizeof(uint32_t)];
80 };
81 
82 struct rtwn_softc;
83 
84 union sec_param {
85 	struct ieee80211_key	key;
86 	int			macid;
87 };
88 
89 #define CMD_FUNC_PROTO		void (*func)(struct rtwn_softc *, \
90 				    union sec_param *)
91 
92 struct rtwn_cmdq {
93 	union sec_param		data;
94 	CMD_FUNC_PROTO;
95 };
96 #define RTWN_CMDQ_SIZE		16
97 
98 struct rtwn_node {
99 	struct ieee80211_node	ni;	/* must be the first */
100 	int			id;
101 
102 	struct rtwn_tx_phystat	last_physt;
103 	int			avg_pwdb;
104 };
105 #define RTWN_NODE(ni)		((struct rtwn_node *)(ni))
106 
107 struct rtwn_vap {
108 	struct ieee80211vap	vap;
109 	int			id;
110 #define RTWN_VAP_ID_INVALID	-1
111 	int			curr_mode;
112 
113 	struct rtwn_tx_buf	bcn_desc;
114 	struct mbuf		*bcn_mbuf;
115 	struct timeout_task	tx_beacon_csa;
116 
117 	struct callout		tsf_sync_adhoc;
118 	struct task		tsf_sync_adhoc_task;
119 
120 	const struct ieee80211_key	*keys[IEEE80211_WEP_NKID];
121 
122 	int			(*newstate)(struct ieee80211vap *,
123 				    enum ieee80211_state, int);
124 	void			(*recv_mgmt)(struct ieee80211_node *,
125 				    struct mbuf *, int,
126 				    const struct ieee80211_rx_stats *,
127 				    int, int);
128 };
129 #define	RTWN_VAP(vap)		((struct rtwn_vap *)(vap))
130 
131 /*
132  * Rx data types.
133  */
134 enum {
135 	RTWN_RX_DATA,
136 	RTWN_RX_TX_REPORT,	/* Per-packet */
137 	RTWN_RX_TX_REPORT2,	/* Per-MACID summary */
138 	RTWN_RX_OTHER
139 };
140 
141 /*
142  * Firmware reset reasons.
143  */
144 enum {
145 	RTWN_FW_RESET_DOWNLOAD,
146 	RTWN_FW_RESET_CHECKSUM,
147 	RTWN_FW_RESET_SHUTDOWN
148 };
149 
150 /*
151  * Rate control algorithm selection.
152  */
153 enum {
154 	RTWN_RATECTL_NONE,
155 	RTWN_RATECTL_NET80211,
156 	RTWN_RATECTL_FW,
157 	RTWN_RATECTL_MAX
158 };
159 
160 /*
161  * Control h/w crypto usage.
162  */
163 enum {
164 	RTWN_CRYPTO_SW,
165 	RTWN_CRYPTO_PAIR,
166 	RTWN_CRYPTO_FULL,
167 	RTWN_CRYPTO_MAX,
168 };
169 
170 struct rtwn_softc {
171 	struct ieee80211com	sc_ic;
172 	struct mbufq		sc_snd;
173 	device_t		sc_dev;
174 
175 	int			sc_ht40;
176 	int			sc_ena_tsf64;
177 	uint32_t		sc_debug;
178 	int			sc_hwcrypto;
179 	int			sc_ratectl_sysctl;
180 	int			sc_ratectl;
181 	uint32_t		sc_reg_addr;
182 
183 	uint8_t			sc_detached;
184 	uint8_t			sc_flags;
185 /* Device flags */
186 #define RTWN_FLAG_CCK_HIPWR	0x01
187 #define RTWN_FLAG_EXT_HDR	0x02
188 #define RTWN_FLAG_CAM_FIXED	0x04
189 /* Driver state */
190 #define RTWN_STARTED		0x08
191 #define RTWN_RUNNING		0x10
192 #define RTWN_FW_LOADED		0x20
193 #define RTWN_TEMP_MEASURED	0x40
194 #define RTWN_RCR_LOCKED		0x80
195 
196 #define RTWN_CHIP_HAS_BCNQ1(_sc)	\
197 	((_sc)->bcn_status_reg[0] != (_sc)->bcn_status_reg[1])
198 
199 	void			*sc_priv;
200 	const char		*name;
201 	int			sc_ant;
202 
203 	struct rtwn_tx_phystat	last_physt;
204 	uint8_t			thcal_temp;
205 	int			cur_bcnq_id;
206 
207 	int			nvaps;
208 	int			ap_vaps;
209 	int			bcn_vaps;
210 	int			mon_vaps;
211 
212 	int			vaps_running;
213 	int			monvaps_running;
214 
215 	uint16_t		next_rom_addr;
216 	uint8_t			keys_bmap[howmany(RTWN_CAM_ENTRY_LIMIT, NBBY)];
217 
218 	struct rtwn_vap		*vaps[RTWN_PORT_COUNT];
219 	struct ieee80211_node	*node_list[RTWN_MACID_LIMIT];
220 	struct mtx		nt_mtx;
221 
222 	struct callout		sc_calib_to;
223 	struct callout		sc_pwrmode_init;
224 #ifndef D4054
225 	struct callout		sc_watchdog_to;
226 	int			sc_tx_timer;
227 #endif
228 
229 	struct mtx		sc_mtx;
230 
231 	struct rtwn_cmdq	cmdq[RTWN_CMDQ_SIZE];
232 	struct mtx		cmdq_mtx;
233 	struct task		cmdq_task;
234 	uint8_t			cmdq_first;
235 	uint8_t			cmdq_last;
236 
237 	struct wmeParams	cap_wmeParams[WME_NUM_AC];
238 
239 	struct rtwn_rx_radiotap_header	sc_rxtap;
240 	struct rtwn_tx_radiotap_header	sc_txtap;
241 
242 	int			ntxchains;
243 	int			nrxchains;
244 
245 	int			ledlink;
246 	uint8_t			thermal_meter;
247 
248 	int			sc_tx_n_active;
249 	uint8_t			qfullmsk;
250 
251 	/* Firmware-specific */
252 	const char		*fwname;
253 	uint16_t		fwver;
254 	uint16_t		fwsig;
255 	int			fwcur;
256 
257 	void		(*sc_node_free)(struct ieee80211_node *);
258 	void		(*sc_scan_curchan)(struct ieee80211_scan_state *,
259 			    unsigned long);
260 
261 	/* Interface-specific. */
262 	int		(*sc_write_1)(struct rtwn_softc *, uint16_t,
263 			    uint8_t);
264 	int		(*sc_write_2)(struct rtwn_softc *, uint16_t,
265 			    uint16_t);
266 	int		(*sc_write_4)(struct rtwn_softc *, uint16_t,
267 			    uint32_t);
268 	uint8_t		(*sc_read_1)(struct rtwn_softc *, uint16_t);
269 	uint16_t	(*sc_read_2)(struct rtwn_softc *, uint16_t);
270 	uint32_t	(*sc_read_4)(struct rtwn_softc *, uint16_t);
271 	/* XXX eliminate */
272 	void		(*sc_delay)(struct rtwn_softc *, int);
273 	int		(*sc_tx_start)(struct rtwn_softc *,
274 			    struct ieee80211_node *, struct mbuf *, uint8_t *,
275 			    uint8_t, int);
276 	void		(*sc_start_xfers)(struct rtwn_softc *);
277 	void		(*sc_reset_lists)(struct rtwn_softc *,
278 			    struct ieee80211vap *);
279 	void		(*sc_abort_xfers)(struct rtwn_softc *);
280 	int		(*sc_fw_write_block)(struct rtwn_softc *,
281 			    const uint8_t *, uint16_t, int);
282 	uint16_t	(*sc_get_qmap)(struct rtwn_softc *);
283 	void		(*sc_set_desc_addr)(struct rtwn_softc *);
284 	void		(*sc_drop_incorrect_tx)(struct rtwn_softc *);
285 	void		(*sc_beacon_update_begin)(struct rtwn_softc *,
286 			    struct ieee80211vap *);
287 	void		(*sc_beacon_update_end)(struct rtwn_softc *,
288 			    struct ieee80211vap *);
289 	void		(*sc_beacon_unload)(struct rtwn_softc *, int);
290 
291 	/* XXX drop checks for PCIe? */
292 	int		bcn_check_interval;
293 
294 	/* Device-specific. */
295 	uint32_t	(*sc_rf_read)(struct rtwn_softc *, int, uint8_t);
296 	void		(*sc_rf_write)(struct rtwn_softc *, int, uint8_t,
297 			    uint32_t);
298 	int		(*sc_check_condition)(struct rtwn_softc *,
299 			    const uint8_t[]);
300 	void		(*sc_efuse_postread)(struct rtwn_softc *);
301 	int		(*sc_efuse_preread)(struct rtwn_softc *);
302 	void		(*sc_parse_rom)(struct rtwn_softc *, uint8_t *);
303 	void		(*sc_set_led)(struct rtwn_softc *, int, int);
304 	int		(*sc_power_on)(struct rtwn_softc *);
305 	void		(*sc_power_off)(struct rtwn_softc *);
306 #ifndef RTWN_WITHOUT_UCODE
307 	void		(*sc_fw_reset)(struct rtwn_softc *, int);
308 	void		(*sc_fw_download_enable)(struct rtwn_softc *, int);
309 #endif
310 	int		(*sc_llt_init)(struct rtwn_softc *);
311 	int		(*sc_set_page_size)(struct rtwn_softc *);
312 	void		(*sc_lc_calib)(struct rtwn_softc *);
313 	void		(*sc_iq_calib)(struct rtwn_softc *);
314 	void		(*sc_read_chipid_vendor)(struct rtwn_softc *,
315 			    uint32_t);
316 	void		(*sc_adj_devcaps)(struct rtwn_softc *);
317 	void		(*sc_vap_preattach)(struct rtwn_softc *,
318 			    struct ieee80211vap *);
319 	void		(*sc_postattach)(struct rtwn_softc *);
320 	void		(*sc_detach_private)(struct rtwn_softc *);
321 	void		(*sc_fill_tx_desc)(struct rtwn_softc *,
322 			    struct ieee80211_node *, struct mbuf *,
323 			    void *, uint8_t, bool, int);
324 	void		(*sc_fill_tx_desc_raw)(struct rtwn_softc *,
325 			    struct ieee80211_node *, struct mbuf *,
326 			    void *, const struct ieee80211_bpf_params *);
327 	void		(*sc_fill_tx_desc_null)(struct rtwn_softc *,
328 			    void *, int, int, int);
329 	void		(*sc_dump_tx_desc)(struct rtwn_softc *, const void *);
330 	uint8_t		(*sc_tx_radiotap_flags)(const void *);
331 	uint8_t		(*sc_rx_radiotap_flags)(const void *);
332 	void		(*sc_beacon_init)(struct rtwn_softc *, void *, int);
333 	void		(*sc_beacon_enable)(struct rtwn_softc *, int, int);
334 	void		(*sc_sta_beacon_enable)(struct rtwn_softc *, int,
335 			    bool);
336 	void		(*sc_beacon_set_rate)(void *, int);
337 	void		(*sc_beacon_select)(struct rtwn_softc *, int);
338 	void		(*sc_set_chan)(struct rtwn_softc *,
339 			    struct ieee80211_channel *);
340 	void		(*sc_set_media_status)(struct rtwn_softc *, int);
341 #ifndef RTWN_WITHOUT_UCODE
342 	int		(*sc_set_rsvd_page)(struct rtwn_softc *, int, int,
343 			    int);
344 	int		(*sc_set_pwrmode)(struct rtwn_softc *,
345 			    struct ieee80211vap *, int);
346 	void		(*sc_set_rssi)(struct rtwn_softc *);
347 #endif
348 	void		(*sc_get_rx_stats)(struct rtwn_softc *,
349 			    struct ieee80211_rx_stats *, const void *,
350 			    const void *);
351 	int8_t		(*sc_get_rssi_cck)(struct rtwn_softc *, void *);
352 	int8_t		(*sc_get_rssi_ofdm)(struct rtwn_softc *, void *);
353 	int		(*sc_classify_intr)(struct rtwn_softc *, void *, int);
354 	void		(*sc_handle_tx_report)(struct rtwn_softc *, uint8_t *,
355 			    int);
356 	void		(*sc_handle_tx_report2)(struct rtwn_softc *, uint8_t *,
357 			    int);
358 	void		(*sc_handle_c2h_report)(struct rtwn_softc *,
359 			    uint8_t *, int);
360 	int		(*sc_check_frame)(struct rtwn_softc *, struct mbuf *);
361 	void		(*sc_temp_measure)(struct rtwn_softc *);
362 	uint8_t		(*sc_temp_read)(struct rtwn_softc *);
363 	void		(*sc_init_tx_agg)(struct rtwn_softc *);
364 	void		(*sc_init_rx_agg)(struct rtwn_softc *);
365 	void		(*sc_init_intr)(struct rtwn_softc *);
366 	void		(*sc_init_ampdu)(struct rtwn_softc *);
367 	void		(*sc_init_edca)(struct rtwn_softc *);
368 	void		(*sc_init_bb)(struct rtwn_softc *);
369 	void		(*sc_init_rf)(struct rtwn_softc *);
370 	void		(*sc_init_antsel)(struct rtwn_softc *);
371 	void		(*sc_post_init)(struct rtwn_softc *);
372 	int		(*sc_init_bcnq1_boundary)(struct rtwn_softc *);
373 	int		(*sc_set_tx_power)(struct rtwn_softc *,
374 			    struct ieee80211vap *);
375 
376 	const uint8_t			*chan_list_5ghz[3];
377 	int				chan_num_5ghz[3];
378 
379 	const struct rtwn_mac_prog	*mac_prog;
380 	int				mac_size;
381 	const struct rtwn_bb_prog	*bb_prog;
382 	int				bb_size;
383 	const struct rtwn_agc_prog	*agc_prog;
384 	int				agc_size;
385 	const struct rtwn_rf_prog	*rf_prog;
386 
387 	int				page_count;
388 	int				pktbuf_count;
389 
390 	int				ackto;
391 
392 	int				npubqpages;
393 	int				nhqpages;
394 	int				nnqpages;
395 	int				nlqpages;
396 	int				page_size;
397 
398 	int				txdesc_len;
399 	int				efuse_maxlen;
400 	int				efuse_maplen;
401 
402 	uint16_t			rx_dma_size;
403 
404 	int				macid_limit;
405 	int				macid_rpt2_max_num;
406 	int				cam_entry_limit;
407 	int				fwsize_limit;
408 	int				temp_delta;
409 
410 	uint16_t			bcn_status_reg[RTWN_PORT_COUNT];
411 	uint32_t			rcr;	/* Rx filter */
412 };
413 MALLOC_DECLARE(M_RTWN_PRIV);
414 
415 #define	RTWN_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
416 #define	RTWN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
417 #define	RTWN_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
418 
419 #define RTWN_CMDQ_LOCK_INIT(sc) \
420 	mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
421 #define RTWN_CMDQ_LOCK(sc)		mtx_lock(&(sc)->cmdq_mtx)
422 #define RTWN_CMDQ_UNLOCK(sc)		mtx_unlock(&(sc)->cmdq_mtx)
423 #define RTWN_CMDQ_LOCK_INITIALIZED(sc)	mtx_initialized(&(sc)->cmdq_mtx)
424 #define RTWN_CMDQ_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->cmdq_mtx)
425 
426 #define RTWN_NT_LOCK_INIT(sc) \
427 	mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
428 #define RTWN_NT_LOCK(sc)		mtx_lock(&(sc)->nt_mtx)
429 #define RTWN_NT_UNLOCK(sc)		mtx_unlock(&(sc)->nt_mtx)
430 #define RTWN_NT_LOCK_INITIALIZED(sc)	mtx_initialized(&(sc)->nt_mtx)
431 #define RTWN_NT_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->nt_mtx)
432 
433 void	rtwn_sysctlattach(struct rtwn_softc *);
434 
435 int	rtwn_attach(struct rtwn_softc *);
436 void	rtwn_detach(struct rtwn_softc *);
437 void	rtwn_resume(struct rtwn_softc *);
438 void	rtwn_suspend(struct rtwn_softc *);
439 
440 void	rtwn_attach_vht_cap_info_mcs(struct rtwn_softc *);
441 
442 /* Interface-specific. */
443 #define rtwn_write_1(_sc, _addr, _val) \
444 	(((_sc)->sc_write_1)((_sc), (_addr), (_val)))
445 #define rtwn_write_2(_sc, _addr, _val) \
446 	(((_sc)->sc_write_2)((_sc), (_addr), (_val)))
447 #define rtwn_write_4(_sc, _addr, _val) \
448 	(((_sc)->sc_write_4)((_sc), (_addr), (_val)))
449 #define rtwn_read_1(_sc, _addr) \
450 	(((_sc)->sc_read_1)((_sc), (_addr)))
451 #define rtwn_read_2(_sc, _addr) \
452 	(((_sc)->sc_read_2)((_sc), (_addr)))
453 #define rtwn_read_4(_sc, _addr) \
454 	(((_sc)->sc_read_4)((_sc), (_addr)))
455 #define rtwn_delay(_sc, _usec) \
456 	(((_sc)->sc_delay)((_sc), (_usec)))
457 #define rtwn_tx_start(_sc, _ni, _m, _desc, _type, _id) \
458 	(((_sc)->sc_tx_start)((_sc), (_ni), (_m), (_desc), (_type), (_id)))
459 #define rtwn_start_xfers(_sc) \
460 	(((_sc)->sc_start_xfers)((_sc)))
461 #define rtwn_reset_lists(_sc, _vap) \
462 	(((_sc)->sc_reset_lists)((_sc), (_vap)))
463 #define rtwn_abort_xfers(_sc) \
464 	(((_sc)->sc_abort_xfers)((_sc)))
465 #define rtwn_fw_write_block(_sc, _buf, _reg, _len) \
466 	(((_sc)->sc_fw_write_block)((_sc), (_buf), (_reg), (_len)))
467 #define rtwn_get_qmap(_sc) \
468 	(((_sc)->sc_get_qmap)((_sc)))
469 #define rtwn_set_desc_addr(_sc) \
470 	(((_sc)->sc_set_desc_addr)((_sc)))
471 #define rtwn_drop_incorrect_tx(_sc) \
472 	(((_sc)->sc_drop_incorrect_tx)((_sc)))
473 #define rtwn_beacon_update_begin(_sc, _vap) \
474 	(((_sc)->sc_beacon_update_begin)((_sc), (_vap)))
475 #define rtwn_beacon_update_end(_sc, _vap) \
476 	(((_sc)->sc_beacon_update_end)((_sc), (_vap)))
477 #define rtwn_beacon_unload(_sc, _id) \
478 	(((_sc)->sc_beacon_unload)((_sc), (_id)))
479 
480 /* Aliases. */
481 #define	rtwn_bb_write		rtwn_write_4
482 #define	rtwn_bb_read		rtwn_read_4
483 #define	rtwn_bb_setbits		rtwn_setbits_4
484 
485 /* Device-specific. */
486 #define rtwn_rf_read(_sc, _chain, _addr) \
487 	(((_sc)->sc_rf_read)((_sc), (_chain), (_addr)))
488 #define rtwn_rf_write(_sc, _chain, _addr, _val) \
489 	(((_sc)->sc_rf_write)((_sc), (_chain), (_addr), (_val)))
490 #define rtwn_check_condition(_sc, _cond) \
491 	(((_sc)->sc_check_condition)((_sc), (_cond)))
492 #define rtwn_efuse_postread(_sc) \
493 	(((_sc)->sc_efuse_postread)((_sc)))
494 #define rtwn_efuse_preread(_sc) \
495 	(((_sc)->sc_efuse_preread)((_sc)))
496 #define rtwn_parse_rom(_sc, _rom) \
497 	(((_sc)->sc_parse_rom)((_sc), (_rom)))
498 #define rtwn_set_led(_sc, _led, _on) \
499 	(((_sc)->sc_set_led)((_sc), (_led), (_on)))
500 #define rtwn_get_rx_stats(_sc, _rxs, _desc, _physt) \
501 	(((_sc)->sc_get_rx_stats((_sc), (_rxs), (_desc), (_physt))))
502 #define rtwn_get_rssi_cck(_sc, _physt) \
503 	(((_sc)->sc_get_rssi_cck)((_sc), (_physt)))
504 #define rtwn_get_rssi_ofdm(_sc, _physt) \
505 	(((_sc)->sc_get_rssi_ofdm)((_sc), (_physt)))
506 #define rtwn_power_on(_sc) \
507 	(((_sc)->sc_power_on)((_sc)))
508 #define rtwn_power_off(_sc) \
509 	(((_sc)->sc_power_off)((_sc)))
510 #ifndef RTWN_WITHOUT_UCODE
511 #define rtwn_fw_reset(_sc, _reason) \
512 	(((_sc)->sc_fw_reset)((_sc), (_reason)))
513 #define rtwn_fw_download_enable(_sc, _enable) \
514 	(((_sc)->sc_fw_download_enable)((_sc), (_enable)))
515 #endif
516 #define rtwn_llt_init(_sc) \
517 	(((_sc)->sc_llt_init)((_sc)))
518 #define rtwn_set_page_size(_sc) \
519 	(((_sc)->sc_set_page_size)((_sc)))
520 #define rtwn_lc_calib(_sc) \
521 	(((_sc)->sc_lc_calib)((_sc)))
522 #define rtwn_iq_calib(_sc) \
523 	(((_sc)->sc_iq_calib)((_sc)))
524 #define rtwn_read_chipid_vendor(_sc, _reg) \
525 	(((_sc)->sc_read_chipid_vendor)((_sc), (_reg)))
526 #define rtwn_adj_devcaps(_sc) \
527 	(((_sc)->sc_adj_devcaps)((_sc)))
528 #define rtwn_vap_preattach(_sc, _vap) \
529 	(((_sc)->sc_vap_preattach)((_sc), (_vap)))
530 #define rtwn_postattach(_sc) \
531 	(((_sc)->sc_postattach)((_sc)))
532 #define rtwn_detach_private(_sc) \
533 	(((_sc)->sc_detach_private)((_sc)))
534 #define rtwn_fill_tx_desc(_sc, _ni, _m, \
535 	    _buf, _ridx, _force, _maxretry) \
536 	(((_sc)->sc_fill_tx_desc)((_sc), (_ni), \
537 	    (_m), (_buf), (_ridx), (_force), (_maxretry)))
538 #define rtwn_fill_tx_desc_raw(_sc, _ni, _m, \
539 	    _buf, _params) \
540 	(((_sc)->sc_fill_tx_desc_raw)((_sc), (_ni), \
541 	    (_m), (_buf), (_params)))
542 #define rtwn_fill_tx_desc_null(_sc, _buf, _11b, _qos, _id) \
543 	(((_sc)->sc_fill_tx_desc_null)((_sc), \
544 	    (_buf), (_11b), (_qos), (_id)))
545 #define rtwn_dump_tx_desc(_sc, _desc) \
546 	(((_sc)->sc_dump_tx_desc)((_sc), (_desc)))
547 #define rtwn_tx_radiotap_flags(_sc, _buf) \
548 	(((_sc)->sc_tx_radiotap_flags)((_buf)))
549 #define rtwn_rx_radiotap_flags(_sc, _buf) \
550 	(((_sc)->sc_rx_radiotap_flags)((_buf)))
551 #define rtwn_set_chan(_sc, _c) \
552 	(((_sc)->sc_set_chan)((_sc), (_c)))
553 #ifndef RTWN_WITHOUT_UCODE
554 #define rtwn_set_rsvd_page(_sc, _resp, _null, _qos_null) \
555 	(((_sc)->sc_set_rsvd_page)((_sc), \
556 	    (_resp), (_null), (_qos_null)))
557 #define rtwn_set_pwrmode(_sc, _vap, _off) \
558 	(((_sc)->sc_set_pwrmode)((_sc), (_vap), (_off)))
559 #define rtwn_set_rssi(_sc) \
560 	(((_sc)->sc_set_rssi)((_sc)))
561 #endif
562 #define rtwn_classify_intr(_sc, _buf, _len) \
563 	(((_sc)->sc_classify_intr)((_sc), (_buf), (_len)))
564 #define rtwn_handle_tx_report(_sc, _buf, _len) \
565 	(((_sc)->sc_handle_tx_report)((_sc), (_buf), (_len)))
566 #define rtwn_handle_tx_report2(_sc, _buf, _len) \
567 	(((_sc)->sc_handle_tx_report2)((_sc), (_buf), (_len)))
568 #define rtwn_handle_c2h_report(_sc, _buf, _len) \
569 	(((_sc)->sc_handle_c2h_report)((_sc), (_buf), (_len)))
570 #define rtwn_check_frame(_sc, _m) \
571 	(((_sc)->sc_check_frame)((_sc), (_m)))
572 #define rtwn_beacon_init(_sc, _buf, _id) \
573 	(((_sc)->sc_beacon_init)((_sc), (_buf), (_id)))
574 #define rtwn_beacon_enable(_sc, _id, _enable) \
575 	(((_sc)->sc_beacon_enable)((_sc), (_id), (_enable)))
576 #define rtwn_sta_beacon_enable(_sc, _id, _enable) \
577 	(((_sc)->sc_sta_beacon_enable)((_sc), (_id), (_enable)))
578 #define rtwn_beacon_set_rate(_sc, _buf, _is5ghz) \
579 	(((_sc)->sc_beacon_set_rate)((_buf), (_is5ghz)))
580 #define rtwn_beacon_select(_sc, _id) \
581 	(((_sc)->sc_beacon_select)((_sc), (_id)))
582 #define rtwn_temp_measure(_sc) \
583 	(((_sc)->sc_temp_measure)((_sc)))
584 #define rtwn_temp_read(_sc) \
585 	(((_sc)->sc_temp_read)((_sc)))
586 #define rtwn_init_tx_agg(_sc) \
587 	(((_sc)->sc_init_tx_agg)((_sc)))
588 #define rtwn_init_rx_agg(_sc) \
589 	(((_sc)->sc_init_rx_agg)((_sc)))
590 #define rtwn_init_intr(_sc) \
591 	(((_sc)->sc_init_intr)((_sc)))
592 #define rtwn_init_ampdu(_sc) \
593 	(((_sc)->sc_init_ampdu)((_sc)))
594 #define rtwn_init_edca(_sc) \
595 	(((_sc)->sc_init_edca)((_sc)))
596 #define rtwn_init_bb(_sc) \
597 	(((_sc)->sc_init_bb)((_sc)))
598 #define rtwn_init_rf(_sc) \
599 	(((_sc)->sc_init_rf)((_sc)))
600 #define rtwn_init_antsel(_sc) \
601 	(((_sc)->sc_init_antsel)((_sc)))
602 #define rtwn_post_init(_sc) \
603 	(((_sc)->sc_post_init)((_sc)))
604 #define rtwn_init_bcnq1_boundary(_sc) \
605 	(((_sc)->sc_init_bcnq1_boundary)((_sc)))
606 #define rtwn_set_tx_power(_sc, _vap) \
607 	(((_sc)->sc_set_tx_power)((_sc), (_vap)))
608 
609 /*
610  * Methods to access subfields in registers.
611  */
612 static __inline int
rtwn_setbits_1(struct rtwn_softc * sc,uint16_t addr,uint8_t clr,uint8_t set)613 rtwn_setbits_1(struct rtwn_softc *sc, uint16_t addr, uint8_t clr,
614     uint8_t set)
615 {
616 	return (rtwn_write_1(sc, addr,
617 	    (rtwn_read_1(sc, addr) & ~clr) | set));
618 }
619 
620 static __inline int
rtwn_setbits_1_shift(struct rtwn_softc * sc,uint16_t addr,uint32_t clr,uint32_t set,int shift)621 rtwn_setbits_1_shift(struct rtwn_softc *sc, uint16_t addr, uint32_t clr,
622     uint32_t set, int shift)
623 {
624 	return (rtwn_setbits_1(sc, addr + shift, clr >> shift * NBBY,
625 	    set >> shift * NBBY));
626 }
627 
628 static __inline int
rtwn_setbits_2(struct rtwn_softc * sc,uint16_t addr,uint16_t clr,uint16_t set)629 rtwn_setbits_2(struct rtwn_softc *sc, uint16_t addr, uint16_t clr,
630     uint16_t set)
631 {
632 	return (rtwn_write_2(sc, addr,
633 	    (rtwn_read_2(sc, addr) & ~clr) | set));
634 }
635 
636 static __inline int
rtwn_setbits_4(struct rtwn_softc * sc,uint16_t addr,uint32_t clr,uint32_t set)637 rtwn_setbits_4(struct rtwn_softc *sc, uint16_t addr, uint32_t clr,
638     uint32_t set)
639 {
640 	return (rtwn_write_4(sc, addr,
641 	    (rtwn_read_4(sc, addr) & ~clr) | set));
642 }
643 
644 static __inline void
rtwn_rf_setbits(struct rtwn_softc * sc,int chain,uint8_t addr,uint32_t clr,uint32_t set)645 rtwn_rf_setbits(struct rtwn_softc *sc, int chain, uint8_t addr,
646     uint32_t clr, uint32_t set)
647 {
648 	rtwn_rf_write(sc, chain, addr,
649 	    (rtwn_rf_read(sc, chain, addr) & ~clr) | set);
650 }
651 
652 #endif	/* IF_RTWNVAR_H */
653