1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* Copyright(c) 2013 - 2018 Intel Corporation. */
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #ifndef _IAVF_H_
5*4882a593Smuzhiyun #define _IAVF_H_
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <linux/module.h>
8*4882a593Smuzhiyun #include <linux/pci.h>
9*4882a593Smuzhiyun #include <linux/aer.h>
10*4882a593Smuzhiyun #include <linux/netdevice.h>
11*4882a593Smuzhiyun #include <linux/vmalloc.h>
12*4882a593Smuzhiyun #include <linux/interrupt.h>
13*4882a593Smuzhiyun #include <linux/ethtool.h>
14*4882a593Smuzhiyun #include <linux/if_vlan.h>
15*4882a593Smuzhiyun #include <linux/ip.h>
16*4882a593Smuzhiyun #include <linux/tcp.h>
17*4882a593Smuzhiyun #include <linux/sctp.h>
18*4882a593Smuzhiyun #include <linux/ipv6.h>
19*4882a593Smuzhiyun #include <linux/kernel.h>
20*4882a593Smuzhiyun #include <linux/bitops.h>
21*4882a593Smuzhiyun #include <linux/timer.h>
22*4882a593Smuzhiyun #include <linux/workqueue.h>
23*4882a593Smuzhiyun #include <linux/wait.h>
24*4882a593Smuzhiyun #include <linux/delay.h>
25*4882a593Smuzhiyun #include <linux/gfp.h>
26*4882a593Smuzhiyun #include <linux/skbuff.h>
27*4882a593Smuzhiyun #include <linux/dma-mapping.h>
28*4882a593Smuzhiyun #include <linux/etherdevice.h>
29*4882a593Smuzhiyun #include <linux/socket.h>
30*4882a593Smuzhiyun #include <linux/jiffies.h>
31*4882a593Smuzhiyun #include <net/ip6_checksum.h>
32*4882a593Smuzhiyun #include <net/pkt_cls.h>
33*4882a593Smuzhiyun #include <net/udp.h>
34*4882a593Smuzhiyun #include <net/tc_act/tc_gact.h>
35*4882a593Smuzhiyun #include <net/tc_act/tc_mirred.h>
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #include "iavf_type.h"
38*4882a593Smuzhiyun #include <linux/avf/virtchnl.h>
39*4882a593Smuzhiyun #include "iavf_txrx.h"
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #define DEFAULT_DEBUG_LEVEL_SHIFT 3
42*4882a593Smuzhiyun #define PFX "iavf: "
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun /* VSI state flags shared with common code */
45*4882a593Smuzhiyun enum iavf_vsi_state_t {
46*4882a593Smuzhiyun __IAVF_VSI_DOWN,
47*4882a593Smuzhiyun /* This must be last as it determines the size of the BITMAP */
48*4882a593Smuzhiyun __IAVF_VSI_STATE_SIZE__,
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* dummy struct to make common code less painful */
52*4882a593Smuzhiyun struct iavf_vsi {
53*4882a593Smuzhiyun struct iavf_adapter *back;
54*4882a593Smuzhiyun struct net_device *netdev;
55*4882a593Smuzhiyun unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
56*4882a593Smuzhiyun u16 seid;
57*4882a593Smuzhiyun u16 id;
58*4882a593Smuzhiyun DECLARE_BITMAP(state, __IAVF_VSI_STATE_SIZE__);
59*4882a593Smuzhiyun int base_vector;
60*4882a593Smuzhiyun u16 work_limit;
61*4882a593Smuzhiyun u16 qs_handle;
62*4882a593Smuzhiyun void *priv; /* client driver data reference. */
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* How many Rx Buffers do we bundle into one write to the hardware ? */
66*4882a593Smuzhiyun #define IAVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
67*4882a593Smuzhiyun #define IAVF_DEFAULT_TXD 512
68*4882a593Smuzhiyun #define IAVF_DEFAULT_RXD 512
69*4882a593Smuzhiyun #define IAVF_MAX_TXD 4096
70*4882a593Smuzhiyun #define IAVF_MIN_TXD 64
71*4882a593Smuzhiyun #define IAVF_MAX_RXD 4096
72*4882a593Smuzhiyun #define IAVF_MIN_RXD 64
73*4882a593Smuzhiyun #define IAVF_REQ_DESCRIPTOR_MULTIPLE 32
74*4882a593Smuzhiyun #define IAVF_MAX_AQ_BUF_SIZE 4096
75*4882a593Smuzhiyun #define IAVF_AQ_LEN 32
76*4882a593Smuzhiyun #define IAVF_AQ_MAX_ERR 20 /* times to try before resetting AQ */
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #define IAVF_RX_DESC(R, i) (&(((union iavf_32byte_rx_desc *)((R)->desc))[i]))
81*4882a593Smuzhiyun #define IAVF_TX_DESC(R, i) (&(((struct iavf_tx_desc *)((R)->desc))[i]))
82*4882a593Smuzhiyun #define IAVF_TX_CTXTDESC(R, i) \
83*4882a593Smuzhiyun (&(((struct iavf_tx_context_desc *)((R)->desc))[i]))
84*4882a593Smuzhiyun #define IAVF_MAX_REQ_QUEUES 16
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun #define IAVF_HKEY_ARRAY_SIZE ((IAVF_VFQF_HKEY_MAX_INDEX + 1) * 4)
87*4882a593Smuzhiyun #define IAVF_HLUT_ARRAY_SIZE ((IAVF_VFQF_HLUT_MAX_INDEX + 1) * 4)
88*4882a593Smuzhiyun #define IAVF_MBPS_DIVISOR 125000 /* divisor to convert to Mbps */
89*4882a593Smuzhiyun #define IAVF_MBPS_QUANTA 50
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun #define IAVF_VIRTCHNL_VF_RESOURCE_SIZE (sizeof(struct virtchnl_vf_resource) + \
92*4882a593Smuzhiyun (IAVF_MAX_VF_VSI * \
93*4882a593Smuzhiyun sizeof(struct virtchnl_vsi_resource)))
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* MAX_MSIX_Q_VECTORS of these are allocated,
96*4882a593Smuzhiyun * but we only use one per queue-specific vector.
97*4882a593Smuzhiyun */
98*4882a593Smuzhiyun struct iavf_q_vector {
99*4882a593Smuzhiyun struct iavf_adapter *adapter;
100*4882a593Smuzhiyun struct iavf_vsi *vsi;
101*4882a593Smuzhiyun struct napi_struct napi;
102*4882a593Smuzhiyun struct iavf_ring_container rx;
103*4882a593Smuzhiyun struct iavf_ring_container tx;
104*4882a593Smuzhiyun u32 ring_mask;
105*4882a593Smuzhiyun u8 itr_countdown; /* when 0 should adjust adaptive ITR */
106*4882a593Smuzhiyun u8 num_ringpairs; /* total number of ring pairs in vector */
107*4882a593Smuzhiyun u16 v_idx; /* index in the vsi->q_vector array. */
108*4882a593Smuzhiyun u16 reg_idx; /* register index of the interrupt */
109*4882a593Smuzhiyun char name[IFNAMSIZ + 15];
110*4882a593Smuzhiyun bool arm_wb_state;
111*4882a593Smuzhiyun cpumask_t affinity_mask;
112*4882a593Smuzhiyun struct irq_affinity_notify affinity_notify;
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* Helper macros to switch between ints/sec and what the register uses.
116*4882a593Smuzhiyun * And yes, it's the same math going both ways. The lowest value
117*4882a593Smuzhiyun * supported by all of the iavf hardware is 8.
118*4882a593Smuzhiyun */
119*4882a593Smuzhiyun #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
120*4882a593Smuzhiyun ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
121*4882a593Smuzhiyun #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun #define IAVF_DESC_UNUSED(R) \
124*4882a593Smuzhiyun ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
125*4882a593Smuzhiyun (R)->next_to_clean - (R)->next_to_use - 1)
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun #define OTHER_VECTOR 1
128*4882a593Smuzhiyun #define NONQ_VECS (OTHER_VECTOR)
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun #define MIN_MSIX_Q_VECTORS 1
131*4882a593Smuzhiyun #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NONQ_VECS)
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun #define IAVF_QUEUE_END_OF_LIST 0x7FF
134*4882a593Smuzhiyun #define IAVF_FREE_VECTOR 0x7FFF
135*4882a593Smuzhiyun struct iavf_mac_filter {
136*4882a593Smuzhiyun struct list_head list;
137*4882a593Smuzhiyun u8 macaddr[ETH_ALEN];
138*4882a593Smuzhiyun bool is_new_mac; /* filter is new, wait for PF decision */
139*4882a593Smuzhiyun bool remove; /* filter needs to be removed */
140*4882a593Smuzhiyun bool add; /* filter needs to be added */
141*4882a593Smuzhiyun };
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun struct iavf_vlan_filter {
144*4882a593Smuzhiyun struct list_head list;
145*4882a593Smuzhiyun u16 vlan;
146*4882a593Smuzhiyun bool remove; /* filter needs to be removed */
147*4882a593Smuzhiyun bool add; /* filter needs to be added */
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun #define IAVF_MAX_TRAFFIC_CLASS 4
151*4882a593Smuzhiyun /* State of traffic class creation */
152*4882a593Smuzhiyun enum iavf_tc_state_t {
153*4882a593Smuzhiyun __IAVF_TC_INVALID, /* no traffic class, default state */
154*4882a593Smuzhiyun __IAVF_TC_RUNNING, /* traffic classes have been created */
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun /* channel info */
158*4882a593Smuzhiyun struct iavf_channel_config {
159*4882a593Smuzhiyun struct virtchnl_channel_info ch_info[IAVF_MAX_TRAFFIC_CLASS];
160*4882a593Smuzhiyun enum iavf_tc_state_t state;
161*4882a593Smuzhiyun u8 total_qps;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun /* State of cloud filter */
165*4882a593Smuzhiyun enum iavf_cloud_filter_state_t {
166*4882a593Smuzhiyun __IAVF_CF_INVALID, /* cloud filter not added */
167*4882a593Smuzhiyun __IAVF_CF_ADD_PENDING, /* cloud filter pending add by the PF */
168*4882a593Smuzhiyun __IAVF_CF_DEL_PENDING, /* cloud filter pending del by the PF */
169*4882a593Smuzhiyun __IAVF_CF_ACTIVE, /* cloud filter is active */
170*4882a593Smuzhiyun };
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun /* Driver state. The order of these is important! */
173*4882a593Smuzhiyun enum iavf_state_t {
174*4882a593Smuzhiyun __IAVF_STARTUP, /* driver loaded, probe complete */
175*4882a593Smuzhiyun __IAVF_REMOVE, /* driver is being unloaded */
176*4882a593Smuzhiyun __IAVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */
177*4882a593Smuzhiyun __IAVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */
178*4882a593Smuzhiyun __IAVF_INIT_SW, /* got resources, setting up structs */
179*4882a593Smuzhiyun __IAVF_RESETTING, /* in reset */
180*4882a593Smuzhiyun __IAVF_COMM_FAILED, /* communication with PF failed */
181*4882a593Smuzhiyun /* Below here, watchdog is running */
182*4882a593Smuzhiyun __IAVF_DOWN, /* ready, can be opened */
183*4882a593Smuzhiyun __IAVF_DOWN_PENDING, /* descending, waiting for watchdog */
184*4882a593Smuzhiyun __IAVF_TESTING, /* in ethtool self-test */
185*4882a593Smuzhiyun __IAVF_RUNNING, /* opened, working */
186*4882a593Smuzhiyun };
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun enum iavf_critical_section_t {
189*4882a593Smuzhiyun __IAVF_IN_CRITICAL_TASK, /* cannot be interrupted */
190*4882a593Smuzhiyun __IAVF_IN_CLIENT_TASK,
191*4882a593Smuzhiyun __IAVF_IN_REMOVE_TASK, /* device being removed */
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun #define IAVF_CLOUD_FIELD_OMAC 0x01
195*4882a593Smuzhiyun #define IAVF_CLOUD_FIELD_IMAC 0x02
196*4882a593Smuzhiyun #define IAVF_CLOUD_FIELD_IVLAN 0x04
197*4882a593Smuzhiyun #define IAVF_CLOUD_FIELD_TEN_ID 0x08
198*4882a593Smuzhiyun #define IAVF_CLOUD_FIELD_IIP 0x10
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun #define IAVF_CF_FLAGS_OMAC IAVF_CLOUD_FIELD_OMAC
201*4882a593Smuzhiyun #define IAVF_CF_FLAGS_IMAC IAVF_CLOUD_FIELD_IMAC
202*4882a593Smuzhiyun #define IAVF_CF_FLAGS_IMAC_IVLAN (IAVF_CLOUD_FIELD_IMAC |\
203*4882a593Smuzhiyun IAVF_CLOUD_FIELD_IVLAN)
204*4882a593Smuzhiyun #define IAVF_CF_FLAGS_IMAC_TEN_ID (IAVF_CLOUD_FIELD_IMAC |\
205*4882a593Smuzhiyun IAVF_CLOUD_FIELD_TEN_ID)
206*4882a593Smuzhiyun #define IAVF_CF_FLAGS_OMAC_TEN_ID_IMAC (IAVF_CLOUD_FIELD_OMAC |\
207*4882a593Smuzhiyun IAVF_CLOUD_FIELD_IMAC |\
208*4882a593Smuzhiyun IAVF_CLOUD_FIELD_TEN_ID)
209*4882a593Smuzhiyun #define IAVF_CF_FLAGS_IMAC_IVLAN_TEN_ID (IAVF_CLOUD_FIELD_IMAC |\
210*4882a593Smuzhiyun IAVF_CLOUD_FIELD_IVLAN |\
211*4882a593Smuzhiyun IAVF_CLOUD_FIELD_TEN_ID)
212*4882a593Smuzhiyun #define IAVF_CF_FLAGS_IIP IAVF_CLOUD_FIELD_IIP
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun /* bookkeeping of cloud filters */
215*4882a593Smuzhiyun struct iavf_cloud_filter {
216*4882a593Smuzhiyun enum iavf_cloud_filter_state_t state;
217*4882a593Smuzhiyun struct list_head list;
218*4882a593Smuzhiyun struct virtchnl_filter f;
219*4882a593Smuzhiyun unsigned long cookie;
220*4882a593Smuzhiyun bool del; /* filter needs to be deleted */
221*4882a593Smuzhiyun bool add; /* filter needs to be added */
222*4882a593Smuzhiyun };
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun #define IAVF_RESET_WAIT_MS 10
225*4882a593Smuzhiyun #define IAVF_RESET_WAIT_DETECTED_COUNT 500
226*4882a593Smuzhiyun #define IAVF_RESET_WAIT_COMPLETE_COUNT 2000
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /* board specific private data structure */
229*4882a593Smuzhiyun struct iavf_adapter {
230*4882a593Smuzhiyun struct work_struct reset_task;
231*4882a593Smuzhiyun struct work_struct adminq_task;
232*4882a593Smuzhiyun struct delayed_work client_task;
233*4882a593Smuzhiyun struct delayed_work init_task;
234*4882a593Smuzhiyun wait_queue_head_t down_waitqueue;
235*4882a593Smuzhiyun struct iavf_q_vector *q_vectors;
236*4882a593Smuzhiyun struct list_head vlan_filter_list;
237*4882a593Smuzhiyun struct list_head mac_filter_list;
238*4882a593Smuzhiyun /* Lock to protect accesses to MAC and VLAN lists */
239*4882a593Smuzhiyun spinlock_t mac_vlan_list_lock;
240*4882a593Smuzhiyun char misc_vector_name[IFNAMSIZ + 9];
241*4882a593Smuzhiyun int num_active_queues;
242*4882a593Smuzhiyun int num_req_queues;
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun /* TX */
245*4882a593Smuzhiyun struct iavf_ring *tx_rings;
246*4882a593Smuzhiyun u32 tx_timeout_count;
247*4882a593Smuzhiyun u32 tx_desc_count;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /* RX */
250*4882a593Smuzhiyun struct iavf_ring *rx_rings;
251*4882a593Smuzhiyun u64 hw_csum_rx_error;
252*4882a593Smuzhiyun u32 rx_desc_count;
253*4882a593Smuzhiyun int num_msix_vectors;
254*4882a593Smuzhiyun int num_iwarp_msix;
255*4882a593Smuzhiyun int iwarp_base_vector;
256*4882a593Smuzhiyun u32 client_pending;
257*4882a593Smuzhiyun struct iavf_client_instance *cinst;
258*4882a593Smuzhiyun struct msix_entry *msix_entries;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun u32 flags;
261*4882a593Smuzhiyun #define IAVF_FLAG_RX_CSUM_ENABLED BIT(0)
262*4882a593Smuzhiyun #define IAVF_FLAG_PF_COMMS_FAILED BIT(3)
263*4882a593Smuzhiyun #define IAVF_FLAG_RESET_PENDING BIT(4)
264*4882a593Smuzhiyun #define IAVF_FLAG_RESET_NEEDED BIT(5)
265*4882a593Smuzhiyun #define IAVF_FLAG_WB_ON_ITR_CAPABLE BIT(6)
266*4882a593Smuzhiyun #define IAVF_FLAG_SERVICE_CLIENT_REQUESTED BIT(9)
267*4882a593Smuzhiyun #define IAVF_FLAG_CLIENT_NEEDS_OPEN BIT(10)
268*4882a593Smuzhiyun #define IAVF_FLAG_CLIENT_NEEDS_CLOSE BIT(11)
269*4882a593Smuzhiyun #define IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS BIT(12)
270*4882a593Smuzhiyun #define IAVF_FLAG_PROMISC_ON BIT(13)
271*4882a593Smuzhiyun #define IAVF_FLAG_ALLMULTI_ON BIT(14)
272*4882a593Smuzhiyun #define IAVF_FLAG_LEGACY_RX BIT(15)
273*4882a593Smuzhiyun #define IAVF_FLAG_REINIT_ITR_NEEDED BIT(16)
274*4882a593Smuzhiyun #define IAVF_FLAG_QUEUES_DISABLED BIT(17)
275*4882a593Smuzhiyun /* duplicates for common code */
276*4882a593Smuzhiyun #define IAVF_FLAG_DCB_ENABLED 0
277*4882a593Smuzhiyun /* flags for admin queue service task */
278*4882a593Smuzhiyun u32 aq_required;
279*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ENABLE_QUEUES BIT(0)
280*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DISABLE_QUEUES BIT(1)
281*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ADD_MAC_FILTER BIT(2)
282*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ADD_VLAN_FILTER BIT(3)
283*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DEL_MAC_FILTER BIT(4)
284*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DEL_VLAN_FILTER BIT(5)
285*4882a593Smuzhiyun #define IAVF_FLAG_AQ_CONFIGURE_QUEUES BIT(6)
286*4882a593Smuzhiyun #define IAVF_FLAG_AQ_MAP_VECTORS BIT(7)
287*4882a593Smuzhiyun #define IAVF_FLAG_AQ_HANDLE_RESET BIT(8)
288*4882a593Smuzhiyun #define IAVF_FLAG_AQ_CONFIGURE_RSS BIT(9) /* direct AQ config */
289*4882a593Smuzhiyun #define IAVF_FLAG_AQ_GET_CONFIG BIT(10)
290*4882a593Smuzhiyun /* Newer style, RSS done by the PF so we can ignore hardware vagaries. */
291*4882a593Smuzhiyun #define IAVF_FLAG_AQ_GET_HENA BIT(11)
292*4882a593Smuzhiyun #define IAVF_FLAG_AQ_SET_HENA BIT(12)
293*4882a593Smuzhiyun #define IAVF_FLAG_AQ_SET_RSS_KEY BIT(13)
294*4882a593Smuzhiyun #define IAVF_FLAG_AQ_SET_RSS_LUT BIT(14)
295*4882a593Smuzhiyun #define IAVF_FLAG_AQ_REQUEST_PROMISC BIT(15)
296*4882a593Smuzhiyun #define IAVF_FLAG_AQ_RELEASE_PROMISC BIT(16)
297*4882a593Smuzhiyun #define IAVF_FLAG_AQ_REQUEST_ALLMULTI BIT(17)
298*4882a593Smuzhiyun #define IAVF_FLAG_AQ_RELEASE_ALLMULTI BIT(18)
299*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING BIT(19)
300*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING BIT(20)
301*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ENABLE_CHANNELS BIT(21)
302*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DISABLE_CHANNELS BIT(22)
303*4882a593Smuzhiyun #define IAVF_FLAG_AQ_ADD_CLOUD_FILTER BIT(23)
304*4882a593Smuzhiyun #define IAVF_FLAG_AQ_DEL_CLOUD_FILTER BIT(24)
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun /* OS defined structs */
307*4882a593Smuzhiyun struct net_device *netdev;
308*4882a593Smuzhiyun struct pci_dev *pdev;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun struct iavf_hw hw; /* defined in iavf_type.h */
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun enum iavf_state_t state;
313*4882a593Smuzhiyun enum iavf_state_t last_state;
314*4882a593Smuzhiyun unsigned long crit_section;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun struct delayed_work watchdog_task;
317*4882a593Smuzhiyun bool netdev_registered;
318*4882a593Smuzhiyun bool link_up;
319*4882a593Smuzhiyun enum virtchnl_link_speed link_speed;
320*4882a593Smuzhiyun /* This is only populated if the VIRTCHNL_VF_CAP_ADV_LINK_SPEED is set
321*4882a593Smuzhiyun * in vf_res->vf_cap_flags. Use ADV_LINK_SUPPORT macro to determine if
322*4882a593Smuzhiyun * this field is valid. This field should be used going forward and the
323*4882a593Smuzhiyun * enum virtchnl_link_speed above should be considered the legacy way of
324*4882a593Smuzhiyun * storing/communicating link speeds.
325*4882a593Smuzhiyun */
326*4882a593Smuzhiyun u32 link_speed_mbps;
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun enum virtchnl_ops current_op;
329*4882a593Smuzhiyun #define CLIENT_ALLOWED(_a) ((_a)->vf_res ? \
330*4882a593Smuzhiyun (_a)->vf_res->vf_cap_flags & \
331*4882a593Smuzhiyun VIRTCHNL_VF_OFFLOAD_IWARP : \
332*4882a593Smuzhiyun 0)
333*4882a593Smuzhiyun #define CLIENT_ENABLED(_a) ((_a)->cinst)
334*4882a593Smuzhiyun /* RSS by the PF should be preferred over RSS via other methods. */
335*4882a593Smuzhiyun #define RSS_PF(_a) ((_a)->vf_res->vf_cap_flags & \
336*4882a593Smuzhiyun VIRTCHNL_VF_OFFLOAD_RSS_PF)
337*4882a593Smuzhiyun #define RSS_AQ(_a) ((_a)->vf_res->vf_cap_flags & \
338*4882a593Smuzhiyun VIRTCHNL_VF_OFFLOAD_RSS_AQ)
339*4882a593Smuzhiyun #define RSS_REG(_a) (!((_a)->vf_res->vf_cap_flags & \
340*4882a593Smuzhiyun (VIRTCHNL_VF_OFFLOAD_RSS_AQ | \
341*4882a593Smuzhiyun VIRTCHNL_VF_OFFLOAD_RSS_PF)))
342*4882a593Smuzhiyun #define VLAN_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
343*4882a593Smuzhiyun VIRTCHNL_VF_OFFLOAD_VLAN)
344*4882a593Smuzhiyun #define ADV_LINK_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
345*4882a593Smuzhiyun VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
346*4882a593Smuzhiyun struct virtchnl_vf_resource *vf_res; /* incl. all VSIs */
347*4882a593Smuzhiyun struct virtchnl_vsi_resource *vsi_res; /* our LAN VSI */
348*4882a593Smuzhiyun struct virtchnl_version_info pf_version;
349*4882a593Smuzhiyun #define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
350*4882a593Smuzhiyun ((_a)->pf_version.minor == 1))
351*4882a593Smuzhiyun u16 msg_enable;
352*4882a593Smuzhiyun struct iavf_eth_stats current_stats;
353*4882a593Smuzhiyun struct iavf_vsi vsi;
354*4882a593Smuzhiyun u32 aq_wait_count;
355*4882a593Smuzhiyun /* RSS stuff */
356*4882a593Smuzhiyun u64 hena;
357*4882a593Smuzhiyun u16 rss_key_size;
358*4882a593Smuzhiyun u16 rss_lut_size;
359*4882a593Smuzhiyun u8 *rss_key;
360*4882a593Smuzhiyun u8 *rss_lut;
361*4882a593Smuzhiyun /* ADQ related members */
362*4882a593Smuzhiyun struct iavf_channel_config ch_config;
363*4882a593Smuzhiyun u8 num_tc;
364*4882a593Smuzhiyun struct list_head cloud_filter_list;
365*4882a593Smuzhiyun /* lock to protect access to the cloud filter list */
366*4882a593Smuzhiyun spinlock_t cloud_filter_list_lock;
367*4882a593Smuzhiyun u16 num_cloud_filters;
368*4882a593Smuzhiyun };
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /* Ethtool Private Flags */
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /* lan device, used by client interface */
374*4882a593Smuzhiyun struct iavf_device {
375*4882a593Smuzhiyun struct list_head list;
376*4882a593Smuzhiyun struct iavf_adapter *vf;
377*4882a593Smuzhiyun };
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /* needed by iavf_ethtool.c */
380*4882a593Smuzhiyun extern char iavf_driver_name[];
381*4882a593Smuzhiyun extern struct workqueue_struct *iavf_wq;
382*4882a593Smuzhiyun
iavf_change_state(struct iavf_adapter * adapter,enum iavf_state_t state)383*4882a593Smuzhiyun static inline void iavf_change_state(struct iavf_adapter *adapter,
384*4882a593Smuzhiyun enum iavf_state_t state)
385*4882a593Smuzhiyun {
386*4882a593Smuzhiyun if (adapter->state != state) {
387*4882a593Smuzhiyun adapter->last_state = adapter->state;
388*4882a593Smuzhiyun adapter->state = state;
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun int iavf_up(struct iavf_adapter *adapter);
393*4882a593Smuzhiyun void iavf_down(struct iavf_adapter *adapter);
394*4882a593Smuzhiyun int iavf_process_config(struct iavf_adapter *adapter);
395*4882a593Smuzhiyun void iavf_schedule_reset(struct iavf_adapter *adapter);
396*4882a593Smuzhiyun void iavf_reset(struct iavf_adapter *adapter);
397*4882a593Smuzhiyun void iavf_set_ethtool_ops(struct net_device *netdev);
398*4882a593Smuzhiyun void iavf_update_stats(struct iavf_adapter *adapter);
399*4882a593Smuzhiyun void iavf_reset_interrupt_capability(struct iavf_adapter *adapter);
400*4882a593Smuzhiyun int iavf_init_interrupt_scheme(struct iavf_adapter *adapter);
401*4882a593Smuzhiyun void iavf_irq_enable_queues(struct iavf_adapter *adapter, u32 mask);
402*4882a593Smuzhiyun void iavf_free_all_tx_resources(struct iavf_adapter *adapter);
403*4882a593Smuzhiyun void iavf_free_all_rx_resources(struct iavf_adapter *adapter);
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun void iavf_napi_add_all(struct iavf_adapter *adapter);
406*4882a593Smuzhiyun void iavf_napi_del_all(struct iavf_adapter *adapter);
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun int iavf_send_api_ver(struct iavf_adapter *adapter);
409*4882a593Smuzhiyun int iavf_verify_api_ver(struct iavf_adapter *adapter);
410*4882a593Smuzhiyun int iavf_send_vf_config_msg(struct iavf_adapter *adapter);
411*4882a593Smuzhiyun int iavf_get_vf_config(struct iavf_adapter *adapter);
412*4882a593Smuzhiyun void iavf_irq_enable(struct iavf_adapter *adapter, bool flush);
413*4882a593Smuzhiyun void iavf_configure_queues(struct iavf_adapter *adapter);
414*4882a593Smuzhiyun void iavf_deconfigure_queues(struct iavf_adapter *adapter);
415*4882a593Smuzhiyun void iavf_enable_queues(struct iavf_adapter *adapter);
416*4882a593Smuzhiyun void iavf_disable_queues(struct iavf_adapter *adapter);
417*4882a593Smuzhiyun void iavf_map_queues(struct iavf_adapter *adapter);
418*4882a593Smuzhiyun int iavf_request_queues(struct iavf_adapter *adapter, int num);
419*4882a593Smuzhiyun void iavf_add_ether_addrs(struct iavf_adapter *adapter);
420*4882a593Smuzhiyun void iavf_del_ether_addrs(struct iavf_adapter *adapter);
421*4882a593Smuzhiyun void iavf_add_vlans(struct iavf_adapter *adapter);
422*4882a593Smuzhiyun void iavf_del_vlans(struct iavf_adapter *adapter);
423*4882a593Smuzhiyun void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags);
424*4882a593Smuzhiyun void iavf_request_stats(struct iavf_adapter *adapter);
425*4882a593Smuzhiyun void iavf_request_reset(struct iavf_adapter *adapter);
426*4882a593Smuzhiyun void iavf_get_hena(struct iavf_adapter *adapter);
427*4882a593Smuzhiyun void iavf_set_hena(struct iavf_adapter *adapter);
428*4882a593Smuzhiyun void iavf_set_rss_key(struct iavf_adapter *adapter);
429*4882a593Smuzhiyun void iavf_set_rss_lut(struct iavf_adapter *adapter);
430*4882a593Smuzhiyun void iavf_enable_vlan_stripping(struct iavf_adapter *adapter);
431*4882a593Smuzhiyun void iavf_disable_vlan_stripping(struct iavf_adapter *adapter);
432*4882a593Smuzhiyun void iavf_virtchnl_completion(struct iavf_adapter *adapter,
433*4882a593Smuzhiyun enum virtchnl_ops v_opcode,
434*4882a593Smuzhiyun enum iavf_status v_retval, u8 *msg, u16 msglen);
435*4882a593Smuzhiyun int iavf_config_rss(struct iavf_adapter *adapter);
436*4882a593Smuzhiyun int iavf_lan_add_device(struct iavf_adapter *adapter);
437*4882a593Smuzhiyun int iavf_lan_del_device(struct iavf_adapter *adapter);
438*4882a593Smuzhiyun void iavf_client_subtask(struct iavf_adapter *adapter);
439*4882a593Smuzhiyun void iavf_notify_client_message(struct iavf_vsi *vsi, u8 *msg, u16 len);
440*4882a593Smuzhiyun void iavf_notify_client_l2_params(struct iavf_vsi *vsi);
441*4882a593Smuzhiyun void iavf_notify_client_open(struct iavf_vsi *vsi);
442*4882a593Smuzhiyun void iavf_notify_client_close(struct iavf_vsi *vsi, bool reset);
443*4882a593Smuzhiyun void iavf_enable_channels(struct iavf_adapter *adapter);
444*4882a593Smuzhiyun void iavf_disable_channels(struct iavf_adapter *adapter);
445*4882a593Smuzhiyun void iavf_add_cloud_filter(struct iavf_adapter *adapter);
446*4882a593Smuzhiyun void iavf_del_cloud_filter(struct iavf_adapter *adapter);
447*4882a593Smuzhiyun struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter,
448*4882a593Smuzhiyun const u8 *macaddr);
449*4882a593Smuzhiyun #endif /* _IAVF_H_ */
450