]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/dev/iwn/if_iwnvar.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / dev / iwn / if_iwnvar.h
1 /*      $FreeBSD$       */
2 /*      $OpenBSD: if_iwnvar.h,v 1.18 2010/04/30 16:06:46 damien Exp $   */
3
4 /*-
5  * Copyright (c) 2007, 2008
6  *      Damien Bergamini <damien.bergamini@free.fr>
7  * Copyright (c) 2008 Sam Leffler, Errno Consulting
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21
22 struct iwn_rx_radiotap_header {
23         struct ieee80211_radiotap_header wr_ihdr;
24         uint64_t        wr_tsft;
25         uint8_t         wr_flags;
26         uint8_t         wr_rate;
27         uint16_t        wr_chan_freq;
28         uint16_t        wr_chan_flags;
29         int8_t          wr_dbm_antsignal;
30         int8_t          wr_dbm_antnoise;
31 } __packed;
32
33 #define IWN_RX_RADIOTAP_PRESENT                                         \
34         ((1 << IEEE80211_RADIOTAP_TSFT) |                               \
35          (1 << IEEE80211_RADIOTAP_FLAGS) |                              \
36          (1 << IEEE80211_RADIOTAP_RATE) |                               \
37          (1 << IEEE80211_RADIOTAP_CHANNEL) |                            \
38          (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |                      \
39          (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
40
41 struct iwn_tx_radiotap_header {
42         struct ieee80211_radiotap_header wt_ihdr;
43         uint8_t         wt_flags;
44         uint8_t         wt_rate;
45         uint16_t        wt_chan_freq;
46         uint16_t        wt_chan_flags;
47 } __packed;
48
49 #define IWN_TX_RADIOTAP_PRESENT                                         \
50         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
51          (1 << IEEE80211_RADIOTAP_RATE) |                               \
52          (1 << IEEE80211_RADIOTAP_CHANNEL))
53
54 struct iwn_dma_info {
55         bus_dma_tag_t           tag;
56         bus_dmamap_t            map;
57         bus_dma_segment_t       seg;
58         bus_addr_t              paddr;
59         caddr_t                 vaddr;
60         bus_size_t              size;
61 };
62
63 struct iwn_tx_data {
64         bus_dmamap_t            map;
65         bus_addr_t              cmd_paddr;
66         bus_addr_t              scratch_paddr;
67         struct mbuf             *m;
68         struct ieee80211_node   *ni;
69 };
70
71 struct iwn_tx_ring {
72         struct iwn_dma_info     desc_dma;
73         struct iwn_dma_info     cmd_dma;
74         struct iwn_tx_desc      *desc;
75         struct iwn_tx_cmd       *cmd;
76         struct iwn_tx_data      data[IWN_TX_RING_COUNT];
77         bus_dma_tag_t           data_dmat;
78         int                     qid;
79         int                     queued;
80         int                     cur;
81 };
82
83 struct iwn_softc;
84
85 struct iwn_rx_data {
86         struct mbuf     *m;
87         bus_dmamap_t    map;
88 };
89
90 struct iwn_rx_ring {
91         struct iwn_dma_info     desc_dma;
92         struct iwn_dma_info     stat_dma;
93         uint32_t                *desc;
94         struct iwn_rx_status    *stat;
95         struct iwn_rx_data      data[IWN_RX_RING_COUNT];
96         bus_dma_tag_t           data_dmat;
97         int                     cur;
98 };
99
100 struct iwn_node {
101         struct  ieee80211_node          ni;     /* must be the first */
102         uint16_t                        disable_tid;
103         uint8_t                         id;
104         uint8_t                         ridx[IEEE80211_RATE_MAXSIZE];
105 };
106
107 struct iwn_calib_state {
108         uint8_t         state;
109 #define IWN_CALIB_STATE_INIT    0
110 #define IWN_CALIB_STATE_ASSOC   1
111 #define IWN_CALIB_STATE_RUN     2
112
113         u_int           nbeacons;
114         uint32_t        noise[3];
115         uint32_t        rssi[3];
116         uint32_t        ofdm_x1;
117         uint32_t        ofdm_mrc_x1;
118         uint32_t        ofdm_x4;
119         uint32_t        ofdm_mrc_x4;
120         uint32_t        cck_x4;
121         uint32_t        cck_mrc_x4;
122         uint32_t        bad_plcp_ofdm;
123         uint32_t        fa_ofdm;
124         uint32_t        bad_plcp_cck;
125         uint32_t        fa_cck;
126         uint32_t        low_fa;
127         uint8_t         cck_state;
128 #define IWN_CCK_STATE_INIT      0
129 #define IWN_CCK_STATE_LOFA      1
130 #define IWN_CCK_STATE_HIFA      2
131
132         uint8_t         noise_samples[20];
133         u_int           cur_noise_sample;
134         uint8_t         noise_ref;
135         uint32_t        energy_samples[10];
136         u_int           cur_energy_sample;
137         uint32_t        energy_cck;
138 };
139
140 struct iwn_calib_info {
141         uint8_t         *buf;
142         u_int           len;
143 };
144
145 struct iwn_fw_part {
146         const uint8_t   *text;
147         uint32_t        textsz;
148         const uint8_t   *data;
149         uint32_t        datasz;
150 };
151
152 struct iwn_fw_info {
153         const uint8_t           *data;
154         size_t                  size;
155         struct iwn_fw_part      init;
156         struct iwn_fw_part      main;
157         struct iwn_fw_part      boot;
158 };
159
160 struct iwn_hal {
161         int             (*load_firmware)(struct iwn_softc *);
162         void            (*read_eeprom)(struct iwn_softc *);
163         int             (*post_alive)(struct iwn_softc *);
164         int             (*nic_config)(struct iwn_softc *);
165         void            (*update_sched)(struct iwn_softc *, int, int, uint8_t,
166                             uint16_t);
167         int             (*get_temperature)(struct iwn_softc *);
168         int             (*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *);
169         int             (*set_txpower)(struct iwn_softc *,
170                             struct ieee80211_channel *, int);
171         int             (*init_gains)(struct iwn_softc *);
172         int             (*set_gains)(struct iwn_softc *);
173         int             (*add_node)(struct iwn_softc *, struct iwn_node_info *,
174                             int);
175         void            (*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
176                             struct iwn_rx_data *);
177 #if 0   /* HT */
178         void            (*ampdu_tx_start)(struct iwn_softc *,
179                             struct ieee80211_node *, uint8_t, uint16_t);
180         void            (*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
181                             uint16_t);
182 #endif
183         int             ntxqs;
184         int             ndmachnls;
185         uint8_t         broadcast_id;
186         int             rxonsz;
187         int             schedsz;
188         uint32_t        fw_text_maxsz;
189         uint32_t        fw_data_maxsz;
190         uint32_t        fwsz;
191         bus_size_t      sched_txfact_addr;
192 };
193
194 struct iwn_vap {
195         struct ieee80211vap     iv_vap;
196         uint8_t                 iv_ridx;
197
198         int                     (*iv_newstate)(struct ieee80211vap *,
199                                     enum ieee80211_state, int);
200 };
201 #define IWN_VAP(_vap)   ((struct iwn_vap *)(_vap))
202
203 struct iwn_softc {
204         struct ifnet            *sc_ifp;
205         int                     sc_debug;
206
207         /* Locks */
208         struct mtx              sc_mtx;
209
210         /* Bus */
211         device_t                sc_dev;
212         int                     mem_rid;
213         int                     irq_rid;
214         struct resource         *mem;
215         struct resource         *irq;
216
217         u_int                   sc_flags;
218 #define IWN_FLAG_HAS_5GHZ       (1 << 0)
219 #define IWN_FLAG_HAS_OTPROM     (1 << 1)
220 #define IWN_FLAG_CALIB_DONE     (1 << 2)
221 #define IWN_FLAG_USE_ICT        (1 << 3)
222 #define IWN_FLAG_INTERNAL_PA    (1 << 4)
223
224         uint8_t                 hw_type;
225         const struct iwn_hal    *sc_hal;
226         const char              *fwname;
227         const struct iwn_sensitivity_limits
228                                 *limits;
229
230         /* TX scheduler rings. */
231         struct iwn_dma_info     sched_dma;
232         uint16_t                *sched;
233         uint32_t                sched_base;
234
235         /* "Keep Warm" page. */
236         struct iwn_dma_info     kw_dma;
237
238         /* Firmware image. */
239         const struct firmware   *fw_fp;
240
241         /* Firmware DMA transfer. */
242         struct iwn_dma_info     fw_dma;
243
244         /* ICT table. */
245         struct iwn_dma_info     ict_dma;
246         uint32_t                *ict;
247         int                     ict_cur;
248
249         /* TX/RX rings. */
250         struct iwn_tx_ring      txq[IWN5000_NTXQUEUES];
251         struct iwn_rx_ring      rxq;
252
253         bus_space_tag_t         sc_st;
254         bus_space_handle_t      sc_sh;
255         void                    *sc_ih;
256         bus_size_t              sc_sz;
257         int                     sc_cap_off;     /* PCIe Capabilities. */
258
259         /* Tasks used by the driver */
260         struct task             sc_reinit_task;
261         struct task             sc_radioon_task;
262         struct task             sc_radiooff_task;
263
264         int                     calib_cnt;
265         struct iwn_calib_state  calib;
266         u_int                   calib_init;
267         u_int                   calib_runtime;
268 #define IWN_CALIB_XTAL                  (1 << IWN_CALIB_IDX_XTAL)
269 #define IWN_CALIB_DC                    (1 << IWN_CALIB_IDX_DC)
270 #define IWN_CALIB_LO                    (1 << IWN_CALIB_IDX_LO)
271 #define IWN_CALIB_TX_IQ                 (1 << IWN_CALIB_IDX_TX_IQ)
272 #define IWN_CALIB_TX_IQ_PERIODIC        (1 << IWN_CALIB_IDX_TX_IQ_PERIODIC)
273 #define IWN_CALIB_BASE_BAND             (1 << IWN_CALIB_IDX_BASE_BAND)
274 #define IWN_CALIB_NUM                   6
275         struct iwn_calib_info   calib_results[IWN_CALIB_NUM];
276 #define IWN_CALIB_IDX_XTAL              0
277 #define IWN_CALIB_IDX_DC                1
278 #define IWN_CALIB_IDX_LO                2
279 #define IWN_CALIB_IDX_TX_IQ             3
280 #define IWN_CALIB_IDX_TX_IQ_PERIODIC    4
281 #define IWN_CALIB_IDX_BASE_BAND         5
282
283         struct iwn_fw_info      fw;
284         uint32_t                errptr;
285
286         struct iwn_rx_stat      last_rx_stat;
287         int                     last_rx_valid;
288         struct iwn_ucode_info   ucode_info;
289         struct iwn_rxon         rxon;
290         uint32_t                rawtemp;
291         int                     temp;
292         int                     noise;
293         uint32_t                qfullmsk;
294
295         uint32_t                prom_base;
296         struct iwn4965_eeprom_band
297                                 bands[IWN_NBANDS];
298         struct iwn_eeprom_chan  eeprom_channels[IWN_NBANDS][IWN_MAX_CHAN_PER_BAND];
299         uint16_t                rfcfg;
300         uint8_t                 calib_ver;
301         char                    eeprom_domain[4];
302         int16_t                 eeprom_voltage;
303         int8_t                  maxpwr2GHz;
304         int8_t                  maxpwr5GHz;
305         int8_t                  maxpwr[IEEE80211_CHAN_MAX];
306         int8_t                  enh_maxpwr[35];
307
308         int32_t                 temp_off;
309         uint32_t                int_mask;
310         uint8_t                 ntxchains;
311         uint8_t                 nrxchains;
312         uint8_t                 txchainmask;
313         uint8_t                 rxchainmask;
314         uint8_t                 chainmask;
315
316         struct callout          sc_timer_to;
317         int                     sc_tx_timer;
318
319         struct iwn_rx_radiotap_header sc_rxtap;
320         struct iwn_tx_radiotap_header sc_txtap;
321 };
322
323 #define IWN_LOCK_INIT(_sc) \
324         mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
325             MTX_NETWORK_LOCK, MTX_DEF)
326 #define IWN_LOCK(_sc)                   mtx_lock(&(_sc)->sc_mtx)
327 #define IWN_LOCK_ASSERT(_sc)            mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
328 #define IWN_UNLOCK(_sc)                 mtx_unlock(&(_sc)->sc_mtx)
329 #define IWN_LOCK_DESTROY(_sc)           mtx_destroy(&(_sc)->sc_mtx)