2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
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.
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.
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>
31 #include "targaddrs.h"
35 #include "../dfs_pattern_detector.h"
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)
43 #define ATH10K_SCAN_ID 0
44 #define WMI_READY_TIMEOUT (5 * HZ)
45 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
46 #define ATH10K_NUM_CHANS 38
48 /* Antenna noise floor */
49 #define ATH10K_DEFAULT_NOISE_FLOOR -95
51 #define ATH10K_MAX_NUM_MGMT_PENDING 128
53 /* number of failed packets */
54 #define ATH10K_KICKOUT_THRESHOLD 50
57 * Use insanely high numbers to make sure that the firmware implementation
58 * won't start, we have the same functionality already in hostapd. Unit
61 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
62 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
63 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
71 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
81 struct ath10k_skb_cb {
90 struct ath10k_htt_txbuf *txbuf;
100 struct ath10k_skb_rxcb {
102 struct hlist_node hlist;
105 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
107 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
108 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
109 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
112 static inline struct ath10k_skb_rxcb *ATH10K_SKB_RXCB(struct sk_buff *skb)
114 BUILD_BUG_ON(sizeof(struct ath10k_skb_rxcb) > sizeof(skb->cb));
115 return (struct ath10k_skb_rxcb *)skb->cb;
118 #define ATH10K_RXCB_SKB(rxcb) \
119 container_of((void *)rxcb, struct sk_buff, cb)
121 static inline u32 host_interest_item_address(u32 item_offset)
123 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
130 struct ath10k_mem_chunk {
138 enum ath10k_fw_wmi_op_version op_version;
139 enum ath10k_htc_ep_id eid;
140 struct completion service_ready;
141 struct completion unified_ready;
142 wait_queue_head_t tx_credits_wq;
143 DECLARE_BITMAP(svc_map, WMI_SERVICE_MAX);
144 struct wmi_cmd_map *cmd;
145 struct wmi_vdev_param_map *vdev_param;
146 struct wmi_pdev_param_map *pdev_param;
147 const struct wmi_ops *ops;
150 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
153 struct ath10k_fw_stats_peer {
154 struct list_head list;
156 u8 peer_macaddr[ETH_ALEN];
159 u32 peer_rx_rate; /* 10x only */
162 struct ath10k_fw_stats_vdev {
163 struct list_head list;
168 u32 num_tx_frames[4];
170 u32 num_tx_frames_retries[4];
171 u32 num_tx_frames_failures[4];
176 u32 num_tx_not_acked;
177 u32 tx_rate_history[10];
178 u32 beacon_rssi_history[10];
181 struct ath10k_fw_stats_pdev {
182 struct list_head list;
215 u32 sw_retry_failure;
216 u32 illgl_rate_phy_err;
217 u32 pdev_cont_xretry;
224 s32 mid_ppdu_route_change;
240 struct ath10k_fw_stats {
241 struct list_head pdevs;
242 struct list_head vdevs;
243 struct list_head peers;
246 struct ath10k_dfs_stats {
250 u32 pulses_discarded;
254 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
257 struct list_head list;
260 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
262 /* protected by ar->data_lock */
263 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
267 struct ath10k_vif *arvif;
269 /* the following are protected by ar->data_lock */
270 u32 changed; /* IEEE80211_RC_* */
275 struct work_struct update_wk;
277 #ifdef CONFIG_MAC80211_DEBUGFS
278 /* protected by conf_mutex */
283 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
285 enum ath10k_beacon_state {
286 ATH10K_BEACON_SCHEDULED = 0,
287 ATH10K_BEACON_SENDING,
292 struct list_head list;
295 enum wmi_vdev_type vdev_type;
296 enum wmi_vdev_subtype vdev_subtype;
299 struct sk_buff *beacon;
300 /* protected by data_lock */
301 enum ath10k_beacon_state beacon_state;
303 dma_addr_t beacon_paddr;
306 struct ieee80211_vif *vif;
310 bool spectral_enabled;
315 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
325 /* 127 stations; wmi limit */
329 u8 ssid[IEEE80211_MAX_SSID_LEN];
331 /* P2P_IE with NoA attribute for P2P_GO case */
341 int num_legacy_stations;
343 struct wmi_wmm_params_all_arg wmm_params;
346 struct ath10k_vif_iter {
348 struct ath10k_vif *arvif;
351 /* used for crash-dump storage, protected by data-lock */
352 struct ath10k_fw_crash_data {
353 bool crashed_since_read;
356 struct timespec timestamp;
357 __le32 registers[REG_DUMP_COUNT_QCA988X];
360 struct ath10k_debug {
361 struct dentry *debugfs_phy;
363 struct ath10k_fw_stats fw_stats;
364 struct completion fw_stats_complete;
367 unsigned long htt_stats_mask;
368 struct delayed_work htt_stats_dwork;
369 struct ath10k_dfs_stats dfs_stats;
370 struct ath_dfs_pool_stats dfs_pool_stats;
372 /* protected by conf_mutex */
382 struct ath10k_fw_crash_data *fw_crash_data;
386 ATH10K_STATE_OFF = 0,
389 /* When doing firmware recovery the device is first powered down.
390 * mac80211 is supposed to call in to start() hook later on. It is
391 * however possible that driver unloading and firmware crash overlap.
392 * mac80211 can wait on conf_mutex in stop() while the device is
393 * stopped in ath10k_core_restart() work holding conf_mutex. The state
394 * RESTARTED means that the device is up and mac80211 has started hw
395 * reconfiguration. Once mac80211 is done with the reconfiguration we
396 * set the state to STATE_ON in reconfig_complete(). */
397 ATH10K_STATE_RESTARTING,
398 ATH10K_STATE_RESTARTED,
400 /* The device has crashed while restarting hw. This state is like ON
401 * but commands are blocked in HTC and -ECOMM response is given. This
402 * prevents completion timeouts and makes the driver more responsive to
403 * userspace commands. This is also prevents recursive recovery. */
410 enum ath10k_firmware_mode {
411 /* the default mode, standard 802.11 functionality */
412 ATH10K_FIRMWARE_MODE_NORMAL,
414 /* factory tests etc */
415 ATH10K_FIRMWARE_MODE_UTF,
418 enum ath10k_fw_features {
419 /* wmi_mgmt_rx_hdr contains extra RSSI information */
420 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
422 /* Firmware from 10X branch. Deprecated, don't use in new code. */
423 ATH10K_FW_FEATURE_WMI_10X = 1,
425 /* firmware support tx frame management over WMI, otherwise it's HTT */
426 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
428 /* Firmware does not support P2P */
429 ATH10K_FW_FEATURE_NO_P2P = 3,
431 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature
432 * bit is required to be set as well. Deprecated, don't use in new
435 ATH10K_FW_FEATURE_WMI_10_2 = 4,
437 /* Some firmware revisions lack proper multi-interface client powersave
438 * implementation. Enabling PS could result in connection drops,
439 * traffic stalls, etc.
441 ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT = 5,
444 ATH10K_FW_FEATURE_COUNT,
447 enum ath10k_dev_flags {
448 /* Indicates that ath10k device is during CAC phase of DFS */
450 ATH10K_FLAG_CORE_REGISTERED,
452 /* Device has crashed and needs to restart. This indicates any pending
453 * waiters should immediately cancel instead of waiting for a time out.
455 ATH10K_FLAG_CRASH_FLUSH,
458 enum ath10k_cal_mode {
459 ATH10K_CAL_MODE_FILE,
464 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
467 case ATH10K_CAL_MODE_FILE:
469 case ATH10K_CAL_MODE_OTP:
471 case ATH10K_CAL_MODE_DT:
478 enum ath10k_scan_state {
480 ATH10K_SCAN_STARTING,
482 ATH10K_SCAN_ABORTING,
485 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
488 case ATH10K_SCAN_IDLE:
490 case ATH10K_SCAN_STARTING:
492 case ATH10K_SCAN_RUNNING:
494 case ATH10K_SCAN_ABORTING:
502 struct ath_common ath_common;
503 struct ieee80211_hw *hw;
505 u8 mac_addr[ETH_ALEN];
507 enum ath10k_hw_rev hw_rev;
511 u32 fw_version_minor;
512 u16 fw_version_release;
513 u16 fw_version_build;
521 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
527 const struct ath10k_hif_ops *ops;
530 struct completion target_suspend;
532 const struct ath10k_hw_regs *regs;
533 struct ath10k_bmi bmi;
534 struct ath10k_wmi wmi;
535 struct ath10k_htc htc;
536 struct ath10k_htt htt;
538 struct ath10k_hw_params {
544 struct ath10k_hw_params_fw {
550 size_t board_ext_size;
554 const struct firmware *board;
555 const void *board_data;
558 const struct firmware *otp;
559 const void *otp_data;
562 const struct firmware *firmware;
563 const void *firmware_data;
566 const struct firmware *cal_file;
569 enum ath10k_cal_mode cal_mode;
572 struct completion started;
573 struct completion completed;
574 struct completion on_channel;
575 struct delayed_work timeout;
576 enum ath10k_scan_state state;
583 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
586 /* should never be NULL; needed for regular htt rx */
587 struct ieee80211_channel *rx_channel;
589 /* valid during scan; needed for mgmt rx during scan */
590 struct ieee80211_channel *scan_channel;
592 /* current operating channel definition */
593 struct cfg80211_chan_def chandef;
595 unsigned long long free_vdev_map;
598 bool monitor_started;
599 unsigned int filter_flags;
600 unsigned long dev_flags;
601 u32 dfs_block_radar_events;
603 /* protected by conf_mutex */
605 int num_started_vdevs;
607 /* Protected by conf-mutex */
608 u8 supp_tx_chainmask;
609 u8 supp_rx_chainmask;
613 struct completion install_key_done;
615 struct completion vdev_setup_done;
617 struct workqueue_struct *workqueue;
619 /* prevents concurrent FW reconfiguration */
620 struct mutex conf_mutex;
622 /* protects shared structure data */
623 spinlock_t data_lock;
625 struct list_head arvifs;
626 struct list_head peers;
627 wait_queue_head_t peer_mapping_wq;
629 /* protected by conf_mutex */
634 int max_num_stations;
637 struct work_struct offchan_tx_work;
638 struct sk_buff_head offchan_tx_queue;
639 struct completion offchan_tx_completed;
640 struct sk_buff *offchan_tx_skb;
642 struct work_struct wmi_mgmt_tx_work;
643 struct sk_buff_head wmi_mgmt_tx_queue;
645 enum ath10k_state state;
647 struct work_struct register_work;
648 struct work_struct restart_work;
650 /* cycle count is reported twice for each visited channel during scan.
651 * access protected by data_lock */
652 u32 survey_last_rx_clear_count;
653 u32 survey_last_cycle_count;
654 struct survey_info survey[ATH10K_NUM_CHANS];
656 struct dfs_pattern_detector *dfs_detector;
658 #ifdef CONFIG_ATH10K_DEBUGFS
659 struct ath10k_debug debug;
663 /* relay(fs) channel for spectral scan */
664 struct rchan *rfs_chan_spec_scan;
666 /* spectral_mode and spec_config are protected by conf_mutex */
667 enum ath10k_spectral_mode mode;
668 struct ath10k_spec_scan config;
672 /* protected by conf_mutex */
673 const struct firmware *utf;
674 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
675 enum ath10k_fw_wmi_op_version orig_wmi_op_version;
677 /* protected by data_lock */
682 /* protected by data_lock */
683 u32 fw_crash_counter;
684 u32 fw_warm_reset_counter;
685 u32 fw_cold_reset_counter;
688 struct ath10k_thermal thermal;
691 u8 drv_priv[0] __aligned(sizeof(void *));
694 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
696 enum ath10k_hw_rev hw_rev,
697 const struct ath10k_hif_ops *hif_ops);
698 void ath10k_core_destroy(struct ath10k *ar);
700 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
701 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
702 void ath10k_core_stop(struct ath10k *ar);
703 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
704 void ath10k_core_unregister(struct ath10k *ar);
706 #endif /* _CORE_H_ */