if_urtwnvar.h revision 1.10.16.4 1 /* $NetBSD: if_urtwnvar.h,v 1.10.16.4 2020/04/08 14:08:13 martin Exp $ */
2 /* $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $ */
3
4 /*-
5 * Copyright (c) 2010 Damien Bergamini <damien.bergamini (at) 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 #ifndef _IF_URTWNVAR_H_
20 #define _IF_URTWNVAR_H_
21
22 /*
23 * Driver definitions.
24 */
25 #define URTWN_RX_LIST_COUNT 1
26 #define URTWN_TX_LIST_COUNT 8
27
28 #define URTWN_HOST_CMD_RING_COUNT 32
29
30 #define URTWN_RXBUFSZ (16 * 1024)
31 #define URTWN_TXBUFSZ (sizeof(struct r92c_tx_desc_usb) + IEEE80211_MAX_LEN + 8)
32
33 #define URTWN_RIDX_COUNT 28
34
35 #define URTWN_TX_TIMEOUT 5000 /* ms */
36
37 #define URTWN_LED_LINK 0
38 #define URTWN_LED_DATA 1
39
40 struct urtwn_rx_radiotap_header {
41 struct ieee80211_radiotap_header wr_ihdr;
42 uint8_t wr_flags;
43 uint8_t wr_rate;
44 uint16_t wr_chan_freq;
45 uint16_t wr_chan_flags;
46 uint8_t wr_dbm_antsignal;
47 } __packed;
48
49 #define URTWN_RX_RADIOTAP_PRESENT \
50 (1 << IEEE80211_RADIOTAP_FLAGS | \
51 1 << IEEE80211_RADIOTAP_RATE | \
52 1 << IEEE80211_RADIOTAP_CHANNEL | \
53 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
54
55 struct urtwn_tx_radiotap_header {
56 struct ieee80211_radiotap_header wt_ihdr;
57 uint8_t wt_flags;
58 uint16_t wt_chan_freq;
59 uint16_t wt_chan_flags;
60 } __packed;
61
62 #define URTWN_TX_RADIOTAP_PRESENT \
63 (1 << IEEE80211_RADIOTAP_FLAGS | \
64 1 << IEEE80211_RADIOTAP_CHANNEL)
65
66 struct urtwn_softc;
67
68 struct urtwn_rx_data {
69 struct urtwn_softc *sc;
70 size_t pidx;
71 struct usbd_xfer *xfer;
72 uint8_t *buf;
73 TAILQ_ENTRY(urtwn_rx_data) next;
74 };
75
76 struct urtwn_tx_data {
77 struct urtwn_softc *sc;
78 size_t pidx;
79 struct usbd_xfer *xfer;
80 uint8_t *buf;
81 TAILQ_ENTRY(urtwn_tx_data) next;
82 };
83
84 struct urtwn_host_cmd {
85 void (*cb)(struct urtwn_softc *, void *);
86 uint8_t data[256];
87 };
88
89 struct urtwn_cmd_newstate {
90 enum ieee80211_state state;
91 int arg;
92 };
93
94 struct urtwn_host_cmd_ring {
95 struct urtwn_host_cmd cmd[URTWN_HOST_CMD_RING_COUNT];
96 int cur;
97 int next;
98 int queued;
99 };
100
101 #if 1 /* XXX: sys/net80211/ieee80211.h */
102
103 #define IEEE80211_HTINFO_2NDCHAN 0x03 /* secondary/ext chan offset */
104 #define IEEE80211_HTINFO_2NDCHAN_S 0
105 #define IEEE80211_HTINFO_2NDCHAN_NONE 0x00 /* no secondary/ext channel */
106 #define IEEE80211_HTINFO_2NDCHAN_ABOVE 0x01 /* above private channel */
107 /* NB: 2 is reserved */
108 #define IEEE80211_HTINFO_2NDCHAN_BELOW 0x03 /* below primary channel */
109 #endif /* XXX: 1 */
110
111 struct urtwn_softc {
112 device_t sc_dev;
113 struct ieee80211com sc_ic;
114 struct ifqueue sc_sendq;
115 int (*sc_newstate)(struct ieee80211vap *,
116 enum ieee80211_state, int);
117
118 struct usbd_device * sc_udev;
119 struct usbd_interface * sc_iface;
120 u_int sc_flags;
121 #define URTWN_FLAG_CCK_HIPWR __BIT(0)
122 #define URTWN_FLAG_ATTACHED __BIT(1)
123 #define URTWN_FLAG_FWREADY __BIT(2)
124 int sc_dying;
125
126 struct usb_task sc_task;
127 callout_t sc_scan_to;
128 callout_t sc_calib_to;
129
130 kcondvar_t sc_task_cv;
131 kmutex_t sc_task_mtx;
132 kmutex_t sc_fwcmd_mtx;
133 kmutex_t sc_tx_mtx;
134 kmutex_t sc_rx_mtx;
135 kmutex_t sc_write_mtx;
136 kmutex_t sc_media_mtx; /* XXX */
137
138 struct usbd_pipe * rx_pipe[R92C_MAX_EPIN];
139 int rx_npipe;
140 struct usbd_pipe * tx_pipe[R92C_MAX_EPOUT];
141 int tx_npipe;
142 int ac2idx[WME_NUM_AC];
143
144 u_int chip;
145 #define URTWN_CHIP_92C 0x01
146 #define URTWN_CHIP_92C_1T2R 0x02
147 #define URTWN_CHIP_UMC 0x04
148 #define URTWN_CHIP_UMC_A_CUT 0x08
149 #define URTWN_CHIP_88E 0x10
150 #define URTWN_CHIP_92EU 0x20
151
152 void (*sc_rf_write)(struct urtwn_softc *,
153 int, uint8_t, uint32_t);
154 int (*sc_power_on)(struct urtwn_softc *);
155 int (*sc_dma_init)(struct urtwn_softc *);
156
157 uint8_t board_type;
158 uint8_t regulatory;
159 uint8_t pa_setting;
160 int avg_pwdb;
161 int thcal_state;
162 int thcal_lctemp;
163 size_t ntxchains;
164 size_t nrxchains;
165 int ledlink;
166 bool iqk_inited;
167
168 int tx_timer;
169
170 struct urtwn_host_cmd_ring cmdq;
171 int fwcur;
172 struct urtwn_rx_data rx_data[R92C_MAX_EPIN][URTWN_RX_LIST_COUNT];
173 struct urtwn_tx_data tx_data[R92C_MAX_EPOUT][URTWN_TX_LIST_COUNT];
174 TAILQ_HEAD(, urtwn_tx_data) tx_free_list[R92C_MAX_EPOUT];
175 TAILQ_HEAD(, urtwn_rx_data) rx_free_list[R92C_MAX_EPIN];
176
177 struct r92c_rom rom;
178 uint8_t r88e_rom[4096];
179 uint8_t cck_tx_pwr[6];
180 uint8_t ht40_tx_pwr[5];
181 int8_t bw20_tx_pwr_diff;
182 int8_t ofdm_tx_pwr_diff;
183
184 uint32_t rf_chnlbw[R92C_MAX_CHAINS];
185
186 struct bpf_if * sc_drvbpf;
187 union {
188 struct urtwn_rx_radiotap_header th;
189 uint8_t pad[64];
190 } sc_rxtapu;
191 #define sc_rxtap sc_rxtapu.th
192 int sc_rxtap_len;
193 union {
194 struct urtwn_tx_radiotap_header th;
195 uint8_t pad[64];
196 } sc_txtapu;
197 #define sc_txtap sc_txtapu.th
198 int sc_txtap_len;
199 bool sc_running;
200
201 struct ieee80211_beacon_offsets sc_bo;
202 };
203
204 #endif /* _IF_URTWNVAR_H_ */
205