]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/urtwn/if_urtwnvar.h
MFC r344990:
[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         uint8_t         wt_pad;
59         uint16_t        wt_chan_freq;
60         uint16_t        wt_chan_flags;
61 } __packed;
62
63 #define URTWN_TX_RADIOTAP_PRESENT                       \
64         (1 << IEEE80211_RADIOTAP_FLAGS |                \
65          1 << IEEE80211_RADIOTAP_CHANNEL)
66
67 struct urtwn_softc;
68
69 struct urtwn_data {
70         struct urtwn_softc              *sc;
71         uint8_t                         *buf;
72         uint16_t                        buflen;
73         struct mbuf                     *m;
74         struct ieee80211_node           *ni;
75         STAILQ_ENTRY(urtwn_data)        next;
76 };
77 typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead;
78
79 union sec_param {
80         struct ieee80211_key            key;
81 };
82
83 #define CMD_FUNC_PROTO                  void (*func)(struct urtwn_softc *, \
84                                             union sec_param *)
85
86 struct urtwn_cmdq {
87         union sec_param                 data;
88         CMD_FUNC_PROTO;
89 };
90 #define URTWN_CMDQ_SIZE                 16
91
92 struct urtwn_fw_info {
93         const uint8_t           *data;
94         size_t                  size;
95 };
96
97 struct urtwn_node {
98         struct ieee80211_node   ni;     /* must be the first */
99         uint8_t                 id;
100         int                     last_rssi;
101 };
102 #define URTWN_NODE(ni)  ((struct urtwn_node *)(ni))
103
104 struct urtwn_vap {
105         struct ieee80211vap     vap;
106
107         struct r92c_tx_desc     bcn_desc;
108         struct mbuf             *bcn_mbuf;
109         struct task             tsf_task_adhoc;
110
111         const struct ieee80211_key      *keys[IEEE80211_WEP_NKID];
112
113         int                     (*newstate)(struct ieee80211vap *,
114                                     enum ieee80211_state, int);
115         void                    (*recv_mgmt)(struct ieee80211_node *,
116                                     struct mbuf *, int,
117                                     const struct ieee80211_rx_stats *,
118                                     int, int);
119 };
120 #define URTWN_VAP(vap)  ((struct urtwn_vap *)(vap))
121
122 enum {
123         URTWN_BULK_RX,
124         URTWN_BULK_TX_BE,       /* = WME_AC_BE */
125         URTWN_BULK_TX_BK,       /* = WME_AC_BK */
126         URTWN_BULK_TX_VI,       /* = WME_AC_VI */
127         URTWN_BULK_TX_VO,       /* = WME_AC_VI */
128         URTWN_N_TRANSFER = 5,
129 };
130
131 #define URTWN_EP_QUEUES URTWN_BULK_RX
132
133 union urtwn_rom {
134         struct r92c_rom                 r92c_rom;
135         struct r88e_rom                 r88e_rom;
136 };
137
138 struct urtwn_softc {
139         struct ieee80211com             sc_ic;
140         struct mbufq                    sc_snd;
141         device_t                        sc_dev;
142         struct usb_device               *sc_udev;
143
144         uint32_t                        sc_debug;
145         uint8_t                         sc_iface_index;
146         uint8_t                         sc_flags;
147 #define URTWN_FLAG_CCK_HIPWR    0x01
148 #define URTWN_DETACHED          0x02
149 #define URTWN_RUNNING           0x04
150 #define URTWN_FW_LOADED         0x08
151 #define URTWN_TEMP_MEASURED     0x10
152
153         u_int                           chip;
154 #define URTWN_CHIP_92C          0x01
155 #define URTWN_CHIP_92C_1T2R     0x02
156 #define URTWN_CHIP_UMC          0x04
157 #define URTWN_CHIP_UMC_A_CUT    0x08
158 #define URTWN_CHIP_88E          0x10
159
160 #define URTWN_CHIP_HAS_RATECTL(_sc)     (!!((_sc)->chip & URTWN_CHIP_88E))
161
162         void                            (*sc_node_free)(struct ieee80211_node *);
163         void                            (*sc_rf_write)(struct urtwn_softc *,
164                                             int, uint8_t, uint32_t);
165         int                             (*sc_power_on)(struct urtwn_softc *);
166         void                            (*sc_power_off)(struct urtwn_softc *);
167
168         struct ieee80211_node           *node_list[R88E_MACID_MAX + 1];
169         struct mtx                      nt_mtx;
170
171         uint8_t                         board_type;
172         uint8_t                         regulatory;
173         uint8_t                         pa_setting;
174         int8_t                          ofdm_tx_pwr_diff;
175         int8_t                          bw20_tx_pwr_diff;
176         int                             avg_pwdb;
177         uint8_t                         thcal_lctemp;
178         int                             ntxchains;
179         int                             nrxchains;
180         int                             ledlink;
181         int                             sc_txtimer;
182
183         int                             last_rssi;
184
185         int                             fwcur;
186         struct urtwn_data               sc_rx[URTWN_RX_LIST_COUNT];
187         urtwn_datahead                  sc_rx_active;
188         urtwn_datahead                  sc_rx_inactive;
189         struct urtwn_data               sc_tx[URTWN_TX_LIST_COUNT];
190         urtwn_datahead                  sc_tx_active;
191         int                             sc_tx_n_active;
192         urtwn_datahead                  sc_tx_inactive;
193         urtwn_datahead                  sc_tx_pending;
194
195         union urtwn_rom                 rom;
196         uint16_t                        last_rom_addr;
197
198         struct callout                  sc_calib_to;
199         struct callout                  sc_watchdog_ch;
200         struct mtx                      sc_mtx;
201         uint32_t                        keys_bmap;
202
203         struct urtwn_cmdq               cmdq[URTWN_CMDQ_SIZE];
204         struct mtx                      cmdq_mtx;
205         struct task                     cmdq_task;
206         uint8_t                         cmdq_first;
207         uint8_t                         cmdq_last;
208
209         uint32_t                        rf_chnlbw[R92C_MAX_CHAINS];
210         struct usb_xfer                 *sc_xfer[URTWN_N_TRANSFER];
211
212         struct urtwn_rx_radiotap_header sc_rxtap;
213         struct urtwn_tx_radiotap_header sc_txtap;
214 };
215
216 #define URTWN_LOCK(sc)                  mtx_lock(&(sc)->sc_mtx)
217 #define URTWN_UNLOCK(sc)                mtx_unlock(&(sc)->sc_mtx)
218 #define URTWN_ASSERT_LOCKED(sc)         mtx_assert(&(sc)->sc_mtx, MA_OWNED)
219
220 #define URTWN_CMDQ_LOCK_INIT(sc) \
221         mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
222 #define URTWN_CMDQ_LOCK(sc)             mtx_lock(&(sc)->cmdq_mtx)
223 #define URTWN_CMDQ_UNLOCK(sc)           mtx_unlock(&(sc)->cmdq_mtx)
224 #define URTWN_CMDQ_LOCK_DESTROY(sc)     mtx_destroy(&(sc)->cmdq_mtx)
225
226 #define URTWN_NT_LOCK_INIT(sc) \
227         mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
228 #define URTWN_NT_LOCK(sc)               mtx_lock(&(sc)->nt_mtx)
229 #define URTWN_NT_UNLOCK(sc)             mtx_unlock(&(sc)->nt_mtx)
230 #define URTWN_NT_LOCK_DESTROY(sc)       mtx_destroy(&(sc)->nt_mtx)