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