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_VALID (1 << 0)
65 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 1)
67 #define RT2870_SOFTC_USB_XFER_COUNT (1 + RT2870_SOFTC_TX_RING_COUNT)
69 #define RT2870_SOFTC_LED_OFF_COUNT 3
71 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
73 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
75 #define RT2870_SOFTC_TXPOW_COUNT 50
77 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
79 #define RT2870_SOFTC_TSSI_COUNT 9
81 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
83 #define RT2870_SOFTC_RSSI_COUNT 3
85 #define RT2870_SOFTC_STAID_COUNT 64
87 #define RT2870_SOFTC_TX_RING_COUNT 6
89 #define RT2870_SOFTC_RX_RING_DATA_COUNT 128
91 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
93 #define RT2870_SOFTC_CMD_DATA_LEN 256
94 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
96 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
97 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
98 (1 << IEEE80211_RADIOTAP_RATE) | \
99 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
100 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
101 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
102 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
103 (1 << IEEE80211_RADIOTAP_XCHANNEL))
105 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
106 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
107 (1 << IEEE80211_RADIOTAP_RATE) | \
108 (1 << IEEE80211_RADIOTAP_XCHANNEL))
112 struct rt2870_softc_rx_data
114 STAILQ_ENTRY(rt2870_softc_rx_data
) next
;
119 typedef STAILQ_HEAD(, rt2870_softc_rx_data
) rt2870_softc_rx_data_queue
;
121 struct rt2870_softc_rx_ring
123 struct rt2870_softc_rx_data data
[RT2870_SOFTC_RX_RING_DATA_COUNT
];
124 rt2870_softc_rx_data_queue inactive
;
125 rt2870_softc_rx_data_queue active
;
126 rt2870_softc_rx_data_queue done
;
129 struct rt2870_softc_tx_data
131 STAILQ_ENTRY(rt2870_softc_tx_data
) next
;
132 struct ieee80211_node
*ni
;
138 typedef STAILQ_HEAD(, rt2870_softc_tx_data
) rt2870_softc_tx_data_queue
;
140 struct rt2870_softc_tx_ring
142 struct rt2870_softc_tx_data data
[RT2870_SOFTC_TX_RING_DATA_COUNT
];
143 rt2870_softc_tx_data_queue inactive
;
144 rt2870_softc_tx_data_queue pending
;
145 rt2870_softc_tx_data_queue active
;
146 rt2870_softc_tx_data_queue done
;
151 struct rt2870_softc_cmd
153 STAILQ_ENTRY(rt2870_softc_cmd
) next
;
154 void (*cb
)(struct rt2870_softc
*sc
, void *arg
);
155 uint8_t data
[RT2870_SOFTC_CMD_DATA_LEN
];
158 typedef STAILQ_HEAD(, rt2870_softc_cmd
) rt2870_softc_cmd_queue
;
160 struct rt2870_softc_cmd_ring
162 struct rt2870_softc_cmd cmd
[RT2870_SOFTC_CMD_RING_CMD_COUNT
];
163 rt2870_softc_cmd_queue inactive
;
164 rt2870_softc_cmd_queue active
;
168 struct rt2870_softc_node
170 struct ieee80211_node ni
;
174 uint8_t last_rssi
[RT2870_SOFTC_RSSI_COUNT
];
175 int8_t last_rssi_dbm
[RT2870_SOFTC_RSSI_COUNT
];
178 struct rt2870_softc_vap
180 struct ieee80211vap vap
;
182 struct ieee80211_beacon_offsets beacon_offsets
;
183 struct mbuf
*beacon_mbuf
;
184 struct rt2870_txwi beacon_txwi
;
186 struct rt2870_amrr amrr
;
188 int (*newstate
)(struct ieee80211vap
*vap
,
189 enum ieee80211_state nstate
, int arg
);
192 struct rt2870_softc_rx_radiotap_header
194 struct ieee80211_radiotap_header ihdr
;
197 int8_t dbm_antsignal
;
208 struct rt2870_softc_tx_radiotap_header
210 struct ieee80211_radiotap_header ihdr
;
229 struct usb_device
*usb_dev
;
230 struct usb_xfer
*usb_xfer
[1 + RT2870_SOFTC_TX_RING_COUNT
];
241 void (*node_cleanup
)(struct ieee80211_node
*ni
);
243 int tx_ampdu_sessions
;
245 int (*recv_action
)(struct ieee80211_node
*ni
,
246 const struct ieee80211_frame
*wh
,
247 const uint8_t *frm
, const uint8_t *efrm
);
249 int (*send_action
)(struct ieee80211_node
*ni
,
250 int cat
, int act
, void *sa
);
252 struct rt2870_amrr_node amrr_node
[RT2870_SOFTC_STAID_COUNT
];
258 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
268 uint8_t country_2ghz
;
269 uint8_t country_5ghz
;
274 uint16_t led_off
[RT2870_SOFTC_LED_OFF_COUNT
];
276 int8_t rssi_off_2ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
277 int8_t rssi_off_5ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
279 int8_t lna_gain
[RT2870_SOFTC_LNA_GAIN_COUNT
];
281 int8_t txpow1
[RT2870_SOFTC_TXPOW_COUNT
];
282 int8_t txpow2
[RT2870_SOFTC_TXPOW_COUNT
];
284 int8_t txpow_rate_delta_2ghz
;
285 int8_t txpow_rate_delta_5ghz
;
286 uint32_t txpow_rate_20mhz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
287 uint32_t txpow_rate_40mhz_2ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
288 uint32_t txpow_rate_40mhz_5ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
290 int tx_agc_cntl_2ghz
;
291 int tx_agc_cntl_5ghz
;
293 uint8_t tssi_2ghz
[RT2870_SOFTC_TSSI_COUNT
];
294 uint8_t tssi_step_2ghz
;
295 uint8_t tssi_5ghz
[RT2870_SOFTC_TSSI_COUNT
];
296 uint8_t tssi_step_5ghz
;
302 } __packed bbp_eeprom
[RT2870_SOFTC_BBP_EEPROM_COUNT
];
304 uint8_t staid_mask
[RT2870_SOFTC_STAID_COUNT
/ NBBY
];
306 struct task rx_done_task
;
307 int rx_process_limit
;
309 struct task tx_done_task
;
310 uint32_t tx_qid_pending_mask
;
312 struct task periodic_task
;
313 struct callout periodic_ch
;
314 unsigned long periodic_round
;
316 struct task cmd_task
;
318 struct taskqueue
*taskqueue
;
320 struct rt2870_softc_rx_ring rx_ring
;
322 struct rt2870_softc_tx_ring tx_ring
[RT2870_SOFTC_TX_RING_COUNT
];
325 struct callout tx_watchdog_ch
;
328 struct rt2870_softc_cmd_ring cmd_ring
;
330 struct rt2870_softc_rx_radiotap_header rxtap
;
331 struct rt2870_softc_tx_radiotap_header txtap
;
333 /* statistic counters */
335 unsigned long interrupts
;
336 unsigned long rx_interrupts
;
337 unsigned long tx_interrupts
[RT2870_SOFTC_TX_RING_COUNT
];
339 unsigned long tx_data_queue_full
[RT2870_SOFTC_TX_RING_COUNT
];
341 unsigned long tx_watchdog_timeouts
;
343 unsigned long rx_mbuf_alloc_errors
;
345 unsigned long tx_queue_not_empty
[2];
347 unsigned long tx_beacons
;
348 unsigned long tx_noretryok
;
349 unsigned long tx_retryok
;
350 unsigned long tx_failed
;
351 unsigned long tx_underflows
;
352 unsigned long tx_zerolen
;
353 unsigned long tx_nonagg
;
354 unsigned long tx_agg
;
355 unsigned long tx_ampdu
;
356 unsigned long tx_mpdu_zero_density
;
358 unsigned long rx_packets
;
359 unsigned long rx_ampdu
;
360 unsigned long rx_mpdu_zero_density
;
361 unsigned long rx_amsdu
;
362 unsigned long rx_crc_errors
;
363 unsigned long rx_phy_errors
;
364 unsigned long rx_false_ccas
;
365 unsigned long rx_plcp_errors
;
366 unsigned long rx_dup_packets
;
367 unsigned long rx_fifo_overflows
;
368 unsigned long rx_cipher_no_errors
;
369 unsigned long rx_cipher_icv_errors
;
370 unsigned long rx_cipher_mic_errors
;
371 unsigned long rx_cipher_invalid_key_errors
;
380 #endif /* #ifndef _RT2870_SOFTC_H_ */