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"
34 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
35 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
36 #define WO(_f) ((_f##_OFFSET) >> 2)
38 #define ATH10K_SCAN_ID 0
39 #define WMI_READY_TIMEOUT (5 * HZ)
40 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
41 #define ATH10K_NUM_CHANS 38
43 /* Antenna noise floor */
44 #define ATH10K_DEFAULT_NOISE_FLOOR -95
46 #define ATH10K_MAX_NUM_MGMT_PENDING 16
50 struct ath10k_skb_cb {
65 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
67 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
68 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
69 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
72 static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
74 if (ATH10K_SKB_CB(skb)->is_mapped)
77 ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
80 if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
83 ATH10K_SKB_CB(skb)->is_mapped = true;
87 static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
89 if (!ATH10K_SKB_CB(skb)->is_mapped)
92 dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
94 ATH10K_SKB_CB(skb)->is_mapped = false;
98 static inline u32 host_interest_item_address(u32 item_offset)
100 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
107 #define ATH10K_MAX_MEM_REQS 16
109 struct ath10k_mem_chunk {
117 enum ath10k_htc_ep_id eid;
118 struct completion service_ready;
119 struct completion unified_ready;
120 wait_queue_head_t tx_credits_wq;
121 struct wmi_cmd_map *cmd;
122 struct wmi_vdev_param_map *vdev_param;
123 struct wmi_pdev_param_map *pdev_param;
126 struct ath10k_mem_chunk mem_chunks[ATH10K_MAX_MEM_REQS];
129 struct ath10k_peer_stat {
130 u8 peer_macaddr[ETH_ALEN];
135 struct ath10k_target_stats {
161 u32 sw_retry_failure;
162 u32 illgl_rate_phy_err;
163 u32 pdev_cont_xretry;
170 s32 mid_ppdu_route_change;
189 struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
191 /* TODO: Beacon filter stats */
195 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
198 struct list_head list;
201 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
202 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
205 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
209 enum wmi_vdev_type vdev_type;
210 enum wmi_vdev_subtype vdev_subtype;
213 struct sk_buff *beacon;
216 struct ieee80211_vif *vif;
218 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
219 u8 def_wep_key_index;
229 /* 127 stations; wmi limit */
233 u8 ssid[IEEE80211_MAX_SSID_LEN];
235 /* P2P_IE with NoA attribute for P2P_GO case */
245 struct ath10k_vif_iter {
247 struct ath10k_vif *arvif;
250 struct ath10k_debug {
251 struct dentry *debugfs_phy;
253 struct ath10k_target_stats target_stats;
254 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
256 struct completion event_stats_compl;
258 unsigned long htt_stats_mask;
259 struct delayed_work htt_stats_dwork;
263 ATH10K_STATE_OFF = 0,
266 /* When doing firmware recovery the device is first powered down.
267 * mac80211 is supposed to call in to start() hook later on. It is
268 * however possible that driver unloading and firmware crash overlap.
269 * mac80211 can wait on conf_mutex in stop() while the device is
270 * stopped in ath10k_core_restart() work holding conf_mutex. The state
271 * RESTARTED means that the device is up and mac80211 has started hw
272 * reconfiguration. Once mac80211 is done with the reconfiguration we
273 * set the state to STATE_ON in restart_complete(). */
274 ATH10K_STATE_RESTARTING,
275 ATH10K_STATE_RESTARTED,
277 /* The device has crashed while restarting hw. This state is like ON
278 * but commands are blocked in HTC and -ECOMM response is given. This
279 * prevents completion timeouts and makes the driver more responsive to
280 * userspace commands. This is also prevents recursive recovery. */
284 enum ath10k_fw_features {
285 /* wmi_mgmt_rx_hdr contains extra RSSI information */
286 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
288 /* firmware from 10X branch */
289 ATH10K_FW_FEATURE_WMI_10X = 1,
291 /* firmware support tx frame management over WMI, otherwise it's HTT */
292 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
295 ATH10K_FW_FEATURE_COUNT,
299 struct ath_common ath_common;
300 struct ieee80211_hw *hw;
302 u8 mac_addr[ETH_ALEN];
307 u32 fw_version_minor;
308 u16 fw_version_release;
309 u16 fw_version_build;
317 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
319 struct targetdef *targetdef;
320 struct hostdef *hostdef;
326 const struct ath10k_hif_ops *ops;
329 wait_queue_head_t event_queue;
330 bool is_target_paused;
332 struct ath10k_bmi bmi;
333 struct ath10k_wmi wmi;
334 struct ath10k_htc htc;
335 struct ath10k_htt htt;
337 struct ath10k_hw_params {
342 struct ath10k_hw_params_fw {
350 const struct firmware *board;
351 const struct firmware *otp;
352 const struct firmware *firmware;
355 struct completion started;
356 struct completion completed;
357 struct completion on_channel;
358 struct timer_list timeout;
367 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
370 /* should never be NULL; needed for regular htt rx */
371 struct ieee80211_channel *rx_channel;
373 /* valid during scan; needed for mgmt rx during scan */
374 struct ieee80211_channel *scan_channel;
378 bool monitor_enabled;
379 bool monitor_present;
380 unsigned int filter_flags;
382 struct wmi_pdev_set_wmm_params_arg wmm_params;
383 struct completion install_key_done;
385 struct completion vdev_setup_done;
387 struct workqueue_struct *workqueue;
389 /* prevents concurrent FW reconfiguration */
390 struct mutex conf_mutex;
392 /* protects shared structure data */
393 spinlock_t data_lock;
395 struct list_head peers;
396 wait_queue_head_t peer_mapping_wq;
398 struct work_struct offchan_tx_work;
399 struct sk_buff_head offchan_tx_queue;
400 struct completion offchan_tx_completed;
401 struct sk_buff *offchan_tx_skb;
403 struct work_struct wmi_mgmt_tx_work;
404 struct sk_buff_head wmi_mgmt_tx_queue;
406 enum ath10k_state state;
408 struct work_struct restart_work;
410 /* cycle count is reported twice for each visited channel during scan.
411 * access protected by data_lock */
412 u32 survey_last_rx_clear_count;
413 u32 survey_last_cycle_count;
414 struct survey_info survey[ATH10K_NUM_CHANS];
416 #ifdef CONFIG_ATH10K_DEBUGFS
417 struct ath10k_debug debug;
421 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
422 const struct ath10k_hif_ops *hif_ops);
423 void ath10k_core_destroy(struct ath10k *ar);
425 int ath10k_core_start(struct ath10k *ar);
426 void ath10k_core_stop(struct ath10k *ar);
427 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
428 void ath10k_core_unregister(struct ath10k *ar);
430 #endif /* _CORE_H_ */