Added new USB device Ralink RT2870
[ralink_drivers/rt2870_fbsd8.git] / rt2870_softc.h
blobb50171d63910c04a050920335f53fab5303159af
2 /*-
3 * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@gmail.com>
4 * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
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.
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.
19 #ifndef _RT2870_SOFTC_H_
20 #define _RT2870_SOFTC_H_
22 #include <sys/param.h>
23 #include <sys/sysctl.h>
24 #include <sys/sockio.h>
25 #include <sys/mbuf.h>
26 #include <sys/kernel.h>
27 #include <sys/socket.h>
28 #include <sys/systm.h>
29 #include <sys/malloc.h>
30 #include <sys/taskqueue.h>
31 #include <sys/queue.h>
32 #include <sys/module.h>
33 #include <sys/bus.h>
34 #include <sys/endian.h>
36 #include <machine/bus.h>
37 #include <machine/resource.h>
38 #include <sys/rman.h>
40 #include <net/bpf.h>
41 #include <net/if.h>
42 #include <net/if_arp.h>
43 #include <net/ethernet.h>
44 #include <net/if_dl.h>
45 #include <net/if_media.h>
46 #include <net/if_types.h>
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_input.h>
50 #include <net80211/ieee80211_radiotap.h>
51 #include <net80211/ieee80211_regdomain.h>
53 #include <dev/usb/usb.h>
54 #include <dev/usb/usbdi.h>
55 #include "usbdevs.h"
57 #include "rt2870_txwi.h"
58 #include "rt2870_amrr.h"
60 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
61 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
62 #define RT2870_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
64 #define RT2870_SOFTC_FLAGS_VALID (1 << 0)
65 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 1)
67 #define RT2870_SOFTC_USB_XFER_COUNT (1 + RT2870_SOFTC_TX_RING_COUNT)
69 #define RT2870_SOFTC_LED_OFF_COUNT 3
71 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
73 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
75 #define RT2870_SOFTC_TXPOW_COUNT 50
77 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
79 #define RT2870_SOFTC_TSSI_COUNT 9
81 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
83 #define RT2870_SOFTC_RSSI_COUNT 3
85 #define RT2870_SOFTC_STAID_COUNT 64
87 #define RT2870_SOFTC_TX_RING_COUNT 6
89 #define RT2870_SOFTC_RX_RING_DATA_COUNT 256
91 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
93 #define RT2870_SOFTC_CMD_DATA_LEN 256
94 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
96 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
97 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
98 (1 << IEEE80211_RADIOTAP_RATE) | \
99 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
100 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
101 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
102 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
103 (1 << IEEE80211_RADIOTAP_XCHANNEL))
105 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
106 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
107 (1 << IEEE80211_RADIOTAP_RATE) | \
108 (1 << IEEE80211_RADIOTAP_XCHANNEL))
110 struct rt2870_softc;
112 struct rt2870_softc_rx_data
114 STAILQ_ENTRY(rt2870_softc_rx_data) next;
115 uint8_t *buf;
116 uint16_t len;
119 typedef STAILQ_HEAD(, rt2870_softc_rx_data) rt2870_softc_rx_data_queue;
121 struct rt2870_softc_rx_ring
123 struct rt2870_softc_rx_data data[RT2870_SOFTC_RX_RING_DATA_COUNT];
124 rt2870_softc_rx_data_queue inactive;
125 rt2870_softc_rx_data_queue active;
126 rt2870_softc_rx_data_queue done;
129 struct rt2870_softc_tx_data
131 STAILQ_ENTRY(rt2870_softc_tx_data) next;
132 struct ieee80211_node *ni;
133 uint8_t *buf;
134 uint16_t len;
135 struct mbuf *m;
138 typedef STAILQ_HEAD(, rt2870_softc_tx_data) rt2870_softc_tx_data_queue;
140 struct rt2870_softc_tx_ring
142 struct rt2870_softc_tx_data data[RT2870_SOFTC_TX_RING_DATA_COUNT];
143 rt2870_softc_tx_data_queue inactive;
144 rt2870_softc_tx_data_queue pending;
145 rt2870_softc_tx_data_queue active;
146 rt2870_softc_tx_data_queue done;
147 int queued;
148 int qid;
151 struct rt2870_softc_cmd
153 STAILQ_ENTRY(rt2870_softc_cmd) next;
154 void (*cb)(struct rt2870_softc *sc, void *arg);
155 uint8_t data[RT2870_SOFTC_CMD_DATA_LEN];
158 typedef STAILQ_HEAD(, rt2870_softc_cmd) rt2870_softc_cmd_queue;
160 struct rt2870_softc_cmd_ring
162 struct rt2870_softc_cmd cmd[RT2870_SOFTC_CMD_RING_CMD_COUNT];
163 rt2870_softc_cmd_queue inactive;
164 rt2870_softc_cmd_queue active;
165 int queued;
168 struct rt2870_softc_node
170 struct ieee80211_node ni;
172 uint8_t staid;
174 uint8_t last_rssi[RT2870_SOFTC_RSSI_COUNT];
175 int8_t last_rssi_dbm[RT2870_SOFTC_RSSI_COUNT];
178 struct rt2870_softc_vap
180 struct ieee80211vap vap;
182 struct ieee80211_beacon_offsets beacon_offsets;
183 struct mbuf *beacon_mbuf;
184 struct rt2870_txwi beacon_txwi;
186 struct rt2870_amrr amrr;
188 int (*newstate)(struct ieee80211vap *vap,
189 enum ieee80211_state nstate, int arg);
192 struct rt2870_softc_rx_radiotap_header
194 struct ieee80211_radiotap_header ihdr;
195 uint8_t flags;
196 uint8_t rate;
197 int8_t dbm_antsignal;
198 int8_t dbm_antnoise;
199 uint8_t antenna;
200 uint8_t antsignal;
201 uint8_t pad[2];
202 uint32_t chan_flags;
203 uint16_t chan_freq;
204 uint8_t chan_ieee;
205 int8_t chan_maxpow;
206 } __packed;
208 struct rt2870_softc_tx_radiotap_header
210 struct ieee80211_radiotap_header ihdr;
211 uint8_t flags;
212 uint8_t rate;
213 uint8_t pad[2];
214 uint32_t chan_flags;
215 uint16_t chan_freq;
216 uint8_t chan_ieee;
217 int8_t chan_maxpow;
218 } __packed;
220 struct rt2870_softc
222 struct mtx lock;
224 uint32_t flags;
226 device_t dev;
228 int usb_endpoints;
229 struct usb_device *usb_dev;
230 struct usb_xfer *usb_xfer[1 + RT2870_SOFTC_TX_RING_COUNT];
232 struct ifnet *ifp;
233 int if_flags;
235 int nvaps;
236 int napvaps;
237 int nadhocvaps;
238 int nstavaps;
239 int nwdsvaps;
241 void (*node_cleanup)(struct ieee80211_node *ni);
243 int (*recv_action)(struct ieee80211_node *ni,
244 const struct ieee80211_frame *wh,
245 const uint8_t *frm, const uint8_t *efrm);
247 int (*send_action)(struct ieee80211_node *ni,
248 int cat, int act, void *sa);
250 int (*addba_response)(struct ieee80211_node *ni,
251 struct ieee80211_tx_ampdu *tap,
252 int status, int baparamset, int batimeout);
254 void (*addba_stop)(struct ieee80211_node *ni,
255 struct ieee80211_tx_ampdu *tap);
257 int (*ampdu_rx_start)(struct ieee80211_node *ni,
258 struct ieee80211_rx_ampdu *rap,
259 int baparamset, int batimeout, int baseqctl);
261 void (*ampdu_rx_stop)(struct ieee80211_node *ni,
262 struct ieee80211_rx_ampdu *rap);
264 struct rt2870_amrr_node amrr_node[RT2870_SOFTC_STAID_COUNT];
266 uint32_t mac_rev;
267 uint16_t eeprom_rev;
268 uint8_t rf_rev;
270 uint8_t mac_addr[IEEE80211_ADDR_LEN];
272 uint8_t ntxpath;
273 uint8_t nrxpath;
275 int hw_radio_cntl;
276 int tx_agc_cntl;
277 int ext_lna_2ghz;
278 int ext_lna_5ghz;
280 uint8_t country_2ghz;
281 uint8_t country_5ghz;
283 uint8_t rf_freq_off;
285 uint8_t led_cntl;
286 uint16_t led_off[RT2870_SOFTC_LED_OFF_COUNT];
288 int8_t rssi_off_2ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
289 int8_t rssi_off_5ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
291 int8_t lna_gain[RT2870_SOFTC_LNA_GAIN_COUNT];
293 int8_t txpow1[RT2870_SOFTC_TXPOW_COUNT];
294 int8_t txpow2[RT2870_SOFTC_TXPOW_COUNT];
296 int8_t txpow_rate_delta_2ghz;
297 int8_t txpow_rate_delta_5ghz;
298 uint32_t txpow_rate_20mhz[RT2870_SOFTC_TXPOW_RATE_COUNT];
299 uint32_t txpow_rate_40mhz_2ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
300 uint32_t txpow_rate_40mhz_5ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
302 int tx_agc_cntl_2ghz;
303 int tx_agc_cntl_5ghz;
305 uint8_t tssi_2ghz[RT2870_SOFTC_TSSI_COUNT];
306 uint8_t tssi_step_2ghz;
307 uint8_t tssi_5ghz[RT2870_SOFTC_TSSI_COUNT];
308 uint8_t tssi_step_5ghz;
310 struct
312 uint8_t val;
313 uint8_t reg;
314 } __packed bbp_eeprom[RT2870_SOFTC_BBP_EEPROM_COUNT];
316 uint8_t staid_mask[RT2870_SOFTC_STAID_COUNT / NBBY];
318 struct task rx_done_task;
319 int rx_process_limit;
321 struct task tx_done_task;
322 uint32_t tx_qid_pending_mask;
324 struct task periodic_task;
325 struct callout periodic_ch;
326 unsigned long periodic_round;
328 struct task cmd_task;
330 struct taskqueue *taskqueue;
332 struct rt2870_softc_rx_ring rx_ring;
334 struct rt2870_softc_tx_ring tx_ring[RT2870_SOFTC_TX_RING_COUNT];
335 int tx_ring_mgtqid;
337 struct callout tx_watchdog_ch;
338 int tx_timer;
340 struct rt2870_softc_cmd_ring cmd_ring;
342 struct rt2870_softc_rx_radiotap_header rxtap;
343 struct rt2870_softc_tx_radiotap_header txtap;
345 /* statistic counters */
347 unsigned long interrupts;
348 unsigned long rx_interrupts;
349 unsigned long tx_interrupts[RT2870_SOFTC_TX_RING_COUNT];
351 unsigned long tx_data_queue_full[RT2870_SOFTC_TX_RING_COUNT];
353 unsigned long tx_watchdog_timeouts;
355 unsigned long rx_mbuf_alloc_errors;
357 unsigned long tx_queue_not_empty[2];
359 unsigned long tx_beacons;
360 unsigned long tx_noretryok;
361 unsigned long tx_retryok;
362 unsigned long tx_failed;
363 unsigned long tx_underflows;
364 unsigned long tx_zerolen;
365 unsigned long tx_nonagg;
366 unsigned long tx_agg;
367 unsigned long tx_ampdu;
368 unsigned long tx_mpdu_zero_density;
369 unsigned long tx_ampdu_sessions;
371 unsigned long rx_packets;
372 unsigned long rx_ampdu;
373 unsigned long rx_ampdu_retries;
374 unsigned long rx_mpdu_zero_density;
375 unsigned long rx_ampdu_sessions;
376 unsigned long rx_amsdu;
377 unsigned long rx_crc_errors;
378 unsigned long rx_phy_errors;
379 unsigned long rx_false_ccas;
380 unsigned long rx_plcp_errors;
381 unsigned long rx_dup_packets;
382 unsigned long rx_fifo_overflows;
383 unsigned long rx_cipher_no_errors;
384 unsigned long rx_cipher_icv_errors;
385 unsigned long rx_cipher_mic_errors;
386 unsigned long rx_cipher_invalid_key_errors;
388 int tx_stbc;
390 #ifdef RT2870_DEBUG
391 int debug;
392 #endif
395 #endif /* #ifndef _RT2870_SOFTC_H_ */