Use ni_chw field in ieee80211_node to choose the right bandwidth during Tx
[ralink_drivers/rt2860_fbsd72.git] / rt2860_softc.h
blobb2418ef1dd02c15068f338ffb492c2b602d8ea51
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_TX_RING_COUNT 6
83 #define RT2860_SOFTC_RX_RING_DATA_COUNT 128
85 #define RT2860_SOFTC_MAX_SCATTER 10
87 #define RT2860_SOFTC_TX_RING_DATA_COUNT 256
88 #define RT2860_SOFTC_TX_RING_DESC_COUNT \
89 (RT2860_SOFTC_TX_RING_DATA_COUNT * RT2860_SOFTC_MAX_SCATTER)
91 #define RT2860_SOFTC_RX_RADIOTAP_PRESENT \
92 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
93 (1 << IEEE80211_RADIOTAP_RATE) | \
94 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
95 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
96 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
97 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
98 (1 << IEEE80211_RADIOTAP_XCHANNEL))
100 #define RT2860_SOFTC_TX_RADIOTAP_PRESENT \
101 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
102 (1 << IEEE80211_RADIOTAP_RATE) | \
103 (1 << IEEE80211_RADIOTAP_XCHANNEL))
105 struct rt2860_softc_rx_data
107 bus_dmamap_t dma_map;
108 struct mbuf *m;
111 struct rt2860_softc_rx_ring
113 bus_dma_tag_t desc_dma_tag;
114 bus_dmamap_t desc_dma_map;
115 bus_addr_t desc_phys_addr;
116 struct rt2860_rxdesc *desc;
117 bus_dma_tag_t data_dma_tag;
118 bus_dmamap_t spare_dma_map;
119 struct rt2860_softc_rx_data data[RT2860_SOFTC_RX_RING_DATA_COUNT];
120 int cur;
123 struct rt2860_softc_tx_data
125 bus_dmamap_t dma_map;
126 struct ieee80211_node *ni;
127 struct mbuf *m;
130 struct rt2860_softc_tx_ring
132 bus_dma_tag_t desc_dma_tag;
133 bus_dmamap_t desc_dma_map;
134 bus_addr_t desc_phys_addr;
135 struct rt2860_txdesc *desc;
136 int desc_queued;
137 int desc_cur;
138 int desc_next;
139 bus_dma_tag_t seg0_dma_tag;
140 bus_dmamap_t seg0_dma_map;
141 bus_addr_t seg0_phys_addr;
142 uint8_t *seg0;
143 bus_dma_tag_t data_dma_tag;
144 struct rt2860_softc_tx_data data[RT2860_SOFTC_TX_RING_DATA_COUNT];
145 int data_queued;
146 int data_cur;
147 int data_next;
148 int qid;
151 struct rt2860_softc_rx_radiotap_header
153 struct ieee80211_radiotap_header ihdr;
154 uint8_t flags;
155 uint8_t rate;
156 int8_t dbm_antsignal;
157 int8_t dbm_antnoise;
158 uint8_t antenna;
159 uint8_t antsignal;
160 uint32_t chan_flags;
161 uint16_t chan_freq;
162 uint8_t chan_ieee;
163 int8_t chan_maxpow;
166 struct rt2860_softc_tx_radiotap_header
168 struct ieee80211_radiotap_header ihdr;
169 uint8_t flags;
170 uint8_t rate;
171 uint32_t chan_flags;
172 uint16_t chan_freq;
173 uint8_t chan_ieee;
174 int8_t chan_maxpow;
177 struct rt2860_softc
179 struct mtx lock;
181 uint32_t flags;
183 device_t dev;
185 int mem_rid;
186 struct resource *mem;
188 int irq_rid;
189 struct resource *irq;
190 void *irqh;
192 bus_space_tag_t bst;
193 bus_space_handle_t bsh;
195 struct ifnet *ifp;
196 int if_flags;
198 struct ieee80211com ic;
200 struct ieee80211_beacon_offsets beacon_offsets;
202 struct rt2860_amrr amrr;
203 struct rt2860_amrr_node amrr_node[RT2860_SOFTC_AMRR_NODE_COUNT];
205 int (*newstate)(struct ieee80211com *ic,
206 enum ieee80211_state nstate, int arg);
208 int tx_ampdu_sessions;
210 void (*recv_action)(struct ieee80211_node *ni,
211 const uint8_t *frm, const uint8_t *efrm);
213 int (*send_action)(struct ieee80211_node *ni,
214 int category, int action, uint16_t args[4]);
216 uint32_t mac_rev;
217 uint8_t eeprom_addr_num;
218 uint16_t eeprom_rev;
219 uint8_t rf_rev;
221 uint8_t mac_addr[IEEE80211_ADDR_LEN];
223 uint8_t ntxpath;
224 uint8_t nrxpath;
226 int hw_radio_cntl;
227 int tx_agc_cntl;
228 int ext_lna_2ghz;
229 int ext_lna_5ghz;
231 uint8_t country_2ghz;
232 uint8_t country_5ghz;
234 uint8_t rf_freq_off;
236 uint8_t led_cntl;
237 uint16_t led_off[RT2860_SOFTC_LED_OFF_COUNT];
239 int8_t rssi_off_2ghz[RT2860_SOFTC_RSSI_OFF_COUNT];
240 int8_t rssi_off_5ghz[RT2860_SOFTC_RSSI_OFF_COUNT];
242 int8_t lna_gain[RT2860_SOFTC_LNA_GAIN_COUNT];
244 int8_t txpow1[RT2860_SOFTC_TXPOW_COUNT];
245 int8_t txpow2[RT2860_SOFTC_TXPOW_COUNT];
247 int8_t txpow_rate_delta_2ghz;
248 int8_t txpow_rate_delta_5ghz;
249 uint32_t txpow_rate_20mhz[RT2860_SOFTC_TXPOW_RATE_COUNT];
250 uint32_t txpow_rate_40mhz_2ghz[RT2860_SOFTC_TXPOW_RATE_COUNT];
251 uint32_t txpow_rate_40mhz_5ghz[RT2860_SOFTC_TXPOW_RATE_COUNT];
253 int tx_agc_cntl_2ghz;
254 int tx_agc_cntl_5ghz;
256 uint8_t tssi_2ghz[RT2860_SOFTC_TSSI_COUNT];
257 uint8_t tssi_step_2ghz;
258 uint8_t tssi_5ghz[RT2860_SOFTC_TSSI_COUNT];
259 uint8_t tssi_step_5ghz;
261 struct
263 uint8_t val;
264 uint8_t reg;
265 } __packed bbp_eeprom[RT2860_SOFTC_BBP_EEPROM_COUNT];
267 uint16_t powersave_level;
269 int sifs;
271 uint32_t intr_enable_mask;
272 uint32_t intr_disable_mask;
273 uint32_t intr_pending_mask;
275 struct task rx_done_task;
276 int rx_process_limit;
278 struct task tx_done_task;
280 struct task fifo_sta_full_task;
282 struct task periodic_task;
283 struct callout periodic_ch;
284 unsigned long periodic_round;
286 struct taskqueue *taskqueue;
288 struct rt2860_softc_rx_ring rx_ring;
290 struct rt2860_softc_tx_ring tx_ring[RT2860_SOFTC_TX_RING_COUNT];
291 int tx_ring_mgtqid;
293 struct callout tx_watchdog_ch;
294 int tx_timer;
296 struct bpf_if *drvbpf;
298 union
300 struct rt2860_softc_rx_radiotap_header th;
301 uint8_t pad[64];
302 } rxtapu;
304 #define rxtap rxtapu.th
306 int rxtap_len;
308 union
310 struct rt2860_softc_tx_radiotap_header th;
311 uint8_t pad[64];
312 } txtapu;
314 #define txtap txtapu.th
316 int txtap_len;
318 /* statistic counters */
320 unsigned long interrupts;
321 unsigned long tx_coherent_interrupts;
322 unsigned long rx_coherent_interrupts;
323 unsigned long txrx_coherent_interrupts;
324 unsigned long fifo_sta_full_interrupts;
325 unsigned long rx_interrupts;
326 unsigned long rx_delay_interrupts;
327 unsigned long tx_interrupts[RT2860_SOFTC_TX_RING_COUNT];
328 unsigned long tx_delay_interrupts;
329 unsigned long pre_tbtt_interrupts;
330 unsigned long tbtt_interrupts;
331 unsigned long mcu_cmd_interrupts;
332 unsigned long auto_wakeup_interrupts;
333 unsigned long gp_timer_interrupts;
335 unsigned long tx_data_queue_full[RT2860_SOFTC_TX_RING_COUNT];
337 unsigned long tx_watchdog_timeouts;
339 unsigned long tx_defrag_packets;
341 unsigned long no_tx_desc_avail;
343 unsigned long rx_mbuf_alloc_errors;
344 unsigned long rx_mbuf_dmamap_errors;
346 unsigned long tx_queue_not_empty[2];
348 unsigned long tx_beacons;
349 unsigned long tx_noretryok;
350 unsigned long tx_retryok;
351 unsigned long tx_failed;
352 unsigned long tx_nonagg;
353 unsigned long tx_agg;
354 unsigned long tx_ampdu;
356 unsigned long rx_packets;
357 unsigned long rx_ampdu;
358 unsigned long rx_amsdu;
359 unsigned long rx_crc_errors;
360 unsigned long rx_phy_errors;
361 unsigned long rx_false_ccas;
362 unsigned long rx_plcp_errors;
363 unsigned long rx_dup_packets;
364 unsigned long rx_fifo_overflows;
366 #ifdef RT2860_DEBUG
367 int debug;
368 #endif
371 #endif /* #ifndef _RT2860_SOFTC_H_ */