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