1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
13 #include <rte_byteorder.h>
14 #include <rte_common.h>
16 #include <rte_interrupts.h>
17 #include <rte_debug.h>
19 #include <rte_atomic.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>
29 #include "iavf_rxtx.h"
30 #include "iavf_generic_flow.h"
32 static int iavf_dev_configure(struct rte_eth_dev *dev);
33 static int iavf_dev_start(struct rte_eth_dev *dev);
34 static void 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_promiscuous_enable(struct rte_eth_dev *dev);
44 static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
45 static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
46 static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
47 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
48 struct rte_ether_addr *addr,
51 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
52 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
53 uint16_t vlan_id, int on);
54 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
55 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
56 struct rte_eth_rss_reta_entry64 *reta_conf,
58 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
59 struct rte_eth_rss_reta_entry64 *reta_conf,
61 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
62 struct rte_eth_rss_conf *rss_conf);
63 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
64 struct rte_eth_rss_conf *rss_conf);
65 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
66 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
67 struct rte_ether_addr *mac_addr);
68 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
70 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
72 static int iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
73 enum rte_filter_type filter_type,
74 enum rte_filter_op filter_op,
76 static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
77 struct rte_ether_addr *mc_addrs,
78 uint32_t mc_addrs_num);
80 static const struct rte_pci_id pci_id_iavf_map[] = {
81 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
82 { .vendor_id = 0, /* sentinel */ },
85 static const struct eth_dev_ops iavf_eth_dev_ops = {
86 .dev_configure = iavf_dev_configure,
87 .dev_start = iavf_dev_start,
88 .dev_stop = iavf_dev_stop,
89 .dev_close = iavf_dev_close,
90 .dev_reset = iavf_dev_reset,
91 .dev_infos_get = iavf_dev_info_get,
92 .dev_supported_ptypes_get = iavf_dev_supported_ptypes_get,
93 .link_update = iavf_dev_link_update,
94 .stats_get = iavf_dev_stats_get,
95 .stats_reset = iavf_dev_stats_reset,
96 .promiscuous_enable = iavf_dev_promiscuous_enable,
97 .promiscuous_disable = iavf_dev_promiscuous_disable,
98 .allmulticast_enable = iavf_dev_allmulticast_enable,
99 .allmulticast_disable = iavf_dev_allmulticast_disable,
100 .mac_addr_add = iavf_dev_add_mac_addr,
101 .mac_addr_remove = iavf_dev_del_mac_addr,
102 .set_mc_addr_list = iavf_set_mc_addr_list,
103 .vlan_filter_set = iavf_dev_vlan_filter_set,
104 .vlan_offload_set = iavf_dev_vlan_offload_set,
105 .rx_queue_start = iavf_dev_rx_queue_start,
106 .rx_queue_stop = iavf_dev_rx_queue_stop,
107 .tx_queue_start = iavf_dev_tx_queue_start,
108 .tx_queue_stop = iavf_dev_tx_queue_stop,
109 .rx_queue_setup = iavf_dev_rx_queue_setup,
110 .rx_queue_release = iavf_dev_rx_queue_release,
111 .tx_queue_setup = iavf_dev_tx_queue_setup,
112 .tx_queue_release = iavf_dev_tx_queue_release,
113 .mac_addr_set = iavf_dev_set_default_mac_addr,
114 .reta_update = iavf_dev_rss_reta_update,
115 .reta_query = iavf_dev_rss_reta_query,
116 .rss_hash_update = iavf_dev_rss_hash_update,
117 .rss_hash_conf_get = iavf_dev_rss_hash_conf_get,
118 .rxq_info_get = iavf_dev_rxq_info_get,
119 .txq_info_get = iavf_dev_txq_info_get,
120 .mtu_set = iavf_dev_mtu_set,
121 .rx_queue_intr_enable = iavf_dev_rx_queue_intr_enable,
122 .rx_queue_intr_disable = iavf_dev_rx_queue_intr_disable,
123 .filter_ctrl = iavf_dev_filter_ctrl,
127 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
128 struct rte_ether_addr *mc_addrs,
129 uint32_t mc_addrs_num)
131 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
132 struct iavf_adapter *adapter =
133 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
136 /* flush previous addresses */
137 err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
142 vf->mc_addrs_num = 0;
145 err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
149 vf->mc_addrs_num = mc_addrs_num;
150 memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
156 iavf_init_rss(struct iavf_adapter *adapter)
158 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
159 struct rte_eth_rss_conf *rss_conf;
163 rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
164 nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
165 IAVF_MAX_NUM_QUEUES);
167 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
168 PMD_DRV_LOG(DEBUG, "RSS is not supported");
171 if (adapter->eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
172 PMD_DRV_LOG(WARNING, "RSS is enabled by PF by default");
173 /* set all lut items to default queue */
174 for (i = 0; i < vf->vf_res->rss_lut_size; i++)
176 ret = iavf_configure_rss_lut(adapter);
180 /* In IAVF, RSS enablement is set by PF driver. It is not supported
181 * to set based on rss_conf->rss_hf.
184 /* configure RSS key */
185 if (!rss_conf->rss_key) {
186 /* Calculate the default hash key */
187 for (i = 0; i <= vf->vf_res->rss_key_size; i++)
188 vf->rss_key[i] = (uint8_t)rte_rand();
190 rte_memcpy(vf->rss_key, rss_conf->rss_key,
191 RTE_MIN(rss_conf->rss_key_len,
192 vf->vf_res->rss_key_size));
194 /* init RSS LUT table */
195 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
200 /* send virtchnnl ops to configure rss*/
201 ret = iavf_configure_rss_lut(adapter);
204 ret = iavf_configure_rss_key(adapter);
212 iavf_dev_configure(struct rte_eth_dev *dev)
214 struct iavf_adapter *ad =
215 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
216 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
217 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
219 ad->rx_bulk_alloc_allowed = true;
220 /* Initialize to TRUE. If any of Rx queues doesn't meet the
221 * vector Rx/Tx preconditions, it will be reset.
223 ad->rx_vec_allowed = true;
224 ad->tx_vec_allowed = true;
226 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
227 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
229 /* Vlan stripping setting */
230 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
231 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
232 iavf_enable_vlan_strip(ad);
234 iavf_disable_vlan_strip(ad);
237 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
238 if (iavf_init_rss(ad) != 0) {
239 PMD_DRV_LOG(ERR, "configure rss failed");
247 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
249 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
250 struct rte_eth_dev_data *dev_data = dev->data;
251 uint16_t buf_size, max_pkt_len, len;
253 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
255 /* Calculate the maximum packet length allowed */
256 len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
257 max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
259 /* Check if the jumbo frame and maximum packet length are set
262 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
263 if (max_pkt_len <= RTE_ETHER_MAX_LEN ||
264 max_pkt_len > IAVF_FRAME_SIZE_MAX) {
265 PMD_DRV_LOG(ERR, "maximum packet length must be "
266 "larger than %u and smaller than %u, "
267 "as jumbo frame is enabled",
268 (uint32_t)RTE_ETHER_MAX_LEN,
269 (uint32_t)IAVF_FRAME_SIZE_MAX);
273 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
274 max_pkt_len > RTE_ETHER_MAX_LEN) {
275 PMD_DRV_LOG(ERR, "maximum packet length must be "
276 "larger than %u and smaller than %u, "
277 "as jumbo frame is disabled",
278 (uint32_t)RTE_ETHER_MIN_LEN,
279 (uint32_t)RTE_ETHER_MAX_LEN);
284 rxq->max_pkt_len = max_pkt_len;
285 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
286 rxq->max_pkt_len > buf_size) {
287 dev_data->scattered_rx = 1;
289 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
290 IAVF_WRITE_FLUSH(hw);
296 iavf_init_queues(struct rte_eth_dev *dev)
298 struct iavf_rx_queue **rxq =
299 (struct iavf_rx_queue **)dev->data->rx_queues;
300 int i, ret = IAVF_SUCCESS;
302 for (i = 0; i < dev->data->nb_rx_queues; i++) {
303 if (!rxq[i] || !rxq[i]->q_set)
305 ret = iavf_init_rxq(dev, rxq[i]);
306 if (ret != IAVF_SUCCESS)
309 /* set rx/tx function to vector/scatter/single-segment
310 * according to parameters
312 iavf_set_rx_function(dev);
313 iavf_set_tx_function(dev);
318 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
319 struct rte_intr_handle *intr_handle)
321 struct iavf_adapter *adapter =
322 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
323 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
324 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
325 uint16_t interval, i;
328 if (rte_intr_cap_multiple(intr_handle) &&
329 dev->data->dev_conf.intr_conf.rxq) {
330 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
334 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
335 intr_handle->intr_vec =
336 rte_zmalloc("intr_vec",
337 dev->data->nb_rx_queues * sizeof(int), 0);
338 if (!intr_handle->intr_vec) {
339 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
340 dev->data->nb_rx_queues);
345 if (!dev->data->dev_conf.intr_conf.rxq ||
346 !rte_intr_dp_is_en(intr_handle)) {
347 /* Rx interrupt disabled, Map interrupt only for writeback */
349 if (vf->vf_res->vf_cap_flags &
350 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
351 /* If WB_ON_ITR supports, enable it */
352 vf->msix_base = IAVF_RX_VEC_START;
354 IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
355 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK |
356 IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
358 /* If no WB_ON_ITR offload flags, need to set
359 * interrupt for descriptor write back.
361 vf->msix_base = IAVF_MISC_VEC_ID;
364 interval = iavf_calc_itr_interval(
365 IAVF_QUEUE_ITR_INTERVAL_MAX);
366 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
367 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
368 (IAVF_ITR_INDEX_DEFAULT <<
369 IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
371 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
373 IAVF_WRITE_FLUSH(hw);
374 /* map all queues to the same interrupt */
375 for (i = 0; i < dev->data->nb_rx_queues; i++)
376 vf->rxq_map[vf->msix_base] |= 1 << i;
378 if (!rte_intr_allow_others(intr_handle)) {
380 vf->msix_base = IAVF_MISC_VEC_ID;
381 for (i = 0; i < dev->data->nb_rx_queues; i++) {
382 vf->rxq_map[vf->msix_base] |= 1 << i;
383 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
386 "vector %u are mapping to all Rx queues",
389 /* If Rx interrupt is reuquired, and we can use
390 * multi interrupts, then the vec is from 1
392 vf->nb_msix = RTE_MIN(vf->vf_res->max_vectors,
393 intr_handle->nb_efd);
394 vf->msix_base = IAVF_RX_VEC_START;
395 vec = IAVF_RX_VEC_START;
396 for (i = 0; i < dev->data->nb_rx_queues; i++) {
397 vf->rxq_map[vec] |= 1 << i;
398 intr_handle->intr_vec[i] = vec++;
399 if (vec >= vf->nb_msix)
400 vec = IAVF_RX_VEC_START;
403 "%u vectors are mapping to %u Rx queues",
404 vf->nb_msix, dev->data->nb_rx_queues);
408 if (iavf_config_irq_map(adapter)) {
409 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
416 iavf_start_queues(struct rte_eth_dev *dev)
418 struct iavf_rx_queue *rxq;
419 struct iavf_tx_queue *txq;
422 for (i = 0; i < dev->data->nb_tx_queues; i++) {
423 txq = dev->data->tx_queues[i];
424 if (txq->tx_deferred_start)
426 if (iavf_dev_tx_queue_start(dev, i) != 0) {
427 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
432 for (i = 0; i < dev->data->nb_rx_queues; i++) {
433 rxq = dev->data->rx_queues[i];
434 if (rxq->rx_deferred_start)
436 if (iavf_dev_rx_queue_start(dev, i) != 0) {
437 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
446 iavf_dev_start(struct rte_eth_dev *dev)
448 struct iavf_adapter *adapter =
449 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
450 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
451 struct rte_intr_handle *intr_handle = dev->intr_handle;
453 PMD_INIT_FUNC_TRACE();
455 adapter->stopped = 0;
457 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
458 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
459 dev->data->nb_tx_queues);
461 if (iavf_init_queues(dev) != 0) {
462 PMD_DRV_LOG(ERR, "failed to do Queue init");
466 if (iavf_configure_queues(adapter) != 0) {
467 PMD_DRV_LOG(ERR, "configure queues failed");
471 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
472 PMD_DRV_LOG(ERR, "configure irq failed");
475 /* re-enable intr again, because efd assign may change */
476 if (dev->data->dev_conf.intr_conf.rxq != 0) {
477 rte_intr_disable(intr_handle);
478 rte_intr_enable(intr_handle);
481 /* Set all mac addrs */
482 iavf_add_del_all_mac_addr(adapter, true);
484 /* Set all multicast addresses */
485 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
488 if (iavf_start_queues(dev) != 0) {
489 PMD_DRV_LOG(ERR, "enable queues failed");
496 iavf_add_del_all_mac_addr(adapter, false);
502 iavf_dev_stop(struct rte_eth_dev *dev)
504 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
505 struct iavf_adapter *adapter =
506 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
507 struct rte_intr_handle *intr_handle = dev->intr_handle;
509 PMD_INIT_FUNC_TRACE();
511 if (adapter->stopped == 1)
514 iavf_stop_queues(dev);
516 /* Disable the interrupt for Rx */
517 rte_intr_efd_disable(intr_handle);
518 /* Rx interrupt vector mapping free */
519 if (intr_handle->intr_vec) {
520 rte_free(intr_handle->intr_vec);
521 intr_handle->intr_vec = NULL;
524 /* remove all mac addrs */
525 iavf_add_del_all_mac_addr(adapter, false);
527 /* remove all multicast addresses */
528 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
531 adapter->stopped = 1;
535 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
537 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
539 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
540 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
541 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
542 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
543 dev_info->hash_key_size = vf->vf_res->rss_key_size;
544 dev_info->reta_size = vf->vf_res->rss_lut_size;
545 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
546 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
547 dev_info->rx_offload_capa =
548 DEV_RX_OFFLOAD_VLAN_STRIP |
549 DEV_RX_OFFLOAD_QINQ_STRIP |
550 DEV_RX_OFFLOAD_IPV4_CKSUM |
551 DEV_RX_OFFLOAD_UDP_CKSUM |
552 DEV_RX_OFFLOAD_TCP_CKSUM |
553 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
554 DEV_RX_OFFLOAD_SCATTER |
555 DEV_RX_OFFLOAD_JUMBO_FRAME |
556 DEV_RX_OFFLOAD_VLAN_FILTER |
557 DEV_RX_OFFLOAD_RSS_HASH;
558 dev_info->tx_offload_capa =
559 DEV_TX_OFFLOAD_VLAN_INSERT |
560 DEV_TX_OFFLOAD_QINQ_INSERT |
561 DEV_TX_OFFLOAD_IPV4_CKSUM |
562 DEV_TX_OFFLOAD_UDP_CKSUM |
563 DEV_TX_OFFLOAD_TCP_CKSUM |
564 DEV_TX_OFFLOAD_SCTP_CKSUM |
565 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
566 DEV_TX_OFFLOAD_TCP_TSO |
567 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
568 DEV_TX_OFFLOAD_GRE_TNL_TSO |
569 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
570 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
571 DEV_TX_OFFLOAD_MULTI_SEGS;
573 dev_info->default_rxconf = (struct rte_eth_rxconf) {
574 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
579 dev_info->default_txconf = (struct rte_eth_txconf) {
580 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
581 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
585 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
586 .nb_max = IAVF_MAX_RING_DESC,
587 .nb_min = IAVF_MIN_RING_DESC,
588 .nb_align = IAVF_ALIGN_RING_DESC,
591 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
592 .nb_max = IAVF_MAX_RING_DESC,
593 .nb_min = IAVF_MIN_RING_DESC,
594 .nb_align = IAVF_ALIGN_RING_DESC,
600 static const uint32_t *
601 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
603 static const uint32_t ptypes[] = {
605 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
608 RTE_PTYPE_L4_NONFRAG,
618 iavf_dev_link_update(struct rte_eth_dev *dev,
619 __rte_unused int wait_to_complete)
621 struct rte_eth_link new_link;
622 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
624 memset(&new_link, 0, sizeof(new_link));
626 /* Only read status info stored in VF, and the info is updated
627 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
629 switch (vf->link_speed) {
631 new_link.link_speed = ETH_SPEED_NUM_10M;
634 new_link.link_speed = ETH_SPEED_NUM_100M;
637 new_link.link_speed = ETH_SPEED_NUM_1G;
640 new_link.link_speed = ETH_SPEED_NUM_10G;
643 new_link.link_speed = ETH_SPEED_NUM_20G;
646 new_link.link_speed = ETH_SPEED_NUM_25G;
649 new_link.link_speed = ETH_SPEED_NUM_40G;
652 new_link.link_speed = ETH_SPEED_NUM_50G;
655 new_link.link_speed = ETH_SPEED_NUM_100G;
658 new_link.link_speed = ETH_SPEED_NUM_NONE;
662 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
663 new_link.link_status = vf->link_up ? ETH_LINK_UP :
665 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
666 ETH_LINK_SPEED_FIXED);
668 if (rte_atomic64_cmpset((uint64_t *)&dev->data->dev_link,
669 *(uint64_t *)&dev->data->dev_link,
670 *(uint64_t *)&new_link) == 0)
677 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
679 struct iavf_adapter *adapter =
680 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
681 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
684 if (vf->promisc_unicast_enabled)
687 ret = iavf_config_promisc(adapter, true, vf->promisc_multicast_enabled);
689 vf->promisc_unicast_enabled = true;
690 else if (ret == IAVF_NOT_SUPPORTED)
699 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
701 struct iavf_adapter *adapter =
702 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
703 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
706 if (!vf->promisc_unicast_enabled)
709 ret = iavf_config_promisc(adapter, false,
710 vf->promisc_multicast_enabled);
712 vf->promisc_unicast_enabled = false;
713 else if (ret == IAVF_NOT_SUPPORTED)
722 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
724 struct iavf_adapter *adapter =
725 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
726 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
729 if (vf->promisc_multicast_enabled)
732 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, true);
734 vf->promisc_multicast_enabled = true;
735 else if (ret == IAVF_NOT_SUPPORTED)
744 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
746 struct iavf_adapter *adapter =
747 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
748 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
751 if (!vf->promisc_multicast_enabled)
754 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, false);
756 vf->promisc_multicast_enabled = false;
757 else if (ret == IAVF_NOT_SUPPORTED)
766 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
767 __rte_unused uint32_t index,
768 __rte_unused uint32_t pool)
770 struct iavf_adapter *adapter =
771 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
772 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
775 if (rte_is_zero_ether_addr(addr)) {
776 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
780 err = iavf_add_del_eth_addr(adapter, addr, true);
782 PMD_DRV_LOG(ERR, "fail to add MAC address");
792 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
794 struct iavf_adapter *adapter =
795 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
796 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
797 struct rte_ether_addr *addr;
800 addr = &dev->data->mac_addrs[index];
802 err = iavf_add_del_eth_addr(adapter, addr, false);
804 PMD_DRV_LOG(ERR, "fail to delete MAC address");
810 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
812 struct iavf_adapter *adapter =
813 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
814 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
817 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
820 err = iavf_add_del_vlan(adapter, vlan_id, on);
827 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
829 struct iavf_adapter *adapter =
830 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
831 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
832 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
835 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
838 /* Vlan stripping setting */
839 if (mask & ETH_VLAN_STRIP_MASK) {
840 /* Enable or disable VLAN stripping */
841 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
842 err = iavf_enable_vlan_strip(adapter);
844 err = iavf_disable_vlan_strip(adapter);
853 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
854 struct rte_eth_rss_reta_entry64 *reta_conf,
857 struct iavf_adapter *adapter =
858 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
859 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
861 uint16_t i, idx, shift;
864 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
867 if (reta_size != vf->vf_res->rss_lut_size) {
868 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
869 "(%d) doesn't match the number of hardware can "
870 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
874 lut = rte_zmalloc("rss_lut", reta_size, 0);
876 PMD_DRV_LOG(ERR, "No memory can be allocated");
879 /* store the old lut table temporarily */
880 rte_memcpy(lut, vf->rss_lut, reta_size);
882 for (i = 0; i < reta_size; i++) {
883 idx = i / RTE_RETA_GROUP_SIZE;
884 shift = i % RTE_RETA_GROUP_SIZE;
885 if (reta_conf[idx].mask & (1ULL << shift))
886 lut[i] = reta_conf[idx].reta[shift];
889 rte_memcpy(vf->rss_lut, lut, reta_size);
890 /* send virtchnnl ops to configure rss*/
891 ret = iavf_configure_rss_lut(adapter);
892 if (ret) /* revert back */
893 rte_memcpy(vf->rss_lut, lut, reta_size);
900 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
901 struct rte_eth_rss_reta_entry64 *reta_conf,
904 struct iavf_adapter *adapter =
905 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
906 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
907 uint16_t i, idx, shift;
909 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
912 if (reta_size != vf->vf_res->rss_lut_size) {
913 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
914 "(%d) doesn't match the number of hardware can "
915 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
919 for (i = 0; i < reta_size; i++) {
920 idx = i / RTE_RETA_GROUP_SIZE;
921 shift = i % RTE_RETA_GROUP_SIZE;
922 if (reta_conf[idx].mask & (1ULL << shift))
923 reta_conf[idx].reta[shift] = vf->rss_lut[i];
930 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
931 struct rte_eth_rss_conf *rss_conf)
933 struct iavf_adapter *adapter =
934 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
935 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
937 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
940 /* HENA setting, it is enabled by default, no change */
941 if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
942 PMD_DRV_LOG(DEBUG, "No key to be configured");
944 } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
945 PMD_DRV_LOG(ERR, "The size of hash key configured "
946 "(%d) doesn't match the size of hardware can "
947 "support (%d)", rss_conf->rss_key_len,
948 vf->vf_res->rss_key_size);
952 rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
954 return iavf_configure_rss_key(adapter);
958 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
959 struct rte_eth_rss_conf *rss_conf)
961 struct iavf_adapter *adapter =
962 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
963 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
965 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
968 /* Just set it to default value now. */
969 rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
971 if (!rss_conf->rss_key)
974 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
975 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
981 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
983 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
986 if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
989 /* mtu setting is forbidden if port is start */
990 if (dev->data->dev_started) {
991 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
995 if (frame_size > RTE_ETHER_MAX_LEN)
996 dev->data->dev_conf.rxmode.offloads |=
997 DEV_RX_OFFLOAD_JUMBO_FRAME;
999 dev->data->dev_conf.rxmode.offloads &=
1000 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1002 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1008 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1009 struct rte_ether_addr *mac_addr)
1011 struct iavf_adapter *adapter =
1012 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1013 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1014 struct rte_ether_addr *perm_addr, *old_addr;
1017 old_addr = (struct rte_ether_addr *)hw->mac.addr;
1018 perm_addr = (struct rte_ether_addr *)hw->mac.perm_addr;
1020 /* If the MAC address is configured by host, skip the setting */
1021 if (rte_is_valid_assigned_ether_addr(perm_addr))
1024 ret = iavf_add_del_eth_addr(adapter, old_addr, false);
1026 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1027 " %02X:%02X:%02X:%02X:%02X:%02X",
1028 old_addr->addr_bytes[0],
1029 old_addr->addr_bytes[1],
1030 old_addr->addr_bytes[2],
1031 old_addr->addr_bytes[3],
1032 old_addr->addr_bytes[4],
1033 old_addr->addr_bytes[5]);
1035 ret = iavf_add_del_eth_addr(adapter, mac_addr, true);
1037 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1038 " %02X:%02X:%02X:%02X:%02X:%02X",
1039 mac_addr->addr_bytes[0],
1040 mac_addr->addr_bytes[1],
1041 mac_addr->addr_bytes[2],
1042 mac_addr->addr_bytes[3],
1043 mac_addr->addr_bytes[4],
1044 mac_addr->addr_bytes[5]);
1049 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1054 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1056 if (*stat >= *offset)
1057 *stat = *stat - *offset;
1059 *stat = (uint64_t)((*stat +
1060 ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1062 *stat &= IAVF_48_BIT_MASK;
1066 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1068 if (*stat >= *offset)
1069 *stat = (uint64_t)(*stat - *offset);
1071 *stat = (uint64_t)((*stat +
1072 ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1076 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1078 struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1080 iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1081 iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1082 iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1083 iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1084 iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1085 iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1086 iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1087 iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1088 iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1089 iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1090 iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1094 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1096 struct iavf_adapter *adapter =
1097 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1098 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1099 struct iavf_vsi *vsi = &vf->vsi;
1100 struct virtchnl_eth_stats *pstats = NULL;
1103 ret = iavf_query_stats(adapter, &pstats);
1105 iavf_update_stats(vsi, pstats);
1106 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1107 pstats->rx_broadcast - pstats->rx_discards;
1108 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1110 stats->imissed = pstats->rx_discards;
1111 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1112 stats->ibytes = pstats->rx_bytes;
1113 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
1114 stats->obytes = pstats->tx_bytes;
1116 PMD_DRV_LOG(ERR, "Get statistics failed");
1122 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1125 struct iavf_adapter *adapter =
1126 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1127 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1128 struct iavf_vsi *vsi = &vf->vsi;
1129 struct virtchnl_eth_stats *pstats = NULL;
1131 /* read stat values to clear hardware registers */
1132 ret = iavf_query_stats(adapter, &pstats);
1136 /* set stats offset base on current values */
1137 vsi->eth_stats_offset = *pstats;
1143 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1145 struct iavf_adapter *adapter =
1146 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1147 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1148 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1151 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1152 if (msix_intr == IAVF_MISC_VEC_ID) {
1153 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1154 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1155 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1156 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1157 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1160 IAVF_VFINT_DYN_CTLN1
1161 (msix_intr - IAVF_RX_VEC_START),
1162 IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1163 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1164 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1167 IAVF_WRITE_FLUSH(hw);
1169 rte_intr_ack(&pci_dev->intr_handle);
1175 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1177 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1178 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1181 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1182 if (msix_intr == IAVF_MISC_VEC_ID) {
1183 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1188 IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1191 IAVF_WRITE_FLUSH(hw);
1196 iavf_check_vf_reset_done(struct iavf_hw *hw)
1200 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1201 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1202 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1203 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1204 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1205 reset == VIRTCHNL_VFR_COMPLETED)
1210 if (i >= IAVF_RESET_WAIT_CNT)
1217 iavf_init_vf(struct rte_eth_dev *dev)
1220 struct iavf_adapter *adapter =
1221 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1222 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1223 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1225 err = iavf_set_mac_type(hw);
1227 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1231 err = iavf_check_vf_reset_done(hw);
1233 PMD_INIT_LOG(ERR, "VF is still resetting");
1237 iavf_init_adminq_parameter(hw);
1238 err = iavf_init_adminq(hw);
1240 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1244 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1246 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1249 if (iavf_check_api_version(adapter) != 0) {
1250 PMD_INIT_LOG(ERR, "check_api version failed");
1254 bufsz = sizeof(struct virtchnl_vf_resource) +
1255 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1256 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1258 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1261 if (iavf_get_vf_resource(adapter) != 0) {
1262 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1265 /* Allocate memort for RSS info */
1266 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1267 vf->rss_key = rte_zmalloc("rss_key",
1268 vf->vf_res->rss_key_size, 0);
1270 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1273 vf->rss_lut = rte_zmalloc("rss_lut",
1274 vf->vf_res->rss_lut_size, 0);
1276 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1281 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1282 if (iavf_get_supported_rxdid(adapter) != 0) {
1283 PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
1288 vf->vf_reset = false;
1292 rte_free(vf->rss_key);
1293 rte_free(vf->rss_lut);
1295 rte_free(vf->vf_res);
1298 rte_free(vf->aq_resp);
1300 iavf_shutdown_adminq(hw);
1305 /* Enable default admin queue interrupt setting */
1307 iavf_enable_irq0(struct iavf_hw *hw)
1309 /* Enable admin queue interrupt trigger */
1310 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
1311 IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
1313 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1314 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1315 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1316 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1318 IAVF_WRITE_FLUSH(hw);
1322 iavf_disable_irq0(struct iavf_hw *hw)
1324 /* Disable all interrupt types */
1325 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
1326 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1327 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1328 IAVF_WRITE_FLUSH(hw);
1332 iavf_dev_interrupt_handler(void *param)
1334 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1335 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1337 iavf_disable_irq0(hw);
1339 iavf_handle_virtchnl_msg(dev);
1341 iavf_enable_irq0(hw);
1345 iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
1346 enum rte_filter_type filter_type,
1347 enum rte_filter_op filter_op,
1355 switch (filter_type) {
1356 case RTE_ETH_FILTER_GENERIC:
1357 if (filter_op != RTE_ETH_FILTER_GET)
1359 *(const void **)arg = &iavf_flow_ops;
1362 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1373 iavf_dev_init(struct rte_eth_dev *eth_dev)
1375 struct iavf_adapter *adapter =
1376 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1377 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1378 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1381 PMD_INIT_FUNC_TRACE();
1383 /* assign ops func pointer */
1384 eth_dev->dev_ops = &iavf_eth_dev_ops;
1385 eth_dev->rx_queue_count = iavf_dev_rxq_count;
1386 eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
1387 eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
1388 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1389 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1390 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1392 /* For secondary processes, we don't initialise any further as primary
1393 * has already done this work. Only check if we need a different RX
1396 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1397 iavf_set_rx_function(eth_dev);
1398 iavf_set_tx_function(eth_dev);
1401 rte_eth_copy_pci_info(eth_dev, pci_dev);
1403 hw->vendor_id = pci_dev->id.vendor_id;
1404 hw->device_id = pci_dev->id.device_id;
1405 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1406 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1407 hw->bus.bus_id = pci_dev->addr.bus;
1408 hw->bus.device = pci_dev->addr.devid;
1409 hw->bus.func = pci_dev->addr.function;
1410 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1411 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1412 adapter->eth_dev = eth_dev;
1413 adapter->stopped = 1;
1415 /* Pass the information to the rte_eth_dev_close() that it should also
1416 * release the private port resources.
1418 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
1420 if (iavf_init_vf(eth_dev) != 0) {
1421 PMD_INIT_LOG(ERR, "Init vf failed");
1425 /* set default ptype table */
1426 adapter->ptype_tbl = iavf_get_default_ptype_table();
1429 eth_dev->data->mac_addrs = rte_zmalloc(
1430 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
1431 if (!eth_dev->data->mac_addrs) {
1432 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1433 " store MAC addresses",
1434 RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1437 /* If the MAC address is not configured by host,
1438 * generate a random one.
1440 if (!rte_is_valid_assigned_ether_addr(
1441 (struct rte_ether_addr *)hw->mac.addr))
1442 rte_eth_random_addr(hw->mac.addr);
1443 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1444 ð_dev->data->mac_addrs[0]);
1446 /* register callback func to eal lib */
1447 rte_intr_callback_register(&pci_dev->intr_handle,
1448 iavf_dev_interrupt_handler,
1451 /* enable uio intr after callback register */
1452 rte_intr_enable(&pci_dev->intr_handle);
1454 /* configure and enable device interrupt */
1455 iavf_enable_irq0(hw);
1457 ret = iavf_flow_init(adapter);
1459 PMD_INIT_LOG(ERR, "Failed to initialize flow");
1467 iavf_dev_close(struct rte_eth_dev *dev)
1469 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1470 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1471 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1472 struct iavf_adapter *adapter =
1473 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1474 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1477 iavf_flow_flush(dev, NULL);
1478 iavf_flow_uninit(adapter);
1479 iavf_shutdown_adminq(hw);
1480 /* disable uio intr before callback unregister */
1481 rte_intr_disable(intr_handle);
1483 /* unregister callback func from eal lib */
1484 rte_intr_callback_unregister(intr_handle,
1485 iavf_dev_interrupt_handler, dev);
1486 iavf_disable_irq0(hw);
1488 dev->dev_ops = NULL;
1489 dev->rx_pkt_burst = NULL;
1490 dev->tx_pkt_burst = NULL;
1492 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1494 rte_free(vf->rss_lut);
1498 rte_free(vf->rss_key);
1503 rte_free(vf->vf_res);
1507 rte_free(vf->aq_resp);
1514 iavf_dev_uninit(struct rte_eth_dev *dev)
1516 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1519 iavf_dev_close(dev);
1525 * Reset VF device only to re-initialize resources in PMD layer
1528 iavf_dev_reset(struct rte_eth_dev *dev)
1532 ret = iavf_dev_uninit(dev);
1536 return iavf_dev_init(dev);
1540 iavf_dcf_cap_check_handler(__rte_unused const char *key,
1541 const char *value, __rte_unused void *opaque)
1543 if (strcmp(value, "dcf"))
1550 iavf_dcf_cap_selected(struct rte_devargs *devargs)
1552 struct rte_kvargs *kvlist;
1553 const char *key = "cap";
1556 if (devargs == NULL)
1559 kvlist = rte_kvargs_parse(devargs->args, NULL);
1563 if (!rte_kvargs_count(kvlist, key))
1566 /* dcf capability selected when there's a key-value pair: cap=dcf */
1567 if (rte_kvargs_process(kvlist, key,
1568 iavf_dcf_cap_check_handler, NULL) < 0)
1574 rte_kvargs_free(kvlist);
1578 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1579 struct rte_pci_device *pci_dev)
1581 if (iavf_dcf_cap_selected(pci_dev->device.devargs))
1584 return rte_eth_dev_pci_generic_probe(pci_dev,
1585 sizeof(struct iavf_adapter), iavf_dev_init);
1588 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1590 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1593 /* Adaptive virtual function driver struct */
1594 static struct rte_pci_driver rte_iavf_pmd = {
1595 .id_table = pci_id_iavf_map,
1596 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1597 .probe = eth_iavf_pci_probe,
1598 .remove = eth_iavf_pci_remove,
1601 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1602 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1603 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1604 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
1605 RTE_LOG_REGISTER(iavf_logtype_init, pmd.net.iavf.init, NOTICE);
1606 RTE_LOG_REGISTER(iavf_logtype_driver, pmd.net.iavf.driver, NOTICE);
1607 #ifdef RTE_LIBRTE_IAVF_DEBUG_RX
1608 RTE_LOG_REGISTER(iavf_logtype_rx, pmd.net.iavf.rx, DEBUG);
1610 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
1611 RTE_LOG_REGISTER(iavf_logtype_tx, pmd.net.iavf.tx, DEBUG);
1613 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_FREE
1614 RTE_LOG_REGISTER(iavf_logtype_tx_free, pmd.net.iavf.tx_free, DEBUG);