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