netdev.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
  4. * All rights reserved.
  5. */
  6. #ifndef WILC_NETDEV_H
  7. #define WILC_NETDEV_H
  8. #include <linux/tcp.h>
  9. #include <linux/ieee80211.h>
  10. #include <net/cfg80211.h>
  11. #include <net/ieee80211_radiotap.h>
  12. #include <linux/if_arp.h>
  13. #include <linux/gpio/consumer.h>
  14. #include "hif.h"
  15. #include "wlan.h"
  16. #include "wlan_cfg.h"
  17. #define FLOW_CONTROL_LOWER_THRESHOLD 128
  18. #define FLOW_CONTROL_UPPER_THRESHOLD 256
  19. #define PMKID_FOUND 1
  20. #define NUM_STA_ASSOCIATED 8
  21. #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
  22. #define DEFAULT_LINK_SPEED 72
  23. struct wilc_wfi_stats {
  24. unsigned long rx_packets;
  25. unsigned long tx_packets;
  26. unsigned long rx_bytes;
  27. unsigned long tx_bytes;
  28. u64 rx_time;
  29. u64 tx_time;
  30. };
  31. struct wilc_wfi_key {
  32. u8 *key;
  33. u8 *seq;
  34. int key_len;
  35. int seq_len;
  36. u32 cipher;
  37. };
  38. struct sta_info {
  39. u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
  40. };
  41. /* Parameters needed for host interface for remaining on channel */
  42. struct wilc_wfi_p2p_listen_params {
  43. struct ieee80211_channel *listen_ch;
  44. u32 listen_duration;
  45. u64 listen_cookie;
  46. };
  47. static const u32 wilc_cipher_suites[] = {
  48. WLAN_CIPHER_SUITE_TKIP,
  49. WLAN_CIPHER_SUITE_CCMP,
  50. WLAN_CIPHER_SUITE_AES_CMAC
  51. };
  52. #define CHAN2G(_channel, _freq, _flags) { \
  53. .band = NL80211_BAND_2GHZ, \
  54. .center_freq = (_freq), \
  55. .hw_value = (_channel), \
  56. .flags = (_flags), \
  57. .max_antenna_gain = 0, \
  58. .max_power = 30, \
  59. }
  60. static const struct ieee80211_channel wilc_2ghz_channels[] = {
  61. CHAN2G(1, 2412, 0),
  62. CHAN2G(2, 2417, 0),
  63. CHAN2G(3, 2422, 0),
  64. CHAN2G(4, 2427, 0),
  65. CHAN2G(5, 2432, 0),
  66. CHAN2G(6, 2437, 0),
  67. CHAN2G(7, 2442, 0),
  68. CHAN2G(8, 2447, 0),
  69. CHAN2G(9, 2452, 0),
  70. CHAN2G(10, 2457, 0),
  71. CHAN2G(11, 2462, 0),
  72. CHAN2G(12, 2467, 0),
  73. CHAN2G(13, 2472, 0),
  74. CHAN2G(14, 2484, 0)
  75. };
  76. #define RATETAB_ENT(_rate, _hw_value, _flags) { \
  77. .bitrate = (_rate), \
  78. .hw_value = (_hw_value), \
  79. .flags = (_flags), \
  80. }
  81. static struct ieee80211_rate wilc_bitrates[] = {
  82. RATETAB_ENT(10, 0, 0),
  83. RATETAB_ENT(20, 1, 0),
  84. RATETAB_ENT(55, 2, 0),
  85. RATETAB_ENT(110, 3, 0),
  86. RATETAB_ENT(60, 9, 0),
  87. RATETAB_ENT(90, 6, 0),
  88. RATETAB_ENT(120, 7, 0),
  89. RATETAB_ENT(180, 8, 0),
  90. RATETAB_ENT(240, 9, 0),
  91. RATETAB_ENT(360, 10, 0),
  92. RATETAB_ENT(480, 11, 0),
  93. RATETAB_ENT(540, 12, 0)
  94. };
  95. struct wilc_priv {
  96. struct wireless_dev wdev;
  97. struct cfg80211_scan_request *scan_req;
  98. struct wilc_wfi_p2p_listen_params remain_on_ch_params;
  99. u64 tx_cookie;
  100. bool cfg_scanning;
  101. u8 associated_bss[ETH_ALEN];
  102. struct sta_info assoc_stainfo;
  103. struct sk_buff *skb;
  104. struct net_device *dev;
  105. struct host_if_drv *hif_drv;
  106. struct wilc_pmkid_attr pmkid_list;
  107. /* The real interface that the monitor is on */
  108. struct net_device *real_ndev;
  109. struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
  110. struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
  111. struct wilc_wfi_key *wilc_igtk[2];
  112. u8 wilc_groupkey;
  113. /* mutexes */
  114. struct mutex scan_req_lock;
  115. bool p2p_listen_state;
  116. int scanned_cnt;
  117. u64 inc_roc_cookie;
  118. };
  119. #define MAX_TCP_SESSION 25
  120. #define MAX_PENDING_ACKS 256
  121. struct ack_session_info {
  122. u32 seq_num;
  123. u32 bigger_ack_num;
  124. u16 src_port;
  125. u16 dst_port;
  126. u16 status;
  127. };
  128. struct pending_acks {
  129. u32 ack_num;
  130. u32 session_index;
  131. struct txq_entry_t *txqe;
  132. };
  133. struct tcp_ack_filter {
  134. struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
  135. struct pending_acks pending_acks[MAX_PENDING_ACKS];
  136. u32 pending_base;
  137. u32 tcp_session;
  138. u32 pending_acks_idx;
  139. bool enabled;
  140. };
  141. struct wilc_vif {
  142. u8 idx;
  143. u8 iftype;
  144. int monitor_flag;
  145. int mac_opened;
  146. u32 mgmt_reg_stypes;
  147. struct net_device_stats netstats;
  148. struct wilc *wilc;
  149. u8 bssid[ETH_ALEN];
  150. struct host_if_drv *hif_drv;
  151. struct net_device *ndev;
  152. struct timer_list during_ip_timer;
  153. struct timer_list periodic_rssi;
  154. struct rf_info periodic_stat;
  155. struct tcp_ack_filter ack_filter;
  156. bool connecting;
  157. struct wilc_priv priv;
  158. struct list_head list;
  159. struct cfg80211_bss *bss;
  160. struct cfg80211_external_auth_params auth;
  161. };
  162. struct wilc_tx_queue_status {
  163. u8 buffer[AC_BUFFER_SIZE];
  164. u16 end_index;
  165. u16 cnt[NQUEUES];
  166. u16 sum;
  167. bool initialized;
  168. };
  169. struct wilc {
  170. struct wiphy *wiphy;
  171. const struct wilc_hif_func *hif_func;
  172. int io_type;
  173. s8 mac_status;
  174. struct clk *rtc_clk;
  175. bool initialized;
  176. u32 chipid;
  177. bool power_save_mode;
  178. int dev_irq_num;
  179. int close;
  180. u8 vif_num;
  181. struct list_head vif_list;
  182. /* protect vif list */
  183. struct mutex vif_mutex;
  184. struct srcu_struct srcu;
  185. u8 open_ifcs;
  186. /* protect head of transmit queue */
  187. struct mutex txq_add_to_head_cs;
  188. /* protect txq_entry_t transmit queue */
  189. spinlock_t txq_spinlock;
  190. /* protect rxq_entry_t receiver queue */
  191. struct mutex rxq_cs;
  192. /* lock to protect hif access */
  193. struct mutex hif_cs;
  194. struct completion cfg_event;
  195. struct completion sync_event;
  196. struct completion txq_event;
  197. struct completion txq_thread_started;
  198. struct task_struct *txq_thread;
  199. int quit;
  200. /* lock to protect issue of wid command to firmware */
  201. struct mutex cfg_cmd_lock;
  202. struct wilc_cfg_frame cfg_frame;
  203. u32 cfg_frame_offset;
  204. u8 cfg_seq_no;
  205. u8 *rx_buffer;
  206. u32 rx_buffer_offset;
  207. u8 *tx_buffer;
  208. u32 *vmm_table;
  209. struct txq_handle txq[NQUEUES];
  210. int txq_entries;
  211. struct wilc_tx_queue_status tx_q_limit;
  212. struct rxq_entry_t rxq_head;
  213. const struct firmware *firmware;
  214. struct device *dev;
  215. bool suspend_event;
  216. struct workqueue_struct *hif_workqueue;
  217. struct wilc_cfg cfg;
  218. void *bus_data;
  219. struct net_device *monitor_dev;
  220. /* deinit lock */
  221. struct mutex deinit_lock;
  222. u8 sta_ch;
  223. u8 op_ch;
  224. struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
  225. struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
  226. struct ieee80211_supported_band band;
  227. u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
  228. };
  229. struct wilc_wfi_mon_priv {
  230. struct net_device *real_ndev;
  231. };
  232. void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
  233. void wilc_mac_indicate(struct wilc *wilc);
  234. void wilc_netdev_cleanup(struct wilc *wilc);
  235. void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth);
  236. void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,
  237. u8 mode);
  238. struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
  239. int vif_type, enum nl80211_iftype type,
  240. bool rtnl_locked);
  241. #endif