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>
55 #include <dev/usb/usbdi_util.h>
58 #include "rt2870_txwi.h"
59 #include "rt2870_amrr.h"
61 #define RT2870_SOFTC_LOCK(sc) mtx_lock(&Giant)
62 #define RT2870_SOFTC_UNLOCK(sc) mtx_unlock(&Giant)
64 #define RT2870_SOFTC_FLAGS_VALID (1 << 0)
65 #define RT2870_SOFTC_FLAGS_UCODE_LOADED (1 << 1)
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_RSSI_DBM_COUNT 3
83 #define RT2870_SOFTC_STAID_COUNT 64
85 #define RT2870_SOFTC_TX_RING_COUNT 6
87 #define RT2870_SOFTC_RX_RING_DATA_COUNT 1
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))
109 struct rt2870_softc_rx_data
111 STAILQ_ENTRY(rt2870_softc_rx_data
) next
;
112 usbd_xfer_handle xfer
;
117 typedef STAILQ_HEAD(, rt2870_softc_rx_data
) rt2870_softc_rx_data_queue
;
119 struct rt2870_softc_rx_ring
122 usbd_pipe_handle usb_pipe
;
123 struct rt2870_softc_rx_data data
[RT2870_SOFTC_RX_RING_DATA_COUNT
];
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
;
132 usbd_xfer_handle xfer
;
137 typedef STAILQ_HEAD(, rt2870_softc_tx_data
) rt2870_softc_tx_data_queue
;
139 struct rt2870_softc_tx_ring
142 usbd_pipe_handle usb_pipe
;
143 struct rt2870_softc
*sc
;
144 struct rt2870_softc_tx_data data
[RT2870_SOFTC_TX_RING_DATA_COUNT
];
145 rt2870_softc_tx_data_queue inactive
;
146 rt2870_softc_tx_data_queue active
;
147 rt2870_softc_tx_data_queue done
;
152 struct rt2870_softc_cmd
154 STAILQ_ENTRY(rt2870_softc_cmd
) next
;
155 void (*cb
)(struct rt2870_softc
*sc
, void *arg
);
156 uint8_t data
[RT2870_SOFTC_CMD_DATA_LEN
];
159 typedef STAILQ_HEAD(, rt2870_softc_cmd
) rt2870_softc_cmd_queue
;
161 struct rt2870_softc_cmd_ring
163 struct rt2870_softc_cmd cmd
[RT2870_SOFTC_CMD_RING_CMD_COUNT
];
164 rt2870_softc_cmd_queue inactive
;
165 rt2870_softc_cmd_queue active
;
169 struct rt2870_softc_node
171 struct ieee80211_node ni
;
175 int8_t last_rssi_dbm
[RT2870_SOFTC_RSSI_DBM_COUNT
];
178 struct rt2870_softc_rx_radiotap_header
180 struct ieee80211_radiotap_header ihdr
;
183 int8_t dbm_antsignal
;
193 struct rt2870_softc_tx_radiotap_header
195 struct ieee80211_radiotap_header ihdr
;
211 usbd_device_handle usb_dev
;
212 usbd_interface_handle usb_iface
;
217 struct ieee80211com ic
;
219 struct ieee80211_beacon_offsets beacon_offsets
;
220 struct mbuf
*beacon_mbuf
;
221 struct rt2870_txwi beacon_txwi
;
223 struct rt2870_amrr amrr
;
224 struct rt2870_amrr_node amrr_node
[RT2870_SOFTC_STAID_COUNT
];
226 int (*newstate
)(struct ieee80211com
*ic
,
227 enum ieee80211_state nstate
, int arg
);
229 void (*node_cleanup
)(struct ieee80211_node
*ni
);
231 void (*recv_action
)(struct ieee80211_node
*ni
,
232 const uint8_t *frm
, const uint8_t *efrm
);
234 int (*send_action
)(struct ieee80211_node
*ni
,
235 int category
, int action
, uint16_t args
[4]);
237 int (*addba_response
)(struct ieee80211_node
*ni
,
238 struct ieee80211_tx_ampdu
*tap
,
239 int status
, int baparamset
, int batimeout
);
241 void (*addba_stop
)(struct ieee80211_node
*ni
,
242 struct ieee80211_tx_ampdu
*tap
);
248 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
258 uint8_t country_2ghz
;
259 uint8_t country_5ghz
;
264 uint16_t led_off
[RT2870_SOFTC_LED_OFF_COUNT
];
266 int8_t rssi_off_2ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
267 int8_t rssi_off_5ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
269 int8_t lna_gain
[RT2870_SOFTC_LNA_GAIN_COUNT
];
271 int8_t txpow1
[RT2870_SOFTC_TXPOW_COUNT
];
272 int8_t txpow2
[RT2870_SOFTC_TXPOW_COUNT
];
274 int8_t txpow_rate_delta_2ghz
;
275 int8_t txpow_rate_delta_5ghz
;
276 uint32_t txpow_rate_20mhz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
277 uint32_t txpow_rate_40mhz_2ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
278 uint32_t txpow_rate_40mhz_5ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
280 int tx_agc_cntl_2ghz
;
281 int tx_agc_cntl_5ghz
;
283 uint8_t tssi_2ghz
[RT2870_SOFTC_TSSI_COUNT
];
284 uint8_t tssi_step_2ghz
;
285 uint8_t tssi_5ghz
[RT2870_SOFTC_TSSI_COUNT
];
286 uint8_t tssi_step_5ghz
;
292 } __packed bbp_eeprom
[RT2870_SOFTC_BBP_EEPROM_COUNT
];
296 uint8_t staid_mask
[RT2870_SOFTC_STAID_COUNT
/ NBBY
];
298 struct task rx_done_task
;
299 int rx_process_limit
;
301 struct task tx_done_task
;
302 uint32_t tx_qid_pending_mask
;
304 struct task periodic_task
;
305 struct callout periodic_ch
;
306 unsigned long periodic_round
;
308 struct task cmd_task
;
310 struct taskqueue
*taskqueue
;
312 struct rt2870_softc_rx_ring rx_ring
;
314 struct rt2870_softc_tx_ring tx_ring
[RT2870_SOFTC_TX_RING_COUNT
];
317 struct callout tx_watchdog_ch
;
320 struct rt2870_softc_cmd_ring cmd_ring
;
322 struct bpf_if
*drvbpf
;
326 struct rt2870_softc_rx_radiotap_header th
;
330 #define rxtap rxtapu.th
336 struct rt2870_softc_tx_radiotap_header th
;
340 #define txtap txtapu.th
344 /* statistic counters */
346 unsigned long interrupts
;
347 unsigned long rx_interrupts
;
348 unsigned long tx_interrupts
[RT2870_SOFTC_TX_RING_COUNT
];
350 unsigned long tx_data_queue_full
[RT2870_SOFTC_TX_RING_COUNT
];
352 unsigned long tx_watchdog_timeouts
;
354 unsigned long rx_mbuf_alloc_errors
;
356 unsigned long tx_queue_not_empty
[2];
358 unsigned long tx_beacons
;
359 unsigned long tx_noretryok
;
360 unsigned long tx_retryok
;
361 unsigned long tx_failed
;
362 unsigned long tx_underflows
;
363 unsigned long tx_zerolen
;
364 unsigned long tx_nonagg
;
365 unsigned long tx_agg
;
366 unsigned long tx_ampdu
;
367 unsigned long tx_mpdu_zero_density
;
368 unsigned long tx_ampdu_sessions
;
370 unsigned long rx_packets
;
371 unsigned long rx_ampdu
;
372 unsigned long rx_mpdu_zero_density
;
373 unsigned long rx_ampdu_sessions
;
374 unsigned long rx_amsdu
;
375 unsigned long rx_crc_errors
;
376 unsigned long rx_phy_errors
;
377 unsigned long rx_false_ccas
;
378 unsigned long rx_plcp_errors
;
379 unsigned long rx_dup_packets
;
380 unsigned long rx_fifo_overflows
;
381 unsigned long rx_cipher_no_errors
;
382 unsigned long rx_cipher_icv_errors
;
383 unsigned long rx_cipher_mic_errors
;
384 unsigned long rx_cipher_invalid_key_errors
;
391 #endif /* #ifndef _RT2870_SOFTC_H_ */