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 
pwrctl_to_dvobj(struct pwrctrl_priv * pwrctl_priv)309 static inline struct dvobj_priv *pwrctl_to_dvobj(struct pwrctrl_priv *pwrctl_priv)
310 {
311 	return container_of(pwrctl_priv, struct dvobj_priv, pwrctl_priv);
312 }
313 
dvobj_to_dev(struct dvobj_priv * dvobj)314 static inline struct device *dvobj_to_dev(struct dvobj_priv *dvobj)
315 {
316 	/* todo: get interface type from dvobj and the return the dev accordingly */
317 #ifdef RTW_DVOBJ_CHIP_HW_TYPE
318 #endif
319 
320 	return &dvobj->intf_data.func->dev;
321 }
322 
323 struct adapter *dvobj_get_port0_adapter(struct dvobj_priv *dvobj);
324 
325 enum {
326 	IFACE_PORT0, /* mapping to port0 for C/D series chips */
327 	IFACE_PORT1, /* mapping to port1 for C/D series chip */
328 	MAX_IFACE_PORT,
329 };
330 
331 enum {
332 	DRIVER_NORMAL = 0,
333 	DRIVER_DISAPPEAR = 1,
334 	DRIVER_REPLACE_DONGLE = 2,
335 };
336 
337 struct adapter {
338 	int	DriverState;/*  for disable driver using module, use dongle to replace module. */
339 	int	pid[3];/* process id from UI, 0:wps, 1:hostapd, 2:dhcpcd */
340 	int	bDongle;/* build-in module or external dongle */
341 
342 	struct dvobj_priv *dvobj;
343 	struct	mlme_priv mlmepriv;
344 	struct	mlme_ext_priv mlmeextpriv;
345 	struct	cmd_priv cmdpriv;
346 	struct	evt_priv evtpriv;
347 	/* struct	io_queue	*pio_queue; */
348 	struct	io_priv iopriv;
349 	struct	xmit_priv xmitpriv;
350 	struct	recv_priv recvpriv;
351 	struct	sta_priv stapriv;
352 	struct	security_priv securitypriv;
353 	spinlock_t   security_key_mutex; /*  add for CONFIG_IEEE80211W, none 11w also can use */
354 	struct	registry_priv registrypriv;
355 	struct	eeprom_priv eeprompriv;
356 
357 	struct	hostapd_priv *phostapdpriv;
358 
359 	u32 setband;
360 
361 	void *HalData;
362 	u32 hal_data_sz;
363 	struct hal_ops	HalFunc;
364 
365 	s32	bDriverStopped;
366 	s32	bSurpriseRemoved;
367 	s32  bCardDisableWOHSM;
368 
369 	u32 IsrContent;
370 	u32 ImrContent;
371 
372 	u8 EepromAddressSize;
373 	u8 hw_init_completed;
374 	u8 bDriverIsGoingToUnload;
375 	u8 init_adpt_in_progress;
376 	u8 bHaltInProgress;
377 
378 	void *cmdThread;
379 	void *evtThread;
380 	void *xmitThread;
381 	void *recvThread;
382 
383 	u32 (*intf_init)(struct dvobj_priv *dvobj);
384 	void (*intf_deinit)(struct dvobj_priv *dvobj);
385 	int (*intf_alloc_irq)(struct dvobj_priv *dvobj);
386 	void (*intf_free_irq)(struct dvobj_priv *dvobj);
387 
388 
389 	void (*intf_start)(struct adapter *adapter);
390 	void (*intf_stop)(struct adapter *adapter);
391 
392 	struct net_device *pnetdev;
393 	char old_ifname[IFNAMSIZ];
394 
395 	/*  used by rtw_rereg_nd_name related function */
396 	struct rereg_nd_name_data {
397 		struct net_device *old_pnetdev;
398 		char old_ifname[IFNAMSIZ];
399 		u8 old_bRegUseLed;
400 	} rereg_nd_name_priv;
401 
402 	int bup;
403 	struct net_device_stats stats;
404 	struct iw_statistics iwstats;
405 
406 	struct wireless_dev *rtw_wdev;
407 	struct rtw_wdev_priv wdev_data;
408 
409 	int net_closed;
410 
411 	u8 netif_up;
412 
413 	u8 bFWReady;
414 	u8 bBTFWReady;
415 	u8 bLinkInfoDump;
416 	u8 bRxRSSIDisplay;
417 	/* 	Added by Albert 2012/10/26 */
418 	/* 	The driver will show up the desired channel number when this flag is 1. */
419 	u8 bNotifyChannelChange;
420 
421 	/* pbuddystruct adapter is used only in two interface case, (iface_nums =2 in struct dvobj_priv) */
422 	/* PRIMARY ADAPTER's buddy is SECONDARY_ADAPTER */
423 	/* SECONDARY_ADAPTER's buddy is PRIMARY_ADAPTER */
424 	/* for iface_id > SECONDARY_ADAPTER(IFACE_ID1), refer to padapters[iface_id]  in struct dvobj_priv */
425 	/* and their pbuddystruct adapter is PRIMARY_ADAPTER. */
426 	/* for PRIMARY_ADAPTER(IFACE_ID0) can directly refer to if1 in struct dvobj_priv */
427 	struct adapter *pbuddy_adapter;
428 
429 	/* extend to support multi interface */
430        /* IFACE_ID0 is equals to PRIMARY_ADAPTER */
431        /* IFACE_ID1 is equals to SECONDARY_ADAPTER */
432 	u8 iface_id;
433 
434 	/* for debug purpose */
435 	u8 fix_rate;
436 	u8 driver_vcs_en; /* Enable = 1, Disable = 0 driver control vrtl_carrier_sense for tx */
437 	u8 driver_vcs_type;/* force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en = 1. */
438 	u8 driver_ampdu_spacing;/* driver control AMPDU Density for peer sta's rx */
439 	u8 driver_rx_ampdu_factor;/* 0xff: disable drv ctrl, 0:8k, 1:16k, 2:32k, 3:64k; */
440 
441 	unsigned char     in_cta_test;
442 };
443 
444 #define adapter_to_dvobj(adapter) (adapter->dvobj)
445 #define adapter_to_pwrctl(adapter) (dvobj_to_pwrctl(adapter->dvobj))
446 #define adapter_wdev_data(adapter) (&((adapter)->wdev_data))
447 
448 /*  */
449 /*  Function disabled. */
450 /*  */
451 #define DF_TX_BIT		BIT0
452 #define DF_RX_BIT		BIT1
453 #define DF_IO_BIT		BIT2
454 
455 /* define RTW_ENABLE_FUNC(padapter, func) (atomic_sub(&adapter_to_dvobj(padapter)->disable_func, (func))) */
456 
RTW_ENABLE_FUNC(struct adapter * padapter,int func_bit)457 static inline void RTW_ENABLE_FUNC(struct adapter *padapter, int func_bit)
458 {
459 	int	df = atomic_read(&adapter_to_dvobj(padapter)->disable_func);
460 	df &= ~(func_bit);
461 	atomic_set(&adapter_to_dvobj(padapter)->disable_func, df);
462 }
463 
464 #define RTW_IS_FUNC_DISABLED(padapter, func_bit) (atomic_read(&adapter_to_dvobj(padapter)->disable_func) & (func_bit))
465 
466 #define RTW_CANNOT_IO(padapter) \
467 			((padapter)->bSurpriseRemoved || \
468 			 RTW_IS_FUNC_DISABLED((padapter), DF_IO_BIT))
469 
470 #define RTW_CANNOT_RX(padapter) \
471 			((padapter)->bDriverStopped || \
472 			 (padapter)->bSurpriseRemoved || \
473 			 RTW_IS_FUNC_DISABLED((padapter), DF_RX_BIT))
474 
475 #define RTW_CANNOT_TX(padapter) \
476 			((padapter)->bDriverStopped || \
477 			 (padapter)->bSurpriseRemoved || \
478 			 RTW_IS_FUNC_DISABLED((padapter), DF_TX_BIT))
479 
myid(struct eeprom_priv * peepriv)480 static inline u8 *myid(struct eeprom_priv *peepriv)
481 {
482 	return peepriv->mac_addr;
483 }
484 
485 /*  HCI Related header file */
486 #include <sdio_ops.h>
487 #include <sdio_hal.h>
488 
489 #include <rtw_btcoex.h>
490 
491 extern char *rtw_initmac;
492 extern int rtw_mc2u_disable;
493 extern int rtw_ht_enable;
494 extern u32 g_wait_hiq_empty;
495 extern u8 g_fwdl_wintint_rdy_fail;
496 extern u8 g_fwdl_chksum_fail;
497 
498 #endif /* __DRV_TYPES_H__ */
499