xref: /freebsd/sys/dev/ral/rt2560var.h (revision 2be1a816b9ff69588e55be0a84cbe2a31efc0f2f)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2005, 2006
5  *	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 
20 struct rt2560_rx_radiotap_header {
21 	struct ieee80211_radiotap_header wr_ihdr;
22 	uint64_t	wr_tsf;
23 	uint8_t		wr_flags;
24 	uint8_t		wr_rate;
25 	uint16_t	wr_chan_freq;
26 	uint16_t	wr_chan_flags;
27 	uint8_t		wr_antenna;
28 	uint8_t		wr_antsignal;
29 };
30 
31 #define RT2560_RX_RADIOTAP_PRESENT					\
32 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
33 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
34 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
35 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
36 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
37 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
38 
39 struct rt2560_tx_radiotap_header {
40 	struct ieee80211_radiotap_header wt_ihdr;
41 	uint8_t		wt_flags;
42 	uint8_t		wt_rate;
43 	uint16_t	wt_chan_freq;
44 	uint16_t	wt_chan_flags;
45 	uint8_t		wt_antenna;
46 };
47 
48 #define RT2560_TX_RADIOTAP_PRESENT					\
49 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
50 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
51 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
52 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
53 
54 struct rt2560_tx_data {
55 	bus_dmamap_t			map;
56 	struct mbuf			*m;
57 	struct ieee80211_node		*ni;
58 	uint8_t				rix;
59 	int8_t				rssi;
60 };
61 
62 struct rt2560_tx_ring {
63 	bus_dma_tag_t		desc_dmat;
64 	bus_dma_tag_t		data_dmat;
65 	bus_dmamap_t		desc_map;
66 	bus_addr_t		physaddr;
67 	struct rt2560_tx_desc	*desc;
68 	struct rt2560_tx_data	*data;
69 	int			count;
70 	int			queued;
71 	int			cur;
72 	int			next;
73 	int			cur_encrypt;
74 	int			next_encrypt;
75 };
76 
77 struct rt2560_rx_data {
78 	bus_dmamap_t	map;
79 	struct mbuf	*m;
80 	int		drop;
81 };
82 
83 struct rt2560_rx_ring {
84 	bus_dma_tag_t		desc_dmat;
85 	bus_dma_tag_t		data_dmat;
86 	bus_dmamap_t		desc_map;
87 	bus_addr_t		physaddr;
88 	struct rt2560_rx_desc	*desc;
89 	struct rt2560_rx_data	*data;
90 	int			count;
91 	int			cur;
92 	int			next;
93 	int			cur_decrypt;
94 };
95 
96 struct rt2560_node {
97 	struct ieee80211_node	ni;
98 	struct ieee80211_amrr_node amrr;
99 };
100 #define	RT2560_NODE(ni)		((struct rt2560_node *)(ni))
101 
102 struct rt2560_vap {
103 	struct ieee80211vap	ral_vap;
104 	struct ieee80211_beacon_offsets	ral_bo;
105 	struct ieee80211_amrr	amrr;
106 
107 	int			(*ral_newstate)(struct ieee80211vap *,
108 				    enum ieee80211_state, int);
109 };
110 #define	RT2560_VAP(vap)		((struct rt2560_vap *)(vap))
111 
112 struct rt2560_softc {
113 	struct ifnet		*sc_ifp;
114 	device_t		sc_dev;
115 	bus_space_tag_t		sc_st;
116 	bus_space_handle_t	sc_sh;
117 
118 	struct mtx		sc_mtx;
119 
120 	struct callout		watchdog_ch;
121 
122 	int			sc_tx_timer;
123 	int                     sc_invalid;
124 	int			sc_debug;
125 
126 	const struct ieee80211_rate_table *sc_rates;
127 /*
128  * The same in both up to here
129  * ------------------------------------------------
130  */
131 	uint32_t		asic_rev;
132 	uint32_t		eeprom_rev;
133 	uint8_t			rf_rev;
134 	uint8_t			rssi_corr;
135 
136 	struct rt2560_tx_ring	txq;
137 	struct rt2560_tx_ring	prioq;
138 	struct rt2560_tx_ring	atimq;
139 	struct rt2560_tx_ring	bcnq;
140 	struct rt2560_rx_ring	rxq;
141 
142 	uint32_t		rf_regs[4];
143 	uint8_t			txpow[14];
144 
145 	struct {
146 		uint8_t	reg;
147 		uint8_t	val;
148 	}			bbp_prom[16];
149 
150 	int			led_mode;
151 	int			hw_radio;
152 	int			rx_ant;
153 	int			tx_ant;
154 	int			nb_ant;
155 
156 	struct rt2560_rx_radiotap_header sc_rxtap;
157 	int			sc_rxtap_len;
158 
159 	struct rt2560_tx_radiotap_header sc_txtap;
160 	int			sc_txtap_len;
161 #define RT2560_F_INPUT_RUNNING	0x1
162 #define RT2560_F_PRIO_OACTIVE	0x2
163 #define RT2560_F_DATA_OACTIVE	0x4
164 	int			sc_flags;
165 };
166 
167 int	rt2560_attach(device_t, int);
168 int	rt2560_detach(void *);
169 void	rt2560_stop(void *);
170 void	rt2560_resume(void *);
171 void	rt2560_intr(void *);
172 
173 #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
174 #define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
175 #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
176