blob: ec6b1674cf38425e3deb9a8a67e25ffb27845390 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/*!
2 * @file wilc_wfi_netdevice.h
3 * @brief Definitions for the network module
4 * @author mdaftedar
5 * @date 01 MAR 2012
6 * @version 1.0
7 */
8#ifndef WILC_WFI_NETDEVICE
9#define WILC_WFI_NETDEVICE
10
Johnny Kimc5c77ba2015-05-11 14:30:56 +090011#define WILC_WFI_RX_INTR 0x0001
12#define WILC_WFI_TX_INTR 0x0002
13
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090014#define WILC_WFI_TIMEOUT 5
Johnny Kimc5c77ba2015-05-11 14:30:56 +090015#define WILC_MAX_NUM_PMKIDS 16
16#define PMKID_LEN 16
17#define PMKID_FOUND 1
18 #define NUM_STA_ASSOCIATED 8
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/moduleparam.h>
23#include <linux/sched.h>
24#include <linux/kernel.h>
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090025#include <linux/slab.h>
26#include <linux/errno.h>
27#include <linux/types.h>
28#include <linux/interrupt.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090029#include <linux/time.h>
30#include <linux/in.h>
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090031#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/ip.h>
34#include <linux/tcp.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035#include <linux/skbuff.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090036#include <linux/ieee80211.h>
37#include <net/cfg80211.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090038#include <net/ieee80211_radiotap.h>
39#include <linux/if_arp.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090040#include <linux/in6.h>
41#include <asm/checksum.h>
42#include "host_interface.h"
43#include "wilc_wlan.h"
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090044#include <linux/wireless.h>
Binoy Jayanb27a6d52016-06-15 11:00:34 +053045#include <linux/completion.h>
Binoy Jayan334bed02016-06-15 11:00:35 +053046#include <linux/mutex.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090047
48#define FLOW_CONTROL_LOWER_THRESHOLD 128
49#define FLOW_CONTROL_UPPER_THRESHOLD 256
50
Johnny Kimc5c77ba2015-05-11 14:30:56 +090051enum stats_flags {
Anish Bhattffda2032015-09-29 12:15:49 -070052 WILC_WFI_RX_PKT = BIT(0),
53 WILC_WFI_TX_PKT = BIT(1),
Johnny Kimc5c77ba2015-05-11 14:30:56 +090054};
55
56struct WILC_WFI_stats {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090057 unsigned long rx_packets;
58 unsigned long tx_packets;
59 unsigned long rx_bytes;
60 unsigned long tx_bytes;
61 u64 rx_time;
62 u64 tx_time;
63
64};
65
66/*
67 * This structure is private to each device. It is used to pass
68 * packets in and out, so there is place for a packet
69 */
70
Johnny Kimc5c77ba2015-05-11 14:30:56 +090071#define num_reg_frame 2
Johnny Kimc5c77ba2015-05-11 14:30:56 +090072
73struct wilc_wfi_key {
74 u8 *key;
75 u8 *seq;
76 int key_len;
77 int seq_len;
78 u32 cipher;
79};
Sunghoon Cho36901b62015-06-26 15:48:15 +090080
Johnny Kimc5c77ba2015-05-11 14:30:56 +090081struct wilc_wfi_wep_key {
82 u8 *key;
83 u8 key_len;
84 u8 key_idx;
85};
86
87struct sta_info {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090088 u8 au8Sta_AssociatedBss[MAX_NUM_STA][ETH_ALEN];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090089};
90
Johnny Kimc5c77ba2015-05-11 14:30:56 +090091/*Parameters needed for host interface for remaining on channel*/
92struct wilc_wfi_p2pListenParams {
93 struct ieee80211_channel *pstrListenChan;
94 enum nl80211_channel_type tenuChannelType;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090095 u32 u32ListenDuration;
Chaehyun Lim57b298f2015-06-11 14:35:56 +090096 u64 u64ListenCookie;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090097 u32 u32ListenSessionID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090098};
99
Chaehyun Lim27268872015-09-15 14:06:13 +0900100struct wilc_priv {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101 struct wireless_dev *wdev;
102 struct cfg80211_scan_request *pstrScanReq;
103
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104 struct wilc_wfi_p2pListenParams strRemainOnChanParams;
Chaehyun Lim57b298f2015-06-11 14:35:56 +0900105 u64 u64tx_cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900106
Dean Lee72ed4dc2015-06-12 14:11:44 +0900107 bool bCfgScanning;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900108 u32 u32RcvdChCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900110 u8 au8AssociatedBss[ETH_ALEN];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111 struct sta_info assoc_stainfo;
112 struct net_device_stats stats;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900113 u8 monitor_flag;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114 int status;
115 struct WILC_WFI_packet *ppool;
116 struct WILC_WFI_packet *rx_queue; /* List of incoming packets */
117 int rx_int_enabled;
118 int tx_packetlen;
119 u8 *tx_packetdata;
120 struct sk_buff *skb;
121 spinlock_t lock;
122 struct net_device *dev;
123 struct napi_struct napi;
Leo Kim48b28df2016-02-04 18:15:32 +0900124 struct host_if_drv *hif_drv;
Leo Kima949f902015-10-05 15:25:44 +0900125 struct host_if_pmkid_attr pmkid_list;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126 struct WILC_WFI_stats netstats;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900127 u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104];
128 u8 WILC_WFI_wep_key_len[4];
Sunghoon Cho70e59d92015-06-26 15:48:16 +0900129 /* The real interface that the monitor is on */
130 struct net_device *real_ndev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900131 struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
132 struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900133 u8 wilc_groupkey;
Joshua Houghtoneeeb5fb2016-08-01 19:17:25 +0000134 /* mutexes */
Chaehyun Lim08662092016-03-28 13:56:00 +0900135 struct mutex scan_req_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900136 /* */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900137 bool gbAutoRateAdjusted;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900138
Dean Lee72ed4dc2015-06-12 14:11:44 +0900139 bool bInP2PlistenState;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900140
141};
142
Leo Kimc92a8692016-03-25 21:16:48 +0900143struct frame_reg {
Leo Kim340a84f2016-03-25 21:16:50 +0900144 u16 type;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900145 bool reg;
Leo Kimc92a8692016-03-25 21:16:48 +0900146};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900147
Tony Cho1a08bc42015-10-14 20:46:32 +0900148struct wilc_vif {
Leo Kim67501402016-02-04 18:15:39 +0900149 u8 idx;
Glen Leea4cac482015-12-21 14:18:36 +0900150 u8 iftype;
151 int monitor_flag;
152 int mac_opened;
Leo Kim89febb22016-03-25 21:16:49 +0900153 struct frame_reg frame_reg[num_reg_frame];
Glen Leea4cac482015-12-21 14:18:36 +0900154 struct net_device_stats netstats;
155 struct wilc *wilc;
Tony Cho7e7fa472015-10-20 14:26:48 +0900156 u8 src_addr[ETH_ALEN];
Tony Cho7201cd22015-10-20 14:26:49 +0900157 u8 bssid[ETH_ALEN];
Tony Cho3134a572015-10-20 14:26:50 +0900158 struct host_if_drv *hif_drv;
Tony Cho817f3fb2015-10-20 14:26:51 +0900159 struct net_device *ndev;
Glen Leeba615f12016-01-25 16:35:15 +0900160 u8 mode;
Tony Cho1a08bc42015-10-14 20:46:32 +0900161};
Tony Chof61c5af2015-10-14 20:46:30 +0900162
163struct wilc {
Glen Leeaf9ae092015-12-21 14:18:09 +0900164 const struct wilc_hif_func *hif_func;
Arnd Bergmann4bd7baf2015-11-16 15:04:59 +0100165 int io_type;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900166 int mac_status;
Arnd Bergmannc4d139c2015-11-16 15:05:04 +0100167 int gpio;
Tony Cho080f11b2015-10-20 14:26:45 +0900168 bool initialized;
Arnd Bergmannc4d139c2015-11-16 15:05:04 +0100169 int dev_irq_num;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900170 int close;
Tony Choc1b30f62015-10-20 14:26:46 +0900171 u8 vif_num;
Glen Lee1f435d22015-12-21 14:18:37 +0900172 struct wilc_vif *vif[NUM_CONCURRENT_IFC];
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900173 u8 open_ifcs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900174
Binoy Jayan334bed02016-06-15 11:00:35 +0530175 struct mutex txq_add_to_head_cs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900176 spinlock_t txq_spinlock;
177
178 struct mutex rxq_cs;
179 struct mutex hif_cs;
180
Binoy Jayanfa659692016-06-15 11:00:36 +0530181 struct completion cfg_event;
Binoy Jayan04247e72016-06-15 11:00:37 +0530182 struct completion sync_event;
Binoy Jayanb27a6d52016-06-15 11:00:34 +0530183 struct completion txq_event;
Leo Kim11a54b32016-04-01 17:44:15 +0900184 struct completion txq_thread_started;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900186 struct task_struct *txq_thread;
187
Glen Lee67e2a072015-12-21 14:18:12 +0900188 int quit;
189 int cfg_frame_in_use;
190 struct wilc_cfg_frame cfg_frame;
191 u32 cfg_frame_offset;
192 int cfg_seq_no;
193
194 u8 *rx_buffer;
195 u32 rx_buffer_offset;
196 u8 *tx_buffer;
197
198 unsigned long txq_spinlock_flags;
199
200 struct txq_entry_t *txq_head;
201 struct txq_entry_t *txq_tail;
202 int txq_entries;
203 int txq_exit;
204
205 struct rxq_entry_t *rxq_head;
206 struct rxq_entry_t *rxq_tail;
207 int rxq_entries;
208 int rxq_exit;
209
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210 unsigned char eth_src_address[NUM_CONCURRENT_IFC][6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900211
Tony Cho8b8ad7b2015-10-20 14:26:53 +0900212 const struct firmware *firmware;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900213
Arnd Bergmannb03314e2015-11-16 15:05:01 +0100214 struct device *dev;
Glen Lee76855ba2016-01-25 16:35:08 +0900215 bool suspend_event;
Glen Lee4fd62292016-02-04 18:15:24 +0900216
217 struct rf_info dummy_statistics;
Tony Chof61c5af2015-10-14 20:46:30 +0900218};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220struct WILC_WFI_mon_priv {
221 struct net_device *real_ndev;
222};
Sunghoon Cho1d1c5b22015-06-17 14:42:36 +0900223
Glen Leea4cac482015-12-21 14:18:36 +0900224int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif);
Arnd Bergmann491880e2015-11-16 15:04:55 +0100225
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100226void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
227void wilc_mac_indicate(struct wilc *wilc, int flag);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100228int wilc_lock_timeout(struct wilc *wilc, void *, u32 timeout);
Arnd Bergmann857c7b02015-11-16 15:05:00 +0100229void wilc_netdev_cleanup(struct wilc *wilc);
Arnd Bergmann7d37a4a2015-11-16 15:05:05 +0100230int wilc_netdev_init(struct wilc **wilc, struct device *, int io_type, int gpio,
231 const struct wilc_hif_func *ops);
Glen Lee53dc0cf2015-10-20 17:13:57 +0900232void wilc1000_wlan_deinit(struct net_device *dev);
Glen Lee11f4b2e2015-10-27 18:27:51 +0900233void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100234int wilc_wlan_get_firmware(struct net_device *dev);
Glen Leeba615f12016-01-25 16:35:15 +0900235int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100236
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900237#endif