Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.13.7.
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*******************************************************************************
  3 *
  4 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  5 * Copyright(c) 2013 - 2016 Intel Corporation.
  6 *
  7 * This program is free software; you can redistribute it and/or modify it
  8 * under the terms and conditions of the GNU General Public License,
  9 * version 2, as published by the Free Software Foundation.
 10 *
 11 * This program is distributed in the hope it will be useful, but WITHOUT
 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 14 * more details.
 15 *
 16 * You should have received a copy of the GNU General Public License along
 17 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 18 *
 19 * The full GNU General Public License is included in this distribution in
 20 * the file called "COPYING".
 21 *
 22 * Contact Information:
 23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
 24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 25 *
 26 ******************************************************************************/
 27
 28#ifndef _I40EVF_H_
 29#define _I40EVF_H_
 30
 31#include <linux/module.h>
 32#include <linux/pci.h>
 33#include <linux/aer.h>
 34#include <linux/netdevice.h>
 35#include <linux/vmalloc.h>
 36#include <linux/interrupt.h>
 37#include <linux/ethtool.h>
 38#include <linux/if_vlan.h>
 39#include <linux/ip.h>
 40#include <linux/tcp.h>
 41#include <linux/sctp.h>
 42#include <linux/ipv6.h>
 43#include <linux/kernel.h>
 44#include <linux/bitops.h>
 45#include <linux/timer.h>
 46#include <linux/workqueue.h>
 47#include <linux/wait.h>
 48#include <linux/delay.h>
 49#include <linux/gfp.h>
 50#include <linux/skbuff.h>
 51#include <linux/dma-mapping.h>
 52#include <linux/etherdevice.h>
 53#include <linux/socket.h>
 54#include <linux/jiffies.h>
 55#include <net/ip6_checksum.h>
 56#include <net/pkt_cls.h>
 57#include <net/udp.h>
 58#include <net/tc_act/tc_gact.h>
 59#include <net/tc_act/tc_mirred.h>
 60
 61#include "i40e_type.h"
 62#include <linux/avf/virtchnl.h>
 63#include "i40e_txrx.h"
 64
 65#define DEFAULT_DEBUG_LEVEL_SHIFT 3
 66#define PFX "i40evf: "
 67
 68/* VSI state flags shared with common code */
 69enum i40evf_vsi_state_t {
 70	__I40E_VSI_DOWN,
 71	/* This must be last as it determines the size of the BITMAP */
 72	__I40E_VSI_STATE_SIZE__,
 73};
 74
 75/* dummy struct to make common code less painful */
 76struct i40e_vsi {
 77	struct i40evf_adapter *back;
 78	struct net_device *netdev;
 79	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
 80	u16 seid;
 81	u16 id;
 82	DECLARE_BITMAP(state, __I40E_VSI_STATE_SIZE__);
 83	int base_vector;
 84	u16 work_limit;
 85	u16 qs_handle;
 86	void *priv;     /* client driver data reference. */
 87};
 88
 89/* How many Rx Buffers do we bundle into one write to the hardware ? */
 90#define I40EVF_RX_BUFFER_WRITE	16	/* Must be power of 2 */
 91#define I40EVF_DEFAULT_TXD	512
 92#define I40EVF_DEFAULT_RXD	512
 93#define I40EVF_MAX_TXD		4096
 94#define I40EVF_MIN_TXD		64
 95#define I40EVF_MAX_RXD		4096
 96#define I40EVF_MIN_RXD		64
 97#define I40EVF_REQ_DESCRIPTOR_MULTIPLE	32
 98#define I40EVF_MAX_AQ_BUF_SIZE	4096
 99#define I40EVF_AQ_LEN		32
100#define I40EVF_AQ_MAX_ERR	20 /* times to try before resetting AQ */
101
102#define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
103
104#define I40E_RX_DESC(R, i) (&(((union i40e_32byte_rx_desc *)((R)->desc))[i]))
105#define I40E_TX_DESC(R, i) (&(((struct i40e_tx_desc *)((R)->desc))[i]))
106#define I40E_TX_CTXTDESC(R, i) \
107	(&(((struct i40e_tx_context_desc *)((R)->desc))[i]))
108#define MAX_QUEUES 16
109#define I40EVF_MAX_REQ_QUEUES 4
110
111#define I40EVF_HKEY_ARRAY_SIZE ((I40E_VFQF_HKEY_MAX_INDEX + 1) * 4)
112#define I40EVF_HLUT_ARRAY_SIZE ((I40E_VFQF_HLUT_MAX_INDEX + 1) * 4)
113#define I40EVF_MBPS_DIVISOR	125000 /* divisor to convert to Mbps */
114
115/* MAX_MSIX_Q_VECTORS of these are allocated,
116 * but we only use one per queue-specific vector.
117 */
118struct i40e_q_vector {
119	struct i40evf_adapter *adapter;
120	struct i40e_vsi *vsi;
121	struct napi_struct napi;
122	struct i40e_ring_container rx;
123	struct i40e_ring_container tx;
124	u32 ring_mask;
125	u8 itr_countdown;	/* when 0 should adjust adaptive ITR */
126	u8 num_ringpairs;	/* total number of ring pairs in vector */
127	u16 v_idx;		/* index in the vsi->q_vector array. */
128	u16 reg_idx;		/* register index of the interrupt */
129	char name[IFNAMSIZ + 15];
130	bool arm_wb_state;
131	cpumask_t affinity_mask;
132	struct irq_affinity_notify affinity_notify;
133};
134
135/* Helper macros to switch between ints/sec and what the register uses.
136 * And yes, it's the same math going both ways.  The lowest value
137 * supported by all of the i40e hardware is 8.
138 */
139#define EITR_INTS_PER_SEC_TO_REG(_eitr) \
140	((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
141#define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
142
143#define I40EVF_DESC_UNUSED(R) \
144	((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
145	(R)->next_to_clean - (R)->next_to_use - 1)
146
147#define I40EVF_RX_DESC_ADV(R, i)	\
148	(&(((union i40e_adv_rx_desc *)((R).desc))[i]))
149#define I40EVF_TX_DESC_ADV(R, i)	\
150	(&(((union i40e_adv_tx_desc *)((R).desc))[i]))
151#define I40EVF_TX_CTXTDESC_ADV(R, i)	\
152	(&(((struct i40e_adv_tx_context_desc *)((R).desc))[i]))
153
154#define OTHER_VECTOR 1
155#define NONQ_VECS (OTHER_VECTOR)
156
157#define MIN_MSIX_Q_VECTORS 1
158#define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NONQ_VECS)
159
160#define I40EVF_QUEUE_END_OF_LIST 0x7FF
161#define I40EVF_FREE_VECTOR 0x7FFF
162struct i40evf_mac_filter {
163	struct list_head list;
164	u8 macaddr[ETH_ALEN];
165	bool remove;		/* filter needs to be removed */
166	bool add;		/* filter needs to be added */
167};
168
169struct i40evf_vlan_filter {
170	struct list_head list;
171	u16 vlan;
172	bool remove;		/* filter needs to be removed */
173	bool add;		/* filter needs to be added */
174};
175
176#define I40EVF_MAX_TRAFFIC_CLASS	4
177/* State of traffic class creation */
178enum i40evf_tc_state_t {
179	__I40EVF_TC_INVALID, /* no traffic class, default state */
180	__I40EVF_TC_RUNNING, /* traffic classes have been created */
181};
182
183/* channel info */
184struct i40evf_channel_config {
185	struct virtchnl_channel_info ch_info[I40EVF_MAX_TRAFFIC_CLASS];
186	enum i40evf_tc_state_t state;
187	u8 total_qps;
188};
189
190/* State of cloud filter */
191enum i40evf_cloud_filter_state_t {
192	__I40EVF_CF_INVALID,	 /* cloud filter not added */
193	__I40EVF_CF_ADD_PENDING, /* cloud filter pending add by the PF */
194	__I40EVF_CF_DEL_PENDING, /* cloud filter pending del by the PF */
195	__I40EVF_CF_ACTIVE,	 /* cloud filter is active */
196};
197
198/* Driver state. The order of these is important! */
199enum i40evf_state_t {
200	__I40EVF_STARTUP,		/* driver loaded, probe complete */
201	__I40EVF_REMOVE,		/* driver is being unloaded */
202	__I40EVF_INIT_VERSION_CHECK,	/* aq msg sent, awaiting reply */
203	__I40EVF_INIT_GET_RESOURCES,	/* aq msg sent, awaiting reply */
204	__I40EVF_INIT_SW,		/* got resources, setting up structs */
205	__I40EVF_RESETTING,		/* in reset */
206	/* Below here, watchdog is running */
207	__I40EVF_DOWN,			/* ready, can be opened */
208	__I40EVF_DOWN_PENDING,		/* descending, waiting for watchdog */
209	__I40EVF_TESTING,		/* in ethtool self-test */
210	__I40EVF_RUNNING,		/* opened, working */
211};
212
213enum i40evf_critical_section_t {
214	__I40EVF_IN_CRITICAL_TASK,	/* cannot be interrupted */
215	__I40EVF_IN_CLIENT_TASK,
216	__I40EVF_IN_REMOVE_TASK,	/* device being removed */
217};
218
219#define I40EVF_CLOUD_FIELD_OMAC		0x01
220#define I40EVF_CLOUD_FIELD_IMAC		0x02
221#define I40EVF_CLOUD_FIELD_IVLAN	0x04
222#define I40EVF_CLOUD_FIELD_TEN_ID	0x08
223#define I40EVF_CLOUD_FIELD_IIP		0x10
224
225#define I40EVF_CF_FLAGS_OMAC	I40EVF_CLOUD_FIELD_OMAC
226#define I40EVF_CF_FLAGS_IMAC	I40EVF_CLOUD_FIELD_IMAC
227#define I40EVF_CF_FLAGS_IMAC_IVLAN	(I40EVF_CLOUD_FIELD_IMAC |\
228					 I40EVF_CLOUD_FIELD_IVLAN)
229#define I40EVF_CF_FLAGS_IMAC_TEN_ID	(I40EVF_CLOUD_FIELD_IMAC |\
230					 I40EVF_CLOUD_FIELD_TEN_ID)
231#define I40EVF_CF_FLAGS_OMAC_TEN_ID_IMAC	(I40EVF_CLOUD_FIELD_OMAC |\
232						 I40EVF_CLOUD_FIELD_IMAC |\
233						 I40EVF_CLOUD_FIELD_TEN_ID)
234#define I40EVF_CF_FLAGS_IMAC_IVLAN_TEN_ID	(I40EVF_CLOUD_FIELD_IMAC |\
235						 I40EVF_CLOUD_FIELD_IVLAN |\
236						 I40EVF_CLOUD_FIELD_TEN_ID)
237#define I40EVF_CF_FLAGS_IIP	I40E_CLOUD_FIELD_IIP
238
239/* bookkeeping of cloud filters */
240struct i40evf_cloud_filter {
241	enum i40evf_cloud_filter_state_t state;
242	struct list_head list;
243	struct virtchnl_filter f;
244	unsigned long cookie;
245	bool del;		/* filter needs to be deleted */
246	bool add;		/* filter needs to be added */
247};
248
249/* board specific private data structure */
250struct i40evf_adapter {
251	struct timer_list watchdog_timer;
252	struct work_struct reset_task;
253	struct work_struct adminq_task;
254	struct delayed_work client_task;
255	struct delayed_work init_task;
256	wait_queue_head_t down_waitqueue;
257	struct i40e_q_vector *q_vectors;
258	struct list_head vlan_filter_list;
259	struct list_head mac_filter_list;
260	/* Lock to protect accesses to MAC and VLAN lists */
261	spinlock_t mac_vlan_list_lock;
262	char misc_vector_name[IFNAMSIZ + 9];
263	int num_active_queues;
264	int num_req_queues;
265
266	/* TX */
267	struct i40e_ring *tx_rings;
268	u32 tx_timeout_count;
269	u32 tx_desc_count;
270
271	/* RX */
272	struct i40e_ring *rx_rings;
273	u64 hw_csum_rx_error;
274	u32 rx_desc_count;
275	int num_msix_vectors;
276	int num_iwarp_msix;
277	int iwarp_base_vector;
278	u32 client_pending;
279	struct i40e_client_instance *cinst;
280	struct msix_entry *msix_entries;
281
282	u32 flags;
283#define I40EVF_FLAG_RX_CSUM_ENABLED		BIT(0)
284#define I40EVF_FLAG_PF_COMMS_FAILED		BIT(3)
285#define I40EVF_FLAG_RESET_PENDING		BIT(4)
286#define I40EVF_FLAG_RESET_NEEDED		BIT(5)
287#define I40EVF_FLAG_WB_ON_ITR_CAPABLE		BIT(6)
288#define I40EVF_FLAG_ADDR_SET_BY_PF		BIT(8)
289#define I40EVF_FLAG_SERVICE_CLIENT_REQUESTED	BIT(9)
290#define I40EVF_FLAG_CLIENT_NEEDS_OPEN		BIT(10)
291#define I40EVF_FLAG_CLIENT_NEEDS_CLOSE		BIT(11)
292#define I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS	BIT(12)
293#define I40EVF_FLAG_PROMISC_ON			BIT(13)
294#define I40EVF_FLAG_ALLMULTI_ON			BIT(14)
295#define I40EVF_FLAG_LEGACY_RX			BIT(15)
296#define I40EVF_FLAG_REINIT_ITR_NEEDED		BIT(16)
297#define I40EVF_FLAG_QUEUES_DISABLED		BIT(17)
298/* duplicates for common code */
299#define I40E_FLAG_DCB_ENABLED			0
300#define I40E_FLAG_RX_CSUM_ENABLED		I40EVF_FLAG_RX_CSUM_ENABLED
301#define I40E_FLAG_LEGACY_RX			I40EVF_FLAG_LEGACY_RX
302	/* flags for admin queue service task */
303	u32 aq_required;
304#define I40EVF_FLAG_AQ_ENABLE_QUEUES		BIT(0)
305#define I40EVF_FLAG_AQ_DISABLE_QUEUES		BIT(1)
306#define I40EVF_FLAG_AQ_ADD_MAC_FILTER		BIT(2)
307#define I40EVF_FLAG_AQ_ADD_VLAN_FILTER		BIT(3)
308#define I40EVF_FLAG_AQ_DEL_MAC_FILTER		BIT(4)
309#define I40EVF_FLAG_AQ_DEL_VLAN_FILTER		BIT(5)
310#define I40EVF_FLAG_AQ_CONFIGURE_QUEUES		BIT(6)
311#define I40EVF_FLAG_AQ_MAP_VECTORS		BIT(7)
312#define I40EVF_FLAG_AQ_HANDLE_RESET		BIT(8)
313#define I40EVF_FLAG_AQ_CONFIGURE_RSS		BIT(9) /* direct AQ config */
314#define I40EVF_FLAG_AQ_GET_CONFIG		BIT(10)
315/* Newer style, RSS done by the PF so we can ignore hardware vagaries. */
316#define I40EVF_FLAG_AQ_GET_HENA			BIT(11)
317#define I40EVF_FLAG_AQ_SET_HENA			BIT(12)
318#define I40EVF_FLAG_AQ_SET_RSS_KEY		BIT(13)
319#define I40EVF_FLAG_AQ_SET_RSS_LUT		BIT(14)
320#define I40EVF_FLAG_AQ_REQUEST_PROMISC		BIT(15)
321#define I40EVF_FLAG_AQ_RELEASE_PROMISC		BIT(16)
322#define I40EVF_FLAG_AQ_REQUEST_ALLMULTI		BIT(17)
323#define I40EVF_FLAG_AQ_RELEASE_ALLMULTI		BIT(18)
324#define I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING	BIT(19)
325#define I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING	BIT(20)
326#define I40EVF_FLAG_AQ_ENABLE_CHANNELS		BIT(21)
327#define I40EVF_FLAG_AQ_DISABLE_CHANNELS		BIT(22)
328#define I40EVF_FLAG_AQ_ADD_CLOUD_FILTER		BIT(23)
329#define I40EVF_FLAG_AQ_DEL_CLOUD_FILTER		BIT(24)
330
331	/* OS defined structs */
332	struct net_device *netdev;
333	struct pci_dev *pdev;
334
335	struct i40e_hw hw; /* defined in i40e_type.h */
336
337	enum i40evf_state_t state;
338	unsigned long crit_section;
339
340	struct work_struct watchdog_task;
341	bool netdev_registered;
342	bool link_up;
343	enum virtchnl_link_speed link_speed;
344	enum virtchnl_ops current_op;
345#define CLIENT_ALLOWED(_a) ((_a)->vf_res ? \
346			    (_a)->vf_res->vf_cap_flags & \
347				VIRTCHNL_VF_OFFLOAD_IWARP : \
348			    0)
349#define CLIENT_ENABLED(_a) ((_a)->cinst)
350/* RSS by the PF should be preferred over RSS via other methods. */
351#define RSS_PF(_a) ((_a)->vf_res->vf_cap_flags & \
352		    VIRTCHNL_VF_OFFLOAD_RSS_PF)
353#define RSS_AQ(_a) ((_a)->vf_res->vf_cap_flags & \
354		    VIRTCHNL_VF_OFFLOAD_RSS_AQ)
355#define RSS_REG(_a) (!((_a)->vf_res->vf_cap_flags & \
356		       (VIRTCHNL_VF_OFFLOAD_RSS_AQ | \
357			VIRTCHNL_VF_OFFLOAD_RSS_PF)))
358#define VLAN_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
359			  VIRTCHNL_VF_OFFLOAD_VLAN)
360	struct virtchnl_vf_resource *vf_res; /* incl. all VSIs */
361	struct virtchnl_vsi_resource *vsi_res; /* our LAN VSI */
362	struct virtchnl_version_info pf_version;
363#define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
364		       ((_a)->pf_version.minor == 1))
365	u16 msg_enable;
366	struct i40e_eth_stats current_stats;
367	struct i40e_vsi vsi;
368	u32 aq_wait_count;
369	/* RSS stuff */
370	u64 hena;
371	u16 rss_key_size;
372	u16 rss_lut_size;
373	u8 *rss_key;
374	u8 *rss_lut;
375	/* ADQ related members */
376	struct i40evf_channel_config ch_config;
377	u8 num_tc;
378	struct list_head cloud_filter_list;
379	/* lock to protest access to the cloud filter list */
380	spinlock_t cloud_filter_list_lock;
381	u16 num_cloud_filters;
382};
383
384
385/* Ethtool Private Flags */
386
387/* lan device */
388struct i40e_device {
389	struct list_head list;
390	struct i40evf_adapter *vf;
391};
392
393/* needed by i40evf_ethtool.c */
394extern char i40evf_driver_name[];
395extern const char i40evf_driver_version[];
396
397int i40evf_up(struct i40evf_adapter *adapter);
398void i40evf_down(struct i40evf_adapter *adapter);
399int i40evf_process_config(struct i40evf_adapter *adapter);
400void i40evf_schedule_reset(struct i40evf_adapter *adapter);
401void i40evf_reset(struct i40evf_adapter *adapter);
402void i40evf_set_ethtool_ops(struct net_device *netdev);
403void i40evf_update_stats(struct i40evf_adapter *adapter);
404void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter);
405int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter);
406void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask);
407void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter);
408void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter);
409
410void i40e_napi_add_all(struct i40evf_adapter *adapter);
411void i40e_napi_del_all(struct i40evf_adapter *adapter);
412
413int i40evf_send_api_ver(struct i40evf_adapter *adapter);
414int i40evf_verify_api_ver(struct i40evf_adapter *adapter);
415int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter);
416int i40evf_get_vf_config(struct i40evf_adapter *adapter);
417void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush);
418void i40evf_configure_queues(struct i40evf_adapter *adapter);
419void i40evf_deconfigure_queues(struct i40evf_adapter *adapter);
420void i40evf_enable_queues(struct i40evf_adapter *adapter);
421void i40evf_disable_queues(struct i40evf_adapter *adapter);
422void i40evf_map_queues(struct i40evf_adapter *adapter);
423int i40evf_request_queues(struct i40evf_adapter *adapter, int num);
424void i40evf_add_ether_addrs(struct i40evf_adapter *adapter);
425void i40evf_del_ether_addrs(struct i40evf_adapter *adapter);
426void i40evf_add_vlans(struct i40evf_adapter *adapter);
427void i40evf_del_vlans(struct i40evf_adapter *adapter);
428void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags);
429void i40evf_request_stats(struct i40evf_adapter *adapter);
430void i40evf_request_reset(struct i40evf_adapter *adapter);
431void i40evf_get_hena(struct i40evf_adapter *adapter);
432void i40evf_set_hena(struct i40evf_adapter *adapter);
433void i40evf_set_rss_key(struct i40evf_adapter *adapter);
434void i40evf_set_rss_lut(struct i40evf_adapter *adapter);
435void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter);
436void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter);
437void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
438				enum virtchnl_ops v_opcode,
439				i40e_status v_retval, u8 *msg, u16 msglen);
440int i40evf_config_rss(struct i40evf_adapter *adapter);
441int i40evf_lan_add_device(struct i40evf_adapter *adapter);
442int i40evf_lan_del_device(struct i40evf_adapter *adapter);
443void i40evf_client_subtask(struct i40evf_adapter *adapter);
444void i40evf_notify_client_message(struct i40e_vsi *vsi, u8 *msg, u16 len);
445void i40evf_notify_client_l2_params(struct i40e_vsi *vsi);
446void i40evf_notify_client_open(struct i40e_vsi *vsi);
447void i40evf_notify_client_close(struct i40e_vsi *vsi, bool reset);
448void i40evf_enable_channels(struct i40evf_adapter *adapter);
449void i40evf_disable_channels(struct i40evf_adapter *adapter);
450void i40evf_add_cloud_filter(struct i40evf_adapter *adapter);
451void i40evf_del_cloud_filter(struct i40evf_adapter *adapter);
452#endif /* _I40EVF_H_ */