xref: /openbmc/linux/drivers/net/wireless/ath/ath9k/htc.h (revision 96810471)
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 TSF_TO_TU(_h, _l) \
43fb9987d0SSujith 	((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
44fb9987d0SSujith 
45fb9987d0SSujith extern struct ieee80211_ops ath9k_htc_ops;
46e1572c5eSSujith extern int htc_modparam_nohwcrypt;
47fb9987d0SSujith 
48fb9987d0SSujith enum htc_phymode {
49c75197a7SSujith Manoharan 	HTC_MODE_11NA		= 0,
50c75197a7SSujith Manoharan 	HTC_MODE_11NG		= 1
51fb9987d0SSujith };
52fb9987d0SSujith 
53fb9987d0SSujith enum htc_opmode {
54fb9987d0SSujith 	HTC_M_STA	= 1,
55fb9987d0SSujith 	HTC_M_IBSS	= 0,
56fb9987d0SSujith 	HTC_M_AHDEMO	= 3,
57fb9987d0SSujith 	HTC_M_HOSTAP	= 6,
58fb9987d0SSujith 	HTC_M_MONITOR	= 8,
59fb9987d0SSujith 	HTC_M_WDS	= 2
60fb9987d0SSujith };
61fb9987d0SSujith 
62fb9987d0SSujith #define ATH9K_HTC_AMPDU  1
63fb9987d0SSujith #define ATH9K_HTC_NORMAL 2
6440dc9e4bSSujith Manoharan #define ATH9K_HTC_BEACON 3
6540dc9e4bSSujith Manoharan #define ATH9K_HTC_MGMT   4
66fb9987d0SSujith 
67fb9987d0SSujith #define ATH9K_HTC_TX_CTSONLY      0x1
68fb9987d0SSujith #define ATH9K_HTC_TX_RTSCTS       0x2
69fb9987d0SSujith 
70fb9987d0SSujith struct tx_frame_hdr {
71fb9987d0SSujith 	u8 data_type;
72fb9987d0SSujith 	u8 node_idx;
73fb9987d0SSujith 	u8 vif_idx;
74fb9987d0SSujith 	u8 tidno;
75dc738cb6SRajkumar Manoharan 	__be32 flags; /* ATH9K_HTC_TX_* */
76fb9987d0SSujith 	u8 key_type;
77fb9987d0SSujith 	u8 keyix;
78e8e38607SSujith Manoharan 	u8 cookie;
79e8e38607SSujith Manoharan 	u8 pad;
80fb9987d0SSujith } __packed;
81fb9987d0SSujith 
82fb9987d0SSujith struct tx_mgmt_hdr {
83fb9987d0SSujith 	u8 node_idx;
84fb9987d0SSujith 	u8 vif_idx;
85fb9987d0SSujith 	u8 tidno;
86fb9987d0SSujith 	u8 flags;
87fb9987d0SSujith 	u8 key_type;
88fb9987d0SSujith 	u8 keyix;
89e8e38607SSujith Manoharan 	u8 cookie;
90e8e38607SSujith Manoharan 	u8 pad;
91fb9987d0SSujith } __packed;
92fb9987d0SSujith 
93fb9987d0SSujith struct tx_beacon_header {
94fb9987d0SSujith 	u8 vif_index;
951c165c97SSujith Manoharan 	u8 len_changed;
96fb9987d0SSujith 	u16 rev;
97fb9987d0SSujith } __packed;
98fb9987d0SSujith 
993a0593efSSujith Manoharan #define MAX_TX_AMPDU_SUBFRAMES_9271 17
1003a0593efSSujith Manoharan #define MAX_TX_AMPDU_SUBFRAMES_7010 22
1013a0593efSSujith Manoharan 
102fb9987d0SSujith struct ath9k_htc_cap_target {
1033a0593efSSujith Manoharan 	__be32 ampdu_limit;
104fb9987d0SSujith 	u8 ampdu_subframes;
1053a0593efSSujith Manoharan 	u8 enable_coex;
106fb9987d0SSujith 	u8 tx_chainmask;
1070a8579f6SSujith Manoharan 	u8 pad;
108fb9987d0SSujith } __packed;
109fb9987d0SSujith 
110fb9987d0SSujith struct ath9k_htc_target_vif {
111fb9987d0SSujith 	u8 index;
112e4c62506SSujith Manoharan 	u8 opmode;
113fb9987d0SSujith 	u8 myaddr[ETH_ALEN];
114fb9987d0SSujith 	u8 ath_cap;
115e4c62506SSujith Manoharan 	__be16 rtsthreshold;
116e4c62506SSujith Manoharan 	u8 pad;
117fb9987d0SSujith } __packed;
118fb9987d0SSujith 
119fb9987d0SSujith struct ath9k_htc_target_sta {
120fb9987d0SSujith 	u8 macaddr[ETH_ALEN];
121fb9987d0SSujith 	u8 bssid[ETH_ALEN];
122fb9987d0SSujith 	u8 sta_index;
123fb9987d0SSujith 	u8 vif_index;
124fb9987d0SSujith 	u8 is_vif_sta;
12584dfa730SSujith Manoharan 	__be16 flags;
126b97c57ffSSujith Manoharan 	__be16 htcap;
127b97c57ffSSujith Manoharan 	__be16 maxampdu;
128b97c57ffSSujith Manoharan 	u8 pad;
129fb9987d0SSujith } __packed;
130fb9987d0SSujith 
131fb9987d0SSujith struct ath9k_htc_target_aggr {
132fb9987d0SSujith 	u8 sta_index;
133fb9987d0SSujith 	u8 tidno;
134fb9987d0SSujith 	u8 aggr_enable;
135fb9987d0SSujith 	u8 padding;
136fb9987d0SSujith } __packed;
137fb9987d0SSujith 
138fb9987d0SSujith #define ATH_HTC_RATE_MAX 30
139fb9987d0SSujith 
140fb9987d0SSujith #define WLAN_RC_DS_FLAG  0x01
141fb9987d0SSujith #define WLAN_RC_40_FLAG  0x02
142fb9987d0SSujith #define WLAN_RC_SGI_FLAG 0x04
143fb9987d0SSujith #define WLAN_RC_HT_FLAG  0x08
144a226c3d9SOleksij Rempel #define ATH_RC_TX_STBC_FLAG 0x20
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;			\
211594e65b6SJavier Cardona 		case NL80211_IFTYPE_MESH_POINT:	\
212594e65b6SJavier Cardona 			_priv->num_mbss_vif++;	\
213594e65b6SJavier Cardona 			break;			\
2140df8359aSSujith Manoharan 		default:			\
2150df8359aSSujith Manoharan 			break;			\
2160df8359aSSujith Manoharan 		}				\
2170df8359aSSujith Manoharan 	} while (0)
2180df8359aSSujith Manoharan 
2190df8359aSSujith Manoharan #define DEC_VIF(_priv, _type) do {		\
2200df8359aSSujith Manoharan 		switch (_type) {		\
2210df8359aSSujith Manoharan 		case NL80211_IFTYPE_STATION:	\
2220df8359aSSujith Manoharan 			_priv->num_sta_vif--;	\
2230df8359aSSujith Manoharan 			break;			\
2240df8359aSSujith Manoharan 		case NL80211_IFTYPE_ADHOC:	\
2250df8359aSSujith Manoharan 			_priv->num_ibss_vif--;	\
2260df8359aSSujith Manoharan 			break;			\
227da8d9d93SSujith Manoharan 		case NL80211_IFTYPE_AP:		\
228da8d9d93SSujith Manoharan 			_priv->num_ap_vif--;	\
229da8d9d93SSujith Manoharan 			break;			\
230594e65b6SJavier Cardona 		case NL80211_IFTYPE_MESH_POINT:	\
231594e65b6SJavier Cardona 			_priv->num_mbss_vif--;	\
232594e65b6SJavier Cardona 			break;			\
2330df8359aSSujith Manoharan 		default:			\
2340df8359aSSujith Manoharan 			break;			\
2350df8359aSSujith Manoharan 		}				\
2360df8359aSSujith Manoharan 	} while (0)
2370df8359aSSujith Manoharan 
238fb9987d0SSujith struct ath9k_htc_vif {
239fb9987d0SSujith 	u8 index;
2409a3d025bSSujith Manoharan 	u16 seq_no;
241e7a2a4f5SSujith Manoharan 	bool beacon_configured;
242832f6a18SSujith Manoharan 	int bslot;
2439b674a02SSujith Manoharan 	__le64 tsfadjust;
244fb9987d0SSujith };
245fb9987d0SSujith 
246585895cdSSujith Manoharan struct ath9k_vif_iter_data {
247585895cdSSujith Manoharan 	const u8 *hw_macaddr;
248585895cdSSujith Manoharan 	u8 mask[ETH_ALEN];
249585895cdSSujith Manoharan };
250585895cdSSujith Manoharan 
251fb9987d0SSujith #define ATH9K_HTC_MAX_STA 8
252fb9987d0SSujith #define ATH9K_HTC_MAX_TID 8
253fb9987d0SSujith 
254fb9987d0SSujith enum tid_aggr_state {
255fb9987d0SSujith 	AGGR_STOP = 0,
256fb9987d0SSujith 	AGGR_PROGRESS,
257fb9987d0SSujith 	AGGR_START,
258fb9987d0SSujith 	AGGR_OPERATIONAL
259fb9987d0SSujith };
260fb9987d0SSujith 
261fb9987d0SSujith struct ath9k_htc_sta {
262fb9987d0SSujith 	u8 index;
263fb9987d0SSujith 	enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
264a243de48SStanislaw Gruszka 	struct work_struct rc_update_work;
265a243de48SStanislaw Gruszka 	struct ath9k_htc_priv *htc_priv;
266fb9987d0SSujith };
267fb9987d0SSujith 
268fb9987d0SSujith #define ATH9K_HTC_RXBUF 256
269fb9987d0SSujith #define HTC_RX_FRAME_HEADER_SIZE 40
270fb9987d0SSujith 
271fb9987d0SSujith struct ath9k_htc_rxbuf {
272fb9987d0SSujith 	bool in_process;
273fb9987d0SSujith 	struct sk_buff *skb;
274fb9987d0SSujith 	struct ath_htc_rx_status rxstatus;
275fb9987d0SSujith 	struct list_head list;
276fb9987d0SSujith };
277fb9987d0SSujith 
278fb9987d0SSujith struct ath9k_htc_rx {
279fb9987d0SSujith 	struct list_head rxbuf;
280fb9987d0SSujith 	spinlock_t rxbuflock;
281fb9987d0SSujith };
282fb9987d0SSujith 
283859c3ca1SSujith Manoharan #define ATH9K_HTC_TX_CLEANUP_INTERVAL 50 /* ms */
28489ea6745SSujith Manoharan #define ATH9K_HTC_TX_TIMEOUT_INTERVAL 3000 /* ms */
2858e86a547SSujith Manoharan #define ATH9K_HTC_TX_RESERVE 10
28689ea6745SSujith Manoharan #define ATH9K_HTC_TX_TIMEOUT_COUNT 40
2878e86a547SSujith Manoharan #define ATH9K_HTC_TX_THRESHOLD (MAX_TX_BUF_NUM - ATH9K_HTC_TX_RESERVE)
288658ef04fSSujith Manoharan 
2898e86a547SSujith Manoharan #define ATH9K_HTC_OP_TX_QUEUES_STOP BIT(0)
29027876a29SSujith Manoharan #define ATH9K_HTC_OP_TX_DRAIN       BIT(1)
2918e86a547SSujith Manoharan 
2928e86a547SSujith Manoharan struct ath9k_htc_tx {
2938e86a547SSujith Manoharan 	u8 flags;
2948e86a547SSujith Manoharan 	int queued_cnt;
29527876a29SSujith Manoharan 	struct sk_buff_head mgmt_ep_queue;
29627876a29SSujith Manoharan 	struct sk_buff_head cab_ep_queue;
29727876a29SSujith Manoharan 	struct sk_buff_head data_be_queue;
29827876a29SSujith Manoharan 	struct sk_buff_head data_bk_queue;
29927876a29SSujith Manoharan 	struct sk_buff_head data_vi_queue;
30027876a29SSujith Manoharan 	struct sk_buff_head data_vo_queue;
301b587fc81SSujith Manoharan 	struct sk_buff_head tx_failed;
3022c5d57f0SSujith Manoharan 	DECLARE_BITMAP(tx_slot, MAX_TX_BUF_NUM);
303859c3ca1SSujith Manoharan 	struct timer_list cleanup_timer;
3048e86a547SSujith Manoharan 	spinlock_t tx_lock;
305658ef04fSSujith Manoharan };
306658ef04fSSujith Manoharan 
307fb9987d0SSujith struct ath9k_htc_tx_ctl {
308fb9987d0SSujith 	u8 type; /* ATH9K_HTC_* */
309d67ee533SSujith Manoharan 	u8 epid;
310729bd3abSSujith Manoharan 	u8 txok;
31184c9e164SSujith Manoharan 	u8 sta_idx;
312859c3ca1SSujith Manoharan 	unsigned long timestamp;
313fb9987d0SSujith };
314fb9987d0SSujith 
31540dc9e4bSSujith Manoharan static inline struct ath9k_htc_tx_ctl *HTC_SKB_CB(struct sk_buff *skb)
31640dc9e4bSSujith Manoharan {
31740dc9e4bSSujith Manoharan 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
31840dc9e4bSSujith Manoharan 
31940dc9e4bSSujith Manoharan 	BUILD_BUG_ON(sizeof(struct ath9k_htc_tx_ctl) >
32040dc9e4bSSujith Manoharan 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
32140dc9e4bSSujith Manoharan 	return (struct ath9k_htc_tx_ctl *) &tx_info->driver_data;
32240dc9e4bSSujith Manoharan }
32340dc9e4bSSujith Manoharan 
324fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
325fb9987d0SSujith 
326fb9987d0SSujith #define TX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c++)
32768185a4bSBen Greear #define TX_STAT_ADD(c, a) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c += a)
328b5a0c86aSOleksij Rempel #define RX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c++)
329b5a0c86aSOleksij Rempel #define RX_STAT_ADD(c, a) (hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c += a)
3307d547eb4SSujith Manoharan #define CAB_STAT_INC   priv->debug.tx_stats.cab_queued++
331fb9987d0SSujith 
3322edb4583SSujith #define TX_QSTAT_INC(q) (priv->debug.tx_stats.queue_stats[q]++)
3332edb4583SSujith 
334719c4cf6SSujith Manoharan void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
335b5a0c86aSOleksij Rempel 			   struct ath_rx_status *rs);
336719c4cf6SSujith Manoharan 
337fb9987d0SSujith struct ath_tx_stats {
338fb9987d0SSujith 	u32 buf_queued;
339fb9987d0SSujith 	u32 buf_completed;
340fb9987d0SSujith 	u32 skb_queued;
341b587fc81SSujith Manoharan 	u32 skb_success;
34268185a4bSBen Greear 	u32 skb_success_bytes;
343b587fc81SSujith Manoharan 	u32 skb_failed;
3447d547eb4SSujith Manoharan 	u32 cab_queued;
345bea843c7SSujith Manoharan 	u32 queue_stats[IEEE80211_NUM_ACS];
346fb9987d0SSujith };
347fb9987d0SSujith 
348b5a0c86aSOleksij Rempel struct ath_skbrx_stats {
349fb9987d0SSujith 	u32 skb_allocated;
350fb9987d0SSujith 	u32 skb_completed;
35168185a4bSBen Greear 	u32 skb_completed_bytes;
352fb9987d0SSujith 	u32 skb_dropped;
353fb9987d0SSujith };
354fb9987d0SSujith 
355fb9987d0SSujith struct ath9k_debug {
356fb9987d0SSujith 	struct dentry *debugfs_phy;
357fb9987d0SSujith 	struct ath_tx_stats tx_stats;
358fb9987d0SSujith 	struct ath_rx_stats rx_stats;
359b5a0c86aSOleksij Rempel 	struct ath_skbrx_stats skbrx_stats;
360fb9987d0SSujith };
361fb9987d0SSujith 
36268185a4bSBen Greear void ath9k_htc_get_et_strings(struct ieee80211_hw *hw,
36368185a4bSBen Greear 			      struct ieee80211_vif *vif,
36468185a4bSBen Greear 			      u32 sset, u8 *data);
36568185a4bSBen Greear int ath9k_htc_get_et_sset_count(struct ieee80211_hw *hw,
36668185a4bSBen Greear 				struct ieee80211_vif *vif, int sset);
36768185a4bSBen Greear void ath9k_htc_get_et_stats(struct ieee80211_hw *hw,
36868185a4bSBen Greear 			    struct ieee80211_vif *vif,
36968185a4bSBen Greear 			    struct ethtool_stats *stats, u64 *data);
370fb9987d0SSujith #else
371fb9987d0SSujith 
372fb9987d0SSujith #define TX_STAT_INC(c) do { } while (0)
37368185a4bSBen Greear #define TX_STAT_ADD(c, a) do { } while (0)
374fb9987d0SSujith #define RX_STAT_INC(c) do { } while (0)
37568185a4bSBen Greear #define RX_STAT_ADD(c, a) do { } while (0)
3767d547eb4SSujith Manoharan #define CAB_STAT_INC   do { } while (0)
377fb9987d0SSujith 
378ed3305b4SJohn W. Linville #define TX_QSTAT_INC(c) do { } while (0)
379ed3305b4SJohn W. Linville 
380719c4cf6SSujith Manoharan static inline void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
38196810471SJohn W. Linville 					 struct ath_rx_status *rs)
382719c4cf6SSujith Manoharan {
383719c4cf6SSujith Manoharan }
384719c4cf6SSujith Manoharan 
385fb9987d0SSujith #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
386fb9987d0SSujith 
387fb9987d0SSujith #define ATH_LED_PIN_DEF             1
3886d64ab7fSRajkumar Manoharan #define ATH_LED_PIN_9287            10
389fb9987d0SSujith #define ATH_LED_PIN_9271            15
39088c1f4f6SSujith #define ATH_LED_PIN_7010            12
391fb9987d0SSujith 
392832f6a18SSujith Manoharan #define BSTUCK_THRESHOLD 10
393832f6a18SSujith Manoharan 
394b0a6ba98SSujith Manoharan /*
395b0a6ba98SSujith Manoharan  * Adjust these when the max. no of beaconing interfaces is
396b0a6ba98SSujith Manoharan  * increased.
397b0a6ba98SSujith Manoharan  */
398b0a6ba98SSujith Manoharan #define DEFAULT_SWBA_RESPONSE 40 /* in TUs */
399b0a6ba98SSujith Manoharan #define MIN_SWBA_RESPONSE     10 /* in TUs */
400b0a6ba98SSujith Manoharan 
4013c4816d9SOleksij Rempel struct htc_beacon {
402cc24c86fSOleksij Rempel 	enum {
403cc24c86fSOleksij Rempel 		OK,		/* no change needed */
404cc24c86fSOleksij Rempel 		UPDATE,		/* update pending */
405cc24c86fSOleksij Rempel 		COMMIT		/* beacon sent, commit change */
406cc24c86fSOleksij Rempel 	} updateslot;		/* slot time update fsm */
407cc24c86fSOleksij Rempel 
408832f6a18SSujith Manoharan 	struct ieee80211_vif *bslot[ATH9K_HTC_MAX_BCN_VIF];
4093c4816d9SOleksij Rempel 	u32 bmisscnt;
410a099874eSOleksij Rempel 	u32 beaconq;
411cc24c86fSOleksij Rempel 	int slottime;
412cc24c86fSOleksij Rempel 	int slotupdate;
4131c3652a5SVivek Natarajan };
4141c3652a5SVivek Natarajan 
41521cb9879SVivek Natarajan struct ath_btcoex {
41621cb9879SVivek Natarajan 	u32 bt_priority_cnt;
41721cb9879SVivek Natarajan 	unsigned long bt_priority_time;
41821cb9879SVivek Natarajan 	int bt_stomp_type; /* Types of BT stomping */
41921cb9879SVivek Natarajan 	u32 btcoex_no_stomp;
42021cb9879SVivek Natarajan 	u32 btcoex_period;
42121cb9879SVivek Natarajan 	u32 btscan_no_stomp;
42221cb9879SVivek Natarajan };
42321cb9879SVivek Natarajan 
4249d5b80fdSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
425cee5341dSSujith Manoharan void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product);
426bf047fcdSSujith Manoharan void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv);
427bf047fcdSSujith Manoharan void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv);
4289d5b80fdSSujith Manoharan #else
4299d5b80fdSSujith Manoharan static inline void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product)
4309d5b80fdSSujith Manoharan {
4319d5b80fdSSujith Manoharan }
4329d5b80fdSSujith Manoharan static inline void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv)
4339d5b80fdSSujith Manoharan {
4349d5b80fdSSujith Manoharan }
4359d5b80fdSSujith Manoharan static inline void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
4369d5b80fdSSujith Manoharan {
4379d5b80fdSSujith Manoharan }
4389d5b80fdSSujith Manoharan #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
43921cb9879SVivek Natarajan 
440d244f21eSSujith Manoharan #define OP_BT_PRIORITY_DETECTED    BIT(3)
441d244f21eSSujith Manoharan #define OP_BT_SCAN                 BIT(4)
442d244f21eSSujith Manoharan #define OP_TSF_RESET               BIT(6)
443fb9987d0SSujith 
444fb9987d0SSujith struct ath9k_htc_priv {
445fb9987d0SSujith 	struct device *dev;
446fb9987d0SSujith 	struct ieee80211_hw *hw;
447fb9987d0SSujith 	struct ath_hw *ah;
448fb9987d0SSujith 	struct htc_target *htc;
449fb9987d0SSujith 	struct wmi *wmi;
450fb9987d0SSujith 
45129bbfb24SSujith Manoharan 	u16 fw_version_major;
45229bbfb24SSujith Manoharan 	u16 fw_version_minor;
45329bbfb24SSujith Manoharan 
454fb9987d0SSujith 	enum htc_endpoint_id wmi_cmd_ep;
455fb9987d0SSujith 	enum htc_endpoint_id beacon_ep;
456fb9987d0SSujith 	enum htc_endpoint_id cab_ep;
457fb9987d0SSujith 	enum htc_endpoint_id uapsd_ep;
458fb9987d0SSujith 	enum htc_endpoint_id mgmt_ep;
459fb9987d0SSujith 	enum htc_endpoint_id data_be_ep;
460fb9987d0SSujith 	enum htc_endpoint_id data_bk_ep;
461fb9987d0SSujith 	enum htc_endpoint_id data_vi_ep;
462fb9987d0SSujith 	enum htc_endpoint_id data_vo_ep;
463fb9987d0SSujith 
464a97b478cSSujith Manoharan 	u8 vif_slot;
465a97b478cSSujith Manoharan 	u8 mon_vif_idx;
466a97b478cSSujith Manoharan 	u8 sta_slot;
467a97b478cSSujith Manoharan 	u8 vif_sta_pos[ATH9K_HTC_MAX_VIF];
4680df8359aSSujith Manoharan 	u8 num_ibss_vif;
469594e65b6SJavier Cardona 	u8 num_mbss_vif;
4700df8359aSSujith Manoharan 	u8 num_sta_vif;
4710cd075d7SSujith Manoharan 	u8 num_sta_assoc_vif;
472da8d9d93SSujith Manoharan 	u8 num_ap_vif;
473a97b478cSSujith Manoharan 
474fb9987d0SSujith 	u16 curtxpow;
475fb9987d0SSujith 	u16 txpowlimit;
476fb9987d0SSujith 	u16 nvifs;
477fb9987d0SSujith 	u16 nstations;
4787c277349SSujith Manoharan 	bool rearm_ani;
4797c277349SSujith Manoharan 	bool reconfig_beacon;
480658ef04fSSujith Manoharan 	unsigned int rxfilter;
481d8a2c51cSSujith Manoharan 	unsigned long op_flags;
482fb9987d0SSujith 
4834e3ae387SRajkumar Manoharan 	struct ath9k_hw_cal_data caldata;
48420bd2a09SFelix Fietkau 
485fb9987d0SSujith 	spinlock_t beacon_lock;
4863c4816d9SOleksij Rempel 	struct ath_beacon_config cur_beacon_conf;
4873c4816d9SOleksij Rempel 	struct htc_beacon beacon;
488658ef04fSSujith Manoharan 
489658ef04fSSujith Manoharan 	struct ath9k_htc_rx rx;
490658ef04fSSujith Manoharan 	struct ath9k_htc_tx tx;
491658ef04fSSujith Manoharan 
49273908674SSujith Manoharan 	struct tasklet_struct swba_tasklet;
493fb9987d0SSujith 	struct tasklet_struct rx_tasklet;
494a236254cSSujith Manoharan 	struct delayed_work ani_work;
49527876a29SSujith Manoharan 	struct tasklet_struct tx_failed_tasklet;
496bde748a4SVivek Natarajan 	struct work_struct ps_work;
49773908674SSujith Manoharan 	struct work_struct fatal_work;
498bde748a4SVivek Natarajan 
499bde748a4SVivek Natarajan 	struct mutex htc_pm_lock;
500bde748a4SVivek Natarajan 	unsigned long ps_usecount;
501bde748a4SVivek Natarajan 	bool ps_enabled;
5028a8572a8SVivek Natarajan 	bool ps_idle;
503fb9987d0SSujith 
504d244f21eSSujith Manoharan #ifdef CONFIG_MAC80211_LEDS
505d244f21eSSujith Manoharan 	enum led_brightness brightness;
506d244f21eSSujith Manoharan 	bool led_registered;
507d244f21eSSujith Manoharan 	char led_name[32];
508d244f21eSSujith Manoharan 	struct led_classdev led_cdev;
509d244f21eSSujith Manoharan 	struct work_struct led_work;
510d244f21eSSujith Manoharan #endif
511ca74b83bSSujith 
512ca74b83bSSujith 	int cabq;
513bea843c7SSujith Manoharan 	int hwq_map[IEEE80211_NUM_ACS];
514fb9987d0SSujith 
5159d5b80fdSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
51621cb9879SVivek Natarajan 	struct ath_btcoex btcoex;
5179d5b80fdSSujith Manoharan #endif
5189d5b80fdSSujith Manoharan 
51921cb9879SVivek Natarajan 	struct delayed_work coex_period_work;
52021cb9879SVivek Natarajan 	struct delayed_work duty_cycle_work;
521fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
522fb9987d0SSujith 	struct ath9k_debug debug;
523fb9987d0SSujith #endif
524fb9987d0SSujith 	struct mutex mutex;
525fb9987d0SSujith };
526fb9987d0SSujith 
527fb9987d0SSujith static inline void ath_read_cachesize(struct ath_common *common, int *csz)
528fb9987d0SSujith {
529fb9987d0SSujith 	common->bus_ops->read_cachesize(common, csz);
530fb9987d0SSujith }
531fb9987d0SSujith 
53273908674SSujith Manoharan void ath9k_htc_reset(struct ath9k_htc_priv *priv);
53373908674SSujith Manoharan 
534832f6a18SSujith Manoharan void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
535832f6a18SSujith Manoharan 			    struct ieee80211_vif *vif);
536832f6a18SSujith Manoharan void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
537832f6a18SSujith Manoharan 			    struct ieee80211_vif *vif);
5389b674a02SSujith Manoharan void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
5399b674a02SSujith Manoharan 			     struct ieee80211_vif *vif);
540764580f5SSujith void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv);
541fb9987d0SSujith void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
5421c3652a5SVivek Natarajan 			     struct ieee80211_vif *vif);
5437c277349SSujith Manoharan void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv);
544f4c88991SSujith Manoharan void ath9k_htc_swba(struct ath9k_htc_priv *priv,
545f4c88991SSujith Manoharan 		    struct wmi_event_swba *swba);
546fb9987d0SSujith 
547fb9987d0SSujith void ath9k_htc_rxep(void *priv, struct sk_buff *skb,
548fb9987d0SSujith 		    enum htc_endpoint_id ep_id);
549fb9987d0SSujith void ath9k_htc_txep(void *priv, struct sk_buff *skb, enum htc_endpoint_id ep_id,
550fb9987d0SSujith 		    bool txok);
5519c6dda4eSSujith void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
5529c6dda4eSSujith 			enum htc_endpoint_id ep_id, bool txok);
553fb9987d0SSujith 
5543a0593efSSujith Manoharan int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
5553a0593efSSujith Manoharan 				u8 enable_coex);
556a236254cSSujith Manoharan void ath9k_htc_ani_work(struct work_struct *work);
557a236254cSSujith Manoharan void ath9k_htc_start_ani(struct ath9k_htc_priv *priv);
558a236254cSSujith Manoharan void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv);
559fb9987d0SSujith 
560fb9987d0SSujith int ath9k_tx_init(struct ath9k_htc_priv *priv);
5617d547eb4SSujith Manoharan int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
56236323f81SThomas Huehn 		       struct ieee80211_sta *sta,
5632c5d57f0SSujith Manoharan 		       struct sk_buff *skb, u8 slot, bool is_cab);
564fb9987d0SSujith void ath9k_tx_cleanup(struct ath9k_htc_priv *priv);
565e8c35a77SFelix Fietkau bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype);
566ca74b83bSSujith int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv);
567fb9987d0SSujith int get_hw_qnum(u16 queue, int *hwq_map);
568e1572c5eSSujith int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
569fb9987d0SSujith 		       struct ath9k_tx_queue_info *qinfo);
5708e86a547SSujith Manoharan void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv);
5718e86a547SSujith Manoharan void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv);
5722c5d57f0SSujith Manoharan int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv);
5732c5d57f0SSujith Manoharan void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot);
574b587fc81SSujith Manoharan void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv);
57527876a29SSujith Manoharan void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event);
57627876a29SSujith Manoharan void ath9k_tx_failed_tasklet(unsigned long data);
577859c3ca1SSujith Manoharan void ath9k_htc_tx_cleanup_timer(unsigned long data);
578fb9987d0SSujith 
579fb9987d0SSujith int ath9k_rx_init(struct ath9k_htc_priv *priv);
580fb9987d0SSujith void ath9k_rx_cleanup(struct ath9k_htc_priv *priv);
581fb9987d0SSujith void ath9k_host_rx_init(struct ath9k_htc_priv *priv);
582fb9987d0SSujith void ath9k_rx_tasklet(unsigned long data);
5830995d110SSujith u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
584fb9987d0SSujith 
585bde748a4SVivek Natarajan void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv);
586bde748a4SVivek Natarajan void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv);
587bde748a4SVivek Natarajan void ath9k_ps_work(struct work_struct *work);
588f933ebedSSujith Manoharan bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
589f933ebedSSujith Manoharan 			enum ath9k_power_mode mode);
590bde748a4SVivek Natarajan 
591fb9987d0SSujith void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
5921e1f4ad2SSujith Manoharan void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw);
593d244f21eSSujith Manoharan 
594156652bbSBen Greear struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv);
595156652bbSBen Greear 
596d244f21eSSujith Manoharan #ifdef CONFIG_MAC80211_LEDS
5971e51acaaSOleksij Rempel void ath9k_configure_leds(struct ath9k_htc_priv *priv);
598fb9987d0SSujith void ath9k_init_leds(struct ath9k_htc_priv *priv);
599fb9987d0SSujith void ath9k_deinit_leds(struct ath9k_htc_priv *priv);
600d244f21eSSujith Manoharan void ath9k_led_work(struct work_struct *work);
601d244f21eSSujith Manoharan #else
6021e51acaaSOleksij Rempel static inline void ath9k_configure_leds(struct ath9k_htc_priv *priv)
6031e51acaaSOleksij Rempel {
6041e51acaaSOleksij Rempel }
6051e51acaaSOleksij Rempel 
606d244f21eSSujith Manoharan static inline void ath9k_init_leds(struct ath9k_htc_priv *priv)
607d244f21eSSujith Manoharan {
608d244f21eSSujith Manoharan }
609d244f21eSSujith Manoharan 
610d244f21eSSujith Manoharan static inline void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
611d244f21eSSujith Manoharan {
612d244f21eSSujith Manoharan }
613d244f21eSSujith Manoharan 
614d244f21eSSujith Manoharan static inline void ath9k_led_work(struct work_struct *work)
615d244f21eSSujith Manoharan {
616d244f21eSSujith Manoharan }
617d244f21eSSujith Manoharan #endif
618fb9987d0SSujith 
619fb9987d0SSujith int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
620fa6e15e0SRajkumar Manoharan 			   u16 devid, char *product, u32 drv_info);
621fb9987d0SSujith void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
622fb9987d0SSujith #ifdef CONFIG_PM
623f933ebedSSujith Manoharan void ath9k_htc_suspend(struct htc_target *htc_handle);
624fb9987d0SSujith int ath9k_htc_resume(struct htc_target *htc_handle);
625fb9987d0SSujith #endif
626fb9987d0SSujith #ifdef CONFIG_ATH9K_HTC_DEBUGFS
627e1572c5eSSujith int ath9k_htc_init_debug(struct ath_hw *ah);
628fb9987d0SSujith #else
629e1572c5eSSujith static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
630fb9987d0SSujith #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
631fb9987d0SSujith 
632fb9987d0SSujith #endif /* HTC_H */
633