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 {
88 struct ath10k_htt_txbuf *txbuf;
98 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
100 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
101 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
102 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
105 static inline u32 host_interest_item_address(u32 item_offset)
107 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
114 struct ath10k_mem_chunk {
122 enum ath10k_htc_ep_id eid;
123 struct completion service_ready;
124 struct completion unified_ready;
125 wait_queue_head_t tx_credits_wq;
126 struct wmi_cmd_map *cmd;
127 struct wmi_vdev_param_map *vdev_param;
128 struct wmi_pdev_param_map *pdev_param;
131 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
134 struct ath10k_fw_stats_peer {
135 struct list_head list;
137 u8 peer_macaddr[ETH_ALEN];
140 u32 peer_rx_rate; /* 10x only */
143 struct ath10k_fw_stats_pdev {
144 struct list_head list;
177 u32 sw_retry_failure;
178 u32 illgl_rate_phy_err;
179 u32 pdev_cont_xretry;
186 s32 mid_ppdu_route_change;
202 struct ath10k_fw_stats {
203 struct list_head pdevs;
204 struct list_head peers;
207 struct ath10k_dfs_stats {
211 u32 pulses_discarded;
215 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
218 struct list_head list;
221 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
223 /* protected by ar->data_lock */
224 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
228 struct ath10k_vif *arvif;
230 /* the following are protected by ar->data_lock */
231 u32 changed; /* IEEE80211_RC_* */
236 struct work_struct update_wk;
239 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
242 struct list_head list;
245 enum wmi_vdev_type vdev_type;
246 enum wmi_vdev_subtype vdev_subtype;
249 struct sk_buff *beacon;
250 /* protected by data_lock */
253 dma_addr_t beacon_paddr;
256 struct ieee80211_vif *vif;
260 bool spectral_enabled;
264 struct work_struct wep_key_work;
265 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
267 u8 def_wep_key_newidx;
276 /* 127 stations; wmi limit */
280 u8 ssid[IEEE80211_MAX_SSID_LEN];
282 /* P2P_IE with NoA attribute for P2P_GO case */
292 int num_legacy_stations;
296 struct ath10k_vif_iter {
298 struct ath10k_vif *arvif;
301 /* used for crash-dump storage, protected by data-lock */
302 struct ath10k_fw_crash_data {
303 bool crashed_since_read;
306 struct timespec timestamp;
307 __le32 registers[REG_DUMP_COUNT_QCA988X];
310 struct ath10k_debug {
311 struct dentry *debugfs_phy;
313 struct ath10k_fw_stats fw_stats;
314 struct completion fw_stats_complete;
316 DECLARE_BITMAP(wmi_service_bitmap, WMI_SERVICE_MAX);
318 unsigned long htt_stats_mask;
319 struct delayed_work htt_stats_dwork;
320 struct ath10k_dfs_stats dfs_stats;
321 struct ath_dfs_pool_stats dfs_pool_stats;
323 /* protected by conf_mutex */
331 struct ath10k_fw_crash_data *fw_crash_data;
335 ATH10K_STATE_OFF = 0,
338 /* When doing firmware recovery the device is first powered down.
339 * mac80211 is supposed to call in to start() hook later on. It is
340 * however possible that driver unloading and firmware crash overlap.
341 * mac80211 can wait on conf_mutex in stop() while the device is
342 * stopped in ath10k_core_restart() work holding conf_mutex. The state
343 * RESTARTED means that the device is up and mac80211 has started hw
344 * reconfiguration. Once mac80211 is done with the reconfiguration we
345 * set the state to STATE_ON in reconfig_complete(). */
346 ATH10K_STATE_RESTARTING,
347 ATH10K_STATE_RESTARTED,
349 /* The device has crashed while restarting hw. This state is like ON
350 * but commands are blocked in HTC and -ECOMM response is given. This
351 * prevents completion timeouts and makes the driver more responsive to
352 * userspace commands. This is also prevents recursive recovery. */
359 enum ath10k_firmware_mode {
360 /* the default mode, standard 802.11 functionality */
361 ATH10K_FIRMWARE_MODE_NORMAL,
363 /* factory tests etc */
364 ATH10K_FIRMWARE_MODE_UTF,
367 enum ath10k_fw_features {
368 /* wmi_mgmt_rx_hdr contains extra RSSI information */
369 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
371 /* firmware from 10X branch */
372 ATH10K_FW_FEATURE_WMI_10X = 1,
374 /* firmware support tx frame management over WMI, otherwise it's HTT */
375 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
377 /* Firmware does not support P2P */
378 ATH10K_FW_FEATURE_NO_P2P = 3,
380 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature bit
381 * is required to be set as well.
383 ATH10K_FW_FEATURE_WMI_10_2 = 4,
386 ATH10K_FW_FEATURE_COUNT,
389 enum ath10k_dev_flags {
390 /* Indicates that ath10k device is during CAC phase of DFS */
392 ATH10K_FLAG_CORE_REGISTERED,
394 /* Device has crashed and needs to restart. This indicates any pending
395 * waiters should immediately cancel instead of waiting for a time out.
397 ATH10K_FLAG_CRASH_FLUSH,
400 enum ath10k_cal_mode {
401 ATH10K_CAL_MODE_FILE,
405 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
408 case ATH10K_CAL_MODE_FILE:
410 case ATH10K_CAL_MODE_OTP:
417 enum ath10k_scan_state {
419 ATH10K_SCAN_STARTING,
421 ATH10K_SCAN_ABORTING,
424 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
427 case ATH10K_SCAN_IDLE:
429 case ATH10K_SCAN_STARTING:
431 case ATH10K_SCAN_RUNNING:
433 case ATH10K_SCAN_ABORTING:
441 struct ath_common ath_common;
442 struct ieee80211_hw *hw;
444 u8 mac_addr[ETH_ALEN];
449 u32 fw_version_minor;
450 u16 fw_version_release;
451 u16 fw_version_build;
459 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
461 struct targetdef *targetdef;
462 struct hostdef *hostdef;
468 const struct ath10k_hif_ops *ops;
471 struct completion target_suspend;
473 struct ath10k_bmi bmi;
474 struct ath10k_wmi wmi;
475 struct ath10k_htc htc;
476 struct ath10k_htt htt;
478 struct ath10k_hw_params {
483 struct ath10k_hw_params_fw {
491 const struct firmware *board;
492 const void *board_data;
495 const struct firmware *otp;
496 const void *otp_data;
499 const struct firmware *firmware;
500 const void *firmware_data;
503 const struct firmware *cal_file;
506 enum ath10k_cal_mode cal_mode;
509 struct completion started;
510 struct completion completed;
511 struct completion on_channel;
512 struct delayed_work timeout;
513 enum ath10k_scan_state state;
520 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
523 /* should never be NULL; needed for regular htt rx */
524 struct ieee80211_channel *rx_channel;
526 /* valid during scan; needed for mgmt rx during scan */
527 struct ieee80211_channel *scan_channel;
529 /* current operating channel definition */
530 struct cfg80211_chan_def chandef;
532 unsigned long long free_vdev_map;
535 bool monitor_started;
536 unsigned int filter_flags;
537 unsigned long dev_flags;
538 u32 dfs_block_radar_events;
540 /* protected by conf_mutex */
542 int num_started_vdevs;
544 /* Protected by conf-mutex */
545 u8 supp_tx_chainmask;
546 u8 supp_rx_chainmask;
550 struct wmi_pdev_set_wmm_params_arg wmm_params;
551 struct completion install_key_done;
553 struct completion vdev_setup_done;
555 struct workqueue_struct *workqueue;
557 /* prevents concurrent FW reconfiguration */
558 struct mutex conf_mutex;
560 /* protects shared structure data */
561 spinlock_t data_lock;
563 struct list_head arvifs;
564 struct list_head peers;
565 wait_queue_head_t peer_mapping_wq;
567 /* number of created peers; protected by data_lock */
570 struct work_struct offchan_tx_work;
571 struct sk_buff_head offchan_tx_queue;
572 struct completion offchan_tx_completed;
573 struct sk_buff *offchan_tx_skb;
575 struct work_struct wmi_mgmt_tx_work;
576 struct sk_buff_head wmi_mgmt_tx_queue;
578 enum ath10k_state state;
580 struct work_struct register_work;
581 struct work_struct restart_work;
583 /* cycle count is reported twice for each visited channel during scan.
584 * access protected by data_lock */
585 u32 survey_last_rx_clear_count;
586 u32 survey_last_cycle_count;
587 struct survey_info survey[ATH10K_NUM_CHANS];
589 struct dfs_pattern_detector *dfs_detector;
591 #ifdef CONFIG_ATH10K_DEBUGFS
592 struct ath10k_debug debug;
596 /* relay(fs) channel for spectral scan */
597 struct rchan *rfs_chan_spec_scan;
599 /* spectral_mode and spec_config are protected by conf_mutex */
600 enum ath10k_spectral_mode mode;
601 struct ath10k_spec_scan config;
605 /* protected by conf_mutex */
606 const struct firmware *utf;
607 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
609 /* protected by data_lock */
614 /* protected by data_lock */
615 u32 fw_crash_counter;
616 u32 fw_warm_reset_counter;
617 u32 fw_cold_reset_counter;
621 u8 drv_priv[0] __aligned(sizeof(void *));
624 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
626 const struct ath10k_hif_ops *hif_ops);
627 void ath10k_core_destroy(struct ath10k *ar);
629 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
630 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
631 void ath10k_core_stop(struct ath10k *ar);
632 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
633 void ath10k_core_unregister(struct ath10k *ar);
635 #endif /* _CORE_H_ */