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
51 struct ath10k_skb_cb
{
66 static inline struct ath10k_skb_cb
*ATH10K_SKB_CB(struct sk_buff
*skb
)
68 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb
) >
69 IEEE80211_TX_INFO_DRIVER_DATA_SIZE
);
70 return (struct ath10k_skb_cb
*)&IEEE80211_SKB_CB(skb
)->driver_data
;
73 static inline int ath10k_skb_map(struct device
*dev
, struct sk_buff
*skb
)
75 if (ATH10K_SKB_CB(skb
)->is_mapped
)
78 ATH10K_SKB_CB(skb
)->paddr
= dma_map_single(dev
, skb
->data
, skb
->len
,
81 if (unlikely(dma_mapping_error(dev
, ATH10K_SKB_CB(skb
)->paddr
)))
84 ATH10K_SKB_CB(skb
)->is_mapped
= true;
88 static inline int ath10k_skb_unmap(struct device
*dev
, struct sk_buff
*skb
)
90 if (!ATH10K_SKB_CB(skb
)->is_mapped
)
93 dma_unmap_single(dev
, ATH10K_SKB_CB(skb
)->paddr
, skb
->len
,
95 ATH10K_SKB_CB(skb
)->is_mapped
= false;
99 static inline u32
host_interest_item_address(u32 item_offset
)
101 return QCA988X_HOST_INTEREST_ADDRESS
+ item_offset
;
108 #define ATH10K_MAX_MEM_REQS 16
110 struct ath10k_mem_chunk
{
118 enum ath10k_htc_ep_id eid
;
119 struct completion service_ready
;
120 struct completion unified_ready
;
121 wait_queue_head_t tx_credits_wq
;
122 struct wmi_cmd_map
*cmd
;
123 struct wmi_vdev_param_map
*vdev_param
;
124 struct wmi_pdev_param_map
*pdev_param
;
127 struct ath10k_mem_chunk mem_chunks
[ATH10K_MAX_MEM_REQS
];
130 struct ath10k_peer_stat
{
131 u8 peer_macaddr
[ETH_ALEN
];
136 struct ath10k_target_stats
{
162 u32 sw_retry_failure
;
163 u32 illgl_rate_phy_err
;
164 u32 pdev_cont_xretry
;
171 s32 mid_ppdu_route_change
;
190 struct ath10k_peer_stat peer_stat
[TARGET_NUM_PEERS
];
192 /* TODO: Beacon filter stats */
196 struct ath10k_dfs_stats
{
200 u32 pulses_discarded
;
204 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
207 struct list_head list
;
210 DECLARE_BITMAP(peer_ids
, ATH10K_MAX_NUM_PEER_IDS
);
211 struct ieee80211_key_conf
*keys
[WMI_MAX_KEY_INDEX
+ 1];
214 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
217 struct list_head list
;
220 enum wmi_vdev_type vdev_type
;
221 enum wmi_vdev_subtype vdev_subtype
;
224 struct sk_buff
*beacon
;
227 struct ieee80211_vif
*vif
;
229 struct work_struct wep_key_work
;
230 struct ieee80211_key_conf
*wep_keys
[WMI_MAX_KEY_INDEX
+ 1];
232 u8 def_wep_key_newidx
;
242 /* 127 stations; wmi limit */
246 u8 ssid
[IEEE80211_MAX_SSID_LEN
];
248 /* P2P_IE with NoA attribute for P2P_GO case */
261 struct ath10k_vif_iter
{
263 struct ath10k_vif
*arvif
;
266 struct ath10k_debug
{
267 struct dentry
*debugfs_phy
;
269 struct ath10k_target_stats target_stats
;
270 u32 wmi_service_bitmap
[WMI_SERVICE_BM_SIZE
];
272 struct completion event_stats_compl
;
274 unsigned long htt_stats_mask
;
275 struct delayed_work htt_stats_dwork
;
276 struct ath10k_dfs_stats dfs_stats
;
277 struct ath_dfs_pool_stats dfs_pool_stats
;
283 ATH10K_STATE_OFF
= 0,
286 /* When doing firmware recovery the device is first powered down.
287 * mac80211 is supposed to call in to start() hook later on. It is
288 * however possible that driver unloading and firmware crash overlap.
289 * mac80211 can wait on conf_mutex in stop() while the device is
290 * stopped in ath10k_core_restart() work holding conf_mutex. The state
291 * RESTARTED means that the device is up and mac80211 has started hw
292 * reconfiguration. Once mac80211 is done with the reconfiguration we
293 * set the state to STATE_ON in restart_complete(). */
294 ATH10K_STATE_RESTARTING
,
295 ATH10K_STATE_RESTARTED
,
297 /* The device has crashed while restarting hw. This state is like ON
298 * but commands are blocked in HTC and -ECOMM response is given. This
299 * prevents completion timeouts and makes the driver more responsive to
300 * userspace commands. This is also prevents recursive recovery. */
304 enum ath10k_fw_features
{
305 /* wmi_mgmt_rx_hdr contains extra RSSI information */
306 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX
= 0,
308 /* firmware from 10X branch */
309 ATH10K_FW_FEATURE_WMI_10X
= 1,
311 /* firmware support tx frame management over WMI, otherwise it's HTT */
312 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
= 2,
314 /* Firmware does not support P2P */
315 ATH10K_FW_FEATURE_NO_P2P
= 3,
318 ATH10K_FW_FEATURE_COUNT
,
321 enum ath10k_dev_flags
{
322 /* Indicates that ath10k device is during CAC phase of DFS */
324 ATH10K_FLAG_FIRST_BOOT_DONE
,
328 struct ath_common ath_common
;
329 struct ieee80211_hw
*hw
;
331 u8 mac_addr
[ETH_ALEN
];
336 u32 fw_version_minor
;
337 u16 fw_version_release
;
338 u16 fw_version_build
;
346 DECLARE_BITMAP(fw_features
, ATH10K_FW_FEATURE_COUNT
);
348 struct targetdef
*targetdef
;
349 struct hostdef
*hostdef
;
355 const struct ath10k_hif_ops
*ops
;
358 wait_queue_head_t event_queue
;
359 bool is_target_paused
;
361 struct ath10k_bmi bmi
;
362 struct ath10k_wmi wmi
;
363 struct ath10k_htc htc
;
364 struct ath10k_htt htt
;
366 struct ath10k_hw_params
{
371 struct ath10k_hw_params_fw
{
379 const struct firmware
*board
;
380 const void *board_data
;
383 const struct firmware
*otp
;
384 const void *otp_data
;
387 const struct firmware
*firmware
;
388 const void *firmware_data
;
394 struct completion started
;
395 struct completion completed
;
396 struct completion on_channel
;
397 struct timer_list timeout
;
406 struct ieee80211_supported_band sbands
[IEEE80211_NUM_BANDS
];
409 /* should never be NULL; needed for regular htt rx */
410 struct ieee80211_channel
*rx_channel
;
412 /* valid during scan; needed for mgmt rx during scan */
413 struct ieee80211_channel
*scan_channel
;
417 bool monitor_enabled
;
418 bool monitor_present
;
419 unsigned int filter_flags
;
420 unsigned long dev_flags
;
421 u32 dfs_block_radar_events
;
423 struct wmi_pdev_set_wmm_params_arg wmm_params
;
424 struct completion install_key_done
;
426 struct completion vdev_setup_done
;
428 struct workqueue_struct
*workqueue
;
430 /* prevents concurrent FW reconfiguration */
431 struct mutex conf_mutex
;
433 /* protects shared structure data */
434 spinlock_t data_lock
;
436 struct list_head arvifs
;
437 struct list_head peers
;
438 wait_queue_head_t peer_mapping_wq
;
440 /* number of created peers; protected by data_lock */
443 struct work_struct offchan_tx_work
;
444 struct sk_buff_head offchan_tx_queue
;
445 struct completion offchan_tx_completed
;
446 struct sk_buff
*offchan_tx_skb
;
448 struct work_struct wmi_mgmt_tx_work
;
449 struct sk_buff_head wmi_mgmt_tx_queue
;
451 enum ath10k_state state
;
453 struct work_struct restart_work
;
455 /* cycle count is reported twice for each visited channel during scan.
456 * access protected by data_lock */
457 u32 survey_last_rx_clear_count
;
458 u32 survey_last_cycle_count
;
459 struct survey_info survey
[ATH10K_NUM_CHANS
];
461 struct dfs_pattern_detector
*dfs_detector
;
463 #ifdef CONFIG_ATH10K_DEBUGFS
464 struct ath10k_debug debug
;
468 struct ath10k
*ath10k_core_create(void *hif_priv
, struct device
*dev
,
469 const struct ath10k_hif_ops
*hif_ops
);
470 void ath10k_core_destroy(struct ath10k
*ar
);
472 int ath10k_core_start(struct ath10k
*ar
);
473 void ath10k_core_stop(struct ath10k
*ar
);
474 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
);
475 void ath10k_core_unregister(struct ath10k
*ar
);
477 #endif /* _CORE_H_ */