xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/infineon/bcmdhd/dhd_linux.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * DHD Linux header file (dhd_linux exports for cfg80211 and other components)
3  *
4  * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, Broadcom Corporation
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *      Notwithstanding the above, under no circumstances may you combine this
23  * software in any way with any other Broadcom software provided under a license
24  * other than the GPL, without Broadcom's express prior written consent.
25  *
26  *
27  * <<Broadcom-WL-IPTag/Open:>>
28  *
29  * $Id: dhd_linux.h 701006 2017-05-23 08:25:04Z $
30  */
31 
32 /* wifi platform functions for power, interrupt and pre-alloc, either
33  * from Android-like platform device data, or Broadcom wifi platform
34  * device data.
35  *
36  */
37 #ifndef __DHD_LINUX_H__
38 #define __DHD_LINUX_H__
39 
40 #include <linux/kernel.h>
41 #include <linux/init.h>
42 #include <linux/fs.h>
43 
44 #include <dngl_stats.h>
45 #include <dhd.h>
46 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 1))
47 #include <linux/time64.h>
48 #define get_monotonic_boottime ktime_get_boottime_ts64
49 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 1)) */
50 /* Linux wireless extension support */
51 #if defined(WL_WIRELESS_EXT)
52 #include <wl_iw.h>
53 #endif /* defined(WL_WIRELESS_EXT) */
54 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
55 #include <linux/earlysuspend.h>
56 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND) */
57 #if defined(CONFIG_WIFI_CONTROL_FUNC)
58 #include <linux/wlan_plat.h>
59 #endif // endif
60 #ifdef PCIE_FULL_DONGLE
61 #include <etd.h>
62 #endif /* PCIE_FULL_DONGLE */
63 #ifdef WL_MONITOR
64 #include <bcmmsgbuf.h>
65 #define MAX_RADIOTAP_SIZE      256 /* Maximum size to hold HE Radiotap header format */
66 #define MAX_MON_PKT_SIZE       (4096 + MAX_RADIOTAP_SIZE)
67 #endif /* WL_MONITOR */
68 
69 #define FILE_DUMP_MAX_WAIT_TIME 4000
70 
71 #define htod32(i) (i)
72 #define htod16(i) (i)
73 #define dtoh32(i) (i)
74 #define dtoh16(i) (i)
75 #define htodchanspec(i) (i)
76 #define dtohchanspec(i) (i)
77 
78 #ifdef BLOCK_IPV6_PACKET
79 #define HEX_PREF_STR	"0x"
80 #define UNI_FILTER_STR	"010000000000"
81 #define ZERO_ADDR_STR	"000000000000"
82 #define ETHER_TYPE_STR	"0000"
83 #define IPV6_FILTER_STR	"20"
84 #define ZERO_TYPE_STR	"00"
85 #endif /* BLOCK_IPV6_PACKET */
86 
87 typedef struct dhd_if_event {
88 	struct list_head	list;
89 	wl_event_data_if_t	event;
90 	char			name[IFNAMSIZ+1];
91 	uint8			mac[ETHER_ADDR_LEN];
92 } dhd_if_event_t;
93 
94 /* Interface control information */
95 typedef struct dhd_if {
96 	struct dhd_info *info;			/* back pointer to dhd_info */
97 	/* OS/stack specifics */
98 	struct net_device *net;
99 	int				idx;			/* iface idx in dongle */
100 	uint			subunit;		/* subunit */
101 	uint8			mac_addr[ETHER_ADDR_LEN];	/* assigned MAC address */
102 	bool			set_macaddress;
103 	bool			set_multicast;
104 	uint8			bssidx;			/* bsscfg index for the interface */
105 	bool			attached;		/* Delayed attachment when unset */
106 	bool			txflowcontrol;	/* Per interface flow control indicator */
107 	char			name[IFNAMSIZ+1]; /* linux interface name */
108 	char			dngl_name[IFNAMSIZ+1]; /* corresponding dongle interface name */
109 	struct net_device_stats stats;
110 	struct list_head sta_list;		/* sll of associated stations */
111 	spinlock_t	sta_list_lock;		/* lock for manipulating sll */
112 	uint32  ap_isolate;			/* ap-isolation settings */
113 #ifdef DHD_L2_FILTER
114 	bool parp_enable;
115 	bool parp_discard;
116 	bool parp_allnode;
117 	arp_table_t *phnd_arp_table;
118 	/* for Per BSS modification */
119 	bool dhcp_unicast;
120 	bool block_ping;
121 	bool grat_arp;
122 	bool block_tdls;
123 #endif /* DHD_L2_FILTER */
124 #ifdef DHD_MCAST_REGEN
125 	bool mcast_regen_bss_enable;
126 #endif // endif
127 	bool rx_pkt_chainable;		/* set all rx packet to chainable config by default */
128 	cumm_ctr_t cumm_ctr;		/* cummulative queue length of child flowrings */
129 	uint8 tx_paths_active;
130 	bool del_in_progress;
131 	bool static_if;			/* used to avoid some operations on static_if */
132 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
133 	struct delayed_work m4state_work;
134 	atomic_t m4state;
135 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
136 #ifdef DHD_POST_EAPOL_M1_AFTER_ROAM_EVT
137 	bool recv_reassoc_evt;
138 	bool post_roam_evt;
139 #endif /* DHD_POST_EAPOL_M1_AFTER_ROAM_EVT */
140 #ifdef DHDTCPSYNC_FLOOD_BLK
141 	uint32 tsync_rcvd;
142 	uint32 tsyncack_txed;
143 	u64 last_sync;
144 	struct work_struct  blk_tsfl_work;
145 #endif /* DHDTCPSYNC_FLOOD_BLK */
146 #if defined(BCMSDIO)
147 	int role;
148 #endif /* BCMSDIO */
149 } dhd_if_t;
150 
151 struct ipv6_work_info_t {
152 	uint8			if_idx;
153 	char			ipv6_addr[IPV6_ADDR_LEN];
154 	unsigned long		event;
155 };
156 
157 typedef struct dhd_dump {
158 	uint8 *buf;
159 	int bufsize;
160 	uint8 *hscb_buf;
161 	int hscb_bufsize;
162 } dhd_dump_t;
163 #ifdef DNGL_AXI_ERROR_LOGGING
164 typedef struct dhd_axi_error_dump {
165 	ulong fault_address;
166 	uint32 axid;
167 	struct hnd_ext_trap_axi_error_v1 etd_axi_error_v1;
168 } dhd_axi_error_dump_t;
169 #endif /* DNGL_AXI_ERROR_LOGGING */
170 
171 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
172 struct dhd_rx_tx_work {
173 	struct work_struct work;
174 	struct sk_buff *skb;
175 	struct net_device *net;
176 	struct dhd_pub *pub;
177 };
178 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
179 
180 #if defined(DHD_LB)
181 #if !defined(PCIE_FULL_DONGLE)
182 #error "DHD Loadbalancing only supported on PCIE_FULL_DONGLE"
183 #endif /* !PCIE_FULL_DONGLE */
184 #endif /* DHD_LB */
185 
186 #if defined(DHD_LB_RXP) || defined(DHD_LB_RXC) || defined(DHD_LB_TXC) || \
187 	defined(DHD_LB_STATS)
188 #if !defined(DHD_LB)
189 #error "DHD loadbalance derivatives are supported only if DHD_LB is defined"
190 #endif /* !DHD_LB */
191 #endif /* DHD_LB_RXP || DHD_LB_RXC || DHD_LB_TXC || DHD_LB_STATS */
192 
193 #if defined(DHD_LB)
194 /* Dynamic CPU selection for load balancing */
195 #include <linux/cpu.h>
196 #include <linux/cpumask.h>
197 #include <linux/notifier.h>
198 #include <linux/workqueue.h>
199 #include <asm/atomic.h>
200 
201 #if !defined(DHD_LB_PRIMARY_CPUS)
202 #define DHD_LB_PRIMARY_CPUS     0x0 /* Big CPU coreids mask */
203 #endif // endif
204 #if !defined(DHD_LB_SECONDARY_CPUS)
205 #define DHD_LB_SECONDARY_CPUS   0xFE /* Little CPU coreids mask */
206 #endif // endif
207 
208 #define HIST_BIN_SIZE	9
209 
210 #if defined(DHD_LB_TXP)
211 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
212 typedef struct dhd_tx_lb_pkttag_fr {
213 	struct net_device *net;
214 	int ifidx;
215 } dhd_tx_lb_pkttag_fr_t;
216 
217 #define DHD_LB_TX_PKTTAG_SET_NETDEV(tag, netdevp)	((tag)->net = netdevp)
218 #define DHD_LB_TX_PKTTAG_NETDEV(tag)			((tag)->net)
219 
220 #define DHD_LB_TX_PKTTAG_SET_IFIDX(tag, ifidx)	((tag)->ifidx = ifidx)
221 #define DHD_LB_TX_PKTTAG_IFIDX(tag)		((tag)->ifidx)
222 #endif /* DHD_LB_TXP */
223 
224 #endif /* DHD_LB */
225 
226 #ifdef FILTER_IE
227 #define FILTER_IE_PATH "/etc/wifi/filter_ie"
228 #define FILTER_IE_BUFSZ 1024 /* ioc buffsize for FILTER_IE */
229 #define FILE_BLOCK_READ_SIZE 256
230 #define WL_FILTER_IE_IOV_HDR_SIZE OFFSETOF(wl_filter_ie_iov_v1_t, tlvs)
231 #endif /* FILTER_IE */
232 
233 #define NULL_CHECK(p, s, err)  \
234 			do { \
235 				if (!(p)) { \
236 					printk("NULL POINTER (%s) : %s\n", __FUNCTION__, (s)); \
237 					err = BCME_ERROR; \
238 					return err; \
239 				} \
240 			} while (0)
241 
242 typedef struct wifi_adapter_info {
243 	const char	*name;
244 	uint		irq_num;
245 	uint		intr_flags;
246 	const char	*fw_path;
247 	const char	*nv_path;
248 	void		*wifi_plat_data;	/* wifi ctrl func, for backward compatibility */
249 	uint		bus_type;
250 	int index;
251 	uint		bus_num;
252 	uint		slot_num;
253 	int         gpio_wl_reg_on;
254 	int         gpio_wl_host_wake;
255 #if defined(BT_OVER_SDIO)
256 	const char	*btfw_path;
257 #endif /* defined (BT_OVER_SDIO) */
258 } wifi_adapter_info_t;
259 
260 #if !defined(CONFIG_WIFI_CONTROL_FUNC)
261 #define WLAN_PLAT_NODFS_FLAG	0x01
262 #define WLAN_PLAT_AP_FLAG	0x02
263 struct wifi_platform_data {
264 	int (*set_power)(int val,  wifi_adapter_info_t *adapter);
265 	int (*set_reset)(int val);
266 	int (*set_carddetect)(int val);
267 	void *(*mem_prealloc)(int section, unsigned long size);
268 	int (*get_mac_addr)(unsigned char *buf);
269 #ifdef BCMSDIO
270 	int (*get_wake_irq)(void);
271 #endif // endif
272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined(CUSTOM_COUNTRY_CODE)
273 	void *(*get_country_code)(char *ccode, u32 flags);
274 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined (CUSTOM_COUNTRY_CODE) */
275 	void *(*get_country_code)(char *ccode);
276 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) */
277 };
278 #endif /* CONFIG_WIFI_CONTROL_FUNC */
279 
280 #define DHD_REGISTRATION_TIMEOUT  12000  /* msec : allowed time to finished dhd registration */
281 
282 
283 typedef struct bcmdhd_wifi_platdata {
284 	uint				num_adapters;
285 	wifi_adapter_info_t	*adapters;
286 } bcmdhd_wifi_platdata_t;
287 
288 /** Per STA params. A list of dhd_sta objects are managed in dhd_if */
289 typedef struct dhd_sta {
290 	cumm_ctr_t cumm_ctr;    /* cummulative queue length of child flowrings */
291 	uint16 flowid[NUMPRIO]; /* allocated flow ring ids (by priority) */
292 	void * ifp;             /* associated dhd_if */
293 	struct ether_addr ea;   /* stations ethernet mac address */
294 	struct list_head list;  /* link into dhd_if::sta_list */
295 	int idx;                /* index of self in dhd_pub::sta_pool[] */
296 	int ifidx;              /* index of interface in dhd */
297 } dhd_sta_t;
298 typedef dhd_sta_t dhd_sta_pool_t;
299 
300 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
301 typedef enum {
302 	M3_RXED,
303 	M4_TXFAILED
304 } msg_4way_state_t;
305 #define MAX_4WAY_TIMEOUT_MS 2000
306 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
307 
308 #ifdef DHD_SEND_HANG_PRIVCMD_ERRORS
309 extern uint32 report_hang_privcmd_err;
310 #endif /* DHD_SEND_HANG_PRIVCMD_ERRORS */
311 
312 #if defined(ARGOS_NOTIFY_CB)
313 int argos_register_notifier_init(struct net_device *net);
314 int argos_register_notifier_deinit(void);
315 
316 extern int sec_argos_register_notifier(struct notifier_block *n, char *label);
317 extern int sec_argos_unregister_notifier(struct notifier_block *n, char *label);
318 
319 typedef struct {
320 	struct net_device *wlan_primary_netdev;
321 	int argos_rps_cpus_enabled;
322 } argos_rps_ctrl;
323 
324 #define RPS_TPUT_THRESHOLD		300
325 #define DELAY_TO_CLEAR_RPS_CPUS		300
326 #endif // endif
327 
328 #if defined(BT_OVER_SDIO)
329 extern void wl_android_set_wifi_on_flag(bool enable);
330 #endif /* BT_OVER_SDIO */
331 
332 #ifdef DHD_LOG_DUMP
333 /* 0: DLD_BUF_TYPE_GENERAL, 1: DLD_BUF_TYPE_PRESERVE
334 * 2: DLD_BUF_TYPE_SPECIAL
335 */
336 #define DLD_BUFFER_NUM 3
337 
338 #ifndef CUSTOM_LOG_DUMP_BUFSIZE_MB
339 #define CUSTOM_LOG_DUMP_BUFSIZE_MB	4 /* DHD_LOG_DUMP_BUF_SIZE 4 MB static memory in kernel */
340 #endif /* CUSTOM_LOG_DUMP_BUFSIZE_MB */
341 
342 #define LOG_DUMP_TOTAL_BUFSIZE (1024 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
343 
344 /*
345  * Below are different sections that use the prealloced buffer
346  * and sum of the sizes of these should not cross LOG_DUMP_TOTAL_BUFSIZE
347  */
348 #define LOG_DUMP_GENERAL_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
349 #define LOG_DUMP_PRESERVE_MAX_BUFSIZE (128 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
350 #define LOG_DUMP_ECNTRS_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
351 #define LOG_DUMP_RTT_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
352 #define LOG_DUMP_FILTER_MAX_BUFSIZE (128 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
353 
354 #if LOG_DUMP_TOTAL_BUFSIZE < (LOG_DUMP_GENERAL_MAX_BUFSIZE + \
355 	LOG_DUMP_PRESERVE_MAX_BUFSIZE + LOG_DUMP_ECNTRS_MAX_BUFSIZE + LOG_DUMP_RTT_MAX_BUFSIZE \
356 	+ LOG_DUMP_FILTER_MAX_BUFSIZE)
357 #error "LOG_DUMP_TOTAL_BUFSIZE is lesser than sum of all rings"
358 #endif // endif
359 
360 /* Special buffer is allocated as separately in prealloc */
361 #define LOG_DUMP_SPECIAL_MAX_BUFSIZE (8 * 1024)
362 
363 #define LOG_DUMP_MAX_FILESIZE (8 *1024 * 1024) /* 8 MB default */
364 #ifdef CONFIG_LOG_BUF_SHIFT
365 /* 15% of kernel log buf size, if for example klog buf size is 512KB
366 * 15% of 512KB ~= 80KB
367 */
368 #define LOG_DUMP_KERNEL_TAIL_FLUSH_SIZE \
369 	(15 * ((1 << CONFIG_LOG_BUF_SHIFT)/100))
370 #endif /* CONFIG_LOG_BUF_SHIFT */
371 
372 #define LOG_DUMP_COOKIE_BUFSIZE	1024u
373 
374 typedef struct {
375 	char *hdr_str;
376 	log_dump_section_type_t sec_type;
377 } dld_hdr_t;
378 
379 typedef struct {
380 	int attr;
381 	char *hdr_str;
382 	log_dump_section_type_t sec_type;
383 	int log_type;
384 } dld_log_hdr_t;
385 
386 #define DHD_PRINT_BUF_NAME_LEN 30
387 #endif /* DHD_LOG_DUMP */
388 
389 int dhd_wifi_platform_register_drv(void);
390 void dhd_wifi_platform_unregister_drv(void);
391 wifi_adapter_info_t* dhd_wifi_platform_get_adapter(uint32 bus_type, uint32 bus_num,
392 	uint32 slot_num);
393 int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long msec);
394 int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present);
395 int wifi_platform_get_irq_number(wifi_adapter_info_t *adapter, unsigned long *irq_flags_ptr);
396 int wifi_platform_get_mac_addr(wifi_adapter_info_t *adapter, unsigned char *buf);
397 #ifdef CUSTOM_COUNTRY_CODE
398 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode,
399 	u32 flags);
400 #else
401 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode);
402 #endif /* CUSTOM_COUNTRY_CODE */
403 void* wifi_platform_prealloc(wifi_adapter_info_t *adapter, int section, unsigned long size);
404 void* wifi_platform_get_prealloc_func_ptr(wifi_adapter_info_t *adapter);
405 
406 int dhd_get_fw_mode(struct dhd_info *dhdinfo);
407 bool dhd_update_fw_nv_path(struct dhd_info *dhdinfo);
408 
409 #if defined(BT_OVER_SDIO)
410 int dhd_net_bus_get(struct net_device *dev);
411 int dhd_net_bus_put(struct net_device *dev);
412 #endif /* BT_OVER_SDIO */
413 #if defined(WLADPS) || defined(WLADPS_PRIVATE_CMD)
414 #define ADPS_ENABLE	1
415 #define ADPS_DISABLE	0
416 
417 int dhd_enable_adps(dhd_pub_t *dhd, uint8 on);
418 #endif /* WLADPS || WLADPS_PRIVATE_CMD */
419 #ifdef DHDTCPSYNC_FLOOD_BLK
420 extern void dhd_reset_tcpsync_info_by_ifp(dhd_if_t *ifp);
421 extern void dhd_reset_tcpsync_info_by_dev(struct net_device *dev);
422 #endif /* DHDTCPSYNC_FLOOD_BLK */
423 
424 int compat_kernel_read(struct file *file, loff_t offset, char *addr, unsigned long count);
425 
426 #endif /* __DHD_LINUX_H__ */
427