xref: /freebsd/sys/dev/ral/rt2560var.h (revision a8089ea5aee578e08acab2438e82fc9a9ae50ed8)
1 
2 /*-
3  * Copyright (c) 2005, 2006
4  *	Damien Bergamini <damien.bergamini@free.fr>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 struct rt2560_rx_radiotap_header {
20 	struct ieee80211_radiotap_header wr_ihdr;
21 	uint64_t	wr_tsf;
22 	uint8_t		wr_flags;
23 	uint8_t		wr_rate;
24 	uint16_t	wr_chan_freq;
25 	uint16_t	wr_chan_flags;
26 	int8_t		wr_antsignal;
27 	int8_t		wr_antnoise;
28 	uint8_t		wr_antenna;
29 } __packed __aligned(8);
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_DBM_ANTSIGNAL) |			\
38 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
39 
40 struct rt2560_tx_radiotap_header {
41 	struct ieee80211_radiotap_header wt_ihdr;
42 	uint8_t		wt_flags;
43 	uint8_t		wt_rate;
44 	uint16_t	wt_chan_freq;
45 	uint16_t	wt_chan_flags;
46 	uint8_t		wt_antenna;
47 } __packed;
48 
49 #define RT2560_TX_RADIOTAP_PRESENT					\
50 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
51 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
52 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
53 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
54 
55 struct rt2560_tx_data {
56 	bus_dmamap_t			map;
57 	struct mbuf			*m;
58 	struct ieee80211_node		*ni;
59 	uint8_t				rix;
60 	int8_t				rssi;
61 };
62 
63 struct rt2560_tx_ring {
64 	bus_dma_tag_t		desc_dmat;
65 	bus_dma_tag_t		data_dmat;
66 	bus_dmamap_t		desc_map;
67 	bus_addr_t		physaddr;
68 	struct rt2560_tx_desc	*desc;
69 	struct rt2560_tx_data	*data;
70 	int			count;
71 	int			queued;
72 	int			cur;
73 	int			next;
74 	int			cur_encrypt;
75 	int			next_encrypt;
76 };
77 
78 struct rt2560_rx_data {
79 	bus_dmamap_t	map;
80 	struct mbuf	*m;
81 	int		drop;
82 };
83 
84 struct rt2560_rx_ring {
85 	bus_dma_tag_t		desc_dmat;
86 	bus_dma_tag_t		data_dmat;
87 	bus_dmamap_t		desc_map;
88 	bus_addr_t		physaddr;
89 	struct rt2560_rx_desc	*desc;
90 	struct rt2560_rx_data	*data;
91 	int			count;
92 	int			cur;
93 	int			next;
94 	int			cur_decrypt;
95 };
96 
97 struct rt2560_vap {
98 	struct ieee80211vap	ral_vap;
99 
100 	int			(*ral_newstate)(struct ieee80211vap *,
101 				    enum ieee80211_state, int);
102 };
103 #define	RT2560_VAP(vap)		((struct rt2560_vap *)(vap))
104 
105 struct rt2560_softc {
106 	struct ieee80211com	sc_ic;
107 	struct ieee80211_ratectl_tx_status sc_txs;
108 	struct mtx		sc_mtx;
109 	struct mbufq		sc_snd;
110 	device_t		sc_dev;
111 	bus_space_tag_t		sc_st;
112 	bus_space_handle_t	sc_sh;
113 
114 	struct callout		watchdog_ch;
115 
116 	int			sc_tx_timer;
117 	int                     sc_invalid;
118 	int			sc_debug;
119 /*
120  * The same in both up to here
121  * ------------------------------------------------
122  */
123 	uint32_t		asic_rev;
124 	uint32_t		eeprom_rev;
125 	uint8_t			rf_rev;
126 	uint8_t			rssi_corr;
127 
128 	struct rt2560_tx_ring	txq;
129 	struct rt2560_tx_ring	prioq;
130 	struct rt2560_tx_ring	atimq;
131 	struct rt2560_tx_ring	bcnq;
132 	struct rt2560_rx_ring	rxq;
133 
134 	uint32_t		rf_regs[4];
135 	uint8_t			txpow[14];
136 
137 	struct {
138 		uint8_t	reg;
139 		uint8_t	val;
140 	}			bbp_prom[16];
141 
142 	int			led_mode;
143 	int			hw_radio;
144 	int			rx_ant;
145 	int			tx_ant;
146 	int			nb_ant;
147 
148 	struct rt2560_rx_radiotap_header sc_rxtap;
149 	struct rt2560_tx_radiotap_header sc_txtap;
150 
151 #define RT2560_F_INPUT_RUNNING	0x1
152 #define RT2560_F_RUNNING	0x2
153 	int			sc_flags;
154 };
155 
156 int	rt2560_attach(device_t, int);
157 int	rt2560_detach(void *);
158 void	rt2560_stop(void *);
159 void	rt2560_resume(void *);
160 void	rt2560_intr(void *);
161 
162 #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
163 #define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
164 #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
165