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>
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>
33 #include <sys/endian.h>
35 #include <machine/bus.h>
36 #include <machine/resource.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_txwi.h"
58 #include "rt2860_amrr.h"
60 #define RT2860_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
61 #define RT2860_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
62 #define RT2860_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
64 #define RT2860_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
66 #define RT2860_SOFTC_LED_OFF_COUNT 3
68 #define RT2860_SOFTC_RSSI_OFF_COUNT 3
70 #define RT2860_SOFTC_LNA_GAIN_COUNT 4
72 #define RT2860_SOFTC_TXPOW_COUNT 50
74 #define RT2860_SOFTC_TXPOW_RATE_COUNT 5
76 #define RT2860_SOFTC_TSSI_COUNT 9
78 #define RT2860_SOFTC_BBP_EEPROM_COUNT 8
80 #define RT2860_SOFTC_RSSI_COUNT 3
82 #define RT2860_SOFTC_STAID_COUNT 64
84 #define RT2860_SOFTC_TX_RING_COUNT 6
86 #define RT2860_SOFTC_RX_RING_DATA_COUNT 128
88 #define RT2860_SOFTC_MAX_SCATTER 10
90 #define RT2860_SOFTC_TX_RING_DATA_COUNT 256
91 #define RT2860_SOFTC_TX_RING_DESC_COUNT \
92 (RT2860_SOFTC_TX_RING_DATA_COUNT * RT2860_SOFTC_MAX_SCATTER)
94 #define RT2860_SOFTC_RX_RADIOTAP_PRESENT \
95 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
96 (1 << IEEE80211_RADIOTAP_RATE) | \
97 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
98 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
99 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
100 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
101 (1 << IEEE80211_RADIOTAP_XCHANNEL))
103 #define RT2860_SOFTC_TX_RADIOTAP_PRESENT \
104 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
105 (1 << IEEE80211_RADIOTAP_RATE) | \
106 (1 << IEEE80211_RADIOTAP_XCHANNEL))
108 struct rt2860_softc_rx_data
110 bus_dmamap_t dma_map
;
114 struct rt2860_softc_rx_ring
116 bus_dma_tag_t desc_dma_tag
;
117 bus_dmamap_t desc_dma_map
;
118 bus_addr_t desc_phys_addr
;
119 struct rt2860_rxdesc
*desc
;
120 bus_dma_tag_t data_dma_tag
;
121 bus_dmamap_t spare_dma_map
;
122 struct rt2860_softc_rx_data data
[RT2860_SOFTC_RX_RING_DATA_COUNT
];
126 struct rt2860_softc_tx_data
128 bus_dmamap_t dma_map
;
129 struct ieee80211_node
*ni
;
133 struct rt2860_softc_tx_ring
135 bus_dma_tag_t desc_dma_tag
;
136 bus_dmamap_t desc_dma_map
;
137 bus_addr_t desc_phys_addr
;
138 struct rt2860_txdesc
*desc
;
142 bus_dma_tag_t seg0_dma_tag
;
143 bus_dmamap_t seg0_dma_map
;
144 bus_addr_t seg0_phys_addr
;
146 bus_dma_tag_t data_dma_tag
;
147 struct rt2860_softc_tx_data data
[RT2860_SOFTC_TX_RING_DATA_COUNT
];
154 struct rt2860_softc_node
156 struct ieee80211_node ni
;
160 uint8_t last_rssi
[RT2860_SOFTC_RSSI_COUNT
];
161 int8_t last_rssi_dbm
[RT2860_SOFTC_RSSI_COUNT
];
164 struct rt2860_softc_vap
166 struct ieee80211vap vap
;
168 struct ieee80211_beacon_offsets beacon_offsets
;
169 struct mbuf
*beacon_mbuf
;
170 struct rt2860_txwi beacon_txwi
;
172 struct rt2860_amrr amrr
;
174 int (*newstate
)(struct ieee80211vap
*vap
,
175 enum ieee80211_state nstate
, int arg
);
178 struct rt2860_softc_rx_radiotap_header
180 struct ieee80211_radiotap_header ihdr
;
183 int8_t dbm_antsignal
;
194 struct rt2860_softc_tx_radiotap_header
196 struct ieee80211_radiotap_header ihdr
;
215 struct resource
*mem
;
218 struct resource
*irq
;
222 bus_space_handle_t bsh
;
233 void (*node_cleanup
)(struct ieee80211_node
*ni
);
235 int tx_ampdu_sessions
;
237 int (*recv_action
)(struct ieee80211_node
*ni
,
238 const struct ieee80211_frame
*wh
,
239 const uint8_t *frm
, const uint8_t *efrm
);
241 int (*send_action
)(struct ieee80211_node
*ni
,
242 int cat
, int act
, void *sa
);
244 struct rt2860_amrr_node amrr_node
[RT2860_SOFTC_STAID_COUNT
];
247 uint8_t eeprom_addr_num
;
251 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
261 uint8_t country_2ghz
;
262 uint8_t country_5ghz
;
267 uint16_t led_off
[RT2860_SOFTC_LED_OFF_COUNT
];
269 int8_t rssi_off_2ghz
[RT2860_SOFTC_RSSI_OFF_COUNT
];
270 int8_t rssi_off_5ghz
[RT2860_SOFTC_RSSI_OFF_COUNT
];
272 int8_t lna_gain
[RT2860_SOFTC_LNA_GAIN_COUNT
];
274 int8_t txpow1
[RT2860_SOFTC_TXPOW_COUNT
];
275 int8_t txpow2
[RT2860_SOFTC_TXPOW_COUNT
];
277 int8_t txpow_rate_delta_2ghz
;
278 int8_t txpow_rate_delta_5ghz
;
279 uint32_t txpow_rate_20mhz
[RT2860_SOFTC_TXPOW_RATE_COUNT
];
280 uint32_t txpow_rate_40mhz_2ghz
[RT2860_SOFTC_TXPOW_RATE_COUNT
];
281 uint32_t txpow_rate_40mhz_5ghz
[RT2860_SOFTC_TXPOW_RATE_COUNT
];
283 int tx_agc_cntl_2ghz
;
284 int tx_agc_cntl_5ghz
;
286 uint8_t tssi_2ghz
[RT2860_SOFTC_TSSI_COUNT
];
287 uint8_t tssi_step_2ghz
;
288 uint8_t tssi_5ghz
[RT2860_SOFTC_TSSI_COUNT
];
289 uint8_t tssi_step_5ghz
;
295 } __packed bbp_eeprom
[RT2860_SOFTC_BBP_EEPROM_COUNT
];
297 uint16_t powersave_level
;
299 uint8_t staid_mask
[RT2860_SOFTC_STAID_COUNT
/ NBBY
];
301 uint32_t intr_enable_mask
;
302 uint32_t intr_disable_mask
;
303 uint32_t intr_pending_mask
;
305 struct task rx_done_task
;
306 int rx_process_limit
;
308 struct task tx_done_task
;
310 struct task fifo_sta_full_task
;
312 struct task periodic_task
;
313 struct callout periodic_ch
;
314 unsigned long periodic_round
;
316 struct taskqueue
*taskqueue
;
318 struct rt2860_softc_rx_ring rx_ring
;
320 struct rt2860_softc_tx_ring tx_ring
[RT2860_SOFTC_TX_RING_COUNT
];
323 struct callout tx_watchdog_ch
;
326 struct rt2860_softc_rx_radiotap_header rxtap
;
327 struct rt2860_softc_tx_radiotap_header txtap
;
329 /* statistic counters */
331 unsigned long interrupts
;
332 unsigned long tx_coherent_interrupts
;
333 unsigned long rx_coherent_interrupts
;
334 unsigned long txrx_coherent_interrupts
;
335 unsigned long fifo_sta_full_interrupts
;
336 unsigned long rx_interrupts
;
337 unsigned long rx_delay_interrupts
;
338 unsigned long tx_interrupts
[RT2860_SOFTC_TX_RING_COUNT
];
339 unsigned long tx_delay_interrupts
;
340 unsigned long pre_tbtt_interrupts
;
341 unsigned long tbtt_interrupts
;
342 unsigned long mcu_cmd_interrupts
;
343 unsigned long auto_wakeup_interrupts
;
344 unsigned long gp_timer_interrupts
;
346 unsigned long tx_data_queue_full
[RT2860_SOFTC_TX_RING_COUNT
];
348 unsigned long tx_watchdog_timeouts
;
350 unsigned long tx_defrag_packets
;
352 unsigned long no_tx_desc_avail
;
354 unsigned long rx_mbuf_alloc_errors
;
355 unsigned long rx_mbuf_dmamap_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
;
370 unsigned long rx_packets
;
371 unsigned long rx_ampdu
;
372 unsigned long rx_mpdu_zero_density
;
373 unsigned long rx_amsdu
;
374 unsigned long rx_crc_errors
;
375 unsigned long rx_phy_errors
;
376 unsigned long rx_false_ccas
;
377 unsigned long rx_plcp_errors
;
378 unsigned long rx_dup_packets
;
379 unsigned long rx_fifo_overflows
;
380 unsigned long rx_cipher_no_errors
;
381 unsigned long rx_cipher_icv_errors
;
382 unsigned long rx_cipher_mic_errors
;
383 unsigned long rx_cipher_invalid_key_errors
;
390 #endif /* #ifndef _RT2860_SOFTC_H_ */