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_TX_RING_COUNT 6
85 #define RT2870_SOFTC_RX_RING_DATA_COUNT 128
87 #define RT2870_SOFTC_TX_RING_DATA_COUNT 128
89 #define RT2870_SOFTC_CMD_DATA_LEN 256
90 #define RT2870_SOFTC_CMD_RING_CMD_COUNT 64
92 #define RT2870_SOFTC_RX_RADIOTAP_PRESENT \
93 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
94 (1 << IEEE80211_RADIOTAP_RATE) | \
95 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
96 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
97 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
98 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
99 (1 << IEEE80211_RADIOTAP_XCHANNEL))
101 #define RT2870_SOFTC_TX_RADIOTAP_PRESENT \
102 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
103 (1 << IEEE80211_RADIOTAP_RATE) | \
104 (1 << IEEE80211_RADIOTAP_XCHANNEL))
108 struct rt2870_softc_rx_data
110 STAILQ_ENTRY(rt2870_softc_rx_data
) next
;
115 typedef STAILQ_HEAD(, rt2870_softc_rx_data
) rt2870_softc_rx_data_queue
;
117 struct rt2870_softc_rx_ring
119 struct rt2870_softc_rx_data data
[RT2870_SOFTC_RX_RING_DATA_COUNT
];
120 rt2870_softc_rx_data_queue inactive
;
121 rt2870_softc_rx_data_queue active
;
122 rt2870_softc_rx_data_queue done
;
125 struct rt2870_softc_tx_data
127 STAILQ_ENTRY(rt2870_softc_tx_data
) next
;
128 struct ieee80211_node
*ni
;
134 typedef STAILQ_HEAD(, rt2870_softc_tx_data
) rt2870_softc_tx_data_queue
;
136 struct rt2870_softc_tx_ring
138 struct rt2870_softc_tx_data data
[RT2870_SOFTC_TX_RING_DATA_COUNT
];
139 rt2870_softc_tx_data_queue inactive
;
140 rt2870_softc_tx_data_queue pending
;
141 rt2870_softc_tx_data_queue active
;
142 rt2870_softc_tx_data_queue done
;
147 struct rt2870_softc_cmd
149 STAILQ_ENTRY(rt2870_softc_cmd
) next
;
150 void (*cb
)(struct rt2870_softc
*sc
, void *arg
);
151 uint8_t data
[RT2870_SOFTC_CMD_DATA_LEN
];
154 typedef STAILQ_HEAD(, rt2870_softc_cmd
) rt2870_softc_cmd_queue
;
156 struct rt2870_softc_cmd_ring
158 struct rt2870_softc_cmd cmd
[RT2870_SOFTC_CMD_RING_CMD_COUNT
];
159 rt2870_softc_cmd_queue inactive
;
160 rt2870_softc_cmd_queue active
;
164 struct rt2870_softc_node
166 struct ieee80211_node ni
;
169 struct rt2870_softc_vap
171 struct ieee80211vap vap
;
172 struct ieee80211_beacon_offsets beacon_offsets
;
173 struct rt2870_amrr amrr
;
175 int (*newstate
)(struct ieee80211vap
*vap
,
176 enum ieee80211_state nstate
, int arg
);
179 struct rt2870_softc_rx_radiotap_header
181 struct ieee80211_radiotap_header ihdr
;
184 int8_t dbm_antsignal
;
195 struct rt2870_softc_tx_radiotap_header
197 struct ieee80211_radiotap_header ihdr
;
216 struct usb_device
*usb_dev
;
217 struct usb_xfer
*usb_xfer
[1 + RT2870_SOFTC_TX_RING_COUNT
];
222 int (*recv_action
)(struct ieee80211_node
*ni
,
223 const struct ieee80211_frame
*wh
,
224 const uint8_t *frm
, const uint8_t *efrm
);
226 int (*send_action
)(struct ieee80211_node
*ni
,
227 int cat
, int act
, void *sa
);
229 struct rt2870_amrr_node amrr_node
[RT2870_SOFTC_AMRR_NODE_COUNT
];
235 uint8_t mac_addr
[IEEE80211_ADDR_LEN
];
245 uint8_t country_2ghz
;
246 uint8_t country_5ghz
;
251 uint16_t led_off
[RT2870_SOFTC_LED_OFF_COUNT
];
253 int8_t rssi_off_2ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
254 int8_t rssi_off_5ghz
[RT2870_SOFTC_RSSI_OFF_COUNT
];
256 int8_t lna_gain
[RT2870_SOFTC_LNA_GAIN_COUNT
];
258 int8_t txpow1
[RT2870_SOFTC_TXPOW_COUNT
];
259 int8_t txpow2
[RT2870_SOFTC_TXPOW_COUNT
];
261 int8_t txpow_rate_delta_2ghz
;
262 int8_t txpow_rate_delta_5ghz
;
263 uint32_t txpow_rate_20mhz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
264 uint32_t txpow_rate_40mhz_2ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
265 uint32_t txpow_rate_40mhz_5ghz
[RT2870_SOFTC_TXPOW_RATE_COUNT
];
267 int tx_agc_cntl_2ghz
;
268 int tx_agc_cntl_5ghz
;
270 uint8_t tssi_2ghz
[RT2870_SOFTC_TSSI_COUNT
];
271 uint8_t tssi_step_2ghz
;
272 uint8_t tssi_5ghz
[RT2870_SOFTC_TSSI_COUNT
];
273 uint8_t tssi_step_5ghz
;
279 } __packed bbp_eeprom
[RT2870_SOFTC_BBP_EEPROM_COUNT
];
281 struct task rx_done_task
;
282 int rx_process_limit
;
284 struct task tx_done_task
;
286 struct task periodic_task
;
287 struct callout periodic_ch
;
288 unsigned long periodic_round
;
290 struct task cmd_task
;
292 struct taskqueue
*taskqueue
;
294 struct rt2870_softc_rx_ring rx_ring
;
296 struct rt2870_softc_tx_ring tx_ring
[RT2870_SOFTC_TX_RING_COUNT
];
299 struct callout tx_watchdog_ch
;
302 struct rt2870_softc_cmd_ring cmd_ring
;
304 struct rt2870_softc_rx_radiotap_header rxtap
;
305 struct rt2870_softc_tx_radiotap_header txtap
;
307 /* statistic counters */
309 unsigned long interrupts
;
310 unsigned long rx_interrupts
;
311 unsigned long tx_interrupts
[RT2870_SOFTC_TX_RING_COUNT
];
313 unsigned long tx_watchdog_timeouts
;
315 unsigned long rx_mbuf_alloc_errors
;
317 unsigned long tx_queue_not_empty
[2];
319 unsigned long rx_packets
;
320 unsigned long rx_crc_errors
;
321 unsigned long rx_phy_errors
;
322 unsigned long rx_false_ccas
;
323 unsigned long rx_plcp_errors
;
324 unsigned long rx_dup_packets
;
325 unsigned long rx_fifo_overflows
;
332 #endif /* #ifndef _RT2870_SOFTC_H_ */