]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/iwi/if_iwivar.h
MFC r344934, r345014: Add separate aggregation limit for non-rotating media.
[FreeBSD/FreeBSD.git] / sys / dev / iwi / if_iwivar.h
1 /*      $FreeBSD$       */
2
3 /*-
4  * Copyright (c) 2004, 2005
5  *      Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 struct iwi_rx_radiotap_header {
31         struct ieee80211_radiotap_header wr_ihdr;
32         uint8_t         wr_flags;
33         uint8_t         wr_rate;
34         uint16_t        wr_chan_freq;
35         uint16_t        wr_chan_flags;
36         int8_t          wr_antsignal;
37         int8_t          wr_antnoise;
38         uint8_t         wr_antenna;
39 } __packed __aligned(8);
40
41 #define IWI_RX_RADIOTAP_PRESENT                                         \
42         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
43          (1 << IEEE80211_RADIOTAP_RATE) |                               \
44          (1 << IEEE80211_RADIOTAP_CHANNEL) |                            \
45          (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |                      \
46          (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |                       \
47          (1 << IEEE80211_RADIOTAP_ANTENNA))
48
49 struct iwi_tx_radiotap_header {
50         struct ieee80211_radiotap_header wt_ihdr;
51         uint8_t         wt_flags;
52         uint8_t         wt_pad;
53         uint16_t        wt_chan_freq;
54         uint16_t        wt_chan_flags;
55 } __packed;
56
57 #define IWI_TX_RADIOTAP_PRESENT                                         \
58         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
59          (1 << IEEE80211_RADIOTAP_CHANNEL))
60
61 struct iwi_cmd_ring {
62         bus_dma_tag_t           desc_dmat;
63         bus_dmamap_t            desc_map;
64         bus_addr_t              physaddr;
65         struct iwi_cmd_desc     *desc;
66         int                     count;
67         int                     queued;
68         int                     cur;
69         int                     next;
70 };
71
72 struct iwi_tx_data {
73         bus_dmamap_t            map;
74         struct mbuf             *m;
75         struct ieee80211_node   *ni;
76 };
77
78 struct iwi_tx_ring {
79         bus_dma_tag_t           desc_dmat;
80         bus_dma_tag_t           data_dmat;
81         bus_dmamap_t            desc_map;
82         bus_addr_t              physaddr;
83         bus_addr_t              csr_ridx;
84         bus_addr_t              csr_widx;
85         struct iwi_tx_desc      *desc;
86         struct iwi_tx_data      *data;
87         int                     count;
88         int                     queued;
89         int                     cur;
90         int                     next;
91 };
92
93 struct iwi_rx_data {
94         bus_dmamap_t    map;
95         bus_addr_t      physaddr;
96         uint32_t        reg;
97         struct mbuf     *m;
98 };
99
100 struct iwi_rx_ring {
101         bus_dma_tag_t           data_dmat;
102         struct iwi_rx_data      *data;
103         int                     count;
104         int                     cur;
105 };
106
107 struct iwi_node {
108         struct ieee80211_node   in_node;
109         int                     in_station;
110 #define IWI_MAX_IBSSNODE        32
111 };
112
113 struct iwi_fw {
114         const struct firmware   *fp;            /* image handle */
115         const char              *data;          /* firmware image data */
116         size_t                  size;           /* firmware image size */
117         const char              *name;          /* associated image name */
118 };
119
120 struct iwi_vap {
121         struct ieee80211vap     iwi_vap;
122
123         int                     (*iwi_newstate)(struct ieee80211vap *,
124                                     enum ieee80211_state, int);
125 };
126 #define IWI_VAP(vap)    ((struct iwi_vap *)(vap))
127
128 struct iwi_softc {
129         struct mtx              sc_mtx;
130         struct ieee80211com     sc_ic;
131         struct mbufq            sc_snd;
132         device_t                sc_dev;
133
134         void                    (*sc_node_free)(struct ieee80211_node *);
135
136         uint8_t                 sc_mcast[IEEE80211_ADDR_LEN];
137         struct unrhdr           *sc_unr;
138
139         uint32_t                flags;
140 #define IWI_FLAG_FW_INITED      (1 << 0)
141 #define IWI_FLAG_BUSY           (1 << 3)        /* busy sending a command */
142 #define IWI_FLAG_ASSOCIATED     (1 << 4)        /* currently associated  */
143 #define IWI_FLAG_CHANNEL_SCAN   (1 << 5)
144         uint32_t                fw_state;
145 #define IWI_FW_IDLE             0
146 #define IWI_FW_LOADING          1
147 #define IWI_FW_ASSOCIATING      2
148 #define IWI_FW_DISASSOCIATING   3
149 #define IWI_FW_SCANNING         4
150         struct iwi_cmd_ring     cmdq;
151         struct iwi_tx_ring      txq[WME_NUM_AC];
152         struct iwi_rx_ring      rxq;
153
154         struct resource         *irq;
155         struct resource         *mem;
156         bus_space_tag_t         sc_st;
157         bus_space_handle_t      sc_sh;
158         void                    *sc_ih;
159
160         /*
161          * The card needs external firmware images to work, which is made of a
162          * bootloader, microcode and firmware proper. In version 3.00 and
163          * above, all pieces are contained in a single image, preceded by a
164          * struct iwi_firmware_hdr indicating the size of the 3 pieces.
165          * Old firmware < 3.0 has separate boot and ucode, so we need to
166          * load all of them explicitly.
167          * To avoid issues related to fragmentation, we keep the block of
168          * dma-ble memory around until detach time, and reallocate it when
169          * it becomes too small. fw_dma_size is the size currently allocated.
170          */
171         int                     fw_dma_size;
172         uint32_t                fw_flags;       /* allocation status */
173 #define IWI_FW_HAVE_DMAT        0x01
174 #define IWI_FW_HAVE_MAP         0x02
175 #define IWI_FW_HAVE_PHY         0x04
176         bus_dma_tag_t           fw_dmat;
177         bus_dmamap_t            fw_map;
178         bus_addr_t              fw_physaddr;
179         void                    *fw_virtaddr;
180         enum ieee80211_opmode   fw_mode;        /* mode of current firmware */
181         struct iwi_fw           fw_boot;        /* boot firmware */
182         struct iwi_fw           fw_uc;          /* microcode */
183         struct iwi_fw           fw_fw;          /* operating mode support */
184
185         int                     curchan;        /* current h/w channel # */
186         int                     antenna;
187         int                     bluetooth;
188         struct iwi_associate    assoc;
189         struct iwi_wme_params   wme[3];
190         u_int                   sc_scangen;
191
192         struct task             sc_radiontask;  /* radio on processing */
193         struct task             sc_radiofftask; /* radio off processing */
194         struct task             sc_restarttask; /* restart adapter processing */
195         struct task             sc_disassoctask;
196         struct task             sc_monitortask;
197
198         unsigned int            sc_running : 1, /* initialized */
199                                 sc_softled : 1, /* enable LED gpio status */
200                                 sc_ledstate: 1, /* LED on/off state */
201                                 sc_blinking: 1; /* LED blink operation active */
202         u_int                   sc_nictype;     /* NIC type from EEPROM */
203         u_int                   sc_ledpin;      /* mask for activity LED */
204         u_int                   sc_ledidle;     /* idle polling interval */
205         int                     sc_ledevent;    /* time of last LED event */
206         u_int8_t                sc_rxrate;      /* current rx rate for LED */
207         u_int8_t                sc_rxrix;
208         u_int8_t                sc_txrate;      /* current tx rate for LED */
209         u_int8_t                sc_txrix;
210         u_int16_t               sc_ledoff;      /* off time for current blink */
211         struct callout          sc_ledtimer;    /* led off timer */
212         struct callout          sc_wdtimer;     /* watchdog timer */
213         struct callout          sc_rftimer;     /* rfkill timer */
214
215         int                     sc_tx_timer;
216         int                     sc_state_timer; /* firmware state timer */
217         int                     sc_busy_timer;  /* firmware cmd timer */
218
219         struct iwi_rx_radiotap_header sc_rxtap;
220         struct iwi_tx_radiotap_header sc_txtap;
221
222         struct iwi_notif_link_quality sc_linkqual;
223         int                     sc_linkqual_valid;
224 };
225
226 #define IWI_STATE_BEGIN(_sc, _state)    do {                    \
227         KASSERT(_sc->fw_state == IWI_FW_IDLE,                   \
228             ("iwi firmware not idle, state %s", iwi_fw_states[_sc->fw_state]));\
229         _sc->fw_state = _state;                                 \
230         _sc->sc_state_timer = 5;                                \
231         DPRINTF(("enter %s state\n", iwi_fw_states[_state]));   \
232 } while (0)
233
234 #define IWI_STATE_END(_sc, _state)      do {                    \
235         if (_sc->fw_state == _state)                            \
236                 DPRINTF(("exit %s state\n", iwi_fw_states[_state])); \
237          else                                                   \
238                 DPRINTF(("expected %s state, got %s\n", \
239                     iwi_fw_states[_state], iwi_fw_states[_sc->fw_state])); \
240         _sc->fw_state = IWI_FW_IDLE;                            \
241         wakeup(_sc);                                            \
242         _sc->sc_state_timer = 0;                                \
243 } while (0)
244 /*
245  * NB.: This models the only instance of async locking in iwi_init_locked
246  *      and must be kept in sync.
247  */
248 #define IWI_LOCK_INIT(sc) \
249         mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \
250             MTX_NETWORK_LOCK, MTX_DEF)
251 #define IWI_LOCK_DESTROY(sc)    mtx_destroy(&(sc)->sc_mtx)
252 #define IWI_LOCK_DECL   int     __waslocked = 0
253 #define IWI_LOCK_ASSERT(sc)     mtx_assert(&(sc)->sc_mtx, MA_OWNED)
254 #define IWI_LOCK(sc)    do {                            \
255         if (!(__waslocked = mtx_owned(&(sc)->sc_mtx)))  \
256                 mtx_lock(&(sc)->sc_mtx);                \
257 } while (0)
258 #define IWI_UNLOCK(sc)  do {                    \
259         if (!__waslocked)                       \
260                 mtx_unlock(&(sc)->sc_mtx);      \
261 } while (0)