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 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,
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 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
171 "can't add more than a limited number (%u) of addresses.",
172 (uint32_t)IAVF_NUM_MACADDR_MAX);
176 /* flush previous addresses */
177 err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
183 err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
186 /* if adding mac address list fails, should add the previous
189 ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
190 vf->mc_addrs_num, true);
194 vf->mc_addrs_num = mc_addrs_num;
196 mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
203 iavf_init_rss(struct iavf_adapter *adapter)
205 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
206 struct rte_eth_rss_conf *rss_conf;
210 rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
211 nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
212 vf->max_rss_qregion);
214 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
215 PMD_DRV_LOG(DEBUG, "RSS is not supported");
218 if (adapter->eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
219 PMD_DRV_LOG(WARNING, "RSS is enabled by PF by default");
220 /* set all lut items to default queue */
221 for (i = 0; i < vf->vf_res->rss_lut_size; i++)
223 ret = iavf_configure_rss_lut(adapter);
227 /* In IAVF, RSS enablement is set by PF driver. It is not supported
228 * to set based on rss_conf->rss_hf.
231 /* configure RSS key */
232 if (!rss_conf->rss_key) {
233 /* Calculate the default hash key */
234 for (i = 0; i <= vf->vf_res->rss_key_size; i++)
235 vf->rss_key[i] = (uint8_t)rte_rand();
237 rte_memcpy(vf->rss_key, rss_conf->rss_key,
238 RTE_MIN(rss_conf->rss_key_len,
239 vf->vf_res->rss_key_size));
241 /* init RSS LUT table */
242 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
247 /* send virtchnnl ops to configure rss*/
248 ret = iavf_configure_rss_lut(adapter);
251 ret = iavf_configure_rss_key(adapter);
259 iavf_queues_req_reset(struct rte_eth_dev *dev, uint16_t num)
261 struct iavf_adapter *ad =
262 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
263 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
266 ret = iavf_request_queues(ad, num);
268 PMD_DRV_LOG(ERR, "request queues from PF failed");
271 PMD_DRV_LOG(INFO, "change queue pairs from %u to %u",
272 vf->vsi_res->num_queue_pairs, num);
274 ret = iavf_dev_reset(dev);
276 PMD_DRV_LOG(ERR, "vf reset failed");
284 iavf_dev_configure(struct rte_eth_dev *dev)
286 struct iavf_adapter *ad =
287 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
288 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
289 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
290 uint16_t num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
291 dev->data->nb_tx_queues);
294 ad->rx_bulk_alloc_allowed = true;
295 /* Initialize to TRUE. If any of Rx queues doesn't meet the
296 * vector Rx/Tx preconditions, it will be reset.
298 ad->rx_vec_allowed = true;
299 ad->tx_vec_allowed = true;
301 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
302 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
304 /* Large VF setting */
305 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT) {
306 if (!(vf->vf_res->vf_cap_flags &
307 VIRTCHNL_VF_LARGE_NUM_QPAIRS)) {
308 PMD_DRV_LOG(ERR, "large VF is not supported");
312 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_LV) {
313 PMD_DRV_LOG(ERR, "queue pairs number cannot be larger than %u",
314 IAVF_MAX_NUM_QUEUES_LV);
318 ret = iavf_queues_req_reset(dev, num_queue_pairs);
322 ret = iavf_get_max_rss_queue_region(ad);
324 PMD_INIT_LOG(ERR, "get max rss queue region failed");
328 vf->lv_enabled = true;
330 /* Check if large VF is already enabled. If so, disable and
331 * release redundant queue resource.
333 if (vf->lv_enabled) {
334 ret = iavf_queues_req_reset(dev, num_queue_pairs);
338 vf->lv_enabled = false;
340 /* if large VF is not required, use default rss queue region */
341 vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
344 /* Vlan stripping setting */
345 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
346 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
347 iavf_enable_vlan_strip(ad);
349 iavf_disable_vlan_strip(ad);
352 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
353 if (iavf_init_rss(ad) != 0) {
354 PMD_DRV_LOG(ERR, "configure rss failed");
362 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
364 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
365 struct rte_eth_dev_data *dev_data = dev->data;
366 uint16_t buf_size, max_pkt_len, len;
368 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
370 /* Calculate the maximum packet length allowed */
371 len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
372 max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
374 /* Check if the jumbo frame and maximum packet length are set
377 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
378 if (max_pkt_len <= RTE_ETHER_MAX_LEN ||
379 max_pkt_len > IAVF_FRAME_SIZE_MAX) {
380 PMD_DRV_LOG(ERR, "maximum packet length must be "
381 "larger than %u and smaller than %u, "
382 "as jumbo frame is enabled",
383 (uint32_t)RTE_ETHER_MAX_LEN,
384 (uint32_t)IAVF_FRAME_SIZE_MAX);
388 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
389 max_pkt_len > RTE_ETHER_MAX_LEN) {
390 PMD_DRV_LOG(ERR, "maximum packet length must be "
391 "larger than %u and smaller than %u, "
392 "as jumbo frame is disabled",
393 (uint32_t)RTE_ETHER_MIN_LEN,
394 (uint32_t)RTE_ETHER_MAX_LEN);
399 rxq->max_pkt_len = max_pkt_len;
400 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
401 rxq->max_pkt_len > buf_size) {
402 dev_data->scattered_rx = 1;
404 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
405 IAVF_WRITE_FLUSH(hw);
411 iavf_init_queues(struct rte_eth_dev *dev)
413 struct iavf_rx_queue **rxq =
414 (struct iavf_rx_queue **)dev->data->rx_queues;
415 int i, ret = IAVF_SUCCESS;
417 for (i = 0; i < dev->data->nb_rx_queues; i++) {
418 if (!rxq[i] || !rxq[i]->q_set)
420 ret = iavf_init_rxq(dev, rxq[i]);
421 if (ret != IAVF_SUCCESS)
424 /* set rx/tx function to vector/scatter/single-segment
425 * according to parameters
427 iavf_set_rx_function(dev);
428 iavf_set_tx_function(dev);
433 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
434 struct rte_intr_handle *intr_handle)
436 struct iavf_adapter *adapter =
437 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
438 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
439 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
440 struct iavf_qv_map *qv_map;
441 uint16_t interval, i;
444 if (rte_intr_cap_multiple(intr_handle) &&
445 dev->data->dev_conf.intr_conf.rxq) {
446 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
450 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
451 intr_handle->intr_vec =
452 rte_zmalloc("intr_vec",
453 dev->data->nb_rx_queues * sizeof(int), 0);
454 if (!intr_handle->intr_vec) {
455 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
456 dev->data->nb_rx_queues);
461 qv_map = rte_zmalloc("qv_map",
462 dev->data->nb_rx_queues * sizeof(struct iavf_qv_map), 0);
464 PMD_DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
465 dev->data->nb_rx_queues);
469 if (!dev->data->dev_conf.intr_conf.rxq ||
470 !rte_intr_dp_is_en(intr_handle)) {
471 /* Rx interrupt disabled, Map interrupt only for writeback */
473 if (vf->vf_res->vf_cap_flags &
474 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
475 /* If WB_ON_ITR supports, enable it */
476 vf->msix_base = IAVF_RX_VEC_START;
478 IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
479 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK |
480 IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
482 /* If no WB_ON_ITR offload flags, need to set
483 * interrupt for descriptor write back.
485 vf->msix_base = IAVF_MISC_VEC_ID;
488 interval = iavf_calc_itr_interval(
489 IAVF_QUEUE_ITR_INTERVAL_MAX);
490 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
491 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
492 (IAVF_ITR_INDEX_DEFAULT <<
493 IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
495 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
497 IAVF_WRITE_FLUSH(hw);
498 /* map all queues to the same interrupt */
499 for (i = 0; i < dev->data->nb_rx_queues; i++) {
500 qv_map[i].queue_id = i;
501 qv_map[i].vector_id = vf->msix_base;
505 if (!rte_intr_allow_others(intr_handle)) {
507 vf->msix_base = IAVF_MISC_VEC_ID;
508 for (i = 0; i < dev->data->nb_rx_queues; i++) {
509 qv_map[i].queue_id = i;
510 qv_map[i].vector_id = vf->msix_base;
511 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
515 "vector %u are mapping to all Rx queues",
518 /* If Rx interrupt is reuquired, and we can use
519 * multi interrupts, then the vec is from 1
521 vf->nb_msix = RTE_MIN(vf->vf_res->max_vectors,
522 intr_handle->nb_efd);
523 vf->msix_base = IAVF_RX_VEC_START;
524 vec = IAVF_RX_VEC_START;
525 for (i = 0; i < dev->data->nb_rx_queues; i++) {
526 qv_map[i].queue_id = i;
527 qv_map[i].vector_id = vec;
528 intr_handle->intr_vec[i] = vec++;
529 if (vec >= vf->nb_msix)
530 vec = IAVF_RX_VEC_START;
534 "%u vectors are mapping to %u Rx queues",
535 vf->nb_msix, dev->data->nb_rx_queues);
539 if (!vf->lv_enabled) {
540 if (iavf_config_irq_map(adapter)) {
541 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
545 uint16_t num_qv_maps = dev->data->nb_rx_queues;
548 while (num_qv_maps > IAVF_IRQ_MAP_NUM_PER_BUF) {
549 if (iavf_config_irq_map_lv(adapter,
550 IAVF_IRQ_MAP_NUM_PER_BUF, index)) {
551 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
554 num_qv_maps -= IAVF_IRQ_MAP_NUM_PER_BUF;
555 index += IAVF_IRQ_MAP_NUM_PER_BUF;
558 if (iavf_config_irq_map_lv(adapter, num_qv_maps, index)) {
559 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
567 iavf_start_queues(struct rte_eth_dev *dev)
569 struct iavf_rx_queue *rxq;
570 struct iavf_tx_queue *txq;
573 for (i = 0; i < dev->data->nb_tx_queues; i++) {
574 txq = dev->data->tx_queues[i];
575 if (txq->tx_deferred_start)
577 if (iavf_dev_tx_queue_start(dev, i) != 0) {
578 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
583 for (i = 0; i < dev->data->nb_rx_queues; i++) {
584 rxq = dev->data->rx_queues[i];
585 if (rxq->rx_deferred_start)
587 if (iavf_dev_rx_queue_start(dev, i) != 0) {
588 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
597 iavf_dev_start(struct rte_eth_dev *dev)
599 struct iavf_adapter *adapter =
600 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
601 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
602 struct rte_intr_handle *intr_handle = dev->intr_handle;
603 uint16_t num_queue_pairs;
606 PMD_INIT_FUNC_TRACE();
608 adapter->stopped = 0;
610 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
611 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
612 dev->data->nb_tx_queues);
613 num_queue_pairs = vf->num_queue_pairs;
615 if (iavf_init_queues(dev) != 0) {
616 PMD_DRV_LOG(ERR, "failed to do Queue init");
620 /* If needed, send configure queues msg multiple times to make the
621 * adminq buffer length smaller than the 4K limitation.
623 while (num_queue_pairs > IAVF_CFG_Q_NUM_PER_BUF) {
624 if (iavf_configure_queues(adapter,
625 IAVF_CFG_Q_NUM_PER_BUF, index) != 0) {
626 PMD_DRV_LOG(ERR, "configure queues failed");
629 num_queue_pairs -= IAVF_CFG_Q_NUM_PER_BUF;
630 index += IAVF_CFG_Q_NUM_PER_BUF;
633 if (iavf_configure_queues(adapter, num_queue_pairs, index) != 0) {
634 PMD_DRV_LOG(ERR, "configure queues failed");
638 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
639 PMD_DRV_LOG(ERR, "configure irq failed");
642 /* re-enable intr again, because efd assign may change */
643 if (dev->data->dev_conf.intr_conf.rxq != 0) {
644 rte_intr_disable(intr_handle);
645 rte_intr_enable(intr_handle);
648 /* Set all mac addrs */
649 iavf_add_del_all_mac_addr(adapter, true);
651 /* Set all multicast addresses */
652 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
655 if (iavf_start_queues(dev) != 0) {
656 PMD_DRV_LOG(ERR, "enable queues failed");
663 iavf_add_del_all_mac_addr(adapter, false);
669 iavf_dev_stop(struct rte_eth_dev *dev)
671 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
672 struct iavf_adapter *adapter =
673 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
674 struct rte_intr_handle *intr_handle = dev->intr_handle;
676 PMD_INIT_FUNC_TRACE();
678 if (adapter->stopped == 1)
681 iavf_stop_queues(dev);
683 /* Disable the interrupt for Rx */
684 rte_intr_efd_disable(intr_handle);
685 /* Rx interrupt vector mapping free */
686 if (intr_handle->intr_vec) {
687 rte_free(intr_handle->intr_vec);
688 intr_handle->intr_vec = NULL;
691 /* remove all mac addrs */
692 iavf_add_del_all_mac_addr(adapter, false);
694 /* remove all multicast addresses */
695 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
698 adapter->stopped = 1;
699 dev->data->dev_started = 0;
705 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
707 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
709 dev_info->max_rx_queues = IAVF_MAX_NUM_QUEUES_LV;
710 dev_info->max_tx_queues = IAVF_MAX_NUM_QUEUES_LV;
711 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
712 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
713 dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
714 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
715 dev_info->hash_key_size = vf->vf_res->rss_key_size;
716 dev_info->reta_size = vf->vf_res->rss_lut_size;
717 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
718 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
719 dev_info->rx_offload_capa =
720 DEV_RX_OFFLOAD_VLAN_STRIP |
721 DEV_RX_OFFLOAD_QINQ_STRIP |
722 DEV_RX_OFFLOAD_IPV4_CKSUM |
723 DEV_RX_OFFLOAD_UDP_CKSUM |
724 DEV_RX_OFFLOAD_TCP_CKSUM |
725 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
726 DEV_RX_OFFLOAD_SCATTER |
727 DEV_RX_OFFLOAD_JUMBO_FRAME |
728 DEV_RX_OFFLOAD_VLAN_FILTER |
729 DEV_RX_OFFLOAD_RSS_HASH;
730 dev_info->tx_offload_capa =
731 DEV_TX_OFFLOAD_VLAN_INSERT |
732 DEV_TX_OFFLOAD_QINQ_INSERT |
733 DEV_TX_OFFLOAD_IPV4_CKSUM |
734 DEV_TX_OFFLOAD_UDP_CKSUM |
735 DEV_TX_OFFLOAD_TCP_CKSUM |
736 DEV_TX_OFFLOAD_SCTP_CKSUM |
737 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
738 DEV_TX_OFFLOAD_TCP_TSO |
739 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
740 DEV_TX_OFFLOAD_GRE_TNL_TSO |
741 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
742 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
743 DEV_TX_OFFLOAD_MULTI_SEGS;
745 dev_info->default_rxconf = (struct rte_eth_rxconf) {
746 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
751 dev_info->default_txconf = (struct rte_eth_txconf) {
752 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
753 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
757 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
758 .nb_max = IAVF_MAX_RING_DESC,
759 .nb_min = IAVF_MIN_RING_DESC,
760 .nb_align = IAVF_ALIGN_RING_DESC,
763 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
764 .nb_max = IAVF_MAX_RING_DESC,
765 .nb_min = IAVF_MIN_RING_DESC,
766 .nb_align = IAVF_ALIGN_RING_DESC,
772 static const uint32_t *
773 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
775 static const uint32_t ptypes[] = {
777 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
780 RTE_PTYPE_L4_NONFRAG,
790 iavf_dev_link_update(struct rte_eth_dev *dev,
791 __rte_unused int wait_to_complete)
793 struct rte_eth_link new_link;
794 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
796 memset(&new_link, 0, sizeof(new_link));
798 /* Only read status info stored in VF, and the info is updated
799 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
801 switch (vf->link_speed) {
803 new_link.link_speed = ETH_SPEED_NUM_10M;
806 new_link.link_speed = ETH_SPEED_NUM_100M;
809 new_link.link_speed = ETH_SPEED_NUM_1G;
812 new_link.link_speed = ETH_SPEED_NUM_10G;
815 new_link.link_speed = ETH_SPEED_NUM_20G;
818 new_link.link_speed = ETH_SPEED_NUM_25G;
821 new_link.link_speed = ETH_SPEED_NUM_40G;
824 new_link.link_speed = ETH_SPEED_NUM_50G;
827 new_link.link_speed = ETH_SPEED_NUM_100G;
830 new_link.link_speed = ETH_SPEED_NUM_NONE;
834 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
835 new_link.link_status = vf->link_up ? ETH_LINK_UP :
837 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
838 ETH_LINK_SPEED_FIXED);
840 return rte_eth_linkstatus_set(dev, &new_link);
844 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
846 struct iavf_adapter *adapter =
847 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
848 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
850 return iavf_config_promisc(adapter,
851 true, vf->promisc_multicast_enabled);
855 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
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 return iavf_config_promisc(adapter,
862 false, vf->promisc_multicast_enabled);
866 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
868 struct iavf_adapter *adapter =
869 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
870 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
872 return iavf_config_promisc(adapter,
873 vf->promisc_unicast_enabled, true);
877 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
879 struct iavf_adapter *adapter =
880 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
881 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
883 return iavf_config_promisc(adapter,
884 vf->promisc_unicast_enabled, false);
888 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
889 __rte_unused uint32_t index,
890 __rte_unused uint32_t pool)
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);
897 if (rte_is_zero_ether_addr(addr)) {
898 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
902 err = iavf_add_del_eth_addr(adapter, addr, true);
904 PMD_DRV_LOG(ERR, "fail to add MAC address");
914 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
916 struct iavf_adapter *adapter =
917 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
918 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
919 struct rte_ether_addr *addr;
922 addr = &dev->data->mac_addrs[index];
924 err = iavf_add_del_eth_addr(adapter, addr, false);
926 PMD_DRV_LOG(ERR, "fail to delete MAC address");
932 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
934 struct iavf_adapter *adapter =
935 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
936 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
939 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
942 err = iavf_add_del_vlan(adapter, vlan_id, on);
949 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
951 struct iavf_adapter *adapter =
952 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
953 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
954 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
957 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
960 /* Vlan stripping setting */
961 if (mask & ETH_VLAN_STRIP_MASK) {
962 /* Enable or disable VLAN stripping */
963 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
964 err = iavf_enable_vlan_strip(adapter);
966 err = iavf_disable_vlan_strip(adapter);
975 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
976 struct rte_eth_rss_reta_entry64 *reta_conf,
979 struct iavf_adapter *adapter =
980 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
981 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
983 uint16_t i, idx, shift;
986 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
989 if (reta_size != vf->vf_res->rss_lut_size) {
990 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
991 "(%d) doesn't match the number of hardware can "
992 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
996 lut = rte_zmalloc("rss_lut", reta_size, 0);
998 PMD_DRV_LOG(ERR, "No memory can be allocated");
1001 /* store the old lut table temporarily */
1002 rte_memcpy(lut, vf->rss_lut, reta_size);
1004 for (i = 0; i < reta_size; i++) {
1005 idx = i / RTE_RETA_GROUP_SIZE;
1006 shift = i % RTE_RETA_GROUP_SIZE;
1007 if (reta_conf[idx].mask & (1ULL << shift))
1008 lut[i] = reta_conf[idx].reta[shift];
1011 rte_memcpy(vf->rss_lut, lut, reta_size);
1012 /* send virtchnnl ops to configure rss*/
1013 ret = iavf_configure_rss_lut(adapter);
1014 if (ret) /* revert back */
1015 rte_memcpy(vf->rss_lut, lut, reta_size);
1022 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
1023 struct rte_eth_rss_reta_entry64 *reta_conf,
1026 struct iavf_adapter *adapter =
1027 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1028 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1029 uint16_t i, idx, shift;
1031 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1034 if (reta_size != vf->vf_res->rss_lut_size) {
1035 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1036 "(%d) doesn't match the number of hardware can "
1037 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1041 for (i = 0; i < reta_size; i++) {
1042 idx = i / RTE_RETA_GROUP_SIZE;
1043 shift = i % RTE_RETA_GROUP_SIZE;
1044 if (reta_conf[idx].mask & (1ULL << shift))
1045 reta_conf[idx].reta[shift] = vf->rss_lut[i];
1052 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
1053 struct rte_eth_rss_conf *rss_conf)
1055 struct iavf_adapter *adapter =
1056 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1057 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1059 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1062 /* HENA setting, it is enabled by default, no change */
1063 if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
1064 PMD_DRV_LOG(DEBUG, "No key to be configured");
1066 } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
1067 PMD_DRV_LOG(ERR, "The size of hash key configured "
1068 "(%d) doesn't match the size of hardware can "
1069 "support (%d)", rss_conf->rss_key_len,
1070 vf->vf_res->rss_key_size);
1074 rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
1076 return iavf_configure_rss_key(adapter);
1080 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1081 struct rte_eth_rss_conf *rss_conf)
1083 struct iavf_adapter *adapter =
1084 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1085 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1087 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1090 /* Just set it to default value now. */
1091 rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
1093 if (!rss_conf->rss_key)
1096 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
1097 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
1103 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1105 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
1108 if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
1111 /* mtu setting is forbidden if port is start */
1112 if (dev->data->dev_started) {
1113 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
1117 if (frame_size > RTE_ETHER_MAX_LEN)
1118 dev->data->dev_conf.rxmode.offloads |=
1119 DEV_RX_OFFLOAD_JUMBO_FRAME;
1121 dev->data->dev_conf.rxmode.offloads &=
1122 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1124 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1130 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1131 struct rte_ether_addr *mac_addr)
1133 struct iavf_adapter *adapter =
1134 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1135 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1136 struct rte_ether_addr *perm_addr, *old_addr;
1139 old_addr = (struct rte_ether_addr *)hw->mac.addr;
1140 perm_addr = (struct rte_ether_addr *)hw->mac.perm_addr;
1142 /* If the MAC address is configured by host, skip the setting */
1143 if (rte_is_valid_assigned_ether_addr(perm_addr))
1146 ret = iavf_add_del_eth_addr(adapter, old_addr, false);
1148 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1149 " %02X:%02X:%02X:%02X:%02X:%02X",
1150 old_addr->addr_bytes[0],
1151 old_addr->addr_bytes[1],
1152 old_addr->addr_bytes[2],
1153 old_addr->addr_bytes[3],
1154 old_addr->addr_bytes[4],
1155 old_addr->addr_bytes[5]);
1157 ret = iavf_add_del_eth_addr(adapter, mac_addr, true);
1159 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1160 " %02X:%02X:%02X:%02X:%02X:%02X",
1161 mac_addr->addr_bytes[0],
1162 mac_addr->addr_bytes[1],
1163 mac_addr->addr_bytes[2],
1164 mac_addr->addr_bytes[3],
1165 mac_addr->addr_bytes[4],
1166 mac_addr->addr_bytes[5]);
1171 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1176 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1178 if (*stat >= *offset)
1179 *stat = *stat - *offset;
1181 *stat = (uint64_t)((*stat +
1182 ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1184 *stat &= IAVF_48_BIT_MASK;
1188 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1190 if (*stat >= *offset)
1191 *stat = (uint64_t)(*stat - *offset);
1193 *stat = (uint64_t)((*stat +
1194 ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1198 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1200 struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1202 iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1203 iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1204 iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1205 iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1206 iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1207 iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1208 iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1209 iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1210 iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1211 iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1212 iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1216 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1218 struct iavf_adapter *adapter =
1219 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1220 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1221 struct iavf_vsi *vsi = &vf->vsi;
1222 struct virtchnl_eth_stats *pstats = NULL;
1225 ret = iavf_query_stats(adapter, &pstats);
1227 iavf_update_stats(vsi, pstats);
1228 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1229 pstats->rx_broadcast - pstats->rx_discards;
1230 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1232 stats->imissed = pstats->rx_discards;
1233 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1234 stats->ibytes = pstats->rx_bytes;
1235 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
1236 stats->obytes = pstats->tx_bytes;
1238 PMD_DRV_LOG(ERR, "Get statistics failed");
1244 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1247 struct iavf_adapter *adapter =
1248 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1249 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1250 struct iavf_vsi *vsi = &vf->vsi;
1251 struct virtchnl_eth_stats *pstats = NULL;
1253 /* read stat values to clear hardware registers */
1254 ret = iavf_query_stats(adapter, &pstats);
1258 /* set stats offset base on current values */
1259 vsi->eth_stats_offset = *pstats;
1264 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1265 struct rte_eth_xstat_name *xstats_names,
1266 __rte_unused unsigned int limit)
1270 if (xstats_names != NULL)
1271 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1272 snprintf(xstats_names[i].name,
1273 sizeof(xstats_names[i].name),
1274 "%s", rte_iavf_stats_strings[i].name);
1276 return IAVF_NB_XSTATS;
1279 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1280 struct rte_eth_xstat *xstats, unsigned int n)
1284 struct iavf_adapter *adapter =
1285 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1286 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1287 struct iavf_vsi *vsi = &vf->vsi;
1288 struct virtchnl_eth_stats *pstats = NULL;
1290 if (n < IAVF_NB_XSTATS)
1291 return IAVF_NB_XSTATS;
1293 ret = iavf_query_stats(adapter, &pstats);
1300 iavf_update_stats(vsi, pstats);
1302 /* loop over xstats array and values from pstats */
1303 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1305 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1306 rte_iavf_stats_strings[i].offset);
1309 return IAVF_NB_XSTATS;
1314 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1316 struct iavf_adapter *adapter =
1317 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1318 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1319 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1322 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1323 if (msix_intr == IAVF_MISC_VEC_ID) {
1324 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1325 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1326 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1327 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1328 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1331 IAVF_VFINT_DYN_CTLN1
1332 (msix_intr - IAVF_RX_VEC_START),
1333 IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1334 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1335 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1338 IAVF_WRITE_FLUSH(hw);
1340 rte_intr_ack(&pci_dev->intr_handle);
1346 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1348 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1349 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1352 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1353 if (msix_intr == IAVF_MISC_VEC_ID) {
1354 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1359 IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1362 IAVF_WRITE_FLUSH(hw);
1367 iavf_check_vf_reset_done(struct iavf_hw *hw)
1371 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1372 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1373 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1374 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1375 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1376 reset == VIRTCHNL_VFR_COMPLETED)
1381 if (i >= IAVF_RESET_WAIT_CNT)
1388 iavf_init_vf(struct rte_eth_dev *dev)
1391 struct iavf_adapter *adapter =
1392 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1393 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1394 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1396 err = iavf_set_mac_type(hw);
1398 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1402 err = iavf_check_vf_reset_done(hw);
1404 PMD_INIT_LOG(ERR, "VF is still resetting");
1408 iavf_init_adminq_parameter(hw);
1409 err = iavf_init_adminq(hw);
1411 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1415 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1417 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1420 if (iavf_check_api_version(adapter) != 0) {
1421 PMD_INIT_LOG(ERR, "check_api version failed");
1425 bufsz = sizeof(struct virtchnl_vf_resource) +
1426 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1427 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1429 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1432 if (iavf_get_vf_resource(adapter) != 0) {
1433 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1436 /* Allocate memort for RSS info */
1437 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1438 vf->rss_key = rte_zmalloc("rss_key",
1439 vf->vf_res->rss_key_size, 0);
1441 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1444 vf->rss_lut = rte_zmalloc("rss_lut",
1445 vf->vf_res->rss_lut_size, 0);
1447 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1452 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1453 if (iavf_get_supported_rxdid(adapter) != 0) {
1454 PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
1461 rte_free(vf->rss_key);
1462 rte_free(vf->rss_lut);
1464 rte_free(vf->vf_res);
1467 rte_free(vf->aq_resp);
1469 iavf_shutdown_adminq(hw);
1474 /* Enable default admin queue interrupt setting */
1476 iavf_enable_irq0(struct iavf_hw *hw)
1478 /* Enable admin queue interrupt trigger */
1479 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
1480 IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
1482 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1483 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1484 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1485 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1487 IAVF_WRITE_FLUSH(hw);
1491 iavf_disable_irq0(struct iavf_hw *hw)
1493 /* Disable all interrupt types */
1494 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
1495 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1496 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1497 IAVF_WRITE_FLUSH(hw);
1501 iavf_dev_interrupt_handler(void *param)
1503 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1504 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1506 iavf_disable_irq0(hw);
1508 iavf_handle_virtchnl_msg(dev);
1510 iavf_enable_irq0(hw);
1514 iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
1515 enum rte_filter_type filter_type,
1516 enum rte_filter_op filter_op,
1524 switch (filter_type) {
1525 case RTE_ETH_FILTER_GENERIC:
1526 if (filter_op != RTE_ETH_FILTER_GET)
1528 *(const void **)arg = &iavf_flow_ops;
1531 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1542 iavf_dev_init(struct rte_eth_dev *eth_dev)
1544 struct iavf_adapter *adapter =
1545 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1546 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1547 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1550 PMD_INIT_FUNC_TRACE();
1552 /* assign ops func pointer */
1553 eth_dev->dev_ops = &iavf_eth_dev_ops;
1554 eth_dev->rx_queue_count = iavf_dev_rxq_count;
1555 eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
1556 eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
1557 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1558 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1559 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1561 /* For secondary processes, we don't initialise any further as primary
1562 * has already done this work. Only check if we need a different RX
1565 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1566 iavf_set_rx_function(eth_dev);
1567 iavf_set_tx_function(eth_dev);
1570 rte_eth_copy_pci_info(eth_dev, pci_dev);
1571 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1573 hw->vendor_id = pci_dev->id.vendor_id;
1574 hw->device_id = pci_dev->id.device_id;
1575 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1576 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1577 hw->bus.bus_id = pci_dev->addr.bus;
1578 hw->bus.device = pci_dev->addr.devid;
1579 hw->bus.func = pci_dev->addr.function;
1580 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1581 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1582 adapter->eth_dev = eth_dev;
1583 adapter->stopped = 1;
1585 if (iavf_init_vf(eth_dev) != 0) {
1586 PMD_INIT_LOG(ERR, "Init vf failed");
1590 /* set default ptype table */
1591 adapter->ptype_tbl = iavf_get_default_ptype_table();
1594 eth_dev->data->mac_addrs = rte_zmalloc(
1595 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
1596 if (!eth_dev->data->mac_addrs) {
1597 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1598 " store MAC addresses",
1599 RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1602 /* If the MAC address is not configured by host,
1603 * generate a random one.
1605 if (!rte_is_valid_assigned_ether_addr(
1606 (struct rte_ether_addr *)hw->mac.addr))
1607 rte_eth_random_addr(hw->mac.addr);
1608 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1609 ð_dev->data->mac_addrs[0]);
1611 /* register callback func to eal lib */
1612 rte_intr_callback_register(&pci_dev->intr_handle,
1613 iavf_dev_interrupt_handler,
1616 /* enable uio intr after callback register */
1617 rte_intr_enable(&pci_dev->intr_handle);
1619 /* configure and enable device interrupt */
1620 iavf_enable_irq0(hw);
1622 ret = iavf_flow_init(adapter);
1624 PMD_INIT_LOG(ERR, "Failed to initialize flow");
1632 iavf_dev_close(struct rte_eth_dev *dev)
1634 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1635 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1636 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1637 struct iavf_adapter *adapter =
1638 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1639 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1642 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1645 ret = iavf_dev_stop(dev);
1647 iavf_flow_flush(dev, NULL);
1648 iavf_flow_uninit(adapter);
1651 * disable promiscuous mode before reset vf
1652 * it is a workaround solution when work with kernel driver
1653 * and it is not the normal way
1655 if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
1656 iavf_config_promisc(adapter, false, false);
1658 iavf_shutdown_adminq(hw);
1659 /* disable uio intr before callback unregister */
1660 rte_intr_disable(intr_handle);
1662 /* unregister callback func from eal lib */
1663 rte_intr_callback_unregister(intr_handle,
1664 iavf_dev_interrupt_handler, dev);
1665 iavf_disable_irq0(hw);
1667 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1669 rte_free(vf->rss_lut);
1673 rte_free(vf->rss_key);
1678 rte_free(vf->vf_res);
1682 rte_free(vf->aq_resp);
1685 vf->vf_reset = false;
1691 iavf_dev_uninit(struct rte_eth_dev *dev)
1693 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1696 iavf_dev_close(dev);
1702 * Reset VF device only to re-initialize resources in PMD layer
1705 iavf_dev_reset(struct rte_eth_dev *dev)
1709 ret = iavf_dev_uninit(dev);
1713 return iavf_dev_init(dev);
1717 iavf_dcf_cap_check_handler(__rte_unused const char *key,
1718 const char *value, __rte_unused void *opaque)
1720 if (strcmp(value, "dcf"))
1727 iavf_dcf_cap_selected(struct rte_devargs *devargs)
1729 struct rte_kvargs *kvlist;
1730 const char *key = "cap";
1733 if (devargs == NULL)
1736 kvlist = rte_kvargs_parse(devargs->args, NULL);
1740 if (!rte_kvargs_count(kvlist, key))
1743 /* dcf capability selected when there's a key-value pair: cap=dcf */
1744 if (rte_kvargs_process(kvlist, key,
1745 iavf_dcf_cap_check_handler, NULL) < 0)
1751 rte_kvargs_free(kvlist);
1755 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1756 struct rte_pci_device *pci_dev)
1758 if (iavf_dcf_cap_selected(pci_dev->device.devargs))
1761 return rte_eth_dev_pci_generic_probe(pci_dev,
1762 sizeof(struct iavf_adapter), iavf_dev_init);
1765 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1767 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1770 /* Adaptive virtual function driver struct */
1771 static struct rte_pci_driver rte_iavf_pmd = {
1772 .id_table = pci_id_iavf_map,
1773 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1774 .probe = eth_iavf_pci_probe,
1775 .remove = eth_iavf_pci_remove,
1778 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1779 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1780 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1781 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
1782 RTE_LOG_REGISTER(iavf_logtype_init, pmd.net.iavf.init, NOTICE);
1783 RTE_LOG_REGISTER(iavf_logtype_driver, pmd.net.iavf.driver, NOTICE);
1784 #ifdef RTE_LIBRTE_IAVF_DEBUG_RX
1785 RTE_LOG_REGISTER(iavf_logtype_rx, pmd.net.iavf.rx, DEBUG);
1787 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
1788 RTE_LOG_REGISTER(iavf_logtype_tx, pmd.net.iavf.tx, DEBUG);
1790 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_FREE
1791 RTE_LOG_REGISTER(iavf_logtype_tx_free, pmd.net.iavf.tx_free, DEBUG);