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_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,
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,
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,
63 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
64 struct rte_eth_rss_reta_entry64 *reta_conf,
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,
75 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
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,
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);
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 */ },
90 struct rte_iavf_xstats_name_off {
91 char name[RTE_ETH_XSTATS_NAME_SIZE];
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)},
111 #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
112 sizeof(rte_iavf_stats_strings[0]))
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,
160 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
161 struct rte_ether_addr *mc_addrs,
162 uint32_t mc_addrs_num)
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);
169 /* flush previous addresses */
170 err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
175 vf->mc_addrs_num = 0;
178 err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
182 vf->mc_addrs_num = mc_addrs_num;
183 memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
189 iavf_init_rss(struct iavf_adapter *adapter)
191 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
192 struct rte_eth_rss_conf *rss_conf;
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);
200 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
201 PMD_DRV_LOG(DEBUG, "RSS is not supported");
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++)
209 ret = iavf_configure_rss_lut(adapter);
213 /* In IAVF, RSS enablement is set by PF driver. It is not supported
214 * to set based on rss_conf->rss_hf.
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();
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));
227 /* init RSS LUT table */
228 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
233 /* send virtchnnl ops to configure rss*/
234 ret = iavf_configure_rss_lut(adapter);
237 ret = iavf_configure_rss_key(adapter);
245 iavf_dev_configure(struct rte_eth_dev *dev)
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;
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.
256 ad->rx_vec_allowed = true;
257 ad->tx_vec_allowed = true;
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;
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);
267 iavf_disable_vlan_strip(ad);
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");
280 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
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;
286 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
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);
292 /* Check if the jumbo frame and maximum packet length are set
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);
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);
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;
322 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
323 IAVF_WRITE_FLUSH(hw);
329 iavf_init_queues(struct rte_eth_dev *dev)
331 struct iavf_rx_queue **rxq =
332 (struct iavf_rx_queue **)dev->data->rx_queues;
333 int i, ret = IAVF_SUCCESS;
335 for (i = 0; i < dev->data->nb_rx_queues; i++) {
336 if (!rxq[i] || !rxq[i]->q_set)
338 ret = iavf_init_rxq(dev, rxq[i]);
339 if (ret != IAVF_SUCCESS)
342 /* set rx/tx function to vector/scatter/single-segment
343 * according to parameters
345 iavf_set_rx_function(dev);
346 iavf_set_tx_function(dev);
351 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
352 struct rte_intr_handle *intr_handle)
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;
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))
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);
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 */
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;
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);
391 /* If no WB_ON_ITR offload flags, need to set
392 * interrupt for descriptor write back.
394 vf->msix_base = IAVF_MISC_VEC_ID;
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) |
404 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
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;
411 if (!rte_intr_allow_others(intr_handle)) {
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;
419 "vector %u are mapping to all Rx queues",
422 /* If Rx interrupt is reuquired, and we can use
423 * multi interrupts, then the vec is from 1
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;
436 "%u vectors are mapping to %u Rx queues",
437 vf->nb_msix, dev->data->nb_rx_queues);
441 if (iavf_config_irq_map(adapter)) {
442 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
449 iavf_start_queues(struct rte_eth_dev *dev)
451 struct iavf_rx_queue *rxq;
452 struct iavf_tx_queue *txq;
455 for (i = 0; i < dev->data->nb_tx_queues; i++) {
456 txq = dev->data->tx_queues[i];
457 if (txq->tx_deferred_start)
459 if (iavf_dev_tx_queue_start(dev, i) != 0) {
460 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
465 for (i = 0; i < dev->data->nb_rx_queues; i++) {
466 rxq = dev->data->rx_queues[i];
467 if (rxq->rx_deferred_start)
469 if (iavf_dev_rx_queue_start(dev, i) != 0) {
470 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
479 iavf_dev_start(struct rte_eth_dev *dev)
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;
486 PMD_INIT_FUNC_TRACE();
488 adapter->stopped = 0;
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);
494 if (iavf_init_queues(dev) != 0) {
495 PMD_DRV_LOG(ERR, "failed to do Queue init");
499 if (iavf_configure_queues(adapter) != 0) {
500 PMD_DRV_LOG(ERR, "configure queues failed");
504 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
505 PMD_DRV_LOG(ERR, "configure irq failed");
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);
514 /* Set all mac addrs */
515 iavf_add_del_all_mac_addr(adapter, true);
517 /* Set all multicast addresses */
518 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
521 if (iavf_start_queues(dev) != 0) {
522 PMD_DRV_LOG(ERR, "enable queues failed");
529 iavf_add_del_all_mac_addr(adapter, false);
535 iavf_dev_stop(struct rte_eth_dev *dev)
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;
542 PMD_INIT_FUNC_TRACE();
544 if (adapter->stopped == 1)
547 iavf_stop_queues(dev);
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;
557 /* remove all mac addrs */
558 iavf_add_del_all_mac_addr(adapter, false);
560 /* remove all multicast addresses */
561 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
564 adapter->stopped = 1;
568 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
570 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
572 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
573 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
574 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
575 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
576 dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
577 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
578 dev_info->hash_key_size = vf->vf_res->rss_key_size;
579 dev_info->reta_size = vf->vf_res->rss_lut_size;
580 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
581 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
582 dev_info->rx_offload_capa =
583 DEV_RX_OFFLOAD_VLAN_STRIP |
584 DEV_RX_OFFLOAD_QINQ_STRIP |
585 DEV_RX_OFFLOAD_IPV4_CKSUM |
586 DEV_RX_OFFLOAD_UDP_CKSUM |
587 DEV_RX_OFFLOAD_TCP_CKSUM |
588 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
589 DEV_RX_OFFLOAD_SCATTER |
590 DEV_RX_OFFLOAD_JUMBO_FRAME |
591 DEV_RX_OFFLOAD_VLAN_FILTER |
592 DEV_RX_OFFLOAD_RSS_HASH;
593 dev_info->tx_offload_capa =
594 DEV_TX_OFFLOAD_VLAN_INSERT |
595 DEV_TX_OFFLOAD_QINQ_INSERT |
596 DEV_TX_OFFLOAD_IPV4_CKSUM |
597 DEV_TX_OFFLOAD_UDP_CKSUM |
598 DEV_TX_OFFLOAD_TCP_CKSUM |
599 DEV_TX_OFFLOAD_SCTP_CKSUM |
600 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
601 DEV_TX_OFFLOAD_TCP_TSO |
602 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
603 DEV_TX_OFFLOAD_GRE_TNL_TSO |
604 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
605 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
606 DEV_TX_OFFLOAD_MULTI_SEGS;
608 dev_info->default_rxconf = (struct rte_eth_rxconf) {
609 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
614 dev_info->default_txconf = (struct rte_eth_txconf) {
615 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
616 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
620 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
621 .nb_max = IAVF_MAX_RING_DESC,
622 .nb_min = IAVF_MIN_RING_DESC,
623 .nb_align = IAVF_ALIGN_RING_DESC,
626 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
627 .nb_max = IAVF_MAX_RING_DESC,
628 .nb_min = IAVF_MIN_RING_DESC,
629 .nb_align = IAVF_ALIGN_RING_DESC,
635 static const uint32_t *
636 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
638 static const uint32_t ptypes[] = {
640 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
643 RTE_PTYPE_L4_NONFRAG,
653 iavf_dev_link_update(struct rte_eth_dev *dev,
654 __rte_unused int wait_to_complete)
656 struct rte_eth_link new_link;
657 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
659 memset(&new_link, 0, sizeof(new_link));
661 /* Only read status info stored in VF, and the info is updated
662 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
664 switch (vf->link_speed) {
666 new_link.link_speed = ETH_SPEED_NUM_10M;
669 new_link.link_speed = ETH_SPEED_NUM_100M;
672 new_link.link_speed = ETH_SPEED_NUM_1G;
675 new_link.link_speed = ETH_SPEED_NUM_10G;
678 new_link.link_speed = ETH_SPEED_NUM_20G;
681 new_link.link_speed = ETH_SPEED_NUM_25G;
684 new_link.link_speed = ETH_SPEED_NUM_40G;
687 new_link.link_speed = ETH_SPEED_NUM_50G;
690 new_link.link_speed = ETH_SPEED_NUM_100G;
693 new_link.link_speed = ETH_SPEED_NUM_NONE;
697 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
698 new_link.link_status = vf->link_up ? ETH_LINK_UP :
700 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
701 ETH_LINK_SPEED_FIXED);
703 return rte_eth_linkstatus_set(dev, &new_link);
707 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
709 struct iavf_adapter *adapter =
710 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
711 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
713 return iavf_config_promisc(adapter,
714 true, vf->promisc_multicast_enabled);
718 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
720 struct iavf_adapter *adapter =
721 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
722 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
724 return iavf_config_promisc(adapter,
725 false, vf->promisc_multicast_enabled);
729 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
731 struct iavf_adapter *adapter =
732 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
733 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
735 return iavf_config_promisc(adapter,
736 vf->promisc_unicast_enabled, true);
740 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
742 struct iavf_adapter *adapter =
743 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
744 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
746 return iavf_config_promisc(adapter,
747 vf->promisc_unicast_enabled, false);
751 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
752 __rte_unused uint32_t index,
753 __rte_unused uint32_t pool)
755 struct iavf_adapter *adapter =
756 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
757 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
760 if (rte_is_zero_ether_addr(addr)) {
761 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
765 err = iavf_add_del_eth_addr(adapter, addr, true);
767 PMD_DRV_LOG(ERR, "fail to add MAC address");
777 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
779 struct iavf_adapter *adapter =
780 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
781 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
782 struct rte_ether_addr *addr;
785 addr = &dev->data->mac_addrs[index];
787 err = iavf_add_del_eth_addr(adapter, addr, false);
789 PMD_DRV_LOG(ERR, "fail to delete MAC address");
795 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
797 struct iavf_adapter *adapter =
798 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
799 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
802 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
805 err = iavf_add_del_vlan(adapter, vlan_id, on);
812 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
814 struct iavf_adapter *adapter =
815 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
816 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
817 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
820 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
823 /* Vlan stripping setting */
824 if (mask & ETH_VLAN_STRIP_MASK) {
825 /* Enable or disable VLAN stripping */
826 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
827 err = iavf_enable_vlan_strip(adapter);
829 err = iavf_disable_vlan_strip(adapter);
838 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
839 struct rte_eth_rss_reta_entry64 *reta_conf,
842 struct iavf_adapter *adapter =
843 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
844 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
846 uint16_t i, idx, shift;
849 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
852 if (reta_size != vf->vf_res->rss_lut_size) {
853 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
854 "(%d) doesn't match the number of hardware can "
855 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
859 lut = rte_zmalloc("rss_lut", reta_size, 0);
861 PMD_DRV_LOG(ERR, "No memory can be allocated");
864 /* store the old lut table temporarily */
865 rte_memcpy(lut, vf->rss_lut, reta_size);
867 for (i = 0; i < reta_size; i++) {
868 idx = i / RTE_RETA_GROUP_SIZE;
869 shift = i % RTE_RETA_GROUP_SIZE;
870 if (reta_conf[idx].mask & (1ULL << shift))
871 lut[i] = reta_conf[idx].reta[shift];
874 rte_memcpy(vf->rss_lut, lut, reta_size);
875 /* send virtchnnl ops to configure rss*/
876 ret = iavf_configure_rss_lut(adapter);
877 if (ret) /* revert back */
878 rte_memcpy(vf->rss_lut, lut, reta_size);
885 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
886 struct rte_eth_rss_reta_entry64 *reta_conf,
889 struct iavf_adapter *adapter =
890 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
891 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
892 uint16_t i, idx, shift;
894 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
897 if (reta_size != vf->vf_res->rss_lut_size) {
898 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
899 "(%d) doesn't match the number of hardware can "
900 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
904 for (i = 0; i < reta_size; i++) {
905 idx = i / RTE_RETA_GROUP_SIZE;
906 shift = i % RTE_RETA_GROUP_SIZE;
907 if (reta_conf[idx].mask & (1ULL << shift))
908 reta_conf[idx].reta[shift] = vf->rss_lut[i];
915 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
916 struct rte_eth_rss_conf *rss_conf)
918 struct iavf_adapter *adapter =
919 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
920 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
922 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
925 /* HENA setting, it is enabled by default, no change */
926 if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
927 PMD_DRV_LOG(DEBUG, "No key to be configured");
929 } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
930 PMD_DRV_LOG(ERR, "The size of hash key configured "
931 "(%d) doesn't match the size of hardware can "
932 "support (%d)", rss_conf->rss_key_len,
933 vf->vf_res->rss_key_size);
937 rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
939 return iavf_configure_rss_key(adapter);
943 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
944 struct rte_eth_rss_conf *rss_conf)
946 struct iavf_adapter *adapter =
947 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
948 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
950 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
953 /* Just set it to default value now. */
954 rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
956 if (!rss_conf->rss_key)
959 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
960 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
966 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
968 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
971 if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
974 /* mtu setting is forbidden if port is start */
975 if (dev->data->dev_started) {
976 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
980 if (frame_size > RTE_ETHER_MAX_LEN)
981 dev->data->dev_conf.rxmode.offloads |=
982 DEV_RX_OFFLOAD_JUMBO_FRAME;
984 dev->data->dev_conf.rxmode.offloads &=
985 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
987 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
993 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
994 struct rte_ether_addr *mac_addr)
996 struct iavf_adapter *adapter =
997 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
998 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
999 struct rte_ether_addr *perm_addr, *old_addr;
1002 old_addr = (struct rte_ether_addr *)hw->mac.addr;
1003 perm_addr = (struct rte_ether_addr *)hw->mac.perm_addr;
1005 /* If the MAC address is configured by host, skip the setting */
1006 if (rte_is_valid_assigned_ether_addr(perm_addr))
1009 ret = iavf_add_del_eth_addr(adapter, old_addr, false);
1011 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1012 " %02X:%02X:%02X:%02X:%02X:%02X",
1013 old_addr->addr_bytes[0],
1014 old_addr->addr_bytes[1],
1015 old_addr->addr_bytes[2],
1016 old_addr->addr_bytes[3],
1017 old_addr->addr_bytes[4],
1018 old_addr->addr_bytes[5]);
1020 ret = iavf_add_del_eth_addr(adapter, mac_addr, true);
1022 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1023 " %02X:%02X:%02X:%02X:%02X:%02X",
1024 mac_addr->addr_bytes[0],
1025 mac_addr->addr_bytes[1],
1026 mac_addr->addr_bytes[2],
1027 mac_addr->addr_bytes[3],
1028 mac_addr->addr_bytes[4],
1029 mac_addr->addr_bytes[5]);
1034 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1039 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1041 if (*stat >= *offset)
1042 *stat = *stat - *offset;
1044 *stat = (uint64_t)((*stat +
1045 ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1047 *stat &= IAVF_48_BIT_MASK;
1051 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1053 if (*stat >= *offset)
1054 *stat = (uint64_t)(*stat - *offset);
1056 *stat = (uint64_t)((*stat +
1057 ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1061 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1063 struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1065 iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1066 iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1067 iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1068 iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1069 iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1070 iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1071 iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1072 iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1073 iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1074 iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1075 iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1079 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1081 struct iavf_adapter *adapter =
1082 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1083 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1084 struct iavf_vsi *vsi = &vf->vsi;
1085 struct virtchnl_eth_stats *pstats = NULL;
1088 ret = iavf_query_stats(adapter, &pstats);
1090 iavf_update_stats(vsi, pstats);
1091 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1092 pstats->rx_broadcast - pstats->rx_discards;
1093 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1095 stats->imissed = pstats->rx_discards;
1096 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1097 stats->ibytes = pstats->rx_bytes;
1098 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
1099 stats->obytes = pstats->tx_bytes;
1101 PMD_DRV_LOG(ERR, "Get statistics failed");
1107 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1110 struct iavf_adapter *adapter =
1111 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1112 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1113 struct iavf_vsi *vsi = &vf->vsi;
1114 struct virtchnl_eth_stats *pstats = NULL;
1116 /* read stat values to clear hardware registers */
1117 ret = iavf_query_stats(adapter, &pstats);
1121 /* set stats offset base on current values */
1122 vsi->eth_stats_offset = *pstats;
1127 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1128 struct rte_eth_xstat_name *xstats_names,
1129 __rte_unused unsigned int limit)
1133 if (xstats_names != NULL)
1134 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1135 snprintf(xstats_names[i].name,
1136 sizeof(xstats_names[i].name),
1137 "%s", rte_iavf_stats_strings[i].name);
1139 return IAVF_NB_XSTATS;
1142 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1143 struct rte_eth_xstat *xstats, unsigned int n)
1147 struct iavf_adapter *adapter =
1148 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1149 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1150 struct iavf_vsi *vsi = &vf->vsi;
1151 struct virtchnl_eth_stats *pstats = NULL;
1153 if (n < IAVF_NB_XSTATS)
1154 return IAVF_NB_XSTATS;
1156 ret = iavf_query_stats(adapter, &pstats);
1163 iavf_update_stats(vsi, pstats);
1165 /* loop over xstats array and values from pstats */
1166 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1168 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1169 rte_iavf_stats_strings[i].offset);
1172 return IAVF_NB_XSTATS;
1177 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1179 struct iavf_adapter *adapter =
1180 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1181 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1182 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1185 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1186 if (msix_intr == IAVF_MISC_VEC_ID) {
1187 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1188 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1189 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1190 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1191 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1194 IAVF_VFINT_DYN_CTLN1
1195 (msix_intr - IAVF_RX_VEC_START),
1196 IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1197 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1198 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1201 IAVF_WRITE_FLUSH(hw);
1203 rte_intr_ack(&pci_dev->intr_handle);
1209 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1211 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1212 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1215 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1216 if (msix_intr == IAVF_MISC_VEC_ID) {
1217 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1222 IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1225 IAVF_WRITE_FLUSH(hw);
1230 iavf_check_vf_reset_done(struct iavf_hw *hw)
1234 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1235 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1236 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1237 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1238 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1239 reset == VIRTCHNL_VFR_COMPLETED)
1244 if (i >= IAVF_RESET_WAIT_CNT)
1251 iavf_init_vf(struct rte_eth_dev *dev)
1254 struct iavf_adapter *adapter =
1255 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1256 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1257 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1259 err = iavf_set_mac_type(hw);
1261 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1265 err = iavf_check_vf_reset_done(hw);
1267 PMD_INIT_LOG(ERR, "VF is still resetting");
1271 iavf_init_adminq_parameter(hw);
1272 err = iavf_init_adminq(hw);
1274 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1278 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1280 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1283 if (iavf_check_api_version(adapter) != 0) {
1284 PMD_INIT_LOG(ERR, "check_api version failed");
1288 bufsz = sizeof(struct virtchnl_vf_resource) +
1289 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1290 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1292 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1295 if (iavf_get_vf_resource(adapter) != 0) {
1296 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1299 /* Allocate memort for RSS info */
1300 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1301 vf->rss_key = rte_zmalloc("rss_key",
1302 vf->vf_res->rss_key_size, 0);
1304 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1307 vf->rss_lut = rte_zmalloc("rss_lut",
1308 vf->vf_res->rss_lut_size, 0);
1310 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1315 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1316 if (iavf_get_supported_rxdid(adapter) != 0) {
1317 PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
1324 rte_free(vf->rss_key);
1325 rte_free(vf->rss_lut);
1327 rte_free(vf->vf_res);
1330 rte_free(vf->aq_resp);
1332 iavf_shutdown_adminq(hw);
1337 /* Enable default admin queue interrupt setting */
1339 iavf_enable_irq0(struct iavf_hw *hw)
1341 /* Enable admin queue interrupt trigger */
1342 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
1343 IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
1345 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1346 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1347 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1348 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1350 IAVF_WRITE_FLUSH(hw);
1354 iavf_disable_irq0(struct iavf_hw *hw)
1356 /* Disable all interrupt types */
1357 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
1358 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1359 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1360 IAVF_WRITE_FLUSH(hw);
1364 iavf_dev_interrupt_handler(void *param)
1366 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1367 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1369 iavf_disable_irq0(hw);
1371 iavf_handle_virtchnl_msg(dev);
1373 iavf_enable_irq0(hw);
1377 iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
1378 enum rte_filter_type filter_type,
1379 enum rte_filter_op filter_op,
1387 switch (filter_type) {
1388 case RTE_ETH_FILTER_GENERIC:
1389 if (filter_op != RTE_ETH_FILTER_GET)
1391 *(const void **)arg = &iavf_flow_ops;
1394 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1405 iavf_dev_init(struct rte_eth_dev *eth_dev)
1407 struct iavf_adapter *adapter =
1408 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1409 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1410 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1413 PMD_INIT_FUNC_TRACE();
1415 /* assign ops func pointer */
1416 eth_dev->dev_ops = &iavf_eth_dev_ops;
1417 eth_dev->rx_queue_count = iavf_dev_rxq_count;
1418 eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
1419 eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
1420 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1421 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1422 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1424 /* For secondary processes, we don't initialise any further as primary
1425 * has already done this work. Only check if we need a different RX
1428 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1429 iavf_set_rx_function(eth_dev);
1430 iavf_set_tx_function(eth_dev);
1433 rte_eth_copy_pci_info(eth_dev, pci_dev);
1435 hw->vendor_id = pci_dev->id.vendor_id;
1436 hw->device_id = pci_dev->id.device_id;
1437 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1438 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1439 hw->bus.bus_id = pci_dev->addr.bus;
1440 hw->bus.device = pci_dev->addr.devid;
1441 hw->bus.func = pci_dev->addr.function;
1442 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1443 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1444 adapter->eth_dev = eth_dev;
1445 adapter->stopped = 1;
1447 if (iavf_init_vf(eth_dev) != 0) {
1448 PMD_INIT_LOG(ERR, "Init vf failed");
1452 /* set default ptype table */
1453 adapter->ptype_tbl = iavf_get_default_ptype_table();
1456 eth_dev->data->mac_addrs = rte_zmalloc(
1457 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
1458 if (!eth_dev->data->mac_addrs) {
1459 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1460 " store MAC addresses",
1461 RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1464 /* If the MAC address is not configured by host,
1465 * generate a random one.
1467 if (!rte_is_valid_assigned_ether_addr(
1468 (struct rte_ether_addr *)hw->mac.addr))
1469 rte_eth_random_addr(hw->mac.addr);
1470 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1471 ð_dev->data->mac_addrs[0]);
1473 /* register callback func to eal lib */
1474 rte_intr_callback_register(&pci_dev->intr_handle,
1475 iavf_dev_interrupt_handler,
1478 /* enable uio intr after callback register */
1479 rte_intr_enable(&pci_dev->intr_handle);
1481 /* configure and enable device interrupt */
1482 iavf_enable_irq0(hw);
1484 ret = iavf_flow_init(adapter);
1486 PMD_INIT_LOG(ERR, "Failed to initialize flow");
1494 iavf_dev_close(struct rte_eth_dev *dev)
1496 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1497 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1498 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1499 struct iavf_adapter *adapter =
1500 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1501 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1503 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1507 iavf_flow_flush(dev, NULL);
1508 iavf_flow_uninit(adapter);
1511 * disable promiscuous mode before reset vf
1512 * it is a workaround solution when work with kernel driver
1513 * and it is not the normal way
1515 if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
1516 iavf_config_promisc(adapter, false, false);
1518 iavf_shutdown_adminq(hw);
1519 /* disable uio intr before callback unregister */
1520 rte_intr_disable(intr_handle);
1522 /* unregister callback func from eal lib */
1523 rte_intr_callback_unregister(intr_handle,
1524 iavf_dev_interrupt_handler, dev);
1525 iavf_disable_irq0(hw);
1527 dev->dev_ops = NULL;
1528 dev->rx_pkt_burst = NULL;
1529 dev->tx_pkt_burst = NULL;
1531 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1533 rte_free(vf->rss_lut);
1537 rte_free(vf->rss_key);
1542 rte_free(vf->vf_res);
1546 rte_free(vf->aq_resp);
1549 vf->vf_reset = false;
1555 iavf_dev_uninit(struct rte_eth_dev *dev)
1557 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1560 iavf_dev_close(dev);
1566 * Reset VF device only to re-initialize resources in PMD layer
1569 iavf_dev_reset(struct rte_eth_dev *dev)
1573 ret = iavf_dev_uninit(dev);
1577 return iavf_dev_init(dev);
1581 iavf_dcf_cap_check_handler(__rte_unused const char *key,
1582 const char *value, __rte_unused void *opaque)
1584 if (strcmp(value, "dcf"))
1591 iavf_dcf_cap_selected(struct rte_devargs *devargs)
1593 struct rte_kvargs *kvlist;
1594 const char *key = "cap";
1597 if (devargs == NULL)
1600 kvlist = rte_kvargs_parse(devargs->args, NULL);
1604 if (!rte_kvargs_count(kvlist, key))
1607 /* dcf capability selected when there's a key-value pair: cap=dcf */
1608 if (rte_kvargs_process(kvlist, key,
1609 iavf_dcf_cap_check_handler, NULL) < 0)
1615 rte_kvargs_free(kvlist);
1619 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1620 struct rte_pci_device *pci_dev)
1622 if (iavf_dcf_cap_selected(pci_dev->device.devargs))
1625 return rte_eth_dev_pci_generic_probe(pci_dev,
1626 sizeof(struct iavf_adapter), iavf_dev_init);
1629 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1631 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1634 /* Adaptive virtual function driver struct */
1635 static struct rte_pci_driver rte_iavf_pmd = {
1636 .id_table = pci_id_iavf_map,
1637 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1638 .probe = eth_iavf_pci_probe,
1639 .remove = eth_iavf_pci_remove,
1642 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1643 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1644 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1645 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
1646 RTE_LOG_REGISTER(iavf_logtype_init, pmd.net.iavf.init, NOTICE);
1647 RTE_LOG_REGISTER(iavf_logtype_driver, pmd.net.iavf.driver, NOTICE);
1648 #ifdef RTE_LIBRTE_IAVF_DEBUG_RX
1649 RTE_LOG_REGISTER(iavf_logtype_rx, pmd.net.iavf.rx, DEBUG);
1651 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
1652 RTE_LOG_REGISTER(iavf_logtype_tx, pmd.net.iavf.tx, DEBUG);
1654 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_FREE
1655 RTE_LOG_REGISTER(iavf_logtype_tx_free, pmd.net.iavf.tx_free, DEBUG);