18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright(c) 2013 - 2019 Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _FM10K_H_ 58c2ecf20Sopenharmony_ci#define _FM10K_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/types.h> 88c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 98c2ecf20Sopenharmony_ci#include <linux/cpumask.h> 108c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h> 118c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 128c2ecf20Sopenharmony_ci#include <linux/pci.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "fm10k_pf.h" 158c2ecf20Sopenharmony_ci#include "fm10k_vf.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define FM10K_MAX_JUMBO_FRAME_SIZE 15342 /* Maximum supported size 15K */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define MAX_QUEUES FM10K_MAX_QUEUES_PF 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define FM10K_MIN_RXD 128 228c2ecf20Sopenharmony_ci#define FM10K_MAX_RXD 4096 238c2ecf20Sopenharmony_ci#define FM10K_DEFAULT_RXD 256 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define FM10K_MIN_TXD 128 268c2ecf20Sopenharmony_ci#define FM10K_MAX_TXD 4096 278c2ecf20Sopenharmony_ci#define FM10K_DEFAULT_TXD 256 288c2ecf20Sopenharmony_ci#define FM10K_DEFAULT_TX_WORK 256 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define FM10K_RXBUFFER_256 256 318c2ecf20Sopenharmony_ci#define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256 328c2ecf20Sopenharmony_ci#define FM10K_RXBUFFER_2048 2048 338c2ecf20Sopenharmony_ci#define FM10K_RX_BUFSZ FM10K_RXBUFFER_2048 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* How many Rx Buffers do we bundle into one write to the hardware ? */ 368c2ecf20Sopenharmony_ci#define FM10K_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define FM10K_MAX_STATIONS 63 398c2ecf20Sopenharmony_cistruct fm10k_l2_accel { 408c2ecf20Sopenharmony_ci int size; 418c2ecf20Sopenharmony_ci u16 count; 428c2ecf20Sopenharmony_ci u16 dglort; 438c2ecf20Sopenharmony_ci struct rcu_head rcu; 448c2ecf20Sopenharmony_ci struct net_device *macvlan[]; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cienum fm10k_ring_state_t { 488c2ecf20Sopenharmony_ci __FM10K_TX_DETECT_HANG, 498c2ecf20Sopenharmony_ci __FM10K_HANG_CHECK_ARMED, 508c2ecf20Sopenharmony_ci __FM10K_TX_XPS_INIT_DONE, 518c2ecf20Sopenharmony_ci /* This must be last and is used to calculate BITMAP size */ 528c2ecf20Sopenharmony_ci __FM10K_TX_STATE_SIZE__, 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define check_for_tx_hang(ring) \ 568c2ecf20Sopenharmony_ci test_bit(__FM10K_TX_DETECT_HANG, (ring)->state) 578c2ecf20Sopenharmony_ci#define set_check_for_tx_hang(ring) \ 588c2ecf20Sopenharmony_ci set_bit(__FM10K_TX_DETECT_HANG, (ring)->state) 598c2ecf20Sopenharmony_ci#define clear_check_for_tx_hang(ring) \ 608c2ecf20Sopenharmony_ci clear_bit(__FM10K_TX_DETECT_HANG, (ring)->state) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistruct fm10k_tx_buffer { 638c2ecf20Sopenharmony_ci struct fm10k_tx_desc *next_to_watch; 648c2ecf20Sopenharmony_ci struct sk_buff *skb; 658c2ecf20Sopenharmony_ci unsigned int bytecount; 668c2ecf20Sopenharmony_ci u16 gso_segs; 678c2ecf20Sopenharmony_ci u16 tx_flags; 688c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_ADDR(dma); 698c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_LEN(len); 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistruct fm10k_rx_buffer { 738c2ecf20Sopenharmony_ci dma_addr_t dma; 748c2ecf20Sopenharmony_ci struct page *page; 758c2ecf20Sopenharmony_ci u32 page_offset; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistruct fm10k_queue_stats { 798c2ecf20Sopenharmony_ci u64 packets; 808c2ecf20Sopenharmony_ci u64 bytes; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct fm10k_tx_queue_stats { 848c2ecf20Sopenharmony_ci u64 restart_queue; 858c2ecf20Sopenharmony_ci u64 csum_err; 868c2ecf20Sopenharmony_ci u64 tx_busy; 878c2ecf20Sopenharmony_ci u64 tx_done_old; 888c2ecf20Sopenharmony_ci u64 csum_good; 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistruct fm10k_rx_queue_stats { 928c2ecf20Sopenharmony_ci u64 alloc_failed; 938c2ecf20Sopenharmony_ci u64 csum_err; 948c2ecf20Sopenharmony_ci u64 errors; 958c2ecf20Sopenharmony_ci u64 csum_good; 968c2ecf20Sopenharmony_ci u64 switch_errors; 978c2ecf20Sopenharmony_ci u64 drops; 988c2ecf20Sopenharmony_ci u64 pp_errors; 998c2ecf20Sopenharmony_ci u64 link_errors; 1008c2ecf20Sopenharmony_ci u64 length_errors; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistruct fm10k_ring { 1048c2ecf20Sopenharmony_ci struct fm10k_q_vector *q_vector;/* backpointer to host q_vector */ 1058c2ecf20Sopenharmony_ci struct net_device *netdev; /* netdev ring belongs to */ 1068c2ecf20Sopenharmony_ci struct device *dev; /* device for DMA mapping */ 1078c2ecf20Sopenharmony_ci struct fm10k_l2_accel __rcu *l2_accel; /* L2 acceleration list */ 1088c2ecf20Sopenharmony_ci void *desc; /* descriptor ring memory */ 1098c2ecf20Sopenharmony_ci union { 1108c2ecf20Sopenharmony_ci struct fm10k_tx_buffer *tx_buffer; 1118c2ecf20Sopenharmony_ci struct fm10k_rx_buffer *rx_buffer; 1128c2ecf20Sopenharmony_ci }; 1138c2ecf20Sopenharmony_ci u32 __iomem *tail; 1148c2ecf20Sopenharmony_ci DECLARE_BITMAP(state, __FM10K_TX_STATE_SIZE__); 1158c2ecf20Sopenharmony_ci dma_addr_t dma; /* phys. address of descriptor ring */ 1168c2ecf20Sopenharmony_ci unsigned int size; /* length in bytes */ 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci u8 queue_index; /* needed for queue management */ 1198c2ecf20Sopenharmony_ci u8 reg_idx; /* holds the special value that gets 1208c2ecf20Sopenharmony_ci * the hardware register offset 1218c2ecf20Sopenharmony_ci * associated with this ring, which is 1228c2ecf20Sopenharmony_ci * different for DCB and RSS modes 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci u8 qos_pc; /* priority class of queue */ 1258c2ecf20Sopenharmony_ci u16 vid; /* default VLAN ID of queue */ 1268c2ecf20Sopenharmony_ci u16 count; /* amount of descriptors */ 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci u16 next_to_alloc; 1298c2ecf20Sopenharmony_ci u16 next_to_use; 1308c2ecf20Sopenharmony_ci u16 next_to_clean; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci struct fm10k_queue_stats stats; 1338c2ecf20Sopenharmony_ci struct u64_stats_sync syncp; 1348c2ecf20Sopenharmony_ci union { 1358c2ecf20Sopenharmony_ci /* Tx */ 1368c2ecf20Sopenharmony_ci struct fm10k_tx_queue_stats tx_stats; 1378c2ecf20Sopenharmony_ci /* Rx */ 1388c2ecf20Sopenharmony_ci struct { 1398c2ecf20Sopenharmony_ci struct fm10k_rx_queue_stats rx_stats; 1408c2ecf20Sopenharmony_ci struct sk_buff *skb; 1418c2ecf20Sopenharmony_ci }; 1428c2ecf20Sopenharmony_ci }; 1438c2ecf20Sopenharmony_ci} ____cacheline_internodealigned_in_smp; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistruct fm10k_ring_container { 1468c2ecf20Sopenharmony_ci struct fm10k_ring *ring; /* pointer to linked list of rings */ 1478c2ecf20Sopenharmony_ci unsigned int total_bytes; /* total bytes processed this int */ 1488c2ecf20Sopenharmony_ci unsigned int total_packets; /* total packets processed this int */ 1498c2ecf20Sopenharmony_ci u16 work_limit; /* total work allowed per interrupt */ 1508c2ecf20Sopenharmony_ci u16 itr; /* interrupt throttle rate value */ 1518c2ecf20Sopenharmony_ci u8 itr_scale; /* ITR adjustment based on PCI speed */ 1528c2ecf20Sopenharmony_ci u8 count; /* total number of rings in vector */ 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */ 1568c2ecf20Sopenharmony_ci#define FM10K_ITR_10K 100 /* 100us */ 1578c2ecf20Sopenharmony_ci#define FM10K_ITR_20K 50 /* 50us */ 1588c2ecf20Sopenharmony_ci#define FM10K_ITR_40K 25 /* 25us */ 1598c2ecf20Sopenharmony_ci#define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */ 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci#define ITR_IS_ADAPTIVE(itr) (!!(itr & FM10K_ITR_ADAPTIVE)) 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci#define FM10K_TX_ITR_DEFAULT FM10K_ITR_40K 1648c2ecf20Sopenharmony_ci#define FM10K_RX_ITR_DEFAULT FM10K_ITR_20K 1658c2ecf20Sopenharmony_ci#define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR) 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic inline struct netdev_queue *txring_txq(const struct fm10k_ring *ring) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci return &ring->netdev->_tx[ring->queue_index]; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci/* iterator for handling rings in ring container */ 1738c2ecf20Sopenharmony_ci#define fm10k_for_each_ring(pos, head) \ 1748c2ecf20Sopenharmony_ci for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#define MAX_Q_VECTORS 256 1778c2ecf20Sopenharmony_ci#define MIN_Q_VECTORS 1 1788c2ecf20Sopenharmony_cienum fm10k_non_q_vectors { 1798c2ecf20Sopenharmony_ci FM10K_MBX_VECTOR, 1808c2ecf20Sopenharmony_ci NON_Q_VECTORS 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci#define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistruct fm10k_q_vector { 1868c2ecf20Sopenharmony_ci struct fm10k_intfc *interface; 1878c2ecf20Sopenharmony_ci u32 __iomem *itr; /* pointer to ITR register for this vector */ 1888c2ecf20Sopenharmony_ci u16 v_idx; /* index of q_vector within interface array */ 1898c2ecf20Sopenharmony_ci struct fm10k_ring_container rx, tx; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci struct napi_struct napi; 1928c2ecf20Sopenharmony_ci cpumask_t affinity_mask; 1938c2ecf20Sopenharmony_ci char name[IFNAMSIZ + 9]; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 1968c2ecf20Sopenharmony_ci struct dentry *dbg_q_vector; 1978c2ecf20Sopenharmony_ci#endif /* CONFIG_DEBUG_FS */ 1988c2ecf20Sopenharmony_ci struct rcu_head rcu; /* to avoid race with update stats on free */ 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci /* for dynamic allocation of rings associated with this q_vector */ 2018c2ecf20Sopenharmony_ci struct fm10k_ring ring[] ____cacheline_internodealigned_in_smp; 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cienum fm10k_ring_f_enum { 2058c2ecf20Sopenharmony_ci RING_F_RSS, 2068c2ecf20Sopenharmony_ci RING_F_QOS, 2078c2ecf20Sopenharmony_ci RING_F_ARRAY_SIZE /* must be last in enum set */ 2088c2ecf20Sopenharmony_ci}; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_cistruct fm10k_ring_feature { 2118c2ecf20Sopenharmony_ci u16 limit; /* upper limit on feature indices */ 2128c2ecf20Sopenharmony_ci u16 indices; /* current value of indices */ 2138c2ecf20Sopenharmony_ci u16 mask; /* Mask used for feature to ring mapping */ 2148c2ecf20Sopenharmony_ci u16 offset; /* offset to start of feature */ 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistruct fm10k_iov_data { 2188c2ecf20Sopenharmony_ci unsigned int num_vfs; 2198c2ecf20Sopenharmony_ci unsigned int next_vf_mbx; 2208c2ecf20Sopenharmony_ci struct rcu_head rcu; 2218c2ecf20Sopenharmony_ci struct fm10k_vf_info vf_info[]; 2228c2ecf20Sopenharmony_ci}; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cienum fm10k_macvlan_request_type { 2258c2ecf20Sopenharmony_ci FM10K_UC_MAC_REQUEST, 2268c2ecf20Sopenharmony_ci FM10K_MC_MAC_REQUEST, 2278c2ecf20Sopenharmony_ci FM10K_VLAN_REQUEST 2288c2ecf20Sopenharmony_ci}; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistruct fm10k_macvlan_request { 2318c2ecf20Sopenharmony_ci enum fm10k_macvlan_request_type type; 2328c2ecf20Sopenharmony_ci struct list_head list; 2338c2ecf20Sopenharmony_ci union { 2348c2ecf20Sopenharmony_ci struct fm10k_mac_request { 2358c2ecf20Sopenharmony_ci u8 addr[ETH_ALEN]; 2368c2ecf20Sopenharmony_ci u16 glort; 2378c2ecf20Sopenharmony_ci u16 vid; 2388c2ecf20Sopenharmony_ci } mac; 2398c2ecf20Sopenharmony_ci struct fm10k_vlan_request { 2408c2ecf20Sopenharmony_ci u32 vid; 2418c2ecf20Sopenharmony_ci u8 vsi; 2428c2ecf20Sopenharmony_ci } vlan; 2438c2ecf20Sopenharmony_ci }; 2448c2ecf20Sopenharmony_ci bool set; 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci/* one work queue for entire driver */ 2488c2ecf20Sopenharmony_ciextern struct workqueue_struct *fm10k_workqueue; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/* The following enumeration contains flags which indicate or enable modified 2518c2ecf20Sopenharmony_ci * driver behaviors. To avoid race conditions, the flags are stored in 2528c2ecf20Sopenharmony_ci * a BITMAP in the fm10k_intfc structure. The BITMAP should be accessed using 2538c2ecf20Sopenharmony_ci * atomic *_bit() operations. 2548c2ecf20Sopenharmony_ci */ 2558c2ecf20Sopenharmony_cienum fm10k_flags_t { 2568c2ecf20Sopenharmony_ci FM10K_FLAG_RESET_REQUESTED, 2578c2ecf20Sopenharmony_ci FM10K_FLAG_RSS_FIELD_IPV4_UDP, 2588c2ecf20Sopenharmony_ci FM10K_FLAG_RSS_FIELD_IPV6_UDP, 2598c2ecf20Sopenharmony_ci FM10K_FLAG_SWPRI_CONFIG, 2608c2ecf20Sopenharmony_ci /* __FM10K_FLAGS_SIZE__ is used to calculate the size of 2618c2ecf20Sopenharmony_ci * interface->flags and must be the last value in this 2628c2ecf20Sopenharmony_ci * enumeration. 2638c2ecf20Sopenharmony_ci */ 2648c2ecf20Sopenharmony_ci __FM10K_FLAGS_SIZE__ 2658c2ecf20Sopenharmony_ci}; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_cienum fm10k_state_t { 2688c2ecf20Sopenharmony_ci __FM10K_RESETTING, 2698c2ecf20Sopenharmony_ci __FM10K_RESET_DETACHED, 2708c2ecf20Sopenharmony_ci __FM10K_RESET_SUSPENDED, 2718c2ecf20Sopenharmony_ci __FM10K_DOWN, 2728c2ecf20Sopenharmony_ci __FM10K_SERVICE_SCHED, 2738c2ecf20Sopenharmony_ci __FM10K_SERVICE_REQUEST, 2748c2ecf20Sopenharmony_ci __FM10K_SERVICE_DISABLE, 2758c2ecf20Sopenharmony_ci __FM10K_MACVLAN_SCHED, 2768c2ecf20Sopenharmony_ci __FM10K_MACVLAN_REQUEST, 2778c2ecf20Sopenharmony_ci __FM10K_MACVLAN_DISABLE, 2788c2ecf20Sopenharmony_ci __FM10K_LINK_DOWN, 2798c2ecf20Sopenharmony_ci __FM10K_UPDATING_STATS, 2808c2ecf20Sopenharmony_ci /* This value must be last and determines the BITMAP size */ 2818c2ecf20Sopenharmony_ci __FM10K_STATE_SIZE__, 2828c2ecf20Sopenharmony_ci}; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistruct fm10k_intfc { 2858c2ecf20Sopenharmony_ci unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 2868c2ecf20Sopenharmony_ci struct net_device *netdev; 2878c2ecf20Sopenharmony_ci struct fm10k_l2_accel *l2_accel; /* pointer to L2 acceleration list */ 2888c2ecf20Sopenharmony_ci struct pci_dev *pdev; 2898c2ecf20Sopenharmony_ci DECLARE_BITMAP(state, __FM10K_STATE_SIZE__); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* Access flag values using atomic *_bit() operations */ 2928c2ecf20Sopenharmony_ci DECLARE_BITMAP(flags, __FM10K_FLAGS_SIZE__); 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci int xcast_mode; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* Tx fast path data */ 2978c2ecf20Sopenharmony_ci int num_tx_queues; 2988c2ecf20Sopenharmony_ci u16 tx_itr; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci /* Rx fast path data */ 3018c2ecf20Sopenharmony_ci int num_rx_queues; 3028c2ecf20Sopenharmony_ci u16 rx_itr; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci /* TX */ 3058c2ecf20Sopenharmony_ci struct fm10k_ring *tx_ring[MAX_QUEUES] ____cacheline_aligned_in_smp; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci u64 restart_queue; 3088c2ecf20Sopenharmony_ci u64 tx_busy; 3098c2ecf20Sopenharmony_ci u64 tx_csum_errors; 3108c2ecf20Sopenharmony_ci u64 alloc_failed; 3118c2ecf20Sopenharmony_ci u64 rx_csum_errors; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci u64 tx_bytes_nic; 3148c2ecf20Sopenharmony_ci u64 tx_packets_nic; 3158c2ecf20Sopenharmony_ci u64 rx_bytes_nic; 3168c2ecf20Sopenharmony_ci u64 rx_packets_nic; 3178c2ecf20Sopenharmony_ci u64 rx_drops_nic; 3188c2ecf20Sopenharmony_ci u64 rx_overrun_pf; 3198c2ecf20Sopenharmony_ci u64 rx_overrun_vf; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* Debug Statistics */ 3228c2ecf20Sopenharmony_ci u64 hw_sm_mbx_full; 3238c2ecf20Sopenharmony_ci u64 hw_csum_tx_good; 3248c2ecf20Sopenharmony_ci u64 hw_csum_rx_good; 3258c2ecf20Sopenharmony_ci u64 rx_switch_errors; 3268c2ecf20Sopenharmony_ci u64 rx_drops; 3278c2ecf20Sopenharmony_ci u64 rx_pp_errors; 3288c2ecf20Sopenharmony_ci u64 rx_link_errors; 3298c2ecf20Sopenharmony_ci u64 rx_length_errors; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci u32 tx_timeout_count; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci /* RX */ 3348c2ecf20Sopenharmony_ci struct fm10k_ring *rx_ring[MAX_QUEUES]; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* Queueing vectors */ 3378c2ecf20Sopenharmony_ci struct fm10k_q_vector *q_vector[MAX_Q_VECTORS]; 3388c2ecf20Sopenharmony_ci struct msix_entry *msix_entries; 3398c2ecf20Sopenharmony_ci int num_q_vectors; /* current number of q_vectors for device */ 3408c2ecf20Sopenharmony_ci struct fm10k_ring_feature ring_feature[RING_F_ARRAY_SIZE]; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci /* SR-IOV information management structure */ 3438c2ecf20Sopenharmony_ci struct fm10k_iov_data *iov_data; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci struct fm10k_hw_stats stats; 3468c2ecf20Sopenharmony_ci struct fm10k_hw hw; 3478c2ecf20Sopenharmony_ci /* Mailbox lock */ 3488c2ecf20Sopenharmony_ci spinlock_t mbx_lock; 3498c2ecf20Sopenharmony_ci u32 __iomem *uc_addr; 3508c2ecf20Sopenharmony_ci u32 __iomem *sw_addr; 3518c2ecf20Sopenharmony_ci u16 msg_enable; 3528c2ecf20Sopenharmony_ci u16 tx_ring_count; 3538c2ecf20Sopenharmony_ci u16 rx_ring_count; 3548c2ecf20Sopenharmony_ci struct timer_list service_timer; 3558c2ecf20Sopenharmony_ci struct work_struct service_task; 3568c2ecf20Sopenharmony_ci unsigned long next_stats_update; 3578c2ecf20Sopenharmony_ci unsigned long next_tx_hang_check; 3588c2ecf20Sopenharmony_ci unsigned long last_reset; 3598c2ecf20Sopenharmony_ci unsigned long link_down_event; 3608c2ecf20Sopenharmony_ci bool host_ready; 3618c2ecf20Sopenharmony_ci bool lport_map_failed; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci u32 reta[FM10K_RETA_SIZE]; 3648c2ecf20Sopenharmony_ci u32 rssrk[FM10K_RSSRK_SIZE]; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci /* UDP encapsulation port tracking information */ 3678c2ecf20Sopenharmony_ci __be16 vxlan_port; 3688c2ecf20Sopenharmony_ci __be16 geneve_port; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci /* MAC/VLAN update queue */ 3718c2ecf20Sopenharmony_ci struct list_head macvlan_requests; 3728c2ecf20Sopenharmony_ci struct delayed_work macvlan_task; 3738c2ecf20Sopenharmony_ci /* MAC/VLAN update queue lock */ 3748c2ecf20Sopenharmony_ci spinlock_t macvlan_lock; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 3778c2ecf20Sopenharmony_ci struct dentry *dbg_intfc; 3788c2ecf20Sopenharmony_ci#endif /* CONFIG_DEBUG_FS */ 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci#ifdef CONFIG_DCB 3818c2ecf20Sopenharmony_ci u8 pfc_en; 3828c2ecf20Sopenharmony_ci#endif 3838c2ecf20Sopenharmony_ci u8 rx_pause; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci /* GLORT resources in use by PF */ 3868c2ecf20Sopenharmony_ci u16 glort; 3878c2ecf20Sopenharmony_ci u16 glort_count; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci /* VLAN ID for updating multicast/unicast lists */ 3908c2ecf20Sopenharmony_ci u16 vid; 3918c2ecf20Sopenharmony_ci}; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistatic inline void fm10k_mbx_lock(struct fm10k_intfc *interface) 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci spin_lock(&interface->mbx_lock); 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_cistatic inline void fm10k_mbx_unlock(struct fm10k_intfc *interface) 3998c2ecf20Sopenharmony_ci{ 4008c2ecf20Sopenharmony_ci spin_unlock(&interface->mbx_lock); 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistatic inline int fm10k_mbx_trylock(struct fm10k_intfc *interface) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci return spin_trylock(&interface->mbx_lock); 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci/* fm10k_test_staterr - test bits in Rx descriptor status and error fields */ 4098c2ecf20Sopenharmony_cistatic inline __le32 fm10k_test_staterr(union fm10k_rx_desc *rx_desc, 4108c2ecf20Sopenharmony_ci const u32 stat_err_bits) 4118c2ecf20Sopenharmony_ci{ 4128c2ecf20Sopenharmony_ci return rx_desc->d.staterr & cpu_to_le32(stat_err_bits); 4138c2ecf20Sopenharmony_ci} 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci/* fm10k_desc_unused - calculate if we have unused descriptors */ 4168c2ecf20Sopenharmony_cistatic inline u16 fm10k_desc_unused(struct fm10k_ring *ring) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci s16 unused = ring->next_to_clean - ring->next_to_use - 1; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci return likely(unused < 0) ? unused + ring->count : unused; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci#define FM10K_TX_DESC(R, i) \ 4248c2ecf20Sopenharmony_ci (&(((struct fm10k_tx_desc *)((R)->desc))[i])) 4258c2ecf20Sopenharmony_ci#define FM10K_RX_DESC(R, i) \ 4268c2ecf20Sopenharmony_ci (&(((union fm10k_rx_desc *)((R)->desc))[i])) 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci#define FM10K_MAX_TXD_PWR 14 4298c2ecf20Sopenharmony_ci#define FM10K_MAX_DATA_PER_TXD (1u << FM10K_MAX_TXD_PWR) 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci/* Tx Descriptors needed, worst case */ 4328c2ecf20Sopenharmony_ci#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD) 4338c2ecf20Sopenharmony_ci#define DESC_NEEDED (MAX_SKB_FRAGS + 4) 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_cienum fm10k_tx_flags { 4368c2ecf20Sopenharmony_ci /* Tx offload flags */ 4378c2ecf20Sopenharmony_ci FM10K_TX_FLAGS_CSUM = 0x01, 4388c2ecf20Sopenharmony_ci}; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci/* This structure is stored as little endian values as that is the native 4418c2ecf20Sopenharmony_ci * format of the Rx descriptor. The ordering of these fields is reversed 4428c2ecf20Sopenharmony_ci * from the actual ftag header to allow for a single bswap to take care 4438c2ecf20Sopenharmony_ci * of placing all of the values in network order 4448c2ecf20Sopenharmony_ci */ 4458c2ecf20Sopenharmony_ciunion fm10k_ftag_info { 4468c2ecf20Sopenharmony_ci __le64 ftag; 4478c2ecf20Sopenharmony_ci struct { 4488c2ecf20Sopenharmony_ci /* dglort and sglort combined into a single 32bit desc read */ 4498c2ecf20Sopenharmony_ci __le32 glort; 4508c2ecf20Sopenharmony_ci /* upper 16 bits of VLAN are reserved 0 for swpri_type_user */ 4518c2ecf20Sopenharmony_ci __le32 vlan; 4528c2ecf20Sopenharmony_ci } d; 4538c2ecf20Sopenharmony_ci struct { 4548c2ecf20Sopenharmony_ci __le16 dglort; 4558c2ecf20Sopenharmony_ci __le16 sglort; 4568c2ecf20Sopenharmony_ci __le16 vlan; 4578c2ecf20Sopenharmony_ci __le16 swpri_type_user; 4588c2ecf20Sopenharmony_ci } w; 4598c2ecf20Sopenharmony_ci}; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_cistruct fm10k_cb { 4628c2ecf20Sopenharmony_ci union { 4638c2ecf20Sopenharmony_ci __le64 tstamp; 4648c2ecf20Sopenharmony_ci unsigned long ts_tx_timeout; 4658c2ecf20Sopenharmony_ci }; 4668c2ecf20Sopenharmony_ci union fm10k_ftag_info fi; 4678c2ecf20Sopenharmony_ci}; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci#define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb) 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci/* main */ 4728c2ecf20Sopenharmony_ciextern char fm10k_driver_name[]; 4738c2ecf20Sopenharmony_ciint fm10k_init_queueing_scheme(struct fm10k_intfc *interface); 4748c2ecf20Sopenharmony_civoid fm10k_clear_queueing_scheme(struct fm10k_intfc *interface); 4758c2ecf20Sopenharmony_ci__be16 fm10k_tx_encap_offload(struct sk_buff *skb); 4768c2ecf20Sopenharmony_cinetdev_tx_t fm10k_xmit_frame_ring(struct sk_buff *skb, 4778c2ecf20Sopenharmony_ci struct fm10k_ring *tx_ring); 4788c2ecf20Sopenharmony_civoid fm10k_tx_timeout_reset(struct fm10k_intfc *interface); 4798c2ecf20Sopenharmony_ciu64 fm10k_get_tx_pending(struct fm10k_ring *ring, bool in_sw); 4808c2ecf20Sopenharmony_cibool fm10k_check_tx_hang(struct fm10k_ring *tx_ring); 4818c2ecf20Sopenharmony_civoid fm10k_alloc_rx_buffers(struct fm10k_ring *rx_ring, u16 cleaned_count); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci/* PCI */ 4848c2ecf20Sopenharmony_civoid fm10k_mbx_free_irq(struct fm10k_intfc *); 4858c2ecf20Sopenharmony_ciint fm10k_mbx_request_irq(struct fm10k_intfc *); 4868c2ecf20Sopenharmony_civoid fm10k_qv_free_irq(struct fm10k_intfc *interface); 4878c2ecf20Sopenharmony_ciint fm10k_qv_request_irq(struct fm10k_intfc *interface); 4888c2ecf20Sopenharmony_ciint fm10k_register_pci_driver(void); 4898c2ecf20Sopenharmony_civoid fm10k_unregister_pci_driver(void); 4908c2ecf20Sopenharmony_civoid fm10k_up(struct fm10k_intfc *interface); 4918c2ecf20Sopenharmony_civoid fm10k_down(struct fm10k_intfc *interface); 4928c2ecf20Sopenharmony_civoid fm10k_update_stats(struct fm10k_intfc *interface); 4938c2ecf20Sopenharmony_civoid fm10k_service_event_schedule(struct fm10k_intfc *interface); 4948c2ecf20Sopenharmony_civoid fm10k_macvlan_schedule(struct fm10k_intfc *interface); 4958c2ecf20Sopenharmony_civoid fm10k_update_rx_drop_en(struct fm10k_intfc *interface); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci/* Netdev */ 4988c2ecf20Sopenharmony_cistruct net_device *fm10k_alloc_netdev(const struct fm10k_info *info); 4998c2ecf20Sopenharmony_ciint fm10k_setup_rx_resources(struct fm10k_ring *); 5008c2ecf20Sopenharmony_ciint fm10k_setup_tx_resources(struct fm10k_ring *); 5018c2ecf20Sopenharmony_civoid fm10k_free_rx_resources(struct fm10k_ring *); 5028c2ecf20Sopenharmony_civoid fm10k_free_tx_resources(struct fm10k_ring *); 5038c2ecf20Sopenharmony_civoid fm10k_clean_all_rx_rings(struct fm10k_intfc *); 5048c2ecf20Sopenharmony_civoid fm10k_clean_all_tx_rings(struct fm10k_intfc *); 5058c2ecf20Sopenharmony_civoid fm10k_unmap_and_free_tx_resource(struct fm10k_ring *, 5068c2ecf20Sopenharmony_ci struct fm10k_tx_buffer *); 5078c2ecf20Sopenharmony_civoid fm10k_restore_rx_state(struct fm10k_intfc *); 5088c2ecf20Sopenharmony_civoid fm10k_reset_rx_state(struct fm10k_intfc *); 5098c2ecf20Sopenharmony_ciint fm10k_setup_tc(struct net_device *dev, u8 tc); 5108c2ecf20Sopenharmony_ciint fm10k_open(struct net_device *netdev); 5118c2ecf20Sopenharmony_ciint fm10k_close(struct net_device *netdev); 5128c2ecf20Sopenharmony_ciint fm10k_queue_vlan_request(struct fm10k_intfc *interface, u32 vid, 5138c2ecf20Sopenharmony_ci u8 vsi, bool set); 5148c2ecf20Sopenharmony_ciint fm10k_queue_mac_request(struct fm10k_intfc *interface, u16 glort, 5158c2ecf20Sopenharmony_ci const unsigned char *addr, u16 vid, bool set); 5168c2ecf20Sopenharmony_civoid fm10k_clear_macvlan_queue(struct fm10k_intfc *interface, 5178c2ecf20Sopenharmony_ci u16 glort, bool vlans); 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci/* Ethtool */ 5208c2ecf20Sopenharmony_civoid fm10k_set_ethtool_ops(struct net_device *dev); 5218c2ecf20Sopenharmony_civoid fm10k_write_reta(struct fm10k_intfc *interface, const u32 *indir); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci/* IOV */ 5248c2ecf20Sopenharmony_cis32 fm10k_iov_event(struct fm10k_intfc *interface); 5258c2ecf20Sopenharmony_cis32 fm10k_iov_mbx(struct fm10k_intfc *interface); 5268c2ecf20Sopenharmony_civoid fm10k_iov_suspend(struct pci_dev *pdev); 5278c2ecf20Sopenharmony_ciint fm10k_iov_resume(struct pci_dev *pdev); 5288c2ecf20Sopenharmony_civoid fm10k_iov_disable(struct pci_dev *pdev); 5298c2ecf20Sopenharmony_ciint fm10k_iov_configure(struct pci_dev *pdev, int num_vfs); 5308c2ecf20Sopenharmony_civoid fm10k_iov_update_stats(struct fm10k_intfc *interface); 5318c2ecf20Sopenharmony_cis32 fm10k_iov_update_pvid(struct fm10k_intfc *interface, u16 glort, u16 pvid); 5328c2ecf20Sopenharmony_ciint fm10k_ndo_set_vf_mac(struct net_device *netdev, int vf_idx, u8 *mac); 5338c2ecf20Sopenharmony_ciint fm10k_ndo_set_vf_vlan(struct net_device *netdev, 5348c2ecf20Sopenharmony_ci int vf_idx, u16 vid, u8 qos, __be16 vlan_proto); 5358c2ecf20Sopenharmony_ciint fm10k_ndo_set_vf_bw(struct net_device *netdev, int vf_idx, 5368c2ecf20Sopenharmony_ci int __always_unused min_rate, int max_rate); 5378c2ecf20Sopenharmony_ciint fm10k_ndo_get_vf_config(struct net_device *netdev, 5388c2ecf20Sopenharmony_ci int vf_idx, struct ifla_vf_info *ivi); 5398c2ecf20Sopenharmony_ciint fm10k_ndo_get_vf_stats(struct net_device *netdev, 5408c2ecf20Sopenharmony_ci int vf_idx, struct ifla_vf_stats *stats); 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci/* DebugFS */ 5438c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 5448c2ecf20Sopenharmony_civoid fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector); 5458c2ecf20Sopenharmony_civoid fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector); 5468c2ecf20Sopenharmony_civoid fm10k_dbg_intfc_init(struct fm10k_intfc *interface); 5478c2ecf20Sopenharmony_civoid fm10k_dbg_intfc_exit(struct fm10k_intfc *interface); 5488c2ecf20Sopenharmony_civoid fm10k_dbg_init(void); 5498c2ecf20Sopenharmony_civoid fm10k_dbg_exit(void); 5508c2ecf20Sopenharmony_ci#else 5518c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector) {} 5528c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector) {} 5538c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_intfc_init(struct fm10k_intfc *interface) {} 5548c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface) {} 5558c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_init(void) {} 5568c2ecf20Sopenharmony_cistatic inline void fm10k_dbg_exit(void) {} 5578c2ecf20Sopenharmony_ci#endif /* CONFIG_DEBUG_FS */ 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci/* DCB */ 5608c2ecf20Sopenharmony_ci#ifdef CONFIG_DCB 5618c2ecf20Sopenharmony_civoid fm10k_dcbnl_set_ops(struct net_device *dev); 5628c2ecf20Sopenharmony_ci#else 5638c2ecf20Sopenharmony_cistatic inline void fm10k_dcbnl_set_ops(struct net_device *dev) {} 5648c2ecf20Sopenharmony_ci#endif 5658c2ecf20Sopenharmony_ci#endif /* _FM10K_H_ */ 566