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