xref: /dpdk/drivers/net/iavf/iavf_ethdev.c (revision 5bd47901)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #include <sys/queue.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12 #include <inttypes.h>
13 #include <rte_byteorder.h>
14 #include <rte_common.h>
15 
16 #include <rte_interrupts.h>
17 #include <rte_debug.h>
18 #include <rte_pci.h>
19 #include <rte_atomic.h>
20 #include <rte_eal.h>
21 #include <rte_ether.h>
22 #include <rte_ethdev_driver.h>
23 #include <rte_ethdev_pci.h>
24 #include <rte_malloc.h>
25 #include <rte_memzone.h>
26 #include <rte_dev.h>
27 
28 #include "iavf.h"
29 #include "iavf_rxtx.h"
30 #include "iavf_generic_flow.h"
31 
32 static int iavf_dev_configure(struct rte_eth_dev *dev);
33 static int iavf_dev_start(struct rte_eth_dev *dev);
34 static int iavf_dev_stop(struct rte_eth_dev *dev);
35 static int iavf_dev_close(struct rte_eth_dev *dev);
36 static int iavf_dev_reset(struct rte_eth_dev *dev);
37 static int iavf_dev_info_get(struct rte_eth_dev *dev,
38 			     struct rte_eth_dev_info *dev_info);
39 static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev);
40 static int iavf_dev_stats_get(struct rte_eth_dev *dev,
41 			     struct rte_eth_stats *stats);
42 static int iavf_dev_stats_reset(struct rte_eth_dev *dev);
43 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
44 				 struct rte_eth_xstat *xstats, unsigned int n);
45 static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev,
46 				       struct rte_eth_xstat_name *xstats_names,
47 				       unsigned int limit);
48 static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
49 static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
50 static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
51 static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
52 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
53 				struct rte_ether_addr *addr,
54 				uint32_t index,
55 				uint32_t pool);
56 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
57 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
58 				   uint16_t vlan_id, int on);
59 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
60 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
61 				   struct rte_eth_rss_reta_entry64 *reta_conf,
62 				   uint16_t reta_size);
63 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
64 				  struct rte_eth_rss_reta_entry64 *reta_conf,
65 				  uint16_t reta_size);
66 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
67 				   struct rte_eth_rss_conf *rss_conf);
68 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
69 				     struct rte_eth_rss_conf *rss_conf);
70 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
71 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
72 					 struct rte_ether_addr *mac_addr);
73 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
74 					uint16_t queue_id);
75 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
76 					 uint16_t queue_id);
77 static int iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
78 		     enum rte_filter_type filter_type,
79 		     enum rte_filter_op filter_op,
80 		     void *arg);
81 static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
82 			struct rte_ether_addr *mc_addrs,
83 			uint32_t mc_addrs_num);
84 
85 static const struct rte_pci_id pci_id_iavf_map[] = {
86 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
87 	{ .vendor_id = 0, /* sentinel */ },
88 };
89 
90 struct rte_iavf_xstats_name_off {
91 	char name[RTE_ETH_XSTATS_NAME_SIZE];
92 	unsigned int offset;
93 };
94 
95 static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = {
96 	{"rx_bytes", offsetof(struct iavf_eth_stats, rx_bytes)},
97 	{"rx_unicast_packets", offsetof(struct iavf_eth_stats, rx_unicast)},
98 	{"rx_multicast_packets", offsetof(struct iavf_eth_stats, rx_multicast)},
99 	{"rx_broadcast_packets", offsetof(struct iavf_eth_stats, rx_broadcast)},
100 	{"rx_dropped_packets", offsetof(struct iavf_eth_stats, rx_discards)},
101 	{"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats,
102 		rx_unknown_protocol)},
103 	{"tx_bytes", offsetof(struct iavf_eth_stats, tx_bytes)},
104 	{"tx_unicast_packets", offsetof(struct iavf_eth_stats, tx_unicast)},
105 	{"tx_multicast_packets", offsetof(struct iavf_eth_stats, tx_multicast)},
106 	{"tx_broadcast_packets", offsetof(struct iavf_eth_stats, tx_broadcast)},
107 	{"tx_dropped_packets", offsetof(struct iavf_eth_stats, tx_discards)},
108 	{"tx_error_packets", offsetof(struct iavf_eth_stats, tx_errors)},
109 };
110 
111 #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
112 		sizeof(rte_iavf_stats_strings[0]))
113 
114 static const struct eth_dev_ops iavf_eth_dev_ops = {
115 	.dev_configure              = iavf_dev_configure,
116 	.dev_start                  = iavf_dev_start,
117 	.dev_stop                   = iavf_dev_stop,
118 	.dev_close                  = iavf_dev_close,
119 	.dev_reset                  = iavf_dev_reset,
120 	.dev_infos_get              = iavf_dev_info_get,
121 	.dev_supported_ptypes_get   = iavf_dev_supported_ptypes_get,
122 	.link_update                = iavf_dev_link_update,
123 	.stats_get                  = iavf_dev_stats_get,
124 	.stats_reset                = iavf_dev_stats_reset,
125 	.xstats_get                 = iavf_dev_xstats_get,
126 	.xstats_get_names           = iavf_dev_xstats_get_names,
127 	.xstats_reset               = iavf_dev_stats_reset,
128 	.promiscuous_enable         = iavf_dev_promiscuous_enable,
129 	.promiscuous_disable        = iavf_dev_promiscuous_disable,
130 	.allmulticast_enable        = iavf_dev_allmulticast_enable,
131 	.allmulticast_disable       = iavf_dev_allmulticast_disable,
132 	.mac_addr_add               = iavf_dev_add_mac_addr,
133 	.mac_addr_remove            = iavf_dev_del_mac_addr,
134 	.set_mc_addr_list			= iavf_set_mc_addr_list,
135 	.vlan_filter_set            = iavf_dev_vlan_filter_set,
136 	.vlan_offload_set           = iavf_dev_vlan_offload_set,
137 	.rx_queue_start             = iavf_dev_rx_queue_start,
138 	.rx_queue_stop              = iavf_dev_rx_queue_stop,
139 	.tx_queue_start             = iavf_dev_tx_queue_start,
140 	.tx_queue_stop              = iavf_dev_tx_queue_stop,
141 	.rx_queue_setup             = iavf_dev_rx_queue_setup,
142 	.rx_queue_release           = iavf_dev_rx_queue_release,
143 	.tx_queue_setup             = iavf_dev_tx_queue_setup,
144 	.tx_queue_release           = iavf_dev_tx_queue_release,
145 	.mac_addr_set               = iavf_dev_set_default_mac_addr,
146 	.reta_update                = iavf_dev_rss_reta_update,
147 	.reta_query                 = iavf_dev_rss_reta_query,
148 	.rss_hash_update            = iavf_dev_rss_hash_update,
149 	.rss_hash_conf_get          = iavf_dev_rss_hash_conf_get,
150 	.rxq_info_get               = iavf_dev_rxq_info_get,
151 	.txq_info_get               = iavf_dev_txq_info_get,
152 	.mtu_set                    = iavf_dev_mtu_set,
153 	.rx_queue_intr_enable       = iavf_dev_rx_queue_intr_enable,
154 	.rx_queue_intr_disable      = iavf_dev_rx_queue_intr_disable,
155 	.filter_ctrl                = iavf_dev_filter_ctrl,
156 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
157 };
158 
159 static int
160 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
161 			struct rte_ether_addr *mc_addrs,
162 			uint32_t mc_addrs_num)
163 {
164 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
165 	struct iavf_adapter *adapter =
166 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
167 	int err;
168 
169 	/* flush previous addresses */
170 	err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
171 					false);
172 	if (err)
173 		return err;
174 
175 	vf->mc_addrs_num = 0;
176 
177 	/* add new ones */
178 	err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
179 	if (err)
180 		return err;
181 
182 	vf->mc_addrs_num = mc_addrs_num;
183 	memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
184 
185 	return 0;
186 }
187 
188 static int
189 iavf_init_rss(struct iavf_adapter *adapter)
190 {
191 	struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
192 	struct rte_eth_rss_conf *rss_conf;
193 	uint16_t i, j, nb_q;
194 	int ret;
195 
196 	rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
197 	nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
198 		       IAVF_MAX_NUM_QUEUES);
199 
200 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
201 		PMD_DRV_LOG(DEBUG, "RSS is not supported");
202 		return -ENOTSUP;
203 	}
204 	if (adapter->eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
205 		PMD_DRV_LOG(WARNING, "RSS is enabled by PF by default");
206 		/* set all lut items to default queue */
207 		for (i = 0; i < vf->vf_res->rss_lut_size; i++)
208 			vf->rss_lut[i] = 0;
209 		ret = iavf_configure_rss_lut(adapter);
210 		return ret;
211 	}
212 
213 	/* In IAVF, RSS enablement is set by PF driver. It is not supported
214 	 * to set based on rss_conf->rss_hf.
215 	 */
216 
217 	/* configure RSS key */
218 	if (!rss_conf->rss_key) {
219 		/* Calculate the default hash key */
220 		for (i = 0; i <= vf->vf_res->rss_key_size; i++)
221 			vf->rss_key[i] = (uint8_t)rte_rand();
222 	} else
223 		rte_memcpy(vf->rss_key, rss_conf->rss_key,
224 			   RTE_MIN(rss_conf->rss_key_len,
225 				   vf->vf_res->rss_key_size));
226 
227 	/* init RSS LUT table */
228 	for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
229 		if (j >= nb_q)
230 			j = 0;
231 		vf->rss_lut[i] = j;
232 	}
233 	/* send virtchnnl ops to configure rss*/
234 	ret = iavf_configure_rss_lut(adapter);
235 	if (ret)
236 		return ret;
237 	ret = iavf_configure_rss_key(adapter);
238 	if (ret)
239 		return ret;
240 
241 	return 0;
242 }
243 
244 static int
245 iavf_dev_configure(struct rte_eth_dev *dev)
246 {
247 	struct iavf_adapter *ad =
248 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
249 	struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(ad);
250 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
251 
252 	ad->rx_bulk_alloc_allowed = true;
253 	/* Initialize to TRUE. If any of Rx queues doesn't meet the
254 	 * vector Rx/Tx preconditions, it will be reset.
255 	 */
256 	ad->rx_vec_allowed = true;
257 	ad->tx_vec_allowed = true;
258 
259 	if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
260 		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
261 
262 	/* Vlan stripping setting */
263 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
264 		if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
265 			iavf_enable_vlan_strip(ad);
266 		else
267 			iavf_disable_vlan_strip(ad);
268 	}
269 
270 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
271 		if (iavf_init_rss(ad) != 0) {
272 			PMD_DRV_LOG(ERR, "configure rss failed");
273 			return -1;
274 		}
275 	}
276 	return 0;
277 }
278 
279 static int
280 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
281 {
282 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
283 	struct rte_eth_dev_data *dev_data = dev->data;
284 	uint16_t buf_size, max_pkt_len, len;
285 
286 	buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
287 
288 	/* Calculate the maximum packet length allowed */
289 	len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
290 	max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
291 
292 	/* Check if the jumbo frame and maximum packet length are set
293 	 * correctly.
294 	 */
295 	if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
296 		if (max_pkt_len <= RTE_ETHER_MAX_LEN ||
297 		    max_pkt_len > IAVF_FRAME_SIZE_MAX) {
298 			PMD_DRV_LOG(ERR, "maximum packet length must be "
299 				    "larger than %u and smaller than %u, "
300 				    "as jumbo frame is enabled",
301 				    (uint32_t)RTE_ETHER_MAX_LEN,
302 				    (uint32_t)IAVF_FRAME_SIZE_MAX);
303 			return -EINVAL;
304 		}
305 	} else {
306 		if (max_pkt_len < RTE_ETHER_MIN_LEN ||
307 		    max_pkt_len > RTE_ETHER_MAX_LEN) {
308 			PMD_DRV_LOG(ERR, "maximum packet length must be "
309 				    "larger than %u and smaller than %u, "
310 				    "as jumbo frame is disabled",
311 				    (uint32_t)RTE_ETHER_MIN_LEN,
312 				    (uint32_t)RTE_ETHER_MAX_LEN);
313 			return -EINVAL;
314 		}
315 	}
316 
317 	rxq->max_pkt_len = max_pkt_len;
318 	if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
319 	    rxq->max_pkt_len > buf_size) {
320 		dev_data->scattered_rx = 1;
321 	}
322 	IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
323 	IAVF_WRITE_FLUSH(hw);
324 
325 	return 0;
326 }
327 
328 static int
329 iavf_init_queues(struct rte_eth_dev *dev)
330 {
331 	struct iavf_rx_queue **rxq =
332 		(struct iavf_rx_queue **)dev->data->rx_queues;
333 	int i, ret = IAVF_SUCCESS;
334 
335 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
336 		if (!rxq[i] || !rxq[i]->q_set)
337 			continue;
338 		ret = iavf_init_rxq(dev, rxq[i]);
339 		if (ret != IAVF_SUCCESS)
340 			break;
341 	}
342 	/* set rx/tx function to vector/scatter/single-segment
343 	 * according to parameters
344 	 */
345 	iavf_set_rx_function(dev);
346 	iavf_set_tx_function(dev);
347 
348 	return ret;
349 }
350 
351 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
352 				     struct rte_intr_handle *intr_handle)
353 {
354 	struct iavf_adapter *adapter =
355 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
356 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
357 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
358 	uint16_t interval, i;
359 	int vec;
360 
361 	if (rte_intr_cap_multiple(intr_handle) &&
362 	    dev->data->dev_conf.intr_conf.rxq) {
363 		if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
364 			return -1;
365 	}
366 
367 	if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
368 		intr_handle->intr_vec =
369 			rte_zmalloc("intr_vec",
370 				    dev->data->nb_rx_queues * sizeof(int), 0);
371 		if (!intr_handle->intr_vec) {
372 			PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
373 				    dev->data->nb_rx_queues);
374 			return -1;
375 		}
376 	}
377 
378 	if (!dev->data->dev_conf.intr_conf.rxq ||
379 	    !rte_intr_dp_is_en(intr_handle)) {
380 		/* Rx interrupt disabled, Map interrupt only for writeback */
381 		vf->nb_msix = 1;
382 		if (vf->vf_res->vf_cap_flags &
383 		    VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
384 			/* If WB_ON_ITR supports, enable it */
385 			vf->msix_base = IAVF_RX_VEC_START;
386 			IAVF_WRITE_REG(hw,
387 				       IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
388 				       IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK |
389 				       IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
390 		} else {
391 			/* If no WB_ON_ITR offload flags, need to set
392 			 * interrupt for descriptor write back.
393 			 */
394 			vf->msix_base = IAVF_MISC_VEC_ID;
395 
396 			/* set ITR to max */
397 			interval = iavf_calc_itr_interval(
398 					IAVF_QUEUE_ITR_INTERVAL_MAX);
399 			IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
400 				       IAVF_VFINT_DYN_CTL01_INTENA_MASK |
401 				       (IAVF_ITR_INDEX_DEFAULT <<
402 					IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
403 				       (interval <<
404 					IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
405 		}
406 		IAVF_WRITE_FLUSH(hw);
407 		/* map all queues to the same interrupt */
408 		for (i = 0; i < dev->data->nb_rx_queues; i++)
409 			vf->rxq_map[vf->msix_base] |= 1 << i;
410 	} else {
411 		if (!rte_intr_allow_others(intr_handle)) {
412 			vf->nb_msix = 1;
413 			vf->msix_base = IAVF_MISC_VEC_ID;
414 			for (i = 0; i < dev->data->nb_rx_queues; i++) {
415 				vf->rxq_map[vf->msix_base] |= 1 << i;
416 				intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
417 			}
418 			PMD_DRV_LOG(DEBUG,
419 				    "vector %u are mapping to all Rx queues",
420 				    vf->msix_base);
421 		} else {
422 			/* If Rx interrupt is reuquired, and we can use
423 			 * multi interrupts, then the vec is from 1
424 			 */
425 			vf->nb_msix = RTE_MIN(vf->vf_res->max_vectors,
426 					      intr_handle->nb_efd);
427 			vf->msix_base = IAVF_RX_VEC_START;
428 			vec = IAVF_RX_VEC_START;
429 			for (i = 0; i < dev->data->nb_rx_queues; i++) {
430 				vf->rxq_map[vec] |= 1 << i;
431 				intr_handle->intr_vec[i] = vec++;
432 				if (vec >= vf->nb_msix)
433 					vec = IAVF_RX_VEC_START;
434 			}
435 			PMD_DRV_LOG(DEBUG,
436 				    "%u vectors are mapping to %u Rx queues",
437 				    vf->nb_msix, dev->data->nb_rx_queues);
438 		}
439 	}
440 
441 	if (iavf_config_irq_map(adapter)) {
442 		PMD_DRV_LOG(ERR, "config interrupt mapping failed");
443 		return -1;
444 	}
445 	return 0;
446 }
447 
448 static int
449 iavf_start_queues(struct rte_eth_dev *dev)
450 {
451 	struct iavf_rx_queue *rxq;
452 	struct iavf_tx_queue *txq;
453 	int i;
454 
455 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
456 		txq = dev->data->tx_queues[i];
457 		if (txq->tx_deferred_start)
458 			continue;
459 		if (iavf_dev_tx_queue_start(dev, i) != 0) {
460 			PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
461 			return -1;
462 		}
463 	}
464 
465 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
466 		rxq = dev->data->rx_queues[i];
467 		if (rxq->rx_deferred_start)
468 			continue;
469 		if (iavf_dev_rx_queue_start(dev, i) != 0) {
470 			PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
471 			return -1;
472 		}
473 	}
474 
475 	return 0;
476 }
477 
478 static int
479 iavf_dev_start(struct rte_eth_dev *dev)
480 {
481 	struct iavf_adapter *adapter =
482 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
483 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
484 	struct rte_intr_handle *intr_handle = dev->intr_handle;
485 
486 	PMD_INIT_FUNC_TRACE();
487 
488 	adapter->stopped = 0;
489 
490 	vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
491 	vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
492 				      dev->data->nb_tx_queues);
493 
494 	if (iavf_init_queues(dev) != 0) {
495 		PMD_DRV_LOG(ERR, "failed to do Queue init");
496 		return -1;
497 	}
498 
499 	if (iavf_configure_queues(adapter) != 0) {
500 		PMD_DRV_LOG(ERR, "configure queues failed");
501 		goto err_queue;
502 	}
503 
504 	if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
505 		PMD_DRV_LOG(ERR, "configure irq failed");
506 		goto err_queue;
507 	}
508 	/* re-enable intr again, because efd assign may change */
509 	if (dev->data->dev_conf.intr_conf.rxq != 0) {
510 		rte_intr_disable(intr_handle);
511 		rte_intr_enable(intr_handle);
512 	}
513 
514 	/* Set all mac addrs */
515 	iavf_add_del_all_mac_addr(adapter, true);
516 
517 	/* Set all multicast addresses */
518 	iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
519 				  true);
520 
521 	if (iavf_start_queues(dev) != 0) {
522 		PMD_DRV_LOG(ERR, "enable queues failed");
523 		goto err_mac;
524 	}
525 
526 	return 0;
527 
528 err_mac:
529 	iavf_add_del_all_mac_addr(adapter, false);
530 err_queue:
531 	return -1;
532 }
533 
534 static int
535 iavf_dev_stop(struct rte_eth_dev *dev)
536 {
537 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
538 	struct iavf_adapter *adapter =
539 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
540 	struct rte_intr_handle *intr_handle = dev->intr_handle;
541 
542 	PMD_INIT_FUNC_TRACE();
543 
544 	if (adapter->stopped == 1)
545 		return 0;
546 
547 	iavf_stop_queues(dev);
548 
549 	/* Disable the interrupt for Rx */
550 	rte_intr_efd_disable(intr_handle);
551 	/* Rx interrupt vector mapping free */
552 	if (intr_handle->intr_vec) {
553 		rte_free(intr_handle->intr_vec);
554 		intr_handle->intr_vec = NULL;
555 	}
556 
557 	/* remove all mac addrs */
558 	iavf_add_del_all_mac_addr(adapter, false);
559 
560 	/* remove all multicast addresses */
561 	iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
562 				  false);
563 
564 	adapter->stopped = 1;
565 	dev->data->dev_started = 0;
566 
567 	return 0;
568 }
569 
570 static int
571 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
572 {
573 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
574 
575 	dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
576 	dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
577 	dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
578 	dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
579 	dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
580 	dev_info->min_mtu = RTE_ETHER_MIN_MTU;
581 	dev_info->hash_key_size = vf->vf_res->rss_key_size;
582 	dev_info->reta_size = vf->vf_res->rss_lut_size;
583 	dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
584 	dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
585 	dev_info->rx_offload_capa =
586 		DEV_RX_OFFLOAD_VLAN_STRIP |
587 		DEV_RX_OFFLOAD_QINQ_STRIP |
588 		DEV_RX_OFFLOAD_IPV4_CKSUM |
589 		DEV_RX_OFFLOAD_UDP_CKSUM |
590 		DEV_RX_OFFLOAD_TCP_CKSUM |
591 		DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
592 		DEV_RX_OFFLOAD_SCATTER |
593 		DEV_RX_OFFLOAD_JUMBO_FRAME |
594 		DEV_RX_OFFLOAD_VLAN_FILTER |
595 		DEV_RX_OFFLOAD_RSS_HASH;
596 	dev_info->tx_offload_capa =
597 		DEV_TX_OFFLOAD_VLAN_INSERT |
598 		DEV_TX_OFFLOAD_QINQ_INSERT |
599 		DEV_TX_OFFLOAD_IPV4_CKSUM |
600 		DEV_TX_OFFLOAD_UDP_CKSUM |
601 		DEV_TX_OFFLOAD_TCP_CKSUM |
602 		DEV_TX_OFFLOAD_SCTP_CKSUM |
603 		DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
604 		DEV_TX_OFFLOAD_TCP_TSO |
605 		DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
606 		DEV_TX_OFFLOAD_GRE_TNL_TSO |
607 		DEV_TX_OFFLOAD_IPIP_TNL_TSO |
608 		DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
609 		DEV_TX_OFFLOAD_MULTI_SEGS;
610 
611 	dev_info->default_rxconf = (struct rte_eth_rxconf) {
612 		.rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
613 		.rx_drop_en = 0,
614 		.offloads = 0,
615 	};
616 
617 	dev_info->default_txconf = (struct rte_eth_txconf) {
618 		.tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
619 		.tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
620 		.offloads = 0,
621 	};
622 
623 	dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
624 		.nb_max = IAVF_MAX_RING_DESC,
625 		.nb_min = IAVF_MIN_RING_DESC,
626 		.nb_align = IAVF_ALIGN_RING_DESC,
627 	};
628 
629 	dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
630 		.nb_max = IAVF_MAX_RING_DESC,
631 		.nb_min = IAVF_MIN_RING_DESC,
632 		.nb_align = IAVF_ALIGN_RING_DESC,
633 	};
634 
635 	return 0;
636 }
637 
638 static const uint32_t *
639 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
640 {
641 	static const uint32_t ptypes[] = {
642 		RTE_PTYPE_L2_ETHER,
643 		RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
644 		RTE_PTYPE_L4_FRAG,
645 		RTE_PTYPE_L4_ICMP,
646 		RTE_PTYPE_L4_NONFRAG,
647 		RTE_PTYPE_L4_SCTP,
648 		RTE_PTYPE_L4_TCP,
649 		RTE_PTYPE_L4_UDP,
650 		RTE_PTYPE_UNKNOWN
651 	};
652 	return ptypes;
653 }
654 
655 int
656 iavf_dev_link_update(struct rte_eth_dev *dev,
657 		    __rte_unused int wait_to_complete)
658 {
659 	struct rte_eth_link new_link;
660 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
661 
662 	memset(&new_link, 0, sizeof(new_link));
663 
664 	/* Only read status info stored in VF, and the info is updated
665 	 *  when receive LINK_CHANGE evnet from PF by Virtchnnl.
666 	 */
667 	switch (vf->link_speed) {
668 	case 10:
669 		new_link.link_speed = ETH_SPEED_NUM_10M;
670 		break;
671 	case 100:
672 		new_link.link_speed = ETH_SPEED_NUM_100M;
673 		break;
674 	case 1000:
675 		new_link.link_speed = ETH_SPEED_NUM_1G;
676 		break;
677 	case 10000:
678 		new_link.link_speed = ETH_SPEED_NUM_10G;
679 		break;
680 	case 20000:
681 		new_link.link_speed = ETH_SPEED_NUM_20G;
682 		break;
683 	case 25000:
684 		new_link.link_speed = ETH_SPEED_NUM_25G;
685 		break;
686 	case 40000:
687 		new_link.link_speed = ETH_SPEED_NUM_40G;
688 		break;
689 	case 50000:
690 		new_link.link_speed = ETH_SPEED_NUM_50G;
691 		break;
692 	case 100000:
693 		new_link.link_speed = ETH_SPEED_NUM_100G;
694 		break;
695 	default:
696 		new_link.link_speed = ETH_SPEED_NUM_NONE;
697 		break;
698 	}
699 
700 	new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
701 	new_link.link_status = vf->link_up ? ETH_LINK_UP :
702 					     ETH_LINK_DOWN;
703 	new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
704 				ETH_LINK_SPEED_FIXED);
705 
706 	return rte_eth_linkstatus_set(dev, &new_link);
707 }
708 
709 static int
710 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
711 {
712 	struct iavf_adapter *adapter =
713 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
714 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
715 
716 	return iavf_config_promisc(adapter,
717 				  true, vf->promisc_multicast_enabled);
718 }
719 
720 static int
721 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
722 {
723 	struct iavf_adapter *adapter =
724 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
725 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
726 
727 	return iavf_config_promisc(adapter,
728 				  false, vf->promisc_multicast_enabled);
729 }
730 
731 static int
732 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
733 {
734 	struct iavf_adapter *adapter =
735 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
736 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
737 
738 	return iavf_config_promisc(adapter,
739 				  vf->promisc_unicast_enabled, true);
740 }
741 
742 static int
743 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
744 {
745 	struct iavf_adapter *adapter =
746 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
747 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
748 
749 	return iavf_config_promisc(adapter,
750 				  vf->promisc_unicast_enabled, false);
751 }
752 
753 static int
754 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
755 		     __rte_unused uint32_t index,
756 		     __rte_unused uint32_t pool)
757 {
758 	struct iavf_adapter *adapter =
759 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
760 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
761 	int err;
762 
763 	if (rte_is_zero_ether_addr(addr)) {
764 		PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
765 		return -EINVAL;
766 	}
767 
768 	err = iavf_add_del_eth_addr(adapter, addr, true);
769 	if (err) {
770 		PMD_DRV_LOG(ERR, "fail to add MAC address");
771 		return -EIO;
772 	}
773 
774 	vf->mac_num++;
775 
776 	return 0;
777 }
778 
779 static void
780 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
781 {
782 	struct iavf_adapter *adapter =
783 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
784 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
785 	struct rte_ether_addr *addr;
786 	int err;
787 
788 	addr = &dev->data->mac_addrs[index];
789 
790 	err = iavf_add_del_eth_addr(adapter, addr, false);
791 	if (err)
792 		PMD_DRV_LOG(ERR, "fail to delete MAC address");
793 
794 	vf->mac_num--;
795 }
796 
797 static int
798 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
799 {
800 	struct iavf_adapter *adapter =
801 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
802 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
803 	int err;
804 
805 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
806 		return -ENOTSUP;
807 
808 	err = iavf_add_del_vlan(adapter, vlan_id, on);
809 	if (err)
810 		return -EIO;
811 	return 0;
812 }
813 
814 static int
815 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
816 {
817 	struct iavf_adapter *adapter =
818 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
819 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
820 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
821 	int err;
822 
823 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
824 		return -ENOTSUP;
825 
826 	/* Vlan stripping setting */
827 	if (mask & ETH_VLAN_STRIP_MASK) {
828 		/* Enable or disable VLAN stripping */
829 		if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
830 			err = iavf_enable_vlan_strip(adapter);
831 		else
832 			err = iavf_disable_vlan_strip(adapter);
833 
834 		if (err)
835 			return -EIO;
836 	}
837 	return 0;
838 }
839 
840 static int
841 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
842 			struct rte_eth_rss_reta_entry64 *reta_conf,
843 			uint16_t reta_size)
844 {
845 	struct iavf_adapter *adapter =
846 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
847 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
848 	uint8_t *lut;
849 	uint16_t i, idx, shift;
850 	int ret;
851 
852 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
853 		return -ENOTSUP;
854 
855 	if (reta_size != vf->vf_res->rss_lut_size) {
856 		PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
857 			"(%d) doesn't match the number of hardware can "
858 			"support (%d)", reta_size, vf->vf_res->rss_lut_size);
859 		return -EINVAL;
860 	}
861 
862 	lut = rte_zmalloc("rss_lut", reta_size, 0);
863 	if (!lut) {
864 		PMD_DRV_LOG(ERR, "No memory can be allocated");
865 		return -ENOMEM;
866 	}
867 	/* store the old lut table temporarily */
868 	rte_memcpy(lut, vf->rss_lut, reta_size);
869 
870 	for (i = 0; i < reta_size; i++) {
871 		idx = i / RTE_RETA_GROUP_SIZE;
872 		shift = i % RTE_RETA_GROUP_SIZE;
873 		if (reta_conf[idx].mask & (1ULL << shift))
874 			lut[i] = reta_conf[idx].reta[shift];
875 	}
876 
877 	rte_memcpy(vf->rss_lut, lut, reta_size);
878 	/* send virtchnnl ops to configure rss*/
879 	ret = iavf_configure_rss_lut(adapter);
880 	if (ret) /* revert back */
881 		rte_memcpy(vf->rss_lut, lut, reta_size);
882 	rte_free(lut);
883 
884 	return ret;
885 }
886 
887 static int
888 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
889 		       struct rte_eth_rss_reta_entry64 *reta_conf,
890 		       uint16_t reta_size)
891 {
892 	struct iavf_adapter *adapter =
893 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
894 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
895 	uint16_t i, idx, shift;
896 
897 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
898 		return -ENOTSUP;
899 
900 	if (reta_size != vf->vf_res->rss_lut_size) {
901 		PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
902 			"(%d) doesn't match the number of hardware can "
903 			"support (%d)", reta_size, vf->vf_res->rss_lut_size);
904 		return -EINVAL;
905 	}
906 
907 	for (i = 0; i < reta_size; i++) {
908 		idx = i / RTE_RETA_GROUP_SIZE;
909 		shift = i % RTE_RETA_GROUP_SIZE;
910 		if (reta_conf[idx].mask & (1ULL << shift))
911 			reta_conf[idx].reta[shift] = vf->rss_lut[i];
912 	}
913 
914 	return 0;
915 }
916 
917 static int
918 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
919 			struct rte_eth_rss_conf *rss_conf)
920 {
921 	struct iavf_adapter *adapter =
922 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
923 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
924 
925 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
926 		return -ENOTSUP;
927 
928 	/* HENA setting, it is enabled by default, no change */
929 	if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
930 		PMD_DRV_LOG(DEBUG, "No key to be configured");
931 		return 0;
932 	} else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
933 		PMD_DRV_LOG(ERR, "The size of hash key configured "
934 			"(%d) doesn't match the size of hardware can "
935 			"support (%d)", rss_conf->rss_key_len,
936 			vf->vf_res->rss_key_size);
937 		return -EINVAL;
938 	}
939 
940 	rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
941 
942 	return iavf_configure_rss_key(adapter);
943 }
944 
945 static int
946 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
947 			  struct rte_eth_rss_conf *rss_conf)
948 {
949 	struct iavf_adapter *adapter =
950 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
951 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
952 
953 	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
954 		return -ENOTSUP;
955 
956 	 /* Just set it to default value now. */
957 	rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
958 
959 	if (!rss_conf->rss_key)
960 		return 0;
961 
962 	rss_conf->rss_key_len = vf->vf_res->rss_key_size;
963 	rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
964 
965 	return 0;
966 }
967 
968 static int
969 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
970 {
971 	uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
972 	int ret = 0;
973 
974 	if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
975 		return -EINVAL;
976 
977 	/* mtu setting is forbidden if port is start */
978 	if (dev->data->dev_started) {
979 		PMD_DRV_LOG(ERR, "port must be stopped before configuration");
980 		return -EBUSY;
981 	}
982 
983 	if (frame_size > RTE_ETHER_MAX_LEN)
984 		dev->data->dev_conf.rxmode.offloads |=
985 				DEV_RX_OFFLOAD_JUMBO_FRAME;
986 	else
987 		dev->data->dev_conf.rxmode.offloads &=
988 				~DEV_RX_OFFLOAD_JUMBO_FRAME;
989 
990 	dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
991 
992 	return ret;
993 }
994 
995 static int
996 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
997 			     struct rte_ether_addr *mac_addr)
998 {
999 	struct iavf_adapter *adapter =
1000 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1001 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1002 	struct rte_ether_addr *perm_addr, *old_addr;
1003 	int ret;
1004 
1005 	old_addr = (struct rte_ether_addr *)hw->mac.addr;
1006 	perm_addr = (struct rte_ether_addr *)hw->mac.perm_addr;
1007 
1008 	/* If the MAC address is configured by host, skip the setting */
1009 	if (rte_is_valid_assigned_ether_addr(perm_addr))
1010 		return -EPERM;
1011 
1012 	ret = iavf_add_del_eth_addr(adapter, old_addr, false);
1013 	if (ret)
1014 		PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1015 			    " %02X:%02X:%02X:%02X:%02X:%02X",
1016 			    old_addr->addr_bytes[0],
1017 			    old_addr->addr_bytes[1],
1018 			    old_addr->addr_bytes[2],
1019 			    old_addr->addr_bytes[3],
1020 			    old_addr->addr_bytes[4],
1021 			    old_addr->addr_bytes[5]);
1022 
1023 	ret = iavf_add_del_eth_addr(adapter, mac_addr, true);
1024 	if (ret)
1025 		PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1026 			    " %02X:%02X:%02X:%02X:%02X:%02X",
1027 			    mac_addr->addr_bytes[0],
1028 			    mac_addr->addr_bytes[1],
1029 			    mac_addr->addr_bytes[2],
1030 			    mac_addr->addr_bytes[3],
1031 			    mac_addr->addr_bytes[4],
1032 			    mac_addr->addr_bytes[5]);
1033 
1034 	if (ret)
1035 		return -EIO;
1036 
1037 	rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1038 	return 0;
1039 }
1040 
1041 static void
1042 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1043 {
1044 	if (*stat >= *offset)
1045 		*stat = *stat - *offset;
1046 	else
1047 		*stat = (uint64_t)((*stat +
1048 			((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1049 
1050 	*stat &= IAVF_48_BIT_MASK;
1051 }
1052 
1053 static void
1054 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1055 {
1056 	if (*stat >= *offset)
1057 		*stat = (uint64_t)(*stat - *offset);
1058 	else
1059 		*stat = (uint64_t)((*stat +
1060 			((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1061 }
1062 
1063 static void
1064 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1065 {
1066 	struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1067 
1068 	iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1069 	iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1070 	iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1071 	iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1072 	iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1073 	iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1074 	iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1075 	iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1076 	iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1077 	iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1078 	iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1079 }
1080 
1081 static int
1082 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1083 {
1084 	struct iavf_adapter *adapter =
1085 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1086 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1087 	struct iavf_vsi *vsi = &vf->vsi;
1088 	struct virtchnl_eth_stats *pstats = NULL;
1089 	int ret;
1090 
1091 	ret = iavf_query_stats(adapter, &pstats);
1092 	if (ret == 0) {
1093 		iavf_update_stats(vsi, pstats);
1094 		stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1095 				pstats->rx_broadcast - pstats->rx_discards;
1096 		stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1097 						pstats->tx_unicast;
1098 		stats->imissed = pstats->rx_discards;
1099 		stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1100 		stats->ibytes = pstats->rx_bytes;
1101 		stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
1102 		stats->obytes = pstats->tx_bytes;
1103 	} else {
1104 		PMD_DRV_LOG(ERR, "Get statistics failed");
1105 	}
1106 	return ret;
1107 }
1108 
1109 static int
1110 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1111 {
1112 	int ret;
1113 	struct iavf_adapter *adapter =
1114 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1115 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1116 	struct iavf_vsi *vsi = &vf->vsi;
1117 	struct virtchnl_eth_stats *pstats = NULL;
1118 
1119 	/* read stat values to clear hardware registers */
1120 	ret = iavf_query_stats(adapter, &pstats);
1121 	if (ret != 0)
1122 		return ret;
1123 
1124 	/* set stats offset base on current values */
1125 	vsi->eth_stats_offset = *pstats;
1126 
1127 	return 0;
1128 }
1129 
1130 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1131 				      struct rte_eth_xstat_name *xstats_names,
1132 				      __rte_unused unsigned int limit)
1133 {
1134 	unsigned int i;
1135 
1136 	if (xstats_names != NULL)
1137 		for (i = 0; i < IAVF_NB_XSTATS; i++) {
1138 			snprintf(xstats_names[i].name,
1139 				sizeof(xstats_names[i].name),
1140 				"%s", rte_iavf_stats_strings[i].name);
1141 		}
1142 	return IAVF_NB_XSTATS;
1143 }
1144 
1145 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1146 				 struct rte_eth_xstat *xstats, unsigned int n)
1147 {
1148 	int ret;
1149 	unsigned int i;
1150 	struct iavf_adapter *adapter =
1151 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1152 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1153 	struct iavf_vsi *vsi = &vf->vsi;
1154 	struct virtchnl_eth_stats *pstats = NULL;
1155 
1156 	if (n < IAVF_NB_XSTATS)
1157 		return IAVF_NB_XSTATS;
1158 
1159 	ret = iavf_query_stats(adapter, &pstats);
1160 	if (ret != 0)
1161 		return 0;
1162 
1163 	if (!xstats)
1164 		return 0;
1165 
1166 	iavf_update_stats(vsi, pstats);
1167 
1168 	/* loop over xstats array and values from pstats */
1169 	for (i = 0; i < IAVF_NB_XSTATS; i++) {
1170 		xstats[i].id = i;
1171 		xstats[i].value = *(uint64_t *)(((char *)pstats) +
1172 			rte_iavf_stats_strings[i].offset);
1173 	}
1174 
1175 	return IAVF_NB_XSTATS;
1176 }
1177 
1178 
1179 static int
1180 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1181 {
1182 	struct iavf_adapter *adapter =
1183 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1184 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1185 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1186 	uint16_t msix_intr;
1187 
1188 	msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1189 	if (msix_intr == IAVF_MISC_VEC_ID) {
1190 		PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1191 		IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1192 			       IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1193 			       IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1194 			       IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1195 	} else {
1196 		IAVF_WRITE_REG(hw,
1197 			       IAVF_VFINT_DYN_CTLN1
1198 				(msix_intr - IAVF_RX_VEC_START),
1199 			       IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1200 			       IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1201 			       IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1202 	}
1203 
1204 	IAVF_WRITE_FLUSH(hw);
1205 
1206 	rte_intr_ack(&pci_dev->intr_handle);
1207 
1208 	return 0;
1209 }
1210 
1211 static int
1212 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1213 {
1214 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1215 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1216 	uint16_t msix_intr;
1217 
1218 	msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1219 	if (msix_intr == IAVF_MISC_VEC_ID) {
1220 		PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1221 		return -EIO;
1222 	}
1223 
1224 	IAVF_WRITE_REG(hw,
1225 		      IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1226 		      0);
1227 
1228 	IAVF_WRITE_FLUSH(hw);
1229 	return 0;
1230 }
1231 
1232 static int
1233 iavf_check_vf_reset_done(struct iavf_hw *hw)
1234 {
1235 	int i, reset;
1236 
1237 	for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1238 		reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1239 			IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1240 		reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1241 		if (reset == VIRTCHNL_VFR_VFACTIVE ||
1242 		    reset == VIRTCHNL_VFR_COMPLETED)
1243 			break;
1244 		rte_delay_ms(20);
1245 	}
1246 
1247 	if (i >= IAVF_RESET_WAIT_CNT)
1248 		return -1;
1249 
1250 	return 0;
1251 }
1252 
1253 static int
1254 iavf_init_vf(struct rte_eth_dev *dev)
1255 {
1256 	int err, bufsz;
1257 	struct iavf_adapter *adapter =
1258 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1259 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1260 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1261 
1262 	err = iavf_set_mac_type(hw);
1263 	if (err) {
1264 		PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1265 		goto err;
1266 	}
1267 
1268 	err = iavf_check_vf_reset_done(hw);
1269 	if (err) {
1270 		PMD_INIT_LOG(ERR, "VF is still resetting");
1271 		goto err;
1272 	}
1273 
1274 	iavf_init_adminq_parameter(hw);
1275 	err = iavf_init_adminq(hw);
1276 	if (err) {
1277 		PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1278 		goto err;
1279 	}
1280 
1281 	vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1282 	if (!vf->aq_resp) {
1283 		PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1284 		goto err_aq;
1285 	}
1286 	if (iavf_check_api_version(adapter) != 0) {
1287 		PMD_INIT_LOG(ERR, "check_api version failed");
1288 		goto err_api;
1289 	}
1290 
1291 	bufsz = sizeof(struct virtchnl_vf_resource) +
1292 		(IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1293 	vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1294 	if (!vf->vf_res) {
1295 		PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1296 		goto err_api;
1297 	}
1298 	if (iavf_get_vf_resource(adapter) != 0) {
1299 		PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1300 		goto err_alloc;
1301 	}
1302 	/* Allocate memort for RSS info */
1303 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1304 		vf->rss_key = rte_zmalloc("rss_key",
1305 					  vf->vf_res->rss_key_size, 0);
1306 		if (!vf->rss_key) {
1307 			PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1308 			goto err_rss;
1309 		}
1310 		vf->rss_lut = rte_zmalloc("rss_lut",
1311 					  vf->vf_res->rss_lut_size, 0);
1312 		if (!vf->rss_lut) {
1313 			PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1314 			goto err_rss;
1315 		}
1316 	}
1317 
1318 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1319 		if (iavf_get_supported_rxdid(adapter) != 0) {
1320 			PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
1321 			goto err_rss;
1322 		}
1323 	}
1324 
1325 	return 0;
1326 err_rss:
1327 	rte_free(vf->rss_key);
1328 	rte_free(vf->rss_lut);
1329 err_alloc:
1330 	rte_free(vf->vf_res);
1331 	vf->vsi_res = NULL;
1332 err_api:
1333 	rte_free(vf->aq_resp);
1334 err_aq:
1335 	iavf_shutdown_adminq(hw);
1336 err:
1337 	return -1;
1338 }
1339 
1340 /* Enable default admin queue interrupt setting */
1341 static inline void
1342 iavf_enable_irq0(struct iavf_hw *hw)
1343 {
1344 	/* Enable admin queue interrupt trigger */
1345 	IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
1346 		       IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
1347 
1348 	IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1349 		       IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1350 		       IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1351 		       IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1352 
1353 	IAVF_WRITE_FLUSH(hw);
1354 }
1355 
1356 static inline void
1357 iavf_disable_irq0(struct iavf_hw *hw)
1358 {
1359 	/* Disable all interrupt types */
1360 	IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
1361 	IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1362 		       IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1363 	IAVF_WRITE_FLUSH(hw);
1364 }
1365 
1366 static void
1367 iavf_dev_interrupt_handler(void *param)
1368 {
1369 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1370 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1371 
1372 	iavf_disable_irq0(hw);
1373 
1374 	iavf_handle_virtchnl_msg(dev);
1375 
1376 	iavf_enable_irq0(hw);
1377 }
1378 
1379 static int
1380 iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
1381 		     enum rte_filter_type filter_type,
1382 		     enum rte_filter_op filter_op,
1383 		     void *arg)
1384 {
1385 	int ret = 0;
1386 
1387 	if (!dev)
1388 		return -EINVAL;
1389 
1390 	switch (filter_type) {
1391 	case RTE_ETH_FILTER_GENERIC:
1392 		if (filter_op != RTE_ETH_FILTER_GET)
1393 			return -EINVAL;
1394 		*(const void **)arg = &iavf_flow_ops;
1395 		break;
1396 	default:
1397 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1398 			    filter_type);
1399 		ret = -EINVAL;
1400 		break;
1401 	}
1402 
1403 	return ret;
1404 }
1405 
1406 
1407 static int
1408 iavf_dev_init(struct rte_eth_dev *eth_dev)
1409 {
1410 	struct iavf_adapter *adapter =
1411 		IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1412 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1413 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1414 	int ret = 0;
1415 
1416 	PMD_INIT_FUNC_TRACE();
1417 
1418 	/* assign ops func pointer */
1419 	eth_dev->dev_ops = &iavf_eth_dev_ops;
1420 	eth_dev->rx_queue_count = iavf_dev_rxq_count;
1421 	eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
1422 	eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
1423 	eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1424 	eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1425 	eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1426 
1427 	/* For secondary processes, we don't initialise any further as primary
1428 	 * has already done this work. Only check if we need a different RX
1429 	 * and TX function.
1430 	 */
1431 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1432 		iavf_set_rx_function(eth_dev);
1433 		iavf_set_tx_function(eth_dev);
1434 		return 0;
1435 	}
1436 	rte_eth_copy_pci_info(eth_dev, pci_dev);
1437 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1438 
1439 	hw->vendor_id = pci_dev->id.vendor_id;
1440 	hw->device_id = pci_dev->id.device_id;
1441 	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1442 	hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1443 	hw->bus.bus_id = pci_dev->addr.bus;
1444 	hw->bus.device = pci_dev->addr.devid;
1445 	hw->bus.func = pci_dev->addr.function;
1446 	hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1447 	hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1448 	adapter->eth_dev = eth_dev;
1449 	adapter->stopped = 1;
1450 
1451 	if (iavf_init_vf(eth_dev) != 0) {
1452 		PMD_INIT_LOG(ERR, "Init vf failed");
1453 		return -1;
1454 	}
1455 
1456 	/* set default ptype table */
1457 	adapter->ptype_tbl = iavf_get_default_ptype_table();
1458 
1459 	/* copy mac addr */
1460 	eth_dev->data->mac_addrs = rte_zmalloc(
1461 		"iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
1462 	if (!eth_dev->data->mac_addrs) {
1463 		PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1464 			     " store MAC addresses",
1465 			     RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1466 		return -ENOMEM;
1467 	}
1468 	/* If the MAC address is not configured by host,
1469 	 * generate a random one.
1470 	 */
1471 	if (!rte_is_valid_assigned_ether_addr(
1472 			(struct rte_ether_addr *)hw->mac.addr))
1473 		rte_eth_random_addr(hw->mac.addr);
1474 	rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1475 			&eth_dev->data->mac_addrs[0]);
1476 
1477 	/* register callback func to eal lib */
1478 	rte_intr_callback_register(&pci_dev->intr_handle,
1479 				   iavf_dev_interrupt_handler,
1480 				   (void *)eth_dev);
1481 
1482 	/* enable uio intr after callback register */
1483 	rte_intr_enable(&pci_dev->intr_handle);
1484 
1485 	/* configure and enable device interrupt */
1486 	iavf_enable_irq0(hw);
1487 
1488 	ret = iavf_flow_init(adapter);
1489 	if (ret) {
1490 		PMD_INIT_LOG(ERR, "Failed to initialize flow");
1491 		return ret;
1492 	}
1493 
1494 	return 0;
1495 }
1496 
1497 static int
1498 iavf_dev_close(struct rte_eth_dev *dev)
1499 {
1500 	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1501 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1502 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1503 	struct iavf_adapter *adapter =
1504 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1505 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1506 	int ret;
1507 
1508 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1509 		return 0;
1510 
1511 	ret = iavf_dev_stop(dev);
1512 
1513 	iavf_flow_flush(dev, NULL);
1514 	iavf_flow_uninit(adapter);
1515 
1516 	/*
1517 	 * disable promiscuous mode before reset vf
1518 	 * it is a workaround solution when work with kernel driver
1519 	 * and it is not the normal way
1520 	 */
1521 	if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
1522 		iavf_config_promisc(adapter, false, false);
1523 
1524 	iavf_shutdown_adminq(hw);
1525 	/* disable uio intr before callback unregister */
1526 	rte_intr_disable(intr_handle);
1527 
1528 	/* unregister callback func from eal lib */
1529 	rte_intr_callback_unregister(intr_handle,
1530 				     iavf_dev_interrupt_handler, dev);
1531 	iavf_disable_irq0(hw);
1532 
1533 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1534 		if (vf->rss_lut) {
1535 			rte_free(vf->rss_lut);
1536 			vf->rss_lut = NULL;
1537 		}
1538 		if (vf->rss_key) {
1539 			rte_free(vf->rss_key);
1540 			vf->rss_key = NULL;
1541 		}
1542 	}
1543 
1544 	rte_free(vf->vf_res);
1545 	vf->vsi_res = NULL;
1546 	vf->vf_res = NULL;
1547 
1548 	rte_free(vf->aq_resp);
1549 	vf->aq_resp = NULL;
1550 
1551 	vf->vf_reset = false;
1552 
1553 	return ret;
1554 }
1555 
1556 static int
1557 iavf_dev_uninit(struct rte_eth_dev *dev)
1558 {
1559 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1560 		return -EPERM;
1561 
1562 	iavf_dev_close(dev);
1563 
1564 	return 0;
1565 }
1566 
1567 /*
1568  * Reset VF device only to re-initialize resources in PMD layer
1569  */
1570 static int
1571 iavf_dev_reset(struct rte_eth_dev *dev)
1572 {
1573 	int ret;
1574 
1575 	ret = iavf_dev_uninit(dev);
1576 	if (ret)
1577 		return ret;
1578 
1579 	return iavf_dev_init(dev);
1580 }
1581 
1582 static int
1583 iavf_dcf_cap_check_handler(__rte_unused const char *key,
1584 			   const char *value, __rte_unused void *opaque)
1585 {
1586 	if (strcmp(value, "dcf"))
1587 		return -1;
1588 
1589 	return 0;
1590 }
1591 
1592 static int
1593 iavf_dcf_cap_selected(struct rte_devargs *devargs)
1594 {
1595 	struct rte_kvargs *kvlist;
1596 	const char *key = "cap";
1597 	int ret = 0;
1598 
1599 	if (devargs == NULL)
1600 		return 0;
1601 
1602 	kvlist = rte_kvargs_parse(devargs->args, NULL);
1603 	if (kvlist == NULL)
1604 		return 0;
1605 
1606 	if (!rte_kvargs_count(kvlist, key))
1607 		goto exit;
1608 
1609 	/* dcf capability selected when there's a key-value pair: cap=dcf */
1610 	if (rte_kvargs_process(kvlist, key,
1611 			       iavf_dcf_cap_check_handler, NULL) < 0)
1612 		goto exit;
1613 
1614 	ret = 1;
1615 
1616 exit:
1617 	rte_kvargs_free(kvlist);
1618 	return ret;
1619 }
1620 
1621 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1622 			     struct rte_pci_device *pci_dev)
1623 {
1624 	if (iavf_dcf_cap_selected(pci_dev->device.devargs))
1625 		return 1;
1626 
1627 	return rte_eth_dev_pci_generic_probe(pci_dev,
1628 		sizeof(struct iavf_adapter), iavf_dev_init);
1629 }
1630 
1631 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1632 {
1633 	return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1634 }
1635 
1636 /* Adaptive virtual function driver struct */
1637 static struct rte_pci_driver rte_iavf_pmd = {
1638 	.id_table = pci_id_iavf_map,
1639 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1640 	.probe = eth_iavf_pci_probe,
1641 	.remove = eth_iavf_pci_remove,
1642 };
1643 
1644 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1645 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1646 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1647 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
1648 RTE_LOG_REGISTER(iavf_logtype_init, pmd.net.iavf.init, NOTICE);
1649 RTE_LOG_REGISTER(iavf_logtype_driver, pmd.net.iavf.driver, NOTICE);
1650 #ifdef RTE_LIBRTE_IAVF_DEBUG_RX
1651 RTE_LOG_REGISTER(iavf_logtype_rx, pmd.net.iavf.rx, DEBUG);
1652 #endif
1653 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
1654 RTE_LOG_REGISTER(iavf_logtype_tx, pmd.net.iavf.tx, DEBUG);
1655 #endif
1656 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_FREE
1657 RTE_LOG_REGISTER(iavf_logtype_tx_free, pmd.net.iavf.tx_free, DEBUG);
1658 #endif
1659