1/*	$NetBSD: if_urtwnvar.h,v 1.16 2020/03/15 23:04:51 thorpej Exp $	*/
2/*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
3
4/*-
5 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19#ifndef _IF_URTWNVAR_H_
20#define _IF_URTWNVAR_H_
21
22/*
23 * Driver definitions.
24 */
25#define URTWN_RX_LIST_COUNT		1
26#define URTWN_TX_LIST_COUNT		8
27
28#define URTWN_HOST_CMD_RING_COUNT	32
29
30#define URTWN_RXBUFSZ	(16 * 1024)
31#define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc_usb) + IEEE80211_MAX_LEN + 8)
32
33#define URTWN_RIDX_COUNT	28
34
35#define URTWN_TX_TIMEOUT	5000	/* ms */
36
37#define URTWN_LED_LINK	0
38#define URTWN_LED_DATA	1
39
40struct urtwn_rx_radiotap_header {
41	struct ieee80211_radiotap_header wr_ihdr;
42	uint8_t		wr_flags;
43	uint8_t		wr_rate;
44	uint16_t	wr_chan_freq;
45	uint16_t	wr_chan_flags;
46	uint8_t		wr_dbm_antsignal;
47};
48
49#define URTWN_RX_RADIOTAP_PRESENT			\
50	(1 << IEEE80211_RADIOTAP_FLAGS |		\
51	 1 << IEEE80211_RADIOTAP_RATE |			\
52	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
53	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
54
55struct urtwn_tx_radiotap_header {
56	struct ieee80211_radiotap_header wt_ihdr;
57	uint8_t		wt_flags;
58	uint16_t	wt_chan_freq;
59	uint16_t	wt_chan_flags;
60};
61
62#define URTWN_TX_RADIOTAP_PRESENT			\
63	(1 << IEEE80211_RADIOTAP_FLAGS |		\
64	 1 << IEEE80211_RADIOTAP_CHANNEL)
65
66struct urtwn_softc;
67
68struct urtwn_rx_data {
69	struct urtwn_softc		*sc;
70	size_t				pidx;
71	struct usbd_xfer		*xfer;
72	uint8_t				*buf;
73	TAILQ_ENTRY(urtwn_rx_data)	next;
74};
75
76struct urtwn_tx_data {
77	struct urtwn_softc		*sc;
78	size_t				pidx;
79	struct usbd_xfer		*xfer;
80	uint8_t				*buf;
81	TAILQ_ENTRY(urtwn_tx_data)	next;
82};
83
84struct urtwn_host_cmd {
85	void	(*cb)(struct urtwn_softc *, void *);
86	uint8_t	data[256];
87};
88
89struct urtwn_cmd_newstate {
90	enum ieee80211_state	state;
91	int			arg;
92};
93
94struct urtwn_host_cmd_ring {
95	struct urtwn_host_cmd	cmd[URTWN_HOST_CMD_RING_COUNT];
96	int			cur;
97	int			next;
98	int			queued;
99};
100
101#if 1	/* XXX: sys/net80211/ieee80211.h */
102
103#define	IEEE80211_HTINFO_2NDCHAN	0x03	/* secondary/ext chan offset */
104#define	IEEE80211_HTINFO_2NDCHAN_S	0
105#define	IEEE80211_HTINFO_2NDCHAN_NONE	0x00	/* no secondary/ext channel */
106#define	IEEE80211_HTINFO_2NDCHAN_ABOVE	0x01	/* above private channel */
107/* NB: 2 is reserved */
108#define	IEEE80211_HTINFO_2NDCHAN_BELOW	0x03	/* below primary channel */
109#endif	/* XXX: 1 */
110
111struct urtwn_softc {
112	device_t			sc_dev;
113	struct ieee80211com		sc_ic;
114	struct ethercom			sc_ec;
115#define sc_if   sc_ec.ec_if
116	int				(*sc_newstate)(struct ieee80211com *,
117					    enum ieee80211_state, int);
118
119	struct usbd_device *		sc_udev;
120	struct usbd_interface *		sc_iface;
121	u_int				sc_flags;
122#define URTWN_FLAG_CCK_HIPWR	__BIT(0)
123#define	URTWN_FLAG_ATTACHED	__BIT(1)
124#define	URTWN_FLAG_FWREADY	__BIT(2)
125	int				sc_dying;
126
127	struct usb_task			sc_task;
128	callout_t			sc_scan_to;
129	callout_t			sc_calib_to;
130
131	kcondvar_t			sc_task_cv;
132	kmutex_t			sc_task_mtx;
133	kmutex_t			sc_fwcmd_mtx;
134	kmutex_t			sc_tx_mtx;
135	kmutex_t			sc_rx_mtx;
136	kmutex_t			sc_write_mtx;
137	kmutex_t			sc_media_mtx;	/* XXX */
138
139	struct usbd_pipe *		rx_pipe[R92C_MAX_EPIN];
140	int				rx_npipe;
141	struct usbd_pipe *		tx_pipe[R92C_MAX_EPOUT];
142	int				tx_npipe;
143	int				ac2idx[WME_NUM_AC];
144
145	u_int				chip;
146#define URTWN_CHIP_92C		0x01
147#define URTWN_CHIP_92C_1T2R	0x02
148#define URTWN_CHIP_UMC		0x04
149#define URTWN_CHIP_UMC_A_CUT	0x08
150#define URTWN_CHIP_88E		0x10
151#define URTWN_CHIP_92EU		0x20
152
153	void				(*sc_rf_write)(struct urtwn_softc *,
154					    int, uint8_t, uint32_t);
155	int				(*sc_power_on)(struct urtwn_softc *);
156	int				(*sc_dma_init)(struct urtwn_softc *);
157
158	uint8_t				board_type;
159	uint8_t				regulatory;
160	uint8_t				pa_setting;
161	int				avg_pwdb;
162	int				thcal_state;
163	int				thcal_lctemp;
164	size_t				ntxchains;
165	size_t				nrxchains;
166	int				ledlink;
167	bool				iqk_inited;
168
169	int				tx_timer;
170
171	struct urtwn_host_cmd_ring	cmdq;
172	int				fwcur;
173	struct urtwn_rx_data		rx_data[R92C_MAX_EPIN][URTWN_RX_LIST_COUNT];
174	struct urtwn_tx_data		tx_data[R92C_MAX_EPOUT][URTWN_TX_LIST_COUNT];
175	TAILQ_HEAD(, urtwn_tx_data)	tx_free_list[R92C_MAX_EPOUT];
176	TAILQ_HEAD(, urtwn_rx_data)	rx_free_list[R92C_MAX_EPIN];
177
178	struct r92c_rom			rom;
179	uint8_t				r88e_rom[4096];
180	uint8_t				cck_tx_pwr[6];
181	uint8_t				ht40_tx_pwr[5];
182	int8_t				bw20_tx_pwr_diff;
183	int8_t				ofdm_tx_pwr_diff;
184
185	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
186
187	struct bpf_if *			sc_drvbpf;
188	union {
189		struct urtwn_rx_radiotap_header th;
190		uint8_t	pad[64];
191	}				sc_rxtapu;
192#define sc_rxtap	sc_rxtapu.th
193	int				sc_rxtap_len;
194	union {
195		struct urtwn_tx_radiotap_header th;
196		uint8_t	pad[64];
197	}				sc_txtapu;
198#define sc_txtap	sc_txtapu.th
199	int				sc_txtap_len;
200	bool				sc_running;
201
202	struct ieee80211_beacon_offsets sc_bo;
203	krndsource_t rnd_source;	/* random source */
204};
205
206#endif /* _IF_URTWNVAR_H_ */
207