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_amrr.h"
59 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&(sc)->lock)
60 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&(sc)->lock)
61 #define RT2870_SOFTC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED)
63 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 0)
65 #define RT2870_SOFTC_USB_XFER_COUNT (1 + RT2870_SOFTC_TX_RING_COUNT)
67 #define RT2870_SOFTC_LED_OFF_COUNT 3
69 #define RT2870_SOFTC_RSSI_OFF_COUNT 3
71 #define RT2870_SOFTC_LNA_GAIN_COUNT 4
73 #define RT2870_SOFTC_TXPOW_COUNT 50
75 #define RT2870_SOFTC_TXPOW_RATE_COUNT 5
77 #define RT2870_SOFTC_TSSI_COUNT 9
79 #define RT2870_SOFTC_BBP_EEPROM_COUNT 8
81 #define RT2870_SOFTC_AMRR_NODE_COUNT 256
83 #define RT2870_SOFTC_RSSI_DBM_COUNT 3
85 #define RT2870_SOFTC_TX_RING_COUNT 6
87 #define RT2870_SOFTC_RX_RING_DATA_COUNT 128
89 #define RT2870_SOFTC_TX_RING_DATA_COUNT 256
91 #define RT2870_SOFTC_CMD_DATA_LEN 256
92 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
94 #define RT2870_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 RT2870_SOFTC_TX_RADIOTAP_PRESENT \
104 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
105 (1 << IEEE80211_RADIOTAP_RATE) | \
106 (1 << IEEE80211_RADIOTAP_XCHANNEL))
110 struct rt2870_softc_rx_data
112 STAILQ_ENTRY(rt2870_softc_rx_data
) next
;
117 typedef STAILQ_HEAD(, rt2870_softc_rx_data
) rt2870_softc_rx_data_queue
;
119 struct rt2870_softc_rx_ring
121 struct rt2870_softc_rx_data data
[RT2870_SOFTC_RX_RING_DATA_COUNT
];
122 rt2870_softc_rx_data_queue inactive
;
123 rt2870_softc_rx_data_queue active
;
124 rt2870_softc_rx_data_queue done
;
127 struct rt2870_softc_tx_data
129 STAILQ_ENTRY(rt2870_softc_tx_data
) next
;
130 struct ieee80211_node
*ni
;
136 typedef STAILQ_HEAD(, rt2870_softc_tx_data
) rt2870_softc_tx_data_queue
;
138 struct rt2870_softc_tx_ring
140 struct rt2870_softc_tx_data data
[RT2870_SOFTC_TX_RING_DATA_COUNT
];
141 rt2870_softc_tx_data_queue inactive
;
142 rt2870_softc_tx_data_queue pending
;
143 rt2870_softc_tx_data_queue active
;
144 rt2870_softc_tx_data_queue done
;
149 struct rt2870_softc_cmd
151 STAILQ_ENTRY(rt2870_softc_cmd
) next
;
152 void (*cb
)(struct rt2870_softc
*sc
, void *arg
);
153 uint8_t data
[RT2870_SOFTC_CMD_DATA_LEN
];
156 typedef STAILQ_HEAD(, rt2870_softc_cmd
) rt2870_softc_cmd_queue
;
158 struct rt2870_softc_cmd_ring
160 struct rt2870_softc_cmd cmd
[RT2870_SOFTC_CMD_RING_CMD_COUNT
];
161 rt2870_softc_cmd_queue inactive
;
162 rt2870_softc_cmd_queue active
;
166 struct rt2870_softc_node
168 struct ieee80211_node ni
;
170 int8_t last_rssi_dbm
[RT2870_SOFTC_RSSI_DBM_COUNT
];
173 struct rt2870_softc_vap
175 struct ieee80211vap vap
;
176 struct ieee80211_beacon_offsets beacon_offsets
;
177 struct rt2870_amrr amrr
;
179 int (*newstate
)(struct ieee80211vap
*vap
,
180 enum ieee80211_state nstate
, int arg
);
183 struct rt2870_softc_rx_radiotap_header
185 struct ieee80211_radiotap_header ihdr
;
188 int8_t dbm_antsignal
;
199 struct rt2870_softc_tx_radiotap_header
201 struct ieee80211_radiotap_header ihdr
;
220 struct usb_device
*usb_dev
;
221 struct usb_xfer
*usb_xfer
[1 + RT2870_SOFTC_TX_RING_COUNT
];
226 int tx_ampdu_sessions
;
228 int (*recv_action
)(struct ieee80211_node
*ni
,
229 const struct ieee80211_frame
*wh
,
230 const uint8_t *frm
, const uint8_t *efrm
);
232 int (*send_action
)(struct ieee80211_node
*ni
,
233 int cat
, int act
, void *sa
);
235 struct rt2870_amrr_node amrr_node
[RT2870_SOFTC_AMRR_NODE_COUNT
];
241 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
251 uint8_t country_2ghz
;
252 uint8_t country_5ghz
;
257 uint16_t led_off
[RT2870_SOFTC_LED_OFF_COUNT
];
259 int8_t rssi_off_2ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
260 int8_t rssi_off_5ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
262 int8_t lna_gain
[RT2870_SOFTC_LNA_GAIN_COUNT
];
264 int8_t txpow1
[RT2870_SOFTC_TXPOW_COUNT
];
265 int8_t txpow2
[RT2870_SOFTC_TXPOW_COUNT
];
267 int8_t txpow_rate_delta_2ghz
;
268 int8_t txpow_rate_delta_5ghz
;
269 uint32_t txpow_rate_20mhz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
270 uint32_t txpow_rate_40mhz_2ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
271 uint32_t txpow_rate_40mhz_5ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
273 int tx_agc_cntl_2ghz
;
274 int tx_agc_cntl_5ghz
;
276 uint8_t tssi_2ghz
[RT2870_SOFTC_TSSI_COUNT
];
277 uint8_t tssi_step_2ghz
;
278 uint8_t tssi_5ghz
[RT2870_SOFTC_TSSI_COUNT
];
279 uint8_t tssi_step_5ghz
;
285 } __packed bbp_eeprom
[RT2870_SOFTC_BBP_EEPROM_COUNT
];
287 struct task rx_done_task
;
288 int rx_process_limit
;
290 struct task tx_done_task
;
291 uint32_t tx_qid_pending_mask
;
293 struct task periodic_task
;
294 struct callout periodic_ch
;
295 unsigned long periodic_round
;
297 struct task cmd_task
;
299 struct taskqueue
*taskqueue
;
301 struct rt2870_softc_rx_ring rx_ring
;
303 struct rt2870_softc_tx_ring tx_ring
[RT2870_SOFTC_TX_RING_COUNT
];
306 struct callout tx_watchdog_ch
;
309 struct rt2870_softc_cmd_ring cmd_ring
;
311 struct rt2870_softc_rx_radiotap_header rxtap
;
312 struct rt2870_softc_tx_radiotap_header txtap
;
314 /* statistic counters */
316 unsigned long interrupts
;
317 unsigned long rx_interrupts
;
318 unsigned long tx_interrupts
[RT2870_SOFTC_TX_RING_COUNT
];
320 unsigned long tx_data_queue_full
[RT2870_SOFTC_TX_RING_COUNT
];
322 unsigned long tx_watchdog_timeouts
;
324 unsigned long rx_mbuf_alloc_errors
;
326 unsigned long tx_queue_not_empty
[2];
328 unsigned long tx_beacons
;
329 unsigned long tx_noretryok
;
330 unsigned long tx_retryok
;
331 unsigned long tx_failed
;
332 unsigned long tx_underflows
;
333 unsigned long tx_zerolen
;
334 unsigned long tx_nonagg
;
335 unsigned long tx_agg
;
336 unsigned long tx_ampdu
;
337 unsigned long tx_mpdu_zero_density
;
339 unsigned long rx_packets
;
340 unsigned long rx_ampdu
;
341 unsigned long rx_mpdu_zero_density
;
342 unsigned long rx_amsdu
;
343 unsigned long rx_crc_errors
;
344 unsigned long rx_phy_errors
;
345 unsigned long rx_false_ccas
;
346 unsigned long rx_plcp_errors
;
347 unsigned long rx_dup_packets
;
348 unsigned long rx_fifo_overflows
;
355 #endif /* #ifndef _RT2870_SOFTC_H_ */