xref: /netbsd/sys/dev/ic/rt2860var.h (revision 74020018)
1 /*	$NetBSD: rt2860var.h,v 1.6 2019/10/05 23:27:20 mrg Exp $	*/
2 /*	$OpenBSD: rt2860var.h,v 1.23 2016/03/21 21:16:30 stsp Exp $	*/
3 
4 /*-
5  * Copyright (c) 2007
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define RT2860_MAX_SCATTER	15
22 #define RT2860_MAX_SCATTER_TXD	(1 + (RT2860_MAX_SCATTER / 2))
23 
24 #define RT2860_RX_RING_COUNT	128
25 #define RT2860_TX_RING_COUNT	64
26 #define RT2860_TX_RING_MAX	(RT2860_TX_RING_COUNT - 1)
27 #define RT2860_TX_RING_ONEMORE	(RT2860_TX_RING_MAX - RT2860_MAX_SCATTER_TXD)
28 #define RT2860_TX_POOL_COUNT	(RT2860_TX_RING_COUNT * 2)
29 
30 /* HW supports up to 255 STAs */
31 #define RT2860_WCID_MAX		254
32 #define RT2860_AID2WCID(aid)	((aid) & 0xff)
33 
34 #define IEEE80211_NO_HT
35 
36 struct rt2860_rx_radiotap_header {
37 	struct ieee80211_radiotap_header wr_ihdr;
38 	uint8_t		wr_flags;
39 	uint8_t		wr_rate;
40 	uint16_t	wr_chan_freq;
41 	uint16_t	wr_chan_flags;
42 	uint8_t		wr_dbm_antsignal;
43 	uint8_t		wr_antenna;
44 	uint8_t		wr_antsignal;
45 } __aligned(8);
46 
47 #define RT2860_RX_RADIOTAP_PRESENT			\
48 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
49 	 1 << IEEE80211_RADIOTAP_RATE |			\
50 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
51 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
52 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
53 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
54 
55 struct rt2860_tx_radiotap_header {
56 	struct ieee80211_radiotap_header wt_ihdr;
57 	uint8_t		wt_flags;
58 	uint8_t		wt_rate;
59 	uint16_t	wt_chan_freq;
60 	uint16_t	wt_chan_flags;
61 	uint8_t		wt_hwqueue;
62 } __aligned(8);
63 
64 #define RT2860_TX_RADIOTAP_PRESENT			\
65 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
66 	 1 << IEEE80211_RADIOTAP_RATE |			\
67 	 1 << IEEE80211_RADIOTAP_CHANNEL)
68 
69 struct rt2860_tx_data {
70 	struct rt2860_txwi		*txwi;
71 	struct mbuf			*m;
72 	struct ieee80211_node		*ni;
73 	bus_dmamap_t			map;
74 	bus_addr_t			paddr;
75 	SLIST_ENTRY(rt2860_tx_data)	next;
76 };
77 
78 struct rt2860_tx_ring {
79 	struct rt2860_txd	*txd;
80 	bus_addr_t		paddr;
81 	bus_dmamap_t		map;
82 	bus_dma_segment_t	seg;
83 	struct rt2860_tx_data	*data[RT2860_TX_RING_COUNT];
84 	int			cur;
85 	int			next;
86 	int			queued;
87 };
88 
89 struct rt2860_rx_data {
90 	struct mbuf	*m;
91 	bus_dmamap_t	map;
92 };
93 
94 struct rt2860_rx_ring {
95 	struct rt2860_rxd	*rxd;
96 	bus_addr_t		paddr;
97 	bus_dmamap_t		map;
98 	bus_dma_segment_t	seg;
99 	unsigned int		cur;	/* must be unsigned */
100 	struct rt2860_rx_data	data[RT2860_RX_RING_COUNT];
101 };
102 
103 struct rt2860_node {
104 	struct ieee80211_node	ni;
105 	uint8_t			wcid;
106 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
107 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
108 };
109 
110 struct rt2860_softc {
111 	device_t			sc_dev;
112 
113 	struct ieee80211com		sc_ic;
114 	int				(*sc_newstate)(struct ieee80211com *,
115 					    enum ieee80211_state, int);
116 
117 	int				(*sc_enable)(struct rt2860_softc *);
118 	void				(*sc_disable)(struct rt2860_softc *);
119 
120 	bus_dma_tag_t			sc_dmat;
121 	bus_space_tag_t			sc_st;
122 	bus_space_handle_t		sc_sh;
123 	void				*sc_soft_ih;
124 
125 	struct ethercom			sc_ec;
126 #define sc_if  sc_ec.ec_if
127 
128 	uint16_t			(*sc_srom_read)(struct rt2860_softc *,
129 					    uint16_t);
130 
131 	int				sc_flags;
132 #define RT2860_ENABLED		(1 << 0)
133 #define RT2860_ADVANCED_PS	(1 << 1)
134 #define RT2860_PCIE		(1 << 2)
135 #define	RT2860_RUNNING		(1 << 3)
136 
137 	struct ieee80211_amrr		amrr;
138 
139 	uint32_t			sc_ic_flags;
140 	int				fixed_ridx;
141 
142 	u_char				*ucode;
143 	size_t				ucsize;
144 
145 	struct rt2860_tx_ring		txq[6];
146 	struct rt2860_rx_ring		rxq;
147 
148 	SLIST_HEAD(, rt2860_tx_data)	data_pool;
149 	struct rt2860_tx_data		data[RT2860_TX_POOL_COUNT];
150 	bus_dmamap_t			txwi_map;
151 	bus_dma_segment_t		txwi_seg;
152 	void				*txwi_vaddr;
153 
154 	int				sc_tx_timer;
155 	struct ieee80211_beacon_offsets	sc_bo;
156 	int				mgtqid;
157 	uint8_t				qfullmsk;
158 
159 	uint16_t			mac_ver;
160 	uint16_t			mac_rev;
161 	uint32_t			rf_rev;
162 	uint8_t				freq;
163 	uint8_t				ntxchains;
164 	uint8_t				nrxchains;
165 	uint8_t				pslevel;
166 	int8_t				txpow1[54];
167 	int8_t				txpow2[54];
168 	int8_t				rssi_2ghz[3];
169 	int8_t				rssi_5ghz[3];
170 	uint8_t				lna[4];
171 	uint8_t				rf24_20mhz;
172 	uint8_t				rf24_40mhz;
173 	uint8_t				patch_dac;
174 	uint8_t				rfswitch;
175 	uint8_t				ext_2ghz_lna;
176 	uint8_t				ext_5ghz_lna;
177 	uint8_t				calib_2ghz;
178 	uint8_t				calib_5ghz;
179 	uint8_t				txmixgain_2ghz;
180 	uint8_t				txmixgain_5ghz;
181 	uint8_t				tssi_2ghz[9];
182 	uint8_t				tssi_5ghz[9];
183 	uint8_t				step_2ghz;
184 	uint8_t				step_5ghz;
185 	struct {
186 		uint8_t	reg;
187 		uint8_t	val;
188 	}				bbp[8], rf[10];
189 	uint8_t				leds;
190 	uint16_t			led[3];
191 	uint32_t			txpow20mhz[5];
192 	uint32_t			txpow40mhz_2ghz[5];
193 	uint32_t			txpow40mhz_5ghz[5];
194 
195 	struct ieee80211_amrr_node	amn[RT2860_WCID_MAX + 1];
196 
197 	struct bpf_if			*sc_drvbpf;
198 	union {
199 		struct rt2860_rx_radiotap_header th;
200 		uint8_t pad[64];
201 	}				sc_rxtapu;
202 #define sc_rxtap			sc_rxtapu.th
203 	int				sc_rxtap_len;
204 
205 	union {
206 		struct rt2860_tx_radiotap_header th;
207 		uint8_t pad[64];
208 	}				sc_txtapu;
209 #define sc_txtap			sc_txtapu.th
210 	int				sc_txtap_len;
211 };
212 
213 int	rt2860_attach(void *, int);
214 int	rt2860_detach(void *);
215 int	rt2860_intr(void *);
216