Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /*! |
| 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 11 | #define WILC_WFI_RX_INTR 0x0001 |
| 12 | #define WILC_WFI_TX_INTR 0x0002 |
| 13 | |
Chaehyun Lim | 30b2ba09 | 2015-10-02 16:41:15 +0900 | [diff] [blame] | 14 | #define WILC_WFI_TIMEOUT 5 |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 15 | #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 Lim | 30b2ba09 | 2015-10-02 16:41:15 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/interrupt.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 29 | #include <linux/time.h> |
| 30 | #include <linux/in.h> |
Chaehyun Lim | 30b2ba09 | 2015-10-02 16:41:15 +0900 | [diff] [blame] | 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/ip.h> |
| 34 | #include <linux/tcp.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 35 | #include <linux/skbuff.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 36 | #include <linux/ieee80211.h> |
| 37 | #include <net/cfg80211.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 38 | #include <net/ieee80211_radiotap.h> |
| 39 | #include <linux/if_arp.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 40 | #include <linux/in6.h> |
| 41 | #include <asm/checksum.h> |
| 42 | #include "host_interface.h" |
| 43 | #include "wilc_wlan.h" |
Chaehyun Lim | 30b2ba09 | 2015-10-02 16:41:15 +0900 | [diff] [blame] | 44 | #include <linux/wireless.h> |
Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 45 | #include <linux/completion.h> |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 46 | #include <linux/mutex.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 47 | |
| 48 | #define FLOW_CONTROL_LOWER_THRESHOLD 128 |
| 49 | #define FLOW_CONTROL_UPPER_THRESHOLD 256 |
| 50 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 51 | enum stats_flags { |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 52 | WILC_WFI_RX_PKT = BIT(0), |
| 53 | WILC_WFI_TX_PKT = BIT(1), |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct WILC_WFI_stats { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 57 | 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 71 | #define num_reg_frame 2 |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 72 | |
| 73 | struct wilc_wfi_key { |
| 74 | u8 *key; |
| 75 | u8 *seq; |
| 76 | int key_len; |
| 77 | int seq_len; |
| 78 | u32 cipher; |
| 79 | }; |
Sunghoon Cho | 36901b6 | 2015-06-26 15:48:15 +0900 | [diff] [blame] | 80 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 81 | struct wilc_wfi_wep_key { |
| 82 | u8 *key; |
| 83 | u8 key_len; |
| 84 | u8 key_idx; |
| 85 | }; |
| 86 | |
| 87 | struct sta_info { |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 88 | u8 au8Sta_AssociatedBss[MAX_NUM_STA][ETH_ALEN]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 89 | }; |
| 90 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 91 | /*Parameters needed for host interface for remaining on channel*/ |
| 92 | struct wilc_wfi_p2pListenParams { |
| 93 | struct ieee80211_channel *pstrListenChan; |
| 94 | enum nl80211_channel_type tenuChannelType; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 95 | u32 u32ListenDuration; |
Chaehyun Lim | 57b298f | 2015-06-11 14:35:56 +0900 | [diff] [blame] | 96 | u64 u64ListenCookie; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 97 | u32 u32ListenSessionID; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 98 | }; |
| 99 | |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 100 | struct wilc_priv { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 101 | struct wireless_dev *wdev; |
| 102 | struct cfg80211_scan_request *pstrScanReq; |
| 103 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 104 | struct wilc_wfi_p2pListenParams strRemainOnChanParams; |
Chaehyun Lim | 57b298f | 2015-06-11 14:35:56 +0900 | [diff] [blame] | 105 | u64 u64tx_cookie; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 106 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 107 | bool bCfgScanning; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 108 | u32 u32RcvdChCount; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 109 | |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 110 | u8 au8AssociatedBss[ETH_ALEN]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 111 | struct sta_info assoc_stainfo; |
| 112 | struct net_device_stats stats; |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 113 | u8 monitor_flag; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 114 | 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 Kim | 48b28df | 2016-02-04 18:15:32 +0900 | [diff] [blame] | 124 | struct host_if_drv *hif_drv; |
Leo Kim | a949f90 | 2015-10-05 15:25:44 +0900 | [diff] [blame] | 125 | struct host_if_pmkid_attr pmkid_list; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 126 | struct WILC_WFI_stats netstats; |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 127 | u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104]; |
| 128 | u8 WILC_WFI_wep_key_len[4]; |
Sunghoon Cho | 70e59d9 | 2015-06-26 15:48:16 +0900 | [diff] [blame] | 129 | /* The real interface that the monitor is on */ |
| 130 | struct net_device *real_ndev; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 131 | struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA]; |
| 132 | struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA]; |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 133 | u8 wilc_groupkey; |
Joshua Houghton | eeeb5fb | 2016-08-01 19:17:25 +0000 | [diff] [blame] | 134 | /* mutexes */ |
Chaehyun Lim | 0866209 | 2016-03-28 13:56:00 +0900 | [diff] [blame] | 135 | struct mutex scan_req_lock; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 136 | /* */ |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 137 | bool gbAutoRateAdjusted; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 138 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 139 | bool bInP2PlistenState; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 140 | |
| 141 | }; |
| 142 | |
Leo Kim | c92a869 | 2016-03-25 21:16:48 +0900 | [diff] [blame] | 143 | struct frame_reg { |
Leo Kim | 340a84f | 2016-03-25 21:16:50 +0900 | [diff] [blame] | 144 | u16 type; |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 145 | bool reg; |
Leo Kim | c92a869 | 2016-03-25 21:16:48 +0900 | [diff] [blame] | 146 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 147 | |
Tony Cho | 1a08bc4 | 2015-10-14 20:46:32 +0900 | [diff] [blame] | 148 | struct wilc_vif { |
Leo Kim | 6750140 | 2016-02-04 18:15:39 +0900 | [diff] [blame] | 149 | u8 idx; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 150 | u8 iftype; |
| 151 | int monitor_flag; |
| 152 | int mac_opened; |
Leo Kim | 89febb2 | 2016-03-25 21:16:49 +0900 | [diff] [blame] | 153 | struct frame_reg frame_reg[num_reg_frame]; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 154 | struct net_device_stats netstats; |
| 155 | struct wilc *wilc; |
Tony Cho | 7e7fa47 | 2015-10-20 14:26:48 +0900 | [diff] [blame] | 156 | u8 src_addr[ETH_ALEN]; |
Tony Cho | 7201cd2 | 2015-10-20 14:26:49 +0900 | [diff] [blame] | 157 | u8 bssid[ETH_ALEN]; |
Tony Cho | 3134a57 | 2015-10-20 14:26:50 +0900 | [diff] [blame] | 158 | struct host_if_drv *hif_drv; |
Tony Cho | 817f3fb | 2015-10-20 14:26:51 +0900 | [diff] [blame] | 159 | struct net_device *ndev; |
Glen Lee | ba615f1 | 2016-01-25 16:35:15 +0900 | [diff] [blame] | 160 | u8 mode; |
Tony Cho | 1a08bc4 | 2015-10-14 20:46:32 +0900 | [diff] [blame] | 161 | }; |
Tony Cho | f61c5af | 2015-10-14 20:46:30 +0900 | [diff] [blame] | 162 | |
| 163 | struct wilc { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 164 | const struct wilc_hif_func *hif_func; |
Arnd Bergmann | 4bd7baf | 2015-11-16 15:04:59 +0100 | [diff] [blame] | 165 | int io_type; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 166 | int mac_status; |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 167 | int gpio; |
Tony Cho | 080f11b | 2015-10-20 14:26:45 +0900 | [diff] [blame] | 168 | bool initialized; |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 169 | int dev_irq_num; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 170 | int close; |
Tony Cho | c1b30f6 | 2015-10-20 14:26:46 +0900 | [diff] [blame] | 171 | u8 vif_num; |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 172 | struct wilc_vif *vif[NUM_CONCURRENT_IFC]; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 173 | u8 open_ifcs; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 174 | |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 175 | struct mutex txq_add_to_head_cs; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 176 | spinlock_t txq_spinlock; |
| 177 | |
| 178 | struct mutex rxq_cs; |
| 179 | struct mutex hif_cs; |
| 180 | |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 181 | struct completion cfg_event; |
Binoy Jayan | 04247e7 | 2016-06-15 11:00:37 +0530 | [diff] [blame] | 182 | struct completion sync_event; |
Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 183 | struct completion txq_event; |
Leo Kim | 11a54b3 | 2016-04-01 17:44:15 +0900 | [diff] [blame] | 184 | struct completion txq_thread_started; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 185 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 186 | struct task_struct *txq_thread; |
| 187 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 188 | 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 210 | unsigned char eth_src_address[NUM_CONCURRENT_IFC][6]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 211 | |
Tony Cho | 8b8ad7b | 2015-10-20 14:26:53 +0900 | [diff] [blame] | 212 | const struct firmware *firmware; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 213 | |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame] | 214 | struct device *dev; |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 215 | bool suspend_event; |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 216 | |
| 217 | struct rf_info dummy_statistics; |
Tony Cho | f61c5af | 2015-10-14 20:46:30 +0900 | [diff] [blame] | 218 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 219 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 220 | struct WILC_WFI_mon_priv { |
| 221 | struct net_device *real_ndev; |
| 222 | }; |
Sunghoon Cho | 1d1c5b2 | 2015-06-17 14:42:36 +0900 | [diff] [blame] | 223 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 224 | int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif); |
Arnd Bergmann | 491880e | 2015-11-16 15:04:55 +0100 | [diff] [blame] | 225 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 226 | void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset); |
| 227 | void wilc_mac_indicate(struct wilc *wilc, int flag); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 228 | int wilc_lock_timeout(struct wilc *wilc, void *, u32 timeout); |
Arnd Bergmann | 857c7b0 | 2015-11-16 15:05:00 +0100 | [diff] [blame] | 229 | void wilc_netdev_cleanup(struct wilc *wilc); |
Arnd Bergmann | 7d37a4a | 2015-11-16 15:05:05 +0100 | [diff] [blame] | 230 | int wilc_netdev_init(struct wilc **wilc, struct device *, int io_type, int gpio, |
| 231 | const struct wilc_hif_func *ops); |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 232 | void wilc1000_wlan_deinit(struct net_device *dev); |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 233 | void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 234 | int wilc_wlan_get_firmware(struct net_device *dev); |
Glen Lee | ba615f1 | 2016-01-25 16:35:15 +0900 | [diff] [blame] | 235 | int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 236 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 237 | #endif |