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
48 struct ath10k_skb_cb {
62 struct sk_buff *txfrag;
66 /* 4 bytes left on 64bit arch */
69 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
71 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
72 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
73 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
76 static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
78 if (ATH10K_SKB_CB(skb)->is_mapped)
81 ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
84 if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
87 ATH10K_SKB_CB(skb)->is_mapped = true;
91 static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
93 if (!ATH10K_SKB_CB(skb)->is_mapped)
96 dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
98 ATH10K_SKB_CB(skb)->is_mapped = false;
102 static inline u32 host_interest_item_address(u32 item_offset)
104 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
112 enum ath10k_htc_ep_id eid;
113 struct completion service_ready;
114 struct completion unified_ready;
115 atomic_t pending_tx_count;
116 wait_queue_head_t wq;
118 struct sk_buff_head wmi_event_list;
119 struct work_struct wmi_event_work;
122 struct ath10k_peer_stat {
123 u8 peer_macaddr[ETH_ALEN];
128 struct ath10k_target_stats {
154 u32 sw_retry_failure;
155 u32 illgl_rate_phy_err;
156 u32 pdev_cont_xretry;
163 s32 mid_ppdu_route_change;
182 struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
184 /* TODO: Beacon filter stats */
188 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
191 struct list_head list;
194 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
195 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
198 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
202 enum wmi_vdev_type vdev_type;
203 enum wmi_vdev_subtype vdev_subtype;
208 struct ieee80211_vif *vif;
210 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
211 u8 def_wep_key_index;
221 /* 127 stations; wmi limit */
225 u8 ssid[IEEE80211_MAX_SSID_LEN];
227 /* P2P_IE with NoA attribute for P2P_GO case */
237 struct ath10k_vif_iter {
239 struct ath10k_vif *arvif;
242 struct ath10k_debug {
243 struct dentry *debugfs_phy;
245 struct ath10k_target_stats target_stats;
246 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
248 struct completion event_stats_compl;
250 unsigned long htt_stats_mask;
251 struct delayed_work htt_stats_dwork;
255 ATH10K_STATE_OFF = 0,
258 /* When doing firmware recovery the device is first powered down.
259 * mac80211 is supposed to call in to start() hook later on. It is
260 * however possible that driver unloading and firmware crash overlap.
261 * mac80211 can wait on conf_mutex in stop() while the device is
262 * stopped in ath10k_core_restart() work holding conf_mutex. The state
263 * RESTARTED means that the device is up and mac80211 has started hw
264 * reconfiguration. Once mac80211 is done with the reconfiguration we
265 * set the state to STATE_ON in restart_complete(). */
266 ATH10K_STATE_RESTARTING,
267 ATH10K_STATE_RESTARTED,
269 /* The device has crashed while restarting hw. This state is like ON
270 * but commands are blocked in HTC and -ECOMM response is given. This
271 * prevents completion timeouts and makes the driver more responsive to
272 * userspace commands. This is also prevents recursive recovery. */
276 enum ath10k_fw_features {
277 /* wmi_mgmt_rx_hdr contains extra RSSI information */
278 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
281 ATH10K_FW_FEATURE_COUNT,
285 struct ath_common ath_common;
286 struct ieee80211_hw *hw;
288 u8 mac_addr[ETH_ALEN];
293 u32 fw_version_minor;
294 u16 fw_version_release;
295 u16 fw_version_build;
303 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
305 struct targetdef *targetdef;
306 struct hostdef *hostdef;
312 const struct ath10k_hif_ops *ops;
315 wait_queue_head_t event_queue;
316 bool is_target_paused;
318 struct ath10k_bmi bmi;
319 struct ath10k_wmi wmi;
320 struct ath10k_htc htc;
321 struct ath10k_htt htt;
323 struct ath10k_hw_params {
328 struct ath10k_hw_params_fw {
336 const struct firmware *board_data;
337 const struct firmware *otp;
338 const struct firmware *firmware;
341 struct completion started;
342 struct completion completed;
343 struct completion on_channel;
344 struct timer_list timeout;
353 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
356 /* should never be NULL; needed for regular htt rx */
357 struct ieee80211_channel *rx_channel;
359 /* valid during scan; needed for mgmt rx during scan */
360 struct ieee80211_channel *scan_channel;
364 bool monitor_enabled;
365 bool monitor_present;
366 unsigned int filter_flags;
368 struct wmi_pdev_set_wmm_params_arg wmm_params;
369 struct completion install_key_done;
371 struct completion vdev_setup_done;
373 struct workqueue_struct *workqueue;
375 /* prevents concurrent FW reconfiguration */
376 struct mutex conf_mutex;
378 /* protects shared structure data */
379 spinlock_t data_lock;
381 struct list_head peers;
382 wait_queue_head_t peer_mapping_wq;
384 struct work_struct offchan_tx_work;
385 struct sk_buff_head offchan_tx_queue;
386 struct completion offchan_tx_completed;
387 struct sk_buff *offchan_tx_skb;
389 enum ath10k_state state;
391 struct work_struct restart_work;
393 /* cycle count is reported twice for each visited channel during scan.
394 * access protected by data_lock */
395 u32 survey_last_rx_clear_count;
396 u32 survey_last_cycle_count;
397 struct survey_info survey[ATH10K_NUM_CHANS];
399 #ifdef CONFIG_ATH10K_DEBUGFS
400 struct ath10k_debug debug;
404 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
405 const struct ath10k_hif_ops *hif_ops);
406 void ath10k_core_destroy(struct ath10k *ar);
408 int ath10k_core_start(struct ath10k *ar);
409 void ath10k_core_stop(struct ath10k *ar);
410 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
411 void ath10k_core_unregister(struct ath10k *ar);
413 #endif /* _CORE_H_ */