xref: /freebsd/sys/dev/ral/rt2661var.h (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2005
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 rt2661_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_antsignal;
28 } __packed;
29 
30 #define RT2661_RX_RADIOTAP_PRESENT					\
31 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
32 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
33 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
34 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
35 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
36 
37 struct rt2661_tx_radiotap_header {
38 	struct ieee80211_radiotap_header wt_ihdr;
39 	uint8_t		wt_flags;
40 	uint8_t		wt_rate;
41 	uint16_t	wt_chan_freq;
42 	uint16_t	wt_chan_flags;
43 } __packed;
44 
45 #define RT2661_TX_RADIOTAP_PRESENT					\
46 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
47 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
48 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
49 
50 struct rt2661_tx_data {
51 	bus_dmamap_t		map;
52 	struct mbuf		*m;
53 	struct ieee80211_node	*ni;
54 	struct ral_rssdesc	id;
55 };
56 
57 struct rt2661_tx_ring {
58 	bus_dma_tag_t		desc_dmat;
59 	bus_dma_tag_t		data_dmat;
60 	bus_dmamap_t		desc_map;
61 	bus_addr_t		physaddr;
62 	struct rt2661_tx_desc	*desc;
63 	struct rt2661_tx_data	*data;
64 	int			count;
65 	int			queued;
66 	int			cur;
67 	int			next;
68 	int			stat;
69 };
70 
71 struct rt2661_rx_data {
72 	bus_dmamap_t	map;
73 	struct mbuf	*m;
74 };
75 
76 struct rt2661_rx_ring {
77 	bus_dma_tag_t		desc_dmat;
78 	bus_dma_tag_t		data_dmat;
79 	bus_dmamap_t		desc_map;
80 	bus_addr_t		physaddr;
81 	struct rt2661_rx_desc	*desc;
82 	struct rt2661_rx_data	*data;
83 	int			count;
84 	int			cur;
85 	int			next;
86 };
87 
88 struct rt2661_node {
89 	struct ieee80211_node	ni;
90 	struct ral_rssadapt	rssadapt;
91 };
92 
93 struct rt2661_softc {
94 	struct ifnet			*sc_ifp;
95 	struct ieee80211com		sc_ic;
96 	int				(*sc_newstate)(struct ieee80211com *,
97 					    enum ieee80211_state, int);
98 	device_t			sc_dev;
99 	bus_space_tag_t			sc_st;
100 	bus_space_handle_t		sc_sh;
101 
102 	struct mtx			sc_mtx;
103 
104 	struct callout			watchdog_ch;
105 	struct callout			rssadapt_ch;
106 
107 	int				sc_tx_timer;
108 	int                             sc_invalid;
109 /*
110  * The same in both up to here
111  * ------------------------------------------------
112  */
113 
114 	struct ieee80211_channel	*sc_curchan;
115 
116 	uint8_t				rf_rev;
117 
118 	uint8_t				rfprog;
119 	uint8_t				rffreq;
120 
121 	struct rt2661_tx_ring		txq[4];
122 	struct rt2661_tx_ring		mgtq;
123 	struct rt2661_rx_ring		rxq;
124 
125 	uint32_t			rf_regs[4];
126 	int8_t				txpow[38];
127 
128 	struct {
129 		uint8_t	reg;
130 		uint8_t	val;
131 	}				bbp_prom[16];
132 
133 	int				hw_radio;
134 	int				rx_ant;
135 	int				tx_ant;
136 	int				nb_ant;
137 	int				ext_2ghz_lna;
138 	int				ext_5ghz_lna;
139 	int				rssi_2ghz_corr;
140 	int				rssi_5ghz_corr;
141 
142 	uint8_t				bbp18;
143 	uint8_t				bbp21;
144 	uint8_t				bbp22;
145 	uint8_t				bbp16;
146 	uint8_t				bbp17;
147 	uint8_t				bbp64;
148 
149 	int				dwelltime;
150 
151 	struct bpf_if			*sc_drvbpf;
152 
153 	union {
154 		struct rt2661_rx_radiotap_header th;
155 		uint8_t	pad[64];
156 	}				sc_rxtapu;
157 #define sc_rxtap	sc_rxtapu.th
158 	int				sc_rxtap_len;
159 
160 	union {
161 		struct rt2661_tx_radiotap_header th;
162 		uint8_t	pad[64];
163 	}				sc_txtapu;
164 #define sc_txtap	sc_txtapu.th
165 	int				sc_txtap_len;
166 #define                 RAL_INPUT_RUNNING       1
167 	int                             sc_flags;
168 };
169 
170 int	rt2661_attach(device_t, int);
171 int	rt2661_detach(void *);
172 void	rt2661_shutdown(void *);
173 void	rt2661_suspend(void *);
174 void	rt2661_resume(void *);
175 void	rt2661_intr(void *);
176 
177 #define RAL_LOCK(sc)	mtx_lock(&(sc)->sc_mtx)
178 #define RAL_UNLOCK(sc)	mtx_unlock(&(sc)->sc_mtx)
179