18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
48c2ecf20Sopenharmony_ci * All rights reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef WILC_NETDEV_H
88c2ecf20Sopenharmony_ci#define WILC_NETDEV_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/tcp.h>
118c2ecf20Sopenharmony_ci#include <linux/ieee80211.h>
128c2ecf20Sopenharmony_ci#include <net/cfg80211.h>
138c2ecf20Sopenharmony_ci#include <net/ieee80211_radiotap.h>
148c2ecf20Sopenharmony_ci#include <linux/if_arp.h>
158c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "hif.h"
188c2ecf20Sopenharmony_ci#include "wlan.h"
198c2ecf20Sopenharmony_ci#include "wlan_cfg.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define FLOW_CONTROL_LOWER_THRESHOLD		128
228c2ecf20Sopenharmony_ci#define FLOW_CONTROL_UPPER_THRESHOLD		256
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define PMKID_FOUND				1
258c2ecf20Sopenharmony_ci#define NUM_STA_ASSOCIATED			8
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define TCP_ACK_FILTER_LINK_SPEED_THRESH	54
288c2ecf20Sopenharmony_ci#define DEFAULT_LINK_SPEED			72
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistruct wilc_wfi_stats {
318c2ecf20Sopenharmony_ci	unsigned long rx_packets;
328c2ecf20Sopenharmony_ci	unsigned long tx_packets;
338c2ecf20Sopenharmony_ci	unsigned long rx_bytes;
348c2ecf20Sopenharmony_ci	unsigned long tx_bytes;
358c2ecf20Sopenharmony_ci	u64 rx_time;
368c2ecf20Sopenharmony_ci	u64 tx_time;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct wilc_wfi_key {
418c2ecf20Sopenharmony_ci	u8 *key;
428c2ecf20Sopenharmony_ci	u8 *seq;
438c2ecf20Sopenharmony_ci	int key_len;
448c2ecf20Sopenharmony_ci	int seq_len;
458c2ecf20Sopenharmony_ci	u32 cipher;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct wilc_wfi_wep_key {
498c2ecf20Sopenharmony_ci	u8 *key;
508c2ecf20Sopenharmony_ci	u8 key_len;
518c2ecf20Sopenharmony_ci	u8 key_idx;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct sta_info {
558c2ecf20Sopenharmony_ci	u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* Parameters needed for host interface for remaining on channel */
598c2ecf20Sopenharmony_cistruct wilc_wfi_p2p_listen_params {
608c2ecf20Sopenharmony_ci	struct ieee80211_channel *listen_ch;
618c2ecf20Sopenharmony_ci	u32 listen_duration;
628c2ecf20Sopenharmony_ci	u64 listen_cookie;
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic const u32 wilc_cipher_suites[] = {
668c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_WEP40,
678c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_WEP104,
688c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_TKIP,
698c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_CCMP,
708c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_AES_CMAC
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define CHAN2G(_channel, _freq, _flags) {	 \
748c2ecf20Sopenharmony_ci	.band             = NL80211_BAND_2GHZ, \
758c2ecf20Sopenharmony_ci	.center_freq      = (_freq),		 \
768c2ecf20Sopenharmony_ci	.hw_value         = (_channel),		 \
778c2ecf20Sopenharmony_ci	.flags            = (_flags),		 \
788c2ecf20Sopenharmony_ci	.max_antenna_gain = 0,			 \
798c2ecf20Sopenharmony_ci	.max_power        = 30,			 \
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic const struct ieee80211_channel wilc_2ghz_channels[] = {
838c2ecf20Sopenharmony_ci	CHAN2G(1,  2412, 0),
848c2ecf20Sopenharmony_ci	CHAN2G(2,  2417, 0),
858c2ecf20Sopenharmony_ci	CHAN2G(3,  2422, 0),
868c2ecf20Sopenharmony_ci	CHAN2G(4,  2427, 0),
878c2ecf20Sopenharmony_ci	CHAN2G(5,  2432, 0),
888c2ecf20Sopenharmony_ci	CHAN2G(6,  2437, 0),
898c2ecf20Sopenharmony_ci	CHAN2G(7,  2442, 0),
908c2ecf20Sopenharmony_ci	CHAN2G(8,  2447, 0),
918c2ecf20Sopenharmony_ci	CHAN2G(9,  2452, 0),
928c2ecf20Sopenharmony_ci	CHAN2G(10, 2457, 0),
938c2ecf20Sopenharmony_ci	CHAN2G(11, 2462, 0),
948c2ecf20Sopenharmony_ci	CHAN2G(12, 2467, 0),
958c2ecf20Sopenharmony_ci	CHAN2G(13, 2472, 0),
968c2ecf20Sopenharmony_ci	CHAN2G(14, 2484, 0)
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define RATETAB_ENT(_rate, _hw_value, _flags) {	\
1008c2ecf20Sopenharmony_ci	.bitrate  = (_rate),			\
1018c2ecf20Sopenharmony_ci	.hw_value = (_hw_value),		\
1028c2ecf20Sopenharmony_ci	.flags    = (_flags),			\
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic struct ieee80211_rate wilc_bitrates[] = {
1068c2ecf20Sopenharmony_ci	RATETAB_ENT(10,  0,  0),
1078c2ecf20Sopenharmony_ci	RATETAB_ENT(20,  1,  0),
1088c2ecf20Sopenharmony_ci	RATETAB_ENT(55,  2,  0),
1098c2ecf20Sopenharmony_ci	RATETAB_ENT(110, 3,  0),
1108c2ecf20Sopenharmony_ci	RATETAB_ENT(60,  9,  0),
1118c2ecf20Sopenharmony_ci	RATETAB_ENT(90,  6,  0),
1128c2ecf20Sopenharmony_ci	RATETAB_ENT(120, 7,  0),
1138c2ecf20Sopenharmony_ci	RATETAB_ENT(180, 8,  0),
1148c2ecf20Sopenharmony_ci	RATETAB_ENT(240, 9,  0),
1158c2ecf20Sopenharmony_ci	RATETAB_ENT(360, 10, 0),
1168c2ecf20Sopenharmony_ci	RATETAB_ENT(480, 11, 0),
1178c2ecf20Sopenharmony_ci	RATETAB_ENT(540, 12, 0)
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistruct wilc_priv {
1218c2ecf20Sopenharmony_ci	struct wireless_dev wdev;
1228c2ecf20Sopenharmony_ci	struct cfg80211_scan_request *scan_req;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	struct wilc_wfi_p2p_listen_params remain_on_ch_params;
1258c2ecf20Sopenharmony_ci	u64 tx_cookie;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	bool cfg_scanning;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	u8 associated_bss[ETH_ALEN];
1308c2ecf20Sopenharmony_ci	struct sta_info assoc_stainfo;
1318c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1328c2ecf20Sopenharmony_ci	struct net_device *dev;
1338c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
1348c2ecf20Sopenharmony_ci	struct wilc_pmkid_attr pmkid_list;
1358c2ecf20Sopenharmony_ci	u8 wep_key[4][WLAN_KEY_LEN_WEP104];
1368c2ecf20Sopenharmony_ci	u8 wep_key_len[4];
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* The real interface that the monitor is on */
1398c2ecf20Sopenharmony_ci	struct net_device *real_ndev;
1408c2ecf20Sopenharmony_ci	struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
1418c2ecf20Sopenharmony_ci	struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
1428c2ecf20Sopenharmony_ci	u8 wilc_groupkey;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* mutexes */
1458c2ecf20Sopenharmony_ci	struct mutex scan_req_lock;
1468c2ecf20Sopenharmony_ci	bool p2p_listen_state;
1478c2ecf20Sopenharmony_ci	int scanned_cnt;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	u64 inc_roc_cookie;
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define MAX_TCP_SESSION                25
1538c2ecf20Sopenharmony_ci#define MAX_PENDING_ACKS               256
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistruct ack_session_info {
1568c2ecf20Sopenharmony_ci	u32 seq_num;
1578c2ecf20Sopenharmony_ci	u32 bigger_ack_num;
1588c2ecf20Sopenharmony_ci	u16 src_port;
1598c2ecf20Sopenharmony_ci	u16 dst_port;
1608c2ecf20Sopenharmony_ci	u16 status;
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistruct pending_acks {
1648c2ecf20Sopenharmony_ci	u32 ack_num;
1658c2ecf20Sopenharmony_ci	u32 session_index;
1668c2ecf20Sopenharmony_ci	struct txq_entry_t  *txqe;
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistruct tcp_ack_filter {
1708c2ecf20Sopenharmony_ci	struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
1718c2ecf20Sopenharmony_ci	struct pending_acks pending_acks[MAX_PENDING_ACKS];
1728c2ecf20Sopenharmony_ci	u32 pending_base;
1738c2ecf20Sopenharmony_ci	u32 tcp_session;
1748c2ecf20Sopenharmony_ci	u32 pending_acks_idx;
1758c2ecf20Sopenharmony_ci	bool enabled;
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistruct wilc_vif {
1798c2ecf20Sopenharmony_ci	u8 idx;
1808c2ecf20Sopenharmony_ci	u8 iftype;
1818c2ecf20Sopenharmony_ci	int monitor_flag;
1828c2ecf20Sopenharmony_ci	int mac_opened;
1838c2ecf20Sopenharmony_ci	u32 mgmt_reg_stypes;
1848c2ecf20Sopenharmony_ci	struct net_device_stats netstats;
1858c2ecf20Sopenharmony_ci	struct wilc *wilc;
1868c2ecf20Sopenharmony_ci	u8 bssid[ETH_ALEN];
1878c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
1888c2ecf20Sopenharmony_ci	struct net_device *ndev;
1898c2ecf20Sopenharmony_ci	u8 mode;
1908c2ecf20Sopenharmony_ci	struct timer_list during_ip_timer;
1918c2ecf20Sopenharmony_ci	struct timer_list periodic_rssi;
1928c2ecf20Sopenharmony_ci	struct rf_info periodic_stat;
1938c2ecf20Sopenharmony_ci	struct tcp_ack_filter ack_filter;
1948c2ecf20Sopenharmony_ci	bool connecting;
1958c2ecf20Sopenharmony_ci	struct wilc_priv priv;
1968c2ecf20Sopenharmony_ci	struct list_head list;
1978c2ecf20Sopenharmony_ci	struct cfg80211_bss *bss;
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistruct wilc {
2018c2ecf20Sopenharmony_ci	struct wiphy *wiphy;
2028c2ecf20Sopenharmony_ci	const struct wilc_hif_func *hif_func;
2038c2ecf20Sopenharmony_ci	int io_type;
2048c2ecf20Sopenharmony_ci	s8 mac_status;
2058c2ecf20Sopenharmony_ci	struct clk *rtc_clk;
2068c2ecf20Sopenharmony_ci	bool initialized;
2078c2ecf20Sopenharmony_ci	int dev_irq_num;
2088c2ecf20Sopenharmony_ci	int close;
2098c2ecf20Sopenharmony_ci	u8 vif_num;
2108c2ecf20Sopenharmony_ci	struct list_head vif_list;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	/* protect vif list */
2138c2ecf20Sopenharmony_ci	struct mutex vif_mutex;
2148c2ecf20Sopenharmony_ci	struct srcu_struct srcu;
2158c2ecf20Sopenharmony_ci	u8 open_ifcs;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	/* protect head of transmit queue */
2188c2ecf20Sopenharmony_ci	struct mutex txq_add_to_head_cs;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* protect txq_entry_t transmit queue */
2218c2ecf20Sopenharmony_ci	spinlock_t txq_spinlock;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	/* protect rxq_entry_t receiver queue */
2248c2ecf20Sopenharmony_ci	struct mutex rxq_cs;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	/* lock to protect hif access */
2278c2ecf20Sopenharmony_ci	struct mutex hif_cs;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	struct completion cfg_event;
2308c2ecf20Sopenharmony_ci	struct completion sync_event;
2318c2ecf20Sopenharmony_ci	struct completion txq_event;
2328c2ecf20Sopenharmony_ci	struct completion txq_thread_started;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	struct task_struct *txq_thread;
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	int quit;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	/* lock to protect issue of wid command to firmware */
2398c2ecf20Sopenharmony_ci	struct mutex cfg_cmd_lock;
2408c2ecf20Sopenharmony_ci	struct wilc_cfg_frame cfg_frame;
2418c2ecf20Sopenharmony_ci	u32 cfg_frame_offset;
2428c2ecf20Sopenharmony_ci	u8 cfg_seq_no;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	u8 *rx_buffer;
2458c2ecf20Sopenharmony_ci	u32 rx_buffer_offset;
2468c2ecf20Sopenharmony_ci	u8 *tx_buffer;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	struct txq_entry_t txq_head;
2498c2ecf20Sopenharmony_ci	int txq_entries;
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	struct rxq_entry_t rxq_head;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	const struct firmware *firmware;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	struct device *dev;
2568c2ecf20Sopenharmony_ci	bool suspend_event;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	int clients_count;
2598c2ecf20Sopenharmony_ci	struct workqueue_struct *hif_workqueue;
2608c2ecf20Sopenharmony_ci	enum chip_ps_states chip_ps_state;
2618c2ecf20Sopenharmony_ci	struct wilc_cfg cfg;
2628c2ecf20Sopenharmony_ci	void *bus_data;
2638c2ecf20Sopenharmony_ci	struct net_device *monitor_dev;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/* deinit lock */
2668c2ecf20Sopenharmony_ci	struct mutex deinit_lock;
2678c2ecf20Sopenharmony_ci	u8 sta_ch;
2688c2ecf20Sopenharmony_ci	u8 op_ch;
2698c2ecf20Sopenharmony_ci	struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
2708c2ecf20Sopenharmony_ci	struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
2718c2ecf20Sopenharmony_ci	struct ieee80211_supported_band band;
2728c2ecf20Sopenharmony_ci	u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
2738c2ecf20Sopenharmony_ci};
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_cistruct wilc_wfi_mon_priv {
2768c2ecf20Sopenharmony_ci	struct net_device *real_ndev;
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_civoid wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
2808c2ecf20Sopenharmony_civoid wilc_mac_indicate(struct wilc *wilc);
2818c2ecf20Sopenharmony_civoid wilc_netdev_cleanup(struct wilc *wilc);
2828c2ecf20Sopenharmony_civoid wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
2838c2ecf20Sopenharmony_civoid wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
2848c2ecf20Sopenharmony_cistruct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
2858c2ecf20Sopenharmony_ci				      int vif_type, enum nl80211_iftype type,
2868c2ecf20Sopenharmony_ci				      bool rtnl_locked);
2878c2ecf20Sopenharmony_ci#endif
288