blob: 98ac8ed04a06cf43c844b48f0cd2fe9e9f8d7e81 [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 <linux/ieee80211.h>
39#include <net/cfg80211.h>
40#include <net/ieee80211_radiotap.h>
41#include <linux/if_arp.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090042#include <linux/in6.h>
43#include <asm/checksum.h>
44#include "host_interface.h"
45#include "wilc_wlan.h"
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090046#include <linux/wireless.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 Kim441dc602015-10-12 16:55:35 +0900124 struct host_if_drv *hWILCWFIDrv;
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_default;
128 u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104];
129 u8 WILC_WFI_wep_key_len[4];
Sunghoon Cho70e59d92015-06-26 15:48:16 +0900130 /* The real interface that the monitor is on */
131 struct net_device *real_ndev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132 struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
133 struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900134 u8 wilc_groupkey;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135 /* semaphores */
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200136 struct semaphore SemHandleUpdateStats;
137 struct semaphore hSemScanReq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900138 /* */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900139 bool gbAutoRateAdjusted;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900140
Dean Lee72ed4dc2015-06-12 14:11:44 +0900141 bool bInP2PlistenState;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900142
143};
144
145typedef struct {
Chaehyun Limd85f5322015-06-11 14:35:54 +0900146 u16 frame_type;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900147 bool reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900148
149} struct_frame_reg;
150
Tony Cho1a08bc42015-10-14 20:46:32 +0900151struct wilc_vif {
Glen Leea4cac482015-12-21 14:18:36 +0900152 u8 u8IfIdx;
153 u8 iftype;
154 int monitor_flag;
155 int mac_opened;
156 struct_frame_reg g_struct_frame_reg[num_reg_frame];
Glen Leea4cac482015-12-21 14:18:36 +0900157 struct net_device_stats netstats;
158 struct wilc *wilc;
Tony Cho7e7fa472015-10-20 14:26:48 +0900159 u8 src_addr[ETH_ALEN];
Tony Cho7201cd22015-10-20 14:26:49 +0900160 u8 bssid[ETH_ALEN];
Tony Cho3134a572015-10-20 14:26:50 +0900161 struct host_if_drv *hif_drv;
Tony Cho817f3fb2015-10-20 14:26:51 +0900162 struct net_device *ndev;
Tony Cho1a08bc42015-10-14 20:46:32 +0900163};
Tony Chof61c5af2015-10-14 20:46:30 +0900164
165struct wilc {
Glen Leeaf9ae092015-12-21 14:18:09 +0900166 const struct wilc_hif_func *hif_func;
Arnd Bergmann4bd7baf2015-11-16 15:04:59 +0100167 int io_type;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900168 int mac_status;
Arnd Bergmannc4d139c2015-11-16 15:05:04 +0100169 int gpio;
Tony Cho080f11b2015-10-20 14:26:45 +0900170 bool initialized;
Arnd Bergmannc4d139c2015-11-16 15:05:04 +0100171 int dev_irq_num;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172 int close;
Tony Choc1b30f62015-10-20 14:26:46 +0900173 u8 vif_num;
Glen Lee1f435d22015-12-21 14:18:37 +0900174 struct wilc_vif *vif[NUM_CONCURRENT_IFC];
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900175 u8 open_ifcs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900176
Greg Kroah-Hartman642768e2015-09-03 19:56:21 -0700177 struct semaphore txq_add_to_head_cs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900178 spinlock_t txq_spinlock;
179
180 struct mutex rxq_cs;
181 struct mutex hif_cs;
182
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900183 struct semaphore cfg_event;
184 struct semaphore sync_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185 struct semaphore txq_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900186
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187 struct semaphore txq_thread_started;
188
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189 struct task_struct *txq_thread;
190
Glen Lee67e2a072015-12-21 14:18:12 +0900191 int quit;
192 int cfg_frame_in_use;
193 struct wilc_cfg_frame cfg_frame;
194 u32 cfg_frame_offset;
195 int cfg_seq_no;
196
197 u8 *rx_buffer;
198 u32 rx_buffer_offset;
199 u8 *tx_buffer;
200
201 unsigned long txq_spinlock_flags;
202
203 struct txq_entry_t *txq_head;
204 struct txq_entry_t *txq_tail;
205 int txq_entries;
206 int txq_exit;
207
208 struct rxq_entry_t *rxq_head;
209 struct rxq_entry_t *rxq_tail;
210 int rxq_entries;
211 int rxq_exit;
212
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900213 unsigned char eth_src_address[NUM_CONCURRENT_IFC][6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900214
Tony Cho8b8ad7b2015-10-20 14:26:53 +0900215 const struct firmware *firmware;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900216
Arnd Bergmannb03314e2015-11-16 15:05:01 +0100217 struct device *dev;
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);
228void wilc_rx_complete(struct wilc *wilc);
Glen Leed36ec222015-11-18 15:11:36 +0900229void wilc_dbg(u8 *buff);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100230
231int wilc_lock_timeout(struct wilc *wilc, void *, u32 timeout);
Arnd Bergmann857c7b02015-11-16 15:05:00 +0100232void wilc_netdev_cleanup(struct wilc *wilc);
Arnd Bergmann7d37a4a2015-11-16 15:05:05 +0100233int wilc_netdev_init(struct wilc **wilc, struct device *, int io_type, int gpio,
234 const struct wilc_hif_func *ops);
Glen Lee53dc0cf2015-10-20 17:13:57 +0900235void wilc1000_wlan_deinit(struct net_device *dev);
Glen Lee11f4b2e2015-10-27 18:27:51 +0900236void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100237u16 wilc_set_machw_change_vir_if(struct net_device *dev, bool value);
238int wilc_wlan_get_firmware(struct net_device *dev);
239int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100240
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900241#endif