6b9512140e7aa6b21d36e55d128486cf29210e74
[cascardo/linux.git] / drivers / net / wireless / mwifiex / main.h
1 /*
2  * Marvell Wireless LAN device driver: major data structures and prototypes
3  *
4  * Copyright (C) 2011-2014, Marvell International Ltd.
5  *
6  * This software file (the "File") is distributed by Marvell International
7  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8  * (the "License").  You may use, redistribute and/or modify this File in
9  * accordance with the terms and conditions of the License, a copy of which
10  * is available by writing to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13  *
14  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
17  * this warranty disclaimer.
18  */
19
20 #ifndef _MWIFIEX_MAIN_H_
21 #define _MWIFIEX_MAIN_H_
22
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/sched.h>
26 #include <linux/semaphore.h>
27 #include <linux/ip.h>
28 #include <linux/skbuff.h>
29 #include <linux/if_arp.h>
30 #include <linux/etherdevice.h>
31 #include <net/sock.h>
32 #include <net/lib80211.h>
33 #include <linux/vmalloc.h>
34 #include <linux/firmware.h>
35 #include <linux/ctype.h>
36 #include <linux/of.h>
37 #include <linux/idr.h>
38 #include <linux/inetdevice.h>
39 #include <linux/devcoredump.h>
40
41 #include "decl.h"
42 #include "ioctl.h"
43 #include "util.h"
44 #include "fw.h"
45 #include "pcie.h"
46 #include "usb.h"
47 #include "sdio.h"
48
49 extern const char driver_version[];
50
51 enum {
52         MWIFIEX_ASYNC_CMD,
53         MWIFIEX_SYNC_CMD
54 };
55
56 #define MWIFIEX_DRIVER_MODE_STA                 BIT(0)
57 #define MWIFIEX_DRIVER_MODE_UAP                 BIT(1)
58 #define MWIFIEX_DRIVER_MODE_P2P                 BIT(2)
59 #define MWIFIEX_DRIVER_MODE_BITMASK             (BIT(0) | BIT(1) | BIT(2))
60
61 #define MWIFIEX_MAX_AP                          64
62
63 #define MWIFIEX_MAX_PKTS_TXQ                    16
64
65 #define MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT        (5 * HZ)
66
67 #define MWIFIEX_TIMER_10S                       10000
68 #define MWIFIEX_TIMER_1S                        1000
69
70 #define MAX_TX_PENDING      100
71 #define LOW_TX_PENDING      80
72
73 #define HIGH_RX_PENDING     50
74 #define LOW_RX_PENDING      20
75
76 #define MWIFIEX_UPLD_SIZE               (2312)
77
78 #define MAX_EVENT_SIZE                  2048
79
80 #define ARP_FILTER_MAX_BUF_SIZE         68
81
82 #define MWIFIEX_KEY_BUFFER_SIZE                 16
83 #define MWIFIEX_DEFAULT_LISTEN_INTERVAL 10
84 #define MWIFIEX_MAX_REGION_CODE         7
85
86 #define DEFAULT_BCN_AVG_FACTOR          8
87 #define DEFAULT_DATA_AVG_FACTOR         8
88
89 #define FIRST_VALID_CHANNEL                             0xff
90 #define DEFAULT_AD_HOC_CHANNEL                  6
91 #define DEFAULT_AD_HOC_CHANNEL_A                36
92
93 #define DEFAULT_BCN_MISS_TIMEOUT                5
94
95 #define MAX_SCAN_BEACON_BUFFER                  8000
96
97 #define SCAN_BEACON_ENTRY_PAD                   6
98
99 #define MWIFIEX_PASSIVE_SCAN_CHAN_TIME  110
100 #define MWIFIEX_ACTIVE_SCAN_CHAN_TIME   30
101 #define MWIFIEX_SPECIFIC_SCAN_CHAN_TIME 30
102 #define MWIFIEX_DEF_SCAN_CHAN_GAP_TIME  50
103
104 #define SCAN_RSSI(RSSI)                                 (0x100 - ((u8)(RSSI)))
105
106 #define MWIFIEX_MAX_TOTAL_SCAN_TIME     (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S)
107
108 #define RSN_GTK_OUI_OFFSET                              2
109
110 #define MWIFIEX_OUI_NOT_PRESENT                 0
111 #define MWIFIEX_OUI_PRESENT                             1
112
113 #define PKT_TYPE_MGMT   0xE5
114
115 /*
116  * Do not check for data_received for USB, as data_received
117  * is handled in mwifiex_usb_recv for USB
118  */
119 #define IS_CARD_RX_RCVD(adapter) (adapter->cmd_resp_received || \
120                                 adapter->event_received || \
121                                 adapter->data_received)
122
123 #define MWIFIEX_TYPE_CMD                                1
124 #define MWIFIEX_TYPE_DATA                               0
125 #define MWIFIEX_TYPE_AGGR_DATA                          10
126 #define MWIFIEX_TYPE_EVENT                              3
127
128 #define MAX_BITMAP_RATES_SIZE                   18
129
130 #define MAX_CHANNEL_BAND_BG     14
131 #define MAX_CHANNEL_BAND_A      165
132
133 #define MAX_FREQUENCY_BAND_BG   2484
134
135 #define MWIFIEX_EVENT_HEADER_LEN           4
136 #define MWIFIEX_UAP_EVENT_EXTRA_HEADER     2
137
138 #define MWIFIEX_TYPE_LEN                        4
139 #define MWIFIEX_USB_TYPE_CMD                    0xF00DFACE
140 #define MWIFIEX_USB_TYPE_DATA                   0xBEADC0DE
141 #define MWIFIEX_USB_TYPE_EVENT                  0xBEEFFACE
142
143 /* Threshold for tx_timeout_cnt before we trigger a card reset */
144 #define TX_TIMEOUT_THRESHOLD    6
145
146 #define MWIFIEX_DRV_INFO_SIZE_MAX 0x40000
147
148 /* Address alignment */
149 #define MWIFIEX_ALIGN_ADDR(p, a) (((long)(p) + (a) - 1) & ~((a) - 1))
150
151 /**
152  *enum mwifiex_debug_level  -  marvell wifi debug level
153  */
154 enum MWIFIEX_DEBUG_LEVEL {
155         MWIFIEX_DBG_MSG         = 0x00000001,
156         MWIFIEX_DBG_FATAL       = 0x00000002,
157         MWIFIEX_DBG_ERROR       = 0x00000004,
158         MWIFIEX_DBG_DATA        = 0x00000008,
159         MWIFIEX_DBG_CMD         = 0x00000010,
160         MWIFIEX_DBG_EVENT       = 0x00000020,
161         MWIFIEX_DBG_INTR        = 0x00000040,
162         MWIFIEX_DBG_IOCTL       = 0x00000080,
163
164         MWIFIEX_DBG_MPA_D       = 0x00008000,
165         MWIFIEX_DBG_DAT_D       = 0x00010000,
166         MWIFIEX_DBG_CMD_D       = 0x00020000,
167         MWIFIEX_DBG_EVT_D       = 0x00040000,
168         MWIFIEX_DBG_FW_D        = 0x00080000,
169         MWIFIEX_DBG_IF_D        = 0x00100000,
170
171         MWIFIEX_DBG_ENTRY       = 0x10000000,
172         MWIFIEX_DBG_WARN        = 0x20000000,
173         MWIFIEX_DBG_INFO        = 0x40000000,
174         MWIFIEX_DBG_DUMP        = 0x80000000,
175
176         MWIFIEX_DBG_ANY         = 0xffffffff
177 };
178
179 #define MWIFIEX_DEFAULT_DEBUG_MASK      (MWIFIEX_DBG_MSG | \
180                                         MWIFIEX_DBG_FATAL | \
181                                         MWIFIEX_DBG_ERROR)
182
183 #define mwifiex_dbg(adapter, dbg_mask, fmt, args...)            \
184 do {                                                            \
185         if ((adapter)->debug_mask & MWIFIEX_DBG_##dbg_mask)     \
186                 if ((adapter)->dev)                             \
187                         dev_info((adapter)->dev, fmt, ## args); \
188 } while (0)
189
190 #define DEBUG_DUMP_DATA_MAX_LEN         128
191 #define mwifiex_dbg_dump(adapter, dbg_mask, str, buf, len)      \
192 do {                                                            \
193         if ((adapter)->debug_mask & MWIFIEX_DBG_##dbg_mask)     \
194                 print_hex_dump(KERN_DEBUG, str,                 \
195                                DUMP_PREFIX_OFFSET, 16, 1,       \
196                                buf, len, false);                \
197 } while (0)
198
199 struct mwifiex_dbg {
200         u32 num_cmd_host_to_card_failure;
201         u32 num_cmd_sleep_cfm_host_to_card_failure;
202         u32 num_tx_host_to_card_failure;
203         u32 num_event_deauth;
204         u32 num_event_disassoc;
205         u32 num_event_link_lost;
206         u32 num_cmd_deauth;
207         u32 num_cmd_assoc_success;
208         u32 num_cmd_assoc_failure;
209         u32 num_tx_timeout;
210         u16 timeout_cmd_id;
211         u16 timeout_cmd_act;
212         u16 last_cmd_id[DBG_CMD_NUM];
213         u16 last_cmd_act[DBG_CMD_NUM];
214         u16 last_cmd_index;
215         u16 last_cmd_resp_id[DBG_CMD_NUM];
216         u16 last_cmd_resp_index;
217         u16 last_event[DBG_CMD_NUM];
218         u16 last_event_index;
219 };
220
221 enum MWIFIEX_HARDWARE_STATUS {
222         MWIFIEX_HW_STATUS_READY,
223         MWIFIEX_HW_STATUS_INITIALIZING,
224         MWIFIEX_HW_STATUS_INIT_DONE,
225         MWIFIEX_HW_STATUS_RESET,
226         MWIFIEX_HW_STATUS_CLOSING,
227         MWIFIEX_HW_STATUS_NOT_READY
228 };
229
230 enum MWIFIEX_802_11_POWER_MODE {
231         MWIFIEX_802_11_POWER_MODE_CAM,
232         MWIFIEX_802_11_POWER_MODE_PSP
233 };
234
235 struct mwifiex_tx_param {
236         u32 next_pkt_len;
237 };
238
239 enum MWIFIEX_PS_STATE {
240         PS_STATE_AWAKE,
241         PS_STATE_PRE_SLEEP,
242         PS_STATE_SLEEP_CFM,
243         PS_STATE_SLEEP
244 };
245
246 enum mwifiex_iface_type {
247         MWIFIEX_SDIO,
248         MWIFIEX_PCIE,
249         MWIFIEX_USB
250 };
251
252 struct mwifiex_add_ba_param {
253         u32 tx_win_size;
254         u32 rx_win_size;
255         u32 timeout;
256         u8 tx_amsdu;
257         u8 rx_amsdu;
258 };
259
260 struct mwifiex_tx_aggr {
261         u8 ampdu_user;
262         u8 ampdu_ap;
263         u8 amsdu;
264 };
265
266 enum mwifiex_ba_status {
267         BA_SETUP_NONE = 0,
268         BA_SETUP_INPROGRESS,
269         BA_SETUP_COMPLETE
270 };
271
272 struct mwifiex_ra_list_tbl {
273         struct list_head list;
274         struct sk_buff_head skb_head;
275         u8 ra[ETH_ALEN];
276         u32 is_11n_enabled;
277         u16 max_amsdu;
278         u16 ba_pkt_count;
279         u8 ba_packet_thr;
280         enum mwifiex_ba_status ba_status;
281         u8 amsdu_in_ampdu;
282         u16 total_pkt_count;
283         bool tdls_link;
284         bool tx_paused;
285 };
286
287 struct mwifiex_tid_tbl {
288         struct list_head ra_list;
289 };
290
291 #define WMM_HIGHEST_PRIORITY            7
292 #define HIGH_PRIO_TID                           7
293 #define LOW_PRIO_TID                            0
294
295 struct mwifiex_wmm_desc {
296         struct mwifiex_tid_tbl tid_tbl_ptr[MAX_NUM_TID];
297         u32 packets_out[MAX_NUM_TID];
298         u32 pkts_paused[MAX_NUM_TID];
299         /* spin lock to protect ra_list */
300         spinlock_t ra_list_spinlock;
301         struct mwifiex_wmm_ac_status ac_status[IEEE80211_NUM_ACS];
302         enum mwifiex_wmm_ac_e ac_down_graded_vals[IEEE80211_NUM_ACS];
303         u32 drv_pkt_delay_max;
304         u8 queue_priority[IEEE80211_NUM_ACS];
305         u32 user_pri_pkt_tx_ctrl[WMM_HIGHEST_PRIORITY + 1];     /* UP: 0 to 7 */
306         /* Number of transmit packets queued */
307         atomic_t tx_pkts_queued;
308         /* Tracks highest priority with a packet queued */
309         atomic_t highest_queued_prio;
310 };
311
312 struct mwifiex_802_11_security {
313         u8 wpa_enabled;
314         u8 wpa2_enabled;
315         u8 wapi_enabled;
316         u8 wapi_key_on;
317         u8 wep_enabled;
318         u32 authentication_mode;
319         u8 is_authtype_auto;
320         u32 encryption_mode;
321 };
322
323 struct ieee_types_header {
324         u8 element_id;
325         u8 len;
326 } __packed;
327
328 struct ieee_types_vendor_specific {
329         struct ieee_types_vendor_header vend_hdr;
330         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_vendor_header)];
331 } __packed;
332
333 struct ieee_types_generic {
334         struct ieee_types_header ieee_hdr;
335         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_header)];
336 } __packed;
337
338 struct ieee_types_bss_co_2040 {
339         struct ieee_types_header ieee_hdr;
340         u8 bss_2040co;
341 } __packed;
342
343 struct ieee_types_extcap {
344         struct ieee_types_header ieee_hdr;
345         u8 ext_capab[8];
346 } __packed;
347
348 struct ieee_types_vht_cap {
349         struct ieee_types_header ieee_hdr;
350         struct ieee80211_vht_cap vhtcap;
351 } __packed;
352
353 struct ieee_types_vht_oper {
354         struct ieee_types_header ieee_hdr;
355         struct ieee80211_vht_operation vhtoper;
356 } __packed;
357
358 struct ieee_types_aid {
359         struct ieee_types_header ieee_hdr;
360         u16 aid;
361 } __packed;
362
363 struct mwifiex_bssdescriptor {
364         u8 mac_address[ETH_ALEN];
365         struct cfg80211_ssid ssid;
366         u32 privacy;
367         s32 rssi;
368         u32 channel;
369         u32 freq;
370         u16 beacon_period;
371         u8 erp_flags;
372         u32 bss_mode;
373         u8 supported_rates[MWIFIEX_SUPPORTED_RATES];
374         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
375         /* Network band.
376          * BAND_B(0x01): 'b' band
377          * BAND_G(0x02): 'g' band
378          * BAND_A(0X04): 'a' band
379          */
380         u16 bss_band;
381         u64 fw_tsf;
382         u64 timestamp;
383         union ieee_types_phy_param_set phy_param_set;
384         union ieee_types_ss_param_set ss_param_set;
385         u16 cap_info_bitmap;
386         struct ieee_types_wmm_parameter wmm_ie;
387         u8  disable_11n;
388         struct ieee80211_ht_cap *bcn_ht_cap;
389         u16 ht_cap_offset;
390         struct ieee80211_ht_operation *bcn_ht_oper;
391         u16 ht_info_offset;
392         u8 *bcn_bss_co_2040;
393         u16 bss_co_2040_offset;
394         u8 *bcn_ext_cap;
395         u16 ext_cap_offset;
396         struct ieee80211_vht_cap *bcn_vht_cap;
397         u16 vht_cap_offset;
398         struct ieee80211_vht_operation *bcn_vht_oper;
399         u16 vht_info_offset;
400         struct ieee_types_oper_mode_ntf *oper_mode;
401         u16 oper_mode_offset;
402         u8 disable_11ac;
403         struct ieee_types_vendor_specific *bcn_wpa_ie;
404         u16 wpa_offset;
405         struct ieee_types_generic *bcn_rsn_ie;
406         u16 rsn_offset;
407         struct ieee_types_generic *bcn_wapi_ie;
408         u16 wapi_offset;
409         u8 *beacon_buf;
410         u32 beacon_buf_size;
411         u8 sensed_11h;
412         u8 local_constraint;
413         u8 chan_sw_ie_present;
414 };
415
416 struct mwifiex_current_bss_params {
417         struct mwifiex_bssdescriptor bss_descriptor;
418         u8 wmm_enabled;
419         u8 wmm_uapsd_enabled;
420         u8 band;
421         u32 num_of_rates;
422         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
423 };
424
425 struct mwifiex_sleep_params {
426         u16 sp_error;
427         u16 sp_offset;
428         u16 sp_stable_time;
429         u8 sp_cal_control;
430         u8 sp_ext_sleep_clk;
431         u16 sp_reserved;
432 };
433
434 struct mwifiex_sleep_period {
435         u16 period;
436         u16 reserved;
437 };
438
439 struct mwifiex_wep_key {
440         u32 length;
441         u32 key_index;
442         u32 key_length;
443         u8 key_material[MWIFIEX_KEY_BUFFER_SIZE];
444 };
445
446 #define MAX_REGION_CHANNEL_NUM  2
447
448 struct mwifiex_chan_freq_power {
449         u16 channel;
450         u32 freq;
451         u16 max_tx_power;
452         u8 unsupported;
453 };
454
455 enum state_11d_t {
456         DISABLE_11D = 0,
457         ENABLE_11D = 1,
458 };
459
460 #define MWIFIEX_MAX_TRIPLET_802_11D             83
461
462 struct mwifiex_802_11d_domain_reg {
463         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
464         u8 no_of_triplet;
465         struct ieee80211_country_ie_triplet
466                 triplet[MWIFIEX_MAX_TRIPLET_802_11D];
467 };
468
469 struct mwifiex_vendor_spec_cfg_ie {
470         u16 mask;
471         u16 flag;
472         u8 ie[MWIFIEX_MAX_VSIE_LEN];
473 };
474
475 struct wps {
476         u8 session_enable;
477 };
478
479 struct mwifiex_roc_cfg {
480         u64 cookie;
481         struct ieee80211_channel chan;
482 };
483
484 #define MWIFIEX_FW_DUMP_IDX             0xff
485 #define MWIFIEX_DRV_INFO_IDX            20
486 #define FW_DUMP_MAX_NAME_LEN            8
487 #define FW_DUMP_HOST_READY              0xEE
488 #define FW_DUMP_DONE                    0xFF
489 #define FW_DUMP_READ_DONE               0xFE
490
491 struct memory_type_mapping {
492         u8 mem_name[FW_DUMP_MAX_NAME_LEN];
493         u8 *mem_ptr;
494         u32 mem_size;
495         u8 done_flag;
496 };
497
498 enum rdwr_status {
499         RDWR_STATUS_SUCCESS = 0,
500         RDWR_STATUS_FAILURE = 1,
501         RDWR_STATUS_DONE = 2
502 };
503
504 enum mwifiex_iface_work_flags {
505         MWIFIEX_IFACE_WORK_DEVICE_DUMP,
506         MWIFIEX_IFACE_WORK_CARD_RESET,
507 };
508
509 struct mwifiex_adapter;
510 struct mwifiex_private;
511
512 struct mwifiex_private {
513         struct mwifiex_adapter *adapter;
514         u8 bss_type;
515         u8 bss_role;
516         u8 bss_priority;
517         u8 bss_num;
518         u8 bss_started;
519         u8 frame_type;
520         u8 curr_addr[ETH_ALEN];
521         u8 media_connected;
522         u8 port_open;
523         u32 num_tx_timeout;
524         /* track consecutive timeout */
525         u8 tx_timeout_cnt;
526         struct net_device *netdev;
527         struct net_device_stats stats;
528         u16 curr_pkt_filter;
529         u32 bss_mode;
530         u32 pkt_tx_ctrl;
531         u16 tx_power_level;
532         u8 max_tx_power_level;
533         u8 min_tx_power_level;
534         u8 tx_rate;
535         u8 tx_htinfo;
536         u8 rxpd_htinfo;
537         u8 rxpd_rate;
538         u16 rate_bitmap;
539         u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
540         u32 data_rate;
541         u8 is_data_rate_auto;
542         u16 bcn_avg_factor;
543         u16 data_avg_factor;
544         s16 data_rssi_last;
545         s16 data_nf_last;
546         s16 data_rssi_avg;
547         s16 data_nf_avg;
548         s16 bcn_rssi_last;
549         s16 bcn_nf_last;
550         s16 bcn_rssi_avg;
551         s16 bcn_nf_avg;
552         struct mwifiex_bssdescriptor *attempted_bss_desc;
553         struct cfg80211_ssid prev_ssid;
554         u8 prev_bssid[ETH_ALEN];
555         struct mwifiex_current_bss_params curr_bss_params;
556         u16 beacon_period;
557         u8 dtim_period;
558         u16 listen_interval;
559         u16 atim_window;
560         u8 adhoc_channel;
561         u8 adhoc_is_link_sensed;
562         u8 adhoc_state;
563         struct mwifiex_802_11_security sec_info;
564         struct mwifiex_wep_key wep_key[NUM_WEP_KEYS];
565         u16 wep_key_curr_index;
566         u8 wpa_ie[256];
567         u8 wpa_ie_len;
568         u8 wpa_is_gtk_set;
569         struct host_cmd_ds_802_11_key_material aes_key;
570         struct host_cmd_ds_802_11_key_material_v2 aes_key_v2;
571         u8 wapi_ie[256];
572         u8 wapi_ie_len;
573         u8 *wps_ie;
574         u8 wps_ie_len;
575         u8 wmm_required;
576         u8 wmm_enabled;
577         u8 wmm_qosinfo;
578         struct mwifiex_wmm_desc wmm;
579         atomic_t wmm_tx_pending[IEEE80211_NUM_ACS];
580         struct list_head sta_list;
581         /* spin lock for associated station/TDLS peers list */
582         spinlock_t sta_list_spinlock;
583         struct list_head auto_tdls_list;
584         /* spin lock for auto TDLS peer list */
585         spinlock_t auto_tdls_lock;
586         struct list_head tx_ba_stream_tbl_ptr;
587         /* spin lock for tx_ba_stream_tbl_ptr queue */
588         spinlock_t tx_ba_stream_tbl_lock;
589         struct mwifiex_tx_aggr aggr_prio_tbl[MAX_NUM_TID];
590         struct mwifiex_add_ba_param add_ba_param;
591         u16 rx_seq[MAX_NUM_TID];
592         u8 tos_to_tid_inv[MAX_NUM_TID];
593         struct list_head rx_reorder_tbl_ptr;
594         /* spin lock for rx_reorder_tbl_ptr queue */
595         spinlock_t rx_reorder_tbl_lock;
596         /* spin lock for Rx packets */
597         spinlock_t rx_pkt_lock;
598
599 #define MWIFIEX_ASSOC_RSP_BUF_SIZE  500
600         u8 assoc_rsp_buf[MWIFIEX_ASSOC_RSP_BUF_SIZE];
601         u32 assoc_rsp_size;
602
603 #define MWIFIEX_GENIE_BUF_SIZE      256
604         u8 gen_ie_buf[MWIFIEX_GENIE_BUF_SIZE];
605         u8 gen_ie_buf_len;
606
607         struct mwifiex_vendor_spec_cfg_ie vs_ie[MWIFIEX_MAX_VSIE_NUM];
608
609 #define MWIFIEX_ASSOC_TLV_BUF_SIZE  256
610         u8 assoc_tlv_buf[MWIFIEX_ASSOC_TLV_BUF_SIZE];
611         u8 assoc_tlv_buf_len;
612
613         u8 *curr_bcn_buf;
614         u32 curr_bcn_size;
615         /* spin lock for beacon buffer */
616         spinlock_t curr_bcn_buf_lock;
617         struct wireless_dev wdev;
618         struct mwifiex_chan_freq_power cfp;
619         char version_str[128];
620 #ifdef CONFIG_DEBUG_FS
621         struct dentry *dfs_dev_dir;
622 #endif
623         u16 current_key_index;
624         struct semaphore async_sem;
625         struct cfg80211_scan_request *scan_request;
626         u8 cfg_bssid[6];
627         struct wps wps;
628         u8 scan_block;
629         s32 cqm_rssi_thold;
630         u32 cqm_rssi_hyst;
631         u8 subsc_evt_rssi_state;
632         struct mwifiex_ds_misc_subsc_evt async_subsc_evt_storage;
633         struct mwifiex_ie mgmt_ie[MAX_MGMT_IE_INDEX];
634         u16 beacon_idx;
635         u16 proberesp_idx;
636         u16 assocresp_idx;
637         u16 gen_idx;
638         u8 ap_11n_enabled;
639         u8 ap_11ac_enabled;
640         u32 mgmt_frame_mask;
641         struct mwifiex_roc_cfg roc_cfg;
642         bool scan_aborting;
643         u8 csa_chan;
644         unsigned long csa_expire_time;
645         u8 del_list_idx;
646         bool hs2_enabled;
647         struct mwifiex_uap_bss_param bss_cfg;
648         struct cfg80211_chan_def bss_chandef;
649         struct station_parameters *sta_params;
650         struct sk_buff_head tdls_txq;
651         u8 check_tdls_tx;
652         struct timer_list auto_tdls_timer;
653         bool auto_tdls_timer_active;
654         struct idr ack_status_frames;
655         /* spin lock for ack status */
656         spinlock_t ack_status_lock;
657         /** rx histogram data */
658         struct mwifiex_histogram_data *hist_data;
659         struct cfg80211_chan_def dfs_chandef;
660         struct workqueue_struct *dfs_cac_workqueue;
661         struct delayed_work dfs_cac_work;
662         struct timer_list dfs_chan_switch_timer;
663         struct workqueue_struct *dfs_chan_sw_workqueue;
664         struct delayed_work dfs_chan_sw_work;
665         struct cfg80211_beacon_data beacon_after;
666         struct mwifiex_11h_intf_state state_11h;
667         struct mwifiex_ds_mem_rw mem_rw;
668         struct sk_buff_head bypass_txq;
669         struct mwifiex_user_scan_chan hidden_chan[MWIFIEX_USER_SCAN_CHAN_MAX];
670 };
671
672
673 struct mwifiex_tx_ba_stream_tbl {
674         struct list_head list;
675         int tid;
676         u8 ra[ETH_ALEN];
677         enum mwifiex_ba_status ba_status;
678         u8 amsdu;
679 };
680
681 struct mwifiex_rx_reorder_tbl;
682
683 struct reorder_tmr_cnxt {
684         struct timer_list timer;
685         struct mwifiex_rx_reorder_tbl *ptr;
686         struct mwifiex_private *priv;
687         u8 timer_is_set;
688 };
689
690 struct mwifiex_rx_reorder_tbl {
691         struct list_head list;
692         int tid;
693         u8 ta[ETH_ALEN];
694         int init_win;
695         int start_win;
696         int win_size;
697         void **rx_reorder_ptr;
698         struct reorder_tmr_cnxt timer_context;
699         u8 amsdu;
700         u8 flags;
701 };
702
703 struct mwifiex_bss_prio_node {
704         struct list_head list;
705         struct mwifiex_private *priv;
706 };
707
708 struct mwifiex_bss_prio_tbl {
709         struct list_head bss_prio_head;
710         /* spin lock for bss priority  */
711         spinlock_t bss_prio_lock;
712         struct mwifiex_bss_prio_node *bss_prio_cur;
713 };
714
715 struct cmd_ctrl_node {
716         struct list_head list;
717         struct mwifiex_private *priv;
718         u32 cmd_oid;
719         u32 cmd_flag;
720         struct sk_buff *cmd_skb;
721         struct sk_buff *resp_skb;
722         void *data_buf;
723         u32 wait_q_enabled;
724         struct sk_buff *skb;
725         u8 *condition;
726         u8 cmd_wait_q_woken;
727 };
728
729 struct mwifiex_bss_priv {
730         u8 band;
731         u64 fw_tsf;
732 };
733
734 struct mwifiex_tdls_capab {
735         __le16 capab;
736         u8 rates[32];
737         u8 rates_len;
738         u8 qos_info;
739         u8 coex_2040;
740         u16 aid;
741         struct ieee80211_ht_cap ht_capb;
742         struct ieee80211_ht_operation ht_oper;
743         struct ieee_types_extcap extcap;
744         struct ieee_types_generic rsn_ie;
745         struct ieee80211_vht_cap vhtcap;
746         struct ieee80211_vht_operation vhtoper;
747 };
748
749 struct mwifiex_station_stats {
750         u64 last_rx;
751         s8 rssi;
752         u64 rx_bytes;
753         u64 tx_bytes;
754         u32 rx_packets;
755         u32 tx_packets;
756         u32 tx_failed;
757         u8 last_tx_rate;
758         u8 last_tx_htinfo;
759 };
760
761 /* This is AP/TDLS specific structure which stores information
762  * about associated/peer STA
763  */
764 struct mwifiex_sta_node {
765         struct list_head list;
766         u8 mac_addr[ETH_ALEN];
767         u8 is_wmm_enabled;
768         u8 is_11n_enabled;
769         u8 is_11ac_enabled;
770         u8 ampdu_sta[MAX_NUM_TID];
771         u16 rx_seq[MAX_NUM_TID];
772         u16 max_amsdu;
773         u8 tdls_status;
774         struct mwifiex_tdls_capab tdls_cap;
775         struct mwifiex_station_stats stats;
776         u8 tx_pause;
777 };
778
779 struct mwifiex_auto_tdls_peer {
780         struct list_head list;
781         u8 mac_addr[ETH_ALEN];
782         u8 tdls_status;
783         int rssi;
784         long rssi_jiffies;
785         u8 failure_count;
786         u8 do_discover;
787         u8 do_setup;
788 };
789
790 struct mwifiex_if_ops {
791         int (*init_if) (struct mwifiex_adapter *);
792         void (*cleanup_if) (struct mwifiex_adapter *);
793         int (*check_fw_status) (struct mwifiex_adapter *, u32);
794         int (*prog_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
795         int (*register_dev) (struct mwifiex_adapter *);
796         void (*unregister_dev) (struct mwifiex_adapter *);
797         int (*enable_int) (struct mwifiex_adapter *);
798         void (*disable_int) (struct mwifiex_adapter *);
799         int (*process_int_status) (struct mwifiex_adapter *);
800         int (*host_to_card) (struct mwifiex_adapter *, u8, struct sk_buff *,
801                              struct mwifiex_tx_param *);
802         int (*wakeup) (struct mwifiex_adapter *);
803         int (*wakeup_complete) (struct mwifiex_adapter *);
804
805         /* Interface specific functions */
806         void (*update_mp_end_port) (struct mwifiex_adapter *, u16);
807         void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
808         int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
809         int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
810         int (*init_fw_port) (struct mwifiex_adapter *);
811         int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
812         void (*card_reset) (struct mwifiex_adapter *);
813         int (*reg_dump)(struct mwifiex_adapter *, char *);
814         void (*device_dump)(struct mwifiex_adapter *);
815         int (*clean_pcie_ring) (struct mwifiex_adapter *adapter);
816         void (*iface_work)(struct work_struct *work);
817         void (*submit_rem_rx_urbs)(struct mwifiex_adapter *adapter);
818         void (*deaggr_pkt)(struct mwifiex_adapter *, struct sk_buff *);
819 };
820
821 struct mwifiex_adapter {
822         u8 iface_type;
823         unsigned int debug_mask;
824         struct mwifiex_iface_comb iface_limit;
825         struct mwifiex_iface_comb curr_iface_comb;
826         struct mwifiex_private *priv[MWIFIEX_MAX_BSS_NUM];
827         u8 priv_num;
828         const struct firmware *firmware;
829         char fw_name[32];
830         int winner;
831         struct device *dev;
832         struct wiphy *wiphy;
833         u8 perm_addr[ETH_ALEN];
834         bool surprise_removed;
835         u32 fw_release_number;
836         u16 init_wait_q_woken;
837         wait_queue_head_t init_wait_q;
838         void *card;
839         struct mwifiex_if_ops if_ops;
840         atomic_t bypass_tx_pending;
841         atomic_t rx_pending;
842         atomic_t tx_pending;
843         atomic_t cmd_pending;
844         struct workqueue_struct *workqueue;
845         struct work_struct main_work;
846         struct workqueue_struct *rx_workqueue;
847         struct work_struct rx_work;
848         struct workqueue_struct *dfs_workqueue;
849         struct work_struct dfs_work;
850         bool rx_work_enabled;
851         bool rx_processing;
852         bool delay_main_work;
853         bool rx_locked;
854         bool main_locked;
855         struct mwifiex_bss_prio_tbl bss_prio_tbl[MWIFIEX_MAX_BSS_NUM];
856         /* spin lock for init/shutdown */
857         spinlock_t mwifiex_lock;
858         /* spin lock for main process */
859         spinlock_t main_proc_lock;
860         u32 mwifiex_processing;
861         u8 more_task_flag;
862         u16 tx_buf_size;
863         u16 curr_tx_buf_size;
864         bool sdio_rx_aggr_enable;
865         u16 sdio_rx_block_size;
866         u32 ioport;
867         enum MWIFIEX_HARDWARE_STATUS hw_status;
868         u16 number_of_antenna;
869         u32 fw_cap_info;
870         /* spin lock for interrupt handling */
871         spinlock_t int_lock;
872         u8 int_status;
873         u32 event_cause;
874         struct sk_buff *event_skb;
875         u8 upld_buf[MWIFIEX_UPLD_SIZE];
876         u8 data_sent;
877         u8 cmd_sent;
878         u8 cmd_resp_received;
879         u8 event_received;
880         u8 data_received;
881         u16 seq_num;
882         struct cmd_ctrl_node *cmd_pool;
883         struct cmd_ctrl_node *curr_cmd;
884         /* spin lock for command */
885         spinlock_t mwifiex_cmd_lock;
886         u8 is_cmd_timedout;
887         u16 last_init_cmd;
888         struct timer_list cmd_timer;
889         struct list_head cmd_free_q;
890         /* spin lock for cmd_free_q */
891         spinlock_t cmd_free_q_lock;
892         struct list_head cmd_pending_q;
893         /* spin lock for cmd_pending_q */
894         spinlock_t cmd_pending_q_lock;
895         struct list_head scan_pending_q;
896         /* spin lock for scan_pending_q */
897         spinlock_t scan_pending_q_lock;
898         /* spin lock for RX processing routine */
899         spinlock_t rx_proc_lock;
900         struct sk_buff_head tx_data_q;
901         atomic_t tx_queued;
902         u32 scan_processing;
903         u16 region_code;
904         struct mwifiex_802_11d_domain_reg domain_reg;
905         u16 scan_probes;
906         u32 scan_mode;
907         u16 specific_scan_time;
908         u16 active_scan_time;
909         u16 passive_scan_time;
910         u16 scan_chan_gap_time;
911         u8 fw_bands;
912         u8 adhoc_start_band;
913         u8 config_bands;
914         struct mwifiex_chan_scan_param_set *scan_channels;
915         u8 tx_lock_flag;
916         struct mwifiex_sleep_params sleep_params;
917         struct mwifiex_sleep_period sleep_period;
918         u16 ps_mode;
919         u32 ps_state;
920         u8 need_to_wakeup;
921         u16 multiple_dtim;
922         u16 local_listen_interval;
923         u16 null_pkt_interval;
924         struct sk_buff *sleep_cfm;
925         u16 bcn_miss_time_out;
926         u16 adhoc_awake_period;
927         u8 is_deep_sleep;
928         u8 delay_null_pkt;
929         u16 delay_to_ps;
930         u16 enhanced_ps_mode;
931         u8 pm_wakeup_card_req;
932         u16 gen_null_pkt;
933         u16 pps_uapsd_mode;
934         u32 pm_wakeup_fw_try;
935         struct timer_list wakeup_timer;
936         u8 is_hs_configured;
937         struct mwifiex_hs_config_param hs_cfg;
938         u8 hs_activated;
939         u16 hs_activate_wait_q_woken;
940         wait_queue_head_t hs_activate_wait_q;
941         bool is_suspended;
942         bool hs_enabling;
943         u8 event_body[MAX_EVENT_SIZE];
944         u32 hw_dot_11n_dev_cap;
945         u8 hw_dev_mcs_support;
946         u8 user_dev_mcs_support;
947         u8 adhoc_11n_enabled;
948         u8 sec_chan_offset;
949         struct mwifiex_dbg dbg;
950         u8 arp_filter[ARP_FILTER_MAX_BUF_SIZE];
951         u32 arp_filter_size;
952         struct mwifiex_wait_queue cmd_wait_q;
953         u8 scan_wait_q_woken;
954         spinlock_t queue_lock;          /* lock for tx queues */
955         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
956         u16 max_mgmt_ie_index;
957         const struct firmware *cal_data;
958         struct device_node *dt_node;
959
960         /* 11AC */
961         u32 is_hw_11ac_capable;
962         u32 hw_dot_11ac_dev_cap;
963         u32 hw_dot_11ac_mcs_support;
964         u32 usr_dot_11ac_dev_cap_bg;
965         u32 usr_dot_11ac_dev_cap_a;
966         u32 usr_dot_11ac_mcs_support;
967
968         atomic_t pending_bridged_pkts;
969         struct semaphore *card_sem;
970         bool ext_scan;
971         u8 fw_api_ver;
972         u8 key_api_major_ver, key_api_minor_ver;
973         struct memory_type_mapping *mem_type_mapping_tbl;
974         u8 num_mem_types;
975         void *drv_info_dump;
976         u32 drv_info_size;
977         bool scan_chan_gap_enabled;
978         struct sk_buff_head rx_data_q;
979         struct mwifiex_chan_stats *chan_stats;
980         u32 num_in_chan_stats;
981         int survey_idx;
982         bool auto_tdls;
983         u8 coex_scan;
984         u8 coex_min_scan_time;
985         u8 coex_max_scan_time;
986         u8 coex_win_size;
987         u8 coex_tx_win_size;
988         u8 coex_rx_win_size;
989         bool drcs_enabled;
990         u8 active_scan_triggered;
991 };
992
993 void mwifiex_process_tx_queue(struct mwifiex_adapter *adapter);
994
995 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
996
997 void mwifiex_set_trans_start(struct net_device *dev);
998
999 void mwifiex_stop_net_dev_queue(struct net_device *netdev,
1000                 struct mwifiex_adapter *adapter);
1001
1002 void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
1003                 struct mwifiex_adapter *adapter);
1004
1005 int mwifiex_init_priv(struct mwifiex_private *priv);
1006 void mwifiex_free_priv(struct mwifiex_private *priv);
1007
1008 int mwifiex_init_fw(struct mwifiex_adapter *adapter);
1009
1010 int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter);
1011
1012 int mwifiex_shutdown_drv(struct mwifiex_adapter *adapter);
1013
1014 int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter);
1015
1016 int mwifiex_dnld_fw(struct mwifiex_adapter *, struct mwifiex_fw_image *);
1017
1018 int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb);
1019
1020 int mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
1021                                 struct sk_buff *skb);
1022
1023 int mwifiex_process_event(struct mwifiex_adapter *adapter);
1024
1025 int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
1026                          struct cmd_ctrl_node *cmd_node);
1027
1028 int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
1029                      u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync);
1030
1031 void mwifiex_cmd_timeout_func(unsigned long function_context);
1032
1033 int mwifiex_get_debug_info(struct mwifiex_private *,
1034                            struct mwifiex_debug_info *);
1035
1036 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter);
1037 int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter);
1038 void mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter);
1039 void mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter);
1040
1041 void mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
1042                                   struct cmd_ctrl_node *cmd_node);
1043 void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
1044                               struct cmd_ctrl_node *cmd_node);
1045
1046 void mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
1047                                      struct cmd_ctrl_node *cmd_node,
1048                                      u32 addtail);
1049
1050 int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter);
1051 int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter);
1052 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
1053                              struct sk_buff *skb);
1054 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
1055                        struct mwifiex_tx_param *tx_param);
1056 int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags);
1057 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
1058                                 struct sk_buff *skb, int aggr, int status);
1059 void mwifiex_clean_txrx(struct mwifiex_private *priv);
1060 u8 mwifiex_check_last_packet_indication(struct mwifiex_private *priv);
1061 void mwifiex_check_ps_cond(struct mwifiex_adapter *adapter);
1062 void mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *, u8 *,
1063                                         u32);
1064 int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
1065                                struct host_cmd_ds_command *cmd,
1066                                u16 cmd_action, uint16_t ps_bitmap,
1067                                struct mwifiex_ds_auto_ds *auto_ds);
1068 int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
1069                                struct host_cmd_ds_command *resp,
1070                                struct mwifiex_ds_pm_cfg *pm_cfg);
1071 void mwifiex_process_hs_config(struct mwifiex_adapter *adapter);
1072 void mwifiex_hs_activated_event(struct mwifiex_private *priv,
1073                                         u8 activated);
1074 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
1075                           int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg);
1076 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
1077                               struct host_cmd_ds_command *resp);
1078 int mwifiex_process_rx_packet(struct mwifiex_private *priv,
1079                               struct sk_buff *skb);
1080 int mwifiex_sta_prepare_cmd(struct mwifiex_private *, uint16_t cmd_no,
1081                             u16 cmd_action, u32 cmd_oid,
1082                             void *data_buf, void *cmd_buf);
1083 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1084                             u16 cmd_action, u32 cmd_oid,
1085                             void *data_buf, void *cmd_buf);
1086 int mwifiex_process_sta_cmdresp(struct mwifiex_private *, u16 cmdresp_no,
1087                                 struct host_cmd_ds_command *resp);
1088 int mwifiex_process_sta_rx_packet(struct mwifiex_private *,
1089                                   struct sk_buff *skb);
1090 int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
1091                                   struct sk_buff *skb);
1092 int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
1093                                   struct sk_buff *skb);
1094 int mwifiex_process_sta_event(struct mwifiex_private *);
1095 int mwifiex_process_uap_event(struct mwifiex_private *);
1096 void mwifiex_delete_all_station_list(struct mwifiex_private *priv);
1097 void mwifiex_wmm_del_peer_ra_list(struct mwifiex_private *priv,
1098                                   const u8 *ra_addr);
1099 void *mwifiex_process_sta_txpd(struct mwifiex_private *, struct sk_buff *skb);
1100 void *mwifiex_process_uap_txpd(struct mwifiex_private *, struct sk_buff *skb);
1101 int mwifiex_sta_init_cmd(struct mwifiex_private *, u8 first_sta, bool init);
1102 int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1103                             struct mwifiex_scan_cmd_config *scan_cfg);
1104 void mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
1105                             struct cmd_ctrl_node *cmd_node);
1106 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
1107                             struct host_cmd_ds_command *resp);
1108 s32 mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2);
1109 int mwifiex_associate(struct mwifiex_private *priv,
1110                       struct mwifiex_bssdescriptor *bss_desc);
1111 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
1112                                  struct host_cmd_ds_command *cmd,
1113                                  struct mwifiex_bssdescriptor *bss_desc);
1114 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
1115                                  struct host_cmd_ds_command *resp);
1116 void mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason);
1117 u8 mwifiex_band_to_radio_type(u8 band);
1118 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac);
1119 void mwifiex_deauthenticate_all(struct mwifiex_adapter *adapter);
1120 int mwifiex_adhoc_start(struct mwifiex_private *priv,
1121                         struct cfg80211_ssid *adhoc_ssid);
1122 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1123                        struct mwifiex_bssdescriptor *bss_desc);
1124 int mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
1125                                     struct host_cmd_ds_command *cmd,
1126                                     struct cfg80211_ssid *req_ssid);
1127 int mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1128                                    struct host_cmd_ds_command *cmd,
1129                                    struct mwifiex_bssdescriptor *bss_desc);
1130 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1131                               struct host_cmd_ds_command *resp);
1132 int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
1133 struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv,
1134                                                 u8 band, u16 channel, u32 freq);
1135 u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv,
1136                                u8 index, u8 ht_info);
1137 u32 mwifiex_index_to_acs_data_rate(struct mwifiex_private *priv,
1138                                    u8 index, u8 ht_info);
1139 u32 mwifiex_find_freq_from_band_chan(u8, u8);
1140 int mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, u16 vsie_mask,
1141                                 u8 **buffer);
1142 u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv,
1143                                     u8 *rates);
1144 u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates);
1145 u32 mwifiex_get_rates_from_cfg80211(struct mwifiex_private *priv,
1146                                     u8 *rates, u8 radio_type);
1147 u8 mwifiex_is_rate_auto(struct mwifiex_private *priv);
1148 extern u16 region_code_index[MWIFIEX_MAX_REGION_CODE];
1149 void mwifiex_save_curr_bcn(struct mwifiex_private *priv);
1150 void mwifiex_free_curr_bcn(struct mwifiex_private *priv);
1151 int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
1152                             struct host_cmd_ds_command *cmd);
1153 int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1154                             struct host_cmd_ds_command *resp);
1155 int is_command_pending(struct mwifiex_adapter *adapter);
1156 void mwifiex_init_priv_params(struct mwifiex_private *priv,
1157                                                 struct net_device *dev);
1158 int mwifiex_set_secure_params(struct mwifiex_private *priv,
1159                               struct mwifiex_uap_bss_param *bss_config,
1160                               struct cfg80211_ap_settings *params);
1161 void mwifiex_set_ht_params(struct mwifiex_private *priv,
1162                            struct mwifiex_uap_bss_param *bss_cfg,
1163                            struct cfg80211_ap_settings *params);
1164 void mwifiex_set_vht_params(struct mwifiex_private *priv,
1165                             struct mwifiex_uap_bss_param *bss_cfg,
1166                             struct cfg80211_ap_settings *params);
1167 void mwifiex_set_tpc_params(struct mwifiex_private *priv,
1168                             struct mwifiex_uap_bss_param *bss_cfg,
1169                             struct cfg80211_ap_settings *params);
1170 void mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
1171                            struct cfg80211_ap_settings *params);
1172 void mwifiex_set_vht_width(struct mwifiex_private *priv,
1173                            enum nl80211_chan_width width,
1174                            bool ap_11ac_disable);
1175 void
1176 mwifiex_set_wmm_params(struct mwifiex_private *priv,
1177                        struct mwifiex_uap_bss_param *bss_cfg,
1178                        struct cfg80211_ap_settings *params);
1179 void mwifiex_set_ba_params(struct mwifiex_private *priv);
1180
1181 void mwifiex_update_ampdu_txwinsize(struct mwifiex_adapter *pmadapter);
1182 void mwifiex_bt_coex_wlan_param_update_event(struct mwifiex_private *priv,
1183                                              struct sk_buff *event_skb);
1184
1185 void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv);
1186 int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1187                                 struct host_cmd_ds_command *cmd,
1188                                 void *data_buf);
1189 int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
1190                                 struct host_cmd_ds_command *resp);
1191 int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
1192                                          void *buf);
1193
1194 /*
1195  * This function checks if the queuing is RA based or not.
1196  */
1197 static inline u8
1198 mwifiex_queuing_ra_based(struct mwifiex_private *priv)
1199 {
1200         /*
1201          * Currently we assume if we are in Infra, then DA=RA. This might not be
1202          * true in the future
1203          */
1204         if ((priv->bss_mode == NL80211_IFTYPE_STATION) &&
1205             (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA))
1206                 return false;
1207
1208         return true;
1209 }
1210
1211 /*
1212  * This function copies rates.
1213  */
1214 static inline u32
1215 mwifiex_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
1216 {
1217         int i;
1218
1219         for (i = 0; i < len && src[i]; i++, pos++) {
1220                 if (pos >= MWIFIEX_SUPPORTED_RATES)
1221                         break;
1222                 dest[pos] = src[i];
1223         }
1224
1225         return pos;
1226 }
1227
1228 /*
1229  * This function returns the correct private structure pointer based
1230  * upon the BSS type and BSS number.
1231  */
1232 static inline struct mwifiex_private *
1233 mwifiex_get_priv_by_id(struct mwifiex_adapter *adapter,
1234                        u8 bss_num, u8 bss_type)
1235 {
1236         int i;
1237
1238         for (i = 0; i < adapter->priv_num; i++) {
1239                 if (adapter->priv[i]) {
1240                         if ((adapter->priv[i]->bss_num == bss_num) &&
1241                             (adapter->priv[i]->bss_type == bss_type))
1242                                 break;
1243                 }
1244         }
1245         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1246 }
1247
1248 /*
1249  * This function returns the first available private structure pointer
1250  * based upon the BSS role.
1251  */
1252 static inline struct mwifiex_private *
1253 mwifiex_get_priv(struct mwifiex_adapter *adapter,
1254                  enum mwifiex_bss_role bss_role)
1255 {
1256         int i;
1257
1258         for (i = 0; i < adapter->priv_num; i++) {
1259                 if (adapter->priv[i]) {
1260                         if (bss_role == MWIFIEX_BSS_ROLE_ANY ||
1261                             GET_BSS_ROLE(adapter->priv[i]) == bss_role)
1262                                 break;
1263                 }
1264         }
1265
1266         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1267 }
1268
1269 /*
1270  * This function returns the first available unused private structure pointer.
1271  */
1272 static inline struct mwifiex_private *
1273 mwifiex_get_unused_priv(struct mwifiex_adapter *adapter)
1274 {
1275         int i;
1276
1277         for (i = 0; i < adapter->priv_num; i++) {
1278                 if (adapter->priv[i]) {
1279                         if (adapter->priv[i]->bss_mode ==
1280                             NL80211_IFTYPE_UNSPECIFIED)
1281                                 break;
1282                 }
1283         }
1284
1285         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1286 }
1287
1288 /*
1289  * This function returns the driver private structure of a network device.
1290  */
1291 static inline struct mwifiex_private *
1292 mwifiex_netdev_get_priv(struct net_device *dev)
1293 {
1294         return (struct mwifiex_private *) (*(unsigned long *) netdev_priv(dev));
1295 }
1296
1297 /*
1298  * This function checks if a skb holds a management frame.
1299  */
1300 static inline bool mwifiex_is_skb_mgmt_frame(struct sk_buff *skb)
1301 {
1302         return (le32_to_cpu(*(__le32 *)skb->data) == PKT_TYPE_MGMT);
1303 }
1304
1305 /* This function retrieves channel closed for operation by Channel
1306  * Switch Announcement.
1307  */
1308 static inline u8
1309 mwifiex_11h_get_csa_closed_channel(struct mwifiex_private *priv)
1310 {
1311         if (!priv->csa_chan)
1312                 return 0;
1313
1314         /* Clear csa channel, if DFS channel move time has passed */
1315         if (time_after(jiffies, priv->csa_expire_time)) {
1316                 priv->csa_chan = 0;
1317                 priv->csa_expire_time = 0;
1318         }
1319
1320         return priv->csa_chan;
1321 }
1322
1323 static inline u8 mwifiex_is_any_intf_active(struct mwifiex_private *priv)
1324 {
1325         struct mwifiex_private *priv_num;
1326         int i;
1327
1328         for (i = 0; i < priv->adapter->priv_num; i++) {
1329                 priv_num = priv->adapter->priv[i];
1330                 if (priv_num) {
1331                         if ((GET_BSS_ROLE(priv_num) == MWIFIEX_BSS_ROLE_UAP &&
1332                              priv_num->bss_started) ||
1333                             (GET_BSS_ROLE(priv_num) == MWIFIEX_BSS_ROLE_STA &&
1334                              priv_num->media_connected))
1335                                 return 1;
1336                 }
1337         }
1338
1339         return 0;
1340 }
1341
1342 static inline u8 mwifiex_is_tdls_link_setup(u8 status)
1343 {
1344         switch (status) {
1345         case TDLS_SETUP_COMPLETE:
1346         case TDLS_CHAN_SWITCHING:
1347         case TDLS_IN_BASE_CHAN:
1348         case TDLS_IN_OFF_CHAN:
1349                 return true;
1350         default:
1351                 break;
1352         }
1353
1354         return false;
1355 }
1356
1357 int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
1358                              u32 func_init_shutdown);
1359 int mwifiex_add_card(void *, struct semaphore *, struct mwifiex_if_ops *, u8);
1360 int mwifiex_remove_card(struct mwifiex_adapter *, struct semaphore *);
1361
1362 void mwifiex_get_version(struct mwifiex_adapter *adapter, char *version,
1363                          int maxlen);
1364 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
1365                         struct mwifiex_multicast_list *mcast_list);
1366 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
1367                             struct net_device *dev);
1368 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
1369                                 struct cmd_ctrl_node *cmd_queued);
1370 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
1371                       struct cfg80211_ssid *req_ssid);
1372 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type);
1373 int mwifiex_enable_hs(struct mwifiex_adapter *adapter);
1374 int mwifiex_disable_auto_ds(struct mwifiex_private *priv);
1375 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate);
1376 int mwifiex_request_scan(struct mwifiex_private *priv,
1377                          struct cfg80211_ssid *req_ssid);
1378 int mwifiex_scan_networks(struct mwifiex_private *priv,
1379                           const struct mwifiex_user_scan_cfg *user_scan_in);
1380 int mwifiex_set_radio(struct mwifiex_private *priv, u8 option);
1381
1382 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1383                        const u8 *key, int key_len, u8 key_index,
1384                        const u8 *mac_addr, int disable);
1385
1386 int mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len);
1387
1388 int mwifiex_get_ver_ext(struct mwifiex_private *priv);
1389
1390 int mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1391                                struct ieee80211_channel *chan,
1392                                unsigned int duration);
1393
1394 int mwifiex_get_stats_info(struct mwifiex_private *priv,
1395                            struct mwifiex_ds_get_stats *log);
1396
1397 int mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1398                       u32 reg_offset, u32 reg_value);
1399
1400 int mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1401                      u32 reg_offset, u32 *value);
1402
1403 int mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1404                         u8 *value);
1405
1406 int mwifiex_set_11n_httx_cfg(struct mwifiex_private *priv, int data);
1407
1408 int mwifiex_get_11n_httx_cfg(struct mwifiex_private *priv, int *data);
1409
1410 int mwifiex_set_tx_rate_cfg(struct mwifiex_private *priv, int tx_rate_index);
1411
1412 int mwifiex_get_tx_rate_cfg(struct mwifiex_private *priv, int *tx_rate_index);
1413
1414 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode);
1415
1416 int mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter,
1417                                    char *version, int max_len);
1418
1419 int mwifiex_set_tx_power(struct mwifiex_private *priv,
1420                          struct mwifiex_power_cfg *power_cfg);
1421
1422 int mwifiex_main_process(struct mwifiex_adapter *);
1423
1424 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb);
1425
1426 int mwifiex_get_bss_info(struct mwifiex_private *,
1427                          struct mwifiex_bss_info *);
1428 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
1429                               struct cfg80211_bss *bss,
1430                               struct mwifiex_bssdescriptor *bss_desc);
1431 int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1432                                     struct mwifiex_bssdescriptor *bss_entry);
1433 int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1434                                         struct mwifiex_bssdescriptor *bss_desc);
1435
1436 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type);
1437 u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset);
1438
1439 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1440                                               const char *name,
1441                                               unsigned char name_assign_type,
1442                                               enum nl80211_iftype type,
1443                                               u32 *flags,
1444                                               struct vif_params *params);
1445 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev);
1446
1447 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config);
1448
1449 int mwifiex_add_wowlan_magic_pkt_filter(struct mwifiex_adapter *adapter);
1450
1451 int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
1452                          struct cfg80211_beacon_data *data);
1453 int mwifiex_del_mgmt_ies(struct mwifiex_private *priv);
1454 u8 *mwifiex_11d_code_2_region(u8 code);
1455 void mwifiex_uap_set_channel(struct mwifiex_private *priv,
1456                              struct mwifiex_uap_bss_param *bss_cfg,
1457                              struct cfg80211_chan_def chandef);
1458 int mwifiex_config_start_uap(struct mwifiex_private *priv,
1459                              struct mwifiex_uap_bss_param *bss_cfg);
1460 void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
1461                               struct mwifiex_sta_node *node);
1462
1463 void mwifiex_init_11h_params(struct mwifiex_private *priv);
1464 int mwifiex_is_11h_active(struct mwifiex_private *priv);
1465 int mwifiex_11h_activate(struct mwifiex_private *priv, bool flag);
1466
1467 void mwifiex_11h_process_join(struct mwifiex_private *priv, u8 **buffer,
1468                               struct mwifiex_bssdescriptor *bss_desc);
1469 int mwifiex_11h_handle_event_chanswann(struct mwifiex_private *priv);
1470 int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1471                             struct device_node *node, const char *prefix);
1472 void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv);
1473
1474 extern const struct ethtool_ops mwifiex_ethtool_ops;
1475
1476 void mwifiex_del_all_sta_list(struct mwifiex_private *priv);
1477 void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1478 void
1479 mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
1480                        int ies_len, struct mwifiex_sta_node *node);
1481 struct mwifiex_sta_node *
1482 mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1483 struct mwifiex_sta_node *
1484 mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1485 u8 mwifiex_is_tdls_chan_switching(struct mwifiex_private *priv);
1486 u8 mwifiex_is_tdls_off_chan(struct mwifiex_private *priv);
1487 u8 mwifiex_is_send_cmd_allowed(struct mwifiex_private *priv);
1488 int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
1489                                  u8 action_code, u8 dialog_token,
1490                                  u16 status_code, const u8 *extra_ies,
1491                                  size_t extra_ies_len);
1492 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
1493                                    u8 action_code, u8 dialog_token,
1494                                    u16 status_code, const u8 *extra_ies,
1495                                    size_t extra_ies_len);
1496 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
1497                                        u8 *buf, int len);
1498 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action);
1499 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac);
1500 int mwifiex_get_tdls_list(struct mwifiex_private *priv,
1501                           struct tdls_peer_info *buf);
1502 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv);
1503 bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv);
1504 u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
1505                                  u32 pri_chan, u8 chan_bw);
1506 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter);
1507
1508 int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb);
1509 void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv);
1510 void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1511                                           const u8 *mac, u8 link_status);
1512 void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1513                                           u8 *mac, s8 snr, s8 nflr);
1514 void mwifiex_check_auto_tdls(unsigned long context);
1515 void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac);
1516 void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv);
1517 void mwifiex_clean_auto_tdls(struct mwifiex_private *priv);
1518 int mwifiex_config_tdls_enable(struct mwifiex_private *priv);
1519 int mwifiex_config_tdls_disable(struct mwifiex_private *priv);
1520 int mwifiex_config_tdls_cs_params(struct mwifiex_private *priv);
1521 int mwifiex_stop_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac);
1522 int mwifiex_start_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac,
1523                           u8 primary_chan, u8 second_chan_offset, u8 band);
1524
1525 int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private *priv,
1526                                           struct host_cmd_ds_command *cmd,
1527                                           void *data_buf);
1528 int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private *priv,
1529                                      struct sk_buff *skb);
1530
1531 void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
1532                                    void *event_body);
1533
1534 struct sk_buff *
1535 mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
1536                                 struct sk_buff *skb, u8 flag, u64 *cookie);
1537 void mwifiex_dfs_cac_work_queue(struct work_struct *work);
1538 void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work);
1539 void mwifiex_abort_cac(struct mwifiex_private *priv);
1540 int mwifiex_stop_radar_detection(struct mwifiex_private *priv,
1541                                  struct cfg80211_chan_def *chandef);
1542 int mwifiex_11h_handle_radar_detected(struct mwifiex_private *priv,
1543                                       struct sk_buff *skb);
1544
1545 void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr,
1546                            s8 nflr);
1547 void mwifiex_hist_data_reset(struct mwifiex_private *priv);
1548 void mwifiex_hist_data_add(struct mwifiex_private *priv,
1549                            u8 rx_rate, s8 snr, s8 nflr);
1550 u8 mwifiex_adjust_data_rate(struct mwifiex_private *priv,
1551                             u8 rx_rate, u8 ht_info);
1552
1553 void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter);
1554 void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter);
1555 void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags);
1556 void mwifiex_queue_main_work(struct mwifiex_adapter *adapter);
1557 void mwifiex_coex_ampdu_rxwinsize(struct mwifiex_adapter *adapter);
1558 void mwifiex_11n_delba(struct mwifiex_private *priv, int tid);
1559 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy);
1560 void mwifiex_process_tx_pause_event(struct mwifiex_private *priv,
1561                                     struct sk_buff *event);
1562 void mwifiex_process_multi_chan_event(struct mwifiex_private *priv,
1563                                       struct sk_buff *event_skb);
1564
1565 #ifdef CONFIG_DEBUG_FS
1566 void mwifiex_debugfs_init(void);
1567 void mwifiex_debugfs_remove(void);
1568
1569 void mwifiex_dev_debugfs_init(struct mwifiex_private *priv);
1570 void mwifiex_dev_debugfs_remove(struct mwifiex_private *priv);
1571 #endif
1572 #endif /* !_MWIFIEX_MAIN_H_ */