Merge branch android-common-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / include / drv_types.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 /*-------------------------------------------------------------------------------
21
22         For type defines and data structure defines
23
24 --------------------------------------------------------------------------------*/
25
26
27 #ifndef __DRV_TYPES_H__
28 #define __DRV_TYPES_H__
29
30 #include <drv_conf.h>
31 #include <basic_types.h>
32 #include <osdep_service.h>
33 #include <rtw_byteorder.h>
34 #include <wlan_bssdef.h>
35 #include <wifi.h>
36 #include <ieee80211.h>
37 #ifdef CONFIG_ARP_KEEP_ALIVE
38 #include <net/neighbour.h>
39 #include <net/arp.h>
40 #endif
41
42 #ifdef PLATFORM_OS_XP
43 #include <drv_types_xp.h>
44 #endif
45
46 #ifdef PLATFORM_OS_CE
47 #include <drv_types_ce.h>
48 #endif
49
50 #ifdef PLATFORM_LINUX
51 #include <drv_types_linux.h>
52 #endif
53
54 enum _NIC_VERSION {
55
56         RTL8711_NIC,
57         RTL8712_NIC,
58         RTL8713_NIC,
59         RTL8716_NIC
60
61 };
62
63 typedef struct _ADAPTER _adapter, ADAPTER,*PADAPTER;
64
65 #include <rtw_debug.h>
66 #include <rtw_rf.h>
67
68 #ifdef CONFIG_80211N_HT
69 #include <rtw_ht.h>
70 #endif
71
72 #ifdef CONFIG_80211AC_VHT
73 #include <rtw_vht.h>
74 #endif
75
76 #ifdef CONFIG_INTEL_WIDI
77 #include <rtw_intel_widi.h>
78 #endif
79
80 #include <rtw_cmd.h>
81 #include <cmd_osdep.h>
82 #include <rtw_security.h>
83 #include <rtw_xmit.h>
84 #include <xmit_osdep.h>
85 #include <rtw_recv.h>
86
87 #ifdef CONFIG_BEAMFORMING
88 #include <rtw_beamforming.h>
89 #endif
90
91 #include <recv_osdep.h>
92 #include <rtw_efuse.h>
93 #include <rtw_sreset.h>
94 #include <hal_intf.h>
95 #include <hal_com.h>
96 #include <hal_com_led.h>
97 #include "../hal/hal_dm.h"
98 #include <rtw_qos.h>
99 #include <rtw_pwrctrl.h>
100 #include <rtw_mlme.h>
101 #include <mlme_osdep.h>
102 #include <rtw_io.h>
103 #include <rtw_ioctl.h>
104 #include <rtw_ioctl_set.h>
105 #include <rtw_ioctl_query.h>
106 #include <rtw_ioctl_rtl.h>
107 #include <osdep_intf.h>
108 #include <rtw_eeprom.h>
109 #include <sta_info.h>
110 #include <rtw_event.h>
111 #include <rtw_mlme_ext.h>
112 #include <rtw_ap.h>
113 #include <rtw_efuse.h>
114 #include <rtw_version.h>
115 #include <rtw_odm.h>
116
117 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
118 #include <rtw_mem.h>
119 #endif
120
121 #ifdef CONFIG_P2P
122 #include <rtw_p2p.h>
123 #endif // CONFIG_P2P
124
125 #ifdef CONFIG_TDLS
126 #include <rtw_tdls.h>
127 #endif // CONFIG_TDLS
128
129 #ifdef CONFIG_WAPI_SUPPORT
130 #include <rtw_wapi.h>
131 #endif // CONFIG_WAPI_SUPPORT
132
133 #ifdef CONFIG_DRVEXT_MODULE
134 #include <drvext_api.h>
135 #endif // CONFIG_DRVEXT_MODULE
136
137 #ifdef CONFIG_MP_INCLUDED
138 #include <rtw_mp.h>
139 #endif // CONFIG_MP_INCLUDED
140
141 #ifdef CONFIG_BR_EXT
142 #include <rtw_br_ext.h>
143 #endif // CONFIG_BR_EXT
144
145 #ifdef CONFIG_IOL
146 #include <rtw_iol.h>
147 #endif // CONFIG_IOL
148
149 #include <ip.h>
150 #include <if_ether.h>
151 #include <ethernet.h>
152 #include <circ_buf.h>
153
154 #include <rtw_android.h>
155
156 #define SPEC_DEV_ID_NONE BIT(0)
157 #define SPEC_DEV_ID_DISABLE_HT BIT(1)
158 #define SPEC_DEV_ID_ENABLE_PS BIT(2)
159 #define SPEC_DEV_ID_RF_CONFIG_1T1R BIT(3)
160 #define SPEC_DEV_ID_RF_CONFIG_2T2R BIT(4)
161 #define SPEC_DEV_ID_ASSIGN_IFNAME BIT(5)
162
163 struct specific_device_id{
164
165         u32             flags;
166
167         u16             idVendor;
168         u16             idProduct;
169
170 };
171
172 struct registry_priv
173 {
174         u8      chip_version;
175         u8      rfintfs;
176         u8      lbkmode;
177         u8      hci;
178         NDIS_802_11_SSID        ssid;
179         u8      network_mode;   //infra, ad-hoc, auto
180         u8      channel;//ad-hoc support requirement
181         u8      wireless_mode;//A, B, G, auto
182         u8      scan_mode;//active, passive
183         u8      radio_enable;
184         u8      preamble;//long, short, auto
185         u8      vrtl_carrier_sense;//Enable, Disable, Auto
186         u8      vcs_type;//RTS/CTS, CTS-to-self
187         u16     rts_thresh;
188         u16  frag_thresh;
189         u8      adhoc_tx_pwr;
190         u8      soft_ap;
191         u8      power_mgnt;
192         u8      ips_mode;
193         u8      smart_ps;
194         u8   usb_rxagg_mode;
195         u8      long_retry_lmt;
196         u8      short_retry_lmt;
197         u16     busy_thresh;
198         u8      ack_policy;
199         u8      mp_mode;
200         u8  mp_dm;
201         u8      software_encrypt;
202         u8      software_decrypt;
203         #ifdef CONFIG_TX_EARLY_MODE
204         u8   early_mode;
205         #endif
206         u8      acm_method;
207           //UAPSD
208         u8      wmm_enable;
209         u8      uapsd_enable;
210         u8      uapsd_max_sp;
211         u8      uapsd_acbk_en;
212         u8      uapsd_acbe_en;
213         u8      uapsd_acvi_en;
214         u8      uapsd_acvo_en;
215
216         WLAN_BSSID_EX    dev_network;
217
218 #ifdef CONFIG_80211N_HT
219         u8      ht_enable;
220         // 0: 20 MHz, 1: 40 MHz, 2: 80 MHz, 3: 160MHz
221         // 2.4G use bit 0 ~ 3, 5G use bit 4 ~ 7
222         // 0x21 means enable 2.4G 40MHz & 5G 80MHz
223         u8      bw_mode;
224         u8      ampdu_enable;//for tx
225         u8      rx_stbc;
226         u8      ampdu_amsdu;//A-MPDU Supports A-MSDU is permitted
227         // Short GI support Bit Map
228         // BIT0 - 20MHz, 1: support, 0: non-support
229         // BIT1 - 40MHz, 1: support, 0: non-support
230         // BIT2 - 80MHz, 1: support, 0: non-support
231         // BIT3 - 160MHz, 1: support, 0: non-support
232         u8      short_gi;
233         // BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx
234         u8      ldpc_cap;
235         // BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx
236         u8      stbc_cap;
237         // BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee
238         u8      beamform_cap;
239 #endif //CONFIG_80211N_HT
240
241 #ifdef CONFIG_80211AC_VHT
242         u8      vht_enable; //0:disable, 1:enable, 2:auto
243         u8      ampdu_factor;
244         u8      vht_rate_sel;
245 #endif //CONFIG_80211AC_VHT
246
247         u8      lowrate_two_xmit;
248
249         u8      rf_config ;
250         u8      low_power ;
251
252         u8      wifi_spec;// !turbo_mode
253         u8      special_rf_path; // 0: 2T2R ,1: only turn on path A 1T1R
254         u8      channel_plan;
255 #ifdef CONFIG_BT_COEXIST
256         u8      btcoex;
257         u8      bt_iso;
258         u8      bt_sco;
259         u8      bt_ampdu;
260         s8      ant_num;
261 #endif
262         BOOLEAN bAcceptAddbaReq;
263
264         u8      antdiv_cfg;
265         u8      antdiv_type;
266
267         u8      usbss_enable;//0:disable,1:enable
268         u8      hwpdn_mode;//0:disable,1:enable,2:decide by EFUSE config
269         u8      hwpwrp_detect;//0:disable,1:enable
270
271         u8      hw_wps_pbc;//0:disable,1:enable
272
273 #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
274         char    adaptor_info_caching_file_path[PATH_LENGTH_MAX];
275 #endif
276
277 #ifdef CONFIG_LAYER2_ROAMING
278         u8      max_roaming_times; // the max number driver will try to roaming
279 #endif
280
281 #ifdef CONFIG_IOL
282         u8 fw_iol; //enable iol without other concern
283 #endif
284
285 #ifdef CONFIG_DUALMAC_CONCURRENT
286         u8      dmsp;//0:disable,1:enable
287 #endif
288
289 #ifdef CONFIG_80211D
290         u8 enable80211d;
291 #endif
292
293         u8 ifname[16];
294         u8 if2name[16];
295
296         u8 notch_filter;
297
298 #ifdef CONFIG_SPECIAL_SETTING_FOR_FUNAI_TV
299         u8 force_ant;//0 normal,1 main,2 aux
300         u8 force_igi;//0 normal
301 #endif
302
303         //define for tx power adjust
304         u8      RegEnableTxPowerLimit;
305         u8      RegEnableTxPowerByRate;
306         u8      RegPowerBase;
307         u8      RegPwrTblSel;
308         s8      TxBBSwing_2G;
309         s8      TxBBSwing_5G;
310         u8      AmplifierType_2G;
311         u8      AmplifierType_5G;
312         u8      bEn_RFE;
313         u8      RFE_Type;
314         u8  check_fw_ps;
315
316 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
317         u8      load_phy_file;
318         u8      RegDecryptCustomFile;
319 #endif
320
321 #ifdef CONFIG_MULTI_VIR_IFACES
322         u8 ext_iface_num;//primary/secondary iface is excluded
323 #endif
324         u8 qos_opt_enable;
325
326         u8 hiq_filter;
327         u8 adaptivity_en;
328         u8 adaptivity_mode;
329         u8 nhm_en;
330 };
331
332
333 //For registry parameters
334 #define RGTRY_OFT(field) ((ULONG)FIELD_OFFSET(struct registry_priv,field))
335 #define RGTRY_SZ(field)   sizeof(((struct registry_priv*) 0)->field)
336
337 #define GetRegAmplifierType2G(_Adapter) (_Adapter->registrypriv.AmplifierType_2G)
338 #define GetRegAmplifierType5G(_Adapter) (_Adapter->registrypriv.AmplifierType_5G)
339
340 #define GetRegTxBBSwing_2G(_Adapter)    (_Adapter->registrypriv.TxBBSwing_2G)
341 #define GetRegTxBBSwing_5G(_Adapter)    (_Adapter->registrypriv.TxBBSwing_5G)
342
343 #define GetRegbENRFEType(_Adapter)      (_Adapter->registrypriv.bEn_RFE)
344 #define GetRegRFEType(_Adapter) (_Adapter->registrypriv.RFE_Type)
345
346
347 #define BSSID_OFT(field) ((ULONG)FIELD_OFFSET(WLAN_BSSID_EX,field))
348 #define BSSID_SZ(field)   sizeof(((PWLAN_BSSID_EX) 0)->field)
349
350
351
352 #ifdef CONFIG_SDIO_HCI
353 #include <drv_types_sdio.h>
354 #define INTF_DATA SDIO_DATA
355 #elif defined(CONFIG_GSPI_HCI)
356 #include <drv_types_gspi.h>
357 #define INTF_DATA GSPI_DATA
358 #elif defined(CONFIG_PCI_HCI)
359 #include <drv_types_pci.h>
360 #endif
361
362 #ifdef CONFIG_CONCURRENT_MODE
363 #define is_primary_adapter(adapter) (adapter->adapter_type == PRIMARY_ADAPTER)
364 #define get_iface_type(adapter) (adapter->iface_type)
365 #else
366 #define is_primary_adapter(adapter) (1)
367 #define get_iface_type(adapter) (IFACE_PORT0)
368 #endif
369 #define GET_PRIMARY_ADAPTER(padapter) (((_adapter *)padapter)->dvobj->if1)
370 #define GET_IFACE_NUMS(padapter) (((_adapter *)padapter)->dvobj->iface_nums)
371 #define GET_ADAPTER(padapter, iface_id) (((_adapter *)padapter)->dvobj->padapters[iface_id])
372
373 #define GetDefaultAdapter(padapter)     padapter
374
375 enum _IFACE_ID {
376         IFACE_ID0, //maping to PRIMARY_ADAPTER
377         IFACE_ID1, //maping to SECONDARY_ADAPTER
378         IFACE_ID2,
379         IFACE_ID3,
380         IFACE_ID_MAX,
381 };
382
383 #ifdef CONFIG_DBG_COUNTER
384
385 struct rx_logs {
386         u32 intf_rx;
387         u32 intf_rx_err_recvframe;
388         u32 intf_rx_err_skb;
389         u32 intf_rx_report;
390         u32 core_rx;
391         u32 core_rx_pre;
392         u32 core_rx_pre_ver_err;
393         u32 core_rx_pre_mgmt;
394         u32 core_rx_pre_mgmt_err_80211w;
395         u32 core_rx_pre_mgmt_err;
396         u32 core_rx_pre_ctrl;
397         u32 core_rx_pre_ctrl_err;
398         u32 core_rx_pre_data;
399         u32 core_rx_pre_data_wapi_seq_err;
400         u32 core_rx_pre_data_wapi_key_err;
401         u32 core_rx_pre_data_handled;
402         u32 core_rx_pre_data_err;
403         u32 core_rx_pre_data_unknown;
404         u32 core_rx_pre_unknown;
405         u32 core_rx_enqueue;
406         u32 core_rx_dequeue;
407         u32 core_rx_post;
408         u32 core_rx_post_decrypt;
409         u32 core_rx_post_decrypt_wep;
410         u32 core_rx_post_decrypt_tkip;
411         u32 core_rx_post_decrypt_aes;
412         u32 core_rx_post_decrypt_wapi;
413         u32 core_rx_post_decrypt_hw;
414         u32 core_rx_post_decrypt_unknown;
415         u32 core_rx_post_decrypt_err;
416         u32 core_rx_post_defrag_err;
417         u32 core_rx_post_portctrl_err;
418         u32 core_rx_post_indicate;
419         u32 core_rx_post_indicate_in_oder;
420         u32 core_rx_post_indicate_reoder;
421         u32 core_rx_post_indicate_err;
422         u32 os_indicate;
423         u32 os_indicate_ap_mcast;
424         u32 os_indicate_ap_forward;
425         u32 os_indicate_ap_self;
426         u32 os_indicate_err;
427         u32 os_netif_ok;
428         u32 os_netif_err;
429 };
430
431 struct tx_logs {
432         u32 os_tx;
433         u32 os_tx_err_up;
434         u32 os_tx_err_xmit;
435         u32 os_tx_m2u;
436         u32 os_tx_m2u_ignore_fw_linked;
437         u32 os_tx_m2u_ignore_self;
438         u32 os_tx_m2u_entry;
439         u32 os_tx_m2u_entry_err_xmit;
440         u32 os_tx_m2u_entry_err_skb;
441         u32 os_tx_m2u_stop;
442         u32 core_tx;
443         u32 core_tx_err_pxmitframe;
444         u32 core_tx_err_brtx;
445         u32 core_tx_upd_attrib;
446         u32 core_tx_upd_attrib_adhoc;
447         u32 core_tx_upd_attrib_sta;
448         u32 core_tx_upd_attrib_ap;
449         u32 core_tx_upd_attrib_unknown;
450         u32 core_tx_upd_attrib_dhcp;
451         u32 core_tx_upd_attrib_icmp;
452         u32 core_tx_upd_attrib_active;
453         u32 core_tx_upd_attrib_err_ucast_sta;
454         u32 core_tx_upd_attrib_err_ucast_ap_link;
455         u32 core_tx_upd_attrib_err_sta;
456         u32 core_tx_upd_attrib_err_link;
457         u32 core_tx_upd_attrib_err_sec;
458         u32 core_tx_ap_enqueue_warn_fwstate;
459         u32 core_tx_ap_enqueue_warn_sta;
460         u32 core_tx_ap_enqueue_warn_nosta;
461         u32 core_tx_ap_enqueue_warn_link;
462         u32 core_tx_ap_enqueue_warn_trigger;
463         u32 core_tx_ap_enqueue_mcast;
464         u32 core_tx_ap_enqueue_ucast;
465         u32 core_tx_ap_enqueue;
466         u32 intf_tx;
467         u32 intf_tx_pending_ac;
468         u32 intf_tx_pending_fw_under_survey;
469         u32 intf_tx_pending_fw_under_linking;
470         u32 intf_tx_pending_xmitbuf;
471         u32 intf_tx_enqueue;
472         u32 core_tx_enqueue;
473         u32 core_tx_enqueue_class;
474         u32 core_tx_enqueue_class_err_sta;
475         u32 core_tx_enqueue_class_err_nosta;
476         u32 core_tx_enqueue_class_err_fwlink;
477         u32 intf_tx_direct;
478         u32 intf_tx_direct_err_coalesce;
479         u32 intf_tx_dequeue;
480         u32 intf_tx_dequeue_err_coalesce;
481         u32 intf_tx_dump_xframe;
482         u32 intf_tx_dump_xframe_err_txdesc;
483         u32 intf_tx_dump_xframe_err_port;
484 };
485
486 struct int_logs {
487         u32 all;
488         u32 err;
489         u32 tbdok;
490         u32 tbder;
491         u32 bcnderr;
492         u32 bcndma;
493         u32 bcndma_e;
494         u32 rx;
495         u32 rx_rdu;
496         u32 rx_fovw;
497         u32 txfovw;
498         u32 mgntok;
499         u32 highdok;
500         u32 bkdok;
501         u32 bedok;
502         u32 vidok;
503         u32 vodok;
504 };
505
506 #endif // CONFIG_DBG_COUNTER
507
508 struct debug_priv {
509         u32 dbg_sdio_free_irq_error_cnt;
510         u32 dbg_sdio_alloc_irq_error_cnt;
511         u32 dbg_sdio_free_irq_cnt;
512         u32 dbg_sdio_alloc_irq_cnt;
513         u32 dbg_sdio_deinit_error_cnt;
514         u32 dbg_sdio_init_error_cnt;
515         u32 dbg_suspend_error_cnt;
516         u32 dbg_suspend_cnt;
517         u32 dbg_resume_cnt;
518         u32 dbg_resume_error_cnt;
519         u32 dbg_deinit_fail_cnt;
520         u32 dbg_carddisable_cnt;
521         u32 dbg_carddisable_error_cnt;
522         u32 dbg_ps_insuspend_cnt;
523         u32     dbg_dev_unload_inIPS_cnt;
524         u32 dbg_wow_leave_ps_fail_cnt;
525         u32 dbg_scan_pwr_state_cnt;
526         u32 dbg_downloadfw_pwr_state_cnt;
527         u32 dbg_fw_read_ps_state_fail_cnt;
528         u32 dbg_leave_ips_fail_cnt;
529         u32 dbg_leave_lps_fail_cnt;
530         u32 dbg_h2c_leave32k_fail_cnt;
531         u32 dbg_diswow_dload_fw_fail_cnt;
532         u32 dbg_enwow_dload_fw_fail_cnt;
533         u32 dbg_ips_drvopen_fail_cnt;
534         u32 dbg_poll_fail_cnt;
535         u32 dbg_rpwm_toogle_cnt;
536         u32 dbg_rpwm_timeout_fail_cnt;
537         u32 dbg_sreset_cnt;
538         u64 dbg_rx_fifo_last_overflow;
539         u64 dbg_rx_fifo_curr_overflow;
540         u64 dbg_rx_fifo_diff_overflow;
541         u64 dbg_rx_ampdu_drop_count;
542         u64 dbg_rx_ampdu_forced_indicate_count;
543         u64 dbg_rx_ampdu_loss_count;
544         u64 dbg_rx_dup_mgt_frame_drop_count;
545         u64 dbg_rx_ampdu_window_shift_cnt;
546 };
547
548 struct rtw_traffic_statistics {
549         // tx statistics
550         u64     tx_bytes;
551         u64     tx_pkts;
552         u64     tx_drop;
553         u64     cur_tx_bytes;
554         u64     last_tx_bytes;
555         u32     cur_tx_tp; // Tx throughput in MBps.
556
557         // rx statistics
558         u64     rx_bytes;
559         u64     rx_pkts;
560         u64     rx_drop;
561         u64     cur_rx_bytes;
562         u64     last_rx_bytes;
563         u32     cur_rx_tp; // Rx throughput in MBps.
564 };
565
566 struct cam_ctl_t {
567         _lock lock;
568         u64 bitmap;
569 };
570
571 struct cam_entry_cache {
572         u16 ctrl;
573         u8 mac[ETH_ALEN];
574         u8 key[16];
575 };
576
577 #define KEY_FMT "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
578 #define KEY_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5], \
579         ((u8*)(x))[6],((u8*)(x))[7],((u8*)(x))[8],((u8*)(x))[9],((u8*)(x))[10],((u8*)(x))[11], \
580         ((u8*)(x))[12],((u8*)(x))[13],((u8*)(x))[14],((u8*)(x))[15]
581
582 struct macid_bmp {
583         u32 m0;
584 #if (MACID_NUM_SW_LIMIT > 32)
585         u32 m1;
586 #endif
587 #if (MACID_NUM_SW_LIMIT > 64)
588         u32 m2;
589 #endif
590 #if (MACID_NUM_SW_LIMIT > 96)
591         u32 m3;
592 #endif
593 };
594
595 struct macid_ctl_t {
596         _lock lock;
597         u8 num;
598         struct macid_bmp used;
599         struct macid_bmp bmc;
600         struct macid_bmp if_g[IFACE_ID_MAX];
601         struct macid_bmp ch_g[2]; /* 2 ch concurrency */
602 };
603
604 struct dvobj_priv
605 {
606         /*-------- below is common data --------*/      
607         _adapter *if1; //PRIMARY_ADAPTER
608         _adapter *if2; //SECONDARY_ADAPTER
609
610         s32     processing_dev_remove;
611
612         struct debug_priv drv_dbg;
613
614         _mutex hw_init_mutex;
615         _mutex h2c_fwcmd_mutex;
616         _mutex setch_mutex;
617         _mutex setbw_mutex;
618
619         unsigned char   oper_channel; //saved channel info when call set_channel_bw
620         unsigned char   oper_bwmode;
621         unsigned char   oper_ch_offset;//PRIME_CHNL_OFFSET
622         u32 on_oper_ch_time;
623
624         //extend to support mulitu interface
625         //padapters[IFACE_ID0] == if1
626         //padapters[IFACE_ID1] == if2
627         _adapter *padapters[IFACE_ID_MAX];
628         u8 iface_nums; // total number of ifaces used runtime
629
630         struct macid_ctl_t macid_ctl;
631
632         struct cam_ctl_t cam_ctl;
633         struct cam_entry_cache cam_cache[TOTAL_CAM_ENTRY];
634
635         //For 92D, DMDP have 2 interface.
636         u8      InterfaceNumber;
637         u8      NumInterfaces;
638
639         //In /Out Pipe information
640         int     RtInPipe[2];
641         int     RtOutPipe[4];
642         u8      Queue2Pipe[HW_QUEUE_ENTRY];//for out pipe mapping
643
644         u8      irq_alloc;
645         ATOMIC_T continual_io_error;
646
647         ATOMIC_T disable_func;
648
649         struct pwrctrl_priv pwrctl_priv;
650
651         struct rtw_traffic_statistics   traffic_stat;
652
653 /*-------- below is for SDIO INTERFACE --------*/
654
655 #ifdef INTF_DATA
656         INTF_DATA intf_data;
657 #endif
658
659 /*-------- below is for USB INTERFACE --------*/
660
661 #ifdef CONFIG_USB_HCI
662
663         u8      usb_speed; // 1.1, 2.0 or 3.0
664         u8      nr_endpoint;
665         u8      RtNumInPipes;
666         u8      RtNumOutPipes;
667         int     ep_num[6]; //endpoint number
668
669         int     RegUsbSS;
670
671         _sema   usb_suspend_sema;
672
673 #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
674         _mutex  usb_vendor_req_mutex;
675 #endif
676
677 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
678         u8 * usb_alloc_vendor_req_buf;
679         u8 * usb_vendor_req_buf;
680 #endif
681
682 #ifdef PLATFORM_WINDOWS
683         //related device objects
684         PDEVICE_OBJECT  pphysdevobj;//pPhysDevObj;
685         PDEVICE_OBJECT  pfuncdevobj;//pFuncDevObj;
686         PDEVICE_OBJECT  pnextdevobj;//pNextDevObj;
687
688         u8      nextdevstacksz;//unsigned char NextDeviceStackSize;     //= (CHAR)CEdevice->pUsbDevObj->StackSize + 1;
689
690         //urb for control diescriptor request
691
692 #ifdef PLATFORM_OS_XP
693         struct _URB_CONTROL_DESCRIPTOR_REQUEST descriptor_urb;
694         PUSB_CONFIGURATION_DESCRIPTOR   pconfig_descriptor;//UsbConfigurationDescriptor;
695 #endif
696
697 #ifdef PLATFORM_OS_CE
698         WCHAR                   active_path[MAX_ACTIVE_REG_PATH];       // adapter regpath
699         USB_EXTENSION   usb_extension;
700
701         _nic_hdl                pipehdls_r8192c[0x10];
702 #endif
703
704         u32     config_descriptor_len;//ULONG UsbConfigurationDescriptorLength;
705 #endif//PLATFORM_WINDOWS
706
707 #ifdef PLATFORM_LINUX
708         struct usb_interface *pusbintf;
709         struct usb_device *pusbdev;
710 #endif//PLATFORM_LINUX
711
712 #ifdef PLATFORM_FREEBSD
713         struct usb_interface *pusbintf;
714         struct usb_device *pusbdev;
715 #endif//PLATFORM_FREEBSD
716         
717 #endif//CONFIG_USB_HCI
718
719 /*-------- below is for PCIE INTERFACE --------*/
720
721 #ifdef CONFIG_PCI_HCI
722
723 #ifdef PLATFORM_LINUX
724         struct pci_dev *ppcidev;
725
726         //PCI MEM map
727         unsigned long   pci_mem_end;    /* shared mem end       */
728         unsigned long   pci_mem_start;  /* shared mem start     */
729
730         //PCI IO map
731         unsigned long   pci_base_addr;  /* device I/O address   */
732
733         //PciBridge
734         struct pci_priv pcipriv;
735
736         u16     irqline;
737         u8      irq_enabled;
738         RT_ISR_CONTENT  isr_content;
739         _lock   irq_th_lock;
740
741         //ASPM
742         u8      const_pci_aspm;
743         u8      const_amdpci_aspm;
744         u8      const_hwsw_rfoff_d3;
745         u8      const_support_pciaspm;
746         // pci-e bridge */
747         u8      const_hostpci_aspm_setting;
748         // pci-e device */
749         u8      const_devicepci_aspm_setting;
750         u8      b_support_aspm; // If it supports ASPM, Offset[560h] = 0x40, otherwise Offset[560h] = 0x00.
751         u8      b_support_backdoor;
752         u8      bdma64;
753 #endif//PLATFORM_LINUX
754
755 #endif//CONFIG_PCI_HCI
756 };
757
758 #define dvobj_to_pwrctl(dvobj) (&(dvobj->pwrctl_priv))
759 #define pwrctl_to_dvobj(pwrctl) container_of(pwrctl, struct dvobj_priv, pwrctl_priv)
760 #define dvobj_to_macidctl(dvobj) (&(dvobj->macid_ctl))
761
762 #ifdef PLATFORM_LINUX
763 static struct device *dvobj_to_dev(struct dvobj_priv *dvobj)
764 {
765         /* todo: get interface type from dvobj and the return the dev accordingly */
766 #ifdef RTW_DVOBJ_CHIP_HW_TYPE
767 #endif
768
769 #ifdef CONFIG_USB_HCI
770         return &dvobj->pusbintf->dev;
771 #endif
772 #ifdef CONFIG_SDIO_HCI
773         return &dvobj->intf_data.func->dev;
774 #endif
775 #ifdef CONFIG_GSPI_HCI
776         return &dvobj->intf_data.func->dev;
777 #endif
778 #ifdef CONFIG_PCI_HCI
779         return &dvobj->ppcidev->dev;
780 #endif
781 }
782 #endif
783
784 _adapter *dvobj_get_port0_adapter(struct dvobj_priv *dvobj);
785
786 enum _IFACE_TYPE {
787         IFACE_PORT0, //mapping to port0 for C/D series chips
788         IFACE_PORT1, //mapping to port1 for C/D series chip
789         MAX_IFACE_PORT,
790 };
791
792 enum _ADAPTER_TYPE {
793         PRIMARY_ADAPTER,
794         SECONDARY_ADAPTER,
795         MAX_ADAPTER = 0xFF,
796 };
797
798 typedef enum _DRIVER_STATE{
799         DRIVER_NORMAL = 0,
800         DRIVER_DISAPPEAR = 1,
801         DRIVER_REPLACE_DONGLE = 2,
802 }DRIVER_STATE;
803
804 #ifdef CONFIG_INTEL_PROXIM
805 struct proxim {
806         bool proxim_support;
807         bool proxim_on;
808
809         void *proximity_priv;
810         int (*proxim_rx)(_adapter *padapter,
811                 union recv_frame *precv_frame);
812         u8      (*proxim_get_var)(_adapter* padapter, u8 type);
813 };
814 #endif  //CONFIG_INTEL_PROXIM
815
816 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
817 typedef struct loopbackdata
818 {
819         _sema   sema;
820         _thread_hdl_ lbkthread;
821         u8 bstop;
822         u32 cnt;
823         u16 size;
824         u16 txsize;
825         u8 txbuf[0x8000];
826         u16 rxsize;
827         u8 rxbuf[0x8000];
828         u8 msg[100];
829
830 }LOOPBACKDATA, *PLOOPBACKDATA;
831 #endif
832
833 struct _ADAPTER{
834         int     DriverState;// for disable driver using module, use dongle to replace module.
835         int     pid[3];//process id from UI, 0:wps, 1:hostapd, 2:dhcpcd
836         int     bDongle;//build-in module or external dongle
837         u16     chip_type;
838         u16     HardwareType;
839         u16     interface_type;//USB,SDIO,SPI,PCI
840
841         struct dvobj_priv *dvobj;
842         struct  mlme_priv mlmepriv;
843         struct  mlme_ext_priv mlmeextpriv;
844         struct  cmd_priv        cmdpriv;
845         struct  evt_priv        evtpriv;
846         //struct        io_queue        *pio_queue;
847         struct  io_priv iopriv;
848         struct  xmit_priv       xmitpriv;
849         struct  recv_priv       recvpriv;
850         struct  sta_priv        stapriv;
851         struct  security_priv   securitypriv;
852         _lock   security_key_mutex; // add for CONFIG_IEEE80211W, none 11w also can use
853         struct  registry_priv   registrypriv;
854         struct  eeprom_priv eeprompriv;
855         struct  led_priv        ledpriv;
856
857 #ifdef CONFIG_MP_INCLUDED
858        struct   mp_priv mppriv;
859 #endif
860
861 #ifdef CONFIG_DRVEXT_MODULE
862         struct  drvext_priv     drvextpriv;
863 #endif
864
865 #ifdef CONFIG_AP_MODE
866         struct  hostapd_priv    *phostapdpriv;
867 #endif
868
869 #ifdef CONFIG_IOCTL_CFG80211
870 #ifdef CONFIG_P2P
871         struct cfg80211_wifidirect_info cfg80211_wdinfo;
872 #endif //CONFIG_P2P
873 #endif //CONFIG_IOCTL_CFG80211
874         u32     setband;
875 #ifdef CONFIG_P2P
876         struct wifidirect_info  wdinfo;
877 #endif //CONFIG_P2P
878
879 #ifdef CONFIG_TDLS
880         struct tdls_info        tdlsinfo;
881 #endif //CONFIG_TDLS
882
883 #ifdef CONFIG_WAPI_SUPPORT
884         u8      WapiSupport;
885         RT_WAPI_T       wapiInfo;
886 #endif
887
888
889 #ifdef CONFIG_WFD
890         struct wifi_display_info wfd_info;
891 #endif //CONFIG_WFD
892
893         PVOID                   HalData;
894         u32 hal_data_sz;
895         struct hal_ops  HalFunc;
896
897         s32     bDriverStopped;
898         s32     bSurpriseRemoved;
899         s32  bCardDisableWOHSM;
900
901         u32     IsrContent;
902         u32     ImrContent;
903
904         u8      EepromAddressSize;
905         u8      hw_init_completed;
906         u8      bDriverIsGoingToUnload;
907         u8      init_adpt_in_progress;
908         u8      bHaltInProgress;
909 #ifdef CONFIG_GPIO_API  
910         u8      pre_gpio_pin;
911 #endif  
912         _thread_hdl_ cmdThread;
913         _thread_hdl_ evtThread;
914         _thread_hdl_ xmitThread;
915         _thread_hdl_ recvThread;
916
917 #ifndef PLATFORM_LINUX
918         NDIS_STATUS (*dvobj_init)(struct dvobj_priv *dvobj);
919         void (*dvobj_deinit)(struct dvobj_priv *dvobj);
920 #endif
921
922         u32 (*intf_init)(struct dvobj_priv *dvobj);
923         void (*intf_deinit)(struct dvobj_priv *dvobj);
924         int (*intf_alloc_irq)(struct dvobj_priv *dvobj);
925         void (*intf_free_irq)(struct dvobj_priv *dvobj);
926         
927
928         void (*intf_start)(_adapter * adapter);
929         void (*intf_stop)(_adapter * adapter);
930
931 #ifdef PLATFORM_WINDOWS
932         _nic_hdl                hndis_adapter;//hNdisAdapter(NDISMiniportAdapterHandle);
933         _nic_hdl                hndis_config;//hNdisConfiguration;
934         NDIS_STRING fw_img;
935
936         u32     NdisPacketFilter;
937         u8      MCList[MAX_MCAST_LIST_NUM][6];
938         u32     MCAddrCount;
939 #endif //end of PLATFORM_WINDOWS
940
941
942 #ifdef PLATFORM_LINUX
943         _nic_hdl pnetdev;
944         char old_ifname[IFNAMSIZ];
945
946         // used by rtw_rereg_nd_name related function
947         struct rereg_nd_name_data {
948                 _nic_hdl old_pnetdev;
949                 char old_ifname[IFNAMSIZ];
950                 u8 old_ips_mode;
951                 u8 old_bRegUseLed;
952         } rereg_nd_name_priv;
953
954         int bup;
955         struct net_device_stats stats;
956         struct iw_statistics iwstats;
957         struct proc_dir_entry *dir_dev;// for proc directory
958         struct proc_dir_entry *dir_odm;
959
960 #ifdef CONFIG_IOCTL_CFG80211
961         struct wireless_dev *rtw_wdev;
962         struct rtw_wdev_priv wdev_data;
963 #endif //CONFIG_IOCTL_CFG80211
964
965 #endif //end of PLATFORM_LINUX
966
967 #ifdef PLATFORM_FREEBSD
968         _nic_hdl pifp;
969         int bup;
970         _lock glock;
971 #endif //PLATFORM_FREEBSD
972         int net_closed;
973         
974         u8 netif_up;
975
976         u8 bFWReady;
977         u8 bBTFWReady;
978         u8 bLinkInfoDump;
979         u8 bRxRSSIDisplay;
980         //      Added by Albert 2012/10/26
981         //      The driver will show up the desired channel number when this flag is 1.
982         u8 bNotifyChannelChange;
983 #ifdef CONFIG_P2P
984         //      Added by Albert 2012/12/06
985         //      The driver will show the current P2P status when the upper application reads it.
986         u8 bShowGetP2PState;
987 #endif
988 #ifdef CONFIG_AUTOSUSPEND
989         u8      bDisableAutosuspend;
990 #endif
991
992         //pbuddy_adapter is used only in  two inteface case, (iface_nums=2 in struct dvobj_priv)
993         //PRIMARY_ADAPTER's buddy is SECONDARY_ADAPTER
994         //SECONDARY_ADAPTER's buddy is PRIMARY_ADAPTER
995         //for iface_id > SECONDARY_ADAPTER(IFACE_ID1), refer to padapters[iface_id]  in struct dvobj_priv
996         //and their pbuddy_adapter is PRIMARY_ADAPTER.
997         //for PRIMARY_ADAPTER(IFACE_ID0) can directly refer to if1 in struct dvobj_priv
998         _adapter *pbuddy_adapter;
999
1000 #if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT)
1001         u8 isprimary; //is primary adapter or not
1002         //notes:
1003         // if isprimary is true, the adapter_type value is 0, iface_id is IFACE_ID0 for PRIMARY_ADAPTER
1004         // if isprimary is false, the adapter_type value is 1, iface_id is IFACE_ID1 for SECONDARY_ADAPTER
1005         // refer to iface_id if iface_nums>2 and isprimary is false and the adapter_type value is 0xff.
1006         u8 adapter_type;//used only in  two inteface case(PRIMARY_ADAPTER and SECONDARY_ADAPTER) .
1007         u8 iface_type; //interface port type, it depends on HW port
1008 #endif //CONFIG_CONCURRENT_MODE || CONFIG_DUALMAC_CONCURRENT
1009
1010         //extend to support multi interface
1011        //IFACE_ID0 is equals to PRIMARY_ADAPTER
1012        //IFACE_ID1 is equals to SECONDARY_ADAPTER
1013         u8 iface_id;
1014
1015 #ifdef CONFIG_DUALMAC_CONCURRENT
1016         u8 DualMacConcurrent; // 1: DMSP 0:DMDP
1017 #endif
1018
1019 #ifdef CONFIG_BR_EXT
1020         _lock                                   br_ext_lock;
1021         //unsigned int                  macclone_completed;
1022         struct nat25_network_db_entry   *nethash[NAT25_HASH_SIZE];
1023         int                             pppoe_connection_in_progress;
1024         unsigned char                   pppoe_addr[MACADDRLEN];
1025         unsigned char                   scdb_mac[MACADDRLEN];
1026         unsigned char                   scdb_ip[4];
1027         struct nat25_network_db_entry   *scdb_entry;
1028         unsigned char                   br_mac[MACADDRLEN];
1029         unsigned char                   br_ip[4];
1030
1031         struct br_ext_info              ethBrExtInfo;
1032 #endif  // CONFIG_BR_EXT
1033
1034 #ifdef CONFIG_INTEL_PROXIM
1035         /* intel Proximity, should be alloc mem
1036          * in intel Proximity module and can only
1037          * be used in intel Proximity mode */
1038         struct proxim proximity;
1039 #endif  //CONFIG_INTEL_PROXIM
1040
1041 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
1042         PLOOPBACKDATA ploopback;
1043 #endif
1044
1045         //for debug purpose
1046         u8 fix_rate;
1047         u8 data_fb; /* data rate fallback, valid only when fix_rate is not 0xff */
1048         u8 driver_vcs_en; //Enable=1, Disable=0 driver control vrtl_carrier_sense for tx
1049         u8 driver_vcs_type;//force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en=1.
1050         u8 driver_ampdu_spacing;//driver control AMPDU Density for peer sta's rx
1051         u8 driver_rx_ampdu_factor;//0xff: disable drv ctrl, 0:8k, 1:16k, 2:32k, 3:64k;
1052         u8 fix_ba_rxbuf_bz; /* 0~127, TODO:consider each sta and each TID */
1053         u8 driver_rx_ampdu_spacing;  //driver control Rx AMPDU Density 
1054         unsigned char     in_cta_test;
1055
1056 #ifdef CONFIG_DBG_COUNTER       
1057         struct rx_logs rx_logs;
1058         struct tx_logs tx_logs;
1059         struct int_logs int_logs;
1060 #endif
1061 };
1062
1063 #define adapter_to_dvobj(adapter) (adapter->dvobj)
1064 #define adapter_to_pwrctl(adapter) (dvobj_to_pwrctl(adapter->dvobj))
1065 #define adapter_wdev_data(adapter) (&((adapter)->wdev_data))
1066
1067 //
1068 // Function disabled.
1069 //
1070 #define DF_TX_BIT               BIT0
1071 #define DF_RX_BIT               BIT1
1072 #define DF_IO_BIT               BIT2
1073
1074 //#define RTW_DISABLE_FUNC(padapter, func) (ATOMIC_ADD(&adapter_to_dvobj(padapter)->disable_func, (func)))
1075 //#define RTW_ENABLE_FUNC(padapter, func) (ATOMIC_SUB(&adapter_to_dvobj(padapter)->disable_func, (func)))
1076 __inline static void RTW_DISABLE_FUNC(_adapter*padapter, int func_bit)
1077 {
1078         int     df = ATOMIC_READ(&adapter_to_dvobj(padapter)->disable_func);
1079         df |= func_bit;
1080         ATOMIC_SET(&adapter_to_dvobj(padapter)->disable_func, df);
1081 }
1082
1083 __inline static void RTW_ENABLE_FUNC(_adapter*padapter, int func_bit)
1084 {
1085         int     df = ATOMIC_READ(&adapter_to_dvobj(padapter)->disable_func);
1086         df &= ~(func_bit);
1087         ATOMIC_SET(&adapter_to_dvobj(padapter)->disable_func, df);
1088 }
1089
1090 #define RTW_IS_FUNC_DISABLED(padapter, func_bit) (ATOMIC_READ(&adapter_to_dvobj(padapter)->disable_func) & (func_bit))
1091
1092 #define RTW_CANNOT_IO(padapter) \
1093                         ((padapter)->bSurpriseRemoved || \
1094                          RTW_IS_FUNC_DISABLED((padapter), DF_IO_BIT))
1095
1096 #define RTW_CANNOT_RX(padapter) \
1097                         ((padapter)->bDriverStopped || \
1098                          (padapter)->bSurpriseRemoved || \
1099                          RTW_IS_FUNC_DISABLED((padapter), DF_RX_BIT))
1100
1101 #define RTW_CANNOT_TX(padapter) \
1102                         ((padapter)->bDriverStopped || \
1103                          (padapter)->bSurpriseRemoved || \
1104                          RTW_IS_FUNC_DISABLED((padapter), DF_TX_BIT))
1105
1106 int rtw_handle_dualmac(_adapter *adapter, bool init);
1107
1108 #ifdef CONFIG_PNO_SUPPORT
1109 int rtw_parse_ssid_list_tlv(char** list_str, pno_ssid_t* ssid, int max, int *bytes_left);
1110 int rtw_dev_pno_set(struct net_device *net, pno_ssid_t* ssid, int num, 
1111                                         int pno_time, int pno_repeat, int pno_freq_expo_max);
1112 #ifdef CONFIG_PNO_SET_DEBUG
1113 void rtw_dev_pno_debug(struct net_device *net);
1114 #endif //CONFIG_PNO_SET_DEBUG
1115 #endif //CONFIG_PNO_SUPPORT
1116
1117 #ifdef CONFIG_WOWLAN
1118 int rtw_suspend_wow(_adapter *padapter);
1119 int rtw_resume_process_wow(_adapter *padapter);
1120 #endif
1121
1122 __inline static u8 *myid(struct eeprom_priv *peepriv)
1123 {
1124         return (peepriv->mac_addr);
1125 }
1126
1127 // HCI Related header file
1128 #ifdef CONFIG_USB_HCI
1129 #include <usb_osintf.h>
1130 #include <usb_ops.h>
1131 #include <usb_hal.h>
1132 #endif
1133
1134 #ifdef CONFIG_SDIO_HCI
1135 #include <sdio_osintf.h>
1136 #include <sdio_ops.h>
1137 #include <sdio_hal.h>
1138 #endif
1139
1140 #ifdef CONFIG_GSPI_HCI
1141 #include <gspi_osintf.h>
1142 #include <gspi_ops.h>
1143 #include <gspi_hal.h>
1144 #endif
1145
1146 #ifdef CONFIG_PCI_HCI
1147 #include <pci_osintf.h>
1148 #include <pci_ops.h>
1149 #include <pci_hal.h>
1150 #endif
1151
1152 #ifdef CONFIG_BT_COEXIST
1153 #include <rtw_btcoex.h>
1154 #endif // CONFIG_BT_COEXIST
1155
1156 #endif //__DRV_TYPES_H__
1157