xref: /freebsd/sys/dev/usb/wlan/if_uralvar.h (revision f4f8f02054f3abb6ceb84aefcdecc78d5c8b462f)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2005
5  *	Damien Bergamini <damien.bergamini@free.fr>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #define RAL_TX_LIST_COUNT	8
21 #define RAL_TX_MINFREE		2
22 
23 #define URAL_SCAN_START         1
24 #define URAL_SCAN_END           2
25 #define URAL_SET_CHANNEL        3
26 
27 
28 struct ural_rx_radiotap_header {
29 	struct ieee80211_radiotap_header wr_ihdr;
30 	uint8_t		wr_flags;
31 	uint8_t		wr_rate;
32 	uint16_t	wr_chan_freq;
33 	uint16_t	wr_chan_flags;
34 	uint8_t		wr_antenna;
35 	uint8_t		wr_antsignal;
36 };
37 
38 #define RAL_RX_RADIOTAP_PRESENT						\
39 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
40 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
41 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
42 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
43 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
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 };
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_node {
73 	struct ieee80211_node		ni;
74 	struct ieee80211_amrr_node	amn;
75 };
76 #define	URAL_NODE(ni)	((struct ural_node *)(ni))
77 
78 struct ural_vap {
79 	struct ieee80211vap		vap;
80 	struct ieee80211_beacon_offsets	bo;
81 	struct ieee80211_amrr		amrr;
82 	struct usb2_callout		amrr_ch;
83 	struct task			amrr_task;
84 
85 	int				(*newstate)(struct ieee80211vap *,
86 					    enum ieee80211_state, int);
87 };
88 #define	URAL_VAP(vap)	((struct ural_vap *)(vap))
89 
90 enum {
91 	URAL_BULK_WR,
92 	URAL_BULK_RD,
93 	URAL_N_TRANSFER = 2,
94 };
95 
96 struct ural_softc {
97 	struct ifnet			*sc_ifp;
98 	device_t			sc_dev;
99 	struct usb2_device		*sc_udev;
100 
101 	uint32_t			asic_rev;
102 	uint8_t				rf_rev;
103 
104 	struct usb2_xfer		*sc_xfer[URAL_N_TRANSFER];
105 
106 	struct ural_tx_data		tx_data[RAL_TX_LIST_COUNT];
107 	ural_txdhead			tx_q;
108 	ural_txdhead			tx_free;
109 	int				tx_nfree;
110 	struct ural_rx_desc		sc_rx_desc;
111 
112 	struct mtx			sc_mtx;
113 
114 	uint16_t			sta[11];
115 	uint32_t			rf_regs[4];
116 	uint8_t				txpow[14];
117 	uint8_t				sc_bssid[6];
118 
119 	struct {
120 		uint8_t			val;
121 		uint8_t			reg;
122 	} __packed			bbp_prom[16];
123 
124 	int				led_mode;
125 	int				hw_radio;
126 	int				rx_ant;
127 	int				tx_ant;
128 	int				nb_ant;
129 
130 	struct ural_rx_radiotap_header	sc_rxtap;
131 	int				sc_rxtap_len;
132 
133 	struct ural_tx_radiotap_header	sc_txtap;
134 	int				sc_txtap_len;
135 };
136 
137 #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
138 #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
139 #define RAL_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
140