1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
5 #include <rte_bus_pci.h>
6 #include <rte_ethdev.h>
8 #include <rte_malloc.h>
10 #include "ethdev_driver.h"
11 #include "base/i40e_type.h"
12 #include "base/virtchnl.h"
13 #include "i40e_ethdev.h"
14 #include "i40e_rxtx.h"
15 #include "rte_pmd_i40e.h"
18 i40e_vf_representor_link_update(struct rte_eth_dev *ethdev,
21 struct i40e_vf_representor *representor = ethdev->data->dev_private;
22 struct rte_eth_dev *dev =
23 &rte_eth_devices[representor->adapter->pf.dev_data->port_id];
25 return i40e_dev_link_update(dev, wait_to_complete);
28 i40e_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
29 struct rte_eth_dev_info *dev_info)
31 struct i40e_vf_representor *representor = ethdev->data->dev_private;
32 struct rte_eth_dev_data *pf_dev_data =
33 representor->adapter->pf.dev_data;
35 /* get dev info for the vdev */
36 dev_info->device = ethdev->device;
38 dev_info->max_rx_queues = ethdev->data->nb_rx_queues;
39 dev_info->max_tx_queues = ethdev->data->nb_tx_queues;
41 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
42 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
43 dev_info->hash_key_size = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
45 dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_64;
46 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
47 dev_info->max_mac_addrs = I40E_NUM_MACADDR_MAX;
48 dev_info->rx_offload_capa =
49 RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
50 RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
51 RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
52 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
53 RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
54 RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
55 dev_info->tx_offload_capa =
56 RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
57 RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
58 RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
59 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
60 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
61 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
62 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
63 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
64 RTE_ETH_TX_OFFLOAD_TCP_TSO |
65 RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
66 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
67 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
68 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO;
70 dev_info->default_rxconf = (struct rte_eth_rxconf) {
72 .pthresh = I40E_DEFAULT_RX_PTHRESH,
73 .hthresh = I40E_DEFAULT_RX_HTHRESH,
74 .wthresh = I40E_DEFAULT_RX_WTHRESH,
76 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
81 dev_info->default_txconf = (struct rte_eth_txconf) {
83 .pthresh = I40E_DEFAULT_TX_PTHRESH,
84 .hthresh = I40E_DEFAULT_TX_HTHRESH,
85 .wthresh = I40E_DEFAULT_TX_WTHRESH,
87 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
88 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
92 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
93 .nb_max = I40E_MAX_RING_DESC,
94 .nb_min = I40E_MIN_RING_DESC,
95 .nb_align = I40E_ALIGN_RING_DESC,
98 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
99 .nb_max = I40E_MAX_RING_DESC,
100 .nb_min = I40E_MIN_RING_DESC,
101 .nb_align = I40E_ALIGN_RING_DESC,
104 dev_info->switch_info.name =
105 rte_eth_devices[pf_dev_data->port_id].device->name;
106 dev_info->switch_info.domain_id = representor->switch_domain_id;
107 dev_info->switch_info.port_id = representor->vf_id;
113 i40e_vf_representor_dev_configure(__rte_unused struct rte_eth_dev *dev)
119 i40e_vf_representor_dev_start(__rte_unused struct rte_eth_dev *dev)
125 i40e_vf_representor_dev_stop(__rte_unused struct rte_eth_dev *dev)
131 i40e_vf_representor_rx_queue_setup(__rte_unused struct rte_eth_dev *dev,
132 __rte_unused uint16_t rx_queue_id,
133 __rte_unused uint16_t nb_rx_desc,
134 __rte_unused unsigned int socket_id,
135 __rte_unused const struct rte_eth_rxconf *rx_conf,
136 __rte_unused struct rte_mempool *mb_pool)
142 i40e_vf_representor_tx_queue_setup(__rte_unused struct rte_eth_dev *dev,
143 __rte_unused uint16_t rx_queue_id,
144 __rte_unused uint16_t nb_rx_desc,
145 __rte_unused unsigned int socket_id,
146 __rte_unused const struct rte_eth_txconf *tx_conf)
152 i40evf_stat_update_48(uint64_t *offset,
155 if (*stat >= *offset)
156 *stat = *stat - *offset;
158 *stat = (uint64_t)((*stat +
159 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
161 *stat &= I40E_48_BIT_MASK;
165 i40evf_stat_update_32(uint64_t *offset,
168 if (*stat >= *offset)
169 *stat = (uint64_t)(*stat - *offset);
171 *stat = (uint64_t)((*stat +
172 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
176 rte_pmd_i40e_get_vf_native_stats(uint16_t port,
178 struct i40e_eth_stats *stats)
180 struct rte_eth_dev *dev;
182 struct i40e_vsi *vsi;
184 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
186 dev = &rte_eth_devices[port];
188 if (!is_i40e_supported(dev))
191 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
193 if (vf_id >= pf->vf_num || !pf->vfs) {
194 PMD_DRV_LOG(ERR, "Invalid VF ID.");
198 vsi = pf->vfs[vf_id].vsi;
200 PMD_DRV_LOG(ERR, "Invalid VSI.");
204 i40e_update_vsi_stats(vsi);
205 memcpy(stats, &vsi->eth_stats, sizeof(vsi->eth_stats));
211 i40e_vf_representor_stats_get(struct rte_eth_dev *ethdev,
212 struct rte_eth_stats *stats)
214 struct i40e_vf_representor *representor = ethdev->data->dev_private;
215 struct i40e_eth_stats native_stats;
218 ret = rte_pmd_i40e_get_vf_native_stats(
219 representor->adapter->pf.dev_data->port_id,
220 representor->vf_id, &native_stats);
222 i40evf_stat_update_48(
223 &representor->stats_offset.rx_bytes,
224 &native_stats.rx_bytes);
225 i40evf_stat_update_48(
226 &representor->stats_offset.rx_unicast,
227 &native_stats.rx_unicast);
228 i40evf_stat_update_48(
229 &representor->stats_offset.rx_multicast,
230 &native_stats.rx_multicast);
231 i40evf_stat_update_48(
232 &representor->stats_offset.rx_broadcast,
233 &native_stats.rx_broadcast);
234 i40evf_stat_update_32(
235 &representor->stats_offset.rx_discards,
236 &native_stats.rx_discards);
237 i40evf_stat_update_32(
238 &representor->stats_offset.rx_unknown_protocol,
239 &native_stats.rx_unknown_protocol);
240 i40evf_stat_update_48(
241 &representor->stats_offset.tx_bytes,
242 &native_stats.tx_bytes);
243 i40evf_stat_update_48(
244 &representor->stats_offset.tx_unicast,
245 &native_stats.tx_unicast);
246 i40evf_stat_update_48(
247 &representor->stats_offset.tx_multicast,
248 &native_stats.tx_multicast);
249 i40evf_stat_update_48(
250 &representor->stats_offset.tx_broadcast,
251 &native_stats.tx_broadcast);
252 i40evf_stat_update_32(
253 &representor->stats_offset.tx_errors,
254 &native_stats.tx_errors);
255 i40evf_stat_update_32(
256 &representor->stats_offset.tx_discards,
257 &native_stats.tx_discards);
259 stats->ipackets = native_stats.rx_unicast +
260 native_stats.rx_multicast +
261 native_stats.rx_broadcast;
262 stats->opackets = native_stats.tx_unicast +
263 native_stats.tx_multicast +
264 native_stats.tx_broadcast;
265 stats->ibytes = native_stats.rx_bytes;
266 stats->obytes = native_stats.tx_bytes;
267 stats->ierrors = native_stats.rx_discards;
268 stats->oerrors = native_stats.tx_errors + native_stats.tx_discards;
274 i40e_vf_representor_stats_reset(struct rte_eth_dev *ethdev)
276 struct i40e_vf_representor *representor = ethdev->data->dev_private;
278 return rte_pmd_i40e_get_vf_native_stats(
279 representor->adapter->pf.dev_data->port_id,
280 representor->vf_id, &representor->stats_offset);
284 i40e_vf_representor_promiscuous_enable(struct rte_eth_dev *ethdev)
286 struct i40e_vf_representor *representor = ethdev->data->dev_private;
288 return rte_pmd_i40e_set_vf_unicast_promisc(
289 representor->adapter->pf.dev_data->port_id,
290 representor->vf_id, 1);
294 i40e_vf_representor_promiscuous_disable(struct rte_eth_dev *ethdev)
296 struct i40e_vf_representor *representor = ethdev->data->dev_private;
298 return rte_pmd_i40e_set_vf_unicast_promisc(
299 representor->adapter->pf.dev_data->port_id,
300 representor->vf_id, 0);
304 i40e_vf_representor_allmulticast_enable(struct rte_eth_dev *ethdev)
306 struct i40e_vf_representor *representor = ethdev->data->dev_private;
308 return rte_pmd_i40e_set_vf_multicast_promisc(
309 representor->adapter->pf.dev_data->port_id,
310 representor->vf_id, 1);
314 i40e_vf_representor_allmulticast_disable(struct rte_eth_dev *ethdev)
316 struct i40e_vf_representor *representor = ethdev->data->dev_private;
318 return rte_pmd_i40e_set_vf_multicast_promisc(
319 representor->adapter->pf.dev_data->port_id,
320 representor->vf_id, 0);
324 i40e_vf_representor_mac_addr_remove(struct rte_eth_dev *ethdev, uint32_t index)
326 struct i40e_vf_representor *representor = ethdev->data->dev_private;
328 rte_pmd_i40e_remove_vf_mac_addr(
329 representor->adapter->pf.dev_data->port_id,
330 representor->vf_id, ðdev->data->mac_addrs[index]);
334 i40e_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev,
335 struct rte_ether_addr *mac_addr)
337 struct i40e_vf_representor *representor = ethdev->data->dev_private;
339 return rte_pmd_i40e_set_vf_mac_addr(
340 representor->adapter->pf.dev_data->port_id,
341 representor->vf_id, mac_addr);
345 i40e_vf_representor_vlan_filter_set(struct rte_eth_dev *ethdev,
346 uint16_t vlan_id, int on)
348 struct i40e_vf_representor *representor = ethdev->data->dev_private;
349 uint64_t vf_mask = 1ULL << representor->vf_id;
351 return rte_pmd_i40e_set_vf_vlan_filter(
352 representor->adapter->pf.dev_data->port_id,
353 vlan_id, vf_mask, on);
357 i40e_vf_representor_vlan_offload_set(struct rte_eth_dev *ethdev, int mask)
359 struct i40e_vf_representor *representor = ethdev->data->dev_private;
360 struct rte_eth_dev *pdev;
361 struct i40e_pf_vf *vf;
362 struct i40e_vsi *vsi;
366 pdev = &rte_eth_devices[representor->adapter->pf.dev_data->port_id];
367 vfid = representor->vf_id;
369 if (!is_i40e_supported(pdev)) {
370 PMD_DRV_LOG(ERR, "Invalid PF dev.");
374 pf = I40E_DEV_PRIVATE_TO_PF(pdev->data->dev_private);
376 if (vfid >= pf->vf_num || !pf->vfs) {
377 PMD_DRV_LOG(ERR, "Invalid VF ID.");
384 PMD_DRV_LOG(ERR, "Invalid VSI.");
388 if (mask & RTE_ETH_VLAN_FILTER_MASK) {
389 /* Enable or disable VLAN filtering offload */
390 if (ethdev->data->dev_conf.rxmode.offloads &
391 RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
392 return i40e_vsi_config_vlan_filter(vsi, TRUE);
394 return i40e_vsi_config_vlan_filter(vsi, FALSE);
397 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
398 /* Enable or disable VLAN stripping offload */
399 if (ethdev->data->dev_conf.rxmode.offloads &
400 RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
401 return i40e_vsi_config_vlan_stripping(vsi, TRUE);
403 return i40e_vsi_config_vlan_stripping(vsi, FALSE);
410 i40e_vf_representor_vlan_strip_queue_set(struct rte_eth_dev *ethdev,
411 __rte_unused uint16_t rx_queue_id, int on)
413 struct i40e_vf_representor *representor = ethdev->data->dev_private;
415 rte_pmd_i40e_set_vf_vlan_stripq(
416 representor->adapter->pf.dev_data->port_id,
417 representor->vf_id, on);
421 i40e_vf_representor_vlan_pvid_set(struct rte_eth_dev *ethdev, uint16_t vlan_id,
424 struct i40e_vf_representor *representor = ethdev->data->dev_private;
426 return rte_pmd_i40e_set_vf_vlan_insert(
427 representor->adapter->pf.dev_data->port_id,
428 representor->vf_id, vlan_id);
431 static const struct eth_dev_ops i40e_representor_dev_ops = {
432 .dev_infos_get = i40e_vf_representor_dev_infos_get,
434 .dev_start = i40e_vf_representor_dev_start,
435 .dev_configure = i40e_vf_representor_dev_configure,
436 .dev_stop = i40e_vf_representor_dev_stop,
438 .rx_queue_setup = i40e_vf_representor_rx_queue_setup,
439 .tx_queue_setup = i40e_vf_representor_tx_queue_setup,
441 .link_update = i40e_vf_representor_link_update,
443 .stats_get = i40e_vf_representor_stats_get,
444 .stats_reset = i40e_vf_representor_stats_reset,
446 .promiscuous_enable = i40e_vf_representor_promiscuous_enable,
447 .promiscuous_disable = i40e_vf_representor_promiscuous_disable,
449 .allmulticast_enable = i40e_vf_representor_allmulticast_enable,
450 .allmulticast_disable = i40e_vf_representor_allmulticast_disable,
452 .mac_addr_remove = i40e_vf_representor_mac_addr_remove,
453 .mac_addr_set = i40e_vf_representor_mac_addr_set,
455 .vlan_filter_set = i40e_vf_representor_vlan_filter_set,
456 .vlan_offload_set = i40e_vf_representor_vlan_offload_set,
457 .vlan_strip_queue_set = i40e_vf_representor_vlan_strip_queue_set,
458 .vlan_pvid_set = i40e_vf_representor_vlan_pvid_set
463 i40e_vf_representor_rx_burst(__rte_unused void *rx_queue,
464 __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
470 i40e_vf_representor_tx_burst(__rte_unused void *tx_queue,
471 __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts)
477 i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
479 struct i40e_vf_representor *representor = ethdev->data->dev_private;
482 struct i40e_pf_vf *vf;
483 struct rte_eth_link *link;
486 ((struct i40e_vf_representor *)init_params)->vf_id;
487 representor->switch_domain_id =
488 ((struct i40e_vf_representor *)init_params)->switch_domain_id;
489 representor->adapter =
490 ((struct i40e_vf_representor *)init_params)->adapter;
492 pf = I40E_DEV_PRIVATE_TO_PF(
493 representor->adapter->pf.dev_data->dev_private);
495 if (representor->vf_id >= pf->vf_num)
498 /* Set representor device ops */
499 ethdev->dev_ops = &i40e_representor_dev_ops;
501 /* No data-path, but need stub Rx/Tx functions to avoid crash
502 * when testing with the likes of testpmd.
504 ethdev->rx_pkt_burst = i40e_vf_representor_rx_burst;
505 ethdev->tx_pkt_burst = i40e_vf_representor_tx_burst;
507 vf = &pf->vfs[representor->vf_id];
510 PMD_DRV_LOG(ERR, "Invalid VSI.");
514 ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
515 ethdev->data->representor_id = representor->vf_id;
516 ethdev->data->backer_port_id = pf->dev_data->port_id;
518 /* Setting the number queues allocated to the VF */
519 ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
520 ethdev->data->nb_tx_queues = vf->vsi->nb_qps;
522 ethdev->data->mac_addrs = &vf->mac_addr;
524 /* Link state. Inherited from PF */
525 link = &representor->adapter->pf.dev_data->dev_link;
527 ethdev->data->dev_link.link_speed = link->link_speed;
528 ethdev->data->dev_link.link_duplex = link->link_duplex;
529 ethdev->data->dev_link.link_status = link->link_status;
530 ethdev->data->dev_link.link_autoneg = link->link_autoneg;
536 i40e_vf_representor_uninit(struct rte_eth_dev *ethdev)
538 /* mac_addrs must not be freed because part of i40e_pf_vf */
539 ethdev->data->mac_addrs = NULL;