ath10k: decouple HTT TX completions
[cascardo/linux.git] / drivers / net / wireless / ath / ath10k / core.h
1 /*
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 "htt.h"
27 #include "htc.h"
28 #include "hw.h"
29 #include "targaddrs.h"
30 #include "wmi.h"
31 #include "../ath.h"
32 #include "../regd.h"
33
34 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
35 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
36 #define WO(_f)      ((_f##_OFFSET) >> 2)
37
38 #define ATH10K_SCAN_ID 0
39 #define WMI_READY_TIMEOUT (5 * HZ)
40 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
41 #define ATH10K_NUM_CHANS 38
42
43 /* Antenna noise floor */
44 #define ATH10K_DEFAULT_NOISE_FLOOR -95
45
46 struct ath10k;
47
48 struct ath10k_skb_cb {
49         dma_addr_t paddr;
50         bool is_mapped;
51         bool is_aborted;
52
53         struct {
54                 u8 vdev_id;
55                 u8 tid;
56                 bool is_offchan;
57                 struct sk_buff *txfrag;
58         } __packed htt;
59 } __packed;
60
61 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
62 {
63         BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
64                      IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
65         return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
66 }
67
68 static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
69 {
70         if (ATH10K_SKB_CB(skb)->is_mapped)
71                 return -EINVAL;
72
73         ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
74                                                    DMA_TO_DEVICE);
75
76         if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
77                 return -EIO;
78
79         ATH10K_SKB_CB(skb)->is_mapped = true;
80         return 0;
81 }
82
83 static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
84 {
85         if (!ATH10K_SKB_CB(skb)->is_mapped)
86                 return -EINVAL;
87
88         dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
89                          DMA_TO_DEVICE);
90         ATH10K_SKB_CB(skb)->is_mapped = false;
91         return 0;
92 }
93
94 static inline u32 host_interest_item_address(u32 item_offset)
95 {
96         return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
97 }
98
99 struct ath10k_bmi {
100         bool done_sent;
101 };
102
103 struct ath10k_wmi {
104         enum ath10k_htc_ep_id eid;
105         struct completion service_ready;
106         struct completion unified_ready;
107         wait_queue_head_t tx_credits_wq;
108 };
109
110 struct ath10k_peer_stat {
111         u8 peer_macaddr[ETH_ALEN];
112         u32 peer_rssi;
113         u32 peer_tx_rate;
114 };
115
116 struct ath10k_target_stats {
117         /* PDEV stats */
118         s32 ch_noise_floor;
119         u32 tx_frame_count;
120         u32 rx_frame_count;
121         u32 rx_clear_count;
122         u32 cycle_count;
123         u32 phy_err_count;
124         u32 chan_tx_power;
125
126         /* PDEV TX stats */
127         s32 comp_queued;
128         s32 comp_delivered;
129         s32 msdu_enqued;
130         s32 mpdu_enqued;
131         s32 wmm_drop;
132         s32 local_enqued;
133         s32 local_freed;
134         s32 hw_queued;
135         s32 hw_reaped;
136         s32 underrun;
137         s32 tx_abort;
138         s32 mpdus_requed;
139         u32 tx_ko;
140         u32 data_rc;
141         u32 self_triggers;
142         u32 sw_retry_failure;
143         u32 illgl_rate_phy_err;
144         u32 pdev_cont_xretry;
145         u32 pdev_tx_timeout;
146         u32 pdev_resets;
147         u32 phy_underrun;
148         u32 txop_ovf;
149
150         /* PDEV RX stats */
151         s32 mid_ppdu_route_change;
152         s32 status_rcvd;
153         s32 r0_frags;
154         s32 r1_frags;
155         s32 r2_frags;
156         s32 r3_frags;
157         s32 htt_msdus;
158         s32 htt_mpdus;
159         s32 loc_msdus;
160         s32 loc_mpdus;
161         s32 oversize_amsdu;
162         s32 phy_errs;
163         s32 phy_err_drop;
164         s32 mpdu_errs;
165
166         /* VDEV STATS */
167
168         /* PEER STATS */
169         u8 peers;
170         struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
171
172         /* TODO: Beacon filter stats */
173
174 };
175
176 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
177
178 struct ath10k_peer {
179         struct list_head list;
180         int vdev_id;
181         u8 addr[ETH_ALEN];
182         DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
183         struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
184 };
185
186 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
187
188 struct ath10k_vif {
189         u32 vdev_id;
190         enum wmi_vdev_type vdev_type;
191         enum wmi_vdev_subtype vdev_subtype;
192         u32 beacon_interval;
193         u32 dtim_period;
194         struct sk_buff *beacon;
195
196         struct ath10k *ar;
197         struct ieee80211_vif *vif;
198
199         struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
200         u8 def_wep_key_index;
201
202         u16 tx_seq_no;
203
204         union {
205                 struct {
206                         u8 bssid[ETH_ALEN];
207                         u32 uapsd;
208                 } sta;
209                 struct {
210                         /* 127 stations; wmi limit */
211                         u8 tim_bitmap[16];
212                         u8 tim_len;
213                         u32 ssid_len;
214                         u8 ssid[IEEE80211_MAX_SSID_LEN];
215                         bool hidden_ssid;
216                         /* P2P_IE with NoA attribute for P2P_GO case */
217                         u32 noa_len;
218                         u8 *noa_data;
219                 } ap;
220                 struct {
221                         u8 bssid[ETH_ALEN];
222                 } ibss;
223         } u;
224 };
225
226 struct ath10k_vif_iter {
227         u32 vdev_id;
228         struct ath10k_vif *arvif;
229 };
230
231 struct ath10k_debug {
232         struct dentry *debugfs_phy;
233
234         struct ath10k_target_stats target_stats;
235         u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
236
237         struct completion event_stats_compl;
238
239         unsigned long htt_stats_mask;
240         struct delayed_work htt_stats_dwork;
241 };
242
243 enum ath10k_state {
244         ATH10K_STATE_OFF = 0,
245         ATH10K_STATE_ON,
246
247         /* When doing firmware recovery the device is first powered down.
248          * mac80211 is supposed to call in to start() hook later on. It is
249          * however possible that driver unloading and firmware crash overlap.
250          * mac80211 can wait on conf_mutex in stop() while the device is
251          * stopped in ath10k_core_restart() work holding conf_mutex. The state
252          * RESTARTED means that the device is up and mac80211 has started hw
253          * reconfiguration. Once mac80211 is done with the reconfiguration we
254          * set the state to STATE_ON in restart_complete(). */
255         ATH10K_STATE_RESTARTING,
256         ATH10K_STATE_RESTARTED,
257
258         /* The device has crashed while restarting hw. This state is like ON
259          * but commands are blocked in HTC and -ECOMM response is given. This
260          * prevents completion timeouts and makes the driver more responsive to
261          * userspace commands. This is also prevents recursive recovery. */
262         ATH10K_STATE_WEDGED,
263 };
264
265 enum ath10k_fw_features {
266         /* wmi_mgmt_rx_hdr contains extra RSSI information */
267         ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
268
269         /* keep last */
270         ATH10K_FW_FEATURE_COUNT,
271 };
272
273 struct ath10k {
274         struct ath_common ath_common;
275         struct ieee80211_hw *hw;
276         struct device *dev;
277         u8 mac_addr[ETH_ALEN];
278
279         u32 chip_id;
280         u32 target_version;
281         u8 fw_version_major;
282         u32 fw_version_minor;
283         u16 fw_version_release;
284         u16 fw_version_build;
285         u32 phy_capability;
286         u32 hw_min_tx_power;
287         u32 hw_max_tx_power;
288         u32 ht_cap_info;
289         u32 vht_cap_info;
290         u32 num_rf_chains;
291
292         DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
293
294         struct targetdef *targetdef;
295         struct hostdef *hostdef;
296
297         bool p2p;
298
299         struct {
300                 void *priv;
301                 const struct ath10k_hif_ops *ops;
302         } hif;
303
304         wait_queue_head_t event_queue;
305         bool is_target_paused;
306
307         struct ath10k_bmi bmi;
308         struct ath10k_wmi wmi;
309         struct ath10k_htc htc;
310         struct ath10k_htt htt;
311
312         struct ath10k_hw_params {
313                 u32 id;
314                 const char *name;
315                 u32 patch_load_addr;
316
317                 struct ath10k_hw_params_fw {
318                         const char *dir;
319                         const char *fw;
320                         const char *otp;
321                         const char *board;
322                 } fw;
323         } hw_params;
324
325         const struct firmware *board_data;
326         const struct firmware *otp;
327         const struct firmware *firmware;
328
329         struct {
330                 struct completion started;
331                 struct completion completed;
332                 struct completion on_channel;
333                 struct timer_list timeout;
334                 bool is_roc;
335                 bool in_progress;
336                 bool aborting;
337                 int vdev_id;
338                 int roc_freq;
339         } scan;
340
341         struct {
342                 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
343         } mac;
344
345         /* should never be NULL; needed for regular htt rx */
346         struct ieee80211_channel *rx_channel;
347
348         /* valid during scan; needed for mgmt rx during scan */
349         struct ieee80211_channel *scan_channel;
350
351         int free_vdev_map;
352         int monitor_vdev_id;
353         bool monitor_enabled;
354         bool monitor_present;
355         unsigned int filter_flags;
356
357         struct wmi_pdev_set_wmm_params_arg wmm_params;
358         struct completion install_key_done;
359
360         struct completion vdev_setup_done;
361
362         struct workqueue_struct *workqueue;
363
364         /* prevents concurrent FW reconfiguration */
365         struct mutex conf_mutex;
366
367         /* protects shared structure data */
368         spinlock_t data_lock;
369
370         struct list_head peers;
371         wait_queue_head_t peer_mapping_wq;
372
373         struct work_struct offchan_tx_work;
374         struct sk_buff_head offchan_tx_queue;
375         struct completion offchan_tx_completed;
376         struct sk_buff *offchan_tx_skb;
377
378         enum ath10k_state state;
379
380         struct work_struct restart_work;
381
382         /* cycle count is reported twice for each visited channel during scan.
383          * access protected by data_lock */
384         u32 survey_last_rx_clear_count;
385         u32 survey_last_cycle_count;
386         struct survey_info survey[ATH10K_NUM_CHANS];
387
388 #ifdef CONFIG_ATH10K_DEBUGFS
389         struct ath10k_debug debug;
390 #endif
391 };
392
393 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
394                                   const struct ath10k_hif_ops *hif_ops);
395 void ath10k_core_destroy(struct ath10k *ar);
396
397 int ath10k_core_start(struct ath10k *ar);
398 void ath10k_core_stop(struct ath10k *ar);
399 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
400 void ath10k_core_unregister(struct ath10k *ar);
401
402 #endif /* _CORE_H_ */