xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/htc.h (revision 838f4279)
1fb9987d0SSujith /*
25b68138eSSujith Manoharan  * Copyright (c) 2010-2011 Atheros Communications Inc.
3fb9987d0SSujith  *
4fb9987d0SSujith  * Permission to use, copy, modify, and/or distribute this software for any
5fb9987d0SSujith  * purpose with or without fee is hereby granted, provided that the above
6fb9987d0SSujith  * copyright notice and this permission notice appear in all copies.
7fb9987d0SSujith  *
8fb9987d0SSujith  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9fb9987d0SSujith  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10fb9987d0SSujith  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11fb9987d0SSujith  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12fb9987d0SSujith  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13fb9987d0SSujith  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14fb9987d0SSujith  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15fb9987d0SSujith  */
16fb9987d0SSujith 
17fb9987d0SSujith #ifndef HTC_H
18fb9987d0SSujith #define HTC_H
19fb9987d0SSujith 
20fb9987d0SSujith #include <linux/module.h>
21fb9987d0SSujith #include <linux/usb.h>
22fb9987d0SSujith #include <linux/firmware.h>
23fb9987d0SSujith #include <linux/skbuff.h>
24fb9987d0SSujith #include <linux/netdevice.h>
25838f4279SFelix Fietkau #include <linux/etherdevice.h>
26fb9987d0SSujith #include <linux/leds.h>
27617f3d0dSTejun Heo #include <linux/slab.h>
28fb9987d0SSujith #include <net/mac80211.h>
29fb9987d0SSujith 
30fb9987d0SSujith #include "common.h"
31fb9987d0SSujith #include "htc_hst.h"
32fb9987d0SSujith #include "hif_usb.h"
33fb9987d0SSujith #include "wmi.h"
34fb9987d0SSujith 
35fb9987d0SSujith #define ATH_STA_SHORT_CALINTERVAL 1000    /* 1 second */
36a236254cSSujith Manoharan #define ATH_AP_SHORT_CALINTERVAL  100     /* 100 ms */
37fb9987d0SSujith #define ATH_ANI_POLLINTERVAL      100     /* 100 ms */
38fb9987d0SSujith #define ATH_LONG_CALINTERVAL      30000   /* 30 seconds */
39fb9987d0SSujith #define ATH_RESTART_CALINTERVAL   1200000 /* 20 minutes */
40fb9987d0SSujith 
41fb9987d0SSujith #define ATH_DEFAULT_BMISS_LIMIT 10
42fb9987d0SSujith #define IEEE80211_MS_TO_TU(x)   (((x) * 1000) / 1024)
43fb9987d0SSujith #define TSF_TO_TU(_h, _l) \
44fb9987d0SSujith 	((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
45fb9987d0SSujith 
46fb9987d0SSujith extern struct ieee80211_ops ath9k_htc_ops;
47e1572c5eSSujith extern int htc_modparam_nohwcrypt;
48fb9987d0SSujith 
49fb9987d0SSujith enum htc_phymode {
50c75197a7SSujith Manoharan 	HTC_MODE_11NA		= 0,
51c75197a7SSujith Manoharan 	HTC_MODE_11NG		= 1
52fb9987d0SSujith };
53fb9987d0SSujith 
54fb9987d0SSujith enum htc_opmode {
55fb9987d0SSujith 	HTC_M_STA	= 1,
56fb9987d0SSujith 	HTC_M_IBSS	= 0,
57fb9987d0SSujith 	HTC_M_AHDEMO	= 3,
58fb9987d0SSujith 	HTC_M_HOSTAP	= 6,
59fb9987d0SSujith 	HTC_M_MONITOR	= 8,
60fb9987d0SSujith 	HTC_M_WDS	= 2
61fb9987d0SSujith };
62fb9987d0SSujith 
63fb9987d0SSujith #define ATH9K_HTC_AMPDU  1
64fb9987d0SSujith #define ATH9K_HTC_NORMAL 2
6540dc9e4bSSujith Manoharan #define ATH9K_HTC_BEACON 3
6640dc9e4bSSujith Manoharan #define ATH9K_HTC_MGMT   4
67fb9987d0SSujith 
68fb9987d0SSujith #define ATH9K_HTC_TX_CTSONLY      0x1
69fb9987d0SSujith #define ATH9K_HTC_TX_RTSCTS       0x2
70fb9987d0SSujith 
71fb9987d0SSujith struct tx_frame_hdr {
72fb9987d0SSujith 	u8 data_type;
73fb9987d0SSujith 	u8 node_idx;
74fb9987d0SSujith 	u8 vif_idx;
75fb9987d0SSujith 	u8 tidno;
76dc738cb6SRajkumar Manoharan 	__be32 flags; /* ATH9K_HTC_TX_* */
77fb9987d0SSujith 	u8 key_type;
78fb9987d0SSujith 	u8 keyix;
79e8e38607SSujith Manoharan 	u8 cookie;
80e8e38607SSujith Manoharan 	u8 pad;
81fb9987d0SSujith } __packed;
82fb9987d0SSujith 
83fb9987d0SSujith struct tx_mgmt_hdr {
84fb9987d0SSujith 	u8 node_idx;
85fb9987d0SSujith 	u8 vif_idx;
86fb9987d0SSujith 	u8 tidno;
87fb9987d0SSujith 	u8 flags;
88fb9987d0SSujith 	u8 key_type;
89fb9987d0SSujith 	u8 keyix;
90e8e38607SSujith Manoharan 	u8 cookie;
91e8e38607SSujith Manoharan 	u8 pad;
92fb9987d0SSujith } __packed;
93fb9987d0SSujith 
94fb9987d0SSujith struct tx_beacon_header {
95fb9987d0SSujith 	u8 vif_index;
961c165c97SSujith Manoharan 	u8 len_changed;
97fb9987d0SSujith 	u16 rev;
98fb9987d0SSujith } __packed;
99fb9987d0SSujith 
1003a0593efSSujith Manoharan #define MAX_TX_AMPDU_SUBFRAMES_9271 17
1013a0593efSSujith Manoharan #define MAX_TX_AMPDU_SUBFRAMES_7010 22
1023a0593efSSujith Manoharan 
103fb9987d0SSujith struct ath9k_htc_cap_target {
1043a0593efSSujith Manoharan 	__be32 ampdu_limit;
105fb9987d0SSujith 	u8 ampdu_subframes;
1063a0593efSSujith Manoharan 	u8 enable_coex;
107fb9987d0SSujith 	u8 tx_chainmask;
1080a8579f6SSujith Manoharan 	u8 pad;
109fb9987d0SSujith } __packed;
110fb9987d0SSujith 
111fb9987d0SSujith struct ath9k_htc_target_vif {
112fb9987d0SSujith 	u8 index;
113e4c62506SSujith Manoharan 	u8 opmode;
114fb9987d0SSujith 	u8 myaddr[ETH_ALEN];
115fb9987d0SSujith 	u8 ath_cap;
116e4c62506SSujith Manoharan 	__be16 rtsthreshold;
117e4c62506SSujith Manoharan 	u8 pad;
118fb9987d0SSujith } __packed;
119fb9987d0SSujith 
120fb9987d0SSujith struct ath9k_htc_target_sta {
121fb9987d0SSujith 	u8 macaddr[ETH_ALEN];
122fb9987d0SSujith 	u8 bssid[ETH_ALEN];
123fb9987d0SSujith 	u8 sta_index;
124fb9987d0SSujith 	u8 vif_index;
125fb9987d0SSujith 	u8 is_vif_sta;
12684dfa730SSujith Manoharan 	__be16 flags;
127b97c57ffSSujith Manoharan 	__be16 htcap;
128b97c57ffSSujith Manoharan 	__be16 maxampdu;
129b97c57ffSSujith Manoharan 	u8 pad;
130fb9987d0SSujith } __packed;
131fb9987d0SSujith 
132fb9987d0SSujith struct ath9k_htc_target_aggr {
133fb9987d0SSujith 	u8 sta_index;
134fb9987d0SSujith 	u8 tidno;
135fb9987d0SSujith 	u8 aggr_enable;
136fb9987d0SSujith 	u8 padding;
137fb9987d0SSujith } __packed;
138fb9987d0SSujith 
139fb9987d0SSujith #define ATH_HTC_RATE_MAX 30
140fb9987d0SSujith 
141fb9987d0SSujith #define WLAN_RC_DS_FLAG  0x01
142fb9987d0SSujith #define WLAN_RC_40_FLAG  0x02
143fb9987d0SSujith #define WLAN_RC_SGI_FLAG 0x04
144fb9987d0SSujith #define WLAN_RC_HT_FLAG  0x08
145fb9987d0SSujith 
146fb9987d0SSujith struct ath9k_htc_rateset {
147fb9987d0SSujith 	u8 rs_nrates;
148fb9987d0SSujith 	u8 rs_rates[ATH_HTC_RATE_MAX];
149fb9987d0SSujith };
150fb9987d0SSujith 
151fb9987d0SSujith struct ath9k_htc_rate {
152fb9987d0SSujith 	struct ath9k_htc_rateset legacy_rates;
153fb9987d0SSujith 	struct ath9k_htc_rateset ht_rates;
154fb9987d0SSujith } __packed;
155fb9987d0SSujith 
156fb9987d0SSujith struct ath9k_htc_target_rate {
157fb9987d0SSujith 	u8 sta_index;
158fb9987d0SSujith 	u8 isnew;
1597f1f5a00SSujith 	__be32 capflags;
160fb9987d0SSujith 	struct ath9k_htc_rate rates;
161fb9987d0SSujith };
162fb9987d0SSujith 
163a55bb94aSSujith Manoharan struct ath9k_htc_target_rate_mask {
164a55bb94aSSujith Manoharan 	u8 vif_index;
165a55bb94aSSujith Manoharan 	u8 band;
166a55bb94aSSujith Manoharan 	__be32 mask;
167a55bb94aSSujith Manoharan 	u16 pad;
168a55bb94aSSujith Manoharan } __packed;
169a55bb94aSSujith Manoharan 
170fbc29d6cSSujith Manoharan struct ath9k_htc_target_int_stats {
171fbc29d6cSSujith Manoharan 	__be32 rx;
172fbc29d6cSSujith Manoharan 	__be32 rxorn;
173fbc29d6cSSujith Manoharan 	__be32 rxeol;
174fbc29d6cSSujith Manoharan 	__be32 txurn;
175fbc29d6cSSujith Manoharan 	__be32 txto;
176fbc29d6cSSujith Manoharan 	__be32 cst;
177fbc29d6cSSujith Manoharan } __packed;
178fbc29d6cSSujith Manoharan 
179fbc29d6cSSujith Manoharan struct ath9k_htc_target_tx_stats {
180fbc29d6cSSujith Manoharan 	__be32 xretries;
181fbc29d6cSSujith Manoharan 	__be32 fifoerr;
182fbc29d6cSSujith Manoharan 	__be32 filtered;
183fbc29d6cSSujith Manoharan 	__be32 timer_exp;
184fbc29d6cSSujith Manoharan 	__be32 shortretries;
185fbc29d6cSSujith Manoharan 	__be32 longretries;
186fbc29d6cSSujith Manoharan 	__be32 qnull;
187fbc29d6cSSujith Manoharan 	__be32 encap_fail;
188fbc29d6cSSujith Manoharan 	__be32 nobuf;
189fbc29d6cSSujith Manoharan } __packed;
190fbc29d6cSSujith Manoharan 
191fbc29d6cSSujith Manoharan struct ath9k_htc_target_rx_stats {
192fbc29d6cSSujith Manoharan 	__be32 nobuf;
193fbc29d6cSSujith Manoharan 	__be32 host_send;
194fbc29d6cSSujith Manoharan 	__be32 host_done;
195fb9987d0SSujith } __packed;
196fb9987d0SSujith 
197a97b478cSSujith Manoharan #define ATH9K_HTC_MAX_VIF 2
198da8d9d93SSujith Manoharan #define ATH9K_HTC_MAX_BCN_VIF 2
199a97b478cSSujith Manoharan 
2000df8359aSSujith Manoharan #define INC_VIF(_priv, _type) do {		\
2010df8359aSSujith Manoharan 		switch (_type) {		\
2020df8359aSSujith Manoharan 		case NL80211_IFTYPE_STATION:	\
2030df8359aSSujith Manoharan 			_priv->num_sta_vif++;	\
2040df8359aSSujith Manoharan 			break;			\
2050df8359aSSujith Manoharan 		case NL80211_IFTYPE_ADHOC:	\
2060df8359aSSujith Manoharan 			_priv->num_ibss_vif++;	\
2070df8359aSSujith Manoharan 			break;			\
208da8d9d93SSujith Manoharan 		case NL80211_IFTYPE_AP:		\
209da8d9d93SSujith Manoharan 			_priv->num_ap_vif++;	\
210da8d9d93SSujith Manoharan 			break;			\
2110df8359aSSujith Manoharan 		default:			\
2120df8359aSSujith Manoharan 			break;			\
2130df8359aSSujith Manoharan 		}				\
2140df8359aSSujith Manoharan 	} while (0)
2150df8359aSSujith Manoharan 
2160df8359aSSujith Manoharan #define DEC_VIF(_priv, _type) do {		\
2170df8359aSSujith Manoharan 		switch (_type) {		\
2180df8359aSSujith Manoharan 		case NL80211_IFTYPE_STATION:	\
2190df8359aSSujith Manoharan 			_priv->num_sta_vif--;	\
2200df8359aSSujith Manoharan 			break;			\
2210df8359aSSujith Manoharan 		case NL80211_IFTYPE_ADHOC:	\
2220df8359aSSujith Manoharan 			_priv->num_ibss_vif--;	\
2230df8359aSSujith Manoharan 			break;			\
224da8d9d93SSujith Manoharan 		case NL80211_IFTYPE_AP:		\
225da8d9d93SSujith Manoharan 			_priv->num_ap_vif--;	\
226da8d9d93SSujith Manoharan 			break;			\
2270df8359aSSujith Manoharan 		default:			\
2280df8359aSSujith Manoharan 			break;			\
2290df8359aSSujith Manoharan 		}				\
2300df8359aSSujith Manoharan 	} while (0)
2310df8359aSSujith Manoharan 
232fb9987d0SSujith struct ath9k_htc_vif {
233fb9987d0SSujith 	u8 index;
2349a3d025bSSujith Manoharan 	u16 seq_no;
235e7a2a4f5SSujith Manoharan 	bool beacon_configured;
236832f6a18SSujith Manoharan 	int bslot;
2379b674a02SSujith Manoharan 	__le64 tsfadjust;
238fb9987d0SSujith };
239fb9987d0SSujith 
240585895cdSSujith Manoharan struct ath9k_vif_iter_data {
241585895cdSSujith Manoharan 	const u8 *hw_macaddr;
242585895cdSSujith Manoharan 	u8 mask[ETH_ALEN];
243585895cdSSujith Manoharan };
244585895cdSSujith Manoharan 
245fb9987d0SSujith #define ATH9K_HTC_MAX_STA 8
246fb9987d0SSujith #define ATH9K_HTC_MAX_TID 8
247fb9987d0SSujith 
248fb9987d0SSujith enum tid_aggr_state {
249fb9987d0SSujith 	AGGR_STOP = 0,
250fb9987d0SSujith 	AGGR_PROGRESS,
251fb9987d0SSujith 	AGGR_START,
252fb9987d0SSujith 	AGGR_OPERATIONAL
253fb9987d0SSujith };
254fb9987d0SSujith 
255fb9987d0SSujith struct ath9k_htc_sta {
256fb9987d0SSujith 	u8 index;
257fb9987d0SSujith 	enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
258fb9987d0SSujith };
259fb9987d0SSujith 
260fb9987d0SSujith #define ATH9K_HTC_RXBUF 256
261fb9987d0SSujith #define HTC_RX_FRAME_HEADER_SIZE 40
262fb9987d0SSujith 
263fb9987d0SSujith struct ath9k_htc_rxbuf {
264fb9987d0SSujith 	bool in_process;
265fb9987d0SSujith 	struct sk_buff *skb;
266fb9987d0SSujith 	struct ath_htc_rx_status rxstatus;
267fb9987d0SSujith 	struct list_head list;
268fb9987d0SSujith };
269fb9987d0SSujith 
270fb9987d0SSujith struct ath9k_htc_rx {
271fb9987d0SSujith 	int last_rssi; /* FIXME: per-STA */
272fb9987d0SSujith 	struct list_head rxbuf;
273fb9987d0SSujith 	spinlock_t rxbuflock;
274fb9987d0SSujith };
275fb9987d0SSujith 
276859c3ca1SSujith Manoharan #define ATH9K_HTC_TX_CLEANUP_INTERVAL 50 /* ms */
27789ea6745SSujith Manoharan #define ATH9K_HTC_TX_TIMEOUT_INTERVAL 3000 /* ms */
2788e86a547SSujith Manoharan #define ATH9K_HTC_TX_RESERVE 10
27989ea6745SSujith Manoharan #define ATH9K_HTC_TX_TIMEOUT_COUNT 40
2808e86a547SSujith Manoharan #define ATH9K_HTC_TX_THRESHOLD (MAX_TX_BUF_NUM - ATH9K_HTC_TX_RESERVE)
281658ef04fSSujith Manoharan 
2828e86a547SSujith Manoharan #define ATH9K_HTC_OP_TX_QUEUES_STOP BIT(0)
28327876a29SSujith Manoharan #define ATH9K_HTC_OP_TX_DRAIN       BIT(1)
2848e86a547SSujith Manoharan 
2858e86a547SSujith Manoharan struct ath9k_htc_tx {
2868e86a547SSujith Manoharan 	u8 flags;
2878e86a547SSujith Manoharan 	int queued_cnt;
28827876a29SSujith Manoharan 	struct sk_buff_head mgmt_ep_queue;
28927876a29SSujith Manoharan 	struct sk_buff_head cab_ep_queue;
29027876a29SSujith Manoharan 	struct sk_buff_head data_be_queue;
29127876a29SSujith Manoharan 	struct sk_buff_head data_bk_queue;
29227876a29SSujith Manoharan 	struct sk_buff_head data_vi_queue;
29327876a29SSujith Manoharan 	struct sk_buff_head data_vo_queue;
294b587fc81SSujith Manoharan 	struct sk_buff_head tx_failed;
2952c5d57f0SSujith Manoharan 	DECLARE_BITMAP(tx_slot, MAX_TX_BUF_NUM);
296859c3ca1SSujith Manoharan 	struct timer_list cleanup_timer;
2978e86a547SSujith Manoharan 	spinlock_t tx_lock;
298658ef04fSSujith Manoharan };
299658ef04fSSujith Manoharan 
300fb9987d0SSujith struct ath9k_htc_tx_ctl {
301fb9987d0SSujith 	u8 type; /* ATH9K_HTC_* */
302d67ee533SSujith Manoharan 	u8 epid;
303729bd3abSSujith Manoharan 	u8 txok;
30484c9e164SSujith Manoharan 	u8 sta_idx;
305859c3ca1SSujith Manoharan 	unsigned long timestamp;
306fb9987d0SSujith };
307fb9987d0SSujith 
30840dc9e4bSSujith Manoharan static inline struct ath9k_htc_tx_ctl *HTC_SKB_CB(struct sk_buff *skb)
30940dc9e4bSSujith Manoharan {
31040dc9e4bSSujith Manoharan 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
31140dc9e4bSSujith Manoharan 
31240dc9e4bSSujith Manoharan 	BUILD_BUG_ON(sizeof(struct ath9k_htc_tx_ctl) >
31340dc9e4bSSujith Manoharan 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
31440dc9e4bSSujith Manoharan 	return (struct ath9k_htc_tx_ctl *) &tx_info->driver_data;
31540dc9e4bSSujith Manoharan }
31640dc9e4bSSujith Manoharan 
317fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
318fb9987d0SSujith 
319fb9987d0SSujith #define TX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c++)
320fb9987d0SSujith #define RX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.rx_stats.c++)
3217d547eb4SSujith Manoharan #define CAB_STAT_INC   priv->debug.tx_stats.cab_queued++
322fb9987d0SSujith 
3232edb4583SSujith #define TX_QSTAT_INC(q) (priv->debug.tx_stats.queue_stats[q]++)
3242edb4583SSujith 
325719c4cf6SSujith Manoharan void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
326719c4cf6SSujith Manoharan 			   struct ath_htc_rx_status *rxs);
327719c4cf6SSujith Manoharan 
328fb9987d0SSujith struct ath_tx_stats {
329fb9987d0SSujith 	u32 buf_queued;
330fb9987d0SSujith 	u32 buf_completed;
331fb9987d0SSujith 	u32 skb_queued;
332b587fc81SSujith Manoharan 	u32 skb_success;
333b587fc81SSujith Manoharan 	u32 skb_failed;
3347d547eb4SSujith Manoharan 	u32 cab_queued;
335bea843c7SSujith Manoharan 	u32 queue_stats[IEEE80211_NUM_ACS];
336fb9987d0SSujith };
337fb9987d0SSujith 
338fb9987d0SSujith struct ath_rx_stats {
339fb9987d0SSujith 	u32 skb_allocated;
340fb9987d0SSujith 	u32 skb_completed;
341fb9987d0SSujith 	u32 skb_dropped;
342719c4cf6SSujith Manoharan 	u32 err_crc;
343719c4cf6SSujith Manoharan 	u32 err_decrypt_crc;
344719c4cf6SSujith Manoharan 	u32 err_mic;
345719c4cf6SSujith Manoharan 	u32 err_pre_delim;
346719c4cf6SSujith Manoharan 	u32 err_post_delim;
347719c4cf6SSujith Manoharan 	u32 err_decrypt_busy;
348719c4cf6SSujith Manoharan 	u32 err_phy;
349719c4cf6SSujith Manoharan 	u32 err_phy_stats[ATH9K_PHYERR_MAX];
350fb9987d0SSujith };
351fb9987d0SSujith 
352fb9987d0SSujith struct ath9k_debug {
353fb9987d0SSujith 	struct dentry *debugfs_phy;
354fb9987d0SSujith 	struct ath_tx_stats tx_stats;
355fb9987d0SSujith 	struct ath_rx_stats rx_stats;
356fb9987d0SSujith };
357fb9987d0SSujith 
358fb9987d0SSujith #else
359fb9987d0SSujith 
360fb9987d0SSujith #define TX_STAT_INC(c) do { } while (0)
361fb9987d0SSujith #define RX_STAT_INC(c) do { } while (0)
3627d547eb4SSujith Manoharan #define CAB_STAT_INC   do { } while (0)
363fb9987d0SSujith 
364ed3305b4SJohn W. Linville #define TX_QSTAT_INC(c) do { } while (0)
365ed3305b4SJohn W. Linville 
366719c4cf6SSujith Manoharan static inline void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
367719c4cf6SSujith Manoharan 					 struct ath_htc_rx_status *rxs)
368719c4cf6SSujith Manoharan {
369719c4cf6SSujith Manoharan }
370719c4cf6SSujith Manoharan 
371fb9987d0SSujith #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
372fb9987d0SSujith 
373fb9987d0SSujith #define ATH_LED_PIN_DEF             1
3746d64ab7fSRajkumar Manoharan #define ATH_LED_PIN_9287            10
375fb9987d0SSujith #define ATH_LED_PIN_9271            15
37688c1f4f6SSujith #define ATH_LED_PIN_7010            12
377fb9987d0SSujith 
378832f6a18SSujith Manoharan #define BSTUCK_THRESHOLD 10
379832f6a18SSujith Manoharan 
380b0a6ba98SSujith Manoharan /*
381b0a6ba98SSujith Manoharan  * Adjust these when the max. no of beaconing interfaces is
382b0a6ba98SSujith Manoharan  * increased.
383b0a6ba98SSujith Manoharan  */
384b0a6ba98SSujith Manoharan #define DEFAULT_SWBA_RESPONSE 40 /* in TUs */
385b0a6ba98SSujith Manoharan #define MIN_SWBA_RESPONSE     10 /* in TUs */
386b0a6ba98SSujith Manoharan 
3871c3652a5SVivek Natarajan struct htc_beacon_config {
388832f6a18SSujith Manoharan 	struct ieee80211_vif *bslot[ATH9K_HTC_MAX_BCN_VIF];
3891c3652a5SVivek Natarajan 	u16 beacon_interval;
3901c3652a5SVivek Natarajan 	u16 dtim_period;
3911c3652a5SVivek Natarajan 	u16 bmiss_timeout;
392832f6a18SSujith Manoharan 	u32 bmiss_cnt;
3931c3652a5SVivek Natarajan };
3941c3652a5SVivek Natarajan 
39521cb9879SVivek Natarajan struct ath_btcoex {
39621cb9879SVivek Natarajan 	u32 bt_priority_cnt;
39721cb9879SVivek Natarajan 	unsigned long bt_priority_time;
39821cb9879SVivek Natarajan 	int bt_stomp_type; /* Types of BT stomping */
39921cb9879SVivek Natarajan 	u32 btcoex_no_stomp;
40021cb9879SVivek Natarajan 	u32 btcoex_period;
40121cb9879SVivek Natarajan 	u32 btscan_no_stomp;
40221cb9879SVivek Natarajan };
40321cb9879SVivek Natarajan 
4049d5b80fdSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
405cee5341dSSujith Manoharan void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product);
406bf047fcdSSujith Manoharan void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv);
407bf047fcdSSujith Manoharan void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv);
4089d5b80fdSSujith Manoharan #else
4099d5b80fdSSujith Manoharan static inline void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product)
4109d5b80fdSSujith Manoharan {
4119d5b80fdSSujith Manoharan }
4129d5b80fdSSujith Manoharan static inline void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv)
4139d5b80fdSSujith Manoharan {
4149d5b80fdSSujith Manoharan }
4159d5b80fdSSujith Manoharan static inline void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
4169d5b80fdSSujith Manoharan {
4179d5b80fdSSujith Manoharan }
4189d5b80fdSSujith Manoharan #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
41921cb9879SVivek Natarajan 
420fb9987d0SSujith #define OP_INVALID		   BIT(0)
421fb9987d0SSujith #define OP_SCANNING		   BIT(1)
422d244f21eSSujith Manoharan #define OP_ENABLE_BEACON           BIT(2)
423d244f21eSSujith Manoharan #define OP_BT_PRIORITY_DETECTED    BIT(3)
424d244f21eSSujith Manoharan #define OP_BT_SCAN                 BIT(4)
425d244f21eSSujith Manoharan #define OP_ANI_RUNNING             BIT(5)
426d244f21eSSujith Manoharan #define OP_TSF_RESET               BIT(6)
427fb9987d0SSujith 
428fb9987d0SSujith struct ath9k_htc_priv {
429fb9987d0SSujith 	struct device *dev;
430fb9987d0SSujith 	struct ieee80211_hw *hw;
431fb9987d0SSujith 	struct ath_hw *ah;
432fb9987d0SSujith 	struct htc_target *htc;
433fb9987d0SSujith 	struct wmi *wmi;
434fb9987d0SSujith 
43529bbfb24SSujith Manoharan 	u16 fw_version_major;
43629bbfb24SSujith Manoharan 	u16 fw_version_minor;
43729bbfb24SSujith Manoharan 
438fb9987d0SSujith 	enum htc_endpoint_id wmi_cmd_ep;
439fb9987d0SSujith 	enum htc_endpoint_id beacon_ep;
440fb9987d0SSujith 	enum htc_endpoint_id cab_ep;
441fb9987d0SSujith 	enum htc_endpoint_id uapsd_ep;
442fb9987d0SSujith 	enum htc_endpoint_id mgmt_ep;
443fb9987d0SSujith 	enum htc_endpoint_id data_be_ep;
444fb9987d0SSujith 	enum htc_endpoint_id data_bk_ep;
445fb9987d0SSujith 	enum htc_endpoint_id data_vi_ep;
446fb9987d0SSujith 	enum htc_endpoint_id data_vo_ep;
447fb9987d0SSujith 
448a97b478cSSujith Manoharan 	u8 vif_slot;
449a97b478cSSujith Manoharan 	u8 mon_vif_idx;
450a97b478cSSujith Manoharan 	u8 sta_slot;
451a97b478cSSujith Manoharan 	u8 vif_sta_pos[ATH9K_HTC_MAX_VIF];
4520df8359aSSujith Manoharan 	u8 num_ibss_vif;
4530df8359aSSujith Manoharan 	u8 num_sta_vif;
4540cd075d7SSujith Manoharan 	u8 num_sta_assoc_vif;
455da8d9d93SSujith Manoharan 	u8 num_ap_vif;
456a97b478cSSujith Manoharan 
457fb9987d0SSujith 	u16 curtxpow;
458fb9987d0SSujith 	u16 txpowlimit;
459fb9987d0SSujith 	u16 nvifs;
460fb9987d0SSujith 	u16 nstations;
4617c277349SSujith Manoharan 	bool rearm_ani;
4627c277349SSujith Manoharan 	bool reconfig_beacon;
463658ef04fSSujith Manoharan 	unsigned int rxfilter;
464d8a2c51cSSujith Manoharan 	unsigned long op_flags;
465fb9987d0SSujith 
4664e3ae387SRajkumar Manoharan 	struct ath9k_hw_cal_data caldata;
467658ef04fSSujith Manoharan 	struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
46820bd2a09SFelix Fietkau 
469fb9987d0SSujith 	spinlock_t beacon_lock;
4701c3652a5SVivek Natarajan 	struct htc_beacon_config cur_beacon_conf;
471658ef04fSSujith Manoharan 
472658ef04fSSujith Manoharan 	struct ath9k_htc_rx rx;
473658ef04fSSujith Manoharan 	struct ath9k_htc_tx tx;
474658ef04fSSujith Manoharan 
47573908674SSujith Manoharan 	struct tasklet_struct swba_tasklet;
476fb9987d0SSujith 	struct tasklet_struct rx_tasklet;
477a236254cSSujith Manoharan 	struct delayed_work ani_work;
47827876a29SSujith Manoharan 	struct tasklet_struct tx_failed_tasklet;
479bde748a4SVivek Natarajan 	struct work_struct ps_work;
48073908674SSujith Manoharan 	struct work_struct fatal_work;
481bde748a4SVivek Natarajan 
482bde748a4SVivek Natarajan 	struct mutex htc_pm_lock;
483bde748a4SVivek Natarajan 	unsigned long ps_usecount;
484bde748a4SVivek Natarajan 	bool ps_enabled;
4858a8572a8SVivek Natarajan 	bool ps_idle;
486fb9987d0SSujith 
487d244f21eSSujith Manoharan #ifdef CONFIG_MAC80211_LEDS
488d244f21eSSujith Manoharan 	enum led_brightness brightness;
489d244f21eSSujith Manoharan 	bool led_registered;
490d244f21eSSujith Manoharan 	char led_name[32];
491d244f21eSSujith Manoharan 	struct led_classdev led_cdev;
492d244f21eSSujith Manoharan 	struct work_struct led_work;
493d244f21eSSujith Manoharan #endif
494ca74b83bSSujith 
495ca74b83bSSujith 	int beaconq;
496ca74b83bSSujith 	int cabq;
497bea843c7SSujith Manoharan 	int hwq_map[IEEE80211_NUM_ACS];
498fb9987d0SSujith 
4999d5b80fdSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50021cb9879SVivek Natarajan 	struct ath_btcoex btcoex;
5019d5b80fdSSujith Manoharan #endif
5029d5b80fdSSujith Manoharan 
50321cb9879SVivek Natarajan 	struct delayed_work coex_period_work;
50421cb9879SVivek Natarajan 	struct delayed_work duty_cycle_work;
505fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
506fb9987d0SSujith 	struct ath9k_debug debug;
507fb9987d0SSujith #endif
508fb9987d0SSujith 	struct mutex mutex;
509fb9987d0SSujith };
510fb9987d0SSujith 
511fb9987d0SSujith static inline void ath_read_cachesize(struct ath_common *common, int *csz)
512fb9987d0SSujith {
513fb9987d0SSujith 	common->bus_ops->read_cachesize(common, csz);
514fb9987d0SSujith }
515fb9987d0SSujith 
51673908674SSujith Manoharan void ath9k_htc_reset(struct ath9k_htc_priv *priv);
51773908674SSujith Manoharan 
518832f6a18SSujith Manoharan void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
519832f6a18SSujith Manoharan 			    struct ieee80211_vif *vif);
520832f6a18SSujith Manoharan void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
521832f6a18SSujith Manoharan 			    struct ieee80211_vif *vif);
5229b674a02SSujith Manoharan void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
5239b674a02SSujith Manoharan 			     struct ieee80211_vif *vif);
524764580f5SSujith void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv);
525fb9987d0SSujith void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
5261c3652a5SVivek Natarajan 			     struct ieee80211_vif *vif);
5277c277349SSujith Manoharan void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv);
528f4c88991SSujith Manoharan void ath9k_htc_swba(struct ath9k_htc_priv *priv,
529f4c88991SSujith Manoharan 		    struct wmi_event_swba *swba);
530fb9987d0SSujith 
531fb9987d0SSujith void ath9k_htc_rxep(void *priv, struct sk_buff *skb,
532fb9987d0SSujith 		    enum htc_endpoint_id ep_id);
533fb9987d0SSujith void ath9k_htc_txep(void *priv, struct sk_buff *skb, enum htc_endpoint_id ep_id,
534fb9987d0SSujith 		    bool txok);
5359c6dda4eSSujith void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
5369c6dda4eSSujith 			enum htc_endpoint_id ep_id, bool txok);
537fb9987d0SSujith 
5383a0593efSSujith Manoharan int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
5393a0593efSSujith Manoharan 				u8 enable_coex);
540a236254cSSujith Manoharan void ath9k_htc_ani_work(struct work_struct *work);
541a236254cSSujith Manoharan void ath9k_htc_start_ani(struct ath9k_htc_priv *priv);
542a236254cSSujith Manoharan void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv);
543fb9987d0SSujith 
544fb9987d0SSujith int ath9k_tx_init(struct ath9k_htc_priv *priv);
5457d547eb4SSujith Manoharan int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
54636323f81SThomas Huehn 		       struct ieee80211_sta *sta,
5472c5d57f0SSujith Manoharan 		       struct sk_buff *skb, u8 slot, bool is_cab);
548fb9987d0SSujith void ath9k_tx_cleanup(struct ath9k_htc_priv *priv);
549e8c35a77SFelix Fietkau bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype);
550ca74b83bSSujith int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv);
551fb9987d0SSujith int get_hw_qnum(u16 queue, int *hwq_map);
552e1572c5eSSujith int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
553fb9987d0SSujith 		       struct ath9k_tx_queue_info *qinfo);
5548e86a547SSujith Manoharan void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv);
5558e86a547SSujith Manoharan void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv);
5562c5d57f0SSujith Manoharan int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv);
5572c5d57f0SSujith Manoharan void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot);
558b587fc81SSujith Manoharan void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv);
55927876a29SSujith Manoharan void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event);
56027876a29SSujith Manoharan void ath9k_tx_failed_tasklet(unsigned long data);
561859c3ca1SSujith Manoharan void ath9k_htc_tx_cleanup_timer(unsigned long data);
562fb9987d0SSujith 
563fb9987d0SSujith int ath9k_rx_init(struct ath9k_htc_priv *priv);
564fb9987d0SSujith void ath9k_rx_cleanup(struct ath9k_htc_priv *priv);
565fb9987d0SSujith void ath9k_host_rx_init(struct ath9k_htc_priv *priv);
566fb9987d0SSujith void ath9k_rx_tasklet(unsigned long data);
5670995d110SSujith u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
568fb9987d0SSujith 
569bde748a4SVivek Natarajan void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv);
570bde748a4SVivek Natarajan void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv);
571bde748a4SVivek Natarajan void ath9k_ps_work(struct work_struct *work);
572f933ebedSSujith Manoharan bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
573f933ebedSSujith Manoharan 			enum ath9k_power_mode mode);
574bde748a4SVivek Natarajan 
575fb9987d0SSujith void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
5761e1f4ad2SSujith Manoharan void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw);
577d244f21eSSujith Manoharan 
578d244f21eSSujith Manoharan #ifdef CONFIG_MAC80211_LEDS
579fb9987d0SSujith void ath9k_init_leds(struct ath9k_htc_priv *priv);
580fb9987d0SSujith void ath9k_deinit_leds(struct ath9k_htc_priv *priv);
581d244f21eSSujith Manoharan void ath9k_led_work(struct work_struct *work);
582d244f21eSSujith Manoharan #else
583d244f21eSSujith Manoharan static inline void ath9k_init_leds(struct ath9k_htc_priv *priv)
584d244f21eSSujith Manoharan {
585d244f21eSSujith Manoharan }
586d244f21eSSujith Manoharan 
587d244f21eSSujith Manoharan static inline void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
588d244f21eSSujith Manoharan {
589d244f21eSSujith Manoharan }
590d244f21eSSujith Manoharan 
591d244f21eSSujith Manoharan static inline void ath9k_led_work(struct work_struct *work)
592d244f21eSSujith Manoharan {
593d244f21eSSujith Manoharan }
594d244f21eSSujith Manoharan #endif
595fb9987d0SSujith 
596fb9987d0SSujith int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
597fa6e15e0SRajkumar Manoharan 			   u16 devid, char *product, u32 drv_info);
598fb9987d0SSujith void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
599fb9987d0SSujith #ifdef CONFIG_PM
600f933ebedSSujith Manoharan void ath9k_htc_suspend(struct htc_target *htc_handle);
601fb9987d0SSujith int ath9k_htc_resume(struct htc_target *htc_handle);
602fb9987d0SSujith #endif
603fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
604e1572c5eSSujith int ath9k_htc_init_debug(struct ath_hw *ah);
605fb9987d0SSujith #else
606e1572c5eSSujith static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
607fb9987d0SSujith #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
608fb9987d0SSujith 
609fb9987d0SSujith #endif /* HTC_H */
610