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