199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2018 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_VDPA_H_ 699a2dd95SBruce Richardson #define _RTE_VDPA_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * Device specific vhost lib 1299a2dd95SBruce Richardson */ 1399a2dd95SBruce Richardson 1499a2dd95SBruce Richardson #include <stdint.h> 1599a2dd95SBruce Richardson 16*719834a6SMattias Rönnblom #ifdef __cplusplus 17*719834a6SMattias Rönnblom extern "C" { 18*719834a6SMattias Rönnblom #endif 19*719834a6SMattias Rönnblom 2099a2dd95SBruce Richardson /** Maximum name length for statistics counters */ 2199a2dd95SBruce Richardson #define RTE_VDPA_STATS_NAME_SIZE 64 2299a2dd95SBruce Richardson 2399a2dd95SBruce Richardson struct rte_vdpa_device; 2499a2dd95SBruce Richardson 2599a2dd95SBruce Richardson /** 2699a2dd95SBruce Richardson * A vDPA device statistic structure 2799a2dd95SBruce Richardson * 2899a2dd95SBruce Richardson * This structure is used by rte_vdpa_stats_get() to provide 2999a2dd95SBruce Richardson * statistics from the HW vDPA device. 3099a2dd95SBruce Richardson * 3199a2dd95SBruce Richardson * It maps a name id, corresponding to an index in the array returned 3299a2dd95SBruce Richardson * by rte_vdpa_get_stats_names, to a statistic value. 3399a2dd95SBruce Richardson */ 3499a2dd95SBruce Richardson struct rte_vdpa_stat { 3599a2dd95SBruce Richardson uint64_t id; /**< The index in stats name array */ 3699a2dd95SBruce Richardson uint64_t value; /**< The statistic counter value */ 3799a2dd95SBruce Richardson }; 3899a2dd95SBruce Richardson 3999a2dd95SBruce Richardson /** 4099a2dd95SBruce Richardson * A name element for statistics 4199a2dd95SBruce Richardson * 4299a2dd95SBruce Richardson * An array of this structure is returned by rte_vdpa_get_stats_names 4399a2dd95SBruce Richardson * It lists the names of extended statistics for a PMD. The rte_vdpa_stat 4499a2dd95SBruce Richardson * structure references these names by their array index 4599a2dd95SBruce Richardson */ 4699a2dd95SBruce Richardson struct rte_vdpa_stat_name { 4799a2dd95SBruce Richardson char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */ 4899a2dd95SBruce Richardson }; 4999a2dd95SBruce Richardson 5099a2dd95SBruce Richardson /** 5199a2dd95SBruce Richardson * Find the device id of a vdpa device from its name 5299a2dd95SBruce Richardson * 5399a2dd95SBruce Richardson * @param name 5499a2dd95SBruce Richardson * the vdpa device name 5599a2dd95SBruce Richardson * @return 5699a2dd95SBruce Richardson * vDPA device pointer on success, NULL on failure 5799a2dd95SBruce Richardson */ 5899a2dd95SBruce Richardson struct rte_vdpa_device * 5999a2dd95SBruce Richardson rte_vdpa_find_device_by_name(const char *name); 6099a2dd95SBruce Richardson 6199a2dd95SBruce Richardson /** 6299a2dd95SBruce Richardson * Get the generic device from the vdpa device 6399a2dd95SBruce Richardson * 6499a2dd95SBruce Richardson * @param vdpa_dev 6599a2dd95SBruce Richardson * the vdpa device pointer 6699a2dd95SBruce Richardson * @return 6799a2dd95SBruce Richardson * generic device pointer on success, NULL on failure 6899a2dd95SBruce Richardson */ 6999a2dd95SBruce Richardson struct rte_device * 7099a2dd95SBruce Richardson rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); 7199a2dd95SBruce Richardson 7299a2dd95SBruce Richardson /** 7399a2dd95SBruce Richardson * Get number of queue pairs supported by the vDPA device 7499a2dd95SBruce Richardson * 7599a2dd95SBruce Richardson * @param dev 7699a2dd95SBruce Richardson * vDP device pointer 7799a2dd95SBruce Richardson * @param queue_num 7899a2dd95SBruce Richardson * pointer on where the number of queue is stored 7999a2dd95SBruce Richardson * @return 8099a2dd95SBruce Richardson * 0 on success, -1 on failure 8199a2dd95SBruce Richardson */ 8299a2dd95SBruce Richardson int 8399a2dd95SBruce Richardson rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num); 8499a2dd95SBruce Richardson 8599a2dd95SBruce Richardson /** 8699a2dd95SBruce Richardson * Get the Virtio features supported by the vDPA device 8799a2dd95SBruce Richardson * 8899a2dd95SBruce Richardson * @param dev 8999a2dd95SBruce Richardson * vDP device pointer 9099a2dd95SBruce Richardson * @param features 9199a2dd95SBruce Richardson * pointer on where the supported features are stored 9299a2dd95SBruce Richardson * @return 9399a2dd95SBruce Richardson * 0 on success, -1 on failure 9499a2dd95SBruce Richardson */ 9599a2dd95SBruce Richardson int 9699a2dd95SBruce Richardson rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features); 9799a2dd95SBruce Richardson 9899a2dd95SBruce Richardson /** 9999a2dd95SBruce Richardson * Get the Vhost-user protocol features supported by the vDPA device 10099a2dd95SBruce Richardson * 10199a2dd95SBruce Richardson * @param dev 10299a2dd95SBruce Richardson * vDP device pointer 10399a2dd95SBruce Richardson * @param features 10499a2dd95SBruce Richardson * pointer on where the supported protocol features are stored 10599a2dd95SBruce Richardson * @return 10699a2dd95SBruce Richardson * 0 on success, -1 on failure 10799a2dd95SBruce Richardson */ 10899a2dd95SBruce Richardson int 10999a2dd95SBruce Richardson rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features); 11099a2dd95SBruce Richardson 11199a2dd95SBruce Richardson /** 11299a2dd95SBruce Richardson * Retrieve names of statistics of a vDPA device. 11399a2dd95SBruce Richardson * 11499a2dd95SBruce Richardson * There is an assumption that 'stat_names' and 'stats' arrays are matched 11599a2dd95SBruce Richardson * by array index: stats_names[i].name => stats[i].value 11699a2dd95SBruce Richardson * 11799a2dd95SBruce Richardson * And the array index is same with id field of 'struct rte_vdpa_stat': 11899a2dd95SBruce Richardson * stats[i].id == i 11999a2dd95SBruce Richardson * 12099a2dd95SBruce Richardson * @param dev 12199a2dd95SBruce Richardson * vDPA device pointer 12299a2dd95SBruce Richardson * @param stats_names 12399a2dd95SBruce Richardson * array of at least size elements to be filled. 12499a2dd95SBruce Richardson * If set to NULL, the function returns the required number of elements. 12599a2dd95SBruce Richardson * @param size 12699a2dd95SBruce Richardson * The number of elements in stats_names array. 12799a2dd95SBruce Richardson * @return 12899a2dd95SBruce Richardson * A negative value on error, otherwise the number of entries filled in the 12999a2dd95SBruce Richardson * stats name array. 13099a2dd95SBruce Richardson */ 13199a2dd95SBruce Richardson int 13299a2dd95SBruce Richardson rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, 13399a2dd95SBruce Richardson struct rte_vdpa_stat_name *stats_names, 13499a2dd95SBruce Richardson unsigned int size); 13599a2dd95SBruce Richardson 13699a2dd95SBruce Richardson /** 13799a2dd95SBruce Richardson * Retrieve statistics of a vDPA device. 13899a2dd95SBruce Richardson * 13999a2dd95SBruce Richardson * There is an assumption that 'stat_names' and 'stats' arrays are matched 14099a2dd95SBruce Richardson * by array index: stats_names[i].name => stats[i].value 14199a2dd95SBruce Richardson * 14299a2dd95SBruce Richardson * And the array index is same with id field of 'struct rte_vdpa_stat': 14399a2dd95SBruce Richardson * stats[i].id == i 14499a2dd95SBruce Richardson * 14599a2dd95SBruce Richardson * @param dev 14699a2dd95SBruce Richardson * vDPA device pointer 14799a2dd95SBruce Richardson * @param qid 14899a2dd95SBruce Richardson * queue id 14999a2dd95SBruce Richardson * @param stats 15099a2dd95SBruce Richardson * A pointer to a table of structure of type rte_vdpa_stat to be filled with 15199a2dd95SBruce Richardson * device statistics ids and values. 15299a2dd95SBruce Richardson * @param n 15399a2dd95SBruce Richardson * The number of elements in stats array. 15499a2dd95SBruce Richardson * @return 15599a2dd95SBruce Richardson * A negative value on error, otherwise the number of entries filled in the 15699a2dd95SBruce Richardson * stats table. 15799a2dd95SBruce Richardson */ 15899a2dd95SBruce Richardson int 15999a2dd95SBruce Richardson rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid, 16099a2dd95SBruce Richardson struct rte_vdpa_stat *stats, unsigned int n); 16199a2dd95SBruce Richardson /** 16299a2dd95SBruce Richardson * Reset statistics of a vDPA device. 16399a2dd95SBruce Richardson * 16499a2dd95SBruce Richardson * @param dev 16599a2dd95SBruce Richardson * vDPA device pointer 16699a2dd95SBruce Richardson * @param qid 16799a2dd95SBruce Richardson * queue id 16899a2dd95SBruce Richardson * @return 16999a2dd95SBruce Richardson * 0 on success, a negative value on error. 17099a2dd95SBruce Richardson */ 17199a2dd95SBruce Richardson int 17299a2dd95SBruce Richardson rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid); 173cedca408SBrian Dooley 174cedca408SBrian Dooley #ifdef __cplusplus 175cedca408SBrian Dooley } 176cedca408SBrian Dooley #endif 177cedca408SBrian Dooley 17899a2dd95SBruce Richardson #endif /* _RTE_VDPA_H_ */ 179