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 "rte_ethdev_driver.h"
10 #include "base/ixgbe_type.h"
11 #include "base/ixgbe_vf.h"
12 #include "ixgbe_ethdev.h"
13 #include "ixgbe_rxtx.h"
14 #include "rte_pmd_ixgbe.h"
18 ixgbe_vf_representor_link_update(struct rte_eth_dev *ethdev,
21 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
23 return ixgbe_dev_link_update_share(representor->pf_ethdev,
28 ixgbe_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev,
29 struct rte_ether_addr *mac_addr)
31 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
33 return rte_pmd_ixgbe_set_vf_mac_addr(
34 representor->pf_ethdev->data->port_id,
35 representor->vf_id, mac_addr);
39 ixgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
40 struct rte_eth_dev_info *dev_info)
42 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
44 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(
45 representor->pf_ethdev->data->dev_private);
47 dev_info->device = representor->pf_ethdev->device;
49 dev_info->min_rx_bufsize = 1024;
50 /**< Minimum size of RX buffer. */
51 dev_info->max_rx_pktlen = 9728;
52 /**< Maximum configurable length of RX pkt. */
53 dev_info->max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
54 /**< Maximum number of RX queues. */
55 dev_info->max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
56 /**< Maximum number of TX queues. */
58 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
59 /**< Maximum number of MAC addresses. */
61 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
62 DEV_RX_OFFLOAD_IPV4_CKSUM | DEV_RX_OFFLOAD_UDP_CKSUM |
63 DEV_RX_OFFLOAD_TCP_CKSUM;
64 /**< Device RX offload capabilities. */
66 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
67 DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM |
68 DEV_TX_OFFLOAD_TCP_CKSUM | DEV_TX_OFFLOAD_SCTP_CKSUM |
69 DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_MULTI_SEGS;
70 /**< Device TX offload capabilities. */
72 dev_info->speed_capa =
73 representor->pf_ethdev->data->dev_link.link_speed;
74 /**< Supported speeds bitmap (ETH_LINK_SPEED_). */
76 dev_info->switch_info.name =
77 representor->pf_ethdev->device->name;
78 dev_info->switch_info.domain_id = representor->switch_domain_id;
79 dev_info->switch_info.port_id = representor->vf_id;
84 static int ixgbe_vf_representor_dev_configure(
85 __rte_unused struct rte_eth_dev *dev)
90 static int ixgbe_vf_representor_rx_queue_setup(
91 __rte_unused struct rte_eth_dev *dev,
92 __rte_unused uint16_t rx_queue_id,
93 __rte_unused uint16_t nb_rx_desc,
94 __rte_unused unsigned int socket_id,
95 __rte_unused const struct rte_eth_rxconf *rx_conf,
96 __rte_unused struct rte_mempool *mb_pool)
101 static int ixgbe_vf_representor_tx_queue_setup(
102 __rte_unused struct rte_eth_dev *dev,
103 __rte_unused uint16_t rx_queue_id,
104 __rte_unused uint16_t nb_rx_desc,
105 __rte_unused unsigned int socket_id,
106 __rte_unused const struct rte_eth_txconf *tx_conf)
111 static int ixgbe_vf_representor_dev_start(__rte_unused struct rte_eth_dev *dev)
116 static void ixgbe_vf_representor_dev_stop(__rte_unused struct rte_eth_dev *dev)
121 ixgbe_vf_representor_vlan_filter_set(struct rte_eth_dev *ethdev,
122 uint16_t vlan_id, int on)
124 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
125 uint64_t vf_mask = 1ULL << representor->vf_id;
127 return rte_pmd_ixgbe_set_vf_vlan_filter(
128 representor->pf_ethdev->data->port_id, vlan_id, vf_mask, on);
132 ixgbe_vf_representor_vlan_strip_queue_set(struct rte_eth_dev *ethdev,
133 __rte_unused uint16_t rx_queue_id, int on)
135 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
137 rte_pmd_ixgbe_set_vf_vlan_stripq(representor->pf_ethdev->data->port_id,
138 representor->vf_id, on);
141 static const struct eth_dev_ops ixgbe_vf_representor_dev_ops = {
142 .dev_infos_get = ixgbe_vf_representor_dev_infos_get,
144 .dev_start = ixgbe_vf_representor_dev_start,
145 .dev_configure = ixgbe_vf_representor_dev_configure,
146 .dev_stop = ixgbe_vf_representor_dev_stop,
148 .rx_queue_setup = ixgbe_vf_representor_rx_queue_setup,
149 .tx_queue_setup = ixgbe_vf_representor_tx_queue_setup,
151 .link_update = ixgbe_vf_representor_link_update,
153 .vlan_filter_set = ixgbe_vf_representor_vlan_filter_set,
154 .vlan_strip_queue_set = ixgbe_vf_representor_vlan_strip_queue_set,
156 .mac_addr_set = ixgbe_vf_representor_mac_addr_set,
160 ixgbe_vf_representor_rx_burst(__rte_unused void *rx_queue,
161 __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
167 ixgbe_vf_representor_tx_burst(__rte_unused void *tx_queue,
168 __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts)
174 ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
176 struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
178 struct ixgbe_vf_info *vf_data;
179 struct rte_pci_device *pci_dev;
180 struct rte_eth_link *link;
186 ((struct ixgbe_vf_representor *)init_params)->vf_id;
187 representor->switch_domain_id =
188 ((struct ixgbe_vf_representor *)init_params)->switch_domain_id;
189 representor->pf_ethdev =
190 ((struct ixgbe_vf_representor *)init_params)->pf_ethdev;
192 pci_dev = RTE_ETH_DEV_TO_PCI(representor->pf_ethdev);
194 if (representor->vf_id >= pci_dev->max_vfs)
197 ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
198 ethdev->data->representor_id = representor->vf_id;
200 /* Set representor device ops */
201 ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
203 /* No data-path, but need stub Rx/Tx functions to avoid crash
204 * when testing with the likes of testpmd.
206 ethdev->rx_pkt_burst = ixgbe_vf_representor_rx_burst;
207 ethdev->tx_pkt_burst = ixgbe_vf_representor_tx_burst;
209 /* Setting the number queues allocated to the VF */
210 ethdev->data->nb_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
211 ethdev->data->nb_tx_queues = IXGBE_VF_MAX_RX_QUEUES;
213 /* Reference VF mac address from PF data structure */
214 vf_data = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(
215 representor->pf_ethdev->data->dev_private);
217 ethdev->data->mac_addrs = (struct rte_ether_addr *)
218 vf_data[representor->vf_id].vf_mac_addresses;
220 /* Link state. Inherited from PF */
221 link = &representor->pf_ethdev->data->dev_link;
223 ethdev->data->dev_link.link_speed = link->link_speed;
224 ethdev->data->dev_link.link_duplex = link->link_duplex;
225 ethdev->data->dev_link.link_status = link->link_status;
226 ethdev->data->dev_link.link_autoneg = link->link_autoneg;
232 ixgbe_vf_representor_uninit(struct rte_eth_dev *ethdev)
234 /* mac_addrs must not be freed because part of ixgbe_vf_info */
235 ethdev->data->mac_addrs = NULL;