]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/urtwn/if_urtwnvar.h
Import to 0.6.1
[FreeBSD/FreeBSD.git] / sys / dev / urtwn / if_urtwnvar.h
1 /*-
2  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  * 
16  * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
17  * $FreeBSD$
18  */
19
20 #define URTWN_RX_LIST_COUNT             64
21 #define URTWN_TX_LIST_COUNT             8
22 #define URTWN_HOST_CMD_RING_COUNT       32
23
24 #define URTWN_RXBUFSZ   (8 * 1024)
25 //#define URTWN_TXBUFSZ (sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN)
26 /* Leave enough space for an A-MSDU frame */
27 #define URTWN_TXBUFSZ   (16 * 1024)
28 #define URTWN_RX_DESC_SIZE      (sizeof(struct r92c_rx_stat))
29 #define URTWN_TX_DESC_SIZE      (sizeof(struct r92c_tx_desc))
30
31 #define URTWN_TX_TIMEOUT        5000    /* ms */
32
33 #define URTWN_LED_LINK  0
34 #define URTWN_LED_DATA  1
35
36 struct urtwn_rx_radiotap_header {
37         struct ieee80211_radiotap_header wr_ihdr;
38         uint64_t        wr_tsft;
39         uint8_t         wr_flags;
40         uint8_t         wr_rate;
41         uint16_t        wr_chan_freq;
42         uint16_t        wr_chan_flags;
43         int8_t          wr_dbm_antsignal;
44         int8_t          wr_dbm_antnoise;
45 } __packed __aligned(8);
46
47 #define URTWN_RX_RADIOTAP_PRESENT                       \
48         (1 << IEEE80211_RADIOTAP_TSFT |                 \
49          1 << IEEE80211_RADIOTAP_FLAGS |                \
50          1 << IEEE80211_RADIOTAP_RATE |                 \
51          1 << IEEE80211_RADIOTAP_CHANNEL |              \
52          1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |        \
53          1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)
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 __aligned(8);
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_data {
69         struct urtwn_softc              *sc;
70         uint8_t                         *buf;
71         uint16_t                        buflen;
72         struct mbuf                     *m;
73         struct ieee80211_node           *ni;
74         STAILQ_ENTRY(urtwn_data)        next;
75 };
76 typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead;
77
78 union sec_param {
79         struct ieee80211_key            key;
80 };
81
82 #define CMD_FUNC_PROTO                  void (*func)(struct urtwn_softc *, \
83                                             union sec_param *)
84
85 struct urtwn_cmdq {
86         union sec_param                 data;
87         CMD_FUNC_PROTO;
88 };
89 #define URTWN_CMDQ_SIZE                 16
90
91 struct urtwn_fw_info {
92         const uint8_t           *data;
93         size_t                  size;
94 };
95
96 struct urtwn_node {
97         struct ieee80211_node   ni;     /* must be the first */
98         uint8_t                 id;
99         int                     last_rssi;
100 };
101 #define URTWN_NODE(ni)  ((struct urtwn_node *)(ni))
102
103 struct urtwn_vap {
104         struct ieee80211vap     vap;
105
106         struct r92c_tx_desc     bcn_desc;
107         struct mbuf             *bcn_mbuf;
108         struct task             tsf_task_adhoc;
109
110         int                     (*newstate)(struct ieee80211vap *,
111                                     enum ieee80211_state, int);
112         void                    (*recv_mgmt)(struct ieee80211_node *,
113                                     struct mbuf *, int,
114                                     const struct ieee80211_rx_stats *,
115                                     int, int);
116 };
117 #define URTWN_VAP(vap)  ((struct urtwn_vap *)(vap))
118
119 struct urtwn_host_cmd {
120         void    (*cb)(struct urtwn_softc *, void *);
121         uint8_t data[256];
122 };
123
124 struct urtwn_cmd_newstate {
125         enum ieee80211_state    state;
126         int                     arg;
127 };
128
129 struct urtwn_cmd_key {
130         struct ieee80211_key    key;
131         uint16_t                associd;
132 };
133
134 enum {
135         URTWN_BULK_RX,
136         URTWN_BULK_TX_BE,       /* = WME_AC_BE */
137         URTWN_BULK_TX_BK,       /* = WME_AC_BK */
138         URTWN_BULK_TX_VI,       /* = WME_AC_VI */
139         URTWN_BULK_TX_VO,       /* = WME_AC_VI */
140         URTWN_N_TRANSFER = 5,
141 };
142
143 #define URTWN_EP_QUEUES URTWN_BULK_RX
144
145 union urtwn_rom {
146         struct r92c_rom                 r92c_rom;
147         struct r88e_rom                 r88e_rom;
148 };
149
150 struct urtwn_softc {
151         struct ieee80211com             sc_ic;
152         struct mbufq                    sc_snd;
153         device_t                        sc_dev;
154         struct usb_device               *sc_udev;
155
156         uint32_t                        sc_debug;
157         uint8_t                         sc_iface_index;
158         uint8_t                         sc_flags;
159 #define URTWN_FLAG_CCK_HIPWR    0x01
160 #define URTWN_DETACHED          0x02
161 #define URTWN_RUNNING           0x04
162 #define URTWN_FW_LOADED         0x08
163 #define URTWN_TEMP_MEASURED     0x10
164
165         u_int                           chip;
166 #define URTWN_CHIP_92C          0x01
167 #define URTWN_CHIP_92C_1T2R     0x02
168 #define URTWN_CHIP_UMC          0x04
169 #define URTWN_CHIP_UMC_A_CUT    0x08
170 #define URTWN_CHIP_88E          0x10
171
172 #define URTWN_CHIP_HAS_RATECTL(_sc)     (!!((_sc)->chip & URTWN_CHIP_88E))
173
174         void                            (*sc_node_free)(struct ieee80211_node *);
175         void                            (*sc_rf_write)(struct urtwn_softc *,
176                                             int, uint8_t, uint32_t);
177         int                             (*sc_power_on)(struct urtwn_softc *);
178         void                            (*sc_power_off)(struct urtwn_softc *);
179
180         struct ieee80211_node           *node_list[R88E_MACID_MAX + 1];
181         struct mtx                      nt_mtx;
182
183         uint8_t                         board_type;
184         uint8_t                         regulatory;
185         uint8_t                         pa_setting;
186         int8_t                          ofdm_tx_pwr_diff;
187         int8_t                          bw20_tx_pwr_diff;
188         int                             avg_pwdb;
189         uint8_t                         thcal_lctemp;
190         int                             ntxchains;
191         int                             nrxchains;
192         int                             ledlink;
193         int                             sc_txtimer;
194
195         int                             last_rssi;
196
197         int                             fwcur;
198         struct urtwn_data               sc_rx[URTWN_RX_LIST_COUNT];
199         urtwn_datahead                  sc_rx_active;
200         urtwn_datahead                  sc_rx_inactive;
201         struct urtwn_data               sc_tx[URTWN_TX_LIST_COUNT];
202         urtwn_datahead                  sc_tx_active;
203         int                             sc_tx_n_active;
204         urtwn_datahead                  sc_tx_inactive;
205         urtwn_datahead                  sc_tx_pending;
206
207         union urtwn_rom                 rom;
208         uint16_t                        last_rom_addr;
209
210         struct callout                  sc_calib_to;
211         struct callout                  sc_watchdog_ch;
212         struct mtx                      sc_mtx;
213         uint32_t                        keys_bmap;
214
215         struct urtwn_cmdq               cmdq[URTWN_CMDQ_SIZE];
216         struct mtx                      cmdq_mtx;
217         struct task                     cmdq_task;
218         uint8_t                         cmdq_first;
219         uint8_t                         cmdq_last;
220
221         uint32_t                        rf_chnlbw[R92C_MAX_CHAINS];
222         struct usb_xfer                 *sc_xfer[URTWN_N_TRANSFER];
223
224         struct urtwn_rx_radiotap_header sc_rxtap;
225         struct urtwn_tx_radiotap_header sc_txtap;
226 };
227
228 #define URTWN_LOCK(sc)                  mtx_lock(&(sc)->sc_mtx)
229 #define URTWN_UNLOCK(sc)                mtx_unlock(&(sc)->sc_mtx)
230 #define URTWN_ASSERT_LOCKED(sc)         mtx_assert(&(sc)->sc_mtx, MA_OWNED)
231
232 #define URTWN_CMDQ_LOCK_INIT(sc) \
233         mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
234 #define URTWN_CMDQ_LOCK(sc)             mtx_lock(&(sc)->cmdq_mtx)
235 #define URTWN_CMDQ_UNLOCK(sc)           mtx_unlock(&(sc)->cmdq_mtx)
236 #define URTWN_CMDQ_LOCK_DESTROY(sc)     mtx_destroy(&(sc)->cmdq_mtx)
237
238 #define URTWN_NT_LOCK_INIT(sc) \
239         mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
240 #define URTWN_NT_LOCK(sc)               mtx_lock(&(sc)->nt_mtx)
241 #define URTWN_NT_UNLOCK(sc)             mtx_unlock(&(sc)->nt_mtx)
242 #define URTWN_NT_LOCK_DESTROY(sc)       mtx_destroy(&(sc)->nt_mtx)