xref: /freebsd/sys/dev/wpi/if_wpivar.h (revision 66e576525d35c68fcb86f142ebaa5a448555c0c7)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2006,2007
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 #include <net80211/ieee80211_amrr.h>
20 
21 struct wpi_rx_radiotap_header {
22 	struct ieee80211_radiotap_header wr_ihdr;
23 	uint64_t	wr_tsft;
24 	uint8_t		wr_flags;
25 	uint8_t		wr_rate;
26 	uint16_t	wr_chan_freq;
27 	uint16_t	wr_chan_flags;
28 	int8_t		wr_dbm_antsignal;
29 	int8_t		wr_dbm_antnoise;
30 	uint8_t		wr_antenna;
31 };
32 
33 #define WPI_RX_RADIOTAP_PRESENT						\
34 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
35 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
36 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
37 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
38 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
39 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
40 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
41 
42 struct wpi_tx_radiotap_header {
43 	struct ieee80211_radiotap_header wt_ihdr;
44 	uint8_t		wt_flags;
45 	uint8_t		wt_rate;
46 	uint16_t	wt_chan_freq;
47 	uint16_t	wt_chan_flags;
48 	uint8_t		wt_hwqueue;
49 };
50 
51 #define WPI_TX_RADIOTAP_PRESENT						\
52 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
53 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
54 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
55 
56 struct wpi_dma_info {
57 	bus_dma_tag_t		tag;
58 	bus_dmamap_t            map;
59 	bus_addr_t		paddr;	      /* aligned p address */
60 	bus_addr_t		paddr_start;  /* possibly unaligned p start*/
61 	caddr_t			vaddr;	      /* aligned v address */
62 	caddr_t			vaddr_start;  /* possibly unaligned v start */
63 	bus_size_t		size;
64 };
65 
66 struct wpi_tx_data {
67 	bus_dmamap_t		map;
68 	struct mbuf		*m;
69 	struct ieee80211_node	*ni;
70 };
71 
72 struct wpi_tx_ring {
73 	struct wpi_dma_info	desc_dma;
74 	struct wpi_dma_info	cmd_dma;
75 	struct wpi_tx_desc	*desc;
76 	struct wpi_tx_cmd	*cmd;
77 	struct wpi_tx_data	*data;
78 	bus_dma_tag_t		data_dmat;
79 	int			qid;
80 	int			count;
81 	int			queued;
82 	int			cur;
83 };
84 
85 #define WPI_RBUF_COUNT ( WPI_RX_RING_COUNT + 16 )
86 
87 struct wpi_rx_data {
88 	bus_dmamap_t		map;
89 	struct mbuf		*m;
90 };
91 
92 struct wpi_rx_ring {
93 	struct wpi_dma_info	desc_dma;
94 	uint32_t		*desc;
95 	struct wpi_rx_data	data[WPI_RX_RING_COUNT];
96 	bus_dma_tag_t		data_dmat;
97 	int			cur;
98 };
99 
100 struct wpi_amrr {
101 	struct	ieee80211_node ni;	/* must be the first */
102 	int	txcnt;
103 	int	retrycnt;
104 	int	success;
105 	int	success_threshold;
106 	int	recovery;
107 };
108 
109 struct wpi_power_sample {
110 	uint8_t	index;
111 	int8_t	power;
112 };
113 
114 struct wpi_power_group {
115 #define WPI_SAMPLES_COUNT	5
116 	struct wpi_power_sample samples[WPI_SAMPLES_COUNT];
117 	uint8_t	chan;
118 	int8_t	maxpwr;
119 	int16_t	temp;
120 };
121 
122 struct wpi_vap {
123 	struct ieee80211vap	vap;
124 
125 	int			(*newstate)(struct ieee80211vap *,
126 				    enum ieee80211_state, int);
127 };
128 #define	WPI_VAP(vap)	((struct wpi_vap *)(vap))
129 
130 struct wpi_softc {
131 	device_t		sc_dev;
132 	struct ifnet		*sc_ifp;
133 	struct mtx		sc_mtx;
134 
135 	/* Flags indicating the current state the driver
136 	 * expects the hardware to be in
137 	 */
138 	uint32_t		flags;
139 #define WPI_FLAG_HW_RADIO_OFF	(1 << 0)
140 #define WPI_FLAG_BUSY		(1 << 1)
141 #define WPI_FLAG_AUTH		(1 << 2)
142 
143 	/* shared area */
144 	struct wpi_dma_info	shared_dma;
145 	struct wpi_shared	*shared;
146 
147 	struct wpi_tx_ring	txq[WME_NUM_AC];
148 	struct wpi_tx_ring	cmdq;
149 	struct wpi_rx_ring	rxq;
150 
151 	/* TX Thermal Callibration */
152 	struct callout		calib_to;
153 	int			calib_cnt;
154 
155 	/* Watch dog timer */
156 	struct callout		watchdog_to;
157 	/* Hardware switch polling timer */
158 	struct callout		hwswitch_to;
159 
160 	struct resource		*irq;
161 	struct resource		*mem;
162 	bus_space_tag_t		sc_st;
163 	bus_space_handle_t	sc_sh;
164 	void			*sc_ih;
165 	int			mem_rid;
166 	int			irq_rid;
167 
168 	struct wpi_config	config;
169 	int			temp;
170 
171 
172 	int			sc_tx_timer;
173 	int			sc_scan_timer;
174 
175 	struct bpf_if		*sc_drvbpf;
176 
177 	struct wpi_rx_radiotap_header sc_rxtap;
178 	struct wpi_tx_radiotap_header sc_txtap;
179 
180 	/* firmware image */
181 	const struct firmware	*fw_fp;
182 
183 	/* firmware DMA transfer */
184 	struct wpi_dma_info	fw_dma;
185 
186 	/* Tasks used by the driver */
187 	struct task		sc_restarttask;	/* reset firmware task */
188 	struct task		sc_radiotask;	/* reset rf task */
189 
190        /* Eeprom info */
191 	uint8_t			cap;
192 	uint16_t		rev;
193 	uint8_t			type;
194 	struct wpi_power_group	groups[WPI_POWER_GROUPS_COUNT];
195 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
196 	char			domain[4];	/*reglatory domain XXX */
197 };
198 #define WPI_LOCK_INIT(_sc) \
199 	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
200             MTX_NETWORK_LOCK, MTX_DEF)
201 #define WPI_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
202 #define WPI_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
203 #define WPI_LOCK_ASSERT(sc)     mtx_assert(&(sc)->sc_mtx, MA_OWNED)
204 #define WPI_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
205