1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
5 #include <rte_ethdev.h>
7 #include <rte_malloc.h>
9 #include "base/ixgbe_type.h"
10 #include "base/ixgbe_vf.h"
11 #include "ixgbe_ethdev.h"
12 #include "ixgbe_rxtx.h"
13 #include "rte_pmd_ixgbe.h"
17 ixgbe_vf_representor_link_update(struct rte_eth_dev *ethdev,
20 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
22 return ixgbe_dev_link_update_share(representor->pf_ethdev,
27 ixgbe_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev,
28 struct rte_ether_addr *mac_addr)
30 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
32 return rte_pmd_ixgbe_set_vf_mac_addr(
33 representor->pf_ethdev->data->port_id,
34 representor->vf_id, mac_addr);
38 ixgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
39 struct rte_eth_dev_info *dev_info)
41 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
43 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(
44 representor->pf_ethdev->data->dev_private);
46 dev_info->device = representor->pf_ethdev->device;
48 dev_info->min_rx_bufsize = 1024;
49 /**< Minimum size of RX buffer. */
50 dev_info->max_rx_pktlen = 9728;
51 /**< Maximum configurable length of RX pkt. */
52 dev_info->max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
53 /**< Maximum number of RX queues. */
54 dev_info->max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
55 /**< Maximum number of TX queues. */
57 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
58 /**< Maximum number of MAC addresses. */
60 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
61 DEV_RX_OFFLOAD_IPV4_CKSUM | DEV_RX_OFFLOAD_UDP_CKSUM |
62 DEV_RX_OFFLOAD_TCP_CKSUM;
63 /**< Device RX offload capabilities. */
65 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
66 DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM |
67 DEV_TX_OFFLOAD_TCP_CKSUM | DEV_TX_OFFLOAD_SCTP_CKSUM |
68 DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_MULTI_SEGS;
69 /**< Device TX offload capabilities. */
71 dev_info->speed_capa =
72 representor->pf_ethdev->data->dev_link.link_speed;
73 /**< Supported speeds bitmap (ETH_LINK_SPEED_). */
75 dev_info->switch_info.name =
76 representor->pf_ethdev->device->name;
77 dev_info->switch_info.domain_id = representor->switch_domain_id;
78 dev_info->switch_info.port_id = representor->vf_id;
83 static int ixgbe_vf_representor_dev_configure(
84 __rte_unused struct rte_eth_dev *dev)
89 static int ixgbe_vf_representor_rx_queue_setup(
90 __rte_unused struct rte_eth_dev *dev,
91 __rte_unused uint16_t rx_queue_id,
92 __rte_unused uint16_t nb_rx_desc,
93 __rte_unused unsigned int socket_id,
94 __rte_unused const struct rte_eth_rxconf *rx_conf,
95 __rte_unused struct rte_mempool *mb_pool)
100 static int ixgbe_vf_representor_tx_queue_setup(
101 __rte_unused struct rte_eth_dev *dev,
102 __rte_unused uint16_t rx_queue_id,
103 __rte_unused uint16_t nb_rx_desc,
104 __rte_unused unsigned int socket_id,
105 __rte_unused const struct rte_eth_txconf *tx_conf)
110 static int ixgbe_vf_representor_dev_start(__rte_unused struct rte_eth_dev *dev)
115 static void ixgbe_vf_representor_dev_stop(__rte_unused struct rte_eth_dev *dev)
120 ixgbe_vf_representor_vlan_filter_set(struct rte_eth_dev *ethdev,
121 uint16_t vlan_id, int on)
123 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
124 uint64_t vf_mask = 1ULL << representor->vf_id;
126 return rte_pmd_ixgbe_set_vf_vlan_filter(
127 representor->pf_ethdev->data->port_id, vlan_id, vf_mask, on);
131 ixgbe_vf_representor_vlan_strip_queue_set(struct rte_eth_dev *ethdev,
132 __rte_unused uint16_t rx_queue_id, int on)
134 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
136 rte_pmd_ixgbe_set_vf_vlan_stripq(representor->pf_ethdev->data->port_id,
137 representor->vf_id, on);
140 static const struct eth_dev_ops ixgbe_vf_representor_dev_ops = {
141 .dev_infos_get = ixgbe_vf_representor_dev_infos_get,
143 .dev_start = ixgbe_vf_representor_dev_start,
144 .dev_configure = ixgbe_vf_representor_dev_configure,
145 .dev_stop = ixgbe_vf_representor_dev_stop,
147 .rx_queue_setup = ixgbe_vf_representor_rx_queue_setup,
148 .tx_queue_setup = ixgbe_vf_representor_tx_queue_setup,
150 .link_update = ixgbe_vf_representor_link_update,
152 .vlan_filter_set = ixgbe_vf_representor_vlan_filter_set,
153 .vlan_strip_queue_set = ixgbe_vf_representor_vlan_strip_queue_set,
155 .mac_addr_set = ixgbe_vf_representor_mac_addr_set,
159 ixgbe_vf_representor_rx_burst(__rte_unused void *rx_queue,
160 __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
166 ixgbe_vf_representor_tx_burst(__rte_unused void *tx_queue,
167 __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts)
173 ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
175 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
177 struct ixgbe_vf_info *vf_data;
178 struct rte_pci_device *pci_dev;
179 struct rte_eth_link *link;
185 ((struct ixgbe_vf_representor *)init_params)->vf_id;
186 representor->switch_domain_id =
187 ((struct ixgbe_vf_representor *)init_params)->switch_domain_id;
188 representor->pf_ethdev =
189 ((struct ixgbe_vf_representor *)init_params)->pf_ethdev;
191 pci_dev = RTE_ETH_DEV_TO_PCI(representor->pf_ethdev);
193 if (representor->vf_id >= pci_dev->max_vfs)
196 ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
197 ethdev->data->representor_id = representor->vf_id;
199 /* Set representor device ops */
200 ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
202 /* No data-path, but need stub Rx/Tx functions to avoid crash
203 * when testing with the likes of testpmd.
205 ethdev->rx_pkt_burst = ixgbe_vf_representor_rx_burst;
206 ethdev->tx_pkt_burst = ixgbe_vf_representor_tx_burst;
208 /* Setting the number queues allocated to the VF */
209 ethdev->data->nb_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
210 ethdev->data->nb_tx_queues = IXGBE_VF_MAX_RX_QUEUES;
212 /* Reference VF mac address from PF data structure */
213 vf_data = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(
214 representor->pf_ethdev->data->dev_private);
216 ethdev->data->mac_addrs = (struct rte_ether_addr *)
217 vf_data[representor->vf_id].vf_mac_addresses;
219 /* Link state. Inherited from PF */
220 link = &representor->pf_ethdev->data->dev_link;
222 ethdev->data->dev_link.link_speed = link->link_speed;
223 ethdev->data->dev_link.link_duplex = link->link_duplex;
224 ethdev->data->dev_link.link_status = link->link_status;
225 ethdev->data->dev_link.link_autoneg = link->link_autoneg;
231 ixgbe_vf_representor_uninit(struct rte_eth_dev *ethdev)
233 /* mac_addrs must not be freed because part of ixgbe_vf_info */
234 ethdev->data->mac_addrs = NULL;