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