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