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