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