xref: /freebsd/sys/dev/ral/rt2560var.h (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
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 	struct ral_rssdesc		id;
59 };
60 
61 struct rt2560_tx_ring {
62 	bus_dma_tag_t		desc_dmat;
63 	bus_dma_tag_t		data_dmat;
64 	bus_dmamap_t		desc_map;
65 	bus_addr_t		physaddr;
66 	struct rt2560_tx_desc	*desc;
67 	struct rt2560_tx_data	*data;
68 	int			count;
69 	int			queued;
70 	int			cur;
71 	int			next;
72 	int			cur_encrypt;
73 	int			next_encrypt;
74 };
75 
76 struct rt2560_rx_data {
77 	bus_dmamap_t	map;
78 	struct mbuf	*m;
79 	int		drop;
80 };
81 
82 struct rt2560_rx_ring {
83 	bus_dma_tag_t		desc_dmat;
84 	bus_dma_tag_t		data_dmat;
85 	bus_dmamap_t		desc_map;
86 	bus_addr_t		physaddr;
87 	struct rt2560_rx_desc	*desc;
88 	struct rt2560_rx_data	*data;
89 	int			count;
90 	int			cur;
91 	int			next;
92 	int			cur_decrypt;
93 };
94 
95 struct rt2560_node {
96 	struct ieee80211_node	ni;
97 	struct ral_rssadapt	rssadapt;
98 };
99 
100 struct rt2560_softc {
101 	struct ifnet		*sc_ifp;
102 	struct ieee80211com	sc_ic;
103 	int			(*sc_newstate)(struct ieee80211com *,
104 				    enum ieee80211_state, int);
105 	device_t		sc_dev;
106 	bus_space_tag_t		sc_st;
107 	bus_space_handle_t	sc_sh;
108 
109 	struct mtx		sc_mtx;
110 
111 	struct callout		watchdog_ch;
112 	struct callout		rssadapt_ch;
113 
114 	int			sc_tx_timer;
115 	int                     sc_invalid;
116 /*
117  * The same in both up to here
118  * ------------------------------------------------
119  */
120 	uint32_t		asic_rev;
121 	uint32_t		eeprom_rev;
122 	uint8_t			rf_rev;
123 	uint8_t			rssi_corr;
124 
125 	struct rt2560_tx_ring	txq;
126 	struct rt2560_tx_ring	prioq;
127 	struct rt2560_tx_ring	atimq;
128 	struct rt2560_tx_ring	bcnq;
129 	struct rt2560_rx_ring	rxq;
130 
131 	struct ieee80211_beacon_offsets	sc_bo;
132 
133 	uint32_t		rf_regs[4];
134 	uint8_t			txpow[14];
135 
136 	struct {
137 		uint8_t	reg;
138 		uint8_t	val;
139 	}			bbp_prom[16];
140 
141 	int			led_mode;
142 	int			hw_radio;
143 	int			rx_ant;
144 	int			tx_ant;
145 	int			nb_ant;
146 
147 	int			dwelltime;
148 
149 	struct bpf_if		*sc_drvbpf;
150 
151 	union {
152 		struct rt2560_rx_radiotap_header th;
153 		uint8_t	pad[64];
154 	}			sc_rxtapu;
155 #define sc_rxtap	sc_rxtapu.th
156 	int			sc_rxtap_len;
157 
158 	union {
159 		struct rt2560_tx_radiotap_header th;
160 		uint8_t	pad[64];
161 	}			sc_txtapu;
162 #define sc_txtap	sc_txtapu.th
163 	int			sc_txtap_len;
164 #define                 RAL_INPUT_RUNNING       1
165 	int                     sc_flags;
166 };
167 
168 int	rt2560_attach(device_t, int);
169 int	rt2560_detach(void *);
170 void	rt2560_stop(void *);
171 void	rt2560_resume(void *);
172 void	rt2560_intr(void *);
173 
174 #define RAL_LOCK(sc)	mtx_lock(&(sc)->sc_mtx)
175 #define RAL_UNLOCK(sc)	mtx_unlock(&(sc)->sc_mtx)
176