Merge branch 'devel' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa...
[pandora-kernel.git] / 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 IWM_SRC_LMAC    UMAC_HDI_IN_SOURCE_FHRX
56 #define IWM_SRC_UDMA    UMAC_HDI_IN_SOURCE_UDMA
57 #define IWM_SRC_UMAC    UMAC_HDI_IN_SOURCE_FW
58 #define IWM_SRC_NUM     3
59
60 #define IWM_POWER_INDEX_MIN     0
61 #define IWM_POWER_INDEX_MAX     5
62 #define IWM_POWER_INDEX_DEFAULT 3
63
64 struct iwm_conf {
65         u32 sdio_ior_timeout;
66         unsigned long calib_map;
67         unsigned long expected_calib_map;
68         bool reset_on_fatal_err;
69         bool auto_connect;
70         bool wimax_not_present;
71         bool enable_qos;
72         u32 mode;
73
74         u32 power_index;
75         u32 frag_threshold;
76         u32 rts_threshold;
77         bool cts_to_self;
78
79         u32 assoc_timeout;
80         u32 roam_timeout;
81         u32 wireless_mode;
82         u32 coexist_mode;
83
84         u8 ibss_band;
85         u8 ibss_channel;
86
87         u8 mac_addr[ETH_ALEN];
88 };
89
90 enum {
91         COEX_MODE_SA = 1,
92         COEX_MODE_XOR,
93         COEX_MODE_CM,
94         COEX_MODE_MAX,
95 };
96
97 struct iwm_if_ops;
98 struct iwm_wifi_cmd;
99
100 struct pool_entry {
101         int id;         /* group id */
102         int sid;        /* super group id */
103         int min_pages;  /* min capacity in pages */
104         int max_pages;  /* max capacity in pages */
105         int alloc_pages;        /* allocated # of pages. incresed by driver */
106         int total_freed_pages;  /* total freed # of pages. incresed by UMAC */
107 };
108
109 struct spool_entry {
110         int id;
111         int max_pages;
112         int alloc_pages;
113 };
114
115 struct iwm_tx_credit {
116         spinlock_t lock;
117         int pool_nr;
118         unsigned long full_pools_map; /* bitmap for # of filled tx pools */
119         struct pool_entry pools[IWM_MACS_OUT_GROUPS];
120         struct spool_entry spools[IWM_MACS_OUT_SGROUPS];
121 };
122
123 struct iwm_notif {
124         struct list_head pending;
125         u32 cmd_id;
126         void *cmd;
127         u8 src;
128         void *buf;
129         unsigned long buf_size;
130 };
131
132 struct iwm_sta_info {
133         u8 addr[ETH_ALEN];
134         bool valid;
135         bool qos;
136         u8 color;
137 };
138
139 struct iwm_tx_info {
140         u8 sta;
141         u8 color;
142         u8 tid;
143 };
144
145 struct iwm_rx_info {
146         unsigned long rx_size;
147         unsigned long rx_buf_size;
148 };
149
150 #define IWM_NUM_KEYS 4
151
152 struct iwm_umac_key_hdr {
153         u8 mac[ETH_ALEN];
154         u8 key_idx;
155         u8 multicast; /* BCast encrypt & BCast decrypt of frames FROM mac */
156 } __attribute__ ((packed));
157
158 struct iwm_key {
159         struct iwm_umac_key_hdr hdr;
160         u32 cipher;
161         u8 key[WLAN_MAX_KEY_LEN];
162         u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
163         int key_len;
164         int seq_len;
165 };
166
167 #define IWM_RX_ID_HASH  0xff
168 #define IWM_RX_ID_GET_HASH(id) ((id) % IWM_RX_ID_HASH)
169
170 #define IWM_STA_TABLE_NUM       16
171 #define IWM_TX_LIST_SIZE        64
172 #define IWM_RX_LIST_SIZE        256
173
174 #define IWM_SCAN_ID_MAX 0xff
175
176 #define IWM_STATUS_READY                0
177 #define IWM_STATUS_SCANNING             1
178 #define IWM_STATUS_SCAN_ABORTING        2
179 #define IWM_STATUS_SME_CONNECTING       3
180 #define IWM_STATUS_ASSOCIATED           4
181 #define IWM_STATUS_RESETTING            5
182
183 struct iwm_tx_queue {
184         int id;
185         struct sk_buff_head queue;
186         struct workqueue_struct *wq;
187         struct work_struct worker;
188         u8 concat_buf[IWM_HAL_CONCATENATE_BUF_SIZE];
189         int concat_count;
190         u8 *concat_ptr;
191 };
192
193 /* Queues 0 ~ 3 for AC data, 5 for iPAN */
194 #define IWM_TX_QUEUES           5
195 #define IWM_TX_DATA_QUEUES      4
196 #define IWM_TX_CMD_QUEUE        4
197
198 struct iwm_bss_info {
199         struct list_head node;
200         struct cfg80211_bss *cfg_bss;
201         struct iwm_umac_notif_bss_info *bss;
202 };
203
204 typedef int (*iwm_handler)(struct iwm_priv *priv, u8 *buf,
205                            unsigned long buf_size, struct iwm_wifi_cmd *cmd);
206
207 #define IWM_WATCHDOG_PERIOD     (6 * HZ)
208
209 struct iwm_priv {
210         struct wireless_dev *wdev;
211         struct iwm_if_ops *bus_ops;
212
213         struct iwm_conf conf;
214
215         unsigned long status;
216
217         struct list_head pending_notif;
218         wait_queue_head_t notif_queue;
219
220         wait_queue_head_t nonwifi_queue;
221
222         unsigned long calib_done_map;
223         struct {
224                 u8 *buf;
225                 u32 size;
226         } calib_res[CALIBRATION_CMD_NUM];
227
228         struct iwm_umac_profile *umac_profile;
229         bool umac_profile_active;
230
231         u8 bssid[ETH_ALEN];
232         u8 channel;
233         u16 rate;
234         u32 txpower;
235
236         struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM];
237         struct list_head bss_list;
238
239         void (*nonwifi_rx_handlers[UMAC_HDI_IN_OPCODE_NONWIFI_MAX])
240         (struct iwm_priv *priv, u8 *buf, unsigned long buf_size);
241
242         const iwm_handler *umac_handlers;
243         const iwm_handler *lmac_handlers;
244         DECLARE_BITMAP(lmac_handler_map, LMAC_COMMAND_ID_NUM);
245         DECLARE_BITMAP(umac_handler_map, LMAC_COMMAND_ID_NUM);
246         DECLARE_BITMAP(udma_handler_map, LMAC_COMMAND_ID_NUM);
247
248         struct list_head wifi_pending_cmd;
249         struct list_head nonwifi_pending_cmd;
250         u16 wifi_seq_num;
251         u8 nonwifi_seq_num;
252         spinlock_t cmd_lock;
253
254         u32 core_enabled;
255
256         u8 scan_id;
257         struct cfg80211_scan_request *scan_request;
258
259         struct sk_buff_head rx_list;
260         struct list_head rx_tickets;
261         struct list_head rx_packets[IWM_RX_ID_HASH];
262         struct workqueue_struct *rx_wq;
263         struct work_struct rx_worker;
264
265         struct iwm_tx_credit tx_credit;
266         struct iwm_tx_queue txq[IWM_TX_QUEUES];
267
268         struct iwm_key keys[IWM_NUM_KEYS];
269         s8 default_key;
270
271         DECLARE_BITMAP(wifi_ntfy, WIFI_IF_NTFY_MAX);
272         wait_queue_head_t wifi_ntfy_queue;
273
274         wait_queue_head_t mlme_queue;
275
276         struct iw_statistics wstats;
277         struct delayed_work stats_request;
278         struct delayed_work disconnect;
279
280         struct iwm_debugfs dbg;
281
282         u8 *eeprom;
283         struct timer_list watchdog;
284         struct work_struct reset_worker;
285         struct mutex mutex;
286
287         u8 *req_ie;
288         int req_ie_len;
289         u8 *resp_ie;
290         int resp_ie_len;
291
292         struct iwm_fw_error_hdr *last_fw_err;
293
294         char private[0] __attribute__((__aligned__(NETDEV_ALIGN)));
295 };
296
297 static inline void *iwm_private(struct iwm_priv *iwm)
298 {
299         BUG_ON(!iwm);
300         return &iwm->private;
301 }
302
303 #define hw_to_iwm(h) (h->iwm)
304 #define iwm_to_dev(i) (wiphy_dev(i->wdev->wiphy))
305 #define iwm_to_wiphy(i) (i->wdev->wiphy)
306 #define wiphy_to_iwm(w) (struct iwm_priv *)(wiphy_priv(w))
307 #define iwm_to_wdev(i) (i->wdev)
308 #define wdev_to_iwm(w) (struct iwm_priv *)(wdev_priv(w))
309 #define iwm_to_ndev(i) (i->wdev->netdev)
310 #define ndev_to_iwm(n) (wdev_to_iwm(n->ieee80211_ptr))
311 #define skb_to_rx_info(s) ((struct iwm_rx_info *)(s->cb))
312 #define skb_to_tx_info(s) ((struct iwm_tx_info *)s->cb)
313
314 void *iwm_if_alloc(int sizeof_bus, struct device *dev,
315                    struct iwm_if_ops *if_ops);
316 void iwm_if_free(struct iwm_priv *iwm);
317 int iwm_if_add(struct iwm_priv *iwm);
318 void iwm_if_remove(struct iwm_priv *iwm);
319 int iwm_mode_to_nl80211_iftype(int mode);
320 int iwm_priv_init(struct iwm_priv *iwm);
321 void iwm_priv_deinit(struct iwm_priv *iwm);
322 void iwm_reset(struct iwm_priv *iwm);
323 void iwm_resetting(struct iwm_priv *iwm);
324 void iwm_tx_credit_init_pools(struct iwm_priv *iwm,
325                               struct iwm_umac_notif_alive *alive);
326 int iwm_tx_credit_alloc(struct iwm_priv *iwm, int id, int nb);
327 int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
328                    u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size);
329 int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout);
330 void iwm_init_default_profile(struct iwm_priv *iwm,
331                               struct iwm_umac_profile *profile);
332 void iwm_link_on(struct iwm_priv *iwm);
333 void iwm_link_off(struct iwm_priv *iwm);
334 int iwm_up(struct iwm_priv *iwm);
335 int iwm_down(struct iwm_priv *iwm);
336
337 /* TX API */
338 void iwm_tx_credit_inc(struct iwm_priv *iwm, int id, int total_freed_pages);
339 void iwm_tx_worker(struct work_struct *work);
340 int iwm_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
341
342 /* RX API */
343 void iwm_rx_setup_handlers(struct iwm_priv *iwm);
344 int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size);
345 int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
346                        struct iwm_wifi_cmd *cmd);
347 void iwm_rx_free(struct iwm_priv *iwm);
348
349 #endif