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"
35 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
36 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
37 #define WO(_f) ((_f##_OFFSET) >> 2)
39 #define ATH10K_SCAN_ID 0
40 #define WMI_READY_TIMEOUT (5 * HZ)
41 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
42 #define ATH10K_NUM_CHANS 38
44 /* Antenna noise floor */
45 #define ATH10K_DEFAULT_NOISE_FLOOR -95
47 #define ATH10K_MAX_NUM_MGMT_PENDING 128
49 /* number of failed packets */
50 #define ATH10K_KICKOUT_THRESHOLD 50
53 * Use insanely high numbers to make sure that the firmware implementation
54 * won't start, we have the same functionality already in hostapd. Unit
57 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
58 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
59 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
63 struct ath10k_skb_cb
{
70 struct ath10k_htt_txbuf
*txbuf
;
80 static inline struct ath10k_skb_cb
*ATH10K_SKB_CB(struct sk_buff
*skb
)
82 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb
) >
83 IEEE80211_TX_INFO_DRIVER_DATA_SIZE
);
84 return (struct ath10k_skb_cb
*)&IEEE80211_SKB_CB(skb
)->driver_data
;
87 static inline u32
host_interest_item_address(u32 item_offset
)
89 return QCA988X_HOST_INTEREST_ADDRESS
+ item_offset
;
96 #define ATH10K_MAX_MEM_REQS 16
98 struct ath10k_mem_chunk
{
106 enum ath10k_htc_ep_id eid
;
107 struct completion service_ready
;
108 struct completion unified_ready
;
109 wait_queue_head_t tx_credits_wq
;
110 struct wmi_cmd_map
*cmd
;
111 struct wmi_vdev_param_map
*vdev_param
;
112 struct wmi_pdev_param_map
*pdev_param
;
115 struct ath10k_mem_chunk mem_chunks
[ATH10K_MAX_MEM_REQS
];
118 struct ath10k_peer_stat
{
119 u8 peer_macaddr
[ETH_ALEN
];
122 u32 peer_rx_rate
; /* 10x only */
125 struct ath10k_target_stats
{
157 u32 sw_retry_failure
;
158 u32 illgl_rate_phy_err
;
159 u32 pdev_cont_xretry
;
166 s32 mid_ppdu_route_change
;
185 struct ath10k_peer_stat peer_stat
[TARGET_NUM_PEERS
];
187 /* TODO: Beacon filter stats */
191 struct ath10k_dfs_stats
{
195 u32 pulses_discarded
;
199 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
202 struct list_head list
;
205 DECLARE_BITMAP(peer_ids
, ATH10K_MAX_NUM_PEER_IDS
);
206 struct ieee80211_key_conf
*keys
[WMI_MAX_KEY_INDEX
+ 1];
210 struct ath10k_vif
*arvif
;
212 /* the following are protected by ar->data_lock */
213 u32 changed
; /* IEEE80211_RC_* */
218 struct work_struct update_wk
;
221 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
224 struct list_head list
;
227 enum wmi_vdev_type vdev_type
;
228 enum wmi_vdev_subtype vdev_subtype
;
231 struct sk_buff
*beacon
;
232 /* protected by data_lock */
236 struct ieee80211_vif
*vif
;
243 struct work_struct wep_key_work
;
244 struct ieee80211_key_conf
*wep_keys
[WMI_MAX_KEY_INDEX
+ 1];
246 u8 def_wep_key_newidx
;
255 /* 127 stations; wmi limit */
259 u8 ssid
[IEEE80211_MAX_SSID_LEN
];
261 /* P2P_IE with NoA attribute for P2P_GO case */
271 int num_legacy_stations
;
274 struct ath10k_vif_iter
{
276 struct ath10k_vif
*arvif
;
279 struct ath10k_debug
{
280 struct dentry
*debugfs_phy
;
282 struct ath10k_target_stats target_stats
;
283 u32 wmi_service_bitmap
[WMI_SERVICE_BM_SIZE
];
285 struct completion event_stats_compl
;
287 unsigned long htt_stats_mask
;
288 struct delayed_work htt_stats_dwork
;
289 struct ath10k_dfs_stats dfs_stats
;
290 struct ath_dfs_pool_stats dfs_pool_stats
;
296 ATH10K_STATE_OFF
= 0,
299 /* When doing firmware recovery the device is first powered down.
300 * mac80211 is supposed to call in to start() hook later on. It is
301 * however possible that driver unloading and firmware crash overlap.
302 * mac80211 can wait on conf_mutex in stop() while the device is
303 * stopped in ath10k_core_restart() work holding conf_mutex. The state
304 * RESTARTED means that the device is up and mac80211 has started hw
305 * reconfiguration. Once mac80211 is done with the reconfiguration we
306 * set the state to STATE_ON in restart_complete(). */
307 ATH10K_STATE_RESTARTING
,
308 ATH10K_STATE_RESTARTED
,
310 /* The device has crashed while restarting hw. This state is like ON
311 * but commands are blocked in HTC and -ECOMM response is given. This
312 * prevents completion timeouts and makes the driver more responsive to
313 * userspace commands. This is also prevents recursive recovery. */
317 enum ath10k_fw_features
{
318 /* wmi_mgmt_rx_hdr contains extra RSSI information */
319 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX
= 0,
321 /* firmware from 10X branch */
322 ATH10K_FW_FEATURE_WMI_10X
= 1,
324 /* firmware support tx frame management over WMI, otherwise it's HTT */
325 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
= 2,
327 /* Firmware does not support P2P */
328 ATH10K_FW_FEATURE_NO_P2P
= 3,
331 ATH10K_FW_FEATURE_COUNT
,
334 enum ath10k_dev_flags
{
335 /* Indicates that ath10k device is during CAC phase of DFS */
337 ATH10K_FLAG_FIRST_BOOT_DONE
,
338 ATH10K_FLAG_CORE_REGISTERED
,
342 struct ath_common ath_common
;
343 struct ieee80211_hw
*hw
;
345 u8 mac_addr
[ETH_ALEN
];
350 u32 fw_version_minor
;
351 u16 fw_version_release
;
352 u16 fw_version_build
;
360 DECLARE_BITMAP(fw_features
, ATH10K_FW_FEATURE_COUNT
);
362 struct targetdef
*targetdef
;
363 struct hostdef
*hostdef
;
369 const struct ath10k_hif_ops
*ops
;
372 struct completion target_suspend
;
374 struct ath10k_bmi bmi
;
375 struct ath10k_wmi wmi
;
376 struct ath10k_htc htc
;
377 struct ath10k_htt htt
;
379 struct ath10k_hw_params
{
384 struct ath10k_hw_params_fw
{
392 const struct firmware
*board
;
393 const void *board_data
;
396 const struct firmware
*otp
;
397 const void *otp_data
;
400 const struct firmware
*firmware
;
401 const void *firmware_data
;
407 struct completion started
;
408 struct completion completed
;
409 struct completion on_channel
;
410 struct timer_list timeout
;
419 struct ieee80211_supported_band sbands
[IEEE80211_NUM_BANDS
];
422 /* should never be NULL; needed for regular htt rx */
423 struct ieee80211_channel
*rx_channel
;
425 /* valid during scan; needed for mgmt rx during scan */
426 struct ieee80211_channel
*scan_channel
;
428 /* current operating channel definition */
429 struct cfg80211_chan_def chandef
;
435 bool monitor_started
;
436 unsigned int filter_flags
;
437 unsigned long dev_flags
;
438 u32 dfs_block_radar_events
;
440 /* protected by conf_mutex */
442 int num_started_vdevs
;
444 /* Protected by conf-mutex */
445 u8 supp_tx_chainmask
;
446 u8 supp_rx_chainmask
;
450 struct wmi_pdev_set_wmm_params_arg wmm_params
;
451 struct completion install_key_done
;
453 struct completion vdev_setup_done
;
455 struct workqueue_struct
*workqueue
;
457 /* prevents concurrent FW reconfiguration */
458 struct mutex conf_mutex
;
460 /* protects shared structure data */
461 spinlock_t data_lock
;
463 struct list_head arvifs
;
464 struct list_head peers
;
465 wait_queue_head_t peer_mapping_wq
;
467 /* number of created peers; protected by data_lock */
470 struct work_struct offchan_tx_work
;
471 struct sk_buff_head offchan_tx_queue
;
472 struct completion offchan_tx_completed
;
473 struct sk_buff
*offchan_tx_skb
;
475 struct work_struct wmi_mgmt_tx_work
;
476 struct sk_buff_head wmi_mgmt_tx_queue
;
478 enum ath10k_state state
;
480 struct work_struct register_work
;
481 struct work_struct restart_work
;
483 /* cycle count is reported twice for each visited channel during scan.
484 * access protected by data_lock */
485 u32 survey_last_rx_clear_count
;
486 u32 survey_last_cycle_count
;
487 struct survey_info survey
[ATH10K_NUM_CHANS
];
489 struct dfs_pattern_detector
*dfs_detector
;
491 #ifdef CONFIG_ATH10K_DEBUGFS
492 struct ath10k_debug debug
;
496 struct ath10k
*ath10k_core_create(void *hif_priv
, struct device
*dev
,
497 const struct ath10k_hif_ops
*hif_ops
);
498 void ath10k_core_destroy(struct ath10k
*ar
);
500 int ath10k_core_start(struct ath10k
*ar
);
501 int ath10k_wait_for_suspend(struct ath10k
*ar
, u32 suspend_opt
);
502 void ath10k_core_stop(struct ath10k
*ar
);
503 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
);
504 void ath10k_core_unregister(struct ath10k
*ar
);
506 #endif /* _CORE_H_ */