blob: dfd4fe1e82fb901e51860580f0667f44937bfc30 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _CORE_H_
19#define _CORE_H_
20
21#include <linux/completion.h>
22#include <linux/if_ether.h>
23#include <linux/types.h>
24#include <linux/pci.h>
25
26#include "htc.h"
27#include "hw.h"
28#include "targaddrs.h"
29#include "wmi.h"
30#include "../ath.h"
31#include "../regd.h"
32
33#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
34#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
35#define WO(_f) ((_f##_OFFSET) >> 2)
36
37#define ATH10K_SCAN_ID 0
38#define WMI_READY_TIMEOUT (5 * HZ)
39#define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
40
41/* Antenna noise floor */
42#define ATH10K_DEFAULT_NOISE_FLOOR -95
43
44struct ath10k;
45
Kalle Valo5e3dd152013-06-12 20:52:10 +030046struct ath10k_skb_cb {
47 dma_addr_t paddr;
48 bool is_mapped;
49 bool is_aborted;
50
51 struct {
52 u8 vdev_id;
53 u16 msdu_id;
54 u8 tid;
55 bool is_offchan;
56 bool is_conf;
57 bool discard;
58 bool no_ack;
59 u8 refcount;
60 struct sk_buff *txfrag;
61 struct sk_buff *msdu;
62 } __packed htt;
63
64 /* 4 bytes left on 64bit arch */
65} __packed;
66
67static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
68{
69 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
70 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
71 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
72}
73
74static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
75{
76 if (ATH10K_SKB_CB(skb)->is_mapped)
77 return -EINVAL;
78
79 ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
80 DMA_TO_DEVICE);
81
82 if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
83 return -EIO;
84
85 ATH10K_SKB_CB(skb)->is_mapped = true;
86 return 0;
87}
88
89static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
90{
91 if (!ATH10K_SKB_CB(skb)->is_mapped)
92 return -EINVAL;
93
94 dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
95 DMA_TO_DEVICE);
96 ATH10K_SKB_CB(skb)->is_mapped = false;
97 return 0;
98}
99
100static inline u32 host_interest_item_address(u32 item_offset)
101{
102 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
103}
104
105struct ath10k_bmi {
106 bool done_sent;
107};
108
109struct ath10k_wmi {
110 enum ath10k_htc_ep_id eid;
111 struct completion service_ready;
112 struct completion unified_ready;
113 atomic_t pending_tx_count;
114 wait_queue_head_t wq;
115
116 struct sk_buff_head wmi_event_list;
117 struct work_struct wmi_event_work;
118};
119
120struct ath10k_peer_stat {
121 u8 peer_macaddr[ETH_ALEN];
122 u32 peer_rssi;
123 u32 peer_tx_rate;
124};
125
126struct ath10k_target_stats {
127 /* PDEV stats */
128 s32 ch_noise_floor;
129 u32 tx_frame_count;
130 u32 rx_frame_count;
131 u32 rx_clear_count;
132 u32 cycle_count;
133 u32 phy_err_count;
134 u32 chan_tx_power;
135
136 /* PDEV TX stats */
137 s32 comp_queued;
138 s32 comp_delivered;
139 s32 msdu_enqued;
140 s32 mpdu_enqued;
141 s32 wmm_drop;
142 s32 local_enqued;
143 s32 local_freed;
144 s32 hw_queued;
145 s32 hw_reaped;
146 s32 underrun;
147 s32 tx_abort;
148 s32 mpdus_requed;
149 u32 tx_ko;
150 u32 data_rc;
151 u32 self_triggers;
152 u32 sw_retry_failure;
153 u32 illgl_rate_phy_err;
154 u32 pdev_cont_xretry;
155 u32 pdev_tx_timeout;
156 u32 pdev_resets;
157 u32 phy_underrun;
158 u32 txop_ovf;
159
160 /* PDEV RX stats */
161 s32 mid_ppdu_route_change;
162 s32 status_rcvd;
163 s32 r0_frags;
164 s32 r1_frags;
165 s32 r2_frags;
166 s32 r3_frags;
167 s32 htt_msdus;
168 s32 htt_mpdus;
169 s32 loc_msdus;
170 s32 loc_mpdus;
171 s32 oversize_amsdu;
172 s32 phy_errs;
173 s32 phy_err_drop;
174 s32 mpdu_errs;
175
176 /* VDEV STATS */
177
178 /* PEER STATS */
179 u8 peers;
180 struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
181
182 /* TODO: Beacon filter stats */
183
184};
185
186#define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
187
188struct ath10k_peer {
189 struct list_head list;
190 int vdev_id;
191 u8 addr[ETH_ALEN];
192 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
193 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
194};
195
196#define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
197
198struct ath10k_vif {
199 u32 vdev_id;
200 enum wmi_vdev_type vdev_type;
201 enum wmi_vdev_subtype vdev_subtype;
202 u32 beacon_interval;
203 u32 dtim_period;
204
205 struct ath10k *ar;
206 struct ieee80211_vif *vif;
207
208 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
209 u8 def_wep_key_index;
210
211 u16 tx_seq_no;
212
213 union {
214 struct {
215 u8 bssid[ETH_ALEN];
216 u32 uapsd;
217 } sta;
218 struct {
219 /* 127 stations; wmi limit */
220 u8 tim_bitmap[16];
221 u8 tim_len;
222 u32 ssid_len;
223 u8 ssid[IEEE80211_MAX_SSID_LEN];
224 bool hidden_ssid;
225 /* P2P_IE with NoA attribute for P2P_GO case */
226 u32 noa_len;
227 u8 *noa_data;
228 } ap;
229 struct {
230 u8 bssid[ETH_ALEN];
231 } ibss;
232 } u;
233};
234
235struct ath10k_vif_iter {
236 u32 vdev_id;
237 struct ath10k_vif *arvif;
238};
239
240struct ath10k_debug {
241 struct dentry *debugfs_phy;
242
243 struct ath10k_target_stats target_stats;
244 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
245
246 struct completion event_stats_compl;
247};
248
249struct ath10k {
250 struct ath_common ath_common;
251 struct ieee80211_hw *hw;
252 struct device *dev;
253 u8 mac_addr[ETH_ALEN];
254
255 u32 target_version;
256 u8 fw_version_major;
257 u32 fw_version_minor;
258 u16 fw_version_release;
259 u16 fw_version_build;
260 u32 phy_capability;
261 u32 hw_min_tx_power;
262 u32 hw_max_tx_power;
263 u32 ht_cap_info;
264 u32 vht_cap_info;
265
266 struct targetdef *targetdef;
267 struct hostdef *hostdef;
268
269 bool p2p;
270
271 struct {
272 void *priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 const struct ath10k_hif_ops *ops;
274 } hif;
275
276 struct ath10k_wmi wmi;
277
278 wait_queue_head_t event_queue;
279 bool is_target_paused;
280
281 struct ath10k_bmi bmi;
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300282 struct ath10k_htc htc;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284 struct ath10k_htt *htt;
285
286 struct ath10k_hw_params {
287 u32 id;
288 const char *name;
289 u32 patch_load_addr;
290
291 struct ath10k_hw_params_fw {
292 const char *dir;
293 const char *fw;
294 const char *otp;
295 const char *board;
296 } fw;
297 } hw_params;
298
299 struct {
300 struct completion started;
301 struct completion completed;
302 struct completion on_channel;
303 struct timer_list timeout;
304 bool is_roc;
305 bool in_progress;
306 bool aborting;
307 int vdev_id;
308 int roc_freq;
309 } scan;
310
311 struct {
312 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
313 } mac;
314
315 /* should never be NULL; needed for regular htt rx */
316 struct ieee80211_channel *rx_channel;
317
318 /* valid during scan; needed for mgmt rx during scan */
319 struct ieee80211_channel *scan_channel;
320
321 int free_vdev_map;
322 int monitor_vdev_id;
323 bool monitor_enabled;
324 bool monitor_present;
325 unsigned int filter_flags;
326
327 struct wmi_pdev_set_wmm_params_arg wmm_params;
328 struct completion install_key_done;
329
330 struct completion vdev_setup_done;
331
332 struct workqueue_struct *workqueue;
333
334 /* prevents concurrent FW reconfiguration */
335 struct mutex conf_mutex;
336
337 /* protects shared structure data */
338 spinlock_t data_lock;
339
340 struct list_head peers;
341 wait_queue_head_t peer_mapping_wq;
342
343 struct work_struct offchan_tx_work;
344 struct sk_buff_head offchan_tx_queue;
345 struct completion offchan_tx_completed;
346 struct sk_buff *offchan_tx_skb;
347
348#ifdef CONFIG_ATH10K_DEBUGFS
349 struct ath10k_debug debug;
350#endif
351};
352
353struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300354 const struct ath10k_hif_ops *hif_ops);
355void ath10k_core_destroy(struct ath10k *ar);
356
357int ath10k_core_register(struct ath10k *ar);
358void ath10k_core_unregister(struct ath10k *ar);
359
360int ath10k_core_target_suspend(struct ath10k *ar);
361int ath10k_core_target_resume(struct ath10k *ar);
362
363#endif /* _CORE_H_ */