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>
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>
34 #include <sys/endian.h>
36 #include <machine/bus.h>
37 #include <machine/resource.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>
57 #include "rt2870_txwi.h"
58 #include "rt2870_amrr.h"
60 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
61 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
62 #define RT2870_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
64 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
66 #define RT2870_SOFTC_USB_XFER_COUNT (1 + RT2870_SOFTC_TX_RING_COUNT)
68 #define RT2870_SOFTC_LED_OFF_COUNT 3
70 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
72 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
74 #define RT2870_SOFTC_TXPOW_COUNT 50
76 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
78 #define RT2870_SOFTC_TSSI_COUNT 9
80 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
82 #define RT2870_SOFTC_AMRR_NODE_COUNT 256
84 #define RT2870_SOFTC_RSSI_COUNT 3
86 #define RT2870_SOFTC_TX_RING_COUNT 6
88 #define RT2870_SOFTC_RX_RING_DATA_COUNT 128
90 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
92 #define RT2870_SOFTC_CMD_DATA_LEN 256
93 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
95 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
96 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
97 (1 << IEEE80211_RADIOTAP_RATE) | \
98 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
99 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
100 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
101 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
102 (1 << IEEE80211_RADIOTAP_XCHANNEL))
104 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
105 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
106 (1 << IEEE80211_RADIOTAP_RATE) | \
107 (1 << IEEE80211_RADIOTAP_XCHANNEL))
111 struct rt2870_softc_rx_data
113 STAILQ_ENTRY(rt2870_softc_rx_data
) next
;
118 typedef STAILQ_HEAD(, rt2870_softc_rx_data
) rt2870_softc_rx_data_queue
;
120 struct rt2870_softc_rx_ring
122 struct rt2870_softc_rx_data data
[RT2870_SOFTC_RX_RING_DATA_COUNT
];
123 rt2870_softc_rx_data_queue inactive
;
124 rt2870_softc_rx_data_queue active
;
125 rt2870_softc_rx_data_queue done
;
128 struct rt2870_softc_tx_data
130 STAILQ_ENTRY(rt2870_softc_tx_data
) next
;
131 struct ieee80211_node
*ni
;
137 typedef STAILQ_HEAD(, rt2870_softc_tx_data
) rt2870_softc_tx_data_queue
;
139 struct rt2870_softc_tx_ring
141 struct rt2870_softc_tx_data data
[RT2870_SOFTC_TX_RING_DATA_COUNT
];
142 rt2870_softc_tx_data_queue inactive
;
143 rt2870_softc_tx_data_queue pending
;
144 rt2870_softc_tx_data_queue active
;
145 rt2870_softc_tx_data_queue done
;
150 struct rt2870_softc_cmd
152 STAILQ_ENTRY(rt2870_softc_cmd
) next
;
153 void (*cb
)(struct rt2870_softc
*sc
, void *arg
);
154 uint8_t data
[RT2870_SOFTC_CMD_DATA_LEN
];
157 typedef STAILQ_HEAD(, rt2870_softc_cmd
) rt2870_softc_cmd_queue
;
159 struct rt2870_softc_cmd_ring
161 struct rt2870_softc_cmd cmd
[RT2870_SOFTC_CMD_RING_CMD_COUNT
];
162 rt2870_softc_cmd_queue inactive
;
163 rt2870_softc_cmd_queue active
;
167 struct rt2870_softc_node
169 struct ieee80211_node ni
;
171 uint8_t last_rssi
[RT2870_SOFTC_RSSI_COUNT
];
172 int8_t last_rssi_dbm
[RT2870_SOFTC_RSSI_COUNT
];
175 struct rt2870_softc_vap
177 struct ieee80211vap vap
;
179 struct ieee80211_beacon_offsets beacon_offsets
;
180 struct mbuf
*beacon_mbuf
;
181 struct rt2870_txwi beacon_txwi
;
183 struct rt2870_amrr amrr
;
185 int (*newstate
)(struct ieee80211vap
*vap
,
186 enum ieee80211_state nstate
, int arg
);
189 struct rt2870_softc_rx_radiotap_header
191 struct ieee80211_radiotap_header ihdr
;
194 int8_t dbm_antsignal
;
205 struct rt2870_softc_tx_radiotap_header
207 struct ieee80211_radiotap_header ihdr
;
226 struct usb_device
*usb_dev
;
227 struct usb_xfer
*usb_xfer
[1 + RT2870_SOFTC_TX_RING_COUNT
];
232 int tx_ampdu_sessions
;
234 int (*recv_action
)(struct ieee80211_node
*ni
,
235 const struct ieee80211_frame
*wh
,
236 const uint8_t *frm
, const uint8_t *efrm
);
238 int (*send_action
)(struct ieee80211_node
*ni
,
239 int cat
, int act
, void *sa
);
241 struct rt2870_amrr_node amrr_node
[RT2870_SOFTC_AMRR_NODE_COUNT
];
247 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
257 uint8_t country_2ghz
;
258 uint8_t country_5ghz
;
263 uint16_t led_off
[RT2870_SOFTC_LED_OFF_COUNT
];
265 int8_t rssi_off_2ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
266 int8_t rssi_off_5ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
268 int8_t lna_gain
[RT2870_SOFTC_LNA_GAIN_COUNT
];
270 int8_t txpow1
[RT2870_SOFTC_TXPOW_COUNT
];
271 int8_t txpow2
[RT2870_SOFTC_TXPOW_COUNT
];
273 int8_t txpow_rate_delta_2ghz
;
274 int8_t txpow_rate_delta_5ghz
;
275 uint32_t txpow_rate_20mhz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
276 uint32_t txpow_rate_40mhz_2ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
277 uint32_t txpow_rate_40mhz_5ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
279 int tx_agc_cntl_2ghz
;
280 int tx_agc_cntl_5ghz
;
282 uint8_t tssi_2ghz
[RT2870_SOFTC_TSSI_COUNT
];
283 uint8_t tssi_step_2ghz
;
284 uint8_t tssi_5ghz
[RT2870_SOFTC_TSSI_COUNT
];
285 uint8_t tssi_step_5ghz
;
291 } __packed bbp_eeprom
[RT2870_SOFTC_BBP_EEPROM_COUNT
];
293 struct task rx_done_task
;
294 int rx_process_limit
;
296 struct task tx_done_task
;
297 uint32_t tx_qid_pending_mask
;
299 struct task periodic_task
;
300 struct callout periodic_ch
;
301 unsigned long periodic_round
;
303 struct task cmd_task
;
305 struct taskqueue
*taskqueue
;
307 struct rt2870_softc_rx_ring rx_ring
;
309 struct rt2870_softc_tx_ring tx_ring
[RT2870_SOFTC_TX_RING_COUNT
];
312 struct callout tx_watchdog_ch
;
315 struct rt2870_softc_cmd_ring cmd_ring
;
317 struct rt2870_softc_rx_radiotap_header rxtap
;
318 struct rt2870_softc_tx_radiotap_header txtap
;
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_underflows
;
339 unsigned long tx_zerolen
;
340 unsigned long tx_nonagg
;
341 unsigned long tx_agg
;
342 unsigned long tx_ampdu
;
343 unsigned long tx_mpdu_zero_density
;
345 unsigned long rx_packets
;
346 unsigned long rx_ampdu
;
347 unsigned long rx_mpdu_zero_density
;
348 unsigned long rx_amsdu
;
349 unsigned long rx_crc_errors
;
350 unsigned long rx_phy_errors
;
351 unsigned long rx_false_ccas
;
352 unsigned long rx_plcp_errors
;
353 unsigned long rx_dup_packets
;
354 unsigned long rx_fifo_overflows
;
355 unsigned long rx_cipher_no_errors
;
356 unsigned long rx_cipher_icv_errors
;
357 unsigned long rx_cipher_mic_errors
;
358 unsigned long rx_cipher_invalid_key_errors
;
365 #endif /* #ifndef _RT2870_SOFTC_H_ */