1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 /*-------------------------------------------------------------------------------
8
9 For type defines and data structure defines
10
11 --------------------------------------------------------------------------------*/
12
13
14 #ifndef __DRV_TYPES_H__
15 #define __DRV_TYPES_H__
16
17 #include <linux/sched/signal.h>
18 #include <basic_types.h>
19 #include <osdep_service.h>
20 #include <rtw_byteorder.h>
21 #include <wlan_bssdef.h>
22 #include <wifi.h>
23 #include <ieee80211.h>
24
25 #include <rtw_rf.h>
26
27 #include <rtw_ht.h>
28
29 #include <rtw_cmd.h>
30 #include <cmd_osdep.h>
31 #include <rtw_security.h>
32 #include <rtw_xmit.h>
33 #include <xmit_osdep.h>
34 #include <rtw_recv.h>
35
36 #include <recv_osdep.h>
37 #include <rtw_efuse.h>
38 #include <hal_intf.h>
39 #include <hal_com.h>
40 #include <rtw_qos.h>
41 #include <rtw_pwrctrl.h>
42 #include <rtw_mlme.h>
43 #include <mlme_osdep.h>
44 #include <rtw_io.h>
45 #include <rtw_ioctl_set.h>
46 #include <osdep_intf.h>
47 #include <rtw_eeprom.h>
48 #include <sta_info.h>
49 #include <rtw_event.h>
50 #include <rtw_mlme_ext.h>
51 #include <rtw_ap.h>
52 #include <rtw_version.h>
53
54 #include "ioctl_cfg80211.h"
55
56 #include <linux/ip.h>
57 #include <linux/if_ether.h>
58
59 #define SPEC_DEV_ID_NONE BIT(0)
60 #define SPEC_DEV_ID_DISABLE_HT BIT(1)
61 #define SPEC_DEV_ID_ENABLE_PS BIT(2)
62 #define SPEC_DEV_ID_RF_CONFIG_1T1R BIT(3)
63 #define SPEC_DEV_ID_RF_CONFIG_2T2R BIT(4)
64 #define SPEC_DEV_ID_ASSIGN_IFNAME BIT(5)
65
66 struct registry_priv {
67 u8 chip_version;
68 u8 rfintfs;
69 u8 lbkmode;
70 u8 hci;
71 struct ndis_802_11_ssid ssid;
72 u8 network_mode; /* infra, ad-hoc, auto */
73 u8 channel;/* ad-hoc support requirement */
74 u8 wireless_mode;/* A, B, G, auto */
75 u8 scan_mode;/* active, passive */
76 u8 radio_enable;
77 u8 preamble;/* long, short, auto */
78 u8 vrtl_carrier_sense;/* Enable, Disable, Auto */
79 u8 vcs_type;/* RTS/CTS, CTS-to-self */
80 u16 rts_thresh;
81 u16 frag_thresh;
82 u8 adhoc_tx_pwr;
83 u8 soft_ap;
84 u8 power_mgnt;
85 u8 ips_mode;
86 u8 smart_ps;
87 u8 usb_rxagg_mode;
88 u8 long_retry_lmt;
89 u8 short_retry_lmt;
90 u16 busy_thresh;
91 u8 ack_policy;
92 u8 mp_dm;
93 u8 software_encrypt;
94 u8 software_decrypt;
95 u8 acm_method;
96 /* UAPSD */
97 u8 wmm_enable;
98 u8 uapsd_enable;
99 u8 uapsd_max_sp;
100 u8 uapsd_acbk_en;
101 u8 uapsd_acbe_en;
102 u8 uapsd_acvi_en;
103 u8 uapsd_acvo_en;
104
105 struct wlan_bssid_ex dev_network;
106
107 u8 ht_enable;
108 /*
109 * 0: 20 MHz, 1: 40 MHz
110 * 2.4G use bit 0 ~ 3
111 * 0x01 means enable 2.4G 40MHz
112 */
113 u8 bw_mode;
114 u8 ampdu_enable;/* for tx */
115 u8 rx_stbc;
116 u8 ampdu_amsdu;/* A-MPDU Supports A-MSDU is permitted */
117 /* Short GI support Bit Map */
118 /* BIT0 - 20MHz, 1: support, 0: non-support */
119 /* BIT1 - 40MHz, 1: support, 0: non-support */
120 /* BIT2 - 80MHz, 1: support, 0: non-support */
121 /* BIT3 - 160MHz, 1: support, 0: non-support */
122 u8 short_gi;
123 /* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */
124 u8 ldpc_cap;
125 /* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */
126 u8 stbc_cap;
127 /* BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee */
128 u8 beamform_cap;
129
130 u8 lowrate_two_xmit;
131
132 u8 low_power;
133
134 u8 wifi_spec;/* !turbo_mode */
135
136 u8 channel_plan;
137
138 s8 ant_num;
139
140 /* false:Reject AP's Add BA req, true:accept AP's Add BA req */
141 bool accept_addba_req;
142
143 u8 antdiv_cfg;
144 u8 antdiv_type;
145
146 u8 usbss_enable;/* 0:disable, 1:enable */
147 u8 hwpdn_mode;/* 0:disable, 1:enable, 2:decide by EFUSE config */
148 u8 hwpwrp_detect;/* 0:disable, 1:enable */
149
150 u8 hw_wps_pbc;/* 0:disable, 1:enable */
151
152 u8 max_roaming_times; /* the max number driver will try to roaming */
153
154 u8 enable80211d;
155
156 u8 ifname[16];
157
158 u8 notch_filter;
159
160 /* define for tx power adjust */
161 u8 RegEnableTxPowerLimit;
162 u8 RegEnableTxPowerByRate;
163 u8 RegPowerBase;
164 u8 RegPwrTblSel;
165 s8 TxBBSwing_2G;
166 u8 AmplifierType_2G;
167 u8 bEn_RFE;
168 u8 RFE_Type;
169 u8 check_fw_ps;
170
171 u8 qos_opt_enable;
172
173 u8 hiq_filter;
174 };
175
176
177 /* For registry parameters */
178 #define RGTRY_OFT(field) ((u32)FIELD_OFFSET(struct registry_priv, field))
179 #define RGTRY_SZ(field) sizeof(((struct registry_priv *)0)->field)
180 #define BSSID_OFT(field) ((u32)FIELD_OFFSET(struct wlan_bssid_ex, field))
181 #define BSSID_SZ(field) sizeof(((struct wlan_bssid_ex *) 0)->field)
182
183 #include <drv_types_sdio.h>
184
185 #define is_primary_adapter(adapter) (1)
186 #define get_iface_type(adapter) (IFACE_PORT0)
187 #define GET_PRIMARY_ADAPTER(padapter) (((struct adapter *)padapter)->dvobj->if1)
188 #define GET_IFACE_NUMS(padapter) (((struct adapter *)padapter)->dvobj->iface_nums)
189 #define GET_ADAPTER(padapter, iface_id) (((struct adapter *)padapter)->dvobj->padapters[iface_id])
190
191 struct debug_priv {
192 u32 dbg_sdio_free_irq_error_cnt;
193 u32 dbg_sdio_alloc_irq_error_cnt;
194 u32 dbg_sdio_free_irq_cnt;
195 u32 dbg_sdio_alloc_irq_cnt;
196 u32 dbg_sdio_deinit_error_cnt;
197 u32 dbg_sdio_init_error_cnt;
198 u32 dbg_suspend_error_cnt;
199 u32 dbg_suspend_cnt;
200 u32 dbg_resume_cnt;
201 u32 dbg_resume_error_cnt;
202 u32 dbg_deinit_fail_cnt;
203 u32 dbg_carddisable_cnt;
204 u32 dbg_carddisable_error_cnt;
205 u32 dbg_ps_insuspend_cnt;
206 u32 dbg_dev_unload_inIPS_cnt;
207 u32 dbg_wow_leave_ps_fail_cnt;
208 u32 dbg_scan_pwr_state_cnt;
209 u32 dbg_downloadfw_pwr_state_cnt;
210 u32 dbg_fw_read_ps_state_fail_cnt;
211 u32 dbg_leave_ips_fail_cnt;
212 u32 dbg_leave_lps_fail_cnt;
213 u32 dbg_h2c_leave32k_fail_cnt;
214 u32 dbg_diswow_dload_fw_fail_cnt;
215 u32 dbg_enwow_dload_fw_fail_cnt;
216 u32 dbg_ips_drvopen_fail_cnt;
217 u32 dbg_poll_fail_cnt;
218 u32 dbg_rpwm_toggle_cnt;
219 u32 dbg_rpwm_timeout_fail_cnt;
220 u64 dbg_rx_fifo_last_overflow;
221 u64 dbg_rx_fifo_curr_overflow;
222 u64 dbg_rx_fifo_diff_overflow;
223 u64 dbg_rx_ampdu_drop_count;
224 u64 dbg_rx_ampdu_forced_indicate_count;
225 u64 dbg_rx_ampdu_loss_count;
226 u64 dbg_rx_dup_mgt_frame_drop_count;
227 u64 dbg_rx_ampdu_window_shift_cnt;
228 };
229
230 struct rtw_traffic_statistics {
231 /* tx statistics */
232 u64 tx_bytes;
233 u64 tx_pkts;
234 u64 tx_drop;
235 u64 cur_tx_bytes;
236 u64 last_tx_bytes;
237 u32 cur_tx_tp; /* Tx throughput in MBps. */
238
239 /* rx statistics */
240 u64 rx_bytes;
241 u64 rx_pkts;
242 u64 rx_drop;
243 u64 cur_rx_bytes;
244 u64 last_rx_bytes;
245 u32 cur_rx_tp; /* Rx throughput in MBps. */
246 };
247
248 struct cam_ctl_t {
249 spinlock_t lock;
250 u64 bitmap;
251 };
252
253 struct cam_entry_cache {
254 u16 ctrl;
255 u8 mac[ETH_ALEN];
256 u8 key[16];
257 };
258
259 struct dvobj_priv {
260 /*-------- below is common data --------*/
261 struct adapter *if1; /* PRIMARY_ADAPTER */
262
263 s32 processing_dev_remove;
264
265 struct debug_priv drv_dbg;
266
267 /* for local/global synchronization */
268 /* */
269 spinlock_t lock;
270 int macid[NUM_STA];
271
272 struct mutex hw_init_mutex;
273 struct mutex h2c_fwcmd_mutex;
274 struct mutex setch_mutex;
275 struct mutex setbw_mutex;
276
277 unsigned char oper_channel; /* saved channel info when call set_channel_bw */
278 unsigned char oper_bwmode;
279 unsigned char oper_ch_offset;/* PRIME_CHNL_OFFSET */
280 unsigned long on_oper_ch_time;
281
282 struct adapter *padapters;
283
284 struct cam_ctl_t cam_ctl;
285 struct cam_entry_cache cam_cache[TOTAL_CAM_ENTRY];
286
287 /* In /Out Pipe information */
288 int RtInPipe[2];
289 int RtOutPipe[4];
290 u8 Queue2Pipe[HW_QUEUE_ENTRY];/* for out pipe mapping */
291
292 u8 irq_alloc;
293 atomic_t continual_io_error;
294
295 atomic_t disable_func;
296
297 struct pwrctrl_priv pwrctl_priv;
298
299 struct rtw_traffic_statistics traffic_stat;
300
301 /*-------- below is for SDIO INTERFACE --------*/
302
303 struct sdio_data intf_data;
304
305 };
306
307 #define dvobj_to_pwrctl(dvobj) (&(dvobj->pwrctl_priv))
308 #define pwrctl_to_dvobj(pwrctl) container_of(pwrctl, struct dvobj_priv, pwrctl_priv)
309
dvobj_to_dev(struct dvobj_priv * dvobj)310 static inline struct device *dvobj_to_dev(struct dvobj_priv *dvobj)
311 {
312 /* todo: get interface type from dvobj and the return the dev accordingly */
313 #ifdef RTW_DVOBJ_CHIP_HW_TYPE
314 #endif
315
316 return &dvobj->intf_data.func->dev;
317 }
318
319 struct adapter *dvobj_get_port0_adapter(struct dvobj_priv *dvobj);
320
321 enum {
322 IFACE_PORT0, /* mapping to port0 for C/D series chips */
323 IFACE_PORT1, /* mapping to port1 for C/D series chip */
324 MAX_IFACE_PORT,
325 };
326
327 enum {
328 DRIVER_NORMAL = 0,
329 DRIVER_DISAPPEAR = 1,
330 DRIVER_REPLACE_DONGLE = 2,
331 };
332
333 struct adapter {
334 int DriverState;/* for disable driver using module, use dongle to replace module. */
335 int pid[3];/* process id from UI, 0:wps, 1:hostapd, 2:dhcpcd */
336 int bDongle;/* build-in module or external dongle */
337
338 struct dvobj_priv *dvobj;
339 struct mlme_priv mlmepriv;
340 struct mlme_ext_priv mlmeextpriv;
341 struct cmd_priv cmdpriv;
342 struct evt_priv evtpriv;
343 /* struct io_queue *pio_queue; */
344 struct io_priv iopriv;
345 struct xmit_priv xmitpriv;
346 struct recv_priv recvpriv;
347 struct sta_priv stapriv;
348 struct security_priv securitypriv;
349 spinlock_t security_key_mutex; /* add for CONFIG_IEEE80211W, none 11w also can use */
350 struct registry_priv registrypriv;
351 struct eeprom_priv eeprompriv;
352
353 struct hostapd_priv *phostapdpriv;
354
355 u32 setband;
356
357 void *HalData;
358 u32 hal_data_sz;
359 struct hal_ops HalFunc;
360
361 s32 bDriverStopped;
362 s32 bSurpriseRemoved;
363 s32 bCardDisableWOHSM;
364
365 u32 IsrContent;
366 u32 ImrContent;
367
368 u8 EepromAddressSize;
369 u8 hw_init_completed;
370 u8 bDriverIsGoingToUnload;
371 u8 init_adpt_in_progress;
372 u8 bHaltInProgress;
373
374 void *cmdThread;
375 void *evtThread;
376 void *xmitThread;
377 void *recvThread;
378
379 u32 (*intf_init)(struct dvobj_priv *dvobj);
380 void (*intf_deinit)(struct dvobj_priv *dvobj);
381 int (*intf_alloc_irq)(struct dvobj_priv *dvobj);
382 void (*intf_free_irq)(struct dvobj_priv *dvobj);
383
384
385 void (*intf_start)(struct adapter *adapter);
386 void (*intf_stop)(struct adapter *adapter);
387
388 struct net_device *pnetdev;
389 char old_ifname[IFNAMSIZ];
390
391 /* used by rtw_rereg_nd_name related function */
392 struct rereg_nd_name_data {
393 struct net_device *old_pnetdev;
394 char old_ifname[IFNAMSIZ];
395 u8 old_bRegUseLed;
396 } rereg_nd_name_priv;
397
398 int bup;
399 struct net_device_stats stats;
400 struct iw_statistics iwstats;
401
402 struct wireless_dev *rtw_wdev;
403 struct rtw_wdev_priv wdev_data;
404
405 int net_closed;
406
407 u8 netif_up;
408
409 u8 bFWReady;
410 u8 bBTFWReady;
411 u8 bLinkInfoDump;
412 u8 bRxRSSIDisplay;
413 /* Added by Albert 2012/10/26 */
414 /* The driver will show up the desired channel number when this flag is 1. */
415 u8 bNotifyChannelChange;
416
417 /* pbuddystruct adapter is used only in two interface case, (iface_nums =2 in struct dvobj_priv) */
418 /* PRIMARY ADAPTER's buddy is SECONDARY_ADAPTER */
419 /* SECONDARY_ADAPTER's buddy is PRIMARY_ADAPTER */
420 /* for iface_id > SECONDARY_ADAPTER(IFACE_ID1), refer to padapters[iface_id] in struct dvobj_priv */
421 /* and their pbuddystruct adapter is PRIMARY_ADAPTER. */
422 /* for PRIMARY_ADAPTER(IFACE_ID0) can directly refer to if1 in struct dvobj_priv */
423 struct adapter *pbuddy_adapter;
424
425 /* extend to support multi interface */
426 /* IFACE_ID0 is equals to PRIMARY_ADAPTER */
427 /* IFACE_ID1 is equals to SECONDARY_ADAPTER */
428 u8 iface_id;
429
430 /* for debug purpose */
431 u8 fix_rate;
432 u8 driver_vcs_en; /* Enable = 1, Disable = 0 driver control vrtl_carrier_sense for tx */
433 u8 driver_vcs_type;/* force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en = 1. */
434 u8 driver_ampdu_spacing;/* driver control AMPDU Density for peer sta's rx */
435 u8 driver_rx_ampdu_factor;/* 0xff: disable drv ctrl, 0:8k, 1:16k, 2:32k, 3:64k; */
436
437 unsigned char in_cta_test;
438 };
439
440 #define adapter_to_dvobj(adapter) (adapter->dvobj)
441 #define adapter_to_pwrctl(adapter) (dvobj_to_pwrctl(adapter->dvobj))
442 #define adapter_wdev_data(adapter) (&((adapter)->wdev_data))
443
444 /* */
445 /* Function disabled. */
446 /* */
447 #define DF_TX_BIT BIT0
448 #define DF_RX_BIT BIT1
449 #define DF_IO_BIT BIT2
450
451 /* define RTW_DISABLE_FUNC(padapter, func) (atomic_add(&adapter_to_dvobj(padapter)->disable_func, (func))) */
452 /* define RTW_ENABLE_FUNC(padapter, func) (atomic_sub(&adapter_to_dvobj(padapter)->disable_func, (func))) */
RTW_DISABLE_FUNC(struct adapter * padapter,int func_bit)453 static inline void RTW_DISABLE_FUNC(struct adapter *padapter, int func_bit)
454 {
455 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func);
456 df |= func_bit;
457 atomic_set(&adapter_to_dvobj(padapter)->disable_func, df);
458 }
459
RTW_ENABLE_FUNC(struct adapter * padapter,int func_bit)460 static inline void RTW_ENABLE_FUNC(struct adapter *padapter, int func_bit)
461 {
462 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func);
463 df &= ~(func_bit);
464 atomic_set(&adapter_to_dvobj(padapter)->disable_func, df);
465 }
466
467 #define RTW_IS_FUNC_DISABLED(padapter, func_bit) (atomic_read(&adapter_to_dvobj(padapter)->disable_func) & (func_bit))
468
469 #define RTW_CANNOT_IO(padapter) \
470 ((padapter)->bSurpriseRemoved || \
471 RTW_IS_FUNC_DISABLED((padapter), DF_IO_BIT))
472
473 #define RTW_CANNOT_RX(padapter) \
474 ((padapter)->bDriverStopped || \
475 (padapter)->bSurpriseRemoved || \
476 RTW_IS_FUNC_DISABLED((padapter), DF_RX_BIT))
477
478 #define RTW_CANNOT_TX(padapter) \
479 ((padapter)->bDriverStopped || \
480 (padapter)->bSurpriseRemoved || \
481 RTW_IS_FUNC_DISABLED((padapter), DF_TX_BIT))
482
myid(struct eeprom_priv * peepriv)483 static inline u8 *myid(struct eeprom_priv *peepriv)
484 {
485 return peepriv->mac_addr;
486 }
487
488 /* HCI Related header file */
489 #include <sdio_osintf.h>
490 #include <sdio_ops.h>
491 #include <sdio_hal.h>
492
493 #include <rtw_btcoex.h>
494
495 extern char *rtw_initmac;
496 extern int rtw_mc2u_disable;
497 extern int rtw_ht_enable;
498 extern u32 g_wait_hiq_empty;
499 extern u8 g_fwdl_wintint_rdy_fail;
500 extern u8 g_fwdl_chksum_fail;
501
502 #endif /* __DRV_TYPES_H__ */
503