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 "base/iavf_prototype.h"
30 #include "base/iavf_adminq_cmd.h"
31 #include "base/iavf_type.h"
34 #include "iavf_rxtx.h"
36 static int iavf_dev_configure(struct rte_eth_dev *dev);
37 static int iavf_dev_start(struct rte_eth_dev *dev);
38 static void iavf_dev_stop(struct rte_eth_dev *dev);
39 static void iavf_dev_close(struct rte_eth_dev *dev);
40 static void iavf_dev_info_get(struct rte_eth_dev *dev,
41 struct rte_eth_dev_info *dev_info);
42 static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev);
43 static int iavf_dev_stats_get(struct rte_eth_dev *dev,
44 struct rte_eth_stats *stats);
45 static void iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
46 static void iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
47 static void iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
48 static void iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
49 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
50 struct ether_addr *addr,
53 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
54 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
55 uint16_t vlan_id, int on);
56 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
57 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
58 struct rte_eth_rss_reta_entry64 *reta_conf,
60 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
61 struct rte_eth_rss_reta_entry64 *reta_conf,
63 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
64 struct rte_eth_rss_conf *rss_conf);
65 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
66 struct rte_eth_rss_conf *rss_conf);
67 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
68 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
69 struct ether_addr *mac_addr);
70 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
72 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
75 int iavf_logtype_init;
76 int iavf_logtype_driver;
78 static const struct rte_pci_id pci_id_iavf_map[] = {
79 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
80 { .vendor_id = 0, /* sentinel */ },
83 static const struct eth_dev_ops iavf_eth_dev_ops = {
84 .dev_configure = iavf_dev_configure,
85 .dev_start = iavf_dev_start,
86 .dev_stop = iavf_dev_stop,
87 .dev_close = iavf_dev_close,
88 .dev_infos_get = iavf_dev_info_get,
89 .dev_supported_ptypes_get = iavf_dev_supported_ptypes_get,
90 .link_update = iavf_dev_link_update,
91 .stats_get = iavf_dev_stats_get,
92 .promiscuous_enable = iavf_dev_promiscuous_enable,
93 .promiscuous_disable = iavf_dev_promiscuous_disable,
94 .allmulticast_enable = iavf_dev_allmulticast_enable,
95 .allmulticast_disable = iavf_dev_allmulticast_disable,
96 .mac_addr_add = iavf_dev_add_mac_addr,
97 .mac_addr_remove = iavf_dev_del_mac_addr,
98 .vlan_filter_set = iavf_dev_vlan_filter_set,
99 .vlan_offload_set = iavf_dev_vlan_offload_set,
100 .rx_queue_start = iavf_dev_rx_queue_start,
101 .rx_queue_stop = iavf_dev_rx_queue_stop,
102 .tx_queue_start = iavf_dev_tx_queue_start,
103 .tx_queue_stop = iavf_dev_tx_queue_stop,
104 .rx_queue_setup = iavf_dev_rx_queue_setup,
105 .rx_queue_release = iavf_dev_rx_queue_release,
106 .tx_queue_setup = iavf_dev_tx_queue_setup,
107 .tx_queue_release = iavf_dev_tx_queue_release,
108 .mac_addr_set = iavf_dev_set_default_mac_addr,
109 .reta_update = iavf_dev_rss_reta_update,
110 .reta_query = iavf_dev_rss_reta_query,
111 .rss_hash_update = iavf_dev_rss_hash_update,
112 .rss_hash_conf_get = iavf_dev_rss_hash_conf_get,
113 .rxq_info_get = iavf_dev_rxq_info_get,
114 .txq_info_get = iavf_dev_txq_info_get,
115 .rx_queue_count = iavf_dev_rxq_count,
116 .rx_descriptor_status = iavf_dev_rx_desc_status,
117 .tx_descriptor_status = iavf_dev_tx_desc_status,
118 .mtu_set = iavf_dev_mtu_set,
119 .rx_queue_intr_enable = iavf_dev_rx_queue_intr_enable,
120 .rx_queue_intr_disable = iavf_dev_rx_queue_intr_disable,
124 iavf_dev_configure(struct rte_eth_dev *dev)
126 struct iavf_adapter *ad =
127 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
128 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
129 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
131 ad->rx_bulk_alloc_allowed = true;
132 #ifdef RTE_LIBRTE_IAVF_INC_VECTOR
133 /* Initialize to TRUE. If any of Rx queues doesn't meet the
134 * vector Rx/Tx preconditions, it will be reset.
136 ad->rx_vec_allowed = true;
137 ad->tx_vec_allowed = true;
139 ad->rx_vec_allowed = false;
140 ad->tx_vec_allowed = false;
143 /* Vlan stripping setting */
144 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
145 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
146 iavf_enable_vlan_strip(ad);
148 iavf_disable_vlan_strip(ad);
154 iavf_init_rss(struct iavf_adapter *adapter)
156 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
157 struct rte_eth_rss_conf *rss_conf;
161 rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
162 nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
163 IAVF_MAX_NUM_QUEUES);
165 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
166 PMD_DRV_LOG(DEBUG, "RSS is not supported");
169 if (adapter->eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
170 PMD_DRV_LOG(WARNING, "RSS is enabled by PF by default");
171 /* set all lut items to default queue */
172 for (i = 0; i < vf->vf_res->rss_lut_size; i++)
174 ret = iavf_configure_rss_lut(adapter);
178 /* In IAVF, RSS enablement is set by PF driver. It is not supported
179 * to set based on rss_conf->rss_hf.
182 /* configure RSS key */
183 if (!rss_conf->rss_key) {
184 /* Calculate the default hash key */
185 for (i = 0; i <= vf->vf_res->rss_key_size; i++)
186 vf->rss_key[i] = (uint8_t)rte_rand();
188 rte_memcpy(vf->rss_key, rss_conf->rss_key,
189 RTE_MIN(rss_conf->rss_key_len,
190 vf->vf_res->rss_key_size));
192 /* init RSS LUT table */
193 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
198 /* send virtchnnl ops to configure rss*/
199 ret = iavf_configure_rss_lut(adapter);
202 ret = iavf_configure_rss_key(adapter);
210 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
212 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
213 struct rte_eth_dev_data *dev_data = dev->data;
214 uint16_t buf_size, max_pkt_len, len;
216 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
218 /* Calculate the maximum packet length allowed */
219 len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
220 max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
222 /* Check if the jumbo frame and maximum packet length are set
225 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
226 if (max_pkt_len <= ETHER_MAX_LEN ||
227 max_pkt_len > IAVF_FRAME_SIZE_MAX) {
228 PMD_DRV_LOG(ERR, "maximum packet length must be "
229 "larger than %u and smaller than %u, "
230 "as jumbo frame is enabled",
231 (uint32_t)ETHER_MAX_LEN,
232 (uint32_t)IAVF_FRAME_SIZE_MAX);
236 if (max_pkt_len < ETHER_MIN_LEN ||
237 max_pkt_len > ETHER_MAX_LEN) {
238 PMD_DRV_LOG(ERR, "maximum packet length must be "
239 "larger than %u and smaller than %u, "
240 "as jumbo frame is disabled",
241 (uint32_t)ETHER_MIN_LEN,
242 (uint32_t)ETHER_MAX_LEN);
247 rxq->max_pkt_len = max_pkt_len;
248 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
249 (rxq->max_pkt_len + 2 * IAVF_VLAN_TAG_SIZE) > buf_size) {
250 dev_data->scattered_rx = 1;
252 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
253 IAVF_WRITE_FLUSH(hw);
259 iavf_init_queues(struct rte_eth_dev *dev)
261 struct iavf_rx_queue **rxq =
262 (struct iavf_rx_queue **)dev->data->rx_queues;
263 int i, ret = IAVF_SUCCESS;
265 for (i = 0; i < dev->data->nb_rx_queues; i++) {
266 if (!rxq[i] || !rxq[i]->q_set)
268 ret = iavf_init_rxq(dev, rxq[i]);
269 if (ret != IAVF_SUCCESS)
272 /* set rx/tx function to vector/scatter/single-segment
273 * according to parameters
275 iavf_set_rx_function(dev);
276 iavf_set_tx_function(dev);
281 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
282 struct rte_intr_handle *intr_handle)
284 struct iavf_adapter *adapter =
285 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
286 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
287 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
288 uint16_t interval, i;
291 if (rte_intr_cap_multiple(intr_handle) &&
292 dev->data->dev_conf.intr_conf.rxq) {
293 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
297 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
298 intr_handle->intr_vec =
299 rte_zmalloc("intr_vec",
300 dev->data->nb_rx_queues * sizeof(int), 0);
301 if (!intr_handle->intr_vec) {
302 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
303 dev->data->nb_rx_queues);
308 if (!dev->data->dev_conf.intr_conf.rxq ||
309 !rte_intr_dp_is_en(intr_handle)) {
310 /* Rx interrupt disabled, Map interrupt only for writeback */
312 if (vf->vf_res->vf_cap_flags &
313 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
314 /* If WB_ON_ITR supports, enable it */
315 vf->msix_base = IAVF_RX_VEC_START;
316 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTLN1(vf->msix_base - 1),
317 IAVFINT_DYN_CTLN1_ITR_INDX_MASK |
318 IAVFINT_DYN_CTLN1_WB_ON_ITR_MASK);
320 /* If no WB_ON_ITR offload flags, need to set
321 * interrupt for descriptor write back.
323 vf->msix_base = IAVF_MISC_VEC_ID;
326 interval = iavf_calc_itr_interval(
327 IAVF_QUEUE_ITR_INTERVAL_MAX);
328 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01,
329 IAVFINT_DYN_CTL01_INTENA_MASK |
330 (IAVF_ITR_INDEX_DEFAULT <<
331 IAVFINT_DYN_CTL01_ITR_INDX_SHIFT) |
333 IAVFINT_DYN_CTL01_INTERVAL_SHIFT));
335 IAVF_WRITE_FLUSH(hw);
336 /* map all queues to the same interrupt */
337 for (i = 0; i < dev->data->nb_rx_queues; i++)
338 vf->rxq_map[vf->msix_base] |= 1 << i;
340 if (!rte_intr_allow_others(intr_handle)) {
342 vf->msix_base = IAVF_MISC_VEC_ID;
343 for (i = 0; i < dev->data->nb_rx_queues; i++) {
344 vf->rxq_map[vf->msix_base] |= 1 << i;
345 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
348 "vector %u are mapping to all Rx queues",
351 /* If Rx interrupt is reuquired, and we can use
352 * multi interrupts, then the vec is from 1
354 vf->nb_msix = RTE_MIN(vf->vf_res->max_vectors,
355 intr_handle->nb_efd);
356 vf->msix_base = IAVF_RX_VEC_START;
357 vec = IAVF_RX_VEC_START;
358 for (i = 0; i < dev->data->nb_rx_queues; i++) {
359 vf->rxq_map[vec] |= 1 << i;
360 intr_handle->intr_vec[i] = vec++;
361 if (vec >= vf->nb_msix)
362 vec = IAVF_RX_VEC_START;
365 "%u vectors are mapping to %u Rx queues",
366 vf->nb_msix, dev->data->nb_rx_queues);
370 if (iavf_config_irq_map(adapter)) {
371 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
378 iavf_start_queues(struct rte_eth_dev *dev)
380 struct iavf_rx_queue *rxq;
381 struct iavf_tx_queue *txq;
384 for (i = 0; i < dev->data->nb_tx_queues; i++) {
385 txq = dev->data->tx_queues[i];
386 if (txq->tx_deferred_start)
388 if (iavf_dev_tx_queue_start(dev, i) != 0) {
389 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
394 for (i = 0; i < dev->data->nb_rx_queues; i++) {
395 rxq = dev->data->rx_queues[i];
396 if (rxq->rx_deferred_start)
398 if (iavf_dev_rx_queue_start(dev, i) != 0) {
399 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
408 iavf_dev_start(struct rte_eth_dev *dev)
410 struct iavf_adapter *adapter =
411 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
412 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
413 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
414 struct rte_intr_handle *intr_handle = dev->intr_handle;
416 PMD_INIT_FUNC_TRACE();
418 hw->adapter_stopped = 0;
420 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
421 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
422 dev->data->nb_tx_queues);
424 if (iavf_init_queues(dev) != 0) {
425 PMD_DRV_LOG(ERR, "failed to do Queue init");
429 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
430 if (iavf_init_rss(adapter) != 0) {
431 PMD_DRV_LOG(ERR, "configure rss failed");
436 if (iavf_configure_queues(adapter) != 0) {
437 PMD_DRV_LOG(ERR, "configure queues failed");
441 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
442 PMD_DRV_LOG(ERR, "configure irq failed");
445 /* re-enable intr again, because efd assign may change */
446 if (dev->data->dev_conf.intr_conf.rxq != 0) {
447 rte_intr_disable(intr_handle);
448 rte_intr_enable(intr_handle);
451 /* Set all mac addrs */
452 iavf_add_del_all_mac_addr(adapter, TRUE);
454 if (iavf_start_queues(dev) != 0) {
455 PMD_DRV_LOG(ERR, "enable queues failed");
462 iavf_add_del_all_mac_addr(adapter, FALSE);
469 iavf_dev_stop(struct rte_eth_dev *dev)
471 struct iavf_adapter *adapter =
472 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
473 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
474 struct rte_intr_handle *intr_handle = dev->intr_handle;
476 PMD_INIT_FUNC_TRACE();
478 if (hw->adapter_stopped == 1)
481 iavf_stop_queues(dev);
483 /* Disable the interrupt for Rx */
484 rte_intr_efd_disable(intr_handle);
485 /* Rx interrupt vector mapping free */
486 if (intr_handle->intr_vec) {
487 rte_free(intr_handle->intr_vec);
488 intr_handle->intr_vec = NULL;
491 /* remove all mac addrs */
492 iavf_add_del_all_mac_addr(adapter, FALSE);
493 hw->adapter_stopped = 1;
497 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
499 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
501 memset(dev_info, 0, sizeof(*dev_info));
502 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
503 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
504 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
505 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
506 dev_info->hash_key_size = vf->vf_res->rss_key_size;
507 dev_info->reta_size = vf->vf_res->rss_lut_size;
508 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
509 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
510 dev_info->rx_offload_capa =
511 DEV_RX_OFFLOAD_VLAN_STRIP |
512 DEV_RX_OFFLOAD_QINQ_STRIP |
513 DEV_RX_OFFLOAD_IPV4_CKSUM |
514 DEV_RX_OFFLOAD_UDP_CKSUM |
515 DEV_RX_OFFLOAD_TCP_CKSUM |
516 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
517 DEV_RX_OFFLOAD_SCATTER |
518 DEV_RX_OFFLOAD_JUMBO_FRAME |
519 DEV_RX_OFFLOAD_VLAN_FILTER;
520 dev_info->tx_offload_capa =
521 DEV_TX_OFFLOAD_VLAN_INSERT |
522 DEV_TX_OFFLOAD_QINQ_INSERT |
523 DEV_TX_OFFLOAD_IPV4_CKSUM |
524 DEV_TX_OFFLOAD_UDP_CKSUM |
525 DEV_TX_OFFLOAD_TCP_CKSUM |
526 DEV_TX_OFFLOAD_SCTP_CKSUM |
527 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
528 DEV_TX_OFFLOAD_TCP_TSO |
529 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
530 DEV_TX_OFFLOAD_GRE_TNL_TSO |
531 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
532 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
533 DEV_TX_OFFLOAD_MULTI_SEGS;
535 dev_info->default_rxconf = (struct rte_eth_rxconf) {
536 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
541 dev_info->default_txconf = (struct rte_eth_txconf) {
542 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
543 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
547 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
548 .nb_max = IAVF_MAX_RING_DESC,
549 .nb_min = IAVF_MIN_RING_DESC,
550 .nb_align = IAVF_ALIGN_RING_DESC,
553 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
554 .nb_max = IAVF_MAX_RING_DESC,
555 .nb_min = IAVF_MIN_RING_DESC,
556 .nb_align = IAVF_ALIGN_RING_DESC,
560 static const uint32_t *
561 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
563 static const uint32_t ptypes[] = {
565 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
568 RTE_PTYPE_L4_NONFRAG,
578 iavf_dev_link_update(struct rte_eth_dev *dev,
579 __rte_unused int wait_to_complete)
581 struct rte_eth_link new_link;
582 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
584 /* Only read status info stored in VF, and the info is updated
585 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
587 switch (vf->link_speed) {
588 case VIRTCHNL_LINK_SPEED_100MB:
589 new_link.link_speed = ETH_SPEED_NUM_100M;
591 case VIRTCHNL_LINK_SPEED_1GB:
592 new_link.link_speed = ETH_SPEED_NUM_1G;
594 case VIRTCHNL_LINK_SPEED_10GB:
595 new_link.link_speed = ETH_SPEED_NUM_10G;
597 case VIRTCHNL_LINK_SPEED_20GB:
598 new_link.link_speed = ETH_SPEED_NUM_20G;
600 case VIRTCHNL_LINK_SPEED_25GB:
601 new_link.link_speed = ETH_SPEED_NUM_25G;
603 case VIRTCHNL_LINK_SPEED_40GB:
604 new_link.link_speed = ETH_SPEED_NUM_40G;
607 new_link.link_speed = ETH_SPEED_NUM_NONE;
611 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
612 new_link.link_status = vf->link_up ? ETH_LINK_UP :
614 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
615 ETH_LINK_SPEED_FIXED);
617 if (rte_atomic64_cmpset((uint64_t *)&dev->data->dev_link,
618 *(uint64_t *)&dev->data->dev_link,
619 *(uint64_t *)&new_link) == 0)
626 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
628 struct iavf_adapter *adapter =
629 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
630 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
633 if (vf->promisc_unicast_enabled)
636 ret = iavf_config_promisc(adapter, TRUE, vf->promisc_multicast_enabled);
638 vf->promisc_unicast_enabled = TRUE;
642 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
644 struct iavf_adapter *adapter =
645 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
646 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
649 if (!vf->promisc_unicast_enabled)
652 ret = iavf_config_promisc(adapter, FALSE, vf->promisc_multicast_enabled);
654 vf->promisc_unicast_enabled = FALSE;
658 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
660 struct iavf_adapter *adapter =
661 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
662 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
665 if (vf->promisc_multicast_enabled)
668 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, TRUE);
670 vf->promisc_multicast_enabled = TRUE;
674 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
676 struct iavf_adapter *adapter =
677 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
678 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
681 if (!vf->promisc_multicast_enabled)
684 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, FALSE);
686 vf->promisc_multicast_enabled = FALSE;
690 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr,
691 __rte_unused uint32_t index,
692 __rte_unused uint32_t pool)
694 struct iavf_adapter *adapter =
695 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
696 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
699 if (is_zero_ether_addr(addr)) {
700 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
704 err = iavf_add_del_eth_addr(adapter, addr, TRUE);
706 PMD_DRV_LOG(ERR, "fail to add MAC address");
716 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
718 struct iavf_adapter *adapter =
719 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
720 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
721 struct ether_addr *addr;
724 addr = &dev->data->mac_addrs[index];
726 err = iavf_add_del_eth_addr(adapter, addr, FALSE);
728 PMD_DRV_LOG(ERR, "fail to delete MAC address");
734 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
736 struct iavf_adapter *adapter =
737 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
738 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
741 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
744 err = iavf_add_del_vlan(adapter, vlan_id, on);
751 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
753 struct iavf_adapter *adapter =
754 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
755 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
756 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
759 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
762 /* Vlan stripping setting */
763 if (mask & ETH_VLAN_STRIP_MASK) {
764 /* Enable or disable VLAN stripping */
765 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
766 err = iavf_enable_vlan_strip(adapter);
768 err = iavf_disable_vlan_strip(adapter);
777 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
778 struct rte_eth_rss_reta_entry64 *reta_conf,
781 struct iavf_adapter *adapter =
782 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
783 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
785 uint16_t i, idx, shift;
788 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
791 if (reta_size != vf->vf_res->rss_lut_size) {
792 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
793 "(%d) doesn't match the number of hardware can "
794 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
798 lut = rte_zmalloc("rss_lut", reta_size, 0);
800 PMD_DRV_LOG(ERR, "No memory can be allocated");
803 /* store the old lut table temporarily */
804 rte_memcpy(lut, vf->rss_lut, reta_size);
806 for (i = 0; i < reta_size; i++) {
807 idx = i / RTE_RETA_GROUP_SIZE;
808 shift = i % RTE_RETA_GROUP_SIZE;
809 if (reta_conf[idx].mask & (1ULL << shift))
810 lut[i] = reta_conf[idx].reta[shift];
813 rte_memcpy(vf->rss_lut, lut, reta_size);
814 /* send virtchnnl ops to configure rss*/
815 ret = iavf_configure_rss_lut(adapter);
816 if (ret) /* revert back */
817 rte_memcpy(vf->rss_lut, lut, reta_size);
824 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
825 struct rte_eth_rss_reta_entry64 *reta_conf,
828 struct iavf_adapter *adapter =
829 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
830 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
831 uint16_t i, idx, shift;
833 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
836 if (reta_size != vf->vf_res->rss_lut_size) {
837 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
838 "(%d) doesn't match the number of hardware can "
839 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
843 for (i = 0; i < reta_size; i++) {
844 idx = i / RTE_RETA_GROUP_SIZE;
845 shift = i % RTE_RETA_GROUP_SIZE;
846 if (reta_conf[idx].mask & (1ULL << shift))
847 reta_conf[idx].reta[shift] = vf->rss_lut[i];
854 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
855 struct rte_eth_rss_conf *rss_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 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
864 /* HENA setting, it is enabled by default, no change */
865 if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
866 PMD_DRV_LOG(DEBUG, "No key to be configured");
868 } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
869 PMD_DRV_LOG(ERR, "The size of hash key configured "
870 "(%d) doesn't match the size of hardware can "
871 "support (%d)", rss_conf->rss_key_len,
872 vf->vf_res->rss_key_size);
876 rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
878 return iavf_configure_rss_key(adapter);
882 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
883 struct rte_eth_rss_conf *rss_conf)
885 struct iavf_adapter *adapter =
886 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
887 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
889 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
892 /* Just set it to default value now. */
893 rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
895 if (!rss_conf->rss_key)
898 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
899 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
905 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
907 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
910 if (mtu < ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
913 /* mtu setting is forbidden if port is start */
914 if (dev->data->dev_started) {
915 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
919 if (frame_size > ETHER_MAX_LEN)
920 dev->data->dev_conf.rxmode.offloads |=
921 DEV_RX_OFFLOAD_JUMBO_FRAME;
923 dev->data->dev_conf.rxmode.offloads &=
924 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
926 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
932 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
933 struct ether_addr *mac_addr)
935 struct iavf_adapter *adapter =
936 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
937 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
938 struct ether_addr *perm_addr, *old_addr;
941 old_addr = (struct ether_addr *)hw->mac.addr;
942 perm_addr = (struct ether_addr *)hw->mac.perm_addr;
944 if (is_same_ether_addr(mac_addr, old_addr))
947 /* If the MAC address is configured by host, skip the setting */
948 if (is_valid_assigned_ether_addr(perm_addr))
951 ret = iavf_add_del_eth_addr(adapter, old_addr, FALSE);
953 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
954 " %02X:%02X:%02X:%02X:%02X:%02X",
955 old_addr->addr_bytes[0],
956 old_addr->addr_bytes[1],
957 old_addr->addr_bytes[2],
958 old_addr->addr_bytes[3],
959 old_addr->addr_bytes[4],
960 old_addr->addr_bytes[5]);
962 ret = iavf_add_del_eth_addr(adapter, mac_addr, TRUE);
964 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
965 " %02X:%02X:%02X:%02X:%02X:%02X",
966 mac_addr->addr_bytes[0],
967 mac_addr->addr_bytes[1],
968 mac_addr->addr_bytes[2],
969 mac_addr->addr_bytes[3],
970 mac_addr->addr_bytes[4],
971 mac_addr->addr_bytes[5]);
976 ether_addr_copy(mac_addr, (struct ether_addr *)hw->mac.addr);
981 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
983 struct iavf_adapter *adapter =
984 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
985 struct virtchnl_eth_stats *pstats = NULL;
988 ret = iavf_query_stats(adapter, &pstats);
990 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
991 pstats->rx_broadcast;
992 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
994 stats->imissed = pstats->rx_discards;
995 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
996 stats->ibytes = pstats->rx_bytes;
997 stats->obytes = pstats->tx_bytes;
999 PMD_DRV_LOG(ERR, "Get statistics failed");
1005 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1007 struct iavf_adapter *adapter =
1008 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1009 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1010 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1013 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1014 if (msix_intr == IAVF_MISC_VEC_ID) {
1015 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1016 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01,
1017 IAVFINT_DYN_CTL01_INTENA_MASK |
1018 IAVFINT_DYN_CTL01_ITR_INDX_MASK);
1021 IAVFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1022 IAVFINT_DYN_CTLN1_INTENA_MASK |
1023 IAVFINT_DYN_CTLN1_ITR_INDX_MASK);
1026 IAVF_WRITE_FLUSH(hw);
1028 rte_intr_enable(&pci_dev->intr_handle);
1034 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1036 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1037 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1040 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1041 if (msix_intr == IAVF_MISC_VEC_ID) {
1042 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1047 IAVFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1050 IAVF_WRITE_FLUSH(hw);
1055 iavf_check_vf_reset_done(struct iavf_hw *hw)
1059 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1060 reset = IAVF_READ_REG(hw, IAVFGEN_RSTAT) &
1061 IAVFGEN_RSTAT_VFR_STATE_MASK;
1062 reset = reset >> IAVFGEN_RSTAT_VFR_STATE_SHIFT;
1063 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1064 reset == VIRTCHNL_VFR_COMPLETED)
1069 if (i >= IAVF_RESET_WAIT_CNT)
1076 iavf_init_vf(struct rte_eth_dev *dev)
1079 struct iavf_adapter *adapter =
1080 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1081 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1082 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1084 err = iavf_set_mac_type(hw);
1086 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1090 err = iavf_check_vf_reset_done(hw);
1092 PMD_INIT_LOG(ERR, "VF is still resetting");
1096 iavf_init_adminq_parameter(hw);
1097 err = iavf_init_adminq(hw);
1099 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1103 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1105 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1108 if (iavf_check_api_version(adapter) != 0) {
1109 PMD_INIT_LOG(ERR, "check_api version failed");
1113 bufsz = sizeof(struct virtchnl_vf_resource) +
1114 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1115 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1117 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1120 if (iavf_get_vf_resource(adapter) != 0) {
1121 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1124 /* Allocate memort for RSS info */
1125 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1126 vf->rss_key = rte_zmalloc("rss_key",
1127 vf->vf_res->rss_key_size, 0);
1129 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1132 vf->rss_lut = rte_zmalloc("rss_lut",
1133 vf->vf_res->rss_lut_size, 0);
1135 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1141 rte_free(vf->rss_key);
1142 rte_free(vf->rss_lut);
1144 rte_free(vf->vf_res);
1147 rte_free(vf->aq_resp);
1149 iavf_shutdown_adminq(hw);
1154 /* Enable default admin queue interrupt setting */
1156 iavf_enable_irq0(struct iavf_hw *hw)
1158 /* Enable admin queue interrupt trigger */
1159 IAVF_WRITE_REG(hw, IAVFINT_ICR0_ENA1, IAVFINT_ICR0_ENA1_ADMINQ_MASK);
1161 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01, IAVFINT_DYN_CTL01_INTENA_MASK |
1162 IAVFINT_DYN_CTL01_CLEARPBA_MASK | IAVFINT_DYN_CTL01_ITR_INDX_MASK);
1164 IAVF_WRITE_FLUSH(hw);
1168 iavf_disable_irq0(struct iavf_hw *hw)
1170 /* Disable all interrupt types */
1171 IAVF_WRITE_REG(hw, IAVFINT_ICR0_ENA1, 0);
1172 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01,
1173 IAVFINT_DYN_CTL01_ITR_INDX_MASK);
1174 IAVF_WRITE_FLUSH(hw);
1178 iavf_dev_interrupt_handler(void *param)
1180 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1181 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1183 iavf_disable_irq0(hw);
1185 iavf_handle_virtchnl_msg(dev);
1187 iavf_enable_irq0(hw);
1191 iavf_dev_init(struct rte_eth_dev *eth_dev)
1193 struct iavf_adapter *adapter =
1194 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1195 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1196 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1198 PMD_INIT_FUNC_TRACE();
1200 /* assign ops func pointer */
1201 eth_dev->dev_ops = &iavf_eth_dev_ops;
1202 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1203 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1204 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1206 /* For secondary processes, we don't initialise any further as primary
1207 * has already done this work. Only check if we need a different RX
1210 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1211 iavf_set_rx_function(eth_dev);
1212 iavf_set_tx_function(eth_dev);
1215 rte_eth_copy_pci_info(eth_dev, pci_dev);
1217 hw->vendor_id = pci_dev->id.vendor_id;
1218 hw->device_id = pci_dev->id.device_id;
1219 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1220 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1221 hw->bus.bus_id = pci_dev->addr.bus;
1222 hw->bus.device = pci_dev->addr.devid;
1223 hw->bus.func = pci_dev->addr.function;
1224 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1225 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1226 adapter->eth_dev = eth_dev;
1228 if (iavf_init_vf(eth_dev) != 0) {
1229 PMD_INIT_LOG(ERR, "Init vf failed");
1234 eth_dev->data->mac_addrs = rte_zmalloc(
1236 ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX,
1238 if (!eth_dev->data->mac_addrs) {
1239 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1240 " store MAC addresses",
1241 ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1244 /* If the MAC address is not configured by host,
1245 * generate a random one.
1247 if (!is_valid_assigned_ether_addr((struct ether_addr *)hw->mac.addr))
1248 eth_random_addr(hw->mac.addr);
1249 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1250 ð_dev->data->mac_addrs[0]);
1252 /* register callback func to eal lib */
1253 rte_intr_callback_register(&pci_dev->intr_handle,
1254 iavf_dev_interrupt_handler,
1257 /* enable uio intr after callback register */
1258 rte_intr_enable(&pci_dev->intr_handle);
1260 /* configure and enable device interrupt */
1261 iavf_enable_irq0(hw);
1267 iavf_dev_close(struct rte_eth_dev *dev)
1269 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1270 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1271 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1274 iavf_shutdown_adminq(hw);
1275 /* disable uio intr before callback unregister */
1276 rte_intr_disable(intr_handle);
1278 /* unregister callback func from eal lib */
1279 rte_intr_callback_unregister(intr_handle,
1280 iavf_dev_interrupt_handler, dev);
1281 iavf_disable_irq0(hw);
1285 iavf_dev_uninit(struct rte_eth_dev *dev)
1287 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1288 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1290 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1293 dev->dev_ops = NULL;
1294 dev->rx_pkt_burst = NULL;
1295 dev->tx_pkt_burst = NULL;
1296 if (hw->adapter_stopped == 0)
1297 iavf_dev_close(dev);
1299 rte_free(vf->vf_res);
1303 rte_free(vf->aq_resp);
1307 rte_free(vf->rss_lut);
1311 rte_free(vf->rss_key);
1318 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1319 struct rte_pci_device *pci_dev)
1321 return rte_eth_dev_pci_generic_probe(pci_dev,
1322 sizeof(struct iavf_adapter), iavf_dev_init);
1325 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1327 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1330 /* Adaptive virtual function driver struct */
1331 static struct rte_pci_driver rte_iavf_pmd = {
1332 .id_table = pci_id_iavf_map,
1333 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
1334 RTE_PCI_DRV_IOVA_AS_VA,
1335 .probe = eth_iavf_pci_probe,
1336 .remove = eth_iavf_pci_remove,
1339 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1340 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1341 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1342 RTE_INIT(iavf_init_log)
1344 iavf_logtype_init = rte_log_register("pmd.net.iavf.init");
1345 if (iavf_logtype_init >= 0)
1346 rte_log_set_level(iavf_logtype_init, RTE_LOG_NOTICE);
1347 iavf_logtype_driver = rte_log_register("pmd.net.iavf.driver");
1348 if (iavf_logtype_driver >= 0)
1349 rte_log_set_level(iavf_logtype_driver, RTE_LOG_NOTICE);
1352 /* memory func for base code */
1353 enum iavf_status_code
1354 iavf_allocate_dma_mem_d(__rte_unused struct iavf_hw *hw,
1355 struct iavf_dma_mem *mem,
1359 const struct rte_memzone *mz = NULL;
1360 char z_name[RTE_MEMZONE_NAMESIZE];
1363 return IAVF_ERR_PARAM;
1365 snprintf(z_name, sizeof(z_name), "iavf_dma_%"PRIu64, rte_rand());
1366 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
1367 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
1369 return IAVF_ERR_NO_MEMORY;
1373 mem->pa = mz->phys_addr;
1374 mem->zone = (const void *)mz;
1376 "memzone %s allocated with physical address: %"PRIu64,
1379 return IAVF_SUCCESS;
1382 enum iavf_status_code
1383 iavf_free_dma_mem_d(__rte_unused struct iavf_hw *hw,
1384 struct iavf_dma_mem *mem)
1387 return IAVF_ERR_PARAM;
1390 "memzone %s to be freed with physical address: %"PRIu64,
1391 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
1392 rte_memzone_free((const struct rte_memzone *)mem->zone);
1397 return IAVF_SUCCESS;
1400 enum iavf_status_code
1401 iavf_allocate_virt_mem_d(__rte_unused struct iavf_hw *hw,
1402 struct iavf_virt_mem *mem,
1406 return IAVF_ERR_PARAM;
1409 mem->va = rte_zmalloc("iavf", size, 0);
1412 return IAVF_SUCCESS;
1414 return IAVF_ERR_NO_MEMORY;
1417 enum iavf_status_code
1418 iavf_free_virt_mem_d(__rte_unused struct iavf_hw *hw,
1419 struct iavf_virt_mem *mem)
1422 return IAVF_ERR_PARAM;
1427 return IAVF_SUCCESS;