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>
29 #include "targaddrs.h"
33 #include "../dfs_pattern_detector.h"
36 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
37 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
38 #define WO(_f) ((_f##_OFFSET) >> 2)
40 #define ATH10K_SCAN_ID 0
41 #define WMI_READY_TIMEOUT (5 * HZ)
42 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
43 #define ATH10K_NUM_CHANS 38
45 /* Antenna noise floor */
46 #define ATH10K_DEFAULT_NOISE_FLOOR -95
48 #define ATH10K_MAX_NUM_MGMT_PENDING 128
50 /* number of failed packets */
51 #define ATH10K_KICKOUT_THRESHOLD 50
54 * Use insanely high numbers to make sure that the firmware implementation
55 * won't start, we have the same functionality already in hostapd. Unit
58 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
59 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
60 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
64 struct ath10k_skb_cb {
71 struct ath10k_htt_txbuf *txbuf;
81 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
83 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
84 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
85 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
88 static inline u32 host_interest_item_address(u32 item_offset)
90 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
97 #define ATH10K_MAX_MEM_REQS 16
99 struct ath10k_mem_chunk {
107 enum ath10k_htc_ep_id eid;
108 struct completion service_ready;
109 struct completion unified_ready;
110 wait_queue_head_t tx_credits_wq;
111 struct wmi_cmd_map *cmd;
112 struct wmi_vdev_param_map *vdev_param;
113 struct wmi_pdev_param_map *pdev_param;
116 struct ath10k_mem_chunk mem_chunks[ATH10K_MAX_MEM_REQS];
119 struct ath10k_peer_stat {
120 u8 peer_macaddr[ETH_ALEN];
123 u32 peer_rx_rate; /* 10x only */
126 struct ath10k_target_stats {
158 u32 sw_retry_failure;
159 u32 illgl_rate_phy_err;
160 u32 pdev_cont_xretry;
167 s32 mid_ppdu_route_change;
186 struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
188 /* TODO: Beacon filter stats */
192 struct ath10k_dfs_stats {
196 u32 pulses_discarded;
200 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
203 struct list_head list;
206 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
207 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
211 struct ath10k_vif *arvif;
213 /* the following are protected by ar->data_lock */
214 u32 changed; /* IEEE80211_RC_* */
219 struct work_struct update_wk;
222 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
225 struct list_head list;
228 enum wmi_vdev_type vdev_type;
229 enum wmi_vdev_subtype vdev_subtype;
232 struct sk_buff *beacon;
233 /* protected by data_lock */
237 struct ieee80211_vif *vif;
241 bool spectral_enabled;
245 struct work_struct wep_key_work;
246 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
248 u8 def_wep_key_newidx;
257 /* 127 stations; wmi limit */
261 u8 ssid[IEEE80211_MAX_SSID_LEN];
263 /* P2P_IE with NoA attribute for P2P_GO case */
273 int num_legacy_stations;
276 struct ath10k_vif_iter {
278 struct ath10k_vif *arvif;
281 struct ath10k_debug {
282 struct dentry *debugfs_phy;
284 struct ath10k_target_stats target_stats;
285 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
287 struct completion event_stats_compl;
289 unsigned long htt_stats_mask;
290 struct delayed_work htt_stats_dwork;
291 struct ath10k_dfs_stats dfs_stats;
292 struct ath_dfs_pool_stats dfs_pool_stats;
301 ATH10K_STATE_OFF = 0,
304 /* When doing firmware recovery the device is first powered down.
305 * mac80211 is supposed to call in to start() hook later on. It is
306 * however possible that driver unloading and firmware crash overlap.
307 * mac80211 can wait on conf_mutex in stop() while the device is
308 * stopped in ath10k_core_restart() work holding conf_mutex. The state
309 * RESTARTED means that the device is up and mac80211 has started hw
310 * reconfiguration. Once mac80211 is done with the reconfiguration we
311 * set the state to STATE_ON in restart_complete(). */
312 ATH10K_STATE_RESTARTING,
313 ATH10K_STATE_RESTARTED,
315 /* The device has crashed while restarting hw. This state is like ON
316 * but commands are blocked in HTC and -ECOMM response is given. This
317 * prevents completion timeouts and makes the driver more responsive to
318 * userspace commands. This is also prevents recursive recovery. */
322 enum ath10k_fw_features {
323 /* wmi_mgmt_rx_hdr contains extra RSSI information */
324 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
326 /* firmware from 10X branch */
327 ATH10K_FW_FEATURE_WMI_10X = 1,
329 /* firmware support tx frame management over WMI, otherwise it's HTT */
330 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
332 /* Firmware does not support P2P */
333 ATH10K_FW_FEATURE_NO_P2P = 3,
335 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature bit
336 * is required to be set as well.
338 ATH10K_FW_FEATURE_WMI_10_2 = 4,
341 ATH10K_FW_FEATURE_COUNT,
344 enum ath10k_dev_flags {
345 /* Indicates that ath10k device is during CAC phase of DFS */
347 ATH10K_FLAG_FIRST_BOOT_DONE,
348 ATH10K_FLAG_CORE_REGISTERED,
352 struct ath_common ath_common;
353 struct ieee80211_hw *hw;
355 u8 mac_addr[ETH_ALEN];
360 u32 fw_version_minor;
361 u16 fw_version_release;
362 u16 fw_version_build;
370 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
372 struct targetdef *targetdef;
373 struct hostdef *hostdef;
379 const struct ath10k_hif_ops *ops;
382 struct completion target_suspend;
384 struct ath10k_bmi bmi;
385 struct ath10k_wmi wmi;
386 struct ath10k_htc htc;
387 struct ath10k_htt htt;
389 struct ath10k_hw_params {
394 struct ath10k_hw_params_fw {
402 const struct firmware *board;
403 const void *board_data;
406 const struct firmware *otp;
407 const void *otp_data;
410 const struct firmware *firmware;
411 const void *firmware_data;
417 struct completion started;
418 struct completion completed;
419 struct completion on_channel;
420 struct timer_list timeout;
429 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
432 /* should never be NULL; needed for regular htt rx */
433 struct ieee80211_channel *rx_channel;
435 /* valid during scan; needed for mgmt rx during scan */
436 struct ieee80211_channel *scan_channel;
438 /* current operating channel definition */
439 struct cfg80211_chan_def chandef;
445 bool monitor_started;
446 unsigned int filter_flags;
447 unsigned long dev_flags;
448 u32 dfs_block_radar_events;
450 /* protected by conf_mutex */
452 int num_started_vdevs;
454 /* Protected by conf-mutex */
455 u8 supp_tx_chainmask;
456 u8 supp_rx_chainmask;
460 struct wmi_pdev_set_wmm_params_arg wmm_params;
461 struct completion install_key_done;
463 struct completion vdev_setup_done;
465 struct workqueue_struct *workqueue;
467 /* prevents concurrent FW reconfiguration */
468 struct mutex conf_mutex;
470 /* protects shared structure data */
471 spinlock_t data_lock;
473 struct list_head arvifs;
474 struct list_head peers;
475 wait_queue_head_t peer_mapping_wq;
477 /* number of created peers; protected by data_lock */
480 struct work_struct offchan_tx_work;
481 struct sk_buff_head offchan_tx_queue;
482 struct completion offchan_tx_completed;
483 struct sk_buff *offchan_tx_skb;
485 struct work_struct wmi_mgmt_tx_work;
486 struct sk_buff_head wmi_mgmt_tx_queue;
488 enum ath10k_state state;
490 struct work_struct register_work;
491 struct work_struct restart_work;
493 /* cycle count is reported twice for each visited channel during scan.
494 * access protected by data_lock */
495 u32 survey_last_rx_clear_count;
496 u32 survey_last_cycle_count;
497 struct survey_info survey[ATH10K_NUM_CHANS];
499 struct dfs_pattern_detector *dfs_detector;
501 #ifdef CONFIG_ATH10K_DEBUGFS
502 struct ath10k_debug debug;
506 /* relay(fs) channel for spectral scan */
507 struct rchan *rfs_chan_spec_scan;
509 /* spectral_mode and spec_config are protected by conf_mutex */
510 enum ath10k_spectral_mode mode;
511 struct ath10k_spec_scan config;
515 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
516 const struct ath10k_hif_ops *hif_ops);
517 void ath10k_core_destroy(struct ath10k *ar);
519 int ath10k_core_start(struct ath10k *ar);
520 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
521 void ath10k_core_stop(struct ath10k *ar);
522 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
523 void ath10k_core_unregister(struct ath10k *ar);
525 #endif /* _CORE_H_ */