15625f965SAjay Singh /* SPDX-License-Identifier: GPL-2.0 */ 25625f965SAjay Singh /* 35625f965SAjay Singh * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries. 45625f965SAjay Singh * All rights reserved. 55625f965SAjay Singh */ 65625f965SAjay Singh 75625f965SAjay Singh #ifndef WILC_NETDEV_H 85625f965SAjay Singh #define WILC_NETDEV_H 95625f965SAjay Singh 105625f965SAjay Singh #include <linux/tcp.h> 115625f965SAjay Singh #include <linux/ieee80211.h> 125625f965SAjay Singh #include <net/cfg80211.h> 135625f965SAjay Singh #include <net/ieee80211_radiotap.h> 145625f965SAjay Singh #include <linux/if_arp.h> 155625f965SAjay Singh #include <linux/gpio/consumer.h> 165625f965SAjay Singh 175625f965SAjay Singh #include "hif.h" 185625f965SAjay Singh #include "wlan.h" 195625f965SAjay Singh #include "wlan_cfg.h" 205625f965SAjay Singh 215625f965SAjay Singh #define FLOW_CONTROL_LOWER_THRESHOLD 128 225625f965SAjay Singh #define FLOW_CONTROL_UPPER_THRESHOLD 256 235625f965SAjay Singh 245625f965SAjay Singh #define PMKID_FOUND 1 255625f965SAjay Singh #define NUM_STA_ASSOCIATED 8 265625f965SAjay Singh 275625f965SAjay Singh #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54 285625f965SAjay Singh #define DEFAULT_LINK_SPEED 72 295625f965SAjay Singh 305625f965SAjay Singh struct wilc_wfi_stats { 315625f965SAjay Singh unsigned long rx_packets; 325625f965SAjay Singh unsigned long tx_packets; 335625f965SAjay Singh unsigned long rx_bytes; 345625f965SAjay Singh unsigned long tx_bytes; 355625f965SAjay Singh u64 rx_time; 365625f965SAjay Singh u64 tx_time; 375625f965SAjay Singh 385625f965SAjay Singh }; 395625f965SAjay Singh 405625f965SAjay Singh struct wilc_wfi_key { 415625f965SAjay Singh u8 *key; 425625f965SAjay Singh u8 *seq; 435625f965SAjay Singh int key_len; 445625f965SAjay Singh int seq_len; 455625f965SAjay Singh u32 cipher; 465625f965SAjay Singh }; 475625f965SAjay Singh 485625f965SAjay Singh struct sta_info { 495625f965SAjay Singh u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN]; 505625f965SAjay Singh }; 515625f965SAjay Singh 525625f965SAjay Singh /* Parameters needed for host interface for remaining on channel */ 535625f965SAjay Singh struct wilc_wfi_p2p_listen_params { 545625f965SAjay Singh struct ieee80211_channel *listen_ch; 555625f965SAjay Singh u32 listen_duration; 565625f965SAjay Singh u64 listen_cookie; 575625f965SAjay Singh }; 585625f965SAjay Singh 595625f965SAjay Singh static const u32 wilc_cipher_suites[] = { 605625f965SAjay Singh WLAN_CIPHER_SUITE_TKIP, 615625f965SAjay Singh WLAN_CIPHER_SUITE_CCMP, 625625f965SAjay Singh WLAN_CIPHER_SUITE_AES_CMAC 635625f965SAjay Singh }; 645625f965SAjay Singh 655625f965SAjay Singh #define CHAN2G(_channel, _freq, _flags) { \ 665625f965SAjay Singh .band = NL80211_BAND_2GHZ, \ 675625f965SAjay Singh .center_freq = (_freq), \ 685625f965SAjay Singh .hw_value = (_channel), \ 695625f965SAjay Singh .flags = (_flags), \ 705625f965SAjay Singh .max_antenna_gain = 0, \ 715625f965SAjay Singh .max_power = 30, \ 725625f965SAjay Singh } 735625f965SAjay Singh 745625f965SAjay Singh static const struct ieee80211_channel wilc_2ghz_channels[] = { 755625f965SAjay Singh CHAN2G(1, 2412, 0), 765625f965SAjay Singh CHAN2G(2, 2417, 0), 775625f965SAjay Singh CHAN2G(3, 2422, 0), 785625f965SAjay Singh CHAN2G(4, 2427, 0), 795625f965SAjay Singh CHAN2G(5, 2432, 0), 805625f965SAjay Singh CHAN2G(6, 2437, 0), 815625f965SAjay Singh CHAN2G(7, 2442, 0), 825625f965SAjay Singh CHAN2G(8, 2447, 0), 835625f965SAjay Singh CHAN2G(9, 2452, 0), 845625f965SAjay Singh CHAN2G(10, 2457, 0), 855625f965SAjay Singh CHAN2G(11, 2462, 0), 865625f965SAjay Singh CHAN2G(12, 2467, 0), 875625f965SAjay Singh CHAN2G(13, 2472, 0), 885625f965SAjay Singh CHAN2G(14, 2484, 0) 895625f965SAjay Singh }; 905625f965SAjay Singh 915625f965SAjay Singh #define RATETAB_ENT(_rate, _hw_value, _flags) { \ 925625f965SAjay Singh .bitrate = (_rate), \ 935625f965SAjay Singh .hw_value = (_hw_value), \ 945625f965SAjay Singh .flags = (_flags), \ 955625f965SAjay Singh } 965625f965SAjay Singh 975625f965SAjay Singh static struct ieee80211_rate wilc_bitrates[] = { 985625f965SAjay Singh RATETAB_ENT(10, 0, 0), 995625f965SAjay Singh RATETAB_ENT(20, 1, 0), 1005625f965SAjay Singh RATETAB_ENT(55, 2, 0), 1015625f965SAjay Singh RATETAB_ENT(110, 3, 0), 1025625f965SAjay Singh RATETAB_ENT(60, 9, 0), 1035625f965SAjay Singh RATETAB_ENT(90, 6, 0), 1045625f965SAjay Singh RATETAB_ENT(120, 7, 0), 1055625f965SAjay Singh RATETAB_ENT(180, 8, 0), 1065625f965SAjay Singh RATETAB_ENT(240, 9, 0), 1075625f965SAjay Singh RATETAB_ENT(360, 10, 0), 1085625f965SAjay Singh RATETAB_ENT(480, 11, 0), 1095625f965SAjay Singh RATETAB_ENT(540, 12, 0) 1105625f965SAjay Singh }; 1115625f965SAjay Singh 1125625f965SAjay Singh struct wilc_priv { 1135625f965SAjay Singh struct wireless_dev wdev; 1145625f965SAjay Singh struct cfg80211_scan_request *scan_req; 1155625f965SAjay Singh 1165625f965SAjay Singh struct wilc_wfi_p2p_listen_params remain_on_ch_params; 1175625f965SAjay Singh u64 tx_cookie; 1185625f965SAjay Singh 1195625f965SAjay Singh bool cfg_scanning; 1205625f965SAjay Singh 1215625f965SAjay Singh u8 associated_bss[ETH_ALEN]; 1225625f965SAjay Singh struct sta_info assoc_stainfo; 1235625f965SAjay Singh struct sk_buff *skb; 1245625f965SAjay Singh struct net_device *dev; 1255625f965SAjay Singh struct host_if_drv *hif_drv; 1265625f965SAjay Singh struct wilc_pmkid_attr pmkid_list; 1275625f965SAjay Singh 1285625f965SAjay Singh /* The real interface that the monitor is on */ 1295625f965SAjay Singh struct net_device *real_ndev; 1305625f965SAjay Singh struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA]; 1315625f965SAjay Singh struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA]; 1320e703de3SAjay Singh struct wilc_wfi_key *wilc_igtk[2]; 1335625f965SAjay Singh u8 wilc_groupkey; 1345625f965SAjay Singh 1355625f965SAjay Singh /* mutexes */ 1365625f965SAjay Singh struct mutex scan_req_lock; 1375625f965SAjay Singh bool p2p_listen_state; 1385625f965SAjay Singh int scanned_cnt; 1395625f965SAjay Singh 1405625f965SAjay Singh u64 inc_roc_cookie; 1415625f965SAjay Singh }; 1425625f965SAjay Singh 1435625f965SAjay Singh #define MAX_TCP_SESSION 25 1445625f965SAjay Singh #define MAX_PENDING_ACKS 256 1455625f965SAjay Singh 1465625f965SAjay Singh struct ack_session_info { 1475625f965SAjay Singh u32 seq_num; 1485625f965SAjay Singh u32 bigger_ack_num; 1495625f965SAjay Singh u16 src_port; 1505625f965SAjay Singh u16 dst_port; 1515625f965SAjay Singh u16 status; 1525625f965SAjay Singh }; 1535625f965SAjay Singh 1545625f965SAjay Singh struct pending_acks { 1555625f965SAjay Singh u32 ack_num; 1565625f965SAjay Singh u32 session_index; 1575625f965SAjay Singh struct txq_entry_t *txqe; 1585625f965SAjay Singh }; 1595625f965SAjay Singh 1605625f965SAjay Singh struct tcp_ack_filter { 1615625f965SAjay Singh struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION]; 1625625f965SAjay Singh struct pending_acks pending_acks[MAX_PENDING_ACKS]; 1635625f965SAjay Singh u32 pending_base; 1645625f965SAjay Singh u32 tcp_session; 1655625f965SAjay Singh u32 pending_acks_idx; 1665625f965SAjay Singh bool enabled; 1675625f965SAjay Singh }; 1685625f965SAjay Singh 1695625f965SAjay Singh struct wilc_vif { 1705625f965SAjay Singh u8 idx; 1715625f965SAjay Singh u8 iftype; 1725625f965SAjay Singh int monitor_flag; 1735625f965SAjay Singh int mac_opened; 1745625f965SAjay Singh u32 mgmt_reg_stypes; 1755625f965SAjay Singh struct net_device_stats netstats; 1765625f965SAjay Singh struct wilc *wilc; 1775625f965SAjay Singh u8 bssid[ETH_ALEN]; 1785625f965SAjay Singh struct host_if_drv *hif_drv; 1795625f965SAjay Singh struct net_device *ndev; 1805625f965SAjay Singh struct timer_list during_ip_timer; 1815625f965SAjay Singh struct timer_list periodic_rssi; 1825625f965SAjay Singh struct rf_info periodic_stat; 1835625f965SAjay Singh struct tcp_ack_filter ack_filter; 1845625f965SAjay Singh bool connecting; 1855625f965SAjay Singh struct wilc_priv priv; 1865625f965SAjay Singh struct list_head list; 1875625f965SAjay Singh struct cfg80211_bss *bss; 188c5b331d4SAjay Singh struct cfg80211_external_auth_params auth; 1895625f965SAjay Singh }; 1905625f965SAjay Singh 191339754ffSAjay Singh struct wilc_tx_queue_status { 192339754ffSAjay Singh u8 buffer[AC_BUFFER_SIZE]; 193339754ffSAjay Singh u16 end_index; 194339754ffSAjay Singh u16 cnt[NQUEUES]; 195339754ffSAjay Singh u16 sum; 196339754ffSAjay Singh bool initialized; 197339754ffSAjay Singh }; 198339754ffSAjay Singh 1995625f965SAjay Singh struct wilc { 2005625f965SAjay Singh struct wiphy *wiphy; 2015625f965SAjay Singh const struct wilc_hif_func *hif_func; 2025625f965SAjay Singh int io_type; 2035625f965SAjay Singh s8 mac_status; 2045625f965SAjay Singh struct clk *rtc_clk; 2055625f965SAjay Singh bool initialized; 2064d2cd7b0SDavid Mosberger-Tang u32 chipid; 207b530d5f3SDavid Mosberger-Tang bool power_save_mode; 2085625f965SAjay Singh int dev_irq_num; 2095625f965SAjay Singh int close; 2105625f965SAjay Singh u8 vif_num; 2115625f965SAjay Singh struct list_head vif_list; 2125625f965SAjay Singh 2135625f965SAjay Singh /* protect vif list */ 2145625f965SAjay Singh struct mutex vif_mutex; 2155625f965SAjay Singh struct srcu_struct srcu; 2165625f965SAjay Singh u8 open_ifcs; 2175625f965SAjay Singh 2185625f965SAjay Singh /* protect head of transmit queue */ 2195625f965SAjay Singh struct mutex txq_add_to_head_cs; 2205625f965SAjay Singh 2215625f965SAjay Singh /* protect txq_entry_t transmit queue */ 2225625f965SAjay Singh spinlock_t txq_spinlock; 2235625f965SAjay Singh 2245625f965SAjay Singh /* protect rxq_entry_t receiver queue */ 2255625f965SAjay Singh struct mutex rxq_cs; 2265625f965SAjay Singh 2275625f965SAjay Singh /* lock to protect hif access */ 2285625f965SAjay Singh struct mutex hif_cs; 2295625f965SAjay Singh 2305625f965SAjay Singh struct completion cfg_event; 2315625f965SAjay Singh struct completion sync_event; 2325625f965SAjay Singh struct completion txq_event; 2335625f965SAjay Singh struct completion txq_thread_started; 2345625f965SAjay Singh 2355625f965SAjay Singh struct task_struct *txq_thread; 2365625f965SAjay Singh 2375625f965SAjay Singh int quit; 2385625f965SAjay Singh 2395625f965SAjay Singh /* lock to protect issue of wid command to firmware */ 2405625f965SAjay Singh struct mutex cfg_cmd_lock; 2415625f965SAjay Singh struct wilc_cfg_frame cfg_frame; 2425625f965SAjay Singh u32 cfg_frame_offset; 2435625f965SAjay Singh u8 cfg_seq_no; 2445625f965SAjay Singh 2455625f965SAjay Singh u8 *rx_buffer; 2465625f965SAjay Singh u32 rx_buffer_offset; 2475625f965SAjay Singh u8 *tx_buffer; 248*40b717bfSAjay.Kathat@microchip.com u32 *vmm_table; 2495625f965SAjay Singh 250339754ffSAjay Singh struct txq_handle txq[NQUEUES]; 2515625f965SAjay Singh int txq_entries; 2525625f965SAjay Singh 253339754ffSAjay Singh struct wilc_tx_queue_status tx_q_limit; 2545625f965SAjay Singh struct rxq_entry_t rxq_head; 2555625f965SAjay Singh 2565625f965SAjay Singh const struct firmware *firmware; 2575625f965SAjay Singh 2585625f965SAjay Singh struct device *dev; 2595625f965SAjay Singh bool suspend_event; 2605625f965SAjay Singh 2615625f965SAjay Singh struct workqueue_struct *hif_workqueue; 2625625f965SAjay Singh struct wilc_cfg cfg; 2635625f965SAjay Singh void *bus_data; 2645625f965SAjay Singh struct net_device *monitor_dev; 2655625f965SAjay Singh 2665625f965SAjay Singh /* deinit lock */ 2675625f965SAjay Singh struct mutex deinit_lock; 2685625f965SAjay Singh u8 sta_ch; 2695625f965SAjay Singh u8 op_ch; 2705625f965SAjay Singh struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)]; 2715625f965SAjay Singh struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)]; 2725625f965SAjay Singh struct ieee80211_supported_band band; 2735625f965SAjay Singh u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)]; 2745625f965SAjay Singh }; 2755625f965SAjay Singh 2765625f965SAjay Singh struct wilc_wfi_mon_priv { 2775625f965SAjay Singh struct net_device *real_ndev; 2785625f965SAjay Singh }; 2795625f965SAjay Singh 2805625f965SAjay Singh void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset); 2815625f965SAjay Singh void wilc_mac_indicate(struct wilc *wilc); 2825625f965SAjay Singh void wilc_netdev_cleanup(struct wilc *wilc); 283c5b331d4SAjay Singh void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth); 2840341ae70SJakub Kicinski void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid, 2850341ae70SJakub Kicinski u8 mode); 2865625f965SAjay Singh struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name, 2875625f965SAjay Singh int vif_type, enum nl80211_iftype type, 2885625f965SAjay Singh bool rtnl_locked); 2895625f965SAjay Singh #endif 290