]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/iwn/if_iwnvar.h
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[FreeBSD/FreeBSD.git] / sys / dev / iwn / if_iwnvar.h
1 /*      $FreeBSD$       */
2 /*-
3  * Copyright (c) 2007
4  *      Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2008 Sam Leffler, Errno Consulting
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
20 struct iwn_rx_radiotap_header {
21         struct ieee80211_radiotap_header wr_ihdr;
22         uint64_t        wr_tsft;
23         uint8_t         wr_flags;
24         uint8_t         wr_rate;
25         uint16_t        wr_chan_freq;
26         uint16_t        wr_chan_flags;
27         int8_t          wr_dbm_antsignal;
28         int8_t          wr_dbm_antnoise;
29 } __packed;
30
31 #define IWN_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
39 struct iwn_tx_radiotap_header {
40         struct ieee80211_radiotap_header wt_ihdr;
41         uint8_t         wt_flags;
42         uint8_t         wt_rate;
43         uint16_t        wt_chan_freq;
44         uint16_t        wt_chan_flags;
45 } __packed;
46
47 #define IWN_TX_RADIOTAP_PRESENT                                         \
48         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
49          (1 << IEEE80211_RADIOTAP_RATE) |                               \
50          (1 << IEEE80211_RADIOTAP_CHANNEL))
51
52 struct iwn_dma_info {
53         bus_dma_tag_t           tag;
54         bus_dmamap_t            map;
55         bus_dma_segment_t       seg;
56         bus_addr_t              paddr;
57         caddr_t                 vaddr;
58         bus_size_t              size;
59 };
60
61 struct iwn_tx_data {
62         bus_dmamap_t            map;
63         struct mbuf             *m;
64         struct ieee80211_node   *ni;
65 };
66
67 struct iwn_tx_ring {
68         struct iwn_dma_info     desc_dma;
69         struct iwn_dma_info     cmd_dma;
70         struct iwn_tx_desc      *desc;
71         struct iwn_tx_cmd       *cmd;
72         struct iwn_tx_data      data[IWN_TX_RING_COUNT];
73         bus_dma_tag_t           data_dmat;
74         int                     qid;
75         int                     queued;
76         int                     cur;
77 };
78
79 struct iwn_rx_data {
80         bus_dmamap_t            map;
81         struct mbuf             *m;
82 };
83
84 struct iwn_rx_ring {
85         struct iwn_dma_info     desc_dma;
86         uint32_t                *desc;
87         struct iwn_rx_data      data[IWN_RX_RING_COUNT];
88         bus_dma_tag_t           data_dmat;
89         int                     cur;
90 };
91
92 struct iwn_node {
93         struct  ieee80211_node          ni;     /* must be the first */
94         struct  ieee80211_amrr_node     amn;
95 };
96 #define IWN_NODE(_ni)   ((struct iwn_node *)(_ni))
97
98 struct iwn_calib_state {
99         uint8_t         state;
100 #define IWN_CALIB_STATE_INIT    0
101 #define IWN_CALIB_STATE_ASSOC   1
102 #define IWN_CALIB_STATE_RUN     2
103         u_int           nbeacons;
104         uint32_t        noise[3];
105         uint32_t        rssi[3];
106         uint32_t        corr_ofdm_x1;
107         uint32_t        corr_ofdm_mrc_x1;
108         uint32_t        corr_ofdm_x4;
109         uint32_t        corr_ofdm_mrc_x4;
110         uint32_t        corr_cck_x4;
111         uint32_t        corr_cck_mrc_x4;
112         uint32_t        bad_plcp_ofdm;
113         uint32_t        fa_ofdm;
114         uint32_t        bad_plcp_cck;
115         uint32_t        fa_cck;
116         uint32_t        low_fa;
117         uint8_t         cck_state;
118 #define IWN_CCK_STATE_INIT      0
119 #define IWN_CCK_STATE_LOFA      1
120 #define IWN_CCK_STATE_HIFA      2
121         uint8_t         noise_samples[20];
122         u_int           cur_noise_sample;
123         uint8_t         noise_ref;
124         uint32_t        energy_samples[10];
125         u_int           cur_energy_sample;
126         uint32_t        energy_cck;
127 };
128
129 struct iwn_vap {
130         struct ieee80211vap     iv_vap;
131         struct ieee80211_amrr   iv_amrr;
132         struct callout          iv_amrr_to;
133
134         int                     (*iv_newstate)(struct ieee80211vap *,
135                                     enum ieee80211_state, int);
136 };
137 #define IWN_VAP(_vap)   ((struct iwn_vap *)(_vap))
138
139 struct iwn_softc {
140         struct ifnet            *sc_ifp;
141         int                     sc_debug;
142         struct callout          sc_timer_to;    /* calib+watchdog timer */
143         int                     sc_tx_timer;    /* tx watchdog timer/counter */
144         const struct ieee80211_channel *sc_curchan;
145
146         struct iwn_rx_radiotap_header sc_rxtap;
147         int                     sc_rxtap_len;
148         struct iwn_tx_radiotap_header sc_txtap;
149         int                     sc_txtap_len;
150
151         /* locks */
152         struct mtx              sc_mtx;
153
154         /* bus */
155         device_t                sc_dev;
156         int                     mem_rid;
157         int                     irq_rid;
158         struct resource         *mem;
159         struct resource         *irq;
160
161         /* shared area */
162         struct iwn_dma_info     shared_dma;
163         struct iwn_shared       *shared;
164
165         /* "keep warm" page */
166         struct iwn_dma_info     kw_dma;
167
168         /* firmware image */
169         const struct firmware   *fw_fp;
170
171         /* firmware DMA transfer */
172         struct iwn_dma_info     fw_dma;
173
174         /* rings */
175         struct iwn_tx_ring      txq[IWN_NTXQUEUES];
176         struct iwn_rx_ring      rxq;
177
178         bus_space_tag_t         sc_st;
179         bus_space_handle_t      sc_sh;
180         void                    *sc_ih;
181         bus_size_t              sc_sz;
182
183         /* command queue related variables */
184 #define IWN_SCAN_START          (1<<0)
185 #define IWN_SCAN_CURCHAN        (1<<1)
186 #define IWN_SCAN_STOP           (1<<2)
187 #define IWN_SET_CHAN            (1<<3)
188 #define IWN_AUTH                (1<<4)
189 #define IWN_SCAN_NEXT           (1<<5)
190 #define IWN_RUN                 (1<<6)
191 #define IWN_RADIO_ENABLE        (1<<7)
192 #define IWN_RADIO_DISABLE       (1<<8)
193 #define IWN_REINIT              (1<<9)
194 #define IWN_CMD_MAXOPS          10
195         /* command queuing request type */
196 #define IWN_QUEUE_NORMAL        0
197 #define IWN_QUEUE_CLEAR         1
198         int                     sc_cmd[IWN_CMD_MAXOPS];
199         int                     sc_cmd_arg[IWN_CMD_MAXOPS];
200         int                     sc_cmd_cur;    /* current queued scan task */
201         int                     sc_cmd_next;   /* last queued scan task */
202         struct mtx              sc_cmdlock;
203
204         /* Task queues used to control the driver */
205         struct taskqueue         *sc_tq; /* Main command task queue */
206
207         /* Tasks used by the driver */
208         struct task             sc_ops_task;    /* deferred ops */
209         struct task             sc_bmiss_task;  /* beacon miss */
210
211         /* Thermal calibration */
212         int                     calib_cnt;
213         struct iwn_calib_state  calib;
214
215         struct iwn_rx_stat      last_rx_stat;
216         int                     last_rx_valid;
217         struct iwn_ucode_info   ucode_info;
218         struct iwn_config       config;
219         uint32_t                rawtemp;
220         int                     temp;
221         int                     noise;
222         uint8_t                 antmsk;
223
224         struct iwn_eeprom_band  bands[IWN_NBANDS];
225         int16_t                 eeprom_voltage;
226         int8_t                  maxpwr2GHz;
227         int8_t                  maxpwr5GHz;
228 };
229
230 #define IWN_LOCK_INIT(_sc) \
231         mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
232              MTX_NETWORK_LOCK, MTX_DEF)
233 #define IWN_LOCK(_sc)                   mtx_lock(&(_sc)->sc_mtx)
234 #define IWN_LOCK_ASSERT(_sc)            mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
235 #define IWN_UNLOCK(_sc)                 mtx_unlock(&(_sc)->sc_mtx)
236 #define IWN_LOCK_DESTROY(_sc)           mtx_destroy(&(_sc)->sc_mtx)
237 #define IWN_CMD_LOCK_INIT(_sc) \
238         mtx_init(&(_sc)->sc_cmdlock, device_get_nameunit((_sc)->sc_dev), \
239              NULL, MTX_DEF);
240 #define IWN_CMD_LOCK_DESTROY(_sc)       mtx_destroy(&(_sc)->sc_cmdlock)
241 #define IWN_CMD_LOCK(_sc)               mtx_lock(&(_sc)->sc_cmdlock)
242 #define IWN_CMD_UNLOCK(_sc)             mtx_unlock(&(_sc)->sc_cmdlock)