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_pdev {
163 struct list_head list;
196 u32 sw_retry_failure;
197 u32 illgl_rate_phy_err;
198 u32 pdev_cont_xretry;
205 s32 mid_ppdu_route_change;
221 struct ath10k_fw_stats {
222 struct list_head pdevs;
223 struct list_head peers;
226 struct ath10k_dfs_stats {
230 u32 pulses_discarded;
234 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
237 struct list_head list;
240 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
242 /* protected by ar->data_lock */
243 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
247 struct ath10k_vif *arvif;
249 /* the following are protected by ar->data_lock */
250 u32 changed; /* IEEE80211_RC_* */
255 struct work_struct update_wk;
257 #ifdef CONFIG_MAC80211_DEBUGFS
258 /* protected by conf_mutex */
263 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
265 enum ath10k_beacon_state {
266 ATH10K_BEACON_SCHEDULED = 0,
267 ATH10K_BEACON_SENDING,
272 struct list_head list;
275 enum wmi_vdev_type vdev_type;
276 enum wmi_vdev_subtype vdev_subtype;
279 struct sk_buff *beacon;
280 /* protected by data_lock */
281 enum ath10k_beacon_state beacon_state;
283 dma_addr_t beacon_paddr;
286 struct ieee80211_vif *vif;
290 bool spectral_enabled;
294 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
304 /* 127 stations; wmi limit */
308 u8 ssid[IEEE80211_MAX_SSID_LEN];
310 /* P2P_IE with NoA attribute for P2P_GO case */
320 int num_legacy_stations;
322 struct wmi_wmm_params_all_arg wmm_params;
325 struct ath10k_vif_iter {
327 struct ath10k_vif *arvif;
330 /* used for crash-dump storage, protected by data-lock */
331 struct ath10k_fw_crash_data {
332 bool crashed_since_read;
335 struct timespec timestamp;
336 __le32 registers[REG_DUMP_COUNT_QCA988X];
339 struct ath10k_debug {
340 struct dentry *debugfs_phy;
342 struct ath10k_fw_stats fw_stats;
343 struct completion fw_stats_complete;
346 unsigned long htt_stats_mask;
347 struct delayed_work htt_stats_dwork;
348 struct ath10k_dfs_stats dfs_stats;
349 struct ath_dfs_pool_stats dfs_pool_stats;
351 /* protected by conf_mutex */
361 struct ath10k_fw_crash_data *fw_crash_data;
365 ATH10K_STATE_OFF = 0,
368 /* When doing firmware recovery the device is first powered down.
369 * mac80211 is supposed to call in to start() hook later on. It is
370 * however possible that driver unloading and firmware crash overlap.
371 * mac80211 can wait on conf_mutex in stop() while the device is
372 * stopped in ath10k_core_restart() work holding conf_mutex. The state
373 * RESTARTED means that the device is up and mac80211 has started hw
374 * reconfiguration. Once mac80211 is done with the reconfiguration we
375 * set the state to STATE_ON in reconfig_complete(). */
376 ATH10K_STATE_RESTARTING,
377 ATH10K_STATE_RESTARTED,
379 /* The device has crashed while restarting hw. This state is like ON
380 * but commands are blocked in HTC and -ECOMM response is given. This
381 * prevents completion timeouts and makes the driver more responsive to
382 * userspace commands. This is also prevents recursive recovery. */
389 enum ath10k_firmware_mode {
390 /* the default mode, standard 802.11 functionality */
391 ATH10K_FIRMWARE_MODE_NORMAL,
393 /* factory tests etc */
394 ATH10K_FIRMWARE_MODE_UTF,
397 enum ath10k_fw_features {
398 /* wmi_mgmt_rx_hdr contains extra RSSI information */
399 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
401 /* Firmware from 10X branch. Deprecated, don't use in new code. */
402 ATH10K_FW_FEATURE_WMI_10X = 1,
404 /* firmware support tx frame management over WMI, otherwise it's HTT */
405 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
407 /* Firmware does not support P2P */
408 ATH10K_FW_FEATURE_NO_P2P = 3,
410 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature
411 * bit is required to be set as well. Deprecated, don't use in new
414 ATH10K_FW_FEATURE_WMI_10_2 = 4,
417 ATH10K_FW_FEATURE_COUNT,
420 enum ath10k_dev_flags {
421 /* Indicates that ath10k device is during CAC phase of DFS */
423 ATH10K_FLAG_CORE_REGISTERED,
425 /* Device has crashed and needs to restart. This indicates any pending
426 * waiters should immediately cancel instead of waiting for a time out.
428 ATH10K_FLAG_CRASH_FLUSH,
431 enum ath10k_cal_mode {
432 ATH10K_CAL_MODE_FILE,
437 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
440 case ATH10K_CAL_MODE_FILE:
442 case ATH10K_CAL_MODE_OTP:
444 case ATH10K_CAL_MODE_DT:
451 enum ath10k_scan_state {
453 ATH10K_SCAN_STARTING,
455 ATH10K_SCAN_ABORTING,
458 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
461 case ATH10K_SCAN_IDLE:
463 case ATH10K_SCAN_STARTING:
465 case ATH10K_SCAN_RUNNING:
467 case ATH10K_SCAN_ABORTING:
475 struct ath_common ath_common;
476 struct ieee80211_hw *hw;
478 u8 mac_addr[ETH_ALEN];
480 enum ath10k_hw_rev hw_rev;
484 u32 fw_version_minor;
485 u16 fw_version_release;
486 u16 fw_version_build;
494 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
500 const struct ath10k_hif_ops *ops;
503 struct completion target_suspend;
505 const struct ath10k_hw_regs *regs;
506 struct ath10k_bmi bmi;
507 struct ath10k_wmi wmi;
508 struct ath10k_htc htc;
509 struct ath10k_htt htt;
511 struct ath10k_hw_params {
517 struct ath10k_hw_params_fw {
523 size_t board_ext_size;
527 const struct firmware *board;
528 const void *board_data;
531 const struct firmware *otp;
532 const void *otp_data;
535 const struct firmware *firmware;
536 const void *firmware_data;
539 const struct firmware *cal_file;
542 enum ath10k_cal_mode cal_mode;
545 struct completion started;
546 struct completion completed;
547 struct completion on_channel;
548 struct delayed_work timeout;
549 enum ath10k_scan_state state;
556 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
559 /* should never be NULL; needed for regular htt rx */
560 struct ieee80211_channel *rx_channel;
562 /* valid during scan; needed for mgmt rx during scan */
563 struct ieee80211_channel *scan_channel;
565 /* current operating channel definition */
566 struct cfg80211_chan_def chandef;
568 unsigned long long free_vdev_map;
571 bool monitor_started;
572 unsigned int filter_flags;
573 unsigned long dev_flags;
574 u32 dfs_block_radar_events;
576 /* protected by conf_mutex */
578 int num_started_vdevs;
580 /* Protected by conf-mutex */
581 u8 supp_tx_chainmask;
582 u8 supp_rx_chainmask;
586 struct completion install_key_done;
588 struct completion vdev_setup_done;
590 struct workqueue_struct *workqueue;
592 /* prevents concurrent FW reconfiguration */
593 struct mutex conf_mutex;
595 /* protects shared structure data */
596 spinlock_t data_lock;
598 struct list_head arvifs;
599 struct list_head peers;
600 wait_queue_head_t peer_mapping_wq;
602 /* protected by conf_mutex */
607 int max_num_stations;
610 struct work_struct offchan_tx_work;
611 struct sk_buff_head offchan_tx_queue;
612 struct completion offchan_tx_completed;
613 struct sk_buff *offchan_tx_skb;
615 struct work_struct wmi_mgmt_tx_work;
616 struct sk_buff_head wmi_mgmt_tx_queue;
618 enum ath10k_state state;
620 struct work_struct register_work;
621 struct work_struct restart_work;
623 /* cycle count is reported twice for each visited channel during scan.
624 * access protected by data_lock */
625 u32 survey_last_rx_clear_count;
626 u32 survey_last_cycle_count;
627 struct survey_info survey[ATH10K_NUM_CHANS];
629 struct dfs_pattern_detector *dfs_detector;
631 #ifdef CONFIG_ATH10K_DEBUGFS
632 struct ath10k_debug debug;
636 /* relay(fs) channel for spectral scan */
637 struct rchan *rfs_chan_spec_scan;
639 /* spectral_mode and spec_config are protected by conf_mutex */
640 enum ath10k_spectral_mode mode;
641 struct ath10k_spec_scan config;
645 /* protected by conf_mutex */
646 const struct firmware *utf;
647 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
648 enum ath10k_fw_wmi_op_version orig_wmi_op_version;
650 /* protected by data_lock */
655 /* protected by data_lock */
656 u32 fw_crash_counter;
657 u32 fw_warm_reset_counter;
658 u32 fw_cold_reset_counter;
661 struct ath10k_thermal thermal;
664 u8 drv_priv[0] __aligned(sizeof(void *));
667 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
669 enum ath10k_hw_rev hw_rev,
670 const struct ath10k_hif_ops *hif_ops);
671 void ath10k_core_destroy(struct ath10k *ar);
673 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
674 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
675 void ath10k_core_stop(struct ath10k *ar);
676 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
677 void ath10k_core_unregister(struct ath10k *ar);
679 #endif /* _CORE_H_ */