xref: /freebsd/sys/dev/usb/wlan/if_uralvar.h (revision 06c3fb27)
1 
2 /*-
3  * Copyright (c) 2005
4  *	Damien Bergamini <damien.bergamini@free.fr>
5  *
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.
9  *
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.
17  */
18 
19 #define RAL_TX_LIST_COUNT	8
20 #define RAL_TX_MINFREE		2
21 
22 #define URAL_SCAN_START         1
23 #define URAL_SCAN_END           2
24 #define URAL_SET_CHANNEL        3
25 
26 struct ural_rx_radiotap_header {
27 	struct ieee80211_radiotap_header wr_ihdr;
28 	uint8_t		wr_flags;
29 	uint8_t		wr_rate;
30 	uint16_t	wr_chan_freq;
31 	uint16_t	wr_chan_flags;
32 	int8_t		wr_antsignal;
33 	int8_t		wr_antnoise;
34 	uint8_t		wr_antenna;
35 } __packed __aligned(8);
36 
37 #define RAL_RX_RADIOTAP_PRESENT						\
38 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
39 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
40 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
41 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
42 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
43 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
44 
45 struct ural_tx_radiotap_header {
46 	struct ieee80211_radiotap_header wt_ihdr;
47 	uint8_t		wt_flags;
48 	uint8_t		wt_rate;
49 	uint16_t	wt_chan_freq;
50 	uint16_t	wt_chan_flags;
51 	uint8_t		wt_antenna;
52 } __packed;
53 
54 #define RAL_TX_RADIOTAP_PRESENT						\
55 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
56 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
57 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
58 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
59 
60 struct ural_softc;
61 
62 struct ural_tx_data {
63 	STAILQ_ENTRY(ural_tx_data)	next;
64 	struct ural_softc		*sc;
65 	struct ural_tx_desc		desc;
66 	struct mbuf			*m;
67 	struct ieee80211_node		*ni;
68 	int				rate;
69 };
70 typedef STAILQ_HEAD(, ural_tx_data) ural_txdhead;
71 
72 struct ural_vap {
73 	struct ieee80211vap		vap;
74 
75 	struct usb_callout		ratectl_ch;
76 	struct task			ratectl_task;
77 
78 	int				(*newstate)(struct ieee80211vap *,
79 					    enum ieee80211_state, int);
80 };
81 #define	URAL_VAP(vap)	((struct ural_vap *)(vap))
82 
83 enum {
84 	URAL_BULK_WR,
85 	URAL_BULK_RD,
86 	URAL_N_TRANSFER = 2,
87 };
88 
89 struct ural_softc {
90 	struct ieee80211com		sc_ic;
91 	struct ieee80211_ratectl_tx_stats sc_txs;
92 	struct mbufq			sc_snd;
93 	device_t			sc_dev;
94 	struct usb_device		*sc_udev;
95 
96 	uint32_t			asic_rev;
97 	uint8_t				rf_rev;
98 
99 	struct usb_xfer			*sc_xfer[URAL_N_TRANSFER];
100 
101 	struct ural_tx_data		tx_data[RAL_TX_LIST_COUNT];
102 	ural_txdhead			tx_q;
103 	ural_txdhead			tx_free;
104 	int				tx_nfree;
105 	struct ural_rx_desc		sc_rx_desc;
106 
107 	struct mtx			sc_mtx;
108 
109 	uint16_t			sta[11];
110 	uint32_t			rf_regs[4];
111 	uint8_t				txpow[14];
112 	u_int				sc_detached:1,
113 					sc_running:1;
114 
115 	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
116 
117 	struct {
118 		uint8_t			val;
119 		uint8_t			reg;
120 	} __packed			bbp_prom[16];
121 
122 	int				led_mode;
123 	int				hw_radio;
124 	int				rx_ant;
125 	int				tx_ant;
126 	int				nb_ant;
127 
128 	struct ural_rx_radiotap_header	sc_rxtap;
129 	struct ural_tx_radiotap_header	sc_txtap;
130 };
131 
132 #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
133 #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
134 #define RAL_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
135