]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/wpi/if_wpivar.h
Update llvm, clang and lldb to 3.7.0 release.
[FreeBSD/FreeBSD.git] / sys / dev / wpi / if_wpivar.h
1 /*      $FreeBSD$       */
2
3 /*-
4  * Copyright (c) 2006,2007
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 struct wpi_rx_radiotap_header {
20         struct ieee80211_radiotap_header wr_ihdr;
21         uint64_t        wr_tsft;
22         uint8_t         wr_flags;
23         uint8_t         wr_rate;
24         uint16_t        wr_chan_freq;
25         uint16_t        wr_chan_flags;
26         int8_t          wr_dbm_antsignal;
27         int8_t          wr_dbm_antnoise;
28         uint8_t         wr_antenna;
29 } __packed;
30
31 #define WPI_RX_RADIOTAP_PRESENT                                         \
32         ((1 << IEEE80211_RADIOTAP_TSFT) |                               \
33          (1 << IEEE80211_RADIOTAP_FLAGS) |                              \
34          (1 << IEEE80211_RADIOTAP_RATE) |                               \
35          (1 << IEEE80211_RADIOTAP_CHANNEL) |                            \
36          (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |                      \
37          (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |                       \
38          (1 << IEEE80211_RADIOTAP_ANTENNA))
39
40 struct wpi_tx_radiotap_header {
41         struct ieee80211_radiotap_header wt_ihdr;
42         uint8_t         wt_flags;
43         uint8_t         wt_rate;
44         uint16_t        wt_chan_freq;
45         uint16_t        wt_chan_flags;
46 } __packed;
47
48 #define WPI_TX_RADIOTAP_PRESENT                                         \
49         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
50          (1 << IEEE80211_RADIOTAP_RATE) |                               \
51          (1 << IEEE80211_RADIOTAP_CHANNEL))
52
53 struct wpi_dma_info {
54         bus_dma_tag_t           tag;
55         bus_dmamap_t            map;
56         bus_addr_t              paddr;
57         caddr_t                 vaddr;
58         bus_size_t              size;
59 };
60
61 struct wpi_tx_data {
62         bus_dmamap_t            map;
63         bus_addr_t              cmd_paddr;
64         struct mbuf             *m;
65         struct ieee80211_node   *ni;
66 };
67
68 struct wpi_tx_ring {
69         struct wpi_dma_info     desc_dma;
70         struct wpi_dma_info     cmd_dma;
71         struct wpi_tx_desc      *desc;
72         struct wpi_tx_cmd       *cmd;
73         struct wpi_tx_data      data[WPI_TX_RING_COUNT];
74         bus_dma_tag_t           data_dmat;
75         struct mbufq            snd;
76         int                     qid;
77         int                     queued;
78         int                     cur;
79         int                     update;
80 };
81
82 struct wpi_rx_data {
83         struct mbuf     *m;
84         bus_dmamap_t    map;
85 };
86
87 struct wpi_rx_ring {
88         struct wpi_dma_info     desc_dma;
89         uint32_t                *desc;
90         struct wpi_rx_data      data[WPI_RX_RING_COUNT];
91         bus_dma_tag_t           data_dmat;
92         int                     cur;
93         int                     update;
94 };
95
96 struct wpi_node {
97         struct ieee80211_node   ni;     /* must be the first */
98         uint8_t                 id;
99 };
100 #define WPI_NODE(ni)    ((struct wpi_node *)(ni))
101
102 struct wpi_power_sample {
103         uint8_t index;
104         int8_t  power;
105 };
106
107 struct wpi_power_group {
108 #define WPI_SAMPLES_COUNT       5
109         struct wpi_power_sample samples[WPI_SAMPLES_COUNT];
110         uint8_t chan;
111         int8_t  maxpwr;
112         int16_t temp;
113 };
114
115 struct wpi_buf {
116         uint8_t                 data[56];  /* sizeof(struct wpi_cmd_beacon) */
117         struct ieee80211_node   *ni;
118         struct mbuf             *m;
119         size_t                  size;
120         int                     code;
121         int                     ac;
122 };
123
124 struct wpi_vap {
125         struct ieee80211vap     wv_vap;
126
127         struct wpi_buf          wv_bcbuf;
128         struct ieee80211_beacon_offsets wv_boff;
129         struct mtx              wv_mtx;
130
131         uint32_t                wv_gtk;
132 #define WPI_VAP_KEY(kid)        (1 << kid)
133
134         int                     (*wv_newstate)(struct ieee80211vap *,
135                                     enum ieee80211_state, int);
136         void                    (*wv_recv_mgmt)(struct ieee80211_node *,
137                                     struct mbuf *, int,
138                                     const struct ieee80211_rx_stats *,
139                                     int, int);
140 };
141 #define WPI_VAP(vap)    ((struct wpi_vap *)(vap))
142
143 #define WPI_VAP_LOCK_INIT(_wvp) \
144         mtx_init(&(_wvp)->wv_mtx, "lock for wv_bcbuf/wv_boff structures", \
145             NULL, MTX_DEF)
146 #define WPI_VAP_LOCK(_wvp)              mtx_lock(&(_wvp)->wv_mtx)
147 #define WPI_VAP_UNLOCK(_wvp)            mtx_unlock(&(_wvp)->wv_mtx)
148 #define WPI_VAP_LOCK_ASSERT(_wvp)       mtx_assert(&(_wvp)->wv_mtx, MA_OWNED)
149 #define WPI_VAP_LOCK_DESTROY(_wvp)      mtx_destroy(&(_wvp)->wv_mtx)
150
151 struct wpi_fw_part {
152         const uint8_t   *text;
153         uint32_t        textsz;
154         const uint8_t   *data;
155         uint32_t        datasz;
156 };
157
158 struct wpi_fw_info {
159         const uint8_t           *data;
160         size_t                  size;
161         struct wpi_fw_part      init;
162         struct wpi_fw_part      main;
163         struct wpi_fw_part      boot;
164 };
165
166 struct wpi_softc {
167         device_t                sc_dev;
168         int                     sc_debug;
169
170         int                     sc_flags;
171 #define WPI_PS_PATH             (1 << 0)
172         int                     sc_running;
173
174         struct mtx              sc_mtx;
175         struct ieee80211com     sc_ic;
176
177         struct mtx              tx_mtx;
178
179         /* Shared area. */
180         struct wpi_dma_info     shared_dma;
181         struct wpi_shared       *shared;
182
183         struct wpi_tx_ring      txq[WPI_NTXQUEUES];
184         struct mtx              txq_mtx;
185         struct mtx              txq_state_mtx;
186
187         struct wpi_rx_ring      rxq;
188         uint64_t                rx_tstamp;
189
190         /* TX Thermal Callibration. */
191         struct callout          calib_to;
192         int                     calib_cnt;
193
194         struct callout          scan_timeout;
195         struct callout          tx_timeout;
196
197         /* Watch dog timer. */
198         struct callout          watchdog_rfkill;
199
200         /* Firmware image. */
201         struct wpi_fw_info      fw;
202         uint32_t                errptr;
203
204         struct resource         *irq;
205         struct resource         *mem;
206         bus_space_tag_t         sc_st;
207         bus_space_handle_t      sc_sh;
208         void                    *sc_ih;
209         bus_size_t              sc_sz;
210         int                     sc_cap_off;     /* PCIe Capabilities. */
211
212         struct wpi_rxon         rxon;
213         struct mtx              rxon_mtx;
214
215         int                     temp;
216         uint32_t                qfullmsk;
217
218         uint32_t                nodesmsk;
219         struct mtx              nt_mtx;
220
221         void                    (*sc_node_free)(struct ieee80211_node *);
222         void                    (*sc_update_rx_ring)(struct wpi_softc *);
223         void                    (*sc_update_tx_ring)(struct wpi_softc *,
224                                     struct wpi_tx_ring *);
225
226         struct wpi_rx_radiotap_header   sc_rxtap;
227         struct wpi_tx_radiotap_header   sc_txtap;
228
229         /* Firmware image. */
230         const struct firmware   *fw_fp;
231
232         /* Firmware DMA transfer. */
233         struct wpi_dma_info     fw_dma;
234
235         /* Tasks used by the driver. */
236         struct task             sc_reinittask;
237         struct task             sc_radiooff_task;
238         struct task             sc_radioon_task;
239         struct task             sc_start_task;
240
241         /* Taskqueue */
242         struct taskqueue        *sc_tq;
243
244         /* Eeprom info. */
245         uint8_t                 cap;
246         uint16_t                rev;
247         uint8_t                 type;
248         struct wpi_eeprom_chan
249             eeprom_channels[WPI_CHAN_BANDS_COUNT][WPI_MAX_CHAN_PER_BAND];
250         struct wpi_power_group  groups[WPI_POWER_GROUPS_COUNT];
251         int8_t                  maxpwr[IEEE80211_CHAN_MAX];
252         char                    domain[4];      /* Regulatory domain. */
253 };
254
255 /*
256  * Locking order:
257  * 1. WPI_LOCK;
258  * 2. WPI_RXON_LOCK;
259  * 3. WPI_TX_LOCK;
260  * 4. WPI_NT_LOCK / WPI_VAP_LOCK;
261  * 5. WPI_TXQ_LOCK;
262  * 6. WPI_TXQ_STATE_LOCK;
263  */
264
265 #define WPI_LOCK_INIT(_sc) \
266         mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
267             MTX_NETWORK_LOCK, MTX_DEF)
268 #define WPI_LOCK(_sc)           mtx_lock(&(_sc)->sc_mtx)
269 #define WPI_UNLOCK(_sc)         mtx_unlock(&(_sc)->sc_mtx)
270 #define WPI_LOCK_ASSERT(_sc)    mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
271 #define WPI_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->sc_mtx)
272
273 #define WPI_RXON_LOCK_INIT(_sc) \
274         mtx_init(&(_sc)->rxon_mtx, "lock for wpi_rxon structure", NULL, MTX_DEF)
275 #define WPI_RXON_LOCK(_sc)              mtx_lock(&(_sc)->rxon_mtx)
276 #define WPI_RXON_UNLOCK(_sc)            mtx_unlock(&(_sc)->rxon_mtx)
277 #define WPI_RXON_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->rxon_mtx, MA_OWNED)
278 #define WPI_RXON_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->rxon_mtx)
279
280 #define WPI_TX_LOCK_INIT(_sc) \
281         mtx_init(&(_sc)->tx_mtx, "tx path lock", NULL, MTX_DEF)
282 #define WPI_TX_LOCK(_sc)                mtx_lock(&(_sc)->tx_mtx)
283 #define WPI_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->tx_mtx)
284 #define WPI_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->tx_mtx)
285
286 #define WPI_NT_LOCK_INIT(_sc) \
287         mtx_init(&(_sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
288 #define WPI_NT_LOCK(_sc)                mtx_lock(&(_sc)->nt_mtx)
289 #define WPI_NT_UNLOCK(_sc)              mtx_unlock(&(_sc)->nt_mtx)
290 #define WPI_NT_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->nt_mtx)
291
292 #define WPI_TXQ_LOCK_INIT(_sc) \
293         mtx_init(&(_sc)->txq_mtx, "txq/cmdq lock", NULL, MTX_DEF)
294 #define WPI_TXQ_LOCK(_sc)               mtx_lock(&(_sc)->txq_mtx)
295 #define WPI_TXQ_UNLOCK(_sc)             mtx_unlock(&(_sc)->txq_mtx)
296 #define WPI_TXQ_LOCK_DESTROY(_sc)       mtx_destroy(&(_sc)->txq_mtx)
297
298 #define WPI_TXQ_STATE_LOCK_INIT(_sc) \
299         mtx_init(&(_sc)->txq_state_mtx, "txq state lock", NULL, MTX_DEF)
300 #define WPI_TXQ_STATE_LOCK(_sc)         mtx_lock(&(_sc)->txq_state_mtx)
301 #define WPI_TXQ_STATE_UNLOCK(_sc)       mtx_unlock(&(_sc)->txq_state_mtx)
302 #define WPI_TXQ_STATE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->txq_state_mtx)