1 /*
2  * Copyright (c) 2010-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
4  *
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.
8  *
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.
16  */
17 
18 #ifndef CORE_H
19 #define CORE_H
20 
21 #include <linux/etherdevice.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/firmware.h>
24 #include <linux/sched.h>
25 #include <linux/circ_buf.h>
26 #include <net/cfg80211.h>
27 #include "htc.h"
28 #include "wmi.h"
29 #include "bmi.h"
30 #include "target.h"
31 
32 #define MAX_ATH6KL                        1
33 #define ATH6KL_MAX_RX_BUFFERS             16
34 #define ATH6KL_BUFFER_SIZE                1664
35 #define ATH6KL_MAX_AMSDU_RX_BUFFERS       4
36 #define ATH6KL_AMSDU_REFILL_THRESHOLD     3
37 #define ATH6KL_AMSDU_BUFFER_SIZE     (WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH + 128)
38 #define MAX_MSDU_SUBFRAME_PAYLOAD_LEN	1508
39 #define MIN_MSDU_SUBFRAME_PAYLOAD_LEN	46
40 
41 #define USER_SAVEDKEYS_STAT_INIT     0
42 #define USER_SAVEDKEYS_STAT_RUN      1
43 
44 #define ATH6KL_TX_TIMEOUT      10
45 #define ATH6KL_MAX_ENDPOINTS   4
46 #define MAX_NODE_NUM           15
47 
48 #define ATH6KL_APSD_ALL_FRAME		0xFFFF
49 #define ATH6KL_APSD_NUM_OF_AC		0x4
50 #define ATH6KL_APSD_FRAME_MASK		0xF
51 
52 /* Extra bytes for htc header alignment */
53 #define ATH6KL_HTC_ALIGN_BYTES 3
54 
55 /* MAX_HI_COOKIE_NUM are reserved for high priority traffic */
56 #define MAX_DEF_COOKIE_NUM                180
57 #define MAX_HI_COOKIE_NUM                 18	/* 10% of MAX_COOKIE_NUM */
58 #define MAX_COOKIE_NUM                 (MAX_DEF_COOKIE_NUM + MAX_HI_COOKIE_NUM)
59 
60 #define MAX_DEFAULT_SEND_QUEUE_DEPTH      (MAX_DEF_COOKIE_NUM / WMM_NUM_AC)
61 
62 #define DISCON_TIMER_INTVAL               10000  /* in msec */
63 
64 /* Channel dwell time in fg scan */
65 #define ATH6KL_FG_SCAN_INTERVAL		50 /* in ms */
66 
67 /* includes also the null byte */
68 #define ATH6KL_FIRMWARE_MAGIC               "QCA-ATH6KL"
69 
70 enum ath6kl_fw_ie_type {
71 	ATH6KL_FW_IE_FW_VERSION = 0,
72 	ATH6KL_FW_IE_TIMESTAMP = 1,
73 	ATH6KL_FW_IE_OTP_IMAGE = 2,
74 	ATH6KL_FW_IE_FW_IMAGE = 3,
75 	ATH6KL_FW_IE_PATCH_IMAGE = 4,
76 	ATH6KL_FW_IE_RESERVED_RAM_SIZE = 5,
77 	ATH6KL_FW_IE_CAPABILITIES = 6,
78 	ATH6KL_FW_IE_PATCH_ADDR = 7,
79 	ATH6KL_FW_IE_BOARD_ADDR = 8,
80 	ATH6KL_FW_IE_VIF_MAX = 9,
81 };
82 
83 enum ath6kl_fw_capability {
84 	ATH6KL_FW_CAPABILITY_HOST_P2P = 0,
85 	ATH6KL_FW_CAPABILITY_SCHED_SCAN = 1,
86 
87 	/*
88 	 * Firmware is capable of supporting P2P mgmt operations on a
89 	 * station interface. After group formation, the station
90 	 * interface will become a P2P client/GO interface as the case may be
91 	 */
92 	ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
93 
94 	/*
95 	 * Firmware has support to cleanup inactive stations
96 	 * in AP mode.
97 	 */
98 	ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
99 
100 	/* Firmware has support to override rsn cap of rsn ie */
101 	ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
102 
103 	/*
104 	 * Multicast support in WOW and host awake mode.
105 	 * Allow all multicast in host awake mode.
106 	 * Apply multicast filter in WOW mode.
107 	 */
108 	ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
109 
110 	/* Firmware supports enhanced bmiss detection */
111 	ATH6KL_FW_CAPABILITY_BMISS_ENHANCE,
112 
113 	/*
114 	 * FW supports matching of ssid in schedule scan
115 	 */
116 	ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST,
117 
118 	/* Firmware supports filtering BSS results by RSSI */
119 	ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
120 
121 	/* FW sets mac_addr[4] ^= 0x80 for newly created interfaces */
122 	ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR,
123 
124 	/* Firmware supports TX error rate notification */
125 	ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
126 
127 	/* supports WMI_SET_REGDOMAIN_CMDID command */
128 	ATH6KL_FW_CAPABILITY_REGDOMAIN,
129 
130 	/* Firmware supports sched scan decoupled from host sleep */
131 	ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2,
132 
133 	/*
134 	 * Firmware capability for hang detection through heart beat
135 	 * challenge messages.
136 	 */
137 	ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
138 
139 	/* WMI_SET_TX_SELECT_RATES_CMDID uses 64 bit size rate table */
140 	ATH6KL_FW_CAPABILITY_64BIT_RATES,
141 
142 	/* WMI_AP_CONN_INACT_CMDID uses minutes as units */
143 	ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS,
144 
145 	/* use low priority endpoint for all data */
146 	ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
147 
148 	/* ratetable is the 2 stream version (max MCS15) */
149 	ATH6KL_FW_CAPABILITY_RATETABLE_MCS15,
150 
151 	/* this needs to be last */
152 	ATH6KL_FW_CAPABILITY_MAX,
153 };
154 
155 #define ATH6KL_CAPABILITY_LEN (ALIGN(ATH6KL_FW_CAPABILITY_MAX, 32) / 32)
156 
157 struct ath6kl_fw_ie {
158 	__le32 id;
159 	__le32 len;
160 	u8 data[0];
161 };
162 
163 enum ath6kl_hw_flags {
164 	ATH6KL_HW_SDIO_CRC_ERROR_WAR	= BIT(3),
165 };
166 
167 #define ATH6KL_FW_API2_FILE "fw-2.bin"
168 #define ATH6KL_FW_API3_FILE "fw-3.bin"
169 #define ATH6KL_FW_API4_FILE "fw-4.bin"
170 
171 /* AR6003 1.0 definitions */
172 #define AR6003_HW_1_0_VERSION                 0x300002ba
173 
174 /* AR6003 2.0 definitions */
175 #define AR6003_HW_2_0_VERSION                 0x30000384
176 #define AR6003_HW_2_0_PATCH_DOWNLOAD_ADDRESS  0x57e910
177 #define AR6003_HW_2_0_FW_DIR			"ath6k/AR6003/hw2.0"
178 #define AR6003_HW_2_0_OTP_FILE			"otp.bin.z77"
179 #define AR6003_HW_2_0_FIRMWARE_FILE		"athwlan.bin.z77"
180 #define AR6003_HW_2_0_TCMD_FIRMWARE_FILE	"athtcmd_ram.bin"
181 #define AR6003_HW_2_0_PATCH_FILE		"data.patch.bin"
182 #define AR6003_HW_2_0_BOARD_DATA_FILE AR6003_HW_2_0_FW_DIR "/bdata.bin"
183 #define AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE \
184 			AR6003_HW_2_0_FW_DIR "/bdata.SD31.bin"
185 
186 /* AR6003 3.0 definitions */
187 #define AR6003_HW_2_1_1_VERSION                 0x30000582
188 #define AR6003_HW_2_1_1_FW_DIR			"ath6k/AR6003/hw2.1.1"
189 #define AR6003_HW_2_1_1_OTP_FILE		"otp.bin"
190 #define AR6003_HW_2_1_1_FIRMWARE_FILE		"athwlan.bin"
191 #define AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE	"athtcmd_ram.bin"
192 #define AR6003_HW_2_1_1_UTF_FIRMWARE_FILE	"utf.bin"
193 #define AR6003_HW_2_1_1_TESTSCRIPT_FILE	"nullTestFlow.bin"
194 #define AR6003_HW_2_1_1_PATCH_FILE		"data.patch.bin"
195 #define AR6003_HW_2_1_1_BOARD_DATA_FILE AR6003_HW_2_1_1_FW_DIR "/bdata.bin"
196 #define AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE	\
197 			AR6003_HW_2_1_1_FW_DIR "/bdata.SD31.bin"
198 
199 /* AR6004 1.0 definitions */
200 #define AR6004_HW_1_0_VERSION                 0x30000623
201 #define AR6004_HW_1_0_FW_DIR			"ath6k/AR6004/hw1.0"
202 #define AR6004_HW_1_0_FIRMWARE_FILE		"fw.ram.bin"
203 #define AR6004_HW_1_0_BOARD_DATA_FILE         AR6004_HW_1_0_FW_DIR "/bdata.bin"
204 #define AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE \
205 	AR6004_HW_1_0_FW_DIR "/bdata.DB132.bin"
206 
207 /* AR6004 1.1 definitions */
208 #define AR6004_HW_1_1_VERSION                 0x30000001
209 #define AR6004_HW_1_1_FW_DIR			"ath6k/AR6004/hw1.1"
210 #define AR6004_HW_1_1_FIRMWARE_FILE		"fw.ram.bin"
211 #define AR6004_HW_1_1_BOARD_DATA_FILE         AR6004_HW_1_1_FW_DIR "/bdata.bin"
212 #define AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE \
213 	AR6004_HW_1_1_FW_DIR "/bdata.DB132.bin"
214 
215 /* AR6004 1.2 definitions */
216 #define AR6004_HW_1_2_VERSION                 0x300007e8
217 #define AR6004_HW_1_2_FW_DIR			"ath6k/AR6004/hw1.2"
218 #define AR6004_HW_1_2_FIRMWARE_FILE           "fw.ram.bin"
219 #define AR6004_HW_1_2_BOARD_DATA_FILE         AR6004_HW_1_2_FW_DIR "/bdata.bin"
220 #define AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE \
221 	AR6004_HW_1_2_FW_DIR "/bdata.bin"
222 
223 /* AR6004 1.3 definitions */
224 #define AR6004_HW_1_3_VERSION			0x31c8088a
225 #define AR6004_HW_1_3_FW_DIR			"ath6k/AR6004/hw1.3"
226 #define AR6004_HW_1_3_FIRMWARE_FILE		"fw.ram.bin"
227 #define AR6004_HW_1_3_BOARD_DATA_FILE		"ath6k/AR6004/hw1.3/bdata.bin"
228 #define AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE	"ath6k/AR6004/hw1.3/bdata.bin"
229 
230 /* Per STA data, used in AP mode */
231 #define STA_PS_AWAKE		BIT(0)
232 #define	STA_PS_SLEEP		BIT(1)
233 #define	STA_PS_POLLED		BIT(2)
234 #define STA_PS_APSD_TRIGGER     BIT(3)
235 #define STA_PS_APSD_EOSP        BIT(4)
236 
237 /* HTC TX packet tagging definitions */
238 #define ATH6KL_CONTROL_PKT_TAG    HTC_TX_PACKET_TAG_USER_DEFINED
239 #define ATH6KL_DATA_PKT_TAG       (ATH6KL_CONTROL_PKT_TAG + 1)
240 
241 #define AR6003_CUST_DATA_SIZE 16
242 
243 #define AGGR_WIN_IDX(x, y)          ((x) % (y))
244 #define AGGR_INCR_IDX(x, y)         AGGR_WIN_IDX(((x) + 1), (y))
245 #define AGGR_DCRM_IDX(x, y)         AGGR_WIN_IDX(((x) - 1), (y))
246 #define ATH6KL_MAX_SEQ_NO		0xFFF
247 #define ATH6KL_NEXT_SEQ_NO(x)		(((x) + 1) & ATH6KL_MAX_SEQ_NO)
248 
249 #define NUM_OF_TIDS         8
250 #define AGGR_SZ_DEFAULT     8
251 
252 #define AGGR_WIN_SZ_MIN     2
253 #define AGGR_WIN_SZ_MAX     8
254 
255 #define TID_WINDOW_SZ(_x)   ((_x) << 1)
256 
257 #define AGGR_NUM_OF_FREE_NETBUFS    16
258 
259 #define AGGR_RX_TIMEOUT     100	/* in ms */
260 
261 #define WMI_TIMEOUT (2 * HZ)
262 
263 #define MBOX_YIELD_LIMIT 99
264 
265 #define ATH6KL_DEFAULT_LISTEN_INTVAL	100 /* in TUs */
266 #define ATH6KL_DEFAULT_BMISS_TIME	1500
267 #define ATH6KL_MAX_WOW_LISTEN_INTL	300 /* in TUs */
268 #define ATH6KL_MAX_BMISS_TIME		5000
269 
270 /* configuration lags */
271 /*
272  * ATH6KL_CONF_IGNORE_ERP_BARKER: Ignore the barker premable in
273  * ERP IE of beacon to determine the short premable support when
274  * sending (Re)Assoc req.
275  * ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN: Don't send the power
276  * module state transition failure events which happen during
277  * scan, to the host.
278  */
279 #define ATH6KL_CONF_IGNORE_ERP_BARKER		BIT(0)
280 #define ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN  BIT(1)
281 #define ATH6KL_CONF_ENABLE_11N			BIT(2)
282 #define ATH6KL_CONF_ENABLE_TX_BURST		BIT(3)
283 #define ATH6KL_CONF_UART_DEBUG			BIT(4)
284 
285 #define P2P_WILDCARD_SSID_LEN			7 /* DIRECT- */
286 
287 enum wlan_low_pwr_state {
288 	WLAN_POWER_STATE_ON,
289 	WLAN_POWER_STATE_CUT_PWR,
290 	WLAN_POWER_STATE_DEEP_SLEEP,
291 	WLAN_POWER_STATE_WOW
292 };
293 
294 enum sme_state {
295 	SME_DISCONNECTED,
296 	SME_CONNECTING,
297 	SME_CONNECTED
298 };
299 
300 struct skb_hold_q {
301 	struct sk_buff *skb;
302 	bool is_amsdu;
303 	u16 seq_no;
304 };
305 
306 struct rxtid {
307 	bool aggr;
308 	bool timer_mon;
309 	u16 win_sz;
310 	u16 seq_next;
311 	u32 hold_q_sz;
312 	struct skb_hold_q *hold_q;
313 	struct sk_buff_head q;
314 
315 	/*
316 	 * lock mainly protects seq_next and hold_q. Movement of seq_next
317 	 * needs to be protected between aggr_timeout() and
318 	 * aggr_process_recv_frm(). hold_q will be holding the pending
319 	 * reorder frames and it's access should also be protected.
320 	 * Some of the other fields like hold_q_sz, win_sz and aggr are
321 	 * initialized/reset when receiving addba/delba req, also while
322 	 * deleting aggr state all the pending buffers are flushed before
323 	 * resetting these fields, so there should not be any race in accessing
324 	 * these fields.
325 	 */
326 	spinlock_t lock;
327 };
328 
329 struct rxtid_stats {
330 	u32 num_into_aggr;
331 	u32 num_dups;
332 	u32 num_oow;
333 	u32 num_mpdu;
334 	u32 num_amsdu;
335 	u32 num_delivered;
336 	u32 num_timeouts;
337 	u32 num_hole;
338 	u32 num_bar;
339 };
340 
341 struct aggr_info_conn {
342 	u8 aggr_sz;
343 	u8 timer_scheduled;
344 	struct timer_list timer;
345 	struct net_device *dev;
346 	struct rxtid rx_tid[NUM_OF_TIDS];
347 	struct rxtid_stats stat[NUM_OF_TIDS];
348 	struct aggr_info *aggr_info;
349 };
350 
351 struct aggr_info {
352 	struct aggr_info_conn *aggr_conn;
353 	struct sk_buff_head rx_amsdu_freeq;
354 };
355 
356 struct ath6kl_wep_key {
357 	u8 key_index;
358 	u8 key_len;
359 	u8 key[64];
360 };
361 
362 #define ATH6KL_KEY_SEQ_LEN 8
363 
364 struct ath6kl_key {
365 	u8 key[WLAN_MAX_KEY_LEN];
366 	u8 key_len;
367 	u8 seq[ATH6KL_KEY_SEQ_LEN];
368 	u8 seq_len;
369 	u32 cipher;
370 };
371 
372 struct ath6kl_node_mapping {
373 	u8 mac_addr[ETH_ALEN];
374 	u8 ep_id;
375 	u8 tx_pend;
376 };
377 
378 struct ath6kl_cookie {
379 	struct sk_buff *skb;
380 	u32 map_no;
381 	struct htc_packet htc_pkt;
382 	struct ath6kl_cookie *arc_list_next;
383 };
384 
385 struct ath6kl_mgmt_buff {
386 	struct list_head list;
387 	u32 freq;
388 	u32 wait;
389 	u32 id;
390 	bool no_cck;
391 	size_t len;
392 	u8 buf[0];
393 };
394 
395 struct ath6kl_sta {
396 	u16 sta_flags;
397 	u8 mac[ETH_ALEN];
398 	u8 aid;
399 	u8 keymgmt;
400 	u8 ucipher;
401 	u8 auth;
402 	u8 wpa_ie[ATH6KL_MAX_IE];
403 	struct sk_buff_head psq;
404 
405 	/* protects psq, mgmt_psq, apsdq, and mgmt_psq_len fields */
406 	spinlock_t psq_lock;
407 
408 	struct list_head mgmt_psq;
409 	size_t mgmt_psq_len;
410 	u8 apsd_info;
411 	struct sk_buff_head apsdq;
412 	struct aggr_info_conn *aggr_conn;
413 };
414 
415 struct ath6kl_version {
416 	u32 target_ver;
417 	u32 wlan_ver;
418 	u32 abi_ver;
419 };
420 
421 struct ath6kl_bmi {
422 	u32 cmd_credits;
423 	bool done_sent;
424 	u8 *cmd_buf;
425 	u32 max_data_size;
426 	u32 max_cmd_size;
427 };
428 
429 struct target_stats {
430 	u64 tx_pkt;
431 	u64 tx_byte;
432 	u64 tx_ucast_pkt;
433 	u64 tx_ucast_byte;
434 	u64 tx_mcast_pkt;
435 	u64 tx_mcast_byte;
436 	u64 tx_bcast_pkt;
437 	u64 tx_bcast_byte;
438 	u64 tx_rts_success_cnt;
439 	u64 tx_pkt_per_ac[4];
440 
441 	u64 tx_err;
442 	u64 tx_fail_cnt;
443 	u64 tx_retry_cnt;
444 	u64 tx_mult_retry_cnt;
445 	u64 tx_rts_fail_cnt;
446 
447 	u64 rx_pkt;
448 	u64 rx_byte;
449 	u64 rx_ucast_pkt;
450 	u64 rx_ucast_byte;
451 	u64 rx_mcast_pkt;
452 	u64 rx_mcast_byte;
453 	u64 rx_bcast_pkt;
454 	u64 rx_bcast_byte;
455 	u64 rx_frgment_pkt;
456 
457 	u64 rx_err;
458 	u64 rx_crc_err;
459 	u64 rx_key_cache_miss;
460 	u64 rx_decrypt_err;
461 	u64 rx_dupl_frame;
462 
463 	u64 tkip_local_mic_fail;
464 	u64 tkip_cnter_measures_invoked;
465 	u64 tkip_replays;
466 	u64 tkip_fmt_err;
467 	u64 ccmp_fmt_err;
468 	u64 ccmp_replays;
469 
470 	u64 pwr_save_fail_cnt;
471 
472 	u64 cs_bmiss_cnt;
473 	u64 cs_low_rssi_cnt;
474 	u64 cs_connect_cnt;
475 	u64 cs_discon_cnt;
476 
477 	s32 tx_ucast_rate;
478 	s32 rx_ucast_rate;
479 
480 	u32 lq_val;
481 
482 	u32 wow_pkt_dropped;
483 	u16 wow_evt_discarded;
484 
485 	s16 noise_floor_calib;
486 	s16 cs_rssi;
487 	s16 cs_ave_beacon_rssi;
488 	u8 cs_ave_beacon_snr;
489 	u8 cs_last_roam_msec;
490 	u8 cs_snr;
491 
492 	u8 wow_host_pkt_wakeups;
493 	u8 wow_host_evt_wakeups;
494 
495 	u32 arp_received;
496 	u32 arp_matched;
497 	u32 arp_replied;
498 };
499 
500 struct ath6kl_mbox_info {
501 	u32 htc_addr;
502 	u32 htc_ext_addr;
503 	u32 htc_ext_sz;
504 
505 	u32 block_size;
506 
507 	u32 gmbox_addr;
508 
509 	u32 gmbox_sz;
510 };
511 
512 /*
513  * 802.11i defines an extended IV for use with non-WEP ciphers.
514  * When the EXTIV bit is set in the key id byte an additional
515  * 4 bytes immediately follow the IV for TKIP.  For CCMP the
516  * EXTIV bit is likewise set but the 8 bytes represent the
517  * CCMP header rather than IV+extended-IV.
518  */
519 
520 #define ATH6KL_KEYBUF_SIZE 16
521 #define ATH6KL_MICBUF_SIZE (8+8)	/* space for both tx and rx */
522 
523 #define ATH6KL_KEY_XMIT  0x01
524 #define ATH6KL_KEY_RECV  0x02
525 #define ATH6KL_KEY_DEFAULT   0x80	/* default xmit key */
526 
527 /* Initial group key for AP mode */
528 struct ath6kl_req_key {
529 	bool valid;
530 	u8 key_index;
531 	int key_type;
532 	u8 key[WLAN_MAX_KEY_LEN];
533 	u8 key_len;
534 };
535 
536 enum ath6kl_hif_type {
537 	ATH6KL_HIF_TYPE_SDIO,
538 	ATH6KL_HIF_TYPE_USB,
539 };
540 
541 enum ath6kl_htc_type {
542 	ATH6KL_HTC_TYPE_MBOX,
543 	ATH6KL_HTC_TYPE_PIPE,
544 };
545 
546 /* Max number of filters that hw supports */
547 #define ATH6K_MAX_MC_FILTERS_PER_LIST 7
548 struct ath6kl_mc_filter {
549 	struct list_head list;
550 	char hw_addr[ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE];
551 };
552 
553 struct ath6kl_htcap {
554 	bool ht_enable;
555 	u8 ampdu_factor;
556 	unsigned short cap_info;
557 };
558 
559 /*
560  * Driver's maximum limit, note that some firmwares support only one vif
561  * and the runtime (current) limit must be checked from ar->vif_max.
562  */
563 #define ATH6KL_VIF_MAX	3
564 
565 /* vif flags info */
566 enum ath6kl_vif_state {
567 	CONNECTED,
568 	CONNECT_PEND,
569 	WMM_ENABLED,
570 	NETQ_STOPPED,
571 	DTIM_EXPIRED,
572 	CLEAR_BSSFILTER_ON_BEACON,
573 	DTIM_PERIOD_AVAIL,
574 	WLAN_ENABLED,
575 	STATS_UPDATE_PEND,
576 	HOST_SLEEP_MODE_CMD_PROCESSED,
577 	NETDEV_MCAST_ALL_ON,
578 	NETDEV_MCAST_ALL_OFF,
579 	SCHED_SCANNING,
580 };
581 
582 struct ath6kl_vif {
583 	struct list_head list;
584 	struct wireless_dev wdev;
585 	struct net_device *ndev;
586 	struct ath6kl *ar;
587 	/* Lock to protect vif specific net_stats and flags */
588 	spinlock_t if_lock;
589 	u8 fw_vif_idx;
590 	unsigned long flags;
591 	int ssid_len;
592 	u8 ssid[IEEE80211_MAX_SSID_LEN];
593 	u8 dot11_auth_mode;
594 	u8 auth_mode;
595 	u8 prwise_crypto;
596 	u8 prwise_crypto_len;
597 	u8 grp_crypto;
598 	u8 grp_crypto_len;
599 	u8 def_txkey_index;
600 	u8 next_mode;
601 	u8 nw_type;
602 	u8 bssid[ETH_ALEN];
603 	u8 req_bssid[ETH_ALEN];
604 	u16 ch_hint;
605 	u16 bss_ch;
606 	struct ath6kl_wep_key wep_key_list[WMI_MAX_KEY_INDEX + 1];
607 	struct ath6kl_key keys[WMI_MAX_KEY_INDEX + 1];
608 	struct aggr_info *aggr_cntxt;
609 	struct ath6kl_htcap htcap[IEEE80211_NUM_BANDS];
610 
611 	struct timer_list disconnect_timer;
612 	struct timer_list sched_scan_timer;
613 
614 	struct cfg80211_scan_request *scan_req;
615 	enum sme_state sme_state;
616 	int reconnect_flag;
617 	u32 last_roc_id;
618 	u32 last_cancel_roc_id;
619 	u32 send_action_id;
620 	bool probe_req_report;
621 	u16 assoc_bss_beacon_int;
622 	u16 listen_intvl_t;
623 	u16 bmiss_time_t;
624 	u32 txe_intvl;
625 	u16 bg_scan_period;
626 	u8 assoc_bss_dtim_period;
627 	struct net_device_stats net_stats;
628 	struct target_stats target_stats;
629 	struct wmi_connect_cmd profile;
630 	u16 rsn_capab;
631 
632 	struct list_head mc_filter;
633 };
634 
635 static inline struct ath6kl_vif *ath6kl_vif_from_wdev(struct wireless_dev *wdev)
636 {
637 	return container_of(wdev, struct ath6kl_vif, wdev);
638 }
639 
640 #define WOW_LIST_ID		0
641 #define WOW_HOST_REQ_DELAY	500 /* ms */
642 
643 #define ATH6KL_SCHED_SCAN_RESULT_DELAY 5000 /* ms */
644 
645 /* Flag info */
646 enum ath6kl_dev_state {
647 	WMI_ENABLED,
648 	WMI_READY,
649 	WMI_CTRL_EP_FULL,
650 	TESTMODE,
651 	DESTROY_IN_PROGRESS,
652 	SKIP_SCAN,
653 	ROAM_TBL_PEND,
654 	FIRST_BOOT,
655 	RECOVERY_CLEANUP,
656 };
657 
658 enum ath6kl_state {
659 	ATH6KL_STATE_OFF,
660 	ATH6KL_STATE_ON,
661 	ATH6KL_STATE_SUSPENDING,
662 	ATH6KL_STATE_RESUMING,
663 	ATH6KL_STATE_DEEPSLEEP,
664 	ATH6KL_STATE_CUTPOWER,
665 	ATH6KL_STATE_WOW,
666 	ATH6KL_STATE_RECOVERY,
667 };
668 
669 /* Fw error recovery */
670 #define ATH6KL_HB_RESP_MISS_THRES	5
671 
672 enum ath6kl_fw_err {
673 	ATH6KL_FW_ASSERT,
674 	ATH6KL_FW_HB_RESP_FAILURE,
675 	ATH6KL_FW_EP_FULL,
676 };
677 
678 struct ath6kl {
679 	struct device *dev;
680 	struct wiphy *wiphy;
681 
682 	enum ath6kl_state state;
683 	unsigned int testmode;
684 
685 	struct ath6kl_bmi bmi;
686 	const struct ath6kl_hif_ops *hif_ops;
687 	const struct ath6kl_htc_ops *htc_ops;
688 	struct wmi *wmi;
689 	int tx_pending[ENDPOINT_MAX];
690 	int total_tx_data_pend;
691 	struct htc_target *htc_target;
692 	enum ath6kl_hif_type hif_type;
693 	void *hif_priv;
694 	struct list_head vif_list;
695 	/* Lock to avoid race in vif_list entries among add/del/traverse */
696 	spinlock_t list_lock;
697 	u8 num_vif;
698 	unsigned int vif_max;
699 	u8 max_norm_iface;
700 	u8 avail_idx_map;
701 
702 	/*
703 	 * Protects at least amsdu_rx_buffer_queue, ath6kl_alloc_cookie()
704 	 * calls, tx_pending and total_tx_data_pend.
705 	 */
706 	spinlock_t lock;
707 
708 	struct semaphore sem;
709 	u8 lrssi_roam_threshold;
710 	struct ath6kl_version version;
711 	u32 target_type;
712 	u8 tx_pwr;
713 	struct ath6kl_node_mapping node_map[MAX_NODE_NUM];
714 	u8 ibss_ps_enable;
715 	bool ibss_if_active;
716 	u8 node_num;
717 	u8 next_ep_id;
718 	struct ath6kl_cookie *cookie_list;
719 	u32 cookie_count;
720 	enum htc_endpoint_id ac2ep_map[WMM_NUM_AC];
721 	bool ac_stream_active[WMM_NUM_AC];
722 	u8 ac_stream_pri_map[WMM_NUM_AC];
723 	u8 hiac_stream_active_pri;
724 	u8 ep2ac_map[ENDPOINT_MAX];
725 	enum htc_endpoint_id ctrl_ep;
726 	struct ath6kl_htc_credit_info credit_state_info;
727 	u32 connect_ctrl_flags;
728 	u32 user_key_ctrl;
729 	u8 usr_bss_filter;
730 	struct ath6kl_sta sta_list[AP_MAX_NUM_STA];
731 	u8 sta_list_index;
732 	struct ath6kl_req_key ap_mode_bkey;
733 	struct sk_buff_head mcastpsq;
734 	u32 want_ch_switch;
735 	u16 last_ch;
736 
737 	/*
738 	 * FIXME: protects access to mcastpsq but is actually useless as
739 	 * all skbe_queue_*() functions provide serialisation themselves
740 	 */
741 	spinlock_t mcastpsq_lock;
742 
743 	u8 intra_bss;
744 	struct wmi_ap_mode_stat ap_stats;
745 	u8 ap_country_code[3];
746 	struct list_head amsdu_rx_buffer_queue;
747 	u8 rx_meta_ver;
748 	enum wlan_low_pwr_state wlan_pwr_state;
749 	u8 mac_addr[ETH_ALEN];
750 #define AR_MCAST_FILTER_MAC_ADDR_SIZE  4
751 	struct {
752 		void *rx_report;
753 		size_t rx_report_len;
754 	} tm;
755 
756 	struct ath6kl_hw {
757 		u32 id;
758 		const char *name;
759 		u32 dataset_patch_addr;
760 		u32 app_load_addr;
761 		u32 app_start_override_addr;
762 		u32 board_ext_data_addr;
763 		u32 reserved_ram_size;
764 		u32 board_addr;
765 		u32 refclk_hz;
766 		u32 uarttx_pin;
767 		u32 testscript_addr;
768 		enum wmi_phy_cap cap;
769 
770 		u32 flags;
771 
772 		struct ath6kl_hw_fw {
773 			const char *dir;
774 			const char *otp;
775 			const char *fw;
776 			const char *tcmd;
777 			const char *patch;
778 			const char *utf;
779 			const char *testscript;
780 		} fw;
781 
782 		const char *fw_board;
783 		const char *fw_default_board;
784 	} hw;
785 
786 	u16 conf_flags;
787 	u16 suspend_mode;
788 	u16 wow_suspend_mode;
789 	wait_queue_head_t event_wq;
790 	struct ath6kl_mbox_info mbox_info;
791 
792 	struct ath6kl_cookie cookie_mem[MAX_COOKIE_NUM];
793 	unsigned long flag;
794 
795 	u8 *fw_board;
796 	size_t fw_board_len;
797 
798 	u8 *fw_otp;
799 	size_t fw_otp_len;
800 
801 	u8 *fw;
802 	size_t fw_len;
803 
804 	u8 *fw_patch;
805 	size_t fw_patch_len;
806 
807 	u8 *fw_testscript;
808 	size_t fw_testscript_len;
809 
810 	unsigned int fw_api;
811 	unsigned long fw_capabilities[ATH6KL_CAPABILITY_LEN];
812 
813 	struct workqueue_struct *ath6kl_wq;
814 
815 	struct dentry *debugfs_phy;
816 
817 	bool p2p;
818 
819 	bool wiphy_registered;
820 
821 	struct ath6kl_fw_recovery {
822 		struct work_struct recovery_work;
823 		unsigned long err_reason;
824 		unsigned long hb_poll;
825 		struct timer_list hb_timer;
826 		u32 seq_num;
827 		bool hb_pending;
828 		u8 hb_misscnt;
829 		bool enable;
830 	} fw_recovery;
831 
832 #ifdef CONFIG_ATH6KL_DEBUG
833 	struct {
834 		struct sk_buff_head fwlog_queue;
835 		struct completion fwlog_completion;
836 		bool fwlog_open;
837 
838 		u32 fwlog_mask;
839 
840 		unsigned int dbgfs_diag_reg;
841 		u32 diag_reg_addr_wr;
842 		u32 diag_reg_val_wr;
843 
844 		struct {
845 			unsigned int invalid_rate;
846 		} war_stats;
847 
848 		u8 *roam_tbl;
849 		unsigned int roam_tbl_len;
850 
851 		u8 keepalive;
852 		u8 disc_timeout;
853 	} debug;
854 #endif /* CONFIG_ATH6KL_DEBUG */
855 };
856 
857 static inline struct ath6kl *ath6kl_priv(struct net_device *dev)
858 {
859 	return ((struct ath6kl_vif *) netdev_priv(dev))->ar;
860 }
861 
862 static inline u32 ath6kl_get_hi_item_addr(struct ath6kl *ar,
863 					  u32 item_offset)
864 {
865 	u32 addr = 0;
866 
867 	if (ar->target_type == TARGET_TYPE_AR6003)
868 		addr = ATH6KL_AR6003_HI_START_ADDR + item_offset;
869 	else if (ar->target_type == TARGET_TYPE_AR6004)
870 		addr = ATH6KL_AR6004_HI_START_ADDR + item_offset;
871 
872 	return addr;
873 }
874 
875 int ath6kl_configure_target(struct ath6kl *ar);
876 void ath6kl_detect_error(unsigned long ptr);
877 void disconnect_timer_handler(unsigned long ptr);
878 void init_netdev(struct net_device *dev);
879 void ath6kl_cookie_init(struct ath6kl *ar);
880 void ath6kl_cookie_cleanup(struct ath6kl *ar);
881 void ath6kl_rx(struct htc_target *target, struct htc_packet *packet);
882 void ath6kl_tx_complete(struct htc_target *context,
883 			struct list_head *packet_queue);
884 enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
885 					       struct htc_packet *packet);
886 void ath6kl_stop_txrx(struct ath6kl *ar);
887 void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar);
888 int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value);
889 int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length);
890 int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value);
891 int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length);
892 int ath6kl_read_fwlogs(struct ath6kl *ar);
893 void ath6kl_init_profile_info(struct ath6kl_vif *vif);
894 void ath6kl_tx_data_cleanup(struct ath6kl *ar);
895 
896 struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar);
897 void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie);
898 int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev);
899 
900 struct aggr_info *aggr_init(struct ath6kl_vif *vif);
901 void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info,
902 		    struct aggr_info_conn *aggr_conn);
903 void ath6kl_rx_refill(struct htc_target *target,
904 		      enum htc_endpoint_id endpoint);
905 void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count);
906 struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
907 					    enum htc_endpoint_id endpoint,
908 					    int len);
909 void aggr_module_destroy(struct aggr_info *aggr_info);
910 void aggr_reset_state(struct aggr_info_conn *aggr_conn);
911 
912 struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr);
913 struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid);
914 
915 void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver,
916 			enum wmi_phy_cap cap);
917 int ath6kl_control_tx(void *devt, struct sk_buff *skb,
918 		      enum htc_endpoint_id eid);
919 void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel,
920 			  u8 *bssid, u16 listen_int,
921 			  u16 beacon_int, enum network_type net_type,
922 			  u8 beacon_ie_len, u8 assoc_req_len,
923 			  u8 assoc_resp_len, u8 *assoc_info);
924 void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel);
925 void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
926 				u8 keymgmt, u8 ucipher, u8 auth,
927 				u8 assoc_req_len, u8 *assoc_info, u8 apsd_info);
928 void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason,
929 			     u8 *bssid, u8 assoc_resp_len,
930 			     u8 *assoc_info, u16 prot_reason_status);
931 void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast);
932 void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr);
933 void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status);
934 void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len);
935 void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active);
936 enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac);
937 
938 void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid);
939 
940 void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif);
941 void ath6kl_disconnect(struct ath6kl_vif *vif);
942 void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid);
943 void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid, u16 seq_no,
944 			     u8 win_sz);
945 void ath6kl_wakeup_event(void *dev);
946 
947 void ath6kl_init_control_info(struct ath6kl_vif *vif);
948 struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar);
949 void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready);
950 int ath6kl_init_hw_start(struct ath6kl *ar);
951 int ath6kl_init_hw_stop(struct ath6kl *ar);
952 int ath6kl_init_fetch_firmwares(struct ath6kl *ar);
953 int ath6kl_init_hw_params(struct ath6kl *ar);
954 
955 void ath6kl_check_wow_status(struct ath6kl *ar);
956 
957 void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb);
958 void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
959 
960 struct ath6kl *ath6kl_core_create(struct device *dev);
961 int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type);
962 void ath6kl_core_cleanup(struct ath6kl *ar);
963 void ath6kl_core_destroy(struct ath6kl *ar);
964 
965 /* Fw error recovery */
966 void ath6kl_init_hw_restart(struct ath6kl *ar);
967 void ath6kl_recovery_err_notify(struct ath6kl *ar, enum ath6kl_fw_err reason);
968 void ath6kl_recovery_hb_event(struct ath6kl *ar, u32 cookie);
969 void ath6kl_recovery_init(struct ath6kl *ar);
970 void ath6kl_recovery_cleanup(struct ath6kl *ar);
971 void ath6kl_recovery_suspend(struct ath6kl *ar);
972 void ath6kl_recovery_resume(struct ath6kl *ar);
973 #endif /* CORE_H */
974