vdpa/sfc: support device and protocol features queries

Implement vDPA ops get_feature and get_protocol_features.
This patch retrieves device supported features and enables
protocol features.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
This commit is contained in:
Vijay Kumar Srivastava 2021-11-03 19:27:47 +05:30 committed by Maxime Coquelin
parent 6dad9a7353
commit f66a66e631
8 changed files with 142 additions and 9 deletions

View File

@ -4,6 +4,16 @@
; Refer to default.ini for the full list of available driver features.
;
[Features]
csum = Y
guest csum = Y
host tso4 = Y
host tso6 = Y
version 1 = Y
mrg rxbuf = Y
any layout = Y
in_order = Y
proto host notifier = Y
IOMMU platform = Y
Linux = Y
x86-64 = Y
Usage doc = Y

View File

@ -187,7 +187,7 @@ prefetch_read_once(const volatile void *addr)
#define EFSYS_OPT_MAE 1
#define EFSYS_OPT_VIRTIO 0
#define EFSYS_OPT_VIRTIO 1
/* ID */

View File

@ -247,6 +247,16 @@ INTERNAL {
efx_txq_nbufs;
efx_txq_size;
efx_virtio_fini;
efx_virtio_get_doorbell_offset;
efx_virtio_get_features;
efx_virtio_init;
efx_virtio_qcreate;
efx_virtio_qdestroy;
efx_virtio_qstart;
efx_virtio_qstop;
efx_virtio_verify_features;
sfc_efx_dev_class_get;
sfc_efx_family;

View File

@ -42,6 +42,26 @@ sfc_vdpa_get_adapter_by_dev(struct rte_pci_device *pdev)
return found ? sva : NULL;
}
struct sfc_vdpa_ops_data *
sfc_vdpa_get_data_by_dev(struct rte_vdpa_device *vdpa_dev)
{
bool found = false;
struct sfc_vdpa_adapter *sva;
pthread_mutex_lock(&sfc_vdpa_adapter_list_lock);
TAILQ_FOREACH(sva, &sfc_vdpa_adapter_list, next) {
if (vdpa_dev == sva->ops_data->vdpa_dev) {
found = true;
break;
}
}
pthread_mutex_unlock(&sfc_vdpa_adapter_list_lock);
return found ? sva->ops_data : NULL;
}
static int
sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)
{

View File

@ -58,6 +58,8 @@ sfc_vdpa_register_logtype(const struct rte_pci_addr *pci_addr,
struct sfc_vdpa_adapter *
sfc_vdpa_get_adapter_by_dev(struct rte_pci_device *pdev);
struct sfc_vdpa_ops_data *
sfc_vdpa_get_data_by_dev(struct rte_vdpa_device *vdpa_dev);
int
sfc_vdpa_hw_init(struct sfc_vdpa_adapter *sva);

View File

@ -276,10 +276,20 @@ sfc_vdpa_hw_init(struct sfc_vdpa_adapter *sva)
if (rc != 0)
goto fail_estimate_rsrc_limits;
sfc_vdpa_log_init(sva, "init virtio");
rc = efx_virtio_init(enp);
if (rc != 0) {
sfc_vdpa_err(sva, "virtio init failed: %s", rte_strerror(rc));
goto fail_virtio_init;
}
sfc_vdpa_log_init(sva, "done");
return 0;
fail_virtio_init:
efx_nic_fini(enp);
fail_estimate_rsrc_limits:
fail_nic_reset:
efx_nic_unprobe(enp);
@ -308,6 +318,9 @@ sfc_vdpa_hw_fini(struct sfc_vdpa_adapter *sva)
sfc_vdpa_log_init(sva, "entry");
sfc_vdpa_log_init(sva, "virtio fini");
efx_virtio_fini(enp);
sfc_vdpa_log_init(sva, "unprobe nic");
efx_nic_unprobe(enp);

View File

@ -2,18 +2,32 @@
* Copyright(c) 2020-2021 Xilinx, Inc.
*/
#include <rte_errno.h>
#include <rte_malloc.h>
#include <rte_vdpa.h>
#include <rte_vhost.h>
#include <vdpa_driver.h>
#include "efx.h"
#include "sfc_vdpa_ops.h"
#include "sfc_vdpa.h"
/* Dummy functions for mandatory vDPA ops to pass vDPA device registration.
* In subsequent patches these ops would be implemented.
/* These protocol features are needed to enable notifier ctrl */
#define SFC_VDPA_PROTOCOL_FEATURES \
((1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
(1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
(1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \
(1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \
(1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD))
/*
* Set of features which are enabled by default.
* Protocol feature bit is needed to enable notification notifier ctrl.
*/
#define SFC_VDPA_DEFAULT_FEATURES \
(1ULL << VHOST_USER_F_PROTOCOL_FEATURES)
static int
sfc_vdpa_get_queue_num(struct rte_vdpa_device *vdpa_dev, uint32_t *queue_num)
{
@ -23,23 +37,68 @@ sfc_vdpa_get_queue_num(struct rte_vdpa_device *vdpa_dev, uint32_t *queue_num)
return -1;
}
static int
sfc_vdpa_get_device_features(struct sfc_vdpa_ops_data *ops_data)
{
int rc;
uint64_t dev_features;
efx_nic_t *nic;
nic = sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)->nic;
rc = efx_virtio_get_features(nic, EFX_VIRTIO_DEVICE_TYPE_NET,
&dev_features);
if (rc != 0) {
sfc_vdpa_err(ops_data->dev_handle,
"could not read device feature: %s",
rte_strerror(rc));
return rc;
}
ops_data->dev_features = dev_features;
sfc_vdpa_info(ops_data->dev_handle,
"device supported virtio features : 0x%" PRIx64,
ops_data->dev_features);
return 0;
}
static int
sfc_vdpa_get_features(struct rte_vdpa_device *vdpa_dev, uint64_t *features)
{
RTE_SET_USED(vdpa_dev);
RTE_SET_USED(features);
struct sfc_vdpa_ops_data *ops_data;
return -1;
ops_data = sfc_vdpa_get_data_by_dev(vdpa_dev);
if (ops_data == NULL)
return -1;
*features = ops_data->drv_features;
sfc_vdpa_info(ops_data->dev_handle,
"vDPA ops get_feature :: features : 0x%" PRIx64,
*features);
return 0;
}
static int
sfc_vdpa_get_protocol_features(struct rte_vdpa_device *vdpa_dev,
uint64_t *features)
{
RTE_SET_USED(vdpa_dev);
RTE_SET_USED(features);
struct sfc_vdpa_ops_data *ops_data;
return -1;
ops_data = sfc_vdpa_get_data_by_dev(vdpa_dev);
if (ops_data == NULL)
return -1;
*features = SFC_VDPA_PROTOCOL_FEATURES;
sfc_vdpa_info(ops_data->dev_handle,
"vDPA ops get_protocol_feature :: features : 0x%" PRIx64,
*features);
return 0;
}
static int
@ -91,6 +150,7 @@ sfc_vdpa_device_init(void *dev_handle, enum sfc_vdpa_context context)
{
struct sfc_vdpa_ops_data *ops_data;
struct rte_pci_device *pci_dev;
int rc;
/* Create vDPA ops context */
ops_data = rte_zmalloc("vdpa", sizeof(struct sfc_vdpa_ops_data), 0);
@ -111,10 +171,25 @@ sfc_vdpa_device_init(void *dev_handle, enum sfc_vdpa_context context)
goto fail_register_device;
}
/* Read supported device features */
sfc_vdpa_log_init(dev_handle, "get device feature");
rc = sfc_vdpa_get_device_features(ops_data);
if (rc != 0)
goto fail_get_dev_feature;
/* Driver features are superset of device supported feature
* and any additional features supported by the driver.
*/
ops_data->drv_features =
ops_data->dev_features | SFC_VDPA_DEFAULT_FEATURES;
ops_data->state = SFC_VDPA_STATE_INITIALIZED;
return ops_data;
fail_get_dev_feature:
rte_vdpa_unregister_device(ops_data->vdpa_dev);
fail_register_device:
rte_free(ops_data);
return NULL;

View File

@ -23,6 +23,9 @@ struct sfc_vdpa_ops_data {
struct rte_vdpa_device *vdpa_dev;
enum sfc_vdpa_context vdpa_context;
enum sfc_vdpa_state state;
uint64_t dev_features;
uint64_t drv_features;
};
struct sfc_vdpa_ops_data *