blob: 2aa17ca60ba87f43927ecaa4bc13026924295d21 [file] [log] [blame]
Solomon Peachya910e4a2013-05-24 20:04:38 -04001/*
2 * Common private data for ST-Ericsson CW1200 drivers
3 *
4 * Copyright (c) 2010, ST-Ericsson
5 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
6 *
7 * Based on the mac80211 Prism54 code, which is
8 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
9 *
10 * Based on the islsm (softmac prism54) driver, which is:
11 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#ifndef CW1200_H
19#define CW1200_H
20
21#include <linux/wait.h>
22#include <linux/version.h>
23#include <linux/mutex.h>
24#include <linux/workqueue.h>
25#include <net/mac80211.h>
26
27#include "queue.h"
28#include "wsm.h"
29#include "scan.h"
30#include "txrx.h"
31#include "pm.h"
32
33/* Forward declarations */
34struct sbus_ops;
35struct task_struct;
36struct cw1200_debug_priv;
37struct firmware;
38
39#ifdef CONFIG_CW1200_ETF
40extern int etf_mode;
41extern char *etf_firmware;
42#endif
43
44#define CW1200_MAX_CTRL_FRAME_LEN (0x1000)
45
46#define CW1200_MAX_STA_IN_AP_MODE (5)
47#define CW1200_LINK_ID_AFTER_DTIM (CW1200_MAX_STA_IN_AP_MODE + 1)
48#define CW1200_LINK_ID_UAPSD (CW1200_MAX_STA_IN_AP_MODE + 2)
49#define CW1200_LINK_ID_MAX (CW1200_MAX_STA_IN_AP_MODE + 3)
50#define CW1200_MAX_REQUEUE_ATTEMPTS (5)
51
52#define CW1200_MAX_TID (8)
53
54#define CW1200_BLOCK_ACK_CNT (30)
55#define CW1200_BLOCK_ACK_THLD (800)
56#define CW1200_BLOCK_ACK_HIST (3)
57#define CW1200_BLOCK_ACK_INTERVAL (1 * HZ / CW1200_BLOCK_ACK_HIST)
58
59#define CW1200_JOIN_TIMEOUT (1 * HZ)
60#define CW1200_AUTH_TIMEOUT (5 * HZ)
61
62struct cw1200_ht_info {
63 struct ieee80211_sta_ht_cap ht_cap;
64 enum nl80211_channel_type channel_type;
65 u16 operation_mode;
66};
67
68/* Please keep order */
69enum cw1200_join_status {
70 CW1200_JOIN_STATUS_PASSIVE = 0,
71 CW1200_JOIN_STATUS_MONITOR,
72 CW1200_JOIN_STATUS_JOINING,
73 CW1200_JOIN_STATUS_PRE_STA,
74 CW1200_JOIN_STATUS_STA,
75 CW1200_JOIN_STATUS_IBSS,
76 CW1200_JOIN_STATUS_AP,
77};
78
79enum cw1200_link_status {
80 CW1200_LINK_OFF,
81 CW1200_LINK_RESERVE,
82 CW1200_LINK_SOFT,
83 CW1200_LINK_HARD,
84 CW1200_LINK_RESET,
85 CW1200_LINK_RESET_REMAP,
86};
87
88extern int cw1200_power_mode;
89extern const char * const cw1200_fw_types[];
90
91struct cw1200_link_entry {
92 unsigned long timestamp;
93 enum cw1200_link_status status;
94 enum cw1200_link_status prev_status;
95 u8 mac[ETH_ALEN];
96 u8 buffered[CW1200_MAX_TID];
97 struct sk_buff_head rx_queue;
98};
99
100struct cw1200_common {
101 /* interfaces to the rest of the stack */
102 struct ieee80211_hw *hw;
103 struct ieee80211_vif *vif;
104 struct device *pdev;
105
106 /* Statistics */
107 struct ieee80211_low_level_stats stats;
108
109 /* Our macaddr */
110 u8 mac_addr[ETH_ALEN];
111
112 /* Hardware interface */
113 const struct sbus_ops *sbus_ops;
114 struct sbus_priv *sbus_priv;
115
116 /* Hardware information */
117 enum {
118 HIF_9000_SILICON_VERSATILE = 0,
119 HIF_8601_VERSATILE,
120 HIF_8601_SILICON,
121 } hw_type;
122 enum {
123 CW1200_HW_REV_CUT10 = 10,
124 CW1200_HW_REV_CUT11 = 11,
125 CW1200_HW_REV_CUT20 = 20,
126 CW1200_HW_REV_CUT22 = 22,
127 CW1X60_HW_REV = 40,
128 } hw_revision;
129 int hw_refclk;
130 bool hw_have_5ghz;
131 const struct firmware *sdd;
132 char *sdd_path;
133
134 struct cw1200_debug_priv *debug;
135
136 struct workqueue_struct *workqueue;
137 struct mutex conf_mutex;
138
139 struct cw1200_queue tx_queue[4];
140 struct cw1200_queue_stats tx_queue_stats;
141 int tx_burst_idx;
142
143 /* firmware/hardware info */
144 unsigned int tx_hdr_len;
145
146 /* Radio data */
147 int output_power;
148
149 /* BBP/MAC state */
150 struct ieee80211_rate *rates;
151 struct ieee80211_rate *mcs_rates;
152 struct ieee80211_channel *channel;
153 struct wsm_edca_params edca;
154 struct wsm_tx_queue_params tx_queue_params;
155 struct wsm_mib_association_mode association_mode;
156 struct wsm_set_bss_params bss_params;
157 struct cw1200_ht_info ht_info;
158 struct wsm_set_pm powersave_mode;
159 struct wsm_set_pm firmware_ps_mode;
160 int cqm_rssi_thold;
161 unsigned cqm_rssi_hyst;
162 bool cqm_use_rssi;
163 int cqm_beacon_loss_count;
164 int channel_switch_in_progress;
165 wait_queue_head_t channel_switch_done;
166 u8 long_frame_max_tx_count;
167 u8 short_frame_max_tx_count;
168 int mode;
169 bool enable_beacon;
170 int beacon_int;
171 bool listening;
172 struct wsm_rx_filter rx_filter;
173 struct wsm_mib_multicast_filter multicast_filter;
174 bool has_multicast_subscription;
175 bool disable_beacon_filter;
176 struct work_struct update_filtering_work;
177 struct work_struct set_beacon_wakeup_period_work;
178
179 u8 ba_rx_tid_mask;
180 u8 ba_tx_tid_mask;
181
182 struct cw1200_pm_state pm_state;
183
184 struct wsm_p2p_ps_modeinfo p2p_ps_modeinfo;
185 struct wsm_uapsd_info uapsd_info;
186 bool setbssparams_done;
187 bool bt_present;
188 u8 conf_listen_interval;
189 u32 listen_interval;
190 u32 erp_info;
191 u32 rts_threshold;
192
193 /* BH */
194 atomic_t bh_rx;
195 atomic_t bh_tx;
196 atomic_t bh_term;
197 atomic_t bh_suspend;
198
199 struct workqueue_struct *bh_workqueue;
200 struct work_struct bh_work;
201
202 int bh_error;
203 wait_queue_head_t bh_wq;
204 wait_queue_head_t bh_evt_wq;
205 u8 buf_id_tx;
206 u8 buf_id_rx;
207 u8 wsm_rx_seq;
208 u8 wsm_tx_seq;
209 int hw_bufs_used;
210 bool powersave_enabled;
211 bool device_can_sleep;
212
213 /* Scan status */
214 struct cw1200_scan scan;
215 /* Keep cw1200 awake (WUP = 1) 1 second after each scan to avoid
216 * FW issue with sleeping/waking up. */
217 atomic_t recent_scan;
218 struct delayed_work clear_recent_scan_work;
219
220 /* WSM */
221 struct wsm_startup_ind wsm_caps;
222 struct mutex wsm_cmd_mux;
223 struct wsm_buf wsm_cmd_buf;
224 struct wsm_cmd wsm_cmd;
225 wait_queue_head_t wsm_cmd_wq;
226 wait_queue_head_t wsm_startup_done;
227 int firmware_ready;
228 atomic_t tx_lock;
229
230 /* WSM debug */
231 int wsm_enable_wsm_dumps;
232
233 /* WSM Join */
234 enum cw1200_join_status join_status;
235 u32 pending_frame_id;
236 bool join_pending;
237 struct delayed_work join_timeout;
238 struct work_struct unjoin_work;
239 struct work_struct join_complete_work;
240 int join_complete_status;
241 int join_dtim_period;
242 bool delayed_unjoin;
243
244 /* TX/RX and security */
245 s8 wep_default_key_id;
246 struct work_struct wep_key_work;
247 u32 key_map;
248 struct wsm_add_key keys[WSM_KEY_MAX_INDEX + 1];
249
250 /* AP powersave */
251 u32 link_id_map;
252 struct cw1200_link_entry link_id_db[CW1200_MAX_STA_IN_AP_MODE];
253 struct work_struct link_id_work;
254 struct delayed_work link_id_gc_work;
255 u32 sta_asleep_mask;
256 u32 pspoll_mask;
257 bool aid0_bit_set;
258 spinlock_t ps_state_lock; /* Protect power save state */
259 bool buffered_multicasts;
260 bool tx_multicast;
261 struct work_struct set_tim_work;
262 struct work_struct set_cts_work;
263 struct work_struct multicast_start_work;
264 struct work_struct multicast_stop_work;
265 struct timer_list mcast_timeout;
266
267 /* WSM events and CQM implementation */
268 spinlock_t event_queue_lock; /* Protect event queue */
269 struct list_head event_queue;
270 struct work_struct event_handler;
271
272 struct delayed_work bss_loss_work;
273 spinlock_t bss_loss_lock; /* Protect BSS loss state */
274 int bss_loss_state;
275 int bss_loss_confirm_id;
276 int delayed_link_loss;
277 struct work_struct bss_params_work;
278
279 /* TX rate policy cache */
280 struct tx_policy_cache tx_policy_cache;
281 struct work_struct tx_policy_upload_work;
282
283 /* legacy PS mode switch in suspend */
284 int ps_mode_switch_in_progress;
285 wait_queue_head_t ps_mode_switch_done;
286
287 /* Workaround for WFD testcase 6.1.10*/
288 struct work_struct linkid_reset_work;
289 u8 action_frame_sa[ETH_ALEN];
290 u8 action_linkid;
291
292#ifdef CONFIG_CW1200_ETF
293 struct sk_buff_head etf_q;
294#endif
295};
296
297struct cw1200_sta_priv {
298 int link_id;
299};
300
301/* interfaces for the drivers */
302int cw1200_core_probe(const struct sbus_ops *sbus_ops,
303 struct sbus_priv *sbus,
304 struct device *pdev,
305 struct cw1200_common **pself,
306 int ref_clk, const u8 *macaddr,
307 const char *sdd_path, bool have_5ghz);
308void cw1200_core_release(struct cw1200_common *self);
309
310#define FWLOAD_BLOCK_SIZE (1024)
311
312static inline int cw1200_is_ht(const struct cw1200_ht_info *ht_info)
313{
314 return ht_info->channel_type != NL80211_CHAN_NO_HT;
315}
316
317static inline int cw1200_ht_greenfield(const struct cw1200_ht_info *ht_info)
318{
319 return cw1200_is_ht(ht_info) &&
320 (ht_info->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
321 !(ht_info->operation_mode &
322 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
323}
324
325static inline int cw1200_ht_ampdu_density(const struct cw1200_ht_info *ht_info)
326{
327 if (!cw1200_is_ht(ht_info))
328 return 0;
329 return ht_info->ht_cap.ampdu_density;
330}
331
332#endif /* CW1200_H */