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 #if !defined(CONFIG_WIFI_CONTROL_FUNC) 243 #define WLAN_PLAT_NODFS_FLAG 0x01 244 #define WLAN_PLAT_AP_FLAG 0x02 245 struct wifi_platform_data { 246 int (*set_power)(int val); 247 int (*set_reset)(int val); 248 int (*set_carddetect)(int val); 249 void *(*mem_prealloc)(int section, unsigned long size); 250 int (*get_mac_addr)(unsigned char *buf); 251 #ifdef BCMSDIO 252 int (*get_wake_irq)(void); 253 #endif // endif 254 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined(CUSTOM_COUNTRY_CODE) 255 void *(*get_country_code)(char *ccode, u32 flags); 256 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined (CUSTOM_COUNTRY_CODE) */ 257 void *(*get_country_code)(char *ccode); 258 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) */ 259 }; 260 #endif /* CONFIG_WIFI_CONTROL_FUNC */ 261 262 #define DHD_REGISTRATION_TIMEOUT 12000 /* msec : allowed time to finished dhd registration */ 263 264 typedef struct wifi_adapter_info { 265 const char *name; 266 uint irq_num; 267 uint intr_flags; 268 const char *fw_path; 269 const char *nv_path; 270 void *wifi_plat_data; /* wifi ctrl func, for backward compatibility */ 271 uint bus_type; 272 uint bus_num; 273 uint slot_num; 274 #if defined(BT_OVER_SDIO) 275 const char *btfw_path; 276 #endif /* defined (BT_OVER_SDIO) */ 277 } wifi_adapter_info_t; 278 279 typedef struct bcmdhd_wifi_platdata { 280 uint num_adapters; 281 wifi_adapter_info_t *adapters; 282 } bcmdhd_wifi_platdata_t; 283 284 /** Per STA params. A list of dhd_sta objects are managed in dhd_if */ 285 typedef struct dhd_sta { 286 cumm_ctr_t cumm_ctr; /* cummulative queue length of child flowrings */ 287 uint16 flowid[NUMPRIO]; /* allocated flow ring ids (by priority) */ 288 void * ifp; /* associated dhd_if */ 289 struct ether_addr ea; /* stations ethernet mac address */ 290 struct list_head list; /* link into dhd_if::sta_list */ 291 int idx; /* index of self in dhd_pub::sta_pool[] */ 292 int ifidx; /* index of interface in dhd */ 293 } dhd_sta_t; 294 typedef dhd_sta_t dhd_sta_pool_t; 295 296 #ifdef DHD_4WAYM4_FAIL_DISCONNECT 297 typedef enum { 298 M3_RXED, 299 M4_TXFAILED 300 } msg_4way_state_t; 301 #define MAX_4WAY_TIMEOUT_MS 2000 302 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */ 303 304 #ifdef DHD_SEND_HANG_PRIVCMD_ERRORS 305 extern uint32 report_hang_privcmd_err; 306 #endif /* DHD_SEND_HANG_PRIVCMD_ERRORS */ 307 308 #if defined(ARGOS_NOTIFY_CB) 309 int argos_register_notifier_init(struct net_device *net); 310 int argos_register_notifier_deinit(void); 311 312 extern int sec_argos_register_notifier(struct notifier_block *n, char *label); 313 extern int sec_argos_unregister_notifier(struct notifier_block *n, char *label); 314 315 typedef struct { 316 struct net_device *wlan_primary_netdev; 317 int argos_rps_cpus_enabled; 318 } argos_rps_ctrl; 319 320 #define RPS_TPUT_THRESHOLD 300 321 #define DELAY_TO_CLEAR_RPS_CPUS 300 322 #endif // endif 323 324 #if defined(BT_OVER_SDIO) 325 extern void wl_android_set_wifi_on_flag(bool enable); 326 #endif /* BT_OVER_SDIO */ 327 328 #ifdef DHD_LOG_DUMP 329 /* 0: DLD_BUF_TYPE_GENERAL, 1: DLD_BUF_TYPE_PRESERVE 330 * 2: DLD_BUF_TYPE_SPECIAL 331 */ 332 #define DLD_BUFFER_NUM 3 333 334 #ifndef CUSTOM_LOG_DUMP_BUFSIZE_MB 335 #define CUSTOM_LOG_DUMP_BUFSIZE_MB 4 /* DHD_LOG_DUMP_BUF_SIZE 4 MB static memory in kernel */ 336 #endif /* CUSTOM_LOG_DUMP_BUFSIZE_MB */ 337 338 #define LOG_DUMP_TOTAL_BUFSIZE (1024 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 339 340 /* 341 * Below are different sections that use the prealloced buffer 342 * and sum of the sizes of these should not cross LOG_DUMP_TOTAL_BUFSIZE 343 */ 344 #define LOG_DUMP_GENERAL_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 345 #define LOG_DUMP_PRESERVE_MAX_BUFSIZE (128 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 346 #define LOG_DUMP_ECNTRS_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 347 #define LOG_DUMP_RTT_MAX_BUFSIZE (256 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 348 #define LOG_DUMP_FILTER_MAX_BUFSIZE (128 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB) 349 350 #if LOG_DUMP_TOTAL_BUFSIZE < (LOG_DUMP_GENERAL_MAX_BUFSIZE + \ 351 LOG_DUMP_PRESERVE_MAX_BUFSIZE + LOG_DUMP_ECNTRS_MAX_BUFSIZE + LOG_DUMP_RTT_MAX_BUFSIZE \ 352 + LOG_DUMP_FILTER_MAX_BUFSIZE) 353 #error "LOG_DUMP_TOTAL_BUFSIZE is lesser than sum of all rings" 354 #endif // endif 355 356 /* Special buffer is allocated as separately in prealloc */ 357 #define LOG_DUMP_SPECIAL_MAX_BUFSIZE (8 * 1024) 358 359 #define LOG_DUMP_MAX_FILESIZE (8 *1024 * 1024) /* 8 MB default */ 360 #ifdef CONFIG_LOG_BUF_SHIFT 361 /* 15% of kernel log buf size, if for example klog buf size is 512KB 362 * 15% of 512KB ~= 80KB 363 */ 364 #define LOG_DUMP_KERNEL_TAIL_FLUSH_SIZE \ 365 (15 * ((1 << CONFIG_LOG_BUF_SHIFT)/100)) 366 #endif /* CONFIG_LOG_BUF_SHIFT */ 367 368 #define LOG_DUMP_COOKIE_BUFSIZE 1024u 369 370 typedef struct { 371 char *hdr_str; 372 log_dump_section_type_t sec_type; 373 } dld_hdr_t; 374 375 typedef struct { 376 int attr; 377 char *hdr_str; 378 log_dump_section_type_t sec_type; 379 int log_type; 380 } dld_log_hdr_t; 381 382 #define DHD_PRINT_BUF_NAME_LEN 30 383 #endif /* DHD_LOG_DUMP */ 384 385 int dhd_wifi_platform_register_drv(void); 386 void dhd_wifi_platform_unregister_drv(void); 387 wifi_adapter_info_t* dhd_wifi_platform_get_adapter(uint32 bus_type, uint32 bus_num, 388 uint32 slot_num); 389 int wifi_platform_set_power(wifi_adapter_info_t *adapter, bool on, unsigned long msec); 390 int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present); 391 int wifi_platform_get_irq_number(wifi_adapter_info_t *adapter, unsigned long *irq_flags_ptr); 392 int wifi_platform_get_mac_addr(wifi_adapter_info_t *adapter, unsigned char *buf); 393 #ifdef CUSTOM_COUNTRY_CODE 394 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode, 395 u32 flags); 396 #else 397 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode); 398 #endif /* CUSTOM_COUNTRY_CODE */ 399 void* wifi_platform_prealloc(wifi_adapter_info_t *adapter, int section, unsigned long size); 400 void* wifi_platform_get_prealloc_func_ptr(wifi_adapter_info_t *adapter); 401 402 int dhd_get_fw_mode(struct dhd_info *dhdinfo); 403 bool dhd_update_fw_nv_path(struct dhd_info *dhdinfo); 404 405 #if defined(BT_OVER_SDIO) 406 int dhd_net_bus_get(struct net_device *dev); 407 int dhd_net_bus_put(struct net_device *dev); 408 #endif /* BT_OVER_SDIO */ 409 #if defined(WLADPS) || defined(WLADPS_PRIVATE_CMD) 410 #define ADPS_ENABLE 1 411 #define ADPS_DISABLE 0 412 413 int dhd_enable_adps(dhd_pub_t *dhd, uint8 on); 414 #endif /* WLADPS || WLADPS_PRIVATE_CMD */ 415 #ifdef DHDTCPSYNC_FLOOD_BLK 416 extern void dhd_reset_tcpsync_info_by_ifp(dhd_if_t *ifp); 417 extern void dhd_reset_tcpsync_info_by_dev(struct net_device *dev); 418 #endif /* DHDTCPSYNC_FLOOD_BLK */ 419 420 int compat_kernel_read(struct file *file, loff_t offset, char *addr, unsigned long count); 421 422 #endif /* __DHD_LINUX_H__ */ 423