xref: /freebsd/sys/dev/ral/rt2860var.h (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1 /*-
2  * Copyright (c) 2007 Damien Bergamini <damien.bergamini@free.fr>
3  * Copyright (c) 2012 Bernhard Schmidt <bschmidt@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: rt2860var.h,v 1.20 2010/09/07 16:21:42 deraadt Exp $
18  */
19 
20 #define RT2860_TX_RING_COUNT	64
21 #define RT2860_RX_RING_COUNT	128
22 #define RT2860_TX_POOL_COUNT	(RT2860_TX_RING_COUNT * 2)
23 
24 #define RT2860_MAX_SCATTER	((RT2860_TX_RING_COUNT * 2) - 1)
25 
26 /* HW supports up to 255 STAs */
27 #define RT2860_WCID_MAX		254
28 #define RT2860_AID2WCID(aid)	((aid) & 0xff)
29 
30 struct rt2860_rx_radiotap_header {
31 	struct ieee80211_radiotap_header wr_ihdr;
32 	uint64_t	wr_tsf;
33 	uint8_t		wr_flags;
34 	uint8_t		wr_rate;
35 	uint16_t	wr_chan_freq;
36 	uint16_t	wr_chan_flags;
37 	uint8_t		wr_antenna;
38 	int8_t		wr_antsignal;
39 	int8_t		wr_antnoise;
40 } __packed __aligned(8);
41 
42 #define RT2860_RX_RADIOTAP_PRESENT					\
43 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
44 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
45 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
46 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
47 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
48 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
49 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
50 
51 struct rt2860_tx_radiotap_header {
52 	struct ieee80211_radiotap_header wt_ihdr;
53 	uint8_t		wt_flags;
54 	uint8_t		wt_rate;
55 	uint16_t	wt_chan_freq;
56 	uint16_t	wt_chan_flags;
57 } __packed;
58 
59 #define RT2860_TX_RADIOTAP_PRESENT					\
60 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
61 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
62 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
63 
64 struct rt2860_tx_data {
65 	struct rt2860_txwi		*txwi;
66 	struct mbuf			*m;
67 	struct ieee80211_node		*ni;
68 	bus_dmamap_t			map;
69 	bus_addr_t			paddr;
70 	SLIST_ENTRY(rt2860_tx_data)	next;
71 };
72 
73 struct rt2860_tx_ring {
74 	struct rt2860_txd	*txd;
75 	bus_addr_t		paddr;
76 	bus_dma_tag_t		desc_dmat;
77 	bus_dmamap_t		desc_map;
78 	bus_dma_segment_t	seg;
79 	struct rt2860_tx_data	*data[RT2860_TX_RING_COUNT];
80 	int			cur;
81 	int			next;
82 	int			queued;
83 };
84 
85 struct rt2860_rx_data {
86 	struct mbuf	*m;
87 	bus_dmamap_t	map;
88 };
89 
90 struct rt2860_rx_ring {
91 	struct rt2860_rxd	*rxd;
92 	bus_addr_t		paddr;
93 	bus_dma_tag_t		desc_dmat;
94 	bus_dmamap_t		desc_map;
95 	bus_dma_tag_t		data_dmat;
96 	bus_dma_segment_t	seg;
97 	unsigned int		cur;	/* must be unsigned */
98 	struct rt2860_rx_data	data[RT2860_RX_RING_COUNT];
99 };
100 
101 struct rt2860_node {
102 	struct ieee80211_node	ni;
103 	uint8_t			wcid;
104 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
105 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
106 };
107 
108 struct rt2860_vap {
109 	struct ieee80211vap	ral_vap;
110 
111 	int			(*ral_newstate)(struct ieee80211vap *,
112 				    enum ieee80211_state, int);
113 };
114 #define	RT2860_VAP(vap)		((struct rt2860_vap *)(vap))
115 
116 struct rt2860_softc {
117 	struct ieee80211com		sc_ic;
118 	struct ieee80211_ratectl_tx_status sc_txs;
119 	struct mbufq			sc_snd;
120 	struct mtx			sc_mtx;
121 	device_t			sc_dev;
122 	bus_space_tag_t			sc_st;
123 	bus_space_handle_t		sc_sh;
124 
125 	struct callout			watchdog_ch;
126 
127 	int				sc_invalid;
128 	int				sc_debug;
129 /*
130  * The same in both up to here
131  * ------------------------------------------------
132  */
133 
134 	uint16_t			(*sc_srom_read)(struct rt2860_softc *,
135 					    uint16_t);
136 	void				(*sc_node_free)(struct ieee80211_node *);
137 
138 	int				sc_flags;
139 #define RT2860_ENABLED		(1 << 0)
140 #define RT2860_ADVANCED_PS	(1 << 1)
141 #define RT2860_PCIE		(1 << 2)
142 #define	RT2860_RUNNING		(1 << 3)
143 
144 	struct ieee80211_node		*wcid2ni[RT2860_WCID_MAX + 1];
145 
146 	struct rt2860_tx_ring		txq[6];
147 	struct rt2860_rx_ring		rxq;
148 
149 	SLIST_HEAD(, rt2860_tx_data)	data_pool;
150 	struct rt2860_tx_data		data[RT2860_TX_POOL_COUNT];
151 	bus_dma_tag_t			txwi_dmat;
152 	bus_dmamap_t			txwi_map;
153 	bus_dma_segment_t		txwi_seg;
154 	caddr_t				txwi_vaddr;
155 
156 	int				sc_tx_timer;
157 	int				mgtqid;
158 	uint8_t				qfullmsk;
159 
160 	uint16_t			mac_ver;
161 	uint16_t			mac_rev;
162 	uint16_t			rf_rev;
163 	uint8_t				freq;
164 	uint8_t				ntxchains;
165 	uint8_t				nrxchains;
166 	uint8_t				pslevel;
167 	int8_t				txpow1[54];
168 	int8_t				txpow2[54];
169 	int8_t				rssi_2ghz[3];
170 	int8_t				rssi_5ghz[3];
171 	uint8_t				lna[4];
172 	uint8_t				rf24_20mhz;
173 	uint8_t				rf24_40mhz;
174 	uint8_t				patch_dac;
175 	uint8_t				rfswitch;
176 	uint8_t				ext_2ghz_lna;
177 	uint8_t				ext_5ghz_lna;
178 	uint8_t				calib_2ghz;
179 	uint8_t				calib_5ghz;
180 	uint8_t				txmixgain_2ghz;
181 	uint8_t				txmixgain_5ghz;
182 	uint8_t				tssi_2ghz[9];
183 	uint8_t				tssi_5ghz[9];
184 	uint8_t				step_2ghz;
185 	uint8_t				step_5ghz;
186 	struct {
187 		uint8_t	reg;
188 		uint8_t	val;
189 	}				bbp[8], rf[10];
190 	uint8_t				leds;
191 	uint16_t			led[3];
192 	uint32_t			txpow20mhz[5];
193 	uint32_t			txpow40mhz_2ghz[5];
194 	uint32_t			txpow40mhz_5ghz[5];
195 
196 	struct rt2860_rx_radiotap_header sc_rxtap;
197 	struct rt2860_tx_radiotap_header sc_txtap;
198 };
199 
200 int	rt2860_attach(device_t, int);
201 int	rt2860_detach(void *);
202 void	rt2860_shutdown(void *);
203 void	rt2860_suspend(void *);
204 void	rt2860_resume(void *);
205 void	rt2860_intr(void *);
206 
207 #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
208 #define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
209 #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
210