netdev.h 6.9 KB

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