]> Git Repo - linux.git/blob - drivers/net/wireless/ath/ath10k/core.h
ath10k: add hw connection monitor support
[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 #include <linux/uuid.h>
26 #include <linux/time.h>
27
28 #include "htt.h"
29 #include "htc.h"
30 #include "hw.h"
31 #include "targaddrs.h"
32 #include "wmi.h"
33 #include "../ath.h"
34 #include "../regd.h"
35 #include "../dfs_pattern_detector.h"
36 #include "spectral.h"
37 #include "thermal.h"
38
39 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
40 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
41 #define WO(_f)      ((_f##_OFFSET) >> 2)
42
43 #define ATH10K_SCAN_ID 0
44 #define WMI_READY_TIMEOUT (5 * HZ)
45 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
46 #define ATH10K_CONNECTION_LOSS_HZ (3*HZ)
47 #define ATH10K_NUM_CHANS 38
48
49 /* Antenna noise floor */
50 #define ATH10K_DEFAULT_NOISE_FLOOR -95
51
52 #define ATH10K_MAX_NUM_MGMT_PENDING 128
53
54 /* number of failed packets */
55 #define ATH10K_KICKOUT_THRESHOLD 50
56
57 /*
58  * Use insanely high numbers to make sure that the firmware implementation
59  * won't start, we have the same functionality already in hostapd. Unit
60  * is seconds.
61  */
62 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
63 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
64 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
65
66 struct ath10k;
67
68 enum ath10k_bus {
69         ATH10K_BUS_PCI,
70 };
71
72 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
73 {
74         switch (bus) {
75         case ATH10K_BUS_PCI:
76                 return "pci";
77         }
78
79         return "unknown";
80 }
81
82 struct ath10k_skb_cb {
83         dma_addr_t paddr;
84         u8 eid;
85         u8 vdev_id;
86
87         struct {
88                 u8 tid;
89                 u16 freq;
90                 bool is_offchan;
91                 struct ath10k_htt_txbuf *txbuf;
92                 u32 txbuf_paddr;
93         } __packed htt;
94
95         struct {
96                 bool dtim_zero;
97                 bool deliver_cab;
98         } bcn;
99 } __packed;
100
101 struct ath10k_skb_rxcb {
102         dma_addr_t paddr;
103         struct hlist_node hlist;
104 };
105
106 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
107 {
108         BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
109                      IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
110         return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
111 }
112
113 static inline struct ath10k_skb_rxcb *ATH10K_SKB_RXCB(struct sk_buff *skb)
114 {
115         BUILD_BUG_ON(sizeof(struct ath10k_skb_rxcb) > sizeof(skb->cb));
116         return (struct ath10k_skb_rxcb *)skb->cb;
117 }
118
119 #define ATH10K_RXCB_SKB(rxcb) \
120                 container_of((void *)rxcb, struct sk_buff, cb)
121
122 static inline u32 host_interest_item_address(u32 item_offset)
123 {
124         return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
125 }
126
127 struct ath10k_bmi {
128         bool done_sent;
129 };
130
131 struct ath10k_mem_chunk {
132         void *vaddr;
133         dma_addr_t paddr;
134         u32 len;
135         u32 req_id;
136 };
137
138 struct ath10k_wmi {
139         enum ath10k_fw_wmi_op_version op_version;
140         enum ath10k_htc_ep_id eid;
141         struct completion service_ready;
142         struct completion unified_ready;
143         wait_queue_head_t tx_credits_wq;
144         DECLARE_BITMAP(svc_map, WMI_SERVICE_MAX);
145         struct wmi_cmd_map *cmd;
146         struct wmi_vdev_param_map *vdev_param;
147         struct wmi_pdev_param_map *pdev_param;
148         const struct wmi_ops *ops;
149
150         u32 num_mem_chunks;
151         struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
152 };
153
154 struct ath10k_fw_stats_peer {
155         struct list_head list;
156
157         u8 peer_macaddr[ETH_ALEN];
158         u32 peer_rssi;
159         u32 peer_tx_rate;
160         u32 peer_rx_rate; /* 10x only */
161 };
162
163 struct ath10k_fw_stats_vdev {
164         struct list_head list;
165
166         u32 vdev_id;
167         u32 beacon_snr;
168         u32 data_snr;
169         u32 num_tx_frames[4];
170         u32 num_rx_frames;
171         u32 num_tx_frames_retries[4];
172         u32 num_tx_frames_failures[4];
173         u32 num_rts_fail;
174         u32 num_rts_success;
175         u32 num_rx_err;
176         u32 num_rx_discard;
177         u32 num_tx_not_acked;
178         u32 tx_rate_history[10];
179         u32 beacon_rssi_history[10];
180 };
181
182 struct ath10k_fw_stats_pdev {
183         struct list_head list;
184
185         /* PDEV stats */
186         s32 ch_noise_floor;
187         u32 tx_frame_count;
188         u32 rx_frame_count;
189         u32 rx_clear_count;
190         u32 cycle_count;
191         u32 phy_err_count;
192         u32 chan_tx_power;
193         u32 ack_rx_bad;
194         u32 rts_bad;
195         u32 rts_good;
196         u32 fcs_bad;
197         u32 no_beacons;
198         u32 mib_int_count;
199
200         /* PDEV TX stats */
201         s32 comp_queued;
202         s32 comp_delivered;
203         s32 msdu_enqued;
204         s32 mpdu_enqued;
205         s32 wmm_drop;
206         s32 local_enqued;
207         s32 local_freed;
208         s32 hw_queued;
209         s32 hw_reaped;
210         s32 underrun;
211         s32 tx_abort;
212         s32 mpdus_requed;
213         u32 tx_ko;
214         u32 data_rc;
215         u32 self_triggers;
216         u32 sw_retry_failure;
217         u32 illgl_rate_phy_err;
218         u32 pdev_cont_xretry;
219         u32 pdev_tx_timeout;
220         u32 pdev_resets;
221         u32 phy_underrun;
222         u32 txop_ovf;
223
224         /* PDEV RX stats */
225         s32 mid_ppdu_route_change;
226         s32 status_rcvd;
227         s32 r0_frags;
228         s32 r1_frags;
229         s32 r2_frags;
230         s32 r3_frags;
231         s32 htt_msdus;
232         s32 htt_mpdus;
233         s32 loc_msdus;
234         s32 loc_mpdus;
235         s32 oversize_amsdu;
236         s32 phy_errs;
237         s32 phy_err_drop;
238         s32 mpdu_errs;
239 };
240
241 struct ath10k_fw_stats {
242         struct list_head pdevs;
243         struct list_head vdevs;
244         struct list_head peers;
245 };
246
247 struct ath10k_dfs_stats {
248         u32 phy_errors;
249         u32 pulses_total;
250         u32 pulses_detected;
251         u32 pulses_discarded;
252         u32 radar_detected;
253 };
254
255 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
256
257 struct ath10k_peer {
258         struct list_head list;
259         int vdev_id;
260         u8 addr[ETH_ALEN];
261         DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
262
263         /* protected by ar->data_lock */
264         struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
265 };
266
267 struct ath10k_sta {
268         struct ath10k_vif *arvif;
269
270         /* the following are protected by ar->data_lock */
271         u32 changed; /* IEEE80211_RC_* */
272         u32 bw;
273         u32 nss;
274         u32 smps;
275
276         struct work_struct update_wk;
277
278 #ifdef CONFIG_MAC80211_DEBUGFS
279         /* protected by conf_mutex */
280         bool aggr_mode;
281 #endif
282 };
283
284 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
285
286 enum ath10k_beacon_state {
287         ATH10K_BEACON_SCHEDULED = 0,
288         ATH10K_BEACON_SENDING,
289         ATH10K_BEACON_SENT,
290 };
291
292 struct ath10k_vif {
293         struct list_head list;
294
295         u32 vdev_id;
296         enum wmi_vdev_type vdev_type;
297         enum wmi_vdev_subtype vdev_subtype;
298         u32 beacon_interval;
299         u32 dtim_period;
300         struct sk_buff *beacon;
301         /* protected by data_lock */
302         enum ath10k_beacon_state beacon_state;
303         void *beacon_buf;
304         dma_addr_t beacon_paddr;
305
306         struct ath10k *ar;
307         struct ieee80211_vif *vif;
308
309         bool is_started;
310         bool is_up;
311         bool spectral_enabled;
312         bool ps;
313         u32 aid;
314         u8 bssid[ETH_ALEN];
315
316         struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
317         s8 def_wep_key_idx;
318
319         u16 tx_seq_no;
320
321         union {
322                 struct {
323                         u32 uapsd;
324                 } sta;
325                 struct {
326                         /* 127 stations; wmi limit */
327                         u8 tim_bitmap[16];
328                         u8 tim_len;
329                         u32 ssid_len;
330                         u8 ssid[IEEE80211_MAX_SSID_LEN];
331                         bool hidden_ssid;
332                         /* P2P_IE with NoA attribute for P2P_GO case */
333                         u32 noa_len;
334                         u8 *noa_data;
335                 } ap;
336         } u;
337
338         u8 fixed_rate;
339         u8 fixed_nss;
340         u8 force_sgi;
341         bool use_cts_prot;
342         int num_legacy_stations;
343         int txpower;
344         struct wmi_wmm_params_all_arg wmm_params;
345         struct work_struct ap_csa_work;
346         struct delayed_work connection_loss_work;
347 };
348
349 struct ath10k_vif_iter {
350         u32 vdev_id;
351         struct ath10k_vif *arvif;
352 };
353
354 /* used for crash-dump storage, protected by data-lock */
355 struct ath10k_fw_crash_data {
356         bool crashed_since_read;
357
358         uuid_le uuid;
359         struct timespec timestamp;
360         __le32 registers[REG_DUMP_COUNT_QCA988X];
361 };
362
363 struct ath10k_debug {
364         struct dentry *debugfs_phy;
365
366         struct ath10k_fw_stats fw_stats;
367         struct completion fw_stats_complete;
368         bool fw_stats_done;
369
370         unsigned long htt_stats_mask;
371         struct delayed_work htt_stats_dwork;
372         struct ath10k_dfs_stats dfs_stats;
373         struct ath_dfs_pool_stats dfs_pool_stats;
374
375         /* protected by conf_mutex */
376         u32 fw_dbglog_mask;
377         u32 fw_dbglog_level;
378         u32 pktlog_filter;
379         u32 reg_addr;
380         u32 nf_cal_period;
381
382         u8 htt_max_amsdu;
383         u8 htt_max_ampdu;
384
385         struct ath10k_fw_crash_data *fw_crash_data;
386 };
387
388 enum ath10k_state {
389         ATH10K_STATE_OFF = 0,
390         ATH10K_STATE_ON,
391
392         /* When doing firmware recovery the device is first powered down.
393          * mac80211 is supposed to call in to start() hook later on. It is
394          * however possible that driver unloading and firmware crash overlap.
395          * mac80211 can wait on conf_mutex in stop() while the device is
396          * stopped in ath10k_core_restart() work holding conf_mutex. The state
397          * RESTARTED means that the device is up and mac80211 has started hw
398          * reconfiguration. Once mac80211 is done with the reconfiguration we
399          * set the state to STATE_ON in reconfig_complete(). */
400         ATH10K_STATE_RESTARTING,
401         ATH10K_STATE_RESTARTED,
402
403         /* The device has crashed while restarting hw. This state is like ON
404          * but commands are blocked in HTC and -ECOMM response is given. This
405          * prevents completion timeouts and makes the driver more responsive to
406          * userspace commands. This is also prevents recursive recovery. */
407         ATH10K_STATE_WEDGED,
408
409         /* factory tests */
410         ATH10K_STATE_UTF,
411 };
412
413 enum ath10k_firmware_mode {
414         /* the default mode, standard 802.11 functionality */
415         ATH10K_FIRMWARE_MODE_NORMAL,
416
417         /* factory tests etc */
418         ATH10K_FIRMWARE_MODE_UTF,
419 };
420
421 enum ath10k_fw_features {
422         /* wmi_mgmt_rx_hdr contains extra RSSI information */
423         ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
424
425         /* Firmware from 10X branch. Deprecated, don't use in new code. */
426         ATH10K_FW_FEATURE_WMI_10X = 1,
427
428         /* firmware support tx frame management over WMI, otherwise it's HTT */
429         ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
430
431         /* Firmware does not support P2P */
432         ATH10K_FW_FEATURE_NO_P2P = 3,
433
434         /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature
435          * bit is required to be set as well. Deprecated, don't use in new
436          * code.
437          */
438         ATH10K_FW_FEATURE_WMI_10_2 = 4,
439
440         /* Some firmware revisions lack proper multi-interface client powersave
441          * implementation. Enabling PS could result in connection drops,
442          * traffic stalls, etc.
443          */
444         ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT = 5,
445
446         /* keep last */
447         ATH10K_FW_FEATURE_COUNT,
448 };
449
450 enum ath10k_dev_flags {
451         /* Indicates that ath10k device is during CAC phase of DFS */
452         ATH10K_CAC_RUNNING,
453         ATH10K_FLAG_CORE_REGISTERED,
454
455         /* Device has crashed and needs to restart. This indicates any pending
456          * waiters should immediately cancel instead of waiting for a time out.
457          */
458         ATH10K_FLAG_CRASH_FLUSH,
459 };
460
461 enum ath10k_cal_mode {
462         ATH10K_CAL_MODE_FILE,
463         ATH10K_CAL_MODE_OTP,
464         ATH10K_CAL_MODE_DT,
465 };
466
467 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
468 {
469         switch (mode) {
470         case ATH10K_CAL_MODE_FILE:
471                 return "file";
472         case ATH10K_CAL_MODE_OTP:
473                 return "otp";
474         case ATH10K_CAL_MODE_DT:
475                 return "dt";
476         }
477
478         return "unknown";
479 }
480
481 enum ath10k_scan_state {
482         ATH10K_SCAN_IDLE,
483         ATH10K_SCAN_STARTING,
484         ATH10K_SCAN_RUNNING,
485         ATH10K_SCAN_ABORTING,
486 };
487
488 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
489 {
490         switch (state) {
491         case ATH10K_SCAN_IDLE:
492                 return "idle";
493         case ATH10K_SCAN_STARTING:
494                 return "starting";
495         case ATH10K_SCAN_RUNNING:
496                 return "running";
497         case ATH10K_SCAN_ABORTING:
498                 return "aborting";
499         }
500
501         return "unknown";
502 }
503
504 struct ath10k {
505         struct ath_common ath_common;
506         struct ieee80211_hw *hw;
507         struct device *dev;
508         u8 mac_addr[ETH_ALEN];
509
510         enum ath10k_hw_rev hw_rev;
511         u32 chip_id;
512         u32 target_version;
513         u8 fw_version_major;
514         u32 fw_version_minor;
515         u16 fw_version_release;
516         u16 fw_version_build;
517         u32 phy_capability;
518         u32 hw_min_tx_power;
519         u32 hw_max_tx_power;
520         u32 ht_cap_info;
521         u32 vht_cap_info;
522         u32 num_rf_chains;
523
524         DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
525
526         bool p2p;
527
528         struct {
529                 enum ath10k_bus bus;
530                 const struct ath10k_hif_ops *ops;
531         } hif;
532
533         struct completion target_suspend;
534
535         const struct ath10k_hw_regs *regs;
536         struct ath10k_bmi bmi;
537         struct ath10k_wmi wmi;
538         struct ath10k_htc htc;
539         struct ath10k_htt htt;
540
541         struct ath10k_hw_params {
542                 u32 id;
543                 const char *name;
544                 u32 patch_load_addr;
545                 int uart_pin;
546
547                 struct ath10k_hw_params_fw {
548                         const char *dir;
549                         const char *fw;
550                         const char *otp;
551                         const char *board;
552                         size_t board_size;
553                         size_t board_ext_size;
554                 } fw;
555         } hw_params;
556
557         const struct firmware *board;
558         const void *board_data;
559         size_t board_len;
560
561         const struct firmware *otp;
562         const void *otp_data;
563         size_t otp_len;
564
565         const struct firmware *firmware;
566         const void *firmware_data;
567         size_t firmware_len;
568
569         const struct firmware *cal_file;
570
571         int fw_api;
572         enum ath10k_cal_mode cal_mode;
573
574         struct {
575                 struct completion started;
576                 struct completion completed;
577                 struct completion on_channel;
578                 struct delayed_work timeout;
579                 enum ath10k_scan_state state;
580                 bool is_roc;
581                 int vdev_id;
582                 int roc_freq;
583         } scan;
584
585         struct {
586                 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
587         } mac;
588
589         /* should never be NULL; needed for regular htt rx */
590         struct ieee80211_channel *rx_channel;
591
592         /* valid during scan; needed for mgmt rx during scan */
593         struct ieee80211_channel *scan_channel;
594
595         /* current operating channel definition */
596         struct cfg80211_chan_def chandef;
597
598         unsigned long long free_vdev_map;
599         bool monitor;
600         int monitor_vdev_id;
601         bool monitor_started;
602         unsigned int filter_flags;
603         unsigned long dev_flags;
604         u32 dfs_block_radar_events;
605
606         /* protected by conf_mutex */
607         bool radar_enabled;
608         int num_started_vdevs;
609
610         /* Protected by conf-mutex */
611         u8 supp_tx_chainmask;
612         u8 supp_rx_chainmask;
613         u8 cfg_tx_chainmask;
614         u8 cfg_rx_chainmask;
615
616         struct completion install_key_done;
617
618         struct completion vdev_setup_done;
619
620         struct workqueue_struct *workqueue;
621
622         /* prevents concurrent FW reconfiguration */
623         struct mutex conf_mutex;
624
625         /* protects shared structure data */
626         spinlock_t data_lock;
627
628         struct list_head arvifs;
629         struct list_head peers;
630         wait_queue_head_t peer_mapping_wq;
631
632         /* protected by conf_mutex */
633         int num_peers;
634         int num_stations;
635
636         int max_num_peers;
637         int max_num_stations;
638         int max_num_vdevs;
639
640         struct work_struct offchan_tx_work;
641         struct sk_buff_head offchan_tx_queue;
642         struct completion offchan_tx_completed;
643         struct sk_buff *offchan_tx_skb;
644
645         struct work_struct wmi_mgmt_tx_work;
646         struct sk_buff_head wmi_mgmt_tx_queue;
647
648         enum ath10k_state state;
649
650         struct work_struct register_work;
651         struct work_struct restart_work;
652
653         /* cycle count is reported twice for each visited channel during scan.
654          * access protected by data_lock */
655         u32 survey_last_rx_clear_count;
656         u32 survey_last_cycle_count;
657         struct survey_info survey[ATH10K_NUM_CHANS];
658
659         struct dfs_pattern_detector *dfs_detector;
660
661 #ifdef CONFIG_ATH10K_DEBUGFS
662         struct ath10k_debug debug;
663 #endif
664
665         struct {
666                 /* relay(fs) channel for spectral scan */
667                 struct rchan *rfs_chan_spec_scan;
668
669                 /* spectral_mode and spec_config are protected by conf_mutex */
670                 enum ath10k_spectral_mode mode;
671                 struct ath10k_spec_scan config;
672         } spectral;
673
674         struct {
675                 /* protected by conf_mutex */
676                 const struct firmware *utf;
677                 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
678                 enum ath10k_fw_wmi_op_version orig_wmi_op_version;
679
680                 /* protected by data_lock */
681                 bool utf_monitor;
682         } testmode;
683
684         struct {
685                 /* protected by data_lock */
686                 u32 fw_crash_counter;
687                 u32 fw_warm_reset_counter;
688                 u32 fw_cold_reset_counter;
689         } stats;
690
691         struct ath10k_thermal thermal;
692
693         /* must be last */
694         u8 drv_priv[0] __aligned(sizeof(void *));
695 };
696
697 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
698                                   enum ath10k_bus bus,
699                                   enum ath10k_hw_rev hw_rev,
700                                   const struct ath10k_hif_ops *hif_ops);
701 void ath10k_core_destroy(struct ath10k *ar);
702
703 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
704 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
705 void ath10k_core_stop(struct ath10k *ar);
706 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
707 void ath10k_core_unregister(struct ath10k *ar);
708
709 #endif /* _CORE_H_ */
This page took 0.082012 seconds and 4 git commands to generate.