Added BBP tuning
[ralink_drivers/rt2870_fbsd72.git] / rt2870_softc.h
bloba44364e11e7503d6b9f00f7e94feec8950c3bf1c
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 <dev/usb/usbdi_util.h>
56 #include "usbdevs.h"
58 #include "rt2870_amrr.h"
60 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&Giant)
61 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&Giant)
63 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
65 #define RT2870_SOFTC_LED_OFF_COUNT 3
67 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
69 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
71 #define RT2870_SOFTC_TXPOW_COUNT 50
73 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
75 #define RT2870_SOFTC_TSSI_COUNT 9
77 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
79 #define RT2870_SOFTC_AMRR_NODE_COUNT 256
81 #define RT2870_SOFTC_TX_RING_COUNT 6
83 #define RT2870_SOFTC_RX_RING_DATA_COUNT 1
85 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
87 #define RT2870_SOFTC_CMD_DATA_LEN 256
88 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
90 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
91 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
92 (1 << IEEE80211_RADIOTAP_RATE) | \
93 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
94 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
95 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
96 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
97 (1 << IEEE80211_RADIOTAP_XCHANNEL))
99 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
100 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
101 (1 << IEEE80211_RADIOTAP_RATE) | \
102 (1 << IEEE80211_RADIOTAP_XCHANNEL))
105 struct rt2870_softc_rx_data
107 STAILQ_ENTRY(rt2870_softc_rx_data) next;
108 usbd_xfer_handle xfer;
109 uint8_t *buf;
110 uint16_t len;
113 typedef STAILQ_HEAD(, rt2870_softc_rx_data) rt2870_softc_rx_data_queue;
115 struct rt2870_softc_rx_ring
117 int usb_ep;
118 usbd_pipe_handle usb_pipe;
119 struct rt2870_softc_rx_data data[RT2870_SOFTC_RX_RING_DATA_COUNT];
120 rt2870_softc_rx_data_queue active;
121 rt2870_softc_rx_data_queue done;
124 struct rt2870_softc_tx_data
126 STAILQ_ENTRY(rt2870_softc_tx_data) next;
127 struct ieee80211_node *ni;
128 usbd_xfer_handle xfer;
129 uint8_t *buf;
130 struct mbuf *m;
133 typedef STAILQ_HEAD(, rt2870_softc_tx_data) rt2870_softc_tx_data_queue;
135 struct rt2870_softc_tx_ring
137 int usb_ep;
138 usbd_pipe_handle usb_pipe;
139 struct rt2870_softc *sc;
140 struct rt2870_softc_tx_data data[RT2870_SOFTC_TX_RING_DATA_COUNT];
141 rt2870_softc_tx_data_queue inactive;
142 rt2870_softc_tx_data_queue active;
143 rt2870_softc_tx_data_queue done;
144 int queued;
145 int qid;
148 struct rt2870_softc_cmd
150 STAILQ_ENTRY(rt2870_softc_cmd) next;
151 void (*cb)(struct rt2870_softc *sc, void *arg);
152 uint8_t data[RT2870_SOFTC_CMD_DATA_LEN];
155 typedef STAILQ_HEAD(, rt2870_softc_cmd) rt2870_softc_cmd_queue;
157 struct rt2870_softc_cmd_ring
159 struct rt2870_softc_cmd cmd[RT2870_SOFTC_CMD_RING_CMD_COUNT];
160 rt2870_softc_cmd_queue inactive;
161 rt2870_softc_cmd_queue active;
162 int queued;
165 struct rt2870_softc_rx_radiotap_header
167 struct ieee80211_radiotap_header ihdr;
168 uint8_t flags;
169 uint8_t rate;
170 int8_t dbm_antsignal;
171 int8_t dbm_antnoise;
172 uint8_t antenna;
173 uint8_t antsignal;
174 uint32_t chan_flags;
175 uint16_t chan_freq;
176 uint8_t chan_ieee;
177 int8_t chan_maxpow;
180 struct rt2870_softc_tx_radiotap_header
182 struct ieee80211_radiotap_header ihdr;
183 uint8_t flags;
184 uint8_t rate;
185 uint32_t chan_flags;
186 uint16_t chan_freq;
187 uint8_t chan_ieee;
188 int8_t chan_maxpow;
191 struct rt2870_softc
193 uint32_t flags;
195 device_t dev;
197 int usb_endpoints;
198 usbd_device_handle usb_dev;
199 usbd_interface_handle usb_iface;
201 struct ifnet *ifp;
202 int if_flags;
204 struct ieee80211com ic;
206 struct ieee80211_beacon_offsets beacon_offsets;
208 struct rt2870_amrr amrr;
209 struct rt2870_amrr_node amrr_node[RT2870_SOFTC_AMRR_NODE_COUNT];
211 int (*newstate)(struct ieee80211com *ic,
212 enum ieee80211_state nstate, int arg);
214 int tx_ampdu_sessions;
216 void (*recv_action)(struct ieee80211_node *ni,
217 const uint8_t *frm, const uint8_t *efrm);
219 int (*send_action)(struct ieee80211_node *ni,
220 int category, int action, uint16_t args[4]);
222 uint32_t mac_rev;
223 uint16_t eeprom_rev;
224 uint8_t rf_rev;
226 uint8_t mac_addr[IEEE80211_ADDR_LEN];
228 uint8_t ntxpath;
229 uint8_t nrxpath;
231 int hw_radio_cntl;
232 int tx_agc_cntl;
233 int ext_lna_2ghz;
234 int ext_lna_5ghz;
236 uint8_t country_2ghz;
237 uint8_t country_5ghz;
239 uint8_t rf_freq_off;
241 uint8_t led_cntl;
242 uint16_t led_off[RT2870_SOFTC_LED_OFF_COUNT];
244 int8_t rssi_off_2ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
245 int8_t rssi_off_5ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
247 int8_t lna_gain[RT2870_SOFTC_LNA_GAIN_COUNT];
249 int8_t txpow1[RT2870_SOFTC_TXPOW_COUNT];
250 int8_t txpow2[RT2870_SOFTC_TXPOW_COUNT];
252 int8_t txpow_rate_delta_2ghz;
253 int8_t txpow_rate_delta_5ghz;
254 uint32_t txpow_rate_20mhz[RT2870_SOFTC_TXPOW_RATE_COUNT];
255 uint32_t txpow_rate_40mhz_2ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
256 uint32_t txpow_rate_40mhz_5ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
258 int tx_agc_cntl_2ghz;
259 int tx_agc_cntl_5ghz;
261 uint8_t tssi_2ghz[RT2870_SOFTC_TSSI_COUNT];
262 uint8_t tssi_step_2ghz;
263 uint8_t tssi_5ghz[RT2870_SOFTC_TSSI_COUNT];
264 uint8_t tssi_step_5ghz;
266 struct
268 uint8_t val;
269 uint8_t reg;
270 } __packed bbp_eeprom[RT2870_SOFTC_BBP_EEPROM_COUNT];
272 int sifs;
274 struct task rx_done_task;
275 int rx_process_limit;
277 struct task tx_done_task;
278 uint32_t tx_qid_pending_mask;
280 struct task periodic_task;
281 struct callout periodic_ch;
282 unsigned long periodic_round;
284 struct task cmd_task;
286 struct taskqueue *taskqueue;
288 struct rt2870_softc_rx_ring rx_ring;
290 struct rt2870_softc_tx_ring tx_ring[RT2870_SOFTC_TX_RING_COUNT];
291 int tx_ring_mgtqid;
293 struct callout tx_watchdog_ch;
294 int tx_timer;
296 struct rt2870_softc_cmd_ring cmd_ring;
298 struct bpf_if *drvbpf;
300 union
302 struct rt2870_softc_rx_radiotap_header th;
303 uint8_t pad[64];
304 } rxtapu;
306 #define rxtap rxtapu.th
308 int rxtap_len;
310 union
312 struct rt2870_softc_tx_radiotap_header th;
313 uint8_t pad[64];
314 } txtapu;
316 #define txtap txtapu.th
318 int txtap_len;
320 /* statistic counters */
322 unsigned long interrupts;
323 unsigned long rx_interrupts;
324 unsigned long tx_interrupts[RT2870_SOFTC_TX_RING_COUNT];
326 unsigned long tx_data_queue_full[RT2870_SOFTC_TX_RING_COUNT];
328 unsigned long tx_watchdog_timeouts;
330 unsigned long rx_mbuf_alloc_errors;
332 unsigned long tx_queue_not_empty[2];
334 unsigned long tx_beacons;
335 unsigned long tx_noretryok;
336 unsigned long tx_retryok;
337 unsigned long tx_failed;
338 unsigned long tx_nonagg;
339 unsigned long tx_agg;
340 unsigned long tx_ampdu;
342 unsigned long rx_packets;
343 unsigned long rx_ampdu;
344 unsigned long rx_amsdu;
345 unsigned long rx_crc_errors;
346 unsigned long rx_phy_errors;
347 unsigned long rx_false_ccas;
348 unsigned long rx_plcp_errors;
349 unsigned long rx_dup_packets;
350 unsigned long rx_fifo_overflows;
352 #ifdef RT2870_DEBUG
353 int debug;
354 #endif
357 #endif /* #ifndef _RT2870_SOFTC_H_ */