iwmc3200wifi: simplify calibration map
[safe/jmp/linux-2.6] / drivers / net / wireless / iwmc3200wifi / iwm.h
1 /*
2  * Intel Wireless Multicomm 3200 WiFi driver
3  *
4  * Copyright (C) 2009 Intel Corporation. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *   * Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in
14  *     the documentation and/or other materials provided with the
15  *     distribution.
16  *   * Neither the name of Intel Corporation nor the names of its
17  *     contributors may be used to endorse or promote products derived
18  *     from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  *
33  * Intel Corporation <ilw@linux.intel.com>
34  * Samuel Ortiz <samuel.ortiz@intel.com>
35  * Zhu Yi <yi.zhu@intel.com>
36  *
37  */
38
39 #ifndef __IWM_H__
40 #define __IWM_H__
41
42 #include <linux/netdevice.h>
43 #include <linux/wireless.h>
44 #include <net/cfg80211.h>
45
46 #include "debug.h"
47 #include "hal.h"
48 #include "umac.h"
49 #include "lmac.h"
50 #include "eeprom.h"
51
52 #define IWM_COPYRIGHT "Copyright(c) 2009 Intel Corporation"
53 #define IWM_AUTHOR "<ilw@linux.intel.com>"
54
55 #define CONFIG_IWM_B0_HW_SUPPORT        1
56
57 #define IWM_SRC_LMAC    UMAC_HDI_IN_SOURCE_FHRX
58 #define IWM_SRC_UDMA    UMAC_HDI_IN_SOURCE_UDMA
59 #define IWM_SRC_UMAC    UMAC_HDI_IN_SOURCE_FW
60 #define IWM_SRC_NUM     3
61
62 #define IWM_POWER_INDEX_MIN     0
63 #define IWM_POWER_INDEX_MAX     5
64 #define IWM_POWER_INDEX_DEFAULT 3
65
66 struct iwm_conf {
67         u32 sdio_ior_timeout;
68         unsigned long calib_map;
69         bool reset_on_fatal_err;
70         bool auto_connect;
71         bool wimax_not_present;
72         bool enable_qos;
73         u32 mode;
74
75         u32 power_index;
76         u32 frag_threshold;
77         u32 rts_threshold;
78         bool cts_to_self;
79
80         u32 assoc_timeout;
81         u32 roam_timeout;
82         u32 wireless_mode;
83         u32 coexist_mode;
84
85         u8 ibss_band;
86         u8 ibss_channel;
87
88         u8 mac_addr[ETH_ALEN];
89 #ifdef CONFIG_IWM_B0_HW_SUPPORT
90         bool hw_b0;
91 #endif
92 };
93
94 enum {
95         COEX_MODE_SA = 1,
96         COEX_MODE_XOR,
97         COEX_MODE_CM,
98         COEX_MODE_MAX,
99 };
100
101 struct iwm_if_ops;
102 struct iwm_wifi_cmd;
103
104 struct pool_entry {
105         int id;         /* group id */
106         int sid;        /* super group id */
107         int min_pages;  /* min capacity in pages */
108         int max_pages;  /* max capacity in pages */
109         int alloc_pages;        /* allocated # of pages. incresed by driver */
110         int total_freed_pages;  /* total freed # of pages. incresed by UMAC */
111 };
112
113 struct spool_entry {
114         int id;
115         int max_pages;
116         int alloc_pages;
117 };
118
119 struct iwm_tx_credit {
120         spinlock_t lock;
121         int pool_nr;
122         unsigned long full_pools_map; /* bitmap for # of filled tx pools */
123         struct pool_entry pools[IWM_MACS_OUT_GROUPS];
124         struct spool_entry spools[IWM_MACS_OUT_SGROUPS];
125 };
126
127 struct iwm_notif {
128         struct list_head pending;
129         u32 cmd_id;
130         void *cmd;
131         u8 src;
132         void *buf;
133         unsigned long buf_size;
134 };
135
136 struct iwm_sta_info {
137         u8 addr[ETH_ALEN];
138         bool valid;
139         bool qos;
140         u8 color;
141 };
142
143 struct iwm_tx_info {
144         u8 sta;
145         u8 color;
146         u8 tid;
147 };
148
149 struct iwm_rx_info {
150         unsigned long rx_size;
151         unsigned long rx_buf_size;
152 };
153
154 #define IWM_NUM_KEYS 4
155
156 struct iwm_umac_key_hdr {
157         u8 mac[ETH_ALEN];
158         u8 key_idx;
159         u8 multicast; /* BCast encrypt & BCast decrypt of frames FROM mac */
160 } __attribute__ ((packed));
161
162 struct iwm_key {
163         struct iwm_umac_key_hdr hdr;
164         u32 cipher;
165         u8 key[WLAN_MAX_KEY_LEN];
166         u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
167         int key_len;
168         int seq_len;
169 };
170
171 #define IWM_RX_ID_HASH  0xff
172 #define IWM_RX_ID_GET_HASH(id) ((id) % IWM_RX_ID_HASH)
173
174 #define IWM_STA_TABLE_NUM       16
175 #define IWM_TX_LIST_SIZE        64
176 #define IWM_RX_LIST_SIZE        256
177
178 #define IWM_SCAN_ID_MAX 0xff
179
180 #define IWM_STATUS_READY                0
181 #define IWM_STATUS_SCANNING             1
182 #define IWM_STATUS_SCAN_ABORTING        2
183 #define IWM_STATUS_ASSOCIATING          3
184 #define IWM_STATUS_ASSOCIATED           4
185
186 struct iwm_tx_queue {
187         int id;
188         struct sk_buff_head queue;
189         struct workqueue_struct *wq;
190         struct work_struct worker;
191         u8 concat_buf[IWM_HAL_CONCATENATE_BUF_SIZE];
192         int concat_count;
193         u8 *concat_ptr;
194 };
195
196 /* Queues 0 ~ 3 for AC data, 5 for iPAN */
197 #define IWM_TX_QUEUES           5
198 #define IWM_TX_DATA_QUEUES      4
199 #define IWM_TX_CMD_QUEUE        4
200
201 struct iwm_bss_info {
202         struct list_head node;
203         struct cfg80211_bss *cfg_bss;
204         struct iwm_umac_notif_bss_info *bss;
205 };
206
207 typedef int (*iwm_handler)(struct iwm_priv *priv, u8 *buf,
208                            unsigned long buf_size, struct iwm_wifi_cmd *cmd);
209
210 #define IWM_WATCHDOG_PERIOD     (6 * HZ)
211
212 struct iwm_priv {
213         struct wireless_dev *wdev;
214         struct iwm_if_ops *bus_ops;
215
216         struct iwm_conf conf;
217
218         unsigned long status;
219
220         struct list_head pending_notif;
221         wait_queue_head_t notif_queue;
222
223         wait_queue_head_t nonwifi_queue;
224
225         unsigned long calib_done_map;
226         struct {
227                 u8 *buf;
228                 u32 size;
229         } calib_res[CALIBRATION_CMD_NUM];
230
231         struct iwm_umac_profile *umac_profile;
232         bool umac_profile_active;
233
234         u8 bssid[ETH_ALEN];
235         u8 channel;
236         u16 rate;
237         u32 txpower;
238
239         struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM];
240         struct list_head bss_list;
241
242         void (*nonwifi_rx_handlers[UMAC_HDI_IN_OPCODE_NONWIFI_MAX])
243         (struct iwm_priv *priv, u8 *buf, unsigned long buf_size);
244
245         const iwm_handler *umac_handlers;
246         const iwm_handler *lmac_handlers;
247         DECLARE_BITMAP(lmac_handler_map, LMAC_COMMAND_ID_NUM);
248         DECLARE_BITMAP(umac_handler_map, LMAC_COMMAND_ID_NUM);
249         DECLARE_BITMAP(udma_handler_map, LMAC_COMMAND_ID_NUM);
250
251         struct list_head wifi_pending_cmd;
252         struct list_head nonwifi_pending_cmd;
253         u16 wifi_seq_num;
254         u8 nonwifi_seq_num;
255         spinlock_t cmd_lock;
256
257         u32 core_enabled;
258
259         u8 scan_id;
260         struct cfg80211_scan_request *scan_request;
261
262         struct sk_buff_head rx_list;
263         struct list_head rx_tickets;
264         struct list_head rx_packets[IWM_RX_ID_HASH];
265         struct workqueue_struct *rx_wq;
266         struct work_struct rx_worker;
267
268         struct iwm_tx_credit tx_credit;
269         struct iwm_tx_queue txq[IWM_TX_QUEUES];
270
271         struct iwm_key keys[IWM_NUM_KEYS];
272         s8 default_key;
273
274         DECLARE_BITMAP(wifi_ntfy, WIFI_IF_NTFY_MAX);
275         wait_queue_head_t wifi_ntfy_queue;
276
277         wait_queue_head_t mlme_queue;
278
279         struct iw_statistics wstats;
280         struct delayed_work stats_request;
281
282         struct iwm_debugfs dbg;
283
284         u8 *eeprom;
285         struct timer_list watchdog;
286         struct work_struct reset_worker;
287         struct mutex mutex;
288
289         char private[0] __attribute__((__aligned__(NETDEV_ALIGN)));
290 };
291
292 static inline void *iwm_private(struct iwm_priv *iwm)
293 {
294         BUG_ON(!iwm);
295         return &iwm->private;
296 }
297
298 #define hw_to_iwm(h) (h->iwm)
299 #define iwm_to_dev(i) (wiphy_dev(i->wdev->wiphy))
300 #define iwm_to_wiphy(i) (i->wdev->wiphy)
301 #define wiphy_to_iwm(w) (struct iwm_priv *)(wiphy_priv(w))
302 #define iwm_to_wdev(i) (i->wdev)
303 #define wdev_to_iwm(w) (struct iwm_priv *)(wdev_priv(w))
304 #define iwm_to_ndev(i) (i->wdev->netdev)
305 #define ndev_to_iwm(n) (wdev_to_iwm(n->ieee80211_ptr))
306 #define skb_to_rx_info(s) ((struct iwm_rx_info *)(s->cb))
307 #define skb_to_tx_info(s) ((struct iwm_tx_info *)s->cb)
308
309 extern const struct iw_handler_def iwm_iw_handler_def;
310
311 void *iwm_if_alloc(int sizeof_bus, struct device *dev,
312                    struct iwm_if_ops *if_ops);
313 void iwm_if_free(struct iwm_priv *iwm);
314 int iwm_if_add(struct iwm_priv *iwm);
315 void iwm_if_remove(struct iwm_priv *iwm);
316 int iwm_mode_to_nl80211_iftype(int mode);
317 int iwm_priv_init(struct iwm_priv *iwm);
318 void iwm_priv_deinit(struct iwm_priv *iwm);
319 void iwm_reset(struct iwm_priv *iwm);
320 void iwm_tx_credit_init_pools(struct iwm_priv *iwm,
321                               struct iwm_umac_notif_alive *alive);
322 int iwm_tx_credit_alloc(struct iwm_priv *iwm, int id, int nb);
323 int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
324                    u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size);
325 int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout);
326 void iwm_init_default_profile(struct iwm_priv *iwm,
327                               struct iwm_umac_profile *profile);
328 void iwm_link_on(struct iwm_priv *iwm);
329 void iwm_link_off(struct iwm_priv *iwm);
330 int iwm_up(struct iwm_priv *iwm);
331 int iwm_down(struct iwm_priv *iwm);
332
333 /* TX API */
334 void iwm_tx_credit_inc(struct iwm_priv *iwm, int id, int total_freed_pages);
335 void iwm_tx_worker(struct work_struct *work);
336 int iwm_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
337
338 /* RX API */
339 void iwm_rx_setup_handlers(struct iwm_priv *iwm);
340 int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size);
341 int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
342                        struct iwm_wifi_cmd *cmd);
343 void iwm_rx_free(struct iwm_priv *iwm);
344
345 #endif