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 
7 #ifndef WILC_WFI_NETDEVICE
8 #define WILC_WFI_NETDEVICE
9 
10 #include <linux/tcp.h>
11 #include <linux/ieee80211.h>
12 #include <net/cfg80211.h>
13 #include <net/ieee80211_radiotap.h>
14 #include <linux/if_arp.h>
15 #include <linux/gpio/consumer.h>
16 
17 #include "host_interface.h"
18 #include "wilc_wlan.h"
19 
20 #define FLOW_CONTROL_LOWER_THRESHOLD		128
21 #define FLOW_CONTROL_UPPER_THRESHOLD		256
22 
23 #define WILC_MAX_NUM_PMKIDS			16
24 #define PMKID_LEN				16
25 #define PMKID_FOUND				1
26 #define NUM_STA_ASSOCIATED			8
27 
28 #define NUM_REG_FRAME				2
29 
30 #define TCP_ACK_FILTER_LINK_SPEED_THRESH	54
31 #define DEFAULT_LINK_SPEED			72
32 
33 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
34 
35 struct wilc_wfi_stats {
36 	unsigned long rx_packets;
37 	unsigned long tx_packets;
38 	unsigned long rx_bytes;
39 	unsigned long tx_bytes;
40 	u64 rx_time;
41 	u64 tx_time;
42 
43 };
44 
45 struct wilc_wfi_key {
46 	u8 *key;
47 	u8 *seq;
48 	int key_len;
49 	int seq_len;
50 	u32 cipher;
51 };
52 
53 struct wilc_wfi_wep_key {
54 	u8 *key;
55 	u8 key_len;
56 	u8 key_idx;
57 };
58 
59 struct sta_info {
60 	u8 sta_associated_bss[MAX_NUM_STA][ETH_ALEN];
61 };
62 
63 /*Parameters needed for host interface for  remaining on channel*/
64 struct wilc_wfi_p2p_listen_params {
65 	struct ieee80211_channel *listen_ch;
66 	u32 listen_duration;
67 	u64 listen_cookie;
68 	u32 listen_session_id;
69 };
70 
71 struct wilc_priv {
72 	struct wireless_dev *wdev;
73 	struct cfg80211_scan_request *scan_req;
74 
75 	struct wilc_wfi_p2p_listen_params remain_on_ch_params;
76 	u64 tx_cookie;
77 
78 	bool cfg_scanning;
79 	u32 rcvd_ch_cnt;
80 
81 	u8 associated_bss[ETH_ALEN];
82 	struct sta_info assoc_stainfo;
83 	struct sk_buff *skb;
84 	struct net_device *dev;
85 	struct host_if_drv *hif_drv;
86 	struct host_if_pmkid_attr pmkid_list;
87 	u8 wep_key[4][WLAN_KEY_LEN_WEP104];
88 	u8 wep_key_len[4];
89 	/* The real interface that the monitor is on */
90 	struct net_device *real_ndev;
91 	struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
92 	struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
93 	u8 wilc_groupkey;
94 	/* mutexes */
95 	struct mutex scan_req_lock;
96 	bool p2p_listen_state;
97 
98 };
99 
100 struct frame_reg {
101 	u16 type;
102 	bool reg;
103 };
104 
105 struct wilc_vif {
106 	u8 idx;
107 	u8 iftype;
108 	int monitor_flag;
109 	int mac_opened;
110 	struct frame_reg frame_reg[NUM_REG_FRAME];
111 	struct net_device_stats netstats;
112 	struct wilc *wilc;
113 	u8 src_addr[ETH_ALEN];
114 	u8 bssid[ETH_ALEN];
115 	struct host_if_drv *hif_drv;
116 	struct net_device *ndev;
117 	u8 mode;
118 	u8 ifc_id;
119 };
120 
121 struct wilc {
122 	const struct wilc_hif_func *hif_func;
123 	int io_type;
124 	int mac_status;
125 	struct gpio_desc *gpio_irq;
126 	bool initialized;
127 	int dev_irq_num;
128 	int close;
129 	u8 vif_num;
130 	struct wilc_vif *vif[NUM_CONCURRENT_IFC];
131 	u8 open_ifcs;
132 	/*protect head of transmit queue*/
133 	struct mutex txq_add_to_head_cs;
134 	/*protect txq_entry_t transmit queue*/
135 	spinlock_t txq_spinlock;
136 	/*protect rxq_entry_t receiver queue*/
137 	struct mutex rxq_cs;
138 	/* lock to protect hif access */
139 	struct mutex hif_cs;
140 
141 	struct completion cfg_event;
142 	struct completion sync_event;
143 	struct completion txq_event;
144 	struct completion txq_thread_started;
145 
146 	struct task_struct *txq_thread;
147 
148 	int quit;
149 	int cfg_frame_in_use;
150 	struct wilc_cfg_frame cfg_frame;
151 	u32 cfg_frame_offset;
152 	int cfg_seq_no;
153 
154 	u8 *rx_buffer;
155 	u32 rx_buffer_offset;
156 	u8 *tx_buffer;
157 
158 	struct txq_entry_t txq_head;
159 	int txq_entries;
160 
161 	struct rxq_entry_t rxq_head;
162 
163 	const struct firmware *firmware;
164 
165 	struct device *dev;
166 	bool suspend_event;
167 
168 	struct rf_info dummy_statistics;
169 };
170 
171 struct wilc_wfi_mon_priv {
172 	struct net_device *real_ndev;
173 };
174 
175 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
176 void wilc_mac_indicate(struct wilc *wilc);
177 void wilc_netdev_cleanup(struct wilc *wilc);
178 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
179 		     const struct wilc_hif_func *ops);
180 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
181 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
182 
183 #endif
184