1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
11 #include <rte_interrupts.h>
12 #include <rte_debug.h>
14 #include <rte_atomic.h>
16 #include <rte_ether.h>
17 #include <ethdev_pci.h>
18 #include <rte_kvargs.h>
19 #include <rte_malloc.h>
20 #include <rte_memzone.h>
23 #include <iavf_devids.h>
25 #include "ice_generic_flow.h"
26 #include "ice_dcf_ethdev.h"
30 ice_dcf_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
31 struct rte_eth_udp_tunnel *udp_tunnel);
33 ice_dcf_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
34 struct rte_eth_udp_tunnel *udp_tunnel);
37 ice_dcf_dev_init(struct rte_eth_dev *eth_dev);
40 ice_dcf_dev_uninit(struct rte_eth_dev *eth_dev);
43 ice_dcf_recv_pkts(__rte_unused void *rx_queue,
44 __rte_unused struct rte_mbuf **bufs,
45 __rte_unused uint16_t nb_pkts)
51 ice_dcf_xmit_pkts(__rte_unused void *tx_queue,
52 __rte_unused struct rte_mbuf **bufs,
53 __rte_unused uint16_t nb_pkts)
59 ice_dcf_init_rxq(struct rte_eth_dev *dev, struct ice_rx_queue *rxq)
61 struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
62 struct rte_eth_dev_data *dev_data = dev->data;
63 struct iavf_hw *hw = &dcf_ad->real_hw.avf;
64 uint16_t buf_size, max_pkt_len;
66 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
68 rxq->rx_buf_len = RTE_ALIGN(buf_size, (1 << ICE_RLAN_CTX_DBUF_S));
69 max_pkt_len = RTE_MIN(ICE_SUPPORT_CHAIN_NUM * rxq->rx_buf_len,
70 dev->data->mtu + ICE_ETH_OVERHEAD);
72 /* Check if the jumbo frame and maximum packet length are set
75 if (dev_data->mtu > RTE_ETHER_MTU) {
76 if (max_pkt_len <= ICE_ETH_MAX_LEN ||
77 max_pkt_len > ICE_FRAME_SIZE_MAX) {
78 PMD_DRV_LOG(ERR, "maximum packet length must be "
79 "larger than %u and smaller than %u, "
80 "as jumbo frame is enabled",
81 (uint32_t)ICE_ETH_MAX_LEN,
82 (uint32_t)ICE_FRAME_SIZE_MAX);
86 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
87 max_pkt_len > ICE_ETH_MAX_LEN) {
88 PMD_DRV_LOG(ERR, "maximum packet length must be "
89 "larger than %u and smaller than %u, "
90 "as jumbo frame is disabled",
91 (uint32_t)RTE_ETHER_MIN_LEN,
92 (uint32_t)ICE_ETH_MAX_LEN);
97 rxq->max_pkt_len = max_pkt_len;
98 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
99 (rxq->max_pkt_len + 2 * ICE_VLAN_TAG_SIZE) > buf_size) {
100 dev_data->scattered_rx = 1;
102 rxq->qrx_tail = hw->hw_addr + IAVF_QRX_TAIL1(rxq->queue_id);
103 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
104 IAVF_WRITE_FLUSH(hw);
110 ice_dcf_init_rx_queues(struct rte_eth_dev *dev)
112 struct ice_rx_queue **rxq =
113 (struct ice_rx_queue **)dev->data->rx_queues;
116 for (i = 0; i < dev->data->nb_rx_queues; i++) {
117 if (!rxq[i] || !rxq[i]->q_set)
119 ret = ice_dcf_init_rxq(dev, rxq[i]);
124 ice_set_rx_function(dev);
125 ice_set_tx_function(dev);
130 #define IAVF_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
131 #define IAVF_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
133 #define IAVF_ITR_INDEX_DEFAULT 0
134 #define IAVF_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
135 #define IAVF_QUEUE_ITR_INTERVAL_MAX 8160 /* 8160 us */
137 static inline uint16_t
138 iavf_calc_itr_interval(int16_t interval)
140 if (interval < 0 || interval > IAVF_QUEUE_ITR_INTERVAL_MAX)
141 interval = IAVF_QUEUE_ITR_INTERVAL_DEFAULT;
143 /* Convert to hardware count, as writing each 1 represents 2 us */
148 ice_dcf_config_rx_queues_irqs(struct rte_eth_dev *dev,
149 struct rte_intr_handle *intr_handle)
151 struct ice_dcf_adapter *adapter = dev->data->dev_private;
152 struct ice_dcf_hw *hw = &adapter->real_hw;
153 uint16_t interval, i;
156 if (rte_intr_cap_multiple(intr_handle) &&
157 dev->data->dev_conf.intr_conf.rxq) {
158 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
162 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
163 intr_handle->intr_vec =
164 rte_zmalloc("intr_vec",
165 dev->data->nb_rx_queues * sizeof(int), 0);
166 if (!intr_handle->intr_vec) {
167 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
168 dev->data->nb_rx_queues);
173 if (!dev->data->dev_conf.intr_conf.rxq ||
174 !rte_intr_dp_is_en(intr_handle)) {
175 /* Rx interrupt disabled, Map interrupt only for writeback */
177 if (hw->vf_res->vf_cap_flags &
178 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
179 /* If WB_ON_ITR supports, enable it */
180 hw->msix_base = IAVF_RX_VEC_START;
181 /* Set the ITR for index zero, to 2us to make sure that
182 * we leave time for aggregation to occur, but don't
183 * increase latency dramatically.
185 IAVF_WRITE_REG(&hw->avf,
186 IAVF_VFINT_DYN_CTLN1(hw->msix_base - 1),
187 (0 << IAVF_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) |
188 IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK |
189 (2UL << IAVF_VFINT_DYN_CTLN1_INTERVAL_SHIFT));
191 /* If no WB_ON_ITR offload flags, need to set
192 * interrupt for descriptor write back.
194 hw->msix_base = IAVF_MISC_VEC_ID;
198 iavf_calc_itr_interval(IAVF_QUEUE_ITR_INTERVAL_MAX);
199 IAVF_WRITE_REG(&hw->avf, IAVF_VFINT_DYN_CTL01,
200 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
201 (IAVF_ITR_INDEX_DEFAULT <<
202 IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
204 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
206 IAVF_WRITE_FLUSH(&hw->avf);
207 /* map all queues to the same interrupt */
208 for (i = 0; i < dev->data->nb_rx_queues; i++)
209 hw->rxq_map[hw->msix_base] |= 1 << i;
211 if (!rte_intr_allow_others(intr_handle)) {
213 hw->msix_base = IAVF_MISC_VEC_ID;
214 for (i = 0; i < dev->data->nb_rx_queues; i++) {
215 hw->rxq_map[hw->msix_base] |= 1 << i;
216 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
219 "vector %u are mapping to all Rx queues",
222 /* If Rx interrupt is reuquired, and we can use
223 * multi interrupts, then the vec is from 1
225 hw->nb_msix = RTE_MIN(hw->vf_res->max_vectors,
226 intr_handle->nb_efd);
227 hw->msix_base = IAVF_MISC_VEC_ID;
228 vec = IAVF_MISC_VEC_ID;
229 for (i = 0; i < dev->data->nb_rx_queues; i++) {
230 hw->rxq_map[vec] |= 1 << i;
231 intr_handle->intr_vec[i] = vec++;
232 if (vec >= hw->nb_msix)
233 vec = IAVF_RX_VEC_START;
236 "%u vectors are mapping to %u Rx queues",
237 hw->nb_msix, dev->data->nb_rx_queues);
241 if (ice_dcf_config_irq_map(hw)) {
242 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
249 alloc_rxq_mbufs(struct ice_rx_queue *rxq)
251 volatile union ice_rx_flex_desc *rxd;
252 struct rte_mbuf *mbuf = NULL;
256 for (i = 0; i < rxq->nb_rx_desc; i++) {
257 mbuf = rte_mbuf_raw_alloc(rxq->mp);
258 if (unlikely(!mbuf)) {
259 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
263 rte_mbuf_refcnt_set(mbuf, 1);
265 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
267 mbuf->port = rxq->port_id;
270 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
272 rxd = &rxq->rx_ring[i];
273 rxd->read.pkt_addr = dma_addr;
274 rxd->read.hdr_addr = 0;
275 #ifndef RTE_LIBRTE_ICE_16BYTE_RX_DESC
280 rxq->sw_ring[i].mbuf = (void *)mbuf;
287 ice_dcf_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
289 struct ice_dcf_adapter *ad = dev->data->dev_private;
290 struct iavf_hw *hw = &ad->real_hw.avf;
291 struct ice_rx_queue *rxq;
294 if (rx_queue_id >= dev->data->nb_rx_queues)
297 rxq = dev->data->rx_queues[rx_queue_id];
299 err = alloc_rxq_mbufs(rxq);
301 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
307 /* Init the RX tail register. */
308 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
309 IAVF_WRITE_FLUSH(hw);
311 /* Ready to switch the queue on */
312 err = ice_dcf_switch_queue(&ad->real_hw, rx_queue_id, true, true);
314 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
319 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
325 reset_rx_queue(struct ice_rx_queue *rxq)
333 len = rxq->nb_rx_desc + ICE_RX_MAX_BURST;
335 for (i = 0; i < len * sizeof(union ice_rx_flex_desc); i++)
336 ((volatile char *)rxq->rx_ring)[i] = 0;
338 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
340 for (i = 0; i < ICE_RX_MAX_BURST; i++)
341 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
344 rxq->rx_nb_avail = 0;
345 rxq->rx_next_avail = 0;
346 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
350 rxq->pkt_first_seg = NULL;
351 rxq->pkt_last_seg = NULL;
355 reset_tx_queue(struct ice_tx_queue *txq)
357 struct ice_tx_entry *txe;
362 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
367 size = sizeof(struct ice_tx_desc) * txq->nb_tx_desc;
368 for (i = 0; i < size; i++)
369 ((volatile char *)txq->tx_ring)[i] = 0;
371 prev = (uint16_t)(txq->nb_tx_desc - 1);
372 for (i = 0; i < txq->nb_tx_desc; i++) {
373 txq->tx_ring[i].cmd_type_offset_bsz =
374 rte_cpu_to_le_64(IAVF_TX_DESC_DTYPE_DESC_DONE);
377 txe[prev].next_id = i;
384 txq->last_desc_cleaned = txq->nb_tx_desc - 1;
385 txq->nb_tx_free = txq->nb_tx_desc - 1;
387 txq->tx_next_dd = txq->tx_rs_thresh - 1;
388 txq->tx_next_rs = txq->tx_rs_thresh - 1;
392 ice_dcf_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
394 struct ice_dcf_adapter *ad = dev->data->dev_private;
395 struct ice_dcf_hw *hw = &ad->real_hw;
396 struct ice_rx_queue *rxq;
399 if (rx_queue_id >= dev->data->nb_rx_queues)
402 err = ice_dcf_switch_queue(hw, rx_queue_id, true, false);
404 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
409 rxq = dev->data->rx_queues[rx_queue_id];
410 rxq->rx_rel_mbufs(rxq);
412 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
418 ice_dcf_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
420 struct ice_dcf_adapter *ad = dev->data->dev_private;
421 struct iavf_hw *hw = &ad->real_hw.avf;
422 struct ice_tx_queue *txq;
425 if (tx_queue_id >= dev->data->nb_tx_queues)
428 txq = dev->data->tx_queues[tx_queue_id];
430 /* Init the RX tail register. */
431 txq->qtx_tail = hw->hw_addr + IAVF_QTX_TAIL1(tx_queue_id);
432 IAVF_PCI_REG_WRITE(txq->qtx_tail, 0);
433 IAVF_WRITE_FLUSH(hw);
435 /* Ready to switch the queue on */
436 err = ice_dcf_switch_queue(&ad->real_hw, tx_queue_id, false, true);
439 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
444 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
450 ice_dcf_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
452 struct ice_dcf_adapter *ad = dev->data->dev_private;
453 struct ice_dcf_hw *hw = &ad->real_hw;
454 struct ice_tx_queue *txq;
457 if (tx_queue_id >= dev->data->nb_tx_queues)
460 err = ice_dcf_switch_queue(hw, tx_queue_id, false, false);
462 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off",
467 txq = dev->data->tx_queues[tx_queue_id];
468 txq->tx_rel_mbufs(txq);
470 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
476 ice_dcf_start_queues(struct rte_eth_dev *dev)
478 struct ice_rx_queue *rxq;
479 struct ice_tx_queue *txq;
483 for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
484 txq = dev->data->tx_queues[nb_txq];
485 if (txq->tx_deferred_start)
487 if (ice_dcf_tx_queue_start(dev, nb_txq) != 0) {
488 PMD_DRV_LOG(ERR, "Fail to start queue %u", nb_txq);
493 for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
494 rxq = dev->data->rx_queues[nb_rxq];
495 if (rxq->rx_deferred_start)
497 if (ice_dcf_rx_queue_start(dev, nb_rxq) != 0) {
498 PMD_DRV_LOG(ERR, "Fail to start queue %u", nb_rxq);
505 /* stop the started queues if failed to start all queues */
507 for (i = 0; i < nb_rxq; i++)
508 ice_dcf_rx_queue_stop(dev, i);
510 for (i = 0; i < nb_txq; i++)
511 ice_dcf_tx_queue_stop(dev, i);
517 ice_dcf_dev_start(struct rte_eth_dev *dev)
519 struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
520 struct rte_intr_handle *intr_handle = dev->intr_handle;
521 struct ice_adapter *ad = &dcf_ad->parent;
522 struct ice_dcf_hw *hw = &dcf_ad->real_hw;
527 "The DCF has been reset by PF, please reinit first");
531 if (hw->tm_conf.root && !hw->tm_conf.committed) {
533 "please call hierarchy_commit() before starting the port");
537 ad->pf.adapter_stopped = 0;
539 hw->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
540 dev->data->nb_tx_queues);
542 ret = ice_dcf_init_rx_queues(dev);
544 PMD_DRV_LOG(ERR, "Fail to init queues");
548 if (hw->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
549 ret = ice_dcf_init_rss(hw);
551 PMD_DRV_LOG(ERR, "Failed to configure RSS");
556 ret = ice_dcf_configure_queues(hw);
558 PMD_DRV_LOG(ERR, "Fail to config queues");
562 ret = ice_dcf_config_rx_queues_irqs(dev, intr_handle);
564 PMD_DRV_LOG(ERR, "Fail to config rx queues' irqs");
568 if (dev->data->dev_conf.intr_conf.rxq != 0) {
569 rte_intr_disable(intr_handle);
570 rte_intr_enable(intr_handle);
573 ret = ice_dcf_start_queues(dev);
575 PMD_DRV_LOG(ERR, "Failed to enable queues");
579 ret = ice_dcf_add_del_all_mac_addr(hw, true);
581 PMD_DRV_LOG(ERR, "Failed to add mac addr");
585 dev->data->dev_link.link_status = ETH_LINK_UP;
591 ice_dcf_stop_queues(struct rte_eth_dev *dev)
593 struct ice_dcf_adapter *ad = dev->data->dev_private;
594 struct ice_dcf_hw *hw = &ad->real_hw;
595 struct ice_rx_queue *rxq;
596 struct ice_tx_queue *txq;
599 /* Stop All queues */
600 ret = ice_dcf_disable_queues(hw);
602 PMD_DRV_LOG(WARNING, "Fail to stop queues");
604 for (i = 0; i < dev->data->nb_tx_queues; i++) {
605 txq = dev->data->tx_queues[i];
608 txq->tx_rel_mbufs(txq);
610 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
612 for (i = 0; i < dev->data->nb_rx_queues; i++) {
613 rxq = dev->data->rx_queues[i];
616 rxq->rx_rel_mbufs(rxq);
618 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
623 ice_dcf_dev_stop(struct rte_eth_dev *dev)
625 struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
626 struct rte_intr_handle *intr_handle = dev->intr_handle;
627 struct ice_adapter *ad = &dcf_ad->parent;
628 struct ice_dcf_hw *hw = &dcf_ad->real_hw;
630 if (ad->pf.adapter_stopped == 1) {
631 PMD_DRV_LOG(DEBUG, "Port is already stopped");
635 /* Stop the VF representors for this device */
636 ice_dcf_vf_repr_stop_all(dcf_ad);
638 ice_dcf_stop_queues(dev);
640 rte_intr_efd_disable(intr_handle);
641 if (intr_handle->intr_vec) {
642 rte_free(intr_handle->intr_vec);
643 intr_handle->intr_vec = NULL;
646 ice_dcf_add_del_all_mac_addr(&dcf_ad->real_hw, false);
647 dev->data->dev_link.link_status = ETH_LINK_DOWN;
648 ad->pf.adapter_stopped = 1;
649 hw->tm_conf.committed = false;
655 ice_dcf_dev_configure(struct rte_eth_dev *dev)
657 struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
658 struct ice_adapter *ad = &dcf_ad->parent;
660 ad->rx_bulk_alloc_allowed = true;
661 ad->tx_simple_allowed = true;
663 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
664 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
670 ice_dcf_dev_info_get(struct rte_eth_dev *dev,
671 struct rte_eth_dev_info *dev_info)
673 struct ice_dcf_adapter *adapter = dev->data->dev_private;
674 struct ice_dcf_hw *hw = &adapter->real_hw;
676 dev_info->max_mac_addrs = 1;
677 dev_info->max_rx_queues = hw->vsi_res->num_queue_pairs;
678 dev_info->max_tx_queues = hw->vsi_res->num_queue_pairs;
679 dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
680 dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
681 dev_info->hash_key_size = hw->vf_res->rss_key_size;
682 dev_info->reta_size = hw->vf_res->rss_lut_size;
683 dev_info->flow_type_rss_offloads = ICE_RSS_OFFLOAD_ALL;
685 dev_info->rx_offload_capa =
686 DEV_RX_OFFLOAD_VLAN_STRIP |
687 DEV_RX_OFFLOAD_IPV4_CKSUM |
688 DEV_RX_OFFLOAD_UDP_CKSUM |
689 DEV_RX_OFFLOAD_TCP_CKSUM |
690 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
691 DEV_RX_OFFLOAD_SCATTER |
692 DEV_RX_OFFLOAD_VLAN_FILTER |
693 DEV_RX_OFFLOAD_RSS_HASH;
694 dev_info->tx_offload_capa =
695 DEV_TX_OFFLOAD_VLAN_INSERT |
696 DEV_TX_OFFLOAD_IPV4_CKSUM |
697 DEV_TX_OFFLOAD_UDP_CKSUM |
698 DEV_TX_OFFLOAD_TCP_CKSUM |
699 DEV_TX_OFFLOAD_SCTP_CKSUM |
700 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
701 DEV_TX_OFFLOAD_TCP_TSO |
702 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
703 DEV_TX_OFFLOAD_GRE_TNL_TSO |
704 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
705 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
706 DEV_TX_OFFLOAD_MULTI_SEGS;
708 dev_info->default_rxconf = (struct rte_eth_rxconf) {
710 .pthresh = ICE_DEFAULT_RX_PTHRESH,
711 .hthresh = ICE_DEFAULT_RX_HTHRESH,
712 .wthresh = ICE_DEFAULT_RX_WTHRESH,
714 .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
719 dev_info->default_txconf = (struct rte_eth_txconf) {
721 .pthresh = ICE_DEFAULT_TX_PTHRESH,
722 .hthresh = ICE_DEFAULT_TX_HTHRESH,
723 .wthresh = ICE_DEFAULT_TX_WTHRESH,
725 .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
726 .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
730 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
731 .nb_max = ICE_MAX_RING_DESC,
732 .nb_min = ICE_MIN_RING_DESC,
733 .nb_align = ICE_ALIGN_RING_DESC,
736 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
737 .nb_max = ICE_MAX_RING_DESC,
738 .nb_min = ICE_MIN_RING_DESC,
739 .nb_align = ICE_ALIGN_RING_DESC,
746 ice_dcf_dev_promiscuous_enable(__rte_unused struct rte_eth_dev *dev)
752 ice_dcf_dev_promiscuous_disable(__rte_unused struct rte_eth_dev *dev)
758 ice_dcf_dev_allmulticast_enable(__rte_unused struct rte_eth_dev *dev)
764 ice_dcf_dev_allmulticast_disable(__rte_unused struct rte_eth_dev *dev)
770 ice_dcf_dev_flow_ops_get(struct rte_eth_dev *dev,
771 const struct rte_flow_ops **ops)
776 *ops = &ice_flow_ops;
780 #define ICE_DCF_32_BIT_WIDTH (CHAR_BIT * 4)
781 #define ICE_DCF_48_BIT_WIDTH (CHAR_BIT * 6)
782 #define ICE_DCF_48_BIT_MASK RTE_LEN2MASK(ICE_DCF_48_BIT_WIDTH, uint64_t)
785 ice_dcf_stat_update_48(uint64_t *offset, uint64_t *stat)
787 if (*stat >= *offset)
788 *stat = *stat - *offset;
790 *stat = (uint64_t)((*stat +
791 ((uint64_t)1 << ICE_DCF_48_BIT_WIDTH)) - *offset);
793 *stat &= ICE_DCF_48_BIT_MASK;
797 ice_dcf_stat_update_32(uint64_t *offset, uint64_t *stat)
799 if (*stat >= *offset)
800 *stat = (uint64_t)(*stat - *offset);
802 *stat = (uint64_t)((*stat +
803 ((uint64_t)1 << ICE_DCF_32_BIT_WIDTH)) - *offset);
807 ice_dcf_update_stats(struct virtchnl_eth_stats *oes,
808 struct virtchnl_eth_stats *nes)
810 ice_dcf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
811 ice_dcf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
812 ice_dcf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
813 ice_dcf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
814 ice_dcf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
815 ice_dcf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
816 ice_dcf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
817 ice_dcf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
818 ice_dcf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
819 ice_dcf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
820 ice_dcf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
825 ice_dcf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
827 struct ice_dcf_adapter *ad = dev->data->dev_private;
828 struct ice_dcf_hw *hw = &ad->real_hw;
829 struct virtchnl_eth_stats pstats;
834 "The DCF has been reset by PF, please reinit first");
838 ret = ice_dcf_query_stats(hw, &pstats);
840 ice_dcf_update_stats(&hw->eth_stats_offset, &pstats);
841 stats->ipackets = pstats.rx_unicast + pstats.rx_multicast +
842 pstats.rx_broadcast - pstats.rx_discards;
843 stats->opackets = pstats.tx_broadcast + pstats.tx_multicast +
845 stats->imissed = pstats.rx_discards;
846 stats->oerrors = pstats.tx_errors + pstats.tx_discards;
847 stats->ibytes = pstats.rx_bytes;
848 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
849 stats->obytes = pstats.tx_bytes;
851 PMD_DRV_LOG(ERR, "Get statistics failed");
857 ice_dcf_stats_reset(struct rte_eth_dev *dev)
859 struct ice_dcf_adapter *ad = dev->data->dev_private;
860 struct ice_dcf_hw *hw = &ad->real_hw;
861 struct virtchnl_eth_stats pstats;
867 /* read stat values to clear hardware registers */
868 ret = ice_dcf_query_stats(hw, &pstats);
872 /* set stats offset base on current values */
873 hw->eth_stats_offset = pstats;
879 ice_dcf_free_repr_info(struct ice_dcf_adapter *dcf_adapter)
881 if (dcf_adapter->repr_infos) {
882 rte_free(dcf_adapter->repr_infos);
883 dcf_adapter->repr_infos = NULL;
888 ice_dcf_init_repr_info(struct ice_dcf_adapter *dcf_adapter)
890 dcf_adapter->repr_infos =
891 rte_calloc("ice_dcf_rep_info",
892 dcf_adapter->real_hw.num_vfs,
893 sizeof(dcf_adapter->repr_infos[0]), 0);
894 if (!dcf_adapter->repr_infos) {
895 PMD_DRV_LOG(ERR, "Failed to alloc memory for VF representors\n");
903 ice_dcf_dev_close(struct rte_eth_dev *dev)
905 struct ice_dcf_adapter *adapter = dev->data->dev_private;
907 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
910 (void)ice_dcf_dev_stop(dev);
912 ice_free_queues(dev);
914 ice_dcf_free_repr_info(adapter);
915 ice_dcf_uninit_parent_adapter(dev);
916 ice_dcf_uninit_hw(dev, &adapter->real_hw);
922 ice_dcf_link_update(struct rte_eth_dev *dev,
923 __rte_unused int wait_to_complete)
925 struct ice_dcf_adapter *ad = dev->data->dev_private;
926 struct ice_dcf_hw *hw = &ad->real_hw;
927 struct rte_eth_link new_link;
929 memset(&new_link, 0, sizeof(new_link));
931 /* Only read status info stored in VF, and the info is updated
932 * when receive LINK_CHANGE event from PF by virtchnl.
934 switch (hw->link_speed) {
936 new_link.link_speed = ETH_SPEED_NUM_10M;
939 new_link.link_speed = ETH_SPEED_NUM_100M;
942 new_link.link_speed = ETH_SPEED_NUM_1G;
945 new_link.link_speed = ETH_SPEED_NUM_10G;
948 new_link.link_speed = ETH_SPEED_NUM_20G;
951 new_link.link_speed = ETH_SPEED_NUM_25G;
954 new_link.link_speed = ETH_SPEED_NUM_40G;
957 new_link.link_speed = ETH_SPEED_NUM_50G;
960 new_link.link_speed = ETH_SPEED_NUM_100G;
963 new_link.link_speed = ETH_SPEED_NUM_NONE;
967 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
968 new_link.link_status = hw->link_up ? ETH_LINK_UP :
970 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
971 ETH_LINK_SPEED_FIXED);
973 return rte_eth_linkstatus_set(dev, &new_link);
976 /* Add UDP tunneling port */
978 ice_dcf_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
979 struct rte_eth_udp_tunnel *udp_tunnel)
981 struct ice_dcf_adapter *adapter = dev->data->dev_private;
982 struct ice_adapter *parent_adapter = &adapter->parent;
983 struct ice_hw *parent_hw = &parent_adapter->hw;
989 switch (udp_tunnel->prot_type) {
990 case RTE_TUNNEL_TYPE_VXLAN:
991 ret = ice_create_tunnel(parent_hw, TNL_VXLAN,
992 udp_tunnel->udp_port);
994 case RTE_TUNNEL_TYPE_ECPRI:
995 ret = ice_create_tunnel(parent_hw, TNL_ECPRI,
996 udp_tunnel->udp_port);
999 PMD_DRV_LOG(ERR, "Invalid tunnel type");
1007 /* Delete UDP tunneling port */
1009 ice_dcf_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1010 struct rte_eth_udp_tunnel *udp_tunnel)
1012 struct ice_dcf_adapter *adapter = dev->data->dev_private;
1013 struct ice_adapter *parent_adapter = &adapter->parent;
1014 struct ice_hw *parent_hw = &parent_adapter->hw;
1020 switch (udp_tunnel->prot_type) {
1021 case RTE_TUNNEL_TYPE_VXLAN:
1022 case RTE_TUNNEL_TYPE_ECPRI:
1023 ret = ice_destroy_tunnel(parent_hw, udp_tunnel->udp_port, 0);
1026 PMD_DRV_LOG(ERR, "Invalid tunnel type");
1035 ice_dcf_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
1041 *(const void **)arg = &ice_dcf_tm_ops;
1047 ice_dcf_dev_reset(struct rte_eth_dev *dev)
1051 ret = ice_dcf_dev_uninit(dev);
1055 ret = ice_dcf_dev_init(dev);
1060 static const struct eth_dev_ops ice_dcf_eth_dev_ops = {
1061 .dev_start = ice_dcf_dev_start,
1062 .dev_stop = ice_dcf_dev_stop,
1063 .dev_close = ice_dcf_dev_close,
1064 .dev_reset = ice_dcf_dev_reset,
1065 .dev_configure = ice_dcf_dev_configure,
1066 .dev_infos_get = ice_dcf_dev_info_get,
1067 .rx_queue_setup = ice_rx_queue_setup,
1068 .tx_queue_setup = ice_tx_queue_setup,
1069 .rx_queue_release = ice_dev_rx_queue_release,
1070 .tx_queue_release = ice_dev_tx_queue_release,
1071 .rx_queue_start = ice_dcf_rx_queue_start,
1072 .tx_queue_start = ice_dcf_tx_queue_start,
1073 .rx_queue_stop = ice_dcf_rx_queue_stop,
1074 .tx_queue_stop = ice_dcf_tx_queue_stop,
1075 .link_update = ice_dcf_link_update,
1076 .stats_get = ice_dcf_stats_get,
1077 .stats_reset = ice_dcf_stats_reset,
1078 .promiscuous_enable = ice_dcf_dev_promiscuous_enable,
1079 .promiscuous_disable = ice_dcf_dev_promiscuous_disable,
1080 .allmulticast_enable = ice_dcf_dev_allmulticast_enable,
1081 .allmulticast_disable = ice_dcf_dev_allmulticast_disable,
1082 .flow_ops_get = ice_dcf_dev_flow_ops_get,
1083 .udp_tunnel_port_add = ice_dcf_dev_udp_tunnel_port_add,
1084 .udp_tunnel_port_del = ice_dcf_dev_udp_tunnel_port_del,
1085 .tm_ops_get = ice_dcf_tm_ops_get,
1089 ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
1091 struct ice_dcf_adapter *adapter = eth_dev->data->dev_private;
1093 adapter->real_hw.resetting = false;
1094 eth_dev->dev_ops = &ice_dcf_eth_dev_ops;
1095 eth_dev->rx_pkt_burst = ice_dcf_recv_pkts;
1096 eth_dev->tx_pkt_burst = ice_dcf_xmit_pkts;
1098 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1101 adapter->real_hw.vc_event_msg_cb = ice_dcf_handle_pf_event_msg;
1102 if (ice_dcf_init_hw(eth_dev, &adapter->real_hw) != 0) {
1103 PMD_INIT_LOG(ERR, "Failed to init DCF hardware");
1107 if (ice_dcf_init_parent_adapter(eth_dev) != 0) {
1108 PMD_INIT_LOG(ERR, "Failed to init DCF parent adapter");
1109 ice_dcf_uninit_hw(eth_dev, &adapter->real_hw);
1117 ice_dcf_dev_uninit(struct rte_eth_dev *eth_dev)
1119 ice_dcf_dev_close(eth_dev);
1125 ice_dcf_cap_check_handler(__rte_unused const char *key,
1126 const char *value, __rte_unused void *opaque)
1128 if (strcmp(value, "dcf"))
1135 ice_dcf_cap_selected(struct rte_devargs *devargs)
1137 struct rte_kvargs *kvlist;
1138 const char *key = "cap";
1141 if (devargs == NULL)
1144 kvlist = rte_kvargs_parse(devargs->args, NULL);
1148 if (!rte_kvargs_count(kvlist, key))
1151 /* dcf capability selected when there's a key-value pair: cap=dcf */
1152 if (rte_kvargs_process(kvlist, key,
1153 ice_dcf_cap_check_handler, NULL) < 0)
1159 rte_kvargs_free(kvlist);
1164 eth_ice_dcf_pci_probe(__rte_unused struct rte_pci_driver *pci_drv,
1165 struct rte_pci_device *pci_dev)
1167 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
1168 struct ice_dcf_vf_repr_param repr_param;
1169 char repr_name[RTE_ETH_NAME_MAX_LEN];
1170 struct ice_dcf_adapter *dcf_adapter;
1171 struct rte_eth_dev *dcf_ethdev;
1172 uint16_t dcf_vsi_id;
1175 if (!ice_dcf_cap_selected(pci_dev->device.devargs))
1178 ret = rte_eth_devargs_parse(pci_dev->device.devargs->args, ð_da);
1182 ret = rte_eth_dev_pci_generic_probe(pci_dev,
1183 sizeof(struct ice_dcf_adapter),
1185 if (ret || !eth_da.nb_representor_ports)
1187 if (eth_da.type != RTE_ETH_REPRESENTOR_VF)
1190 dcf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
1191 if (dcf_ethdev == NULL)
1194 dcf_adapter = dcf_ethdev->data->dev_private;
1195 ret = ice_dcf_init_repr_info(dcf_adapter);
1199 if (eth_da.nb_representor_ports > dcf_adapter->real_hw.num_vfs ||
1200 eth_da.nb_representor_ports >= RTE_MAX_ETHPORTS) {
1201 PMD_DRV_LOG(ERR, "the number of port representors is too large: %u",
1202 eth_da.nb_representor_ports);
1203 ice_dcf_free_repr_info(dcf_adapter);
1207 dcf_vsi_id = dcf_adapter->real_hw.vsi_id | VIRTCHNL_DCF_VF_VSI_VALID;
1209 repr_param.dcf_eth_dev = dcf_ethdev;
1210 repr_param.switch_domain_id = 0;
1212 for (i = 0; i < eth_da.nb_representor_ports; i++) {
1213 uint16_t vf_id = eth_da.representor_ports[i];
1214 struct rte_eth_dev *vf_rep_eth_dev;
1216 if (vf_id >= dcf_adapter->real_hw.num_vfs) {
1217 PMD_DRV_LOG(ERR, "VF ID %u is out of range (0 ~ %u)",
1218 vf_id, dcf_adapter->real_hw.num_vfs - 1);
1223 if (dcf_adapter->real_hw.vf_vsi_map[vf_id] == dcf_vsi_id) {
1224 PMD_DRV_LOG(ERR, "VF ID %u is DCF's ID.\n", vf_id);
1229 repr_param.vf_id = vf_id;
1230 snprintf(repr_name, sizeof(repr_name), "net_%s_representor_%u",
1231 pci_dev->device.name, vf_id);
1232 ret = rte_eth_dev_create(&pci_dev->device, repr_name,
1233 sizeof(struct ice_dcf_vf_repr),
1234 NULL, NULL, ice_dcf_vf_repr_init,
1237 PMD_DRV_LOG(ERR, "failed to create DCF VF representor %s",
1242 vf_rep_eth_dev = rte_eth_dev_allocated(repr_name);
1243 if (!vf_rep_eth_dev) {
1245 "Failed to find the ethdev for DCF VF representor: %s",
1251 dcf_adapter->repr_infos[vf_id].vf_rep_eth_dev = vf_rep_eth_dev;
1252 dcf_adapter->num_reprs++;
1259 eth_ice_dcf_pci_remove(struct rte_pci_device *pci_dev)
1261 struct rte_eth_dev *eth_dev;
1263 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
1267 if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
1268 return rte_eth_dev_pci_generic_remove(pci_dev,
1269 ice_dcf_vf_repr_uninit);
1271 return rte_eth_dev_pci_generic_remove(pci_dev,
1272 ice_dcf_dev_uninit);
1275 static const struct rte_pci_id pci_id_ice_dcf_map[] = {
1276 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
1277 { .vendor_id = 0, /* sentinel */ },
1280 static struct rte_pci_driver rte_ice_dcf_pmd = {
1281 .id_table = pci_id_ice_dcf_map,
1282 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1283 .probe = eth_ice_dcf_pci_probe,
1284 .remove = eth_ice_dcf_pci_remove,
1287 RTE_PMD_REGISTER_PCI(net_ice_dcf, rte_ice_dcf_pmd);
1288 RTE_PMD_REGISTER_PCI_TABLE(net_ice_dcf, pci_id_ice_dcf_map);
1289 RTE_PMD_REGISTER_KMOD_DEP(net_ice_dcf, "* igb_uio | vfio-pci");
1290 RTE_PMD_REGISTER_PARAM_STRING(net_ice_dcf, "cap=dcf");