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_CONNECTION_LOSS_HZ (3*HZ)
47 #define ATH10K_NUM_CHANS 38
49 /* Antenna noise floor */
50 #define ATH10K_DEFAULT_NOISE_FLOOR -95
52 #define ATH10K_MAX_NUM_MGMT_PENDING 128
54 /* number of failed packets */
55 #define ATH10K_KICKOUT_THRESHOLD 50
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
62 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
63 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
64 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
72 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
82 struct ath10k_skb_cb {
91 struct ath10k_htt_txbuf *txbuf;
101 struct ath10k_skb_rxcb {
103 struct hlist_node hlist;
106 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
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;
113 static inline struct ath10k_skb_rxcb *ATH10K_SKB_RXCB(struct sk_buff *skb)
115 BUILD_BUG_ON(sizeof(struct ath10k_skb_rxcb) > sizeof(skb->cb));
116 return (struct ath10k_skb_rxcb *)skb->cb;
119 #define ATH10K_RXCB_SKB(rxcb) \
120 container_of((void *)rxcb, struct sk_buff, cb)
122 static inline u32 host_interest_item_address(u32 item_offset)
124 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
131 struct ath10k_mem_chunk {
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;
151 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
154 struct ath10k_fw_stats_peer {
155 struct list_head list;
157 u8 peer_macaddr[ETH_ALEN];
160 u32 peer_rx_rate; /* 10x only */
163 struct ath10k_fw_stats_vdev {
164 struct list_head list;
169 u32 num_tx_frames[4];
171 u32 num_tx_frames_retries[4];
172 u32 num_tx_frames_failures[4];
177 u32 num_tx_not_acked;
178 u32 tx_rate_history[10];
179 u32 beacon_rssi_history[10];
182 struct ath10k_fw_stats_pdev {
183 struct list_head list;
216 u32 sw_retry_failure;
217 u32 illgl_rate_phy_err;
218 u32 pdev_cont_xretry;
225 s32 mid_ppdu_route_change;
241 struct ath10k_fw_stats {
242 struct list_head pdevs;
243 struct list_head vdevs;
244 struct list_head peers;
247 struct ath10k_dfs_stats {
251 u32 pulses_discarded;
255 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
258 struct list_head list;
261 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
263 /* protected by ar->data_lock */
264 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
268 struct ath10k_vif *arvif;
270 /* the following are protected by ar->data_lock */
271 u32 changed; /* IEEE80211_RC_* */
276 struct work_struct update_wk;
278 #ifdef CONFIG_MAC80211_DEBUGFS
279 /* protected by conf_mutex */
284 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
286 enum ath10k_beacon_state {
287 ATH10K_BEACON_SCHEDULED = 0,
288 ATH10K_BEACON_SENDING,
293 struct list_head list;
296 enum wmi_vdev_type vdev_type;
297 enum wmi_vdev_subtype vdev_subtype;
300 struct sk_buff *beacon;
301 /* protected by data_lock */
302 enum ath10k_beacon_state beacon_state;
304 dma_addr_t beacon_paddr;
307 struct ieee80211_vif *vif;
311 bool spectral_enabled;
316 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
326 /* 127 stations; wmi limit */
330 u8 ssid[IEEE80211_MAX_SSID_LEN];
332 /* P2P_IE with NoA attribute for P2P_GO case */
342 int num_legacy_stations;
344 struct wmi_wmm_params_all_arg wmm_params;
345 struct work_struct ap_csa_work;
346 struct delayed_work connection_loss_work;
349 struct ath10k_vif_iter {
351 struct ath10k_vif *arvif;
354 /* used for crash-dump storage, protected by data-lock */
355 struct ath10k_fw_crash_data {
356 bool crashed_since_read;
359 struct timespec timestamp;
360 __le32 registers[REG_DUMP_COUNT_QCA988X];
363 struct ath10k_debug {
364 struct dentry *debugfs_phy;
366 struct ath10k_fw_stats fw_stats;
367 struct completion fw_stats_complete;
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;
375 /* protected by conf_mutex */
385 struct ath10k_fw_crash_data *fw_crash_data;
389 ATH10K_STATE_OFF = 0,
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,
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. */
413 enum ath10k_firmware_mode {
414 /* the default mode, standard 802.11 functionality */
415 ATH10K_FIRMWARE_MODE_NORMAL,
417 /* factory tests etc */
418 ATH10K_FIRMWARE_MODE_UTF,
421 enum ath10k_fw_features {
422 /* wmi_mgmt_rx_hdr contains extra RSSI information */
423 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
425 /* Firmware from 10X branch. Deprecated, don't use in new code. */
426 ATH10K_FW_FEATURE_WMI_10X = 1,
428 /* firmware support tx frame management over WMI, otherwise it's HTT */
429 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
431 /* Firmware does not support P2P */
432 ATH10K_FW_FEATURE_NO_P2P = 3,
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
438 ATH10K_FW_FEATURE_WMI_10_2 = 4,
440 /* Some firmware revisions lack proper multi-interface client powersave
441 * implementation. Enabling PS could result in connection drops,
442 * traffic stalls, etc.
444 ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT = 5,
447 ATH10K_FW_FEATURE_COUNT,
450 enum ath10k_dev_flags {
451 /* Indicates that ath10k device is during CAC phase of DFS */
453 ATH10K_FLAG_CORE_REGISTERED,
455 /* Device has crashed and needs to restart. This indicates any pending
456 * waiters should immediately cancel instead of waiting for a time out.
458 ATH10K_FLAG_CRASH_FLUSH,
461 enum ath10k_cal_mode {
462 ATH10K_CAL_MODE_FILE,
467 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
470 case ATH10K_CAL_MODE_FILE:
472 case ATH10K_CAL_MODE_OTP:
474 case ATH10K_CAL_MODE_DT:
481 enum ath10k_scan_state {
483 ATH10K_SCAN_STARTING,
485 ATH10K_SCAN_ABORTING,
488 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
491 case ATH10K_SCAN_IDLE:
493 case ATH10K_SCAN_STARTING:
495 case ATH10K_SCAN_RUNNING:
497 case ATH10K_SCAN_ABORTING:
505 struct ath_common ath_common;
506 struct ieee80211_hw *hw;
508 u8 mac_addr[ETH_ALEN];
510 enum ath10k_hw_rev hw_rev;
514 u32 fw_version_minor;
515 u16 fw_version_release;
516 u16 fw_version_build;
524 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
530 const struct ath10k_hif_ops *ops;
533 struct completion target_suspend;
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;
541 struct ath10k_hw_params {
547 struct ath10k_hw_params_fw {
553 size_t board_ext_size;
557 const struct firmware *board;
558 const void *board_data;
561 const struct firmware *otp;
562 const void *otp_data;
565 const struct firmware *firmware;
566 const void *firmware_data;
569 const struct firmware *cal_file;
572 enum ath10k_cal_mode cal_mode;
575 struct completion started;
576 struct completion completed;
577 struct completion on_channel;
578 struct delayed_work timeout;
579 enum ath10k_scan_state state;
586 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
589 /* should never be NULL; needed for regular htt rx */
590 struct ieee80211_channel *rx_channel;
592 /* valid during scan; needed for mgmt rx during scan */
593 struct ieee80211_channel *scan_channel;
595 /* current operating channel definition */
596 struct cfg80211_chan_def chandef;
598 unsigned long long free_vdev_map;
601 bool monitor_started;
602 unsigned int filter_flags;
603 unsigned long dev_flags;
604 u32 dfs_block_radar_events;
606 /* protected by conf_mutex */
608 int num_started_vdevs;
610 /* Protected by conf-mutex */
611 u8 supp_tx_chainmask;
612 u8 supp_rx_chainmask;
616 struct completion install_key_done;
618 struct completion vdev_setup_done;
620 struct workqueue_struct *workqueue;
622 /* prevents concurrent FW reconfiguration */
623 struct mutex conf_mutex;
625 /* protects shared structure data */
626 spinlock_t data_lock;
628 struct list_head arvifs;
629 struct list_head peers;
630 wait_queue_head_t peer_mapping_wq;
632 /* protected by conf_mutex */
637 int max_num_stations;
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;
645 struct work_struct wmi_mgmt_tx_work;
646 struct sk_buff_head wmi_mgmt_tx_queue;
648 enum ath10k_state state;
650 struct work_struct register_work;
651 struct work_struct restart_work;
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];
659 struct dfs_pattern_detector *dfs_detector;
661 #ifdef CONFIG_ATH10K_DEBUGFS
662 struct ath10k_debug debug;
666 /* relay(fs) channel for spectral scan */
667 struct rchan *rfs_chan_spec_scan;
669 /* spectral_mode and spec_config are protected by conf_mutex */
670 enum ath10k_spectral_mode mode;
671 struct ath10k_spec_scan config;
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;
680 /* protected by data_lock */
685 /* protected by data_lock */
686 u32 fw_crash_counter;
687 u32 fw_warm_reset_counter;
688 u32 fw_cold_reset_counter;
691 struct ath10k_thermal thermal;
694 u8 drv_priv[0] __aligned(sizeof(void *));
697 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
699 enum ath10k_hw_rev hw_rev,
700 const struct ath10k_hif_ops *hif_ops);
701 void ath10k_core_destroy(struct ath10k *ar);
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);
709 #endif /* _CORE_H_ */