Disable RTS threshold when A-MSDU Tx is enabled
[ralink_drivers/rt2860_fbsd72.git] / rt2860_softc.h
blobbd9fb87d1ba5651918bc7ac89747e115df4dc49b
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 _RT2860_SOFTC_H_
20 #define _RT2860_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/module.h>
32 #include <sys/bus.h>
33 #include <sys/endian.h>
35 #include <machine/bus.h>
36 #include <machine/resource.h>
37 #include <sys/rman.h>
39 #include <net/bpf.h>
40 #include <net/if.h>
41 #include <net/if_arp.h>
42 #include <net/ethernet.h>
43 #include <net/if_dl.h>
44 #include <net/if_media.h>
45 #include <net/if_types.h>
47 #include <net80211/ieee80211_var.h>
48 #include <net80211/ieee80211_input.h>
49 #include <net80211/ieee80211_radiotap.h>
50 #include <net80211/ieee80211_regdomain.h>
52 #include <dev/pci/pcireg.h>
53 #include <dev/pci/pcivar.h>
55 #include "rt2860_rxdesc.h"
56 #include "rt2860_txdesc.h"
57 #include "rt2860_amrr.h"
59 #define RT2860_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
60 #define RT2860_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
61 #define RT2860_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
63 #define RT2860_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
65 #define RT2860_SOFTC_LED_OFF_COUNT 3
67 #define RT2860_SOFTC_RSSI_OFF_COUNT 3
69 #define RT2860_SOFTC_LNA_GAIN_COUNT 4
71 #define RT2860_SOFTC_TXPOW_COUNT 50
73 #define RT2860_SOFTC_TXPOW_RATE_COUNT 5
75 #define RT2860_SOFTC_TSSI_COUNT 9
77 #define RT2860_SOFTC_BBP_EEPROM_COUNT 8
79 #define RT2860_SOFTC_AMRR_NODE_COUNT 256
81 #define RT2860_SOFTC_RSSI_DBM_COUNT 3
83 #define RT2860_SOFTC_TX_RING_COUNT 6
85 #define RT2860_SOFTC_RX_RING_DATA_COUNT 128
87 #define RT2860_SOFTC_MAX_SCATTER 10
89 #define RT2860_SOFTC_TX_RING_DATA_COUNT 256
90 #define RT2860_SOFTC_TX_RING_DESC_COUNT \
91 (RT2860_SOFTC_TX_RING_DATA_COUNT * RT2860_SOFTC_MAX_SCATTER)
93 #define RT2860_SOFTC_RX_RADIOTAP_PRESENT \
94 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
95 (1 << IEEE80211_RADIOTAP_RATE) | \
96 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
97 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
98 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
99 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
100 (1 << IEEE80211_RADIOTAP_XCHANNEL))
102 #define RT2860_SOFTC_TX_RADIOTAP_PRESENT \
103 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
104 (1 << IEEE80211_RADIOTAP_RATE) | \
105 (1 << IEEE80211_RADIOTAP_XCHANNEL))
107 struct rt2860_softc_rx_data
109 bus_dmamap_t dma_map;
110 struct mbuf *m;
113 struct rt2860_softc_rx_ring
115 bus_dma_tag_t desc_dma_tag;
116 bus_dmamap_t desc_dma_map;
117 bus_addr_t desc_phys_addr;
118 struct rt2860_rxdesc *desc;
119 bus_dma_tag_t data_dma_tag;
120 bus_dmamap_t spare_dma_map;
121 struct rt2860_softc_rx_data data[RT2860_SOFTC_RX_RING_DATA_COUNT];
122 int cur;
125 struct rt2860_softc_tx_data
127 bus_dmamap_t dma_map;
128 struct ieee80211_node *ni;
129 struct mbuf *m;
132 struct rt2860_softc_tx_ring
134 bus_dma_tag_t desc_dma_tag;
135 bus_dmamap_t desc_dma_map;
136 bus_addr_t desc_phys_addr;
137 struct rt2860_txdesc *desc;
138 int desc_queued;
139 int desc_cur;
140 int desc_next;
141 bus_dma_tag_t seg0_dma_tag;
142 bus_dmamap_t seg0_dma_map;
143 bus_addr_t seg0_phys_addr;
144 uint8_t *seg0;
145 bus_dma_tag_t data_dma_tag;
146 struct rt2860_softc_tx_data data[RT2860_SOFTC_TX_RING_DATA_COUNT];
147 int data_queued;
148 int data_cur;
149 int data_next;
150 int qid;
153 struct rt2860_softc_node
155 struct ieee80211_node ni;
157 int8_t last_rssi_dbm[RT2860_SOFTC_RSSI_DBM_COUNT];
160 struct rt2860_softc_rx_radiotap_header
162 struct ieee80211_radiotap_header ihdr;
163 uint8_t flags;
164 uint8_t rate;
165 int8_t dbm_antsignal;
166 int8_t dbm_antnoise;
167 uint8_t antenna;
168 uint8_t antsignal;
169 uint32_t chan_flags;
170 uint16_t chan_freq;
171 uint8_t chan_ieee;
172 int8_t chan_maxpow;
175 struct rt2860_softc_tx_radiotap_header
177 struct ieee80211_radiotap_header ihdr;
178 uint8_t flags;
179 uint8_t rate;
180 uint32_t chan_flags;
181 uint16_t chan_freq;
182 uint8_t chan_ieee;
183 int8_t chan_maxpow;
186 struct rt2860_softc
188 struct mtx lock;
190 uint32_t flags;
192 device_t dev;
194 int mem_rid;
195 struct resource *mem;
197 int irq_rid;
198 struct resource *irq;
199 void *irqh;
201 bus_space_tag_t bst;
202 bus_space_handle_t bsh;
204 struct ifnet *ifp;
205 int if_flags;
207 struct ieee80211com ic;
209 struct ieee80211_beacon_offsets beacon_offsets;
211 struct rt2860_amrr amrr;
212 struct rt2860_amrr_node amrr_node[RT2860_SOFTC_AMRR_NODE_COUNT];
214 int (*newstate)(struct ieee80211com *ic,
215 enum ieee80211_state nstate, int arg);
217 int tx_ampdu_sessions;
219 void (*recv_action)(struct ieee80211_node *ni,
220 const uint8_t *frm, const uint8_t *efrm);
222 int (*send_action)(struct ieee80211_node *ni,
223 int category, int action, uint16_t args[4]);
225 uint32_t mac_rev;
226 uint8_t eeprom_addr_num;
227 uint16_t eeprom_rev;
228 uint8_t rf_rev;
230 uint8_t mac_addr[IEEE80211_ADDR_LEN];
232 uint8_t ntxpath;
233 uint8_t nrxpath;
235 int hw_radio_cntl;
236 int tx_agc_cntl;
237 int ext_lna_2ghz;
238 int ext_lna_5ghz;
240 uint8_t country_2ghz;
241 uint8_t country_5ghz;
243 uint8_t rf_freq_off;
245 uint8_t led_cntl;
246 uint16_t led_off[RT2860_SOFTC_LED_OFF_COUNT];
248 int8_t rssi_off_2ghz[RT2860_SOFTC_RSSI_OFF_COUNT];
249 int8_t rssi_off_5ghz[RT2860_SOFTC_RSSI_OFF_COUNT];
251 int8_t lna_gain[RT2860_SOFTC_LNA_GAIN_COUNT];
253 int8_t txpow1[RT2860_SOFTC_TXPOW_COUNT];
254 int8_t txpow2[RT2860_SOFTC_TXPOW_COUNT];
256 int8_t txpow_rate_delta_2ghz;
257 int8_t txpow_rate_delta_5ghz;
258 uint32_t txpow_rate_20mhz[RT2860_SOFTC_TXPOW_RATE_COUNT];
259 uint32_t txpow_rate_40mhz_2ghz[RT2860_SOFTC_TXPOW_RATE_COUNT];
260 uint32_t txpow_rate_40mhz_5ghz[RT2860_SOFTC_TXPOW_RATE_COUNT];
262 int tx_agc_cntl_2ghz;
263 int tx_agc_cntl_5ghz;
265 uint8_t tssi_2ghz[RT2860_SOFTC_TSSI_COUNT];
266 uint8_t tssi_step_2ghz;
267 uint8_t tssi_5ghz[RT2860_SOFTC_TSSI_COUNT];
268 uint8_t tssi_step_5ghz;
270 struct
272 uint8_t val;
273 uint8_t reg;
274 } __packed bbp_eeprom[RT2860_SOFTC_BBP_EEPROM_COUNT];
276 uint16_t powersave_level;
278 int sifs;
280 uint32_t intr_enable_mask;
281 uint32_t intr_disable_mask;
282 uint32_t intr_pending_mask;
284 struct task rx_done_task;
285 int rx_process_limit;
287 struct task tx_done_task;
289 struct task fifo_sta_full_task;
291 struct task periodic_task;
292 struct callout periodic_ch;
293 unsigned long periodic_round;
295 struct taskqueue *taskqueue;
297 struct rt2860_softc_rx_ring rx_ring;
299 struct rt2860_softc_tx_ring tx_ring[RT2860_SOFTC_TX_RING_COUNT];
300 int tx_ring_mgtqid;
302 struct callout tx_watchdog_ch;
303 int tx_timer;
305 struct bpf_if *drvbpf;
307 union
309 struct rt2860_softc_rx_radiotap_header th;
310 uint8_t pad[64];
311 } rxtapu;
313 #define rxtap rxtapu.th
315 int rxtap_len;
317 union
319 struct rt2860_softc_tx_radiotap_header th;
320 uint8_t pad[64];
321 } txtapu;
323 #define txtap txtapu.th
325 int txtap_len;
327 /* statistic counters */
329 unsigned long interrupts;
330 unsigned long tx_coherent_interrupts;
331 unsigned long rx_coherent_interrupts;
332 unsigned long txrx_coherent_interrupts;
333 unsigned long fifo_sta_full_interrupts;
334 unsigned long rx_interrupts;
335 unsigned long rx_delay_interrupts;
336 unsigned long tx_interrupts[RT2860_SOFTC_TX_RING_COUNT];
337 unsigned long tx_delay_interrupts;
338 unsigned long pre_tbtt_interrupts;
339 unsigned long tbtt_interrupts;
340 unsigned long mcu_cmd_interrupts;
341 unsigned long auto_wakeup_interrupts;
342 unsigned long gp_timer_interrupts;
344 unsigned long tx_data_queue_full[RT2860_SOFTC_TX_RING_COUNT];
346 unsigned long tx_watchdog_timeouts;
348 unsigned long tx_defrag_packets;
350 unsigned long no_tx_desc_avail;
352 unsigned long rx_mbuf_alloc_errors;
353 unsigned long rx_mbuf_dmamap_errors;
355 unsigned long tx_queue_not_empty[2];
357 unsigned long tx_beacons;
358 unsigned long tx_noretryok;
359 unsigned long tx_retryok;
360 unsigned long tx_failed;
361 unsigned long tx_underflows;
362 unsigned long tx_zerolen;
363 unsigned long tx_nonagg;
364 unsigned long tx_agg;
365 unsigned long tx_ampdu;
366 unsigned long tx_mpdu_zero_density;
368 unsigned long rx_packets;
369 unsigned long rx_ampdu;
370 unsigned long rx_mpdu_zero_density;
371 unsigned long rx_amsdu;
372 unsigned long rx_crc_errors;
373 unsigned long rx_phy_errors;
374 unsigned long rx_false_ccas;
375 unsigned long rx_plcp_errors;
376 unsigned long rx_dup_packets;
377 unsigned long rx_fifo_overflows;
379 #ifdef RT2860_DEBUG
380 int debug;
381 #endif
384 #endif /* #ifndef _RT2860_SOFTC_H_ */