dhd_linux.h 14 KB

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