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"
38 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
39 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
40 #define WO(_f) ((_f##_OFFSET) >> 2)
42 #define ATH10K_SCAN_ID 0
43 #define WMI_READY_TIMEOUT (5 * HZ)
44 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
45 #define ATH10K_NUM_CHANS 38
47 /* Antenna noise floor */
48 #define ATH10K_DEFAULT_NOISE_FLOOR -95
50 #define ATH10K_MAX_NUM_MGMT_PENDING 128
52 /* number of failed packets */
53 #define ATH10K_KICKOUT_THRESHOLD 50
56 * Use insanely high numbers to make sure that the firmware implementation
57 * won't start, we have the same functionality already in hostapd. Unit
60 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
61 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
62 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
70 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
80 struct ath10k_skb_cb {
87 struct ath10k_htt_txbuf *txbuf;
97 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
99 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
100 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
101 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
104 static inline u32 host_interest_item_address(u32 item_offset)
106 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
113 struct ath10k_mem_chunk {
121 enum ath10k_htc_ep_id eid;
122 struct completion service_ready;
123 struct completion unified_ready;
124 wait_queue_head_t tx_credits_wq;
125 struct wmi_cmd_map *cmd;
126 struct wmi_vdev_param_map *vdev_param;
127 struct wmi_pdev_param_map *pdev_param;
130 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
133 struct ath10k_fw_stats_peer {
134 struct list_head list;
136 u8 peer_macaddr[ETH_ALEN];
139 u32 peer_rx_rate; /* 10x only */
142 struct ath10k_fw_stats_pdev {
143 struct list_head list;
176 u32 sw_retry_failure;
177 u32 illgl_rate_phy_err;
178 u32 pdev_cont_xretry;
185 s32 mid_ppdu_route_change;
201 struct ath10k_fw_stats {
202 struct list_head pdevs;
203 struct list_head peers;
206 struct ath10k_dfs_stats {
210 u32 pulses_discarded;
214 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
217 struct list_head list;
220 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
221 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
225 struct ath10k_vif *arvif;
227 /* the following are protected by ar->data_lock */
228 u32 changed; /* IEEE80211_RC_* */
233 struct work_struct update_wk;
236 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
239 struct list_head list;
242 enum wmi_vdev_type vdev_type;
243 enum wmi_vdev_subtype vdev_subtype;
246 struct sk_buff *beacon;
247 /* protected by data_lock */
250 dma_addr_t beacon_paddr;
253 struct ieee80211_vif *vif;
257 bool spectral_enabled;
261 struct work_struct wep_key_work;
262 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
264 u8 def_wep_key_newidx;
273 /* 127 stations; wmi limit */
277 u8 ssid[IEEE80211_MAX_SSID_LEN];
279 /* P2P_IE with NoA attribute for P2P_GO case */
289 int num_legacy_stations;
293 struct ath10k_vif_iter {
295 struct ath10k_vif *arvif;
298 /* used for crash-dump storage, protected by data-lock */
299 struct ath10k_fw_crash_data {
300 bool crashed_since_read;
303 struct timespec timestamp;
304 __le32 registers[REG_DUMP_COUNT_QCA988X];
307 struct ath10k_debug {
308 struct dentry *debugfs_phy;
310 struct ath10k_fw_stats fw_stats;
311 struct completion fw_stats_complete;
313 DECLARE_BITMAP(wmi_service_bitmap, WMI_SERVICE_MAX);
315 unsigned long htt_stats_mask;
316 struct delayed_work htt_stats_dwork;
317 struct ath10k_dfs_stats dfs_stats;
318 struct ath_dfs_pool_stats dfs_pool_stats;
320 /* protected by conf_mutex */
327 struct ath10k_fw_crash_data *fw_crash_data;
331 ATH10K_STATE_OFF = 0,
334 /* When doing firmware recovery the device is first powered down.
335 * mac80211 is supposed to call in to start() hook later on. It is
336 * however possible that driver unloading and firmware crash overlap.
337 * mac80211 can wait on conf_mutex in stop() while the device is
338 * stopped in ath10k_core_restart() work holding conf_mutex. The state
339 * RESTARTED means that the device is up and mac80211 has started hw
340 * reconfiguration. Once mac80211 is done with the reconfiguration we
341 * set the state to STATE_ON in reconfig_complete(). */
342 ATH10K_STATE_RESTARTING,
343 ATH10K_STATE_RESTARTED,
345 /* The device has crashed while restarting hw. This state is like ON
346 * but commands are blocked in HTC and -ECOMM response is given. This
347 * prevents completion timeouts and makes the driver more responsive to
348 * userspace commands. This is also prevents recursive recovery. */
355 enum ath10k_firmware_mode {
356 /* the default mode, standard 802.11 functionality */
357 ATH10K_FIRMWARE_MODE_NORMAL,
359 /* factory tests etc */
360 ATH10K_FIRMWARE_MODE_UTF,
363 enum ath10k_fw_features {
364 /* wmi_mgmt_rx_hdr contains extra RSSI information */
365 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
367 /* firmware from 10X branch */
368 ATH10K_FW_FEATURE_WMI_10X = 1,
370 /* firmware support tx frame management over WMI, otherwise it's HTT */
371 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
373 /* Firmware does not support P2P */
374 ATH10K_FW_FEATURE_NO_P2P = 3,
376 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature bit
377 * is required to be set as well.
379 ATH10K_FW_FEATURE_WMI_10_2 = 4,
382 ATH10K_FW_FEATURE_COUNT,
385 enum ath10k_dev_flags {
386 /* Indicates that ath10k device is during CAC phase of DFS */
388 ATH10K_FLAG_CORE_REGISTERED,
390 /* Device has crashed and needs to restart. This indicates any pending
391 * waiters should immediately cancel instead of waiting for a time out.
393 ATH10K_FLAG_CRASH_FLUSH,
396 enum ath10k_cal_mode {
397 ATH10K_CAL_MODE_FILE,
401 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
404 case ATH10K_CAL_MODE_FILE:
406 case ATH10K_CAL_MODE_OTP:
413 enum ath10k_scan_state {
415 ATH10K_SCAN_STARTING,
417 ATH10K_SCAN_ABORTING,
420 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
423 case ATH10K_SCAN_IDLE:
425 case ATH10K_SCAN_STARTING:
427 case ATH10K_SCAN_RUNNING:
429 case ATH10K_SCAN_ABORTING:
437 struct ath_common ath_common;
438 struct ieee80211_hw *hw;
440 u8 mac_addr[ETH_ALEN];
445 u32 fw_version_minor;
446 u16 fw_version_release;
447 u16 fw_version_build;
455 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
457 struct targetdef *targetdef;
458 struct hostdef *hostdef;
464 const struct ath10k_hif_ops *ops;
467 struct completion target_suspend;
469 struct ath10k_bmi bmi;
470 struct ath10k_wmi wmi;
471 struct ath10k_htc htc;
472 struct ath10k_htt htt;
474 struct ath10k_hw_params {
479 struct ath10k_hw_params_fw {
487 const struct firmware *board;
488 const void *board_data;
491 const struct firmware *otp;
492 const void *otp_data;
495 const struct firmware *firmware;
496 const void *firmware_data;
499 const struct firmware *cal_file;
502 enum ath10k_cal_mode cal_mode;
505 struct completion started;
506 struct completion completed;
507 struct completion on_channel;
508 struct delayed_work timeout;
509 enum ath10k_scan_state state;
516 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
519 /* should never be NULL; needed for regular htt rx */
520 struct ieee80211_channel *rx_channel;
522 /* valid during scan; needed for mgmt rx during scan */
523 struct ieee80211_channel *scan_channel;
525 /* current operating channel definition */
526 struct cfg80211_chan_def chandef;
528 unsigned long long free_vdev_map;
531 bool monitor_started;
532 unsigned int filter_flags;
533 unsigned long dev_flags;
534 u32 dfs_block_radar_events;
536 /* protected by conf_mutex */
538 int num_started_vdevs;
540 /* Protected by conf-mutex */
541 u8 supp_tx_chainmask;
542 u8 supp_rx_chainmask;
546 struct wmi_pdev_set_wmm_params_arg wmm_params;
547 struct completion install_key_done;
549 struct completion vdev_setup_done;
551 struct workqueue_struct *workqueue;
553 /* prevents concurrent FW reconfiguration */
554 struct mutex conf_mutex;
556 /* protects shared structure data */
557 spinlock_t data_lock;
559 struct list_head arvifs;
560 struct list_head peers;
561 wait_queue_head_t peer_mapping_wq;
563 /* number of created peers; protected by data_lock */
566 struct work_struct offchan_tx_work;
567 struct sk_buff_head offchan_tx_queue;
568 struct completion offchan_tx_completed;
569 struct sk_buff *offchan_tx_skb;
571 struct work_struct wmi_mgmt_tx_work;
572 struct sk_buff_head wmi_mgmt_tx_queue;
574 enum ath10k_state state;
576 struct work_struct register_work;
577 struct work_struct restart_work;
579 /* cycle count is reported twice for each visited channel during scan.
580 * access protected by data_lock */
581 u32 survey_last_rx_clear_count;
582 u32 survey_last_cycle_count;
583 struct survey_info survey[ATH10K_NUM_CHANS];
585 struct dfs_pattern_detector *dfs_detector;
587 #ifdef CONFIG_ATH10K_DEBUGFS
588 struct ath10k_debug debug;
592 /* relay(fs) channel for spectral scan */
593 struct rchan *rfs_chan_spec_scan;
595 /* spectral_mode and spec_config are protected by conf_mutex */
596 enum ath10k_spectral_mode mode;
597 struct ath10k_spec_scan config;
601 /* protected by conf_mutex */
602 const struct firmware *utf;
603 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
605 /* protected by data_lock */
610 /* protected by data_lock */
611 u32 fw_crash_counter;
612 u32 fw_warm_reset_counter;
613 u32 fw_cold_reset_counter;
617 u8 drv_priv[0] __aligned(sizeof(void *));
620 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
622 const struct ath10k_hif_ops *hif_ops);
623 void ath10k_core_destroy(struct ath10k *ar);
625 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
626 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
627 void ath10k_core_stop(struct ath10k *ar);
628 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
629 void ath10k_core_unregister(struct ath10k *ar);
631 #endif /* _CORE_H_ */