A-MPDU Tx support; Increased size of Tx ring to 256
[ralink_drivers/rt2870_fbsd8.git] / rt2870_softc.h
blob3399dd87956a1e5fc41dd630ab4cbc6073542e40
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_amrr.h"
59 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
60 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
61 #define RT2870_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
63 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
65 #define RT2870_SOFTC_USB_XFER_COUNT (1 + RT2870_SOFTC_TX_RING_COUNT)
67 #define RT2870_SOFTC_LED_OFF_COUNT 3
69 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
71 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
73 #define RT2870_SOFTC_TXPOW_COUNT 50
75 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
77 #define RT2870_SOFTC_TSSI_COUNT 9
79 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
81 #define RT2870_SOFTC_AMRR_NODE_COUNT 256
83 #define RT2870_SOFTC_TX_RING_COUNT 6
85 #define RT2870_SOFTC_RX_RING_DATA_COUNT 128
87 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
89 #define RT2870_SOFTC_CMD_DATA_LEN 256
90 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
92 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
93 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
94 (1 << IEEE80211_RADIOTAP_RATE) | \
95 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
96 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
97 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
98 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
99 (1 << IEEE80211_RADIOTAP_XCHANNEL))
101 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
102 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
103 (1 << IEEE80211_RADIOTAP_RATE) | \
104 (1 << IEEE80211_RADIOTAP_XCHANNEL))
106 struct rt2870_softc;
108 struct rt2870_softc_rx_data
110 STAILQ_ENTRY(rt2870_softc_rx_data) next;
111 uint8_t *buf;
112 uint16_t len;
115 typedef STAILQ_HEAD(, rt2870_softc_rx_data) rt2870_softc_rx_data_queue;
117 struct rt2870_softc_rx_ring
119 struct rt2870_softc_rx_data data[RT2870_SOFTC_RX_RING_DATA_COUNT];
120 rt2870_softc_rx_data_queue inactive;
121 rt2870_softc_rx_data_queue active;
122 rt2870_softc_rx_data_queue done;
125 struct rt2870_softc_tx_data
127 STAILQ_ENTRY(rt2870_softc_tx_data) next;
128 struct ieee80211_node *ni;
129 uint8_t *buf;
130 uint16_t len;
131 struct mbuf *m;
134 typedef STAILQ_HEAD(, rt2870_softc_tx_data) rt2870_softc_tx_data_queue;
136 struct rt2870_softc_tx_ring
138 struct rt2870_softc_tx_data data[RT2870_SOFTC_TX_RING_DATA_COUNT];
139 rt2870_softc_tx_data_queue inactive;
140 rt2870_softc_tx_data_queue pending;
141 rt2870_softc_tx_data_queue active;
142 rt2870_softc_tx_data_queue done;
143 int queued;
144 int qid;
147 struct rt2870_softc_cmd
149 STAILQ_ENTRY(rt2870_softc_cmd) next;
150 void (*cb)(struct rt2870_softc *sc, void *arg);
151 uint8_t data[RT2870_SOFTC_CMD_DATA_LEN];
154 typedef STAILQ_HEAD(, rt2870_softc_cmd) rt2870_softc_cmd_queue;
156 struct rt2870_softc_cmd_ring
158 struct rt2870_softc_cmd cmd[RT2870_SOFTC_CMD_RING_CMD_COUNT];
159 rt2870_softc_cmd_queue inactive;
160 rt2870_softc_cmd_queue active;
161 int queued;
164 struct rt2870_softc_node
166 struct ieee80211_node ni;
169 struct rt2870_softc_vap
171 struct ieee80211vap vap;
172 struct ieee80211_beacon_offsets beacon_offsets;
173 struct rt2870_amrr amrr;
175 int (*newstate)(struct ieee80211vap *vap,
176 enum ieee80211_state nstate, int arg);
179 struct rt2870_softc_rx_radiotap_header
181 struct ieee80211_radiotap_header ihdr;
182 uint8_t flags;
183 uint8_t rate;
184 int8_t dbm_antsignal;
185 int8_t dbm_antnoise;
186 uint8_t antenna;
187 uint8_t antsignal;
188 uint8_t pad[2];
189 uint32_t chan_flags;
190 uint16_t chan_freq;
191 uint8_t chan_ieee;
192 int8_t chan_maxpow;
193 } __packed;
195 struct rt2870_softc_tx_radiotap_header
197 struct ieee80211_radiotap_header ihdr;
198 uint8_t flags;
199 uint8_t rate;
200 uint8_t pad[2];
201 uint32_t chan_flags;
202 uint16_t chan_freq;
203 uint8_t chan_ieee;
204 int8_t chan_maxpow;
205 } __packed;
207 struct rt2870_softc
209 struct mtx lock;
211 uint32_t flags;
213 device_t dev;
215 int usb_endpoints;
216 struct usb_device *usb_dev;
217 struct usb_xfer *usb_xfer[1 + RT2870_SOFTC_TX_RING_COUNT];
219 struct ifnet *ifp;
220 int if_flags;
222 int tx_ampdu_sessions;
224 int (*recv_action)(struct ieee80211_node *ni,
225 const struct ieee80211_frame *wh,
226 const uint8_t *frm, const uint8_t *efrm);
228 int (*send_action)(struct ieee80211_node *ni,
229 int cat, int act, void *sa);
231 struct rt2870_amrr_node amrr_node[RT2870_SOFTC_AMRR_NODE_COUNT];
233 uint32_t mac_rev;
234 uint16_t eeprom_rev;
235 uint8_t rf_rev;
237 uint8_t mac_addr[IEEE80211_ADDR_LEN];
239 uint8_t ntxpath;
240 uint8_t nrxpath;
242 int hw_radio_cntl;
243 int tx_agc_cntl;
244 int ext_lna_2ghz;
245 int ext_lna_5ghz;
247 uint8_t country_2ghz;
248 uint8_t country_5ghz;
250 uint8_t rf_freq_off;
252 uint8_t led_cntl;
253 uint16_t led_off[RT2870_SOFTC_LED_OFF_COUNT];
255 int8_t rssi_off_2ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
256 int8_t rssi_off_5ghz[RT2870_SOFTC_RSSI_OFF_COUNT];
258 int8_t lna_gain[RT2870_SOFTC_LNA_GAIN_COUNT];
260 int8_t txpow1[RT2870_SOFTC_TXPOW_COUNT];
261 int8_t txpow2[RT2870_SOFTC_TXPOW_COUNT];
263 int8_t txpow_rate_delta_2ghz;
264 int8_t txpow_rate_delta_5ghz;
265 uint32_t txpow_rate_20mhz[RT2870_SOFTC_TXPOW_RATE_COUNT];
266 uint32_t txpow_rate_40mhz_2ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
267 uint32_t txpow_rate_40mhz_5ghz[RT2870_SOFTC_TXPOW_RATE_COUNT];
269 int tx_agc_cntl_2ghz;
270 int tx_agc_cntl_5ghz;
272 uint8_t tssi_2ghz[RT2870_SOFTC_TSSI_COUNT];
273 uint8_t tssi_step_2ghz;
274 uint8_t tssi_5ghz[RT2870_SOFTC_TSSI_COUNT];
275 uint8_t tssi_step_5ghz;
277 struct
279 uint8_t val;
280 uint8_t reg;
281 } __packed bbp_eeprom[RT2870_SOFTC_BBP_EEPROM_COUNT];
283 struct task rx_done_task;
284 int rx_process_limit;
286 struct task tx_done_task;
287 uint32_t tx_qid_pending_mask;
289 struct task periodic_task;
290 struct callout periodic_ch;
291 unsigned long periodic_round;
293 struct task cmd_task;
295 struct taskqueue *taskqueue;
297 struct rt2870_softc_rx_ring rx_ring;
299 struct rt2870_softc_tx_ring tx_ring[RT2870_SOFTC_TX_RING_COUNT];
300 int tx_ring_mgtqid;
302 struct callout tx_watchdog_ch;
303 int tx_timer;
305 struct rt2870_softc_cmd_ring cmd_ring;
307 struct rt2870_softc_rx_radiotap_header rxtap;
308 struct rt2870_softc_tx_radiotap_header txtap;
310 /* statistic counters */
312 unsigned long interrupts;
313 unsigned long rx_interrupts;
314 unsigned long tx_interrupts[RT2870_SOFTC_TX_RING_COUNT];
316 unsigned long tx_data_queue_full[RT2870_SOFTC_TX_RING_COUNT];
318 unsigned long tx_watchdog_timeouts;
320 unsigned long rx_mbuf_alloc_errors;
322 unsigned long tx_queue_not_empty[2];
324 unsigned long tx_beacons;
325 unsigned long tx_noretryok;
326 unsigned long tx_retryok;
327 unsigned long tx_failed;
328 unsigned long tx_nonagg;
329 unsigned long tx_agg;
330 unsigned long tx_ampdu;
332 unsigned long rx_packets;
333 unsigned long rx_ampdu;
334 unsigned long rx_amsdu;
335 unsigned long rx_crc_errors;
336 unsigned long rx_phy_errors;
337 unsigned long rx_false_ccas;
338 unsigned long rx_plcp_errors;
339 unsigned long rx_dup_packets;
340 unsigned long rx_fifo_overflows;
342 #ifdef RT2870_DEBUG
343 int debug;
344 #endif
347 #endif /* #ifndef _RT2870_SOFTC_H_ */