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 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
502 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
503 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
504 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
505 dev_info->hash_key_size = vf->vf_res->rss_key_size;
506 dev_info->reta_size = vf->vf_res->rss_lut_size;
507 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
508 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
509 dev_info->rx_offload_capa =
510 DEV_RX_OFFLOAD_VLAN_STRIP |
511 DEV_RX_OFFLOAD_QINQ_STRIP |
512 DEV_RX_OFFLOAD_IPV4_CKSUM |
513 DEV_RX_OFFLOAD_UDP_CKSUM |
514 DEV_RX_OFFLOAD_TCP_CKSUM |
515 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
516 DEV_RX_OFFLOAD_SCATTER |
517 DEV_RX_OFFLOAD_JUMBO_FRAME |
518 DEV_RX_OFFLOAD_VLAN_FILTER;
519 dev_info->tx_offload_capa =
520 DEV_TX_OFFLOAD_VLAN_INSERT |
521 DEV_TX_OFFLOAD_QINQ_INSERT |
522 DEV_TX_OFFLOAD_IPV4_CKSUM |
523 DEV_TX_OFFLOAD_UDP_CKSUM |
524 DEV_TX_OFFLOAD_TCP_CKSUM |
525 DEV_TX_OFFLOAD_SCTP_CKSUM |
526 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
527 DEV_TX_OFFLOAD_TCP_TSO |
528 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
529 DEV_TX_OFFLOAD_GRE_TNL_TSO |
530 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
531 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
532 DEV_TX_OFFLOAD_MULTI_SEGS;
534 dev_info->default_rxconf = (struct rte_eth_rxconf) {
535 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
540 dev_info->default_txconf = (struct rte_eth_txconf) {
541 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
542 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
546 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
547 .nb_max = IAVF_MAX_RING_DESC,
548 .nb_min = IAVF_MIN_RING_DESC,
549 .nb_align = IAVF_ALIGN_RING_DESC,
552 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
553 .nb_max = IAVF_MAX_RING_DESC,
554 .nb_min = IAVF_MIN_RING_DESC,
555 .nb_align = IAVF_ALIGN_RING_DESC,
559 static const uint32_t *
560 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
562 static const uint32_t ptypes[] = {
564 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
567 RTE_PTYPE_L4_NONFRAG,
577 iavf_dev_link_update(struct rte_eth_dev *dev,
578 __rte_unused int wait_to_complete)
580 struct rte_eth_link new_link;
581 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
583 /* Only read status info stored in VF, and the info is updated
584 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
586 switch (vf->link_speed) {
587 case VIRTCHNL_LINK_SPEED_100MB:
588 new_link.link_speed = ETH_SPEED_NUM_100M;
590 case VIRTCHNL_LINK_SPEED_1GB:
591 new_link.link_speed = ETH_SPEED_NUM_1G;
593 case VIRTCHNL_LINK_SPEED_10GB:
594 new_link.link_speed = ETH_SPEED_NUM_10G;
596 case VIRTCHNL_LINK_SPEED_20GB:
597 new_link.link_speed = ETH_SPEED_NUM_20G;
599 case VIRTCHNL_LINK_SPEED_25GB:
600 new_link.link_speed = ETH_SPEED_NUM_25G;
602 case VIRTCHNL_LINK_SPEED_40GB:
603 new_link.link_speed = ETH_SPEED_NUM_40G;
606 new_link.link_speed = ETH_SPEED_NUM_NONE;
610 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
611 new_link.link_status = vf->link_up ? ETH_LINK_UP :
613 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
614 ETH_LINK_SPEED_FIXED);
616 if (rte_atomic64_cmpset((uint64_t *)&dev->data->dev_link,
617 *(uint64_t *)&dev->data->dev_link,
618 *(uint64_t *)&new_link) == 0)
625 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
627 struct iavf_adapter *adapter =
628 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
629 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
632 if (vf->promisc_unicast_enabled)
635 ret = iavf_config_promisc(adapter, TRUE, vf->promisc_multicast_enabled);
637 vf->promisc_unicast_enabled = TRUE;
641 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
643 struct iavf_adapter *adapter =
644 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
645 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
648 if (!vf->promisc_unicast_enabled)
651 ret = iavf_config_promisc(adapter, FALSE, vf->promisc_multicast_enabled);
653 vf->promisc_unicast_enabled = FALSE;
657 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
659 struct iavf_adapter *adapter =
660 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
661 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
664 if (vf->promisc_multicast_enabled)
667 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, TRUE);
669 vf->promisc_multicast_enabled = TRUE;
673 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
675 struct iavf_adapter *adapter =
676 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
677 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
680 if (!vf->promisc_multicast_enabled)
683 ret = iavf_config_promisc(adapter, vf->promisc_unicast_enabled, FALSE);
685 vf->promisc_multicast_enabled = FALSE;
689 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr,
690 __rte_unused uint32_t index,
691 __rte_unused uint32_t pool)
693 struct iavf_adapter *adapter =
694 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
695 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
698 if (is_zero_ether_addr(addr)) {
699 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
703 err = iavf_add_del_eth_addr(adapter, addr, TRUE);
705 PMD_DRV_LOG(ERR, "fail to add MAC address");
715 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
717 struct iavf_adapter *adapter =
718 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
719 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
720 struct ether_addr *addr;
723 addr = &dev->data->mac_addrs[index];
725 err = iavf_add_del_eth_addr(adapter, addr, FALSE);
727 PMD_DRV_LOG(ERR, "fail to delete MAC address");
733 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
735 struct iavf_adapter *adapter =
736 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
737 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
740 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
743 err = iavf_add_del_vlan(adapter, vlan_id, on);
750 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
752 struct iavf_adapter *adapter =
753 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
754 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
755 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
758 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
761 /* Vlan stripping setting */
762 if (mask & ETH_VLAN_STRIP_MASK) {
763 /* Enable or disable VLAN stripping */
764 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
765 err = iavf_enable_vlan_strip(adapter);
767 err = iavf_disable_vlan_strip(adapter);
776 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
777 struct rte_eth_rss_reta_entry64 *reta_conf,
780 struct iavf_adapter *adapter =
781 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
782 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
784 uint16_t i, idx, shift;
787 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
790 if (reta_size != vf->vf_res->rss_lut_size) {
791 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
792 "(%d) doesn't match the number of hardware can "
793 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
797 lut = rte_zmalloc("rss_lut", reta_size, 0);
799 PMD_DRV_LOG(ERR, "No memory can be allocated");
802 /* store the old lut table temporarily */
803 rte_memcpy(lut, vf->rss_lut, reta_size);
805 for (i = 0; i < reta_size; i++) {
806 idx = i / RTE_RETA_GROUP_SIZE;
807 shift = i % RTE_RETA_GROUP_SIZE;
808 if (reta_conf[idx].mask & (1ULL << shift))
809 lut[i] = reta_conf[idx].reta[shift];
812 rte_memcpy(vf->rss_lut, lut, reta_size);
813 /* send virtchnnl ops to configure rss*/
814 ret = iavf_configure_rss_lut(adapter);
815 if (ret) /* revert back */
816 rte_memcpy(vf->rss_lut, lut, reta_size);
823 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
824 struct rte_eth_rss_reta_entry64 *reta_conf,
827 struct iavf_adapter *adapter =
828 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
829 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
830 uint16_t i, idx, shift;
832 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
835 if (reta_size != vf->vf_res->rss_lut_size) {
836 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
837 "(%d) doesn't match the number of hardware can "
838 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
842 for (i = 0; i < reta_size; i++) {
843 idx = i / RTE_RETA_GROUP_SIZE;
844 shift = i % RTE_RETA_GROUP_SIZE;
845 if (reta_conf[idx].mask & (1ULL << shift))
846 reta_conf[idx].reta[shift] = vf->rss_lut[i];
853 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
854 struct rte_eth_rss_conf *rss_conf)
856 struct iavf_adapter *adapter =
857 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
858 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
860 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
863 /* HENA setting, it is enabled by default, no change */
864 if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
865 PMD_DRV_LOG(DEBUG, "No key to be configured");
867 } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
868 PMD_DRV_LOG(ERR, "The size of hash key configured "
869 "(%d) doesn't match the size of hardware can "
870 "support (%d)", rss_conf->rss_key_len,
871 vf->vf_res->rss_key_size);
875 rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
877 return iavf_configure_rss_key(adapter);
881 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
882 struct rte_eth_rss_conf *rss_conf)
884 struct iavf_adapter *adapter =
885 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
886 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
888 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
891 /* Just set it to default value now. */
892 rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
894 if (!rss_conf->rss_key)
897 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
898 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
904 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
906 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
909 if (mtu < ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
912 /* mtu setting is forbidden if port is start */
913 if (dev->data->dev_started) {
914 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
918 if (frame_size > ETHER_MAX_LEN)
919 dev->data->dev_conf.rxmode.offloads |=
920 DEV_RX_OFFLOAD_JUMBO_FRAME;
922 dev->data->dev_conf.rxmode.offloads &=
923 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
925 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
931 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
932 struct ether_addr *mac_addr)
934 struct iavf_adapter *adapter =
935 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
936 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
937 struct ether_addr *perm_addr, *old_addr;
940 old_addr = (struct ether_addr *)hw->mac.addr;
941 perm_addr = (struct ether_addr *)hw->mac.perm_addr;
943 if (is_same_ether_addr(mac_addr, old_addr))
946 /* If the MAC address is configured by host, skip the setting */
947 if (is_valid_assigned_ether_addr(perm_addr))
950 ret = iavf_add_del_eth_addr(adapter, old_addr, FALSE);
952 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
953 " %02X:%02X:%02X:%02X:%02X:%02X",
954 old_addr->addr_bytes[0],
955 old_addr->addr_bytes[1],
956 old_addr->addr_bytes[2],
957 old_addr->addr_bytes[3],
958 old_addr->addr_bytes[4],
959 old_addr->addr_bytes[5]);
961 ret = iavf_add_del_eth_addr(adapter, mac_addr, TRUE);
963 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
964 " %02X:%02X:%02X:%02X:%02X:%02X",
965 mac_addr->addr_bytes[0],
966 mac_addr->addr_bytes[1],
967 mac_addr->addr_bytes[2],
968 mac_addr->addr_bytes[3],
969 mac_addr->addr_bytes[4],
970 mac_addr->addr_bytes[5]);
975 ether_addr_copy(mac_addr, (struct ether_addr *)hw->mac.addr);
980 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
982 struct iavf_adapter *adapter =
983 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
984 struct virtchnl_eth_stats *pstats = NULL;
987 ret = iavf_query_stats(adapter, &pstats);
989 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
990 pstats->rx_broadcast;
991 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
993 stats->imissed = pstats->rx_discards;
994 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
995 stats->ibytes = pstats->rx_bytes;
996 stats->obytes = pstats->tx_bytes;
998 PMD_DRV_LOG(ERR, "Get statistics failed");
1004 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1006 struct iavf_adapter *adapter =
1007 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1008 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1009 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1012 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1013 if (msix_intr == IAVF_MISC_VEC_ID) {
1014 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1015 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01,
1016 IAVFINT_DYN_CTL01_INTENA_MASK |
1017 IAVFINT_DYN_CTL01_CLEARPBA_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_CTL01_CLEARPBA_MASK |
1024 IAVFINT_DYN_CTLN1_ITR_INDX_MASK);
1027 IAVF_WRITE_FLUSH(hw);
1029 rte_intr_enable(&pci_dev->intr_handle);
1035 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1037 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1038 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1041 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1042 if (msix_intr == IAVF_MISC_VEC_ID) {
1043 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1048 IAVFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1051 IAVF_WRITE_FLUSH(hw);
1056 iavf_check_vf_reset_done(struct iavf_hw *hw)
1060 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1061 reset = IAVF_READ_REG(hw, IAVFGEN_RSTAT) &
1062 IAVFGEN_RSTAT_VFR_STATE_MASK;
1063 reset = reset >> IAVFGEN_RSTAT_VFR_STATE_SHIFT;
1064 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1065 reset == VIRTCHNL_VFR_COMPLETED)
1070 if (i >= IAVF_RESET_WAIT_CNT)
1077 iavf_init_vf(struct rte_eth_dev *dev)
1080 struct iavf_adapter *adapter =
1081 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1082 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1083 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1085 err = iavf_set_mac_type(hw);
1087 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1091 err = iavf_check_vf_reset_done(hw);
1093 PMD_INIT_LOG(ERR, "VF is still resetting");
1097 iavf_init_adminq_parameter(hw);
1098 err = iavf_init_adminq(hw);
1100 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1104 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1106 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1109 if (iavf_check_api_version(adapter) != 0) {
1110 PMD_INIT_LOG(ERR, "check_api version failed");
1114 bufsz = sizeof(struct virtchnl_vf_resource) +
1115 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1116 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1118 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1121 if (iavf_get_vf_resource(adapter) != 0) {
1122 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1125 /* Allocate memort for RSS info */
1126 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1127 vf->rss_key = rte_zmalloc("rss_key",
1128 vf->vf_res->rss_key_size, 0);
1130 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1133 vf->rss_lut = rte_zmalloc("rss_lut",
1134 vf->vf_res->rss_lut_size, 0);
1136 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1142 rte_free(vf->rss_key);
1143 rte_free(vf->rss_lut);
1145 rte_free(vf->vf_res);
1148 rte_free(vf->aq_resp);
1150 iavf_shutdown_adminq(hw);
1155 /* Enable default admin queue interrupt setting */
1157 iavf_enable_irq0(struct iavf_hw *hw)
1159 /* Enable admin queue interrupt trigger */
1160 IAVF_WRITE_REG(hw, IAVFINT_ICR0_ENA1, IAVFINT_ICR0_ENA1_ADMINQ_MASK);
1162 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01, IAVFINT_DYN_CTL01_INTENA_MASK |
1163 IAVFINT_DYN_CTL01_CLEARPBA_MASK | IAVFINT_DYN_CTL01_ITR_INDX_MASK);
1165 IAVF_WRITE_FLUSH(hw);
1169 iavf_disable_irq0(struct iavf_hw *hw)
1171 /* Disable all interrupt types */
1172 IAVF_WRITE_REG(hw, IAVFINT_ICR0_ENA1, 0);
1173 IAVF_WRITE_REG(hw, IAVFINT_DYN_CTL01,
1174 IAVFINT_DYN_CTL01_ITR_INDX_MASK);
1175 IAVF_WRITE_FLUSH(hw);
1179 iavf_dev_interrupt_handler(void *param)
1181 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1182 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1184 iavf_disable_irq0(hw);
1186 iavf_handle_virtchnl_msg(dev);
1188 iavf_enable_irq0(hw);
1192 iavf_dev_init(struct rte_eth_dev *eth_dev)
1194 struct iavf_adapter *adapter =
1195 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1196 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1197 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1199 PMD_INIT_FUNC_TRACE();
1201 /* assign ops func pointer */
1202 eth_dev->dev_ops = &iavf_eth_dev_ops;
1203 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1204 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1205 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1207 /* For secondary processes, we don't initialise any further as primary
1208 * has already done this work. Only check if we need a different RX
1211 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1212 iavf_set_rx_function(eth_dev);
1213 iavf_set_tx_function(eth_dev);
1216 rte_eth_copy_pci_info(eth_dev, pci_dev);
1218 hw->vendor_id = pci_dev->id.vendor_id;
1219 hw->device_id = pci_dev->id.device_id;
1220 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1221 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1222 hw->bus.bus_id = pci_dev->addr.bus;
1223 hw->bus.device = pci_dev->addr.devid;
1224 hw->bus.func = pci_dev->addr.function;
1225 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1226 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1227 adapter->eth_dev = eth_dev;
1229 if (iavf_init_vf(eth_dev) != 0) {
1230 PMD_INIT_LOG(ERR, "Init vf failed");
1235 eth_dev->data->mac_addrs = rte_zmalloc(
1237 ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX,
1239 if (!eth_dev->data->mac_addrs) {
1240 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1241 " store MAC addresses",
1242 ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1245 /* If the MAC address is not configured by host,
1246 * generate a random one.
1248 if (!is_valid_assigned_ether_addr((struct ether_addr *)hw->mac.addr))
1249 eth_random_addr(hw->mac.addr);
1250 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1251 ð_dev->data->mac_addrs[0]);
1253 /* register callback func to eal lib */
1254 rte_intr_callback_register(&pci_dev->intr_handle,
1255 iavf_dev_interrupt_handler,
1258 /* enable uio intr after callback register */
1259 rte_intr_enable(&pci_dev->intr_handle);
1261 /* configure and enable device interrupt */
1262 iavf_enable_irq0(hw);
1268 iavf_dev_close(struct rte_eth_dev *dev)
1270 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1271 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1272 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1275 iavf_shutdown_adminq(hw);
1276 /* disable uio intr before callback unregister */
1277 rte_intr_disable(intr_handle);
1279 /* unregister callback func from eal lib */
1280 rte_intr_callback_unregister(intr_handle,
1281 iavf_dev_interrupt_handler, dev);
1282 iavf_disable_irq0(hw);
1286 iavf_dev_uninit(struct rte_eth_dev *dev)
1288 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1289 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1291 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1294 dev->dev_ops = NULL;
1295 dev->rx_pkt_burst = NULL;
1296 dev->tx_pkt_burst = NULL;
1297 if (hw->adapter_stopped == 0)
1298 iavf_dev_close(dev);
1300 rte_free(vf->vf_res);
1304 rte_free(vf->aq_resp);
1308 rte_free(vf->rss_lut);
1312 rte_free(vf->rss_key);
1319 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1320 struct rte_pci_device *pci_dev)
1322 return rte_eth_dev_pci_generic_probe(pci_dev,
1323 sizeof(struct iavf_adapter), iavf_dev_init);
1326 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1328 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1331 /* Adaptive virtual function driver struct */
1332 static struct rte_pci_driver rte_iavf_pmd = {
1333 .id_table = pci_id_iavf_map,
1334 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
1335 RTE_PCI_DRV_IOVA_AS_VA,
1336 .probe = eth_iavf_pci_probe,
1337 .remove = eth_iavf_pci_remove,
1340 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1341 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1342 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1343 RTE_INIT(iavf_init_log)
1345 iavf_logtype_init = rte_log_register("pmd.net.iavf.init");
1346 if (iavf_logtype_init >= 0)
1347 rte_log_set_level(iavf_logtype_init, RTE_LOG_NOTICE);
1348 iavf_logtype_driver = rte_log_register("pmd.net.iavf.driver");
1349 if (iavf_logtype_driver >= 0)
1350 rte_log_set_level(iavf_logtype_driver, RTE_LOG_NOTICE);
1353 /* memory func for base code */
1354 enum iavf_status_code
1355 iavf_allocate_dma_mem_d(__rte_unused struct iavf_hw *hw,
1356 struct iavf_dma_mem *mem,
1360 const struct rte_memzone *mz = NULL;
1361 char z_name[RTE_MEMZONE_NAMESIZE];
1364 return IAVF_ERR_PARAM;
1366 snprintf(z_name, sizeof(z_name), "iavf_dma_%"PRIu64, rte_rand());
1367 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
1368 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
1370 return IAVF_ERR_NO_MEMORY;
1374 mem->pa = mz->phys_addr;
1375 mem->zone = (const void *)mz;
1377 "memzone %s allocated with physical address: %"PRIu64,
1380 return IAVF_SUCCESS;
1383 enum iavf_status_code
1384 iavf_free_dma_mem_d(__rte_unused struct iavf_hw *hw,
1385 struct iavf_dma_mem *mem)
1388 return IAVF_ERR_PARAM;
1391 "memzone %s to be freed with physical address: %"PRIu64,
1392 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
1393 rte_memzone_free((const struct rte_memzone *)mem->zone);
1398 return IAVF_SUCCESS;
1401 enum iavf_status_code
1402 iavf_allocate_virt_mem_d(__rte_unused struct iavf_hw *hw,
1403 struct iavf_virt_mem *mem,
1407 return IAVF_ERR_PARAM;
1410 mem->va = rte_zmalloc("iavf", size, 0);
1413 return IAVF_SUCCESS;
1415 return IAVF_ERR_NO_MEMORY;
1418 enum iavf_status_code
1419 iavf_free_virt_mem_d(__rte_unused struct iavf_hw *hw,
1420 struct iavf_virt_mem *mem)
1423 return IAVF_ERR_PARAM;
1428 return IAVF_SUCCESS;