DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver
@ 2021-03-11 11:03 Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
                   ` (10 more replies)
  0 siblings, 11 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev

Update base driver to provide functionality required by vDPA driver.

Factor out helper functions to be shared by net and vDPA drivers.

Vijay Kumar Srivastava (6):
  common/sfc_efx/base: add virtio build dependency
  common/sfc_efx/base: add support to get virtio features
  common/sfc_efx/base: add support to verify virtio features
  common/sfc_efx: add support to get the device class
  net/sfc: skip driver probe for incompatible device class
  drivers: add common driver API to get efx family

Vijay Srivastava (2):
  common/sfc_efx/base: add base virtio support for vDPA
  common/sfc_efx/base: add API to get VirtQ doorbell offset

 doc/guides/nics/sfc_efx.rst                |   8 +
 drivers/common/meson.build                 |   2 +-
 drivers/common/sfc_efx/base/efx.h          | 142 ++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   9 +
 drivers/common/sfc_efx/base/efx_impl.h     |  42 +++
 drivers/common/sfc_efx/base/efx_virtio.c   | 340 ++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  37 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 379 +++++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 drivers/common/sfc_efx/meson.build         |   1 +
 drivers/common/sfc_efx/sfc_efx.c           | 105 ++++++
 drivers/common/sfc_efx/sfc_efx.h           |  44 +++
 drivers/common/sfc_efx/version.map         |  13 +
 drivers/meson.build                        |   1 +
 drivers/net/sfc/sfc.c                      |  61 +---
 drivers/net/sfc/sfc.h                      |   1 +
 drivers/net/sfc/sfc_ethdev.c               |   7 +
 drivers/net/sfc/sfc_kvargs.c               |   1 +
 19 files changed, 1139 insertions(+), 58 deletions(-)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

In the vDPA mode, only data path is offloaded in the hardware and
control path still goes through the hypervisor and it configures
virtqueues via vDPA driver so new virtqueue APIs are required.

Implement virtio init/fini and virtqueue create/destroy APIs.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 109 +++++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   6 +
 drivers/common/sfc_efx/base/efx_impl.h     |  36 ++++
 drivers/common/sfc_efx/base/efx_virtio.c   | 216 +++++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  17 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 190 ++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 drivers/common/sfc_efx/version.map         |   7 +
 9 files changed, 585 insertions(+)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index ccf9c7ab8a..f9004ae2a4 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4368,6 +4368,115 @@ efx_mae_action_rule_remove(
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+/* A Virtio net device can have one or more pairs of Rx/Tx virtqueues
+ * while virtio block device has a single virtqueue,
+ * for further details refer section of 4.2.3 of SF-120734
+ */
+typedef enum efx_virtio_vq_type_e {
+	EFX_VIRTIO_VQ_TYPE_NET_RXQ,
+	EFX_VIRTIO_VQ_TYPE_NET_TXQ,
+	EFX_VIRTIO_VQ_TYPE_BLOCK,
+	EFX_VIRTIO_VQ_NTYPES
+} efx_virtio_vq_type_t;
+
+typedef struct efx_virtio_vq_dyncfg_s {
+	/*
+	 * If queue is being created to be migrated then this
+	 * should be the FINAL_PIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_pidx;
+	/*
+	 * If this queue is being created to be migrated then this
+	 * should be the FINAL_CIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_cidx;
+} efx_virtio_vq_dyncfg_t;
+
+/*
+ * Virtqueue size must be a power of 2, maximum size is 32768
+ * (see VIRTIO v1.1 section 2.6)
+ */
+#define EFX_VIRTIO_MAX_VQ_SIZE	0x8000
+
+typedef struct efx_virtio_vq_cfg_s {
+	unsigned int		evvc_vq_num;
+	efx_virtio_vq_type_t	evvc_type;
+	/*
+	 * vDPA as VF : It is target VF number if queue is being created on VF.
+	 * vDPA as PF : If queue to be created on PF then it should be
+	 * EFX_PCI_VF_INVALID.
+	 */
+	uint16_t		evvc_target_vf;
+	/*
+	 * Maximum virtqueue size is EFX_VIRTIO_MAX_VQ_SIZE and
+	 * virtqueue size 0 means the queue is unavailable.
+	 */
+	uint32_t		evvc_vq_size;
+	efsys_dma_addr_t        evvc_desc_tbl_addr;
+	efsys_dma_addr_t	evvc_avail_ring_addr;
+	efsys_dma_addr_t	evvc_used_ring_addr;
+	/* MSIX vector number for the virtqueue or 0xFFFF if MSIX is not used */
+	uint16_t                evvc_msix_vector;
+	/*
+	 * evvc_pas_id contains a PCIe address space identifier if the queue
+	 * uses PASID.
+	 */
+	boolean_t               evvc_use_pasid;
+	uint32_t		evvc_pas_id;
+	/* Negotiated virtio features to be applied to this virtqueue */
+	uint64_t		evcc_features;
+} efx_virtio_vq_cfg_t;
+
+typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp);
+
+LIBEFX_API
+extern			void
+efx_virtio_fini(
+	__in		efx_nic_t *enp);
+
+/*
+ * When virtio net driver in the guest sets VIRTIO_CONFIG_STATUS_DRIVER_OK bit,
+ * hypervisor starts configuring all the virtqueues in the device. When the
+ * vhost_user has received VHOST_USER_SET_VRING_ENABLE for all the virtqueues,
+ * then it invokes VDPA driver callback dev_conf. APIs qstart and qcreate would
+ * be invoked from dev_conf callback to create the virtqueues, For further
+ * details refer SF-122427.
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern			void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 078e5b9811..4e49163518 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -407,4 +407,10 @@
 # endif
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+# if !EFSYS_OPT_RIVERHEAD
+#  error "VIRTIO requires RIVERHEAD"
+# endif
+#endif /* EFSYS_OPT_VIRTIO */
+
 #endif /* _SYS_EFX_CHECK_H */
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 1005dd0aa8..374b14d253 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -65,6 +65,7 @@ extern "C" {
 #define	EFX_MOD_TUNNEL		0x00004000
 #define	EFX_MOD_EVB		0x00008000
 #define	EFX_MOD_PROXY		0x00010000
+#define	EFX_MOD_VIRTIO		0x00020000
 
 #define	EFX_RESET_PHY		0x00000001
 #define	EFX_RESET_RXQ_ERR	0x00000002
@@ -308,6 +309,16 @@ typedef struct efx_tunnel_ops_s {
 } efx_tunnel_ops_t;
 #endif /* EFSYS_OPT_TUNNEL */
 
+#if EFSYS_OPT_VIRTIO
+typedef struct efx_virtio_ops_s {
+	efx_rc_t	(*evo_virtio_qstart)(efx_virtio_vq_t *,
+				efx_virtio_vq_cfg_t *,
+				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
+				efx_virtio_vq_dyncfg_t *);
+} efx_virtio_ops_t;
+#endif /* EFSYS_OPT_VIRTIO */
+
 typedef struct efx_port_s {
 	efx_mac_type_t		ep_mac_type;
 	uint32_t		ep_phy_type;
@@ -858,6 +869,9 @@ struct efx_nic_s {
 #if EFSYS_OPT_VPD
 	const efx_vpd_ops_t	*en_evpdop;
 #endif	/* EFSYS_OPT_VPD */
+#if EFSYS_OPT_VIRTIO
+	const efx_virtio_ops_t	*en_evop;
+#endif	/* EFSYS_OPT_VPD */
 #if EFSYS_OPT_RX_SCALE
 	efx_rx_hash_support_t		en_hash_support;
 	efx_rx_scale_context_type_t	en_rss_context_type;
@@ -1750,6 +1764,28 @@ struct efx_mae_actions_s {
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+#define	EFX_VQ_MAGIC	0x026011950
+
+typedef enum efx_virtio_vq_state_e {
+	EFX_VIRTIO_VQ_STATE_UNKNOWN = 0,
+	EFX_VIRTIO_VQ_STATE_INITIALIZED,
+	EFX_VIRTIO_VQ_STATE_STARTED,
+	EFX_VIRTIO_VQ_NSTATES
+} efx_virtio_vq_state_t;
+
+struct efx_virtio_vq_s {
+	uint32_t		evv_magic;
+	efx_nic_t		*evv_enp;
+	efx_virtio_vq_state_t	evv_state;
+	uint32_t		evv_vi_index;
+	efx_virtio_vq_type_t	evv_type;
+	uint16_t		evv_target_vf;
+};
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
new file mode 100644
index 0000000000..1b7b01556e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_VIRTIO
+
+#if EFSYS_OPT_RIVERHEAD
+static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
+	rhead_virtio_qstart,			/* evo_virtio_qstart */
+	rhead_virtio_qstop,			/* evo_virtio_qstop */
+};
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_VIRTIO));
+
+	switch (enp->en_family) {
+#if EFSYS_OPT_RIVERHEAD
+	case EFX_FAMILY_RIVERHEAD:
+		evop = &__efx_virtio_rhead_ops;
+		break;
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	default:
+		EFSYS_ASSERT(0);
+		rc = ENOTSUP;
+		goto fail1;
+	}
+
+	enp->en_evop = evop;
+	enp->en_mod_flags |= EFX_MOD_VIRTIO;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+
+	return (rc);
+}
+
+	void
+efx_virtio_fini(
+	__in		efx_nic_t *enp)
+{
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_virtio_vq_t *evvp;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	/* Allocate a virtqueue object */
+	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	if (evvp == NULL) {
+		rc = ENOMEM;
+		goto fail1;
+	}
+
+	evvp->evv_magic = EFX_VQ_MAGIC;
+	evvp->evv_enp = enp;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	*evvpp = evvp;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvcp == NULL) || (evvp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	evop = evvp->evv_enp->en_evop;
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstart(evvp, evvcp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_type = evvcp->evvc_type;
+	evvp->evv_target_vf = evvcp->evvc_target_vf;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_STARTED;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if (evvp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(evvp->evv_magic, ==, EFX_VQ_MAGIC);
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_STARTED) {
+		rc = EINVAL;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstop(evvp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	return 0;
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp)
+{
+	efx_nic_t *enp;
+
+	if (evvp == NULL)
+		return;
+
+	enp = evvp->evv_enp;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+
+	if (evvp->evv_state == EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		/* Free the virtqueue object */
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	}
+}
+
+#endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/meson.build b/drivers/common/sfc_efx/base/meson.build
index 2016346eb5..de955dfe65 100644
--- a/drivers/common/sfc_efx/base/meson.build
+++ b/drivers/common/sfc_efx/base/meson.build
@@ -29,6 +29,7 @@ sources = [
 	'efx_tunnel.c',
 	'efx_tx.c',
 	'efx_vpd.c',
+	'efx_virtio.c',
 	'mcdi_mon.c',
 	'siena_mac.c',
 	'siena_mcdi.c',
@@ -61,6 +62,7 @@ sources = [
 	'rhead_rx.c',
 	'rhead_tunnel.c',
 	'rhead_tx.c',
+	'rhead_virtio.c',
 ]
 
 extra_flags = [
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 09a991f566..e22c3e9b1a 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -477,6 +477,23 @@ rhead_nic_xilinx_cap_tbl_read_ef100_locator(
 	__in				efsys_dma_addr_t offset,
 	__out				efx_bar_region_t *ebrp);
 
+#if EFSYS_OPT_VIRTIO
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstart(
+	__in				efx_virtio_vq_t *evvp,
+	__in				efx_virtio_vq_cfg_t *evvcp,
+	__in_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstop(
+	__in				efx_virtio_vq_t *evvp,
+	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
new file mode 100644
index 0000000000..d1719f834e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -0,0 +1,190 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO
+
+/*
+ * Get function-local index of the associated VI from the
+ * virtqueue number queue 0 is reserved for MCDI
+ */
+#define EFX_VIRTIO_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1)
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t vi_index;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_RXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_TXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_BLOCK);
+
+	if (evvcp->evvc_type >= EFX_VIRTIO_VQ_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	/* virtqueue size must be power of 2 */
+	if ((!ISP2(evvcp->evvc_vq_size)) ||
+	    (evvcp->evvc_vq_size > EFX_VIRTIO_MAX_VQ_SIZE)) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		if ((evvdp->evvd_vq_cidx > evvcp->evvc_vq_size) ||
+		    (evvdp->evvd_vq_pidx > evvcp->evvc_vq_size)) {
+			rc = EINVAL;
+			goto fail3;
+		}
+	}
+
+	req.emr_cmd = MC_CMD_VIRTIO_INIT_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_INIT_QUEUE_REQ_QUEUE_TYPE,
+		evvcp->evvc_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvcp->evvc_target_vf);
+
+	vi_index = EFX_VIRTIO_GET_VI_INDEX(evvcp->evvc_vq_num);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE, vi_index);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_SIZE,
+		evvcp->evvc_vq_size);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_LO,
+		evvcp->evvc_desc_tbl_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_HI,
+		evvcp->evvc_desc_tbl_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_LO,
+		evvcp->evvc_avail_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_HI,
+		evvcp->evvc_avail_ring_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_LO,
+		evvcp->evvc_used_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_HI,
+		evvcp->evvc_used_ring_addr >> 32);
+
+	if (evvcp->evvc_use_pasid) {
+		MCDI_IN_POPULATE_DWORD_1(req, VIRTIO_INIT_QUEUE_REQ_FLAGS,
+			VIRTIO_INIT_QUEUE_REQ_USE_PASID, 1);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_PASID,
+			evvcp->evvc_pas_id);
+	}
+
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_MSIX_VECTOR,
+		evvcp->evvc_msix_vector);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_LO,
+		evvcp->evcc_features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_HI,
+		evvcp->evcc_features >> 32);
+
+	if (evvdp != NULL) {
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_PIDX,
+			evvdp->evvd_vq_pidx);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_CIDX,
+			evvdp->evvd_vq_cidx);
+	}
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_MPORT_SELECTOR,
+		MAE_MPORT_SELECTOR_ASSIGNED);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail4;
+	}
+
+	evvp->evv_vi_index = vi_index;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_mcdi_req_t req;
+	efx_nic_t *enp = evvp->evv_enp;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_FINI_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_FINI_QUEUE_REQ_QUEUE_TYPE, evvp->evv_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		evvdp->evvd_vq_pidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_PIDX);
+		evvdp->evvd_vq_cidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_CIDX);
+	}
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+#endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/efsys.h b/drivers/common/sfc_efx/efsys.h
index a3ae3137e6..6427804470 100644
--- a/drivers/common/sfc_efx/efsys.h
+++ b/drivers/common/sfc_efx/efsys.h
@@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAE 1
 
+#define EFSYS_OPT_VIRTIO 0
+
 /* ID */
 
 typedef struct __efsys_identifier_s efsys_identifier_t;
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 403feeaf11..b4da2ee5e6 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -221,6 +221,13 @@ INTERNAL {
 	efx_txq_nbufs;
 	efx_txq_size;
 
+	efx_virtio_fini;
+	efx_virtio_init;
+	efx_virtio_qcreate;
+	efx_virtio_qdestroy;
+	efx_virtio_qstart;
+	efx_virtio_qstop;
+
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to query the virtqueue doorbell offset in the BAR for a VI.
For vDPA, the virtio net driver notifies the device directly by writing
doorbell. This API would be invoked from vDPA client driver.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 12 +++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 41 ++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  6 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 93 ++++++++++++++++++++++
 drivers/common/sfc_efx/version.map         |  1 +
 6 files changed, 155 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index f9004ae2a4..733ef4a115 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4475,6 +4475,18 @@ extern			void
 efx_virtio_qdestroy(
 	__in		efx_virtio_vq_t *evvp);
 
+/*
+ * Get the offset in the BAR of the doorbells for a VI.
+ * net device : doorbell offset of RX & TX queues
+ * block device : request doorbell offset in the BAR.
+ * For further details refer section of 4 of SF-119689
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 374b14d253..dee9d936df 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -316,6 +316,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
 				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
+				uint32_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 1b7b01556e..de998fcad9 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -12,6 +12,7 @@
 static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
+	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -213,4 +214,44 @@ efx_virtio_qdestroy(
 	}
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvp == NULL) || (offsetp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_get_doorbell_offset(evvp, offsetp)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index e22c3e9b1a..4601e491fd 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -492,6 +492,12 @@ rhead_virtio_qstop(
 	__in				efx_virtio_vq_t *evvp,
 	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in				efx_virtio_vq_t *evvp,
+	__out				uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index d1719f834e..147460c95c 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -187,4 +187,97 @@ rhead_virtio_qstop(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t type;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN,
+		MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN;
+
+	switch (evvp->evv_type) {
+	case EFX_VIRTIO_VQ_TYPE_NET_RXQ:
+	case EFX_VIRTIO_VQ_TYPE_NET_TXQ:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET;
+		break;
+	case EFX_VIRTIO_VQ_TYPE_BLOCK:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK;
+		break;
+	default:
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_DEVICE_ID,
+		type);
+	MCDI_IN_SET_WORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail2;
+	}
+
+	switch (type) {
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_NET:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail3;
+		}
+
+		if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_RXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_RX_DBL_OFFSET);
+		} else if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_TXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_TX_DBL_OFFSET);
+		}
+		break;
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail4;
+		}
+
+		*offsetp = MCDI_OUT_DWORD(req,
+			VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_DBL_OFFSET);
+		break;
+	default:
+		EFSYS_ASSERT(0);
+		rc = EINVAL;
+		goto fail5;
+	}
+
+	return (0);
+
+fail5:
+	EFSYS_PROBE(fail5);
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index b4da2ee5e6..0e41fd84fe 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -222,6 +222,7 @@ INTERNAL {
 	efx_txq_size;
 
 	efx_virtio_fini;
+	efx_virtio_get_doorbell_offset;
 	efx_virtio_init;
 	efx_virtio_qcreate;
 	efx_virtio_qdestroy;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 3/8] common/sfc_efx/base: add virtio build dependency
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add EFSYS_HAS_UINT64 build dependency on EFSYS_OPT_VIRTIO.
virtio features are represented as bitmask in 64-bit unsigned
integer.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx_check.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 4e49163518..da6b682cbc 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -411,6 +411,9 @@
 # if !EFSYS_OPT_RIVERHEAD
 #  error "VIRTIO requires RIVERHEAD"
 # endif
+# if !EFSYS_HAS_UINT64
+#  error "VIRTIO requires UINT64"
+# endif
 #endif /* EFSYS_OPT_VIRTIO */
 
 #endif /* _SYS_EFX_CHECK_H */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 4/8] common/sfc_efx/base: add support to get virtio features
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (2 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to get virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 14 ++++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 45 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 +++
 drivers/common/sfc_efx/base/rhead_virtio.c | 52 ++++++++++++++++++++++
 drivers/common/sfc_efx/version.map         |  1 +
 6 files changed, 121 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 733ef4a115..ded6c4cac3 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4433,6 +4433,13 @@ typedef struct efx_virtio_vq_cfg_s {
 
 typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
 
+typedef enum efx_virtio_device_type_e {
+	EFX_VIRTIO_DEVICE_TYPE_RESERVED,
+	EFX_VIRTIO_DEVICE_TYPE_NET,
+	EFX_VIRTIO_DEVICE_TYPE_BLOCK,
+	EFX_VIRTIO_DEVICE_NTYPES
+} efx_virtio_device_type_t;
+
 LIBEFX_API
 extern	__checkReturn	efx_rc_t
 efx_virtio_init(
@@ -4487,6 +4494,13 @@ efx_virtio_get_doorbell_offset(
 	__in		efx_virtio_vq_t *evvp,
 	__out		uint32_t *offsetp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index dee9d936df..ba24babddd 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -318,6 +318,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
 				uint32_t *);
+	efx_rc_t	(*evo_get_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index de998fcad9..20c22f02b5 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -13,6 +13,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
+	rhead_virtio_get_features,		/* evo_get_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -254,4 +255,48 @@ efx_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (featuresp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_get_features(enp, type, featuresp)) != 0)
+		goto fail4;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 4601e491fd..2d69cf02e6 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -498,6 +498,13 @@ rhead_virtio_get_doorbell_offset(
 	__in				efx_virtio_vq_t *evvp,
 	__out				uint32_t *offsetp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__out				uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 147460c95c..508d03d58f 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -280,4 +280,56 @@ rhead_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	efx_mcdi_req_t req;
+	uint32_t features_lo;
+	uint32_t features_hi;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_FEATURES_IN_DEVICE_ID, type);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	features_lo = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_LO);
+	features_hi = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_HI);
+	*featuresp = ((uint64_t)features_hi << 32) | features_lo;
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 0e41fd84fe..01be45e9e9 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -223,6 +223,7 @@ INTERNAL {
 
 	efx_virtio_fini;
 	efx_virtio_get_doorbell_offset;
+	efx_virtio_get_features;
 	efx_virtio_init;
 	efx_virtio_qcreate;
 	efx_virtio_qdestroy;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 5/8] common/sfc_efx/base: add support to verify virtio features
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (3 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to verify virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          |  7 ++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 38 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 ++++
 drivers/common/sfc_efx/base/rhead_virtio.c | 44 ++++++++++++++++++++++
 drivers/common/sfc_efx/version.map         |  1 +
 6 files changed, 99 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index ded6c4cac3..f3b386177d 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4501,6 +4501,13 @@ efx_virtio_get_features(
 	__in		efx_virtio_device_type_t type,
 	__out		uint64_t *featuresp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index ba24babddd..94c730f4f5 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -320,6 +320,8 @@ typedef struct efx_virtio_ops_s {
 				uint32_t *);
 	efx_rc_t	(*evo_get_features)(efx_nic_t *,
 				efx_virtio_device_type_t, uint64_t *);
+	efx_rc_t	(*evo_verify_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 20c22f02b5..b46997c09e 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -14,6 +14,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 	rhead_virtio_get_features,		/* evo_get_features */
+	rhead_virtio_verify_features,		/* evo_verify_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -299,4 +300,41 @@ efx_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_verify_features(enp, type, features)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 2d69cf02e6..2e696a259f 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -505,6 +505,13 @@ rhead_virtio_get_features(
 	__in				efx_virtio_device_type_t type,
 	__out				uint64_t *featuresp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_verify_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__in				uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 508d03d58f..0023ea1e83 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -332,4 +332,48 @@ rhead_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	efx_mcdi_req_t req;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_TEST_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_DEVICE_ID, type);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_LO,
+		features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_HI,
+		((features >> 32) & 0xFFFFFFFF));
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 01be45e9e9..fd275104e4 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -229,6 +229,7 @@ INTERNAL {
 	efx_virtio_qdestroy;
 	efx_virtio_qstart;
 	efx_virtio_qstop;
+	efx_virtio_verify_features;
 
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 6/8] common/sfc_efx: add support to get the device class
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (4 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Device class argument would be used to select compatible driver.
Driver probe would be skipped for incompatible device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/sfc_efx.c   | 49 ++++++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 34 +++++++++++++++++++++
 drivers/common/sfc_efx/version.map |  2 ++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index 0b8d5efee9..e165150bf2 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -7,12 +7,61 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
+#include <string.h>
 #include <rte_log.h>
+#include <rte_kvargs.h>
+#include <rte_devargs.h>
 
 #include "sfc_efx_log.h"
+#include "sfc_efx.h"
 
 uint32_t sfc_efx_logtype;
 
+static int
+sfc_efx_kvarg_dev_class_handler(__rte_unused const char *key,
+				const char *class_str, void *opaque)
+{
+	enum sfc_efx_dev_class *dev_class = opaque;
+
+	if (class_str == NULL)
+		return *dev_class;
+
+	if (strcmp(class_str, "vdpa") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_VDPA;
+	} else if (strcmp(class_str, "net") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_NET;
+	} else {
+		SFC_EFX_LOG(ERR, "Unsupported class %s.", class_str);
+		*dev_class = SFC_EFX_DEV_CLASS_INVALID;
+	}
+
+	return 0;
+}
+
+enum sfc_efx_dev_class
+sfc_efx_dev_class_get(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvargs;
+	const char *key = SFC_EFX_KVARG_DEV_CLASS;
+	enum sfc_efx_dev_class dev_class = SFC_EFX_DEV_CLASS_NET;
+
+	if (devargs == NULL)
+		return dev_class;
+
+	kvargs = rte_kvargs_parse(devargs->args, NULL);
+	if (kvargs == NULL)
+		return dev_class;
+
+	if (rte_kvargs_count(kvargs, key) != 0) {
+		rte_kvargs_process(kvargs, key, sfc_efx_kvarg_dev_class_handler,
+				   &dev_class);
+	}
+
+	rte_kvargs_free(kvargs);
+
+	return dev_class;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
new file mode 100644
index 0000000000..bbccd3e9e8
--- /dev/null
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2019-2020 Xilinx, Inc.
+ * Copyright(c) 2019 Solarflare Communications Inc.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ */
+
+#ifndef _SFC_EFX_H_
+#define _SFC_EFX_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SFC_EFX_KVARG_DEV_CLASS	"class"
+
+enum sfc_efx_dev_class {
+	SFC_EFX_DEV_CLASS_INVALID = 0,
+	SFC_EFX_DEV_CLASS_NET,
+	SFC_EFX_DEV_CLASS_VDPA,
+
+	SFC_EFX_DEV_NCLASS
+};
+
+__rte_internal
+enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFC_EFX_H_ */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index fd275104e4..5e9290b99d 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -231,6 +231,8 @@ INTERNAL {
 	efx_virtio_qstop;
 	efx_virtio_verify_features;
 
+	sfc_efx_dev_class_get;
+
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 7/8] net/sfc: skip driver probe for incompatible device class
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (5 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Driver would be probed only for the net device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst  | 8 ++++++++
 drivers/net/sfc/sfc.h        | 1 +
 drivers/net/sfc/sfc_ethdev.c | 7 +++++++
 drivers/net/sfc/sfc_kvargs.c | 1 +
 4 files changed, 17 insertions(+)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index f5e9f9495e..61ceae9714 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -357,6 +357,14 @@ allow option like "-a 02:00.0,arg1=value1,...".
 Case-insensitive 1/y/yes/on or 0/n/no/off may be used to specify
 boolean parameters value.
 
+- ``class`` [net|vdpa] (default **net**)
+
+  Choose the mode of operation of ef100 device.
+  **net** device will work as network device and will be probed by net/sfc driver.
+  **vdpa** device will work as vdpa device and will be probed by vdpa/sfc driver.
+  If this parameter is not specified then ef100 device will operate as
+  network device.
+
 - ``rx_datapath`` [auto|efx|ef10|ef10_essb] (default **auto**)
 
   Choose receive datapath implementation.
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index fdee800482..85b28ca3be 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -22,6 +22,7 @@
 #include "efx.h"
 
 #include "sfc_efx_mcdi.h"
+#include "sfc_efx.h"
 
 #include "sfc_debug.h"
 #include "sfc_log.h"
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 479b4f4df6..e68cf673cb 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -2161,6 +2161,13 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	const struct rte_ether_addr *from;
 	int ret;
 
+	if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
+			SFC_EFX_DEV_CLASS_NET) {
+		SFC_GENERIC_LOG(DEBUG,
+			"Incompatible device class: skip probing, should be probed by other sfc driver.");
+		return 1;
+	}
+
 	sfc_register_dp();
 
 	logtype_main = sfc_register_logtype(&pci_dev->addr,
diff --git a/drivers/net/sfc/sfc_kvargs.c b/drivers/net/sfc/sfc_kvargs.c
index 13e9665bb4..730ce4c7ee 100644
--- a/drivers/net/sfc/sfc_kvargs.c
+++ b/drivers/net/sfc/sfc_kvargs.c
@@ -28,6 +28,7 @@ sfc_kvargs_parse(struct sfc_adapter *sa)
 		SFC_KVARG_TX_DATAPATH,
 		SFC_KVARG_FW_VARIANT,
 		SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
+		SFC_EFX_KVARG_DEV_CLASS,
 		NULL,
 	};
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (6 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
@ 2021-03-11 11:03 ` Andrew Rybchenko
  2021-03-14  0:36   ` Ferruh Yigit
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-11 11:03 UTC (permalink / raw)
  To: dev; +Cc: Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Move function to get efx family from net driver into common driver.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/meson.build         |  2 +-
 drivers/common/sfc_efx/meson.build |  1 +
 drivers/common/sfc_efx/sfc_efx.c   | 56 +++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 10 +++++
 drivers/common/sfc_efx/version.map |  1 +
 drivers/meson.build                |  1 +
 drivers/net/sfc/sfc.c              | 61 ++----------------------------
 7 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/drivers/common/meson.build b/drivers/common/meson.build
index ba6325adf3..66e12143b2 100644
--- a/drivers/common/meson.build
+++ b/drivers/common/meson.build
@@ -6,4 +6,4 @@ if is_windows
 endif
 
 std_deps = ['eal']
-drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2', 'sfc_efx']
+drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2']
diff --git a/drivers/common/sfc_efx/meson.build b/drivers/common/sfc_efx/meson.build
index 6cb9f0737f..68559348a6 100644
--- a/drivers/common/sfc_efx/meson.build
+++ b/drivers/common/sfc_efx/meson.build
@@ -32,6 +32,7 @@ endforeach
 subdir('base')
 objs = [base_objs]
 
+deps += ['bus_pci']
 sources = files(
 	'sfc_efx.c',
 	'sfc_efx_mcdi.c',
diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index e165150bf2..d52fe50553 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -62,6 +62,62 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)
 	return dev_class;
 }
 
+static efx_rc_t
+sfc_efx_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
+		     efsys_bar_t *barp)
+{
+	efsys_bar_t result;
+	struct rte_pci_device *dev;
+
+	memset(&result, 0, sizeof(result));
+
+	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
+		return -EINVAL;
+
+	dev = configp->espc_dev;
+
+	result.esb_rid = bar_index;
+	result.esb_dev = dev;
+	result.esb_base = dev->mem_resource[bar_index].addr;
+
+	*barp = result;
+
+	return 0;
+}
+
+static efx_rc_t
+sfc_efx_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
+			 efx_dword_t *edp)
+{
+	int rc;
+
+	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
+				 offset);
+
+	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
+}
+
+int
+sfc_efx_family(struct rte_pci_device *pci_dev,
+	       efx_bar_region_t *mem_ebrp, efx_family_t *family)
+{
+	static const efx_pci_ops_t ops = {
+		.epo_config_readd = sfc_efx_pci_config_readd,
+		.epo_find_mem_bar = sfc_efx_find_mem_bar,
+	};
+
+	efsys_pci_config_t espcp;
+	int rc;
+
+	espcp.espc_dev = pci_dev;
+
+	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
+				  pci_dev->id.device_id,
+				  &espcp, &ops, family, mem_ebrp);
+
+	return rc;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
index bbccd3e9e8..71288b7299 100644
--- a/drivers/common/sfc_efx/sfc_efx.h
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -10,6 +10,11 @@
 #ifndef _SFC_EFX_H_
 #define _SFC_EFX_H_
 
+#include <rte_bus_pci.h>
+
+#include "efx.h"
+#include "efsys.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -27,6 +32,11 @@ enum sfc_efx_dev_class {
 __rte_internal
 enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
 
+__rte_internal
+int sfc_efx_family(struct rte_pci_device *pci_dev,
+		   efx_bar_region_t *mem_ebrp,
+		   efx_family_t *family);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 5e9290b99d..e3b9e1cb2b 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -232,6 +232,7 @@ INTERNAL {
 	efx_virtio_verify_features;
 
 	sfc_efx_dev_class_get;
+	sfc_efx_family;
 
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
diff --git a/drivers/meson.build b/drivers/meson.build
index fdf76120ac..9c8eded697 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -7,6 +7,7 @@ subdirs = [
 	'bus',
 	'common/mlx5', # depends on bus.
 	'common/qat', # depends on bus.
+	'common/sfc_efx', # depends on bus.
 	'mempool', # depends on common and bus.
 	'net',     # depends on common, bus, mempool
 	'raw',     # depends on common, bus and net.
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 671a166402..a4cd8dbd46 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -631,29 +631,6 @@ sfc_close(struct sfc_adapter *sa)
 	sfc_log_init(sa, "done");
 }
 
-static efx_rc_t
-sfc_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
-		 efsys_bar_t *barp)
-{
-	efsys_bar_t result;
-	struct rte_pci_device *dev;
-
-	memset(&result, 0, sizeof(result));
-
-	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
-		return EINVAL;
-
-	dev = configp->espc_dev;
-
-	result.esb_rid = bar_index;
-	result.esb_dev = dev;
-	result.esb_base = dev->mem_resource[bar_index].addr;
-
-	*barp = result;
-
-	return 0;
-}
-
 static int
 sfc_mem_bar_init(struct sfc_adapter *sa, const efx_bar_region_t *mem_ebrp)
 {
@@ -1095,43 +1072,12 @@ sfc_nic_probe(struct sfc_adapter *sa)
 	return 0;
 }
 
-static efx_rc_t
-sfc_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
-		     efx_dword_t *edp)
-{
-	int rc;
-
-	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
-				 offset);
-
-	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
-}
-
-static int
-sfc_family(struct sfc_adapter *sa, efx_bar_region_t *mem_ebrp)
-{
-	struct rte_eth_dev *eth_dev = sa->eth_dev;
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	efsys_pci_config_t espcp;
-	static const efx_pci_ops_t ops = {
-		.epo_config_readd = sfc_pci_config_readd,
-		.epo_find_mem_bar = sfc_find_mem_bar,
-	};
-	int rc;
-
-	espcp.espc_dev = pci_dev;
-
-	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
-				  pci_dev->id.device_id,
-				  &espcp, &ops, &sa->family, mem_ebrp);
-
-	return rc;
-}
-
 int
 sfc_probe(struct sfc_adapter *sa)
 {
 	efx_bar_region_t mem_ebrp;
+	struct rte_eth_dev *eth_dev = sa->eth_dev;
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	efx_nic_t *enp;
 	int rc;
 
@@ -1143,7 +1089,8 @@ sfc_probe(struct sfc_adapter *sa)
 	rte_atomic32_init(&sa->restart_required);
 
 	sfc_log_init(sa, "get family");
-	rc = sfc_family(sa, &mem_ebrp);
+	rc = sfc_efx_family(pci_dev, &mem_ebrp, &sa->family);
+
 	if (rc != 0)
 		goto fail_family;
 	sfc_log_init(sa,
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
@ 2021-03-14  0:36   ` Ferruh Yigit
  2021-03-15 14:01     ` Andrew Rybchenko
  0 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-14  0:36 UTC (permalink / raw)
  To: Andrew Rybchenko, dev; +Cc: Vijay Kumar Srivastava

On 3/11/2021 11:03 AM, Andrew Rybchenko wrote:
> From: Vijay Kumar Srivastava <vsrivast@xilinx.com>
> 
> Move function to get efx family from net driver into common driver.
> 
> Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

<...>

> diff --git a/drivers/meson.build b/drivers/meson.build
> index fdf76120ac..9c8eded697 100644
> --- a/drivers/meson.build
> +++ b/drivers/meson.build
> @@ -7,6 +7,7 @@ subdirs = [
>   	'bus',
>   	'common/mlx5', # depends on bus.
>   	'common/qat', # depends on bus.
> +	'common/sfc_efx', # depends on bus.
>   	'mempool', # depends on common and bus.
>   	'net',     # depends on common, bus, mempool
>   	'raw',     # depends on common, bus and net.

This enables building 'common/sfc_efx' for windows and fail. A windows build 
check needs to be added to 'common/sfc_efx'

^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (7 preceding siblings ...)
  2021-03-11 11:03 ` [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
@ 2021-03-15 13:58 ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
                     ` (8 more replies)
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
  10 siblings, 9 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

Update base driver to provide functionality required by vDPA driver.

Factor out helper functions to be shared by net and vDPA drivers.

v2:
 - fix windows build breakage - do not build common/sfc_efx in the case
   of windows
 - remove undefined efx_virtio_* functions from version.map (since
   EFSYS_OPT_VIRTIO is disabled)

Vijay Kumar Srivastava (6):
  common/sfc_efx/base: add virtio build dependency
  common/sfc_efx/base: add support to get virtio features
  common/sfc_efx/base: add support to verify virtio features
  common/sfc_efx: add support to get the device class
  net/sfc: skip driver probe for incompatible device class
  drivers: add common driver API to get efx family

Vijay Srivastava (2):
  common/sfc_efx/base: add base virtio support for vDPA
  common/sfc_efx/base: add API to get VirtQ doorbell offset

 doc/guides/nics/sfc_efx.rst                |   8 +
 drivers/common/meson.build                 |   2 +-
 drivers/common/sfc_efx/base/efx.h          | 142 ++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   9 +
 drivers/common/sfc_efx/base/efx_impl.h     |  42 +++
 drivers/common/sfc_efx/base/efx_virtio.c   | 340 ++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  37 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 379 +++++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 drivers/common/sfc_efx/meson.build         |   5 +
 drivers/common/sfc_efx/sfc_efx.c           | 105 ++++++
 drivers/common/sfc_efx/sfc_efx.h           |  44 +++
 drivers/common/sfc_efx/version.map         |   3 +
 drivers/meson.build                        |   1 +
 drivers/net/sfc/sfc.c                      |  61 +---
 drivers/net/sfc/sfc.h                      |   1 +
 drivers/net/sfc/sfc_ethdev.c               |   7 +
 drivers/net/sfc/sfc_kvargs.c               |   1 +
 19 files changed, 1133 insertions(+), 58 deletions(-)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

In the vDPA mode, only data path is offloaded in the hardware and
control path still goes through the hypervisor and it configures
virtqueues via vDPA driver so new virtqueue APIs are required.

Implement virtio init/fini and virtqueue create/destroy APIs.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 109 +++++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   6 +
 drivers/common/sfc_efx/base/efx_impl.h     |  36 ++++
 drivers/common/sfc_efx/base/efx_virtio.c   | 216 +++++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  17 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 190 ++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 8 files changed, 578 insertions(+)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 2c820022b2..c2c73bd382 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4368,6 +4368,115 @@ efx_mae_action_rule_remove(
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+/* A Virtio net device can have one or more pairs of Rx/Tx virtqueues
+ * while virtio block device has a single virtqueue,
+ * for further details refer section of 4.2.3 of SF-120734
+ */
+typedef enum efx_virtio_vq_type_e {
+	EFX_VIRTIO_VQ_TYPE_NET_RXQ,
+	EFX_VIRTIO_VQ_TYPE_NET_TXQ,
+	EFX_VIRTIO_VQ_TYPE_BLOCK,
+	EFX_VIRTIO_VQ_NTYPES
+} efx_virtio_vq_type_t;
+
+typedef struct efx_virtio_vq_dyncfg_s {
+	/*
+	 * If queue is being created to be migrated then this
+	 * should be the FINAL_PIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_pidx;
+	/*
+	 * If this queue is being created to be migrated then this
+	 * should be the FINAL_CIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_cidx;
+} efx_virtio_vq_dyncfg_t;
+
+/*
+ * Virtqueue size must be a power of 2, maximum size is 32768
+ * (see VIRTIO v1.1 section 2.6)
+ */
+#define EFX_VIRTIO_MAX_VQ_SIZE	0x8000
+
+typedef struct efx_virtio_vq_cfg_s {
+	unsigned int		evvc_vq_num;
+	efx_virtio_vq_type_t	evvc_type;
+	/*
+	 * vDPA as VF : It is target VF number if queue is being created on VF.
+	 * vDPA as PF : If queue to be created on PF then it should be
+	 * EFX_PCI_VF_INVALID.
+	 */
+	uint16_t		evvc_target_vf;
+	/*
+	 * Maximum virtqueue size is EFX_VIRTIO_MAX_VQ_SIZE and
+	 * virtqueue size 0 means the queue is unavailable.
+	 */
+	uint32_t		evvc_vq_size;
+	efsys_dma_addr_t        evvc_desc_tbl_addr;
+	efsys_dma_addr_t	evvc_avail_ring_addr;
+	efsys_dma_addr_t	evvc_used_ring_addr;
+	/* MSIX vector number for the virtqueue or 0xFFFF if MSIX is not used */
+	uint16_t                evvc_msix_vector;
+	/*
+	 * evvc_pas_id contains a PCIe address space identifier if the queue
+	 * uses PASID.
+	 */
+	boolean_t               evvc_use_pasid;
+	uint32_t		evvc_pas_id;
+	/* Negotiated virtio features to be applied to this virtqueue */
+	uint64_t		evcc_features;
+} efx_virtio_vq_cfg_t;
+
+typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp);
+
+LIBEFX_API
+extern			void
+efx_virtio_fini(
+	__in		efx_nic_t *enp);
+
+/*
+ * When virtio net driver in the guest sets VIRTIO_CONFIG_STATUS_DRIVER_OK bit,
+ * hypervisor starts configuring all the virtqueues in the device. When the
+ * vhost_user has received VHOST_USER_SET_VRING_ENABLE for all the virtqueues,
+ * then it invokes VDPA driver callback dev_conf. APIs qstart and qcreate would
+ * be invoked from dev_conf callback to create the virtqueues, For further
+ * details refer SF-122427.
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern			void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 9e288f272a..86a6d92fef 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -407,4 +407,10 @@
 # endif
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+# if !EFSYS_OPT_RIVERHEAD
+#  error "VIRTIO requires RIVERHEAD"
+# endif
+#endif /* EFSYS_OPT_VIRTIO */
+
 #endif /* _SYS_EFX_CHECK_H */
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index a0628e6927..f27d9fa82c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -65,6 +65,7 @@ extern "C" {
 #define	EFX_MOD_TUNNEL		0x00004000
 #define	EFX_MOD_EVB		0x00008000
 #define	EFX_MOD_PROXY		0x00010000
+#define	EFX_MOD_VIRTIO		0x00020000
 
 #define	EFX_RESET_PHY		0x00000001
 #define	EFX_RESET_RXQ_ERR	0x00000002
@@ -308,6 +309,16 @@ typedef struct efx_tunnel_ops_s {
 } efx_tunnel_ops_t;
 #endif /* EFSYS_OPT_TUNNEL */
 
+#if EFSYS_OPT_VIRTIO
+typedef struct efx_virtio_ops_s {
+	efx_rc_t	(*evo_virtio_qstart)(efx_virtio_vq_t *,
+				efx_virtio_vq_cfg_t *,
+				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
+				efx_virtio_vq_dyncfg_t *);
+} efx_virtio_ops_t;
+#endif /* EFSYS_OPT_VIRTIO */
+
 typedef struct efx_port_s {
 	efx_mac_type_t		ep_mac_type;
 	uint32_t		ep_phy_type;
@@ -858,6 +869,9 @@ struct efx_nic_s {
 #if EFSYS_OPT_VPD
 	const efx_vpd_ops_t	*en_evpdop;
 #endif	/* EFSYS_OPT_VPD */
+#if EFSYS_OPT_VIRTIO
+	const efx_virtio_ops_t	*en_evop;
+#endif	/* EFSYS_OPT_VPD */
 #if EFSYS_OPT_RX_SCALE
 	efx_rx_hash_support_t		en_hash_support;
 	efx_rx_scale_context_type_t	en_rss_context_type;
@@ -1750,6 +1764,28 @@ struct efx_mae_actions_s {
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+#define	EFX_VQ_MAGIC	0x026011950
+
+typedef enum efx_virtio_vq_state_e {
+	EFX_VIRTIO_VQ_STATE_UNKNOWN = 0,
+	EFX_VIRTIO_VQ_STATE_INITIALIZED,
+	EFX_VIRTIO_VQ_STATE_STARTED,
+	EFX_VIRTIO_VQ_NSTATES
+} efx_virtio_vq_state_t;
+
+struct efx_virtio_vq_s {
+	uint32_t		evv_magic;
+	efx_nic_t		*evv_enp;
+	efx_virtio_vq_state_t	evv_state;
+	uint32_t		evv_vi_index;
+	efx_virtio_vq_type_t	evv_type;
+	uint16_t		evv_target_vf;
+};
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
new file mode 100644
index 0000000000..1b7b01556e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_VIRTIO
+
+#if EFSYS_OPT_RIVERHEAD
+static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
+	rhead_virtio_qstart,			/* evo_virtio_qstart */
+	rhead_virtio_qstop,			/* evo_virtio_qstop */
+};
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_VIRTIO));
+
+	switch (enp->en_family) {
+#if EFSYS_OPT_RIVERHEAD
+	case EFX_FAMILY_RIVERHEAD:
+		evop = &__efx_virtio_rhead_ops;
+		break;
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	default:
+		EFSYS_ASSERT(0);
+		rc = ENOTSUP;
+		goto fail1;
+	}
+
+	enp->en_evop = evop;
+	enp->en_mod_flags |= EFX_MOD_VIRTIO;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+
+	return (rc);
+}
+
+	void
+efx_virtio_fini(
+	__in		efx_nic_t *enp)
+{
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_virtio_vq_t *evvp;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	/* Allocate a virtqueue object */
+	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	if (evvp == NULL) {
+		rc = ENOMEM;
+		goto fail1;
+	}
+
+	evvp->evv_magic = EFX_VQ_MAGIC;
+	evvp->evv_enp = enp;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	*evvpp = evvp;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvcp == NULL) || (evvp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	evop = evvp->evv_enp->en_evop;
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstart(evvp, evvcp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_type = evvcp->evvc_type;
+	evvp->evv_target_vf = evvcp->evvc_target_vf;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_STARTED;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if (evvp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(evvp->evv_magic, ==, EFX_VQ_MAGIC);
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_STARTED) {
+		rc = EINVAL;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstop(evvp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	return 0;
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp)
+{
+	efx_nic_t *enp;
+
+	if (evvp == NULL)
+		return;
+
+	enp = evvp->evv_enp;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+
+	if (evvp->evv_state == EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		/* Free the virtqueue object */
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	}
+}
+
+#endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/meson.build b/drivers/common/sfc_efx/base/meson.build
index f995eacac2..1a39418c65 100644
--- a/drivers/common/sfc_efx/base/meson.build
+++ b/drivers/common/sfc_efx/base/meson.build
@@ -29,6 +29,7 @@ sources = [
 	'efx_tunnel.c',
 	'efx_tx.c',
 	'efx_vpd.c',
+	'efx_virtio.c',
 	'mcdi_mon.c',
 	'siena_mac.c',
 	'siena_mcdi.c',
@@ -61,6 +62,7 @@ sources = [
 	'rhead_rx.c',
 	'rhead_tunnel.c',
 	'rhead_tx.c',
+	'rhead_virtio.c',
 ]
 
 extra_flags = [
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 50262b16a8..a15ac52a58 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -477,6 +477,23 @@ rhead_nic_xilinx_cap_tbl_read_ef100_locator(
 	__in				efsys_dma_addr_t offset,
 	__out				efx_bar_region_t *ebrp);
 
+#if EFSYS_OPT_VIRTIO
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstart(
+	__in				efx_virtio_vq_t *evvp,
+	__in				efx_virtio_vq_cfg_t *evvcp,
+	__in_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstop(
+	__in				efx_virtio_vq_t *evvp,
+	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
new file mode 100644
index 0000000000..d1719f834e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -0,0 +1,190 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO
+
+/*
+ * Get function-local index of the associated VI from the
+ * virtqueue number queue 0 is reserved for MCDI
+ */
+#define EFX_VIRTIO_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1)
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t vi_index;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_RXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_TXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_BLOCK);
+
+	if (evvcp->evvc_type >= EFX_VIRTIO_VQ_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	/* virtqueue size must be power of 2 */
+	if ((!ISP2(evvcp->evvc_vq_size)) ||
+	    (evvcp->evvc_vq_size > EFX_VIRTIO_MAX_VQ_SIZE)) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		if ((evvdp->evvd_vq_cidx > evvcp->evvc_vq_size) ||
+		    (evvdp->evvd_vq_pidx > evvcp->evvc_vq_size)) {
+			rc = EINVAL;
+			goto fail3;
+		}
+	}
+
+	req.emr_cmd = MC_CMD_VIRTIO_INIT_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_INIT_QUEUE_REQ_QUEUE_TYPE,
+		evvcp->evvc_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvcp->evvc_target_vf);
+
+	vi_index = EFX_VIRTIO_GET_VI_INDEX(evvcp->evvc_vq_num);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE, vi_index);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_SIZE,
+		evvcp->evvc_vq_size);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_LO,
+		evvcp->evvc_desc_tbl_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_HI,
+		evvcp->evvc_desc_tbl_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_LO,
+		evvcp->evvc_avail_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_HI,
+		evvcp->evvc_avail_ring_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_LO,
+		evvcp->evvc_used_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_HI,
+		evvcp->evvc_used_ring_addr >> 32);
+
+	if (evvcp->evvc_use_pasid) {
+		MCDI_IN_POPULATE_DWORD_1(req, VIRTIO_INIT_QUEUE_REQ_FLAGS,
+			VIRTIO_INIT_QUEUE_REQ_USE_PASID, 1);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_PASID,
+			evvcp->evvc_pas_id);
+	}
+
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_MSIX_VECTOR,
+		evvcp->evvc_msix_vector);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_LO,
+		evvcp->evcc_features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_HI,
+		evvcp->evcc_features >> 32);
+
+	if (evvdp != NULL) {
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_PIDX,
+			evvdp->evvd_vq_pidx);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_CIDX,
+			evvdp->evvd_vq_cidx);
+	}
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_MPORT_SELECTOR,
+		MAE_MPORT_SELECTOR_ASSIGNED);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail4;
+	}
+
+	evvp->evv_vi_index = vi_index;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_mcdi_req_t req;
+	efx_nic_t *enp = evvp->evv_enp;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_FINI_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_FINI_QUEUE_REQ_QUEUE_TYPE, evvp->evv_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		evvdp->evvd_vq_pidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_PIDX);
+		evvdp->evvd_vq_cidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_CIDX);
+	}
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+#endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/efsys.h b/drivers/common/sfc_efx/efsys.h
index 663601412e..d133d61b3d 100644
--- a/drivers/common/sfc_efx/efsys.h
+++ b/drivers/common/sfc_efx/efsys.h
@@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAE 1
 
+#define EFSYS_OPT_VIRTIO 0
+
 /* ID */
 
 typedef struct __efsys_identifier_s efsys_identifier_t;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

Add an API to query the virtqueue doorbell offset in the BAR for a VI.
For vDPA, the virtio net driver notifies the device directly by writing
doorbell. This API would be invoked from vDPA client driver.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 12 +++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 41 ++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  6 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 93 ++++++++++++++++++++++
 5 files changed, 154 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index c2c73bd382..d4b7d7f47e 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4475,6 +4475,18 @@ extern			void
 efx_virtio_qdestroy(
 	__in		efx_virtio_vq_t *evvp);
 
+/*
+ * Get the offset in the BAR of the doorbells for a VI.
+ * net device : doorbell offset of RX & TX queues
+ * block device : request doorbell offset in the BAR.
+ * For further details refer section of 4 of SF-119689
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index f27d9fa82c..d6742f4a8c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -316,6 +316,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
 				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
+				uint32_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 1b7b01556e..de998fcad9 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -12,6 +12,7 @@
 static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
+	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -213,4 +214,44 @@ efx_virtio_qdestroy(
 	}
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvp == NULL) || (offsetp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_get_doorbell_offset(evvp, offsetp)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index a15ac52a58..4304f63f4c 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -492,6 +492,12 @@ rhead_virtio_qstop(
 	__in				efx_virtio_vq_t *evvp,
 	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in				efx_virtio_vq_t *evvp,
+	__out				uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index d1719f834e..147460c95c 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -187,4 +187,97 @@ rhead_virtio_qstop(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t type;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN,
+		MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN;
+
+	switch (evvp->evv_type) {
+	case EFX_VIRTIO_VQ_TYPE_NET_RXQ:
+	case EFX_VIRTIO_VQ_TYPE_NET_TXQ:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET;
+		break;
+	case EFX_VIRTIO_VQ_TYPE_BLOCK:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK;
+		break;
+	default:
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_DEVICE_ID,
+		type);
+	MCDI_IN_SET_WORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail2;
+	}
+
+	switch (type) {
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_NET:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail3;
+		}
+
+		if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_RXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_RX_DBL_OFFSET);
+		} else if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_TXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_TX_DBL_OFFSET);
+		}
+		break;
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail4;
+		}
+
+		*offsetp = MCDI_OUT_DWORD(req,
+			VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_DBL_OFFSET);
+		break;
+	default:
+		EFSYS_ASSERT(0);
+		rc = EINVAL;
+		goto fail5;
+	}
+
+	return (0);
+
+fail5:
+	EFSYS_PROBE(fail5);
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 3/8] common/sfc_efx/base: add virtio build dependency
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add EFSYS_HAS_UINT64 build dependency on EFSYS_OPT_VIRTIO.
virtio features are represented as bitmask in 64-bit unsigned
integer.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx_check.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 86a6d92fef..66b38eeae0 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -411,6 +411,9 @@
 # if !EFSYS_OPT_RIVERHEAD
 #  error "VIRTIO requires RIVERHEAD"
 # endif
+# if !EFSYS_HAS_UINT64
+#  error "VIRTIO requires UINT64"
+# endif
 #endif /* EFSYS_OPT_VIRTIO */
 
 #endif /* _SYS_EFX_CHECK_H */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 4/8] common/sfc_efx/base: add support to get virtio features
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (2 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to get virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 14 ++++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 45 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 +++
 drivers/common/sfc_efx/base/rhead_virtio.c | 52 ++++++++++++++++++++++
 5 files changed, 120 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index d4b7d7f47e..e3ac51eae0 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4433,6 +4433,13 @@ typedef struct efx_virtio_vq_cfg_s {
 
 typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
 
+typedef enum efx_virtio_device_type_e {
+	EFX_VIRTIO_DEVICE_TYPE_RESERVED,
+	EFX_VIRTIO_DEVICE_TYPE_NET,
+	EFX_VIRTIO_DEVICE_TYPE_BLOCK,
+	EFX_VIRTIO_DEVICE_NTYPES
+} efx_virtio_device_type_t;
+
 LIBEFX_API
 extern	__checkReturn	efx_rc_t
 efx_virtio_init(
@@ -4487,6 +4494,13 @@ efx_virtio_get_doorbell_offset(
 	__in		efx_virtio_vq_t *evvp,
 	__out		uint32_t *offsetp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index d6742f4a8c..758206d382 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -318,6 +318,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
 				uint32_t *);
+	efx_rc_t	(*evo_get_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index de998fcad9..20c22f02b5 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -13,6 +13,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
+	rhead_virtio_get_features,		/* evo_get_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -254,4 +255,48 @@ efx_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (featuresp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_get_features(enp, type, featuresp)) != 0)
+		goto fail4;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 4304f63f4c..69d701a47e 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -498,6 +498,13 @@ rhead_virtio_get_doorbell_offset(
 	__in				efx_virtio_vq_t *evvp,
 	__out				uint32_t *offsetp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__out				uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 147460c95c..508d03d58f 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -280,4 +280,56 @@ rhead_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	efx_mcdi_req_t req;
+	uint32_t features_lo;
+	uint32_t features_hi;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_FEATURES_IN_DEVICE_ID, type);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	features_lo = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_LO);
+	features_hi = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_HI);
+	*featuresp = ((uint64_t)features_hi << 32) | features_lo;
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 5/8] common/sfc_efx/base: add support to verify virtio features
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (3 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to verify virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          |  7 ++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 38 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 ++++
 drivers/common/sfc_efx/base/rhead_virtio.c | 44 ++++++++++++++++++++++
 5 files changed, 98 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index e3ac51eae0..ff5091a36b 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4501,6 +4501,13 @@ efx_virtio_get_features(
 	__in		efx_virtio_device_type_t type,
 	__out		uint64_t *featuresp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 758206d382..aa878014c1 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -320,6 +320,8 @@ typedef struct efx_virtio_ops_s {
 				uint32_t *);
 	efx_rc_t	(*evo_get_features)(efx_nic_t *,
 				efx_virtio_device_type_t, uint64_t *);
+	efx_rc_t	(*evo_verify_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 20c22f02b5..b46997c09e 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -14,6 +14,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 	rhead_virtio_get_features,		/* evo_get_features */
+	rhead_virtio_verify_features,		/* evo_verify_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -299,4 +300,41 @@ efx_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_verify_features(enp, type, features)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 69d701a47e..3bf9beceb0 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -505,6 +505,13 @@ rhead_virtio_get_features(
 	__in				efx_virtio_device_type_t type,
 	__out				uint64_t *featuresp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_verify_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__in				uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 508d03d58f..0023ea1e83 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -332,4 +332,48 @@ rhead_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	efx_mcdi_req_t req;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_TEST_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_DEVICE_ID, type);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_LO,
+		features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_HI,
+		((features >> 32) & 0xFFFFFFFF));
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 6/8] common/sfc_efx: add support to get the device class
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (4 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Device class argument would be used to select compatible driver.
Driver probe would be skipped for incompatible device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/sfc_efx.c   | 49 ++++++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 34 +++++++++++++++++++++
 drivers/common/sfc_efx/version.map |  2 ++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index d7a84c9835..a3146db255 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -7,12 +7,61 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
+#include <string.h>
 #include <rte_log.h>
+#include <rte_kvargs.h>
+#include <rte_devargs.h>
 
 #include "sfc_efx_log.h"
+#include "sfc_efx.h"
 
 uint32_t sfc_efx_logtype;
 
+static int
+sfc_efx_kvarg_dev_class_handler(__rte_unused const char *key,
+				const char *class_str, void *opaque)
+{
+	enum sfc_efx_dev_class *dev_class = opaque;
+
+	if (class_str == NULL)
+		return *dev_class;
+
+	if (strcmp(class_str, "vdpa") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_VDPA;
+	} else if (strcmp(class_str, "net") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_NET;
+	} else {
+		SFC_EFX_LOG(ERR, "Unsupported class %s.", class_str);
+		*dev_class = SFC_EFX_DEV_CLASS_INVALID;
+	}
+
+	return 0;
+}
+
+enum sfc_efx_dev_class
+sfc_efx_dev_class_get(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvargs;
+	const char *key = SFC_EFX_KVARG_DEV_CLASS;
+	enum sfc_efx_dev_class dev_class = SFC_EFX_DEV_CLASS_NET;
+
+	if (devargs == NULL)
+		return dev_class;
+
+	kvargs = rte_kvargs_parse(devargs->args, NULL);
+	if (kvargs == NULL)
+		return dev_class;
+
+	if (rte_kvargs_count(kvargs, key) != 0) {
+		rte_kvargs_process(kvargs, key, sfc_efx_kvarg_dev_class_handler,
+				   &dev_class);
+	}
+
+	rte_kvargs_free(kvargs);
+
+	return dev_class;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
new file mode 100644
index 0000000000..bbccd3e9e8
--- /dev/null
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2019-2020 Xilinx, Inc.
+ * Copyright(c) 2019 Solarflare Communications Inc.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ */
+
+#ifndef _SFC_EFX_H_
+#define _SFC_EFX_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SFC_EFX_KVARG_DEV_CLASS	"class"
+
+enum sfc_efx_dev_class {
+	SFC_EFX_DEV_CLASS_INVALID = 0,
+	SFC_EFX_DEV_CLASS_NET,
+	SFC_EFX_DEV_CLASS_VDPA,
+
+	SFC_EFX_DEV_NCLASS
+};
+
+__rte_internal
+enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFC_EFX_H_ */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 403feeaf11..a3345d34f7 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -221,6 +221,8 @@ INTERNAL {
 	efx_txq_nbufs;
 	efx_txq_size;
 
+	sfc_efx_dev_class_get;
+
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 7/8] net/sfc: skip driver probe for incompatible device class
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (5 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
  2021-03-15 15:54   ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Driver would be probed only for the net device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst  | 8 ++++++++
 drivers/net/sfc/sfc.h        | 1 +
 drivers/net/sfc/sfc_ethdev.c | 7 +++++++
 drivers/net/sfc/sfc_kvargs.c | 1 +
 4 files changed, 17 insertions(+)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index b6047cf5c7..cf1269cc03 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -357,6 +357,14 @@ allow option like "-a 02:00.0,arg1=value1,...".
 Case-insensitive 1/y/yes/on or 0/n/no/off may be used to specify
 boolean parameters value.
 
+- ``class`` [net|vdpa] (default **net**)
+
+  Choose the mode of operation of ef100 device.
+  **net** device will work as network device and will be probed by net/sfc driver.
+  **vdpa** device will work as vdpa device and will be probed by vdpa/sfc driver.
+  If this parameter is not specified then ef100 device will operate as
+  network device.
+
 - ``rx_datapath`` [auto|efx|ef10|ef10_essb] (default **auto**)
 
   Choose receive datapath implementation.
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index c2945b6ba2..b48a818adb 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -22,6 +22,7 @@
 #include "efx.h"
 
 #include "sfc_efx_mcdi.h"
+#include "sfc_efx.h"
 
 #include "sfc_debug.h"
 #include "sfc_log.h"
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 00a0fd3d02..23828c24ff 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -2161,6 +2161,13 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	const struct rte_ether_addr *from;
 	int ret;
 
+	if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
+			SFC_EFX_DEV_CLASS_NET) {
+		SFC_GENERIC_LOG(DEBUG,
+			"Incompatible device class: skip probing, should be probed by other sfc driver.");
+		return 1;
+	}
+
 	sfc_register_dp();
 
 	logtype_main = sfc_register_logtype(&pci_dev->addr,
diff --git a/drivers/net/sfc/sfc_kvargs.c b/drivers/net/sfc/sfc_kvargs.c
index c42b326ab0..0efa92ed28 100644
--- a/drivers/net/sfc/sfc_kvargs.c
+++ b/drivers/net/sfc/sfc_kvargs.c
@@ -28,6 +28,7 @@ sfc_kvargs_parse(struct sfc_adapter *sa)
 		SFC_KVARG_TX_DATAPATH,
 		SFC_KVARG_FW_VARIANT,
 		SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
+		SFC_EFX_KVARG_DEV_CLASS,
 		NULL,
 	};
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v2 8/8] drivers: add common driver API to get efx family
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (6 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
@ 2021-03-15 13:58   ` Andrew Rybchenko
  2021-03-15 15:54   ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 13:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Move function to get efx family from net driver into common driver.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/meson.build         |  2 +-
 drivers/common/sfc_efx/meson.build |  5 +++
 drivers/common/sfc_efx/sfc_efx.c   | 56 +++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 10 +++++
 drivers/common/sfc_efx/version.map |  1 +
 drivers/meson.build                |  1 +
 drivers/net/sfc/sfc.c              | 61 ++----------------------------
 7 files changed, 78 insertions(+), 58 deletions(-)

diff --git a/drivers/common/meson.build b/drivers/common/meson.build
index ba6325adf3..66e12143b2 100644
--- a/drivers/common/meson.build
+++ b/drivers/common/meson.build
@@ -6,4 +6,4 @@ if is_windows
 endif
 
 std_deps = ['eal']
-drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2', 'sfc_efx']
+drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2']
diff --git a/drivers/common/sfc_efx/meson.build b/drivers/common/sfc_efx/meson.build
index d9afcf3eeb..9faf5161f5 100644
--- a/drivers/common/sfc_efx/meson.build
+++ b/drivers/common/sfc_efx/meson.build
@@ -5,6 +5,10 @@
 # This software was jointly developed between OKTET Labs (under contract
 # for Solarflare) and Solarflare Communications, Inc.
 
+if is_windows
+	subdir_done()
+endif
+
 if (arch_subdir != 'x86' or not dpdk_conf.get('RTE_ARCH_64')) and (arch_subdir != 'arm' or not host_machine.cpu_family().startswith('aarch64'))
 	build = false
 	reason = 'only supported on x86_64 and aarch64'
@@ -32,6 +36,7 @@ endforeach
 subdir('base')
 objs = [base_objs]
 
+deps += ['bus_pci']
 sources = files(
 	'sfc_efx.c',
 	'sfc_efx_mcdi.c',
diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index a3146db255..0b78933d9f 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -62,6 +62,62 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)
 	return dev_class;
 }
 
+static efx_rc_t
+sfc_efx_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
+		     efsys_bar_t *barp)
+{
+	efsys_bar_t result;
+	struct rte_pci_device *dev;
+
+	memset(&result, 0, sizeof(result));
+
+	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
+		return -EINVAL;
+
+	dev = configp->espc_dev;
+
+	result.esb_rid = bar_index;
+	result.esb_dev = dev;
+	result.esb_base = dev->mem_resource[bar_index].addr;
+
+	*barp = result;
+
+	return 0;
+}
+
+static efx_rc_t
+sfc_efx_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
+			 efx_dword_t *edp)
+{
+	int rc;
+
+	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
+				 offset);
+
+	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
+}
+
+int
+sfc_efx_family(struct rte_pci_device *pci_dev,
+	       efx_bar_region_t *mem_ebrp, efx_family_t *family)
+{
+	static const efx_pci_ops_t ops = {
+		.epo_config_readd = sfc_efx_pci_config_readd,
+		.epo_find_mem_bar = sfc_efx_find_mem_bar,
+	};
+
+	efsys_pci_config_t espcp;
+	int rc;
+
+	espcp.espc_dev = pci_dev;
+
+	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
+				  pci_dev->id.device_id,
+				  &espcp, &ops, family, mem_ebrp);
+
+	return rc;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
index bbccd3e9e8..71288b7299 100644
--- a/drivers/common/sfc_efx/sfc_efx.h
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -10,6 +10,11 @@
 #ifndef _SFC_EFX_H_
 #define _SFC_EFX_H_
 
+#include <rte_bus_pci.h>
+
+#include "efx.h"
+#include "efsys.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -27,6 +32,11 @@ enum sfc_efx_dev_class {
 __rte_internal
 enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
 
+__rte_internal
+int sfc_efx_family(struct rte_pci_device *pci_dev,
+		   efx_bar_region_t *mem_ebrp,
+		   efx_family_t *family);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index a3345d34f7..c3414b760b 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -222,6 +222,7 @@ INTERNAL {
 	efx_txq_size;
 
 	sfc_efx_dev_class_get;
+	sfc_efx_family;
 
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
diff --git a/drivers/meson.build b/drivers/meson.build
index fdf76120ac..9c8eded697 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -7,6 +7,7 @@ subdirs = [
 	'bus',
 	'common/mlx5', # depends on bus.
 	'common/qat', # depends on bus.
+	'common/sfc_efx', # depends on bus.
 	'mempool', # depends on common and bus.
 	'net',     # depends on common, bus, mempool
 	'raw',     # depends on common, bus and net.
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 3135068c39..3477c7530b 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -631,29 +631,6 @@ sfc_close(struct sfc_adapter *sa)
 	sfc_log_init(sa, "done");
 }
 
-static efx_rc_t
-sfc_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
-		 efsys_bar_t *barp)
-{
-	efsys_bar_t result;
-	struct rte_pci_device *dev;
-
-	memset(&result, 0, sizeof(result));
-
-	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
-		return EINVAL;
-
-	dev = configp->espc_dev;
-
-	result.esb_rid = bar_index;
-	result.esb_dev = dev;
-	result.esb_base = dev->mem_resource[bar_index].addr;
-
-	*barp = result;
-
-	return 0;
-}
-
 static int
 sfc_mem_bar_init(struct sfc_adapter *sa, const efx_bar_region_t *mem_ebrp)
 {
@@ -1095,43 +1072,12 @@ sfc_nic_probe(struct sfc_adapter *sa)
 	return 0;
 }
 
-static efx_rc_t
-sfc_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
-		     efx_dword_t *edp)
-{
-	int rc;
-
-	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
-				 offset);
-
-	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
-}
-
-static int
-sfc_family(struct sfc_adapter *sa, efx_bar_region_t *mem_ebrp)
-{
-	struct rte_eth_dev *eth_dev = sa->eth_dev;
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	efsys_pci_config_t espcp;
-	static const efx_pci_ops_t ops = {
-		.epo_config_readd = sfc_pci_config_readd,
-		.epo_find_mem_bar = sfc_find_mem_bar,
-	};
-	int rc;
-
-	espcp.espc_dev = pci_dev;
-
-	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
-				  pci_dev->id.device_id,
-				  &espcp, &ops, &sa->family, mem_ebrp);
-
-	return rc;
-}
-
 int
 sfc_probe(struct sfc_adapter *sa)
 {
 	efx_bar_region_t mem_ebrp;
+	struct rte_eth_dev *eth_dev = sa->eth_dev;
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	efx_nic_t *enp;
 	int rc;
 
@@ -1143,7 +1089,8 @@ sfc_probe(struct sfc_adapter *sa)
 	rte_atomic32_init(&sa->restart_required);
 
 	sfc_log_init(sa, "get family");
-	rc = sfc_family(sa, &mem_ebrp);
+	rc = sfc_efx_family(pci_dev, &mem_ebrp, &sa->family);
+
 	if (rc != 0)
 		goto fail_family;
 	sfc_log_init(sa,
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family
  2021-03-14  0:36   ` Ferruh Yigit
@ 2021-03-15 14:01     ` Andrew Rybchenko
  0 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 14:01 UTC (permalink / raw)
  To: Ferruh Yigit, dev; +Cc: Vijay Kumar Srivastava

On 3/14/21 3:36 AM, Ferruh Yigit wrote:
> On 3/11/2021 11:03 AM, Andrew Rybchenko wrote:
>> From: Vijay Kumar Srivastava <vsrivast@xilinx.com>
>>
>> Move function to get efx family from net driver into common driver.
>>
>> Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>
> <...>
>
>> diff --git a/drivers/meson.build b/drivers/meson.build
>> index fdf76120ac..9c8eded697 100644
>> --- a/drivers/meson.build
>> +++ b/drivers/meson.build
>> @@ -7,6 +7,7 @@ subdirs = [
>>       'bus',
>>       'common/mlx5', # depends on bus.
>>       'common/qat', # depends on bus.
>> +    'common/sfc_efx', # depends on bus.
>>       'mempool', # depends on common and bus.
>>       'net',     # depends on common, bus, mempool
>>       'raw',     # depends on common, bus and net.
>
> This enables building 'common/sfc_efx' for windows and fail. A windows
> build check needs to be added to 'common/sfc_efx'

I've send v2 which fixes the problem and one more -
undefined functions mentioned in version.map.

Thanks,
Andrew.

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                     ` (7 preceding siblings ...)
  2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
@ 2021-03-15 15:54   ` Ferruh Yigit
  2021-03-16  7:25     ` Andrew Rybchenko
  8 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-15 15:54 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev

On 3/15/2021 1:58 PM, Andrew Rybchenko wrote:
> Update base driver to provide functionality required by vDPA driver.
> 
> Factor out helper functions to be shared by net and vDPA drivers.
> 
> v2:
>   - fix windows build breakage - do not build common/sfc_efx in the case
>     of windows
>   - remove undefined efx_virtio_* functions from version.map (since
>     EFSYS_OPT_VIRTIO is disabled)
> 
> Vijay Kumar Srivastava (6):
>    common/sfc_efx/base: add virtio build dependency
>    common/sfc_efx/base: add support to get virtio features
>    common/sfc_efx/base: add support to verify virtio features
>    common/sfc_efx: add support to get the device class
>    net/sfc: skip driver probe for incompatible device class
>    drivers: add common driver API to get efx family
> 
> Vijay Srivastava (2):
>    common/sfc_efx/base: add base virtio support for vDPA
>    common/sfc_efx/base: add API to get VirtQ doorbell offset
> 

build still fails for windows,
http://mails.dpdk.org/archives/test-report/2021-March/182539.html

I guess it is missing, "build=false":
   if is_windows
  +       build=false
          subdir_done()
   endif



^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (8 preceding siblings ...)
  2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
@ 2021-03-16  6:15 ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
                     ` (8 more replies)
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
  10 siblings, 9 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

Update base driver to provide functionality required by vDPA driver.

Factor out helper functions to be shared by net and vDPA drivers.

v3:
 - one more attempt to fix windows build breakage

v2:
 - fix windows build breakage - do not build common/sfc_efx in the case
   of windows
 - remove undefined efx_virtio_* functions from version.map (since
   EFSYS_OPT_VIRTIO is disabled)

Vijay Kumar Srivastava (6):
  common/sfc_efx/base: add virtio build dependency
  common/sfc_efx/base: add support to get virtio features
  common/sfc_efx/base: add support to verify virtio features
  common/sfc_efx: add support to get the device class
  net/sfc: skip driver probe for incompatible device class
  drivers: add common driver API to get efx family

Vijay Srivastava (2):
  common/sfc_efx/base: add base virtio support for vDPA
  common/sfc_efx/base: add API to get VirtQ doorbell offset

 doc/guides/nics/sfc_efx.rst                |   8 +
 drivers/common/meson.build                 |   2 +-
 drivers/common/sfc_efx/base/efx.h          | 142 ++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   9 +
 drivers/common/sfc_efx/base/efx_impl.h     |  42 +++
 drivers/common/sfc_efx/base/efx_virtio.c   | 340 ++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  37 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 379 +++++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 drivers/common/sfc_efx/meson.build         |   6 +
 drivers/common/sfc_efx/sfc_efx.c           | 105 ++++++
 drivers/common/sfc_efx/sfc_efx.h           |  44 +++
 drivers/common/sfc_efx/version.map         |   3 +
 drivers/meson.build                        |   1 +
 drivers/net/sfc/sfc.c                      |  61 +---
 drivers/net/sfc/sfc.h                      |   1 +
 drivers/net/sfc/sfc_ethdev.c               |   7 +
 drivers/net/sfc/sfc_kvargs.c               |   1 +
 19 files changed, 1134 insertions(+), 58 deletions(-)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

In the vDPA mode, only data path is offloaded in the hardware and
control path still goes through the hypervisor and it configures
virtqueues via vDPA driver so new virtqueue APIs are required.

Implement virtio init/fini and virtqueue create/destroy APIs.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 109 +++++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   6 +
 drivers/common/sfc_efx/base/efx_impl.h     |  36 ++++
 drivers/common/sfc_efx/base/efx_virtio.c   | 216 +++++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  17 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 190 ++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 8 files changed, 578 insertions(+)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 2c820022b2..c2c73bd382 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4368,6 +4368,115 @@ efx_mae_action_rule_remove(
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+/* A Virtio net device can have one or more pairs of Rx/Tx virtqueues
+ * while virtio block device has a single virtqueue,
+ * for further details refer section of 4.2.3 of SF-120734
+ */
+typedef enum efx_virtio_vq_type_e {
+	EFX_VIRTIO_VQ_TYPE_NET_RXQ,
+	EFX_VIRTIO_VQ_TYPE_NET_TXQ,
+	EFX_VIRTIO_VQ_TYPE_BLOCK,
+	EFX_VIRTIO_VQ_NTYPES
+} efx_virtio_vq_type_t;
+
+typedef struct efx_virtio_vq_dyncfg_s {
+	/*
+	 * If queue is being created to be migrated then this
+	 * should be the FINAL_PIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_pidx;
+	/*
+	 * If this queue is being created to be migrated then this
+	 * should be the FINAL_CIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_cidx;
+} efx_virtio_vq_dyncfg_t;
+
+/*
+ * Virtqueue size must be a power of 2, maximum size is 32768
+ * (see VIRTIO v1.1 section 2.6)
+ */
+#define EFX_VIRTIO_MAX_VQ_SIZE	0x8000
+
+typedef struct efx_virtio_vq_cfg_s {
+	unsigned int		evvc_vq_num;
+	efx_virtio_vq_type_t	evvc_type;
+	/*
+	 * vDPA as VF : It is target VF number if queue is being created on VF.
+	 * vDPA as PF : If queue to be created on PF then it should be
+	 * EFX_PCI_VF_INVALID.
+	 */
+	uint16_t		evvc_target_vf;
+	/*
+	 * Maximum virtqueue size is EFX_VIRTIO_MAX_VQ_SIZE and
+	 * virtqueue size 0 means the queue is unavailable.
+	 */
+	uint32_t		evvc_vq_size;
+	efsys_dma_addr_t        evvc_desc_tbl_addr;
+	efsys_dma_addr_t	evvc_avail_ring_addr;
+	efsys_dma_addr_t	evvc_used_ring_addr;
+	/* MSIX vector number for the virtqueue or 0xFFFF if MSIX is not used */
+	uint16_t                evvc_msix_vector;
+	/*
+	 * evvc_pas_id contains a PCIe address space identifier if the queue
+	 * uses PASID.
+	 */
+	boolean_t               evvc_use_pasid;
+	uint32_t		evvc_pas_id;
+	/* Negotiated virtio features to be applied to this virtqueue */
+	uint64_t		evcc_features;
+} efx_virtio_vq_cfg_t;
+
+typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp);
+
+LIBEFX_API
+extern			void
+efx_virtio_fini(
+	__in		efx_nic_t *enp);
+
+/*
+ * When virtio net driver in the guest sets VIRTIO_CONFIG_STATUS_DRIVER_OK bit,
+ * hypervisor starts configuring all the virtqueues in the device. When the
+ * vhost_user has received VHOST_USER_SET_VRING_ENABLE for all the virtqueues,
+ * then it invokes VDPA driver callback dev_conf. APIs qstart and qcreate would
+ * be invoked from dev_conf callback to create the virtqueues, For further
+ * details refer SF-122427.
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern			void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 9e288f272a..86a6d92fef 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -407,4 +407,10 @@
 # endif
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+# if !EFSYS_OPT_RIVERHEAD
+#  error "VIRTIO requires RIVERHEAD"
+# endif
+#endif /* EFSYS_OPT_VIRTIO */
+
 #endif /* _SYS_EFX_CHECK_H */
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index a0628e6927..f27d9fa82c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -65,6 +65,7 @@ extern "C" {
 #define	EFX_MOD_TUNNEL		0x00004000
 #define	EFX_MOD_EVB		0x00008000
 #define	EFX_MOD_PROXY		0x00010000
+#define	EFX_MOD_VIRTIO		0x00020000
 
 #define	EFX_RESET_PHY		0x00000001
 #define	EFX_RESET_RXQ_ERR	0x00000002
@@ -308,6 +309,16 @@ typedef struct efx_tunnel_ops_s {
 } efx_tunnel_ops_t;
 #endif /* EFSYS_OPT_TUNNEL */
 
+#if EFSYS_OPT_VIRTIO
+typedef struct efx_virtio_ops_s {
+	efx_rc_t	(*evo_virtio_qstart)(efx_virtio_vq_t *,
+				efx_virtio_vq_cfg_t *,
+				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
+				efx_virtio_vq_dyncfg_t *);
+} efx_virtio_ops_t;
+#endif /* EFSYS_OPT_VIRTIO */
+
 typedef struct efx_port_s {
 	efx_mac_type_t		ep_mac_type;
 	uint32_t		ep_phy_type;
@@ -858,6 +869,9 @@ struct efx_nic_s {
 #if EFSYS_OPT_VPD
 	const efx_vpd_ops_t	*en_evpdop;
 #endif	/* EFSYS_OPT_VPD */
+#if EFSYS_OPT_VIRTIO
+	const efx_virtio_ops_t	*en_evop;
+#endif	/* EFSYS_OPT_VPD */
 #if EFSYS_OPT_RX_SCALE
 	efx_rx_hash_support_t		en_hash_support;
 	efx_rx_scale_context_type_t	en_rss_context_type;
@@ -1750,6 +1764,28 @@ struct efx_mae_actions_s {
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+#define	EFX_VQ_MAGIC	0x026011950
+
+typedef enum efx_virtio_vq_state_e {
+	EFX_VIRTIO_VQ_STATE_UNKNOWN = 0,
+	EFX_VIRTIO_VQ_STATE_INITIALIZED,
+	EFX_VIRTIO_VQ_STATE_STARTED,
+	EFX_VIRTIO_VQ_NSTATES
+} efx_virtio_vq_state_t;
+
+struct efx_virtio_vq_s {
+	uint32_t		evv_magic;
+	efx_nic_t		*evv_enp;
+	efx_virtio_vq_state_t	evv_state;
+	uint32_t		evv_vi_index;
+	efx_virtio_vq_type_t	evv_type;
+	uint16_t		evv_target_vf;
+};
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
new file mode 100644
index 0000000000..1b7b01556e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_VIRTIO
+
+#if EFSYS_OPT_RIVERHEAD
+static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
+	rhead_virtio_qstart,			/* evo_virtio_qstart */
+	rhead_virtio_qstop,			/* evo_virtio_qstop */
+};
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_VIRTIO));
+
+	switch (enp->en_family) {
+#if EFSYS_OPT_RIVERHEAD
+	case EFX_FAMILY_RIVERHEAD:
+		evop = &__efx_virtio_rhead_ops;
+		break;
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	default:
+		EFSYS_ASSERT(0);
+		rc = ENOTSUP;
+		goto fail1;
+	}
+
+	enp->en_evop = evop;
+	enp->en_mod_flags |= EFX_MOD_VIRTIO;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+
+	return (rc);
+}
+
+	void
+efx_virtio_fini(
+	__in		efx_nic_t *enp)
+{
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_virtio_vq_t *evvp;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	/* Allocate a virtqueue object */
+	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	if (evvp == NULL) {
+		rc = ENOMEM;
+		goto fail1;
+	}
+
+	evvp->evv_magic = EFX_VQ_MAGIC;
+	evvp->evv_enp = enp;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	*evvpp = evvp;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvcp == NULL) || (evvp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	evop = evvp->evv_enp->en_evop;
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstart(evvp, evvcp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_type = evvcp->evvc_type;
+	evvp->evv_target_vf = evvcp->evvc_target_vf;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_STARTED;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if (evvp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(evvp->evv_magic, ==, EFX_VQ_MAGIC);
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_STARTED) {
+		rc = EINVAL;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstop(evvp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	return 0;
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp)
+{
+	efx_nic_t *enp;
+
+	if (evvp == NULL)
+		return;
+
+	enp = evvp->evv_enp;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+
+	if (evvp->evv_state == EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		/* Free the virtqueue object */
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	}
+}
+
+#endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/meson.build b/drivers/common/sfc_efx/base/meson.build
index f995eacac2..1a39418c65 100644
--- a/drivers/common/sfc_efx/base/meson.build
+++ b/drivers/common/sfc_efx/base/meson.build
@@ -29,6 +29,7 @@ sources = [
 	'efx_tunnel.c',
 	'efx_tx.c',
 	'efx_vpd.c',
+	'efx_virtio.c',
 	'mcdi_mon.c',
 	'siena_mac.c',
 	'siena_mcdi.c',
@@ -61,6 +62,7 @@ sources = [
 	'rhead_rx.c',
 	'rhead_tunnel.c',
 	'rhead_tx.c',
+	'rhead_virtio.c',
 ]
 
 extra_flags = [
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 50262b16a8..a15ac52a58 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -477,6 +477,23 @@ rhead_nic_xilinx_cap_tbl_read_ef100_locator(
 	__in				efsys_dma_addr_t offset,
 	__out				efx_bar_region_t *ebrp);
 
+#if EFSYS_OPT_VIRTIO
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstart(
+	__in				efx_virtio_vq_t *evvp,
+	__in				efx_virtio_vq_cfg_t *evvcp,
+	__in_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstop(
+	__in				efx_virtio_vq_t *evvp,
+	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
new file mode 100644
index 0000000000..d1719f834e
--- /dev/null
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -0,0 +1,190 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO
+
+/*
+ * Get function-local index of the associated VI from the
+ * virtqueue number queue 0 is reserved for MCDI
+ */
+#define EFX_VIRTIO_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1)
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t vi_index;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_RXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_TXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_BLOCK);
+
+	if (evvcp->evvc_type >= EFX_VIRTIO_VQ_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	/* virtqueue size must be power of 2 */
+	if ((!ISP2(evvcp->evvc_vq_size)) ||
+	    (evvcp->evvc_vq_size > EFX_VIRTIO_MAX_VQ_SIZE)) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		if ((evvdp->evvd_vq_cidx > evvcp->evvc_vq_size) ||
+		    (evvdp->evvd_vq_pidx > evvcp->evvc_vq_size)) {
+			rc = EINVAL;
+			goto fail3;
+		}
+	}
+
+	req.emr_cmd = MC_CMD_VIRTIO_INIT_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_INIT_QUEUE_REQ_QUEUE_TYPE,
+		evvcp->evvc_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvcp->evvc_target_vf);
+
+	vi_index = EFX_VIRTIO_GET_VI_INDEX(evvcp->evvc_vq_num);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE, vi_index);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_SIZE,
+		evvcp->evvc_vq_size);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_LO,
+		evvcp->evvc_desc_tbl_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_HI,
+		evvcp->evvc_desc_tbl_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_LO,
+		evvcp->evvc_avail_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_HI,
+		evvcp->evvc_avail_ring_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_LO,
+		evvcp->evvc_used_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_HI,
+		evvcp->evvc_used_ring_addr >> 32);
+
+	if (evvcp->evvc_use_pasid) {
+		MCDI_IN_POPULATE_DWORD_1(req, VIRTIO_INIT_QUEUE_REQ_FLAGS,
+			VIRTIO_INIT_QUEUE_REQ_USE_PASID, 1);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_PASID,
+			evvcp->evvc_pas_id);
+	}
+
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_MSIX_VECTOR,
+		evvcp->evvc_msix_vector);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_LO,
+		evvcp->evcc_features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_HI,
+		evvcp->evcc_features >> 32);
+
+	if (evvdp != NULL) {
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_PIDX,
+			evvdp->evvd_vq_pidx);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_CIDX,
+			evvdp->evvd_vq_cidx);
+	}
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_MPORT_SELECTOR,
+		MAE_MPORT_SELECTOR_ASSIGNED);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail4;
+	}
+
+	evvp->evv_vi_index = vi_index;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_mcdi_req_t req;
+	efx_nic_t *enp = evvp->evv_enp;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_FINI_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_FINI_QUEUE_REQ_QUEUE_TYPE, evvp->evv_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		evvdp->evvd_vq_pidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_PIDX);
+		evvdp->evvd_vq_cidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_CIDX);
+	}
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+#endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/efsys.h b/drivers/common/sfc_efx/efsys.h
index 663601412e..d133d61b3d 100644
--- a/drivers/common/sfc_efx/efsys.h
+++ b/drivers/common/sfc_efx/efsys.h
@@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAE 1
 
+#define EFSYS_OPT_VIRTIO 0
+
 /* ID */
 
 typedef struct __efsys_identifier_s efsys_identifier_t;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

Add an API to query the virtqueue doorbell offset in the BAR for a VI.
For vDPA, the virtio net driver notifies the device directly by writing
doorbell. This API would be invoked from vDPA client driver.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 12 +++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 41 ++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  6 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 93 ++++++++++++++++++++++
 5 files changed, 154 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index c2c73bd382..d4b7d7f47e 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4475,6 +4475,18 @@ extern			void
 efx_virtio_qdestroy(
 	__in		efx_virtio_vq_t *evvp);
 
+/*
+ * Get the offset in the BAR of the doorbells for a VI.
+ * net device : doorbell offset of RX & TX queues
+ * block device : request doorbell offset in the BAR.
+ * For further details refer section of 4 of SF-119689
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index f27d9fa82c..d6742f4a8c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -316,6 +316,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
 				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
+				uint32_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 1b7b01556e..de998fcad9 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -12,6 +12,7 @@
 static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
+	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -213,4 +214,44 @@ efx_virtio_qdestroy(
 	}
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvp == NULL) || (offsetp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_get_doorbell_offset(evvp, offsetp)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index a15ac52a58..4304f63f4c 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -492,6 +492,12 @@ rhead_virtio_qstop(
 	__in				efx_virtio_vq_t *evvp,
 	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in				efx_virtio_vq_t *evvp,
+	__out				uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index d1719f834e..147460c95c 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -187,4 +187,97 @@ rhead_virtio_qstop(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t type;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN,
+		MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN;
+
+	switch (evvp->evv_type) {
+	case EFX_VIRTIO_VQ_TYPE_NET_RXQ:
+	case EFX_VIRTIO_VQ_TYPE_NET_TXQ:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET;
+		break;
+	case EFX_VIRTIO_VQ_TYPE_BLOCK:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK;
+		break;
+	default:
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_DEVICE_ID,
+		type);
+	MCDI_IN_SET_WORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail2;
+	}
+
+	switch (type) {
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_NET:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail3;
+		}
+
+		if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_RXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_RX_DBL_OFFSET);
+		} else if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_TXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_TX_DBL_OFFSET);
+		}
+		break;
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail4;
+		}
+
+		*offsetp = MCDI_OUT_DWORD(req,
+			VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_DBL_OFFSET);
+		break;
+	default:
+		EFSYS_ASSERT(0);
+		rc = EINVAL;
+		goto fail5;
+	}
+
+	return (0);
+
+fail5:
+	EFSYS_PROBE(fail5);
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 3/8] common/sfc_efx/base: add virtio build dependency
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add EFSYS_HAS_UINT64 build dependency on EFSYS_OPT_VIRTIO.
virtio features are represented as bitmask in 64-bit unsigned
integer.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx_check.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 86a6d92fef..66b38eeae0 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -411,6 +411,9 @@
 # if !EFSYS_OPT_RIVERHEAD
 #  error "VIRTIO requires RIVERHEAD"
 # endif
+# if !EFSYS_HAS_UINT64
+#  error "VIRTIO requires UINT64"
+# endif
 #endif /* EFSYS_OPT_VIRTIO */
 
 #endif /* _SYS_EFX_CHECK_H */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 4/8] common/sfc_efx/base: add support to get virtio features
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (2 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to get virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 14 ++++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 45 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 +++
 drivers/common/sfc_efx/base/rhead_virtio.c | 52 ++++++++++++++++++++++
 5 files changed, 120 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index d4b7d7f47e..e3ac51eae0 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4433,6 +4433,13 @@ typedef struct efx_virtio_vq_cfg_s {
 
 typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
 
+typedef enum efx_virtio_device_type_e {
+	EFX_VIRTIO_DEVICE_TYPE_RESERVED,
+	EFX_VIRTIO_DEVICE_TYPE_NET,
+	EFX_VIRTIO_DEVICE_TYPE_BLOCK,
+	EFX_VIRTIO_DEVICE_NTYPES
+} efx_virtio_device_type_t;
+
 LIBEFX_API
 extern	__checkReturn	efx_rc_t
 efx_virtio_init(
@@ -4487,6 +4494,13 @@ efx_virtio_get_doorbell_offset(
 	__in		efx_virtio_vq_t *evvp,
 	__out		uint32_t *offsetp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index d6742f4a8c..758206d382 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -318,6 +318,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
 				uint32_t *);
+	efx_rc_t	(*evo_get_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index de998fcad9..20c22f02b5 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -13,6 +13,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
+	rhead_virtio_get_features,		/* evo_get_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -254,4 +255,48 @@ efx_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (featuresp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_get_features(enp, type, featuresp)) != 0)
+		goto fail4;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 4304f63f4c..69d701a47e 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -498,6 +498,13 @@ rhead_virtio_get_doorbell_offset(
 	__in				efx_virtio_vq_t *evvp,
 	__out				uint32_t *offsetp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__out				uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 147460c95c..508d03d58f 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -280,4 +280,56 @@ rhead_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	efx_mcdi_req_t req;
+	uint32_t features_lo;
+	uint32_t features_hi;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_FEATURES_IN_DEVICE_ID, type);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	features_lo = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_LO);
+	features_hi = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_HI);
+	*featuresp = ((uint64_t)features_hi << 32) | features_lo;
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 5/8] common/sfc_efx/base: add support to verify virtio features
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (3 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to verify virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          |  7 ++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 38 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 ++++
 drivers/common/sfc_efx/base/rhead_virtio.c | 44 ++++++++++++++++++++++
 5 files changed, 98 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index e3ac51eae0..ff5091a36b 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4501,6 +4501,13 @@ efx_virtio_get_features(
 	__in		efx_virtio_device_type_t type,
 	__out		uint64_t *featuresp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 758206d382..aa878014c1 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -320,6 +320,8 @@ typedef struct efx_virtio_ops_s {
 				uint32_t *);
 	efx_rc_t	(*evo_get_features)(efx_nic_t *,
 				efx_virtio_device_type_t, uint64_t *);
+	efx_rc_t	(*evo_verify_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 20c22f02b5..b46997c09e 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -14,6 +14,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 	rhead_virtio_get_features,		/* evo_get_features */
+	rhead_virtio_verify_features,		/* evo_verify_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -299,4 +300,41 @@ efx_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_verify_features(enp, type, features)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 69d701a47e..3bf9beceb0 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -505,6 +505,13 @@ rhead_virtio_get_features(
 	__in				efx_virtio_device_type_t type,
 	__out				uint64_t *featuresp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_verify_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__in				uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index 508d03d58f..0023ea1e83 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -332,4 +332,48 @@ rhead_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	efx_mcdi_req_t req;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_TEST_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_DEVICE_ID, type);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_LO,
+		features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_HI,
+		((features >> 32) & 0xFFFFFFFF));
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 6/8] common/sfc_efx: add support to get the device class
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (4 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Device class argument would be used to select compatible driver.
Driver probe would be skipped for incompatible device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/sfc_efx.c   | 49 ++++++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 34 +++++++++++++++++++++
 drivers/common/sfc_efx/version.map |  2 ++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index d7a84c9835..a3146db255 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -7,12 +7,61 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
+#include <string.h>
 #include <rte_log.h>
+#include <rte_kvargs.h>
+#include <rte_devargs.h>
 
 #include "sfc_efx_log.h"
+#include "sfc_efx.h"
 
 uint32_t sfc_efx_logtype;
 
+static int
+sfc_efx_kvarg_dev_class_handler(__rte_unused const char *key,
+				const char *class_str, void *opaque)
+{
+	enum sfc_efx_dev_class *dev_class = opaque;
+
+	if (class_str == NULL)
+		return *dev_class;
+
+	if (strcmp(class_str, "vdpa") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_VDPA;
+	} else if (strcmp(class_str, "net") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_NET;
+	} else {
+		SFC_EFX_LOG(ERR, "Unsupported class %s.", class_str);
+		*dev_class = SFC_EFX_DEV_CLASS_INVALID;
+	}
+
+	return 0;
+}
+
+enum sfc_efx_dev_class
+sfc_efx_dev_class_get(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvargs;
+	const char *key = SFC_EFX_KVARG_DEV_CLASS;
+	enum sfc_efx_dev_class dev_class = SFC_EFX_DEV_CLASS_NET;
+
+	if (devargs == NULL)
+		return dev_class;
+
+	kvargs = rte_kvargs_parse(devargs->args, NULL);
+	if (kvargs == NULL)
+		return dev_class;
+
+	if (rte_kvargs_count(kvargs, key) != 0) {
+		rte_kvargs_process(kvargs, key, sfc_efx_kvarg_dev_class_handler,
+				   &dev_class);
+	}
+
+	rte_kvargs_free(kvargs);
+
+	return dev_class;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
new file mode 100644
index 0000000000..bbccd3e9e8
--- /dev/null
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2019-2020 Xilinx, Inc.
+ * Copyright(c) 2019 Solarflare Communications Inc.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ */
+
+#ifndef _SFC_EFX_H_
+#define _SFC_EFX_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SFC_EFX_KVARG_DEV_CLASS	"class"
+
+enum sfc_efx_dev_class {
+	SFC_EFX_DEV_CLASS_INVALID = 0,
+	SFC_EFX_DEV_CLASS_NET,
+	SFC_EFX_DEV_CLASS_VDPA,
+
+	SFC_EFX_DEV_NCLASS
+};
+
+__rte_internal
+enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFC_EFX_H_ */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 403feeaf11..a3345d34f7 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -221,6 +221,8 @@ INTERNAL {
 	efx_txq_nbufs;
 	efx_txq_size;
 
+	sfc_efx_dev_class_get;
+
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 7/8] net/sfc: skip driver probe for incompatible device class
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (5 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
  2021-03-16  8:55   ` [dpdk-dev] [PATCH v3 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Driver would be probed only for the net device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst  | 8 ++++++++
 drivers/net/sfc/sfc.h        | 1 +
 drivers/net/sfc/sfc_ethdev.c | 7 +++++++
 drivers/net/sfc/sfc_kvargs.c | 1 +
 4 files changed, 17 insertions(+)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index b6047cf5c7..cf1269cc03 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -357,6 +357,14 @@ allow option like "-a 02:00.0,arg1=value1,...".
 Case-insensitive 1/y/yes/on or 0/n/no/off may be used to specify
 boolean parameters value.
 
+- ``class`` [net|vdpa] (default **net**)
+
+  Choose the mode of operation of ef100 device.
+  **net** device will work as network device and will be probed by net/sfc driver.
+  **vdpa** device will work as vdpa device and will be probed by vdpa/sfc driver.
+  If this parameter is not specified then ef100 device will operate as
+  network device.
+
 - ``rx_datapath`` [auto|efx|ef10|ef10_essb] (default **auto**)
 
   Choose receive datapath implementation.
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index c2945b6ba2..b48a818adb 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -22,6 +22,7 @@
 #include "efx.h"
 
 #include "sfc_efx_mcdi.h"
+#include "sfc_efx.h"
 
 #include "sfc_debug.h"
 #include "sfc_log.h"
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 00a0fd3d02..23828c24ff 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -2161,6 +2161,13 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	const struct rte_ether_addr *from;
 	int ret;
 
+	if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
+			SFC_EFX_DEV_CLASS_NET) {
+		SFC_GENERIC_LOG(DEBUG,
+			"Incompatible device class: skip probing, should be probed by other sfc driver.");
+		return 1;
+	}
+
 	sfc_register_dp();
 
 	logtype_main = sfc_register_logtype(&pci_dev->addr,
diff --git a/drivers/net/sfc/sfc_kvargs.c b/drivers/net/sfc/sfc_kvargs.c
index c42b326ab0..0efa92ed28 100644
--- a/drivers/net/sfc/sfc_kvargs.c
+++ b/drivers/net/sfc/sfc_kvargs.c
@@ -28,6 +28,7 @@ sfc_kvargs_parse(struct sfc_adapter *sa)
 		SFC_KVARG_TX_DATAPATH,
 		SFC_KVARG_FW_VARIANT,
 		SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
+		SFC_EFX_KVARG_DEV_CLASS,
 		NULL,
 	};
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v3 8/8] drivers: add common driver API to get efx family
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (6 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
@ 2021-03-16  6:15   ` Andrew Rybchenko
  2021-03-16  8:55   ` [dpdk-dev] [PATCH v3 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  6:15 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Move function to get efx family from net driver into common driver.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/meson.build         |  2 +-
 drivers/common/sfc_efx/meson.build |  6 +++
 drivers/common/sfc_efx/sfc_efx.c   | 56 +++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 10 +++++
 drivers/common/sfc_efx/version.map |  1 +
 drivers/meson.build                |  1 +
 drivers/net/sfc/sfc.c              | 61 ++----------------------------
 7 files changed, 79 insertions(+), 58 deletions(-)

diff --git a/drivers/common/meson.build b/drivers/common/meson.build
index ba6325adf3..66e12143b2 100644
--- a/drivers/common/meson.build
+++ b/drivers/common/meson.build
@@ -6,4 +6,4 @@ if is_windows
 endif
 
 std_deps = ['eal']
-drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2', 'sfc_efx']
+drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2']
diff --git a/drivers/common/sfc_efx/meson.build b/drivers/common/sfc_efx/meson.build
index d9afcf3eeb..1ca9510733 100644
--- a/drivers/common/sfc_efx/meson.build
+++ b/drivers/common/sfc_efx/meson.build
@@ -5,6 +5,11 @@
 # This software was jointly developed between OKTET Labs (under contract
 # for Solarflare) and Solarflare Communications, Inc.
 
+if is_windows
+	build = false
+	reason = 'not supported on Windows'
+endif
+
 if (arch_subdir != 'x86' or not dpdk_conf.get('RTE_ARCH_64')) and (arch_subdir != 'arm' or not host_machine.cpu_family().startswith('aarch64'))
 	build = false
 	reason = 'only supported on x86_64 and aarch64'
@@ -32,6 +37,7 @@ endforeach
 subdir('base')
 objs = [base_objs]
 
+deps += ['bus_pci']
 sources = files(
 	'sfc_efx.c',
 	'sfc_efx_mcdi.c',
diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index a3146db255..0b78933d9f 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -62,6 +62,62 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)
 	return dev_class;
 }
 
+static efx_rc_t
+sfc_efx_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
+		     efsys_bar_t *barp)
+{
+	efsys_bar_t result;
+	struct rte_pci_device *dev;
+
+	memset(&result, 0, sizeof(result));
+
+	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
+		return -EINVAL;
+
+	dev = configp->espc_dev;
+
+	result.esb_rid = bar_index;
+	result.esb_dev = dev;
+	result.esb_base = dev->mem_resource[bar_index].addr;
+
+	*barp = result;
+
+	return 0;
+}
+
+static efx_rc_t
+sfc_efx_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
+			 efx_dword_t *edp)
+{
+	int rc;
+
+	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
+				 offset);
+
+	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
+}
+
+int
+sfc_efx_family(struct rte_pci_device *pci_dev,
+	       efx_bar_region_t *mem_ebrp, efx_family_t *family)
+{
+	static const efx_pci_ops_t ops = {
+		.epo_config_readd = sfc_efx_pci_config_readd,
+		.epo_find_mem_bar = sfc_efx_find_mem_bar,
+	};
+
+	efsys_pci_config_t espcp;
+	int rc;
+
+	espcp.espc_dev = pci_dev;
+
+	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
+				  pci_dev->id.device_id,
+				  &espcp, &ops, family, mem_ebrp);
+
+	return rc;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
index bbccd3e9e8..71288b7299 100644
--- a/drivers/common/sfc_efx/sfc_efx.h
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -10,6 +10,11 @@
 #ifndef _SFC_EFX_H_
 #define _SFC_EFX_H_
 
+#include <rte_bus_pci.h>
+
+#include "efx.h"
+#include "efsys.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -27,6 +32,11 @@ enum sfc_efx_dev_class {
 __rte_internal
 enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
 
+__rte_internal
+int sfc_efx_family(struct rte_pci_device *pci_dev,
+		   efx_bar_region_t *mem_ebrp,
+		   efx_family_t *family);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index a3345d34f7..c3414b760b 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -222,6 +222,7 @@ INTERNAL {
 	efx_txq_size;
 
 	sfc_efx_dev_class_get;
+	sfc_efx_family;
 
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
diff --git a/drivers/meson.build b/drivers/meson.build
index fdf76120ac..9c8eded697 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -7,6 +7,7 @@ subdirs = [
 	'bus',
 	'common/mlx5', # depends on bus.
 	'common/qat', # depends on bus.
+	'common/sfc_efx', # depends on bus.
 	'mempool', # depends on common and bus.
 	'net',     # depends on common, bus, mempool
 	'raw',     # depends on common, bus and net.
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 3135068c39..3477c7530b 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -631,29 +631,6 @@ sfc_close(struct sfc_adapter *sa)
 	sfc_log_init(sa, "done");
 }
 
-static efx_rc_t
-sfc_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
-		 efsys_bar_t *barp)
-{
-	efsys_bar_t result;
-	struct rte_pci_device *dev;
-
-	memset(&result, 0, sizeof(result));
-
-	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
-		return EINVAL;
-
-	dev = configp->espc_dev;
-
-	result.esb_rid = bar_index;
-	result.esb_dev = dev;
-	result.esb_base = dev->mem_resource[bar_index].addr;
-
-	*barp = result;
-
-	return 0;
-}
-
 static int
 sfc_mem_bar_init(struct sfc_adapter *sa, const efx_bar_region_t *mem_ebrp)
 {
@@ -1095,43 +1072,12 @@ sfc_nic_probe(struct sfc_adapter *sa)
 	return 0;
 }
 
-static efx_rc_t
-sfc_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
-		     efx_dword_t *edp)
-{
-	int rc;
-
-	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
-				 offset);
-
-	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
-}
-
-static int
-sfc_family(struct sfc_adapter *sa, efx_bar_region_t *mem_ebrp)
-{
-	struct rte_eth_dev *eth_dev = sa->eth_dev;
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	efsys_pci_config_t espcp;
-	static const efx_pci_ops_t ops = {
-		.epo_config_readd = sfc_pci_config_readd,
-		.epo_find_mem_bar = sfc_find_mem_bar,
-	};
-	int rc;
-
-	espcp.espc_dev = pci_dev;
-
-	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
-				  pci_dev->id.device_id,
-				  &espcp, &ops, &sa->family, mem_ebrp);
-
-	return rc;
-}
-
 int
 sfc_probe(struct sfc_adapter *sa)
 {
 	efx_bar_region_t mem_ebrp;
+	struct rte_eth_dev *eth_dev = sa->eth_dev;
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	efx_nic_t *enp;
 	int rc;
 
@@ -1143,7 +1089,8 @@ sfc_probe(struct sfc_adapter *sa)
 	rte_atomic32_init(&sa->restart_required);
 
 	sfc_log_init(sa, "get family");
-	rc = sfc_family(sa, &mem_ebrp);
+	rc = sfc_efx_family(pci_dev, &mem_ebrp, &sa->family);
+
 	if (rc != 0)
 		goto fail_family;
 	sfc_log_init(sa,
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-15 15:54   ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
@ 2021-03-16  7:25     ` Andrew Rybchenko
  0 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  7:25 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

On 3/15/21 6:54 PM, Ferruh Yigit wrote:
> On 3/15/2021 1:58 PM, Andrew Rybchenko wrote:
>> Update base driver to provide functionality required by vDPA driver.
>>
>> Factor out helper functions to be shared by net and vDPA drivers.
>>
>> v2:
>>   - fix windows build breakage - do not build common/sfc_efx in the case
>>     of windows
>>   - remove undefined efx_virtio_* functions from version.map (since
>>     EFSYS_OPT_VIRTIO is disabled)
>>
>> Vijay Kumar Srivastava (6):
>>    common/sfc_efx/base: add virtio build dependency
>>    common/sfc_efx/base: add support to get virtio features
>>    common/sfc_efx/base: add support to verify virtio features
>>    common/sfc_efx: add support to get the device class
>>    net/sfc: skip driver probe for incompatible device class
>>    drivers: add common driver API to get efx family
>>
>> Vijay Srivastava (2):
>>    common/sfc_efx/base: add base virtio support for vDPA
>>    common/sfc_efx/base: add API to get VirtQ doorbell offset
>>
>
> build still fails for windows,
> http://mails.dpdk.org/archives/test-report/2021-March/182539.html
>
> I guess it is missing, "build=false":
>   if is_windows
>  +       build=false
>          subdir_done()
>   endif
>

Looks like fixed in v3. At least Intel compilation test is OK now.

Thanks,
Andrew.


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v3 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
                     ` (7 preceding siblings ...)
  2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
@ 2021-03-16  8:55   ` Andrew Rybchenko
  8 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:55 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

On 3/16/21 9:15 AM, Andrew Rybchenko wrote:
> Update base driver to provide functionality required by vDPA driver.
> 
> Factor out helper functions to be shared by net and vDPA drivers.

Sorry, self NACK, will send v4 shortly.
Forgot about Copyright year in new files.


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
                   ` (9 preceding siblings ...)
  2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
@ 2021-03-16  8:58 ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
                     ` (9 more replies)
  10 siblings, 10 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

Update base driver to provide functionality required by vDPA driver.

Factor out helper functions to be shared by net and vDPA drivers.

v4:
 - fix Copyright year

v3:
 - one more attempt to fix windows build breakage

v2:
 - fix windows build breakage - do not build common/sfc_efx in the case
   of windows
 - remove undefined efx_virtio_* functions from version.map (since
   EFSYS_OPT_VIRTIO is disabled)

Vijay Kumar Srivastava (6):
  common/sfc_efx/base: add virtio build dependency
  common/sfc_efx/base: add support to get virtio features
  common/sfc_efx/base: add support to verify virtio features
  common/sfc_efx: add support to get the device class
  net/sfc: skip driver probe for incompatible device class
  drivers: add common driver API to get efx family

Vijay Srivastava (2):
  common/sfc_efx/base: add base virtio support for vDPA
  common/sfc_efx/base: add API to get VirtQ doorbell offset

 doc/guides/nics/sfc_efx.rst                |   8 +
 drivers/common/meson.build                 |   2 +-
 drivers/common/sfc_efx/base/efx.h          | 142 ++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   9 +
 drivers/common/sfc_efx/base/efx_impl.h     |  42 +++
 drivers/common/sfc_efx/base/efx_virtio.c   | 340 ++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  37 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 379 +++++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 drivers/common/sfc_efx/meson.build         |   6 +
 drivers/common/sfc_efx/sfc_efx.c           | 105 ++++++
 drivers/common/sfc_efx/sfc_efx.h           |  44 +++
 drivers/common/sfc_efx/version.map         |   3 +
 drivers/meson.build                        |   1 +
 drivers/net/sfc/sfc.c                      |  61 +---
 drivers/net/sfc/sfc.h                      |   1 +
 drivers/net/sfc/sfc_ethdev.c               |   7 +
 drivers/net/sfc/sfc_kvargs.c               |   1 +
 19 files changed, 1134 insertions(+), 58 deletions(-)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16 11:30     ` Ferruh Yigit
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
                     ` (8 subsequent siblings)
  9 siblings, 1 reply; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

In the vDPA mode, only data path is offloaded in the hardware and
control path still goes through the hypervisor and it configures
virtqueues via vDPA driver so new virtqueue APIs are required.

Implement virtio init/fini and virtqueue create/destroy APIs.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 109 +++++++++++
 drivers/common/sfc_efx/base/efx_check.h    |   6 +
 drivers/common/sfc_efx/base/efx_impl.h     |  36 ++++
 drivers/common/sfc_efx/base/efx_virtio.c   | 216 +++++++++++++++++++++
 drivers/common/sfc_efx/base/meson.build    |   2 +
 drivers/common/sfc_efx/base/rhead_impl.h   |  17 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 190 ++++++++++++++++++
 drivers/common/sfc_efx/efsys.h             |   2 +
 8 files changed, 578 insertions(+)
 create mode 100644 drivers/common/sfc_efx/base/efx_virtio.c
 create mode 100644 drivers/common/sfc_efx/base/rhead_virtio.c

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 2c820022b2..c2c73bd382 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4368,6 +4368,115 @@ efx_mae_action_rule_remove(
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+/* A Virtio net device can have one or more pairs of Rx/Tx virtqueues
+ * while virtio block device has a single virtqueue,
+ * for further details refer section of 4.2.3 of SF-120734
+ */
+typedef enum efx_virtio_vq_type_e {
+	EFX_VIRTIO_VQ_TYPE_NET_RXQ,
+	EFX_VIRTIO_VQ_TYPE_NET_TXQ,
+	EFX_VIRTIO_VQ_TYPE_BLOCK,
+	EFX_VIRTIO_VQ_NTYPES
+} efx_virtio_vq_type_t;
+
+typedef struct efx_virtio_vq_dyncfg_s {
+	/*
+	 * If queue is being created to be migrated then this
+	 * should be the FINAL_PIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_pidx;
+	/*
+	 * If this queue is being created to be migrated then this
+	 * should be the FINAL_CIDX value returned by MC_CMD_VIRTIO_FINI_QUEUE
+	 * of the queue being migrated from. Otherwise, it should be zero.
+	 */
+	uint32_t		evvd_vq_cidx;
+} efx_virtio_vq_dyncfg_t;
+
+/*
+ * Virtqueue size must be a power of 2, maximum size is 32768
+ * (see VIRTIO v1.1 section 2.6)
+ */
+#define EFX_VIRTIO_MAX_VQ_SIZE	0x8000
+
+typedef struct efx_virtio_vq_cfg_s {
+	unsigned int		evvc_vq_num;
+	efx_virtio_vq_type_t	evvc_type;
+	/*
+	 * vDPA as VF : It is target VF number if queue is being created on VF.
+	 * vDPA as PF : If queue to be created on PF then it should be
+	 * EFX_PCI_VF_INVALID.
+	 */
+	uint16_t		evvc_target_vf;
+	/*
+	 * Maximum virtqueue size is EFX_VIRTIO_MAX_VQ_SIZE and
+	 * virtqueue size 0 means the queue is unavailable.
+	 */
+	uint32_t		evvc_vq_size;
+	efsys_dma_addr_t        evvc_desc_tbl_addr;
+	efsys_dma_addr_t	evvc_avail_ring_addr;
+	efsys_dma_addr_t	evvc_used_ring_addr;
+	/* MSIX vector number for the virtqueue or 0xFFFF if MSIX is not used */
+	uint16_t                evvc_msix_vector;
+	/*
+	 * evvc_pas_id contains a PCIe address space identifier if the queue
+	 * uses PASID.
+	 */
+	boolean_t               evvc_use_pasid;
+	uint32_t		evvc_pas_id;
+	/* Negotiated virtio features to be applied to this virtqueue */
+	uint64_t		evcc_features;
+} efx_virtio_vq_cfg_t;
+
+typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp);
+
+LIBEFX_API
+extern			void
+efx_virtio_fini(
+	__in		efx_nic_t *enp);
+
+/*
+ * When virtio net driver in the guest sets VIRTIO_CONFIG_STATUS_DRIVER_OK bit,
+ * hypervisor starts configuring all the virtqueues in the device. When the
+ * vhost_user has received VHOST_USER_SET_VRING_ENABLE for all the virtqueues,
+ * then it invokes VDPA driver callback dev_conf. APIs qstart and qcreate would
+ * be invoked from dev_conf callback to create the virtqueues, For further
+ * details refer SF-122427.
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_API
+extern			void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 9e288f272a..86a6d92fef 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -407,4 +407,10 @@
 # endif
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+# if !EFSYS_OPT_RIVERHEAD
+#  error "VIRTIO requires RIVERHEAD"
+# endif
+#endif /* EFSYS_OPT_VIRTIO */
+
 #endif /* _SYS_EFX_CHECK_H */
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index a0628e6927..f27d9fa82c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -65,6 +65,7 @@ extern "C" {
 #define	EFX_MOD_TUNNEL		0x00004000
 #define	EFX_MOD_EVB		0x00008000
 #define	EFX_MOD_PROXY		0x00010000
+#define	EFX_MOD_VIRTIO		0x00020000
 
 #define	EFX_RESET_PHY		0x00000001
 #define	EFX_RESET_RXQ_ERR	0x00000002
@@ -308,6 +309,16 @@ typedef struct efx_tunnel_ops_s {
 } efx_tunnel_ops_t;
 #endif /* EFSYS_OPT_TUNNEL */
 
+#if EFSYS_OPT_VIRTIO
+typedef struct efx_virtio_ops_s {
+	efx_rc_t	(*evo_virtio_qstart)(efx_virtio_vq_t *,
+				efx_virtio_vq_cfg_t *,
+				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
+				efx_virtio_vq_dyncfg_t *);
+} efx_virtio_ops_t;
+#endif /* EFSYS_OPT_VIRTIO */
+
 typedef struct efx_port_s {
 	efx_mac_type_t		ep_mac_type;
 	uint32_t		ep_phy_type;
@@ -858,6 +869,9 @@ struct efx_nic_s {
 #if EFSYS_OPT_VPD
 	const efx_vpd_ops_t	*en_evpdop;
 #endif	/* EFSYS_OPT_VPD */
+#if EFSYS_OPT_VIRTIO
+	const efx_virtio_ops_t	*en_evop;
+#endif	/* EFSYS_OPT_VPD */
 #if EFSYS_OPT_RX_SCALE
 	efx_rx_hash_support_t		en_hash_support;
 	efx_rx_scale_context_type_t	en_rss_context_type;
@@ -1750,6 +1764,28 @@ struct efx_mae_actions_s {
 
 #endif /* EFSYS_OPT_MAE */
 
+#if EFSYS_OPT_VIRTIO
+
+#define	EFX_VQ_MAGIC	0x026011950
+
+typedef enum efx_virtio_vq_state_e {
+	EFX_VIRTIO_VQ_STATE_UNKNOWN = 0,
+	EFX_VIRTIO_VQ_STATE_INITIALIZED,
+	EFX_VIRTIO_VQ_STATE_STARTED,
+	EFX_VIRTIO_VQ_NSTATES
+} efx_virtio_vq_state_t;
+
+struct efx_virtio_vq_s {
+	uint32_t		evv_magic;
+	efx_nic_t		*evv_enp;
+	efx_virtio_vq_state_t	evv_state;
+	uint32_t		evv_vi_index;
+	efx_virtio_vq_type_t	evv_type;
+	uint16_t		evv_target_vf;
+};
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
new file mode 100644
index 0000000000..68d157bea6
--- /dev/null
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020-2021 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_VIRTIO
+
+#if EFSYS_OPT_RIVERHEAD
+static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
+	rhead_virtio_qstart,			/* evo_virtio_qstart */
+	rhead_virtio_qstop,			/* evo_virtio_qstop */
+};
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	__checkReturn	efx_rc_t
+efx_virtio_init(
+	__in		efx_nic_t *enp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_VIRTIO));
+
+	switch (enp->en_family) {
+#if EFSYS_OPT_RIVERHEAD
+	case EFX_FAMILY_RIVERHEAD:
+		evop = &__efx_virtio_rhead_ops;
+		break;
+#endif /* EFSYS_OPT_RIVERHEAD */
+
+	default:
+		EFSYS_ASSERT(0);
+		rc = ENOTSUP;
+		goto fail1;
+	}
+
+	enp->en_evop = evop;
+	enp->en_mod_flags |= EFX_MOD_VIRTIO;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+
+	return (rc);
+}
+
+	void
+efx_virtio_fini(
+	__in		efx_nic_t *enp)
+{
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	enp->en_evop = NULL;
+	enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qcreate(
+	__in		efx_nic_t *enp,
+	__deref_out	efx_virtio_vq_t **evvpp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_virtio_vq_t *evvp;
+	efx_rc_t rc;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	/* Allocate a virtqueue object */
+	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	if (evvp == NULL) {
+		rc = ENOMEM;
+		goto fail1;
+	}
+
+	evvp->evv_magic = EFX_VQ_MAGIC;
+	evvp->evv_enp = enp;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	*evvpp = evvp;
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvcp == NULL) || (evvp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	evop = evvp->evv_enp->en_evop;
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstart(evvp, evvcp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_type = evvcp->evvc_type;
+	evvp->evv_target_vf = evvcp->evvc_target_vf;
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_STARTED;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+efx_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if (evvp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(evvp->evv_magic, ==, EFX_VQ_MAGIC);
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_STARTED) {
+		rc = EINVAL;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_virtio_qstop(evvp, evvdp)) != 0)
+		goto fail4;
+
+	evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
+
+	return 0;
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	void
+efx_virtio_qdestroy(
+	__in		efx_virtio_vq_t *evvp)
+{
+	efx_nic_t *enp;
+
+	if (evvp == NULL)
+		return;
+
+	enp = evvp->evv_enp;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+
+	if (evvp->evv_state == EFX_VIRTIO_VQ_STATE_INITIALIZED) {
+		/* Free the virtqueue object */
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
+	}
+}
+
+#endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/meson.build b/drivers/common/sfc_efx/base/meson.build
index f995eacac2..1a39418c65 100644
--- a/drivers/common/sfc_efx/base/meson.build
+++ b/drivers/common/sfc_efx/base/meson.build
@@ -29,6 +29,7 @@ sources = [
 	'efx_tunnel.c',
 	'efx_tx.c',
 	'efx_vpd.c',
+	'efx_virtio.c',
 	'mcdi_mon.c',
 	'siena_mac.c',
 	'siena_mcdi.c',
@@ -61,6 +62,7 @@ sources = [
 	'rhead_rx.c',
 	'rhead_tunnel.c',
 	'rhead_tx.c',
+	'rhead_virtio.c',
 ]
 
 extra_flags = [
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 50262b16a8..a15ac52a58 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -477,6 +477,23 @@ rhead_nic_xilinx_cap_tbl_read_ef100_locator(
 	__in				efsys_dma_addr_t offset,
 	__out				efx_bar_region_t *ebrp);
 
+#if EFSYS_OPT_VIRTIO
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstart(
+	__in				efx_virtio_vq_t *evvp,
+	__in				efx_virtio_vq_cfg_t *evvcp,
+	__in_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_qstop(
+	__in				efx_virtio_vq_t *evvp,
+	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
+
+#endif /* EFSYS_OPT_VIRTIO */
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
new file mode 100644
index 0000000000..ab83b24a45
--- /dev/null
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -0,0 +1,190 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020-2021 Xilinx, Inc.
+ */
+
+#include "efx.h"
+#include "efx_impl.h"
+
+#if EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO
+
+/*
+ * Get function-local index of the associated VI from the
+ * virtqueue number queue 0 is reserved for MCDI
+ */
+#define EFX_VIRTIO_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1)
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstart(
+	__in		efx_virtio_vq_t *evvp,
+	__in		efx_virtio_vq_cfg_t *evvcp,
+	__in_opt	efx_virtio_vq_dyncfg_t *evvdp)
+
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t vi_index;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_RXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_NET_TXQ ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_VQ_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_INIT_QUEUE_REQ_BLOCK);
+
+	if (evvcp->evvc_type >= EFX_VIRTIO_VQ_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	/* virtqueue size must be power of 2 */
+	if ((!ISP2(evvcp->evvc_vq_size)) ||
+	    (evvcp->evvc_vq_size > EFX_VIRTIO_MAX_VQ_SIZE)) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		if ((evvdp->evvd_vq_cidx > evvcp->evvc_vq_size) ||
+		    (evvdp->evvd_vq_pidx > evvcp->evvc_vq_size)) {
+			rc = EINVAL;
+			goto fail3;
+		}
+	}
+
+	req.emr_cmd = MC_CMD_VIRTIO_INIT_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_INIT_QUEUE_REQ_QUEUE_TYPE,
+		evvcp->evvc_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvcp->evvc_target_vf);
+
+	vi_index = EFX_VIRTIO_GET_VI_INDEX(evvcp->evvc_vq_num);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE, vi_index);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_SIZE,
+		evvcp->evvc_vq_size);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_LO,
+		evvcp->evvc_desc_tbl_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_HI,
+		evvcp->evvc_desc_tbl_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_LO,
+		evvcp->evvc_avail_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_HI,
+		evvcp->evvc_avail_ring_addr >> 32);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_LO,
+		evvcp->evvc_used_ring_addr & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_HI,
+		evvcp->evvc_used_ring_addr >> 32);
+
+	if (evvcp->evvc_use_pasid) {
+		MCDI_IN_POPULATE_DWORD_1(req, VIRTIO_INIT_QUEUE_REQ_FLAGS,
+			VIRTIO_INIT_QUEUE_REQ_USE_PASID, 1);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_PASID,
+			evvcp->evvc_pas_id);
+	}
+
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_MSIX_VECTOR,
+		evvcp->evvc_msix_vector);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_LO,
+		evvcp->evcc_features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_FEATURES_HI,
+		evvcp->evcc_features >> 32);
+
+	if (evvdp != NULL) {
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_PIDX,
+			evvdp->evvd_vq_pidx);
+		MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INITIAL_CIDX,
+			evvdp->evvd_vq_cidx);
+	}
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_MPORT_SELECTOR,
+		MAE_MPORT_SELECTOR_ASSIGNED);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail4;
+	}
+
+	evvp->evv_vi_index = vi_index;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+	__checkReturn   efx_rc_t
+rhead_virtio_qstop(
+	__in		efx_virtio_vq_t *evvp,
+	__out_opt	efx_virtio_vq_dyncfg_t *evvdp)
+{
+	efx_mcdi_req_t req;
+	efx_nic_t *enp = evvp->evv_enp;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN,
+		MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_FINI_QUEUE;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN;
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_FINI_QUEUE_REQ_QUEUE_TYPE, evvp->evv_type);
+	MCDI_IN_SET_WORD(req, VIRTIO_INIT_QUEUE_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_INIT_QUEUE_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	if (evvdp != NULL) {
+		evvdp->evvd_vq_pidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_PIDX);
+		evvdp->evvd_vq_cidx =
+		    MCDI_OUT_DWORD(req, VIRTIO_FINI_QUEUE_RESP_FINAL_CIDX);
+	}
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+#endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/efsys.h b/drivers/common/sfc_efx/efsys.h
index 663601412e..d133d61b3d 100644
--- a/drivers/common/sfc_efx/efsys.h
+++ b/drivers/common/sfc_efx/efsys.h
@@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAE 1
 
+#define EFSYS_OPT_VIRTIO 0
+
 /* ID */
 
 typedef struct __efsys_identifier_s efsys_identifier_t;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

From: Vijay Srivastava <vijays@solarflare.com>

Add an API to query the virtqueue doorbell offset in the BAR for a VI.
For vDPA, the virtio net driver notifies the device directly by writing
doorbell. This API would be invoked from vDPA client driver.

Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 12 +++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 41 ++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  6 ++
 drivers/common/sfc_efx/base/rhead_virtio.c | 93 ++++++++++++++++++++++
 5 files changed, 154 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index c2c73bd382..d4b7d7f47e 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4475,6 +4475,18 @@ extern			void
 efx_virtio_qdestroy(
 	__in		efx_virtio_vq_t *evvp);
 
+/*
+ * Get the offset in the BAR of the doorbells for a VI.
+ * net device : doorbell offset of RX & TX queues
+ * block device : request doorbell offset in the BAR.
+ * For further details refer section of 4 of SF-119689
+ */
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index f27d9fa82c..d6742f4a8c 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -316,6 +316,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_virtio_qstop)(efx_virtio_vq_t *,
 				efx_virtio_vq_dyncfg_t *);
+	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
+				uint32_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 68d157bea6..7303c00a0c 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -12,6 +12,7 @@
 static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
+	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -213,4 +214,44 @@ efx_virtio_qdestroy(
 	}
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp;
+	const efx_virtio_ops_t *evop;
+	efx_rc_t rc;
+
+	if ((evvp == NULL) || (offsetp == NULL)) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	enp = evvp->evv_enp;
+	evop = enp->en_evop;
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_get_doorbell_offset(evvp, offsetp)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index a15ac52a58..4304f63f4c 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -492,6 +492,12 @@ rhead_virtio_qstop(
 	__in				efx_virtio_vq_t *evvp,
 	__out_opt			efx_virtio_vq_dyncfg_t *evvdp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in				efx_virtio_vq_t *evvp,
+	__out				uint32_t *offsetp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index ab83b24a45..e69671394a 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -187,4 +187,97 @@ rhead_virtio_qstop(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_doorbell_offset(
+	__in		efx_virtio_vq_t *evvp,
+	__out		uint32_t *offsetp)
+{
+	efx_nic_t *enp = evvp->evv_enp;
+	efx_mcdi_req_t req;
+	uint32_t type;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN,
+		MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN);
+	efx_rc_t rc;
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN;
+
+	switch (evvp->evv_type) {
+	case EFX_VIRTIO_VQ_TYPE_NET_RXQ:
+	case EFX_VIRTIO_VQ_TYPE_NET_TXQ:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET;
+		break;
+	case EFX_VIRTIO_VQ_TYPE_BLOCK:
+		type = MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK;
+		break;
+	default:
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	MCDI_IN_SET_BYTE(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_DEVICE_ID,
+		type);
+	MCDI_IN_SET_WORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_TARGET_VF,
+		evvp->evv_target_vf);
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_DOORBELL_OFFSET_REQ_INSTANCE,
+		evvp->evv_vi_index);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail2;
+	}
+
+	switch (type) {
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_NET:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail3;
+		}
+
+		if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_RXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_RX_DBL_OFFSET);
+		} else if (evvp->evv_type == EFX_VIRTIO_VQ_TYPE_NET_TXQ) {
+			*offsetp = MCDI_OUT_DWORD(req,
+			    VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_TX_DBL_OFFSET);
+		}
+		break;
+	case MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK:
+		if (req.emr_out_length_used <
+		    MC_CMD_VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_LEN) {
+			rc = EMSGSIZE;
+			goto fail4;
+		}
+
+		*offsetp = MCDI_OUT_DWORD(req,
+			VIRTIO_GET_BLOCK_DOORBELL_OFFSET_RESP_DBL_OFFSET);
+		break;
+	default:
+		EFSYS_ASSERT(0);
+		rc = EINVAL;
+		goto fail5;
+	}
+
+	return (0);
+
+fail5:
+	EFSYS_PROBE(fail5);
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 3/8] common/sfc_efx/base: add virtio build dependency
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add EFSYS_HAS_UINT64 build dependency on EFSYS_OPT_VIRTIO.
virtio features are represented as bitmask in 64-bit unsigned
integer.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx_check.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx_check.h b/drivers/common/sfc_efx/base/efx_check.h
index 86a6d92fef..66b38eeae0 100644
--- a/drivers/common/sfc_efx/base/efx_check.h
+++ b/drivers/common/sfc_efx/base/efx_check.h
@@ -411,6 +411,9 @@
 # if !EFSYS_OPT_RIVERHEAD
 #  error "VIRTIO requires RIVERHEAD"
 # endif
+# if !EFSYS_HAS_UINT64
+#  error "VIRTIO requires UINT64"
+# endif
 #endif /* EFSYS_OPT_VIRTIO */
 
 #endif /* _SYS_EFX_CHECK_H */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 4/8] common/sfc_efx/base: add support to get virtio features
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (2 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to get virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          | 14 ++++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 45 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 +++
 drivers/common/sfc_efx/base/rhead_virtio.c | 52 ++++++++++++++++++++++
 5 files changed, 120 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index d4b7d7f47e..e3ac51eae0 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4433,6 +4433,13 @@ typedef struct efx_virtio_vq_cfg_s {
 
 typedef struct efx_virtio_vq_s	efx_virtio_vq_t;
 
+typedef enum efx_virtio_device_type_e {
+	EFX_VIRTIO_DEVICE_TYPE_RESERVED,
+	EFX_VIRTIO_DEVICE_TYPE_NET,
+	EFX_VIRTIO_DEVICE_TYPE_BLOCK,
+	EFX_VIRTIO_DEVICE_NTYPES
+} efx_virtio_device_type_t;
+
 LIBEFX_API
 extern	__checkReturn	efx_rc_t
 efx_virtio_init(
@@ -4487,6 +4494,13 @@ efx_virtio_get_doorbell_offset(
 	__in		efx_virtio_vq_t *evvp,
 	__out		uint32_t *offsetp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index d6742f4a8c..758206d382 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -318,6 +318,8 @@ typedef struct efx_virtio_ops_s {
 				efx_virtio_vq_dyncfg_t *);
 	efx_rc_t	(*evo_get_doorbell_offset)(efx_virtio_vq_t *,
 				uint32_t *);
+	efx_rc_t	(*evo_get_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t *);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 7303c00a0c..925dcc342b 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -13,6 +13,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstart,			/* evo_virtio_qstart */
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
+	rhead_virtio_get_features,		/* evo_get_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -254,4 +255,48 @@ efx_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (featuresp == NULL) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail2;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail3;
+	}
+
+	if ((rc = evop->evo_get_features(enp, type, featuresp)) != 0)
+		goto fail4;
+
+	return (0);
+
+fail4:
+	EFSYS_PROBE(fail4);
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 4304f63f4c..69d701a47e 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -498,6 +498,13 @@ rhead_virtio_get_doorbell_offset(
 	__in				efx_virtio_vq_t *evvp,
 	__out				uint32_t *offsetp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_get_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__out				uint64_t *featuresp);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index e69671394a..c49ac10b72 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -280,4 +280,56 @@ rhead_virtio_get_doorbell_offset(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_get_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__out		uint64_t *featuresp)
+{
+	efx_mcdi_req_t req;
+	uint32_t features_lo;
+	uint32_t features_hi;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_GET_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_GET_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_GET_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_GET_FEATURES_IN_DEVICE_ID, type);
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	features_lo = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_LO);
+	features_hi = MCDI_OUT_DWORD(req, VIRTIO_GET_FEATURES_OUT_FEATURES_HI);
+	*featuresp = ((uint64_t)features_hi << 32) | features_lo;
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 5/8] common/sfc_efx/base: add support to verify virtio features
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (3 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Add an API to verify virtio features supported by device.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx.h          |  7 ++++
 drivers/common/sfc_efx/base/efx_impl.h     |  2 +
 drivers/common/sfc_efx/base/efx_virtio.c   | 38 +++++++++++++++++++
 drivers/common/sfc_efx/base/rhead_impl.h   |  7 ++++
 drivers/common/sfc_efx/base/rhead_virtio.c | 44 ++++++++++++++++++++++
 5 files changed, 98 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index e3ac51eae0..ff5091a36b 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -4501,6 +4501,13 @@ efx_virtio_get_features(
 	__in		efx_virtio_device_type_t type,
 	__out		uint64_t *featuresp);
 
+LIBEFX_API
+extern	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 758206d382..aa878014c1 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -320,6 +320,8 @@ typedef struct efx_virtio_ops_s {
 				uint32_t *);
 	efx_rc_t	(*evo_get_features)(efx_nic_t *,
 				efx_virtio_device_type_t, uint64_t *);
+	efx_rc_t	(*evo_verify_features)(efx_nic_t *,
+				efx_virtio_device_type_t, uint64_t);
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
diff --git a/drivers/common/sfc_efx/base/efx_virtio.c b/drivers/common/sfc_efx/base/efx_virtio.c
index 925dcc342b..b9c351d732 100644
--- a/drivers/common/sfc_efx/base/efx_virtio.c
+++ b/drivers/common/sfc_efx/base/efx_virtio.c
@@ -14,6 +14,7 @@ static const efx_virtio_ops_t	__efx_virtio_rhead_ops = {
 	rhead_virtio_qstop,			/* evo_virtio_qstop */
 	rhead_virtio_get_doorbell_offset,	/* evo_get_doorbell_offset */
 	rhead_virtio_get_features,		/* evo_get_features */
+	rhead_virtio_verify_features,		/* evo_verify_features */
 };
 #endif /* EFSYS_OPT_RIVERHEAD */
 
@@ -299,4 +300,41 @@ efx_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+efx_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	const efx_virtio_ops_t *evop = enp->en_evop;
+	efx_rc_t rc;
+
+	if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
+	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
+
+	if (evop == NULL) {
+		rc = ENOTSUP;
+		goto fail2;
+	}
+
+	if ((rc = evop->evo_verify_features(enp, type, features)) != 0)
+		goto fail3;
+
+	return (0);
+
+fail3:
+	EFSYS_PROBE(fail3);
+fail2:
+	EFSYS_PROBE(fail2);
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif /* EFSYS_OPT_VIRTIO */
diff --git a/drivers/common/sfc_efx/base/rhead_impl.h b/drivers/common/sfc_efx/base/rhead_impl.h
index 69d701a47e..3bf9beceb0 100644
--- a/drivers/common/sfc_efx/base/rhead_impl.h
+++ b/drivers/common/sfc_efx/base/rhead_impl.h
@@ -505,6 +505,13 @@ rhead_virtio_get_features(
 	__in				efx_virtio_device_type_t type,
 	__out				uint64_t *featuresp);
 
+LIBEFX_INTERNAL
+extern	__checkReturn			efx_rc_t
+rhead_virtio_verify_features(
+	__in				efx_nic_t *enp,
+	__in				efx_virtio_device_type_t type,
+	__in				uint64_t features);
+
 #endif /* EFSYS_OPT_VIRTIO */
 
 #ifdef	__cplusplus
diff --git a/drivers/common/sfc_efx/base/rhead_virtio.c b/drivers/common/sfc_efx/base/rhead_virtio.c
index c49ac10b72..335cb747d1 100644
--- a/drivers/common/sfc_efx/base/rhead_virtio.c
+++ b/drivers/common/sfc_efx/base/rhead_virtio.c
@@ -332,4 +332,48 @@ rhead_virtio_get_features(
 	return (rc);
 }
 
+	__checkReturn	efx_rc_t
+rhead_virtio_verify_features(
+	__in		efx_nic_t *enp,
+	__in		efx_virtio_device_type_t type,
+	__in		uint64_t features)
+{
+	efx_mcdi_req_t req;
+	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN,
+		MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN);
+	efx_rc_t rc;
+
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_NET ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_NET);
+	EFX_STATIC_ASSERT(EFX_VIRTIO_DEVICE_TYPE_BLOCK ==
+		MC_CMD_VIRTIO_GET_FEATURES_IN_BLOCK);
+
+	req.emr_cmd = MC_CMD_VIRTIO_TEST_FEATURES;
+	req.emr_in_buf = payload;
+	req.emr_in_length = MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN;
+	req.emr_out_buf = payload;
+	req.emr_out_length = MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN;
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_DEVICE_ID, type);
+
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_LO,
+		features & 0xFFFFFFFF);
+	MCDI_IN_SET_DWORD(req, VIRTIO_TEST_FEATURES_IN_FEATURES_HI,
+		((features >> 32) & 0xFFFFFFFF));
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 #endif	/* EFSYS_OPT_RIVERHEAD && EFSYS_OPT_VIRTIO */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 6/8] common/sfc_efx: add support to get the device class
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (4 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Device class argument would be used to select compatible driver.
Driver probe would be skipped for incompatible device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/sfc_efx.c   | 49 ++++++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 34 +++++++++++++++++++++
 drivers/common/sfc_efx/version.map |  2 ++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/common/sfc_efx/sfc_efx.h

diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index d7a84c9835..a3146db255 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -7,12 +7,61 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
+#include <string.h>
 #include <rte_log.h>
+#include <rte_kvargs.h>
+#include <rte_devargs.h>
 
 #include "sfc_efx_log.h"
+#include "sfc_efx.h"
 
 uint32_t sfc_efx_logtype;
 
+static int
+sfc_efx_kvarg_dev_class_handler(__rte_unused const char *key,
+				const char *class_str, void *opaque)
+{
+	enum sfc_efx_dev_class *dev_class = opaque;
+
+	if (class_str == NULL)
+		return *dev_class;
+
+	if (strcmp(class_str, "vdpa") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_VDPA;
+	} else if (strcmp(class_str, "net") == 0) {
+		*dev_class = SFC_EFX_DEV_CLASS_NET;
+	} else {
+		SFC_EFX_LOG(ERR, "Unsupported class %s.", class_str);
+		*dev_class = SFC_EFX_DEV_CLASS_INVALID;
+	}
+
+	return 0;
+}
+
+enum sfc_efx_dev_class
+sfc_efx_dev_class_get(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvargs;
+	const char *key = SFC_EFX_KVARG_DEV_CLASS;
+	enum sfc_efx_dev_class dev_class = SFC_EFX_DEV_CLASS_NET;
+
+	if (devargs == NULL)
+		return dev_class;
+
+	kvargs = rte_kvargs_parse(devargs->args, NULL);
+	if (kvargs == NULL)
+		return dev_class;
+
+	if (rte_kvargs_count(kvargs, key) != 0) {
+		rte_kvargs_process(kvargs, key, sfc_efx_kvarg_dev_class_handler,
+				   &dev_class);
+	}
+
+	rte_kvargs_free(kvargs);
+
+	return dev_class;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
new file mode 100644
index 0000000000..f2aff0b4e8
--- /dev/null
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2019-2021 Xilinx, Inc.
+ * Copyright(c) 2019 Solarflare Communications Inc.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ */
+
+#ifndef _SFC_EFX_H_
+#define _SFC_EFX_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SFC_EFX_KVARG_DEV_CLASS	"class"
+
+enum sfc_efx_dev_class {
+	SFC_EFX_DEV_CLASS_INVALID = 0,
+	SFC_EFX_DEV_CLASS_NET,
+	SFC_EFX_DEV_CLASS_VDPA,
+
+	SFC_EFX_DEV_NCLASS
+};
+
+__rte_internal
+enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SFC_EFX_H_ */
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index 403feeaf11..a3345d34f7 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -221,6 +221,8 @@ INTERNAL {
 	efx_txq_nbufs;
 	efx_txq_size;
 
+	sfc_efx_dev_class_get;
+
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 7/8] net/sfc: skip driver probe for incompatible device class
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (5 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Driver would be probed only for the net device class.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst  | 8 ++++++++
 drivers/net/sfc/sfc.h        | 1 +
 drivers/net/sfc/sfc_ethdev.c | 7 +++++++
 drivers/net/sfc/sfc_kvargs.c | 1 +
 4 files changed, 17 insertions(+)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index b6047cf5c7..cf1269cc03 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -357,6 +357,14 @@ allow option like "-a 02:00.0,arg1=value1,...".
 Case-insensitive 1/y/yes/on or 0/n/no/off may be used to specify
 boolean parameters value.
 
+- ``class`` [net|vdpa] (default **net**)
+
+  Choose the mode of operation of ef100 device.
+  **net** device will work as network device and will be probed by net/sfc driver.
+  **vdpa** device will work as vdpa device and will be probed by vdpa/sfc driver.
+  If this parameter is not specified then ef100 device will operate as
+  network device.
+
 - ``rx_datapath`` [auto|efx|ef10|ef10_essb] (default **auto**)
 
   Choose receive datapath implementation.
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index c2945b6ba2..b48a818adb 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -22,6 +22,7 @@
 #include "efx.h"
 
 #include "sfc_efx_mcdi.h"
+#include "sfc_efx.h"
 
 #include "sfc_debug.h"
 #include "sfc_log.h"
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 00a0fd3d02..23828c24ff 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -2161,6 +2161,13 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	const struct rte_ether_addr *from;
 	int ret;
 
+	if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
+			SFC_EFX_DEV_CLASS_NET) {
+		SFC_GENERIC_LOG(DEBUG,
+			"Incompatible device class: skip probing, should be probed by other sfc driver.");
+		return 1;
+	}
+
 	sfc_register_dp();
 
 	logtype_main = sfc_register_logtype(&pci_dev->addr,
diff --git a/drivers/net/sfc/sfc_kvargs.c b/drivers/net/sfc/sfc_kvargs.c
index c42b326ab0..0efa92ed28 100644
--- a/drivers/net/sfc/sfc_kvargs.c
+++ b/drivers/net/sfc/sfc_kvargs.c
@@ -28,6 +28,7 @@ sfc_kvargs_parse(struct sfc_adapter *sa)
 		SFC_KVARG_TX_DATAPATH,
 		SFC_KVARG_FW_VARIANT,
 		SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
+		SFC_EFX_KVARG_DEV_CLASS,
 		NULL,
 	};
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* [dpdk-dev] [PATCH v4 8/8] drivers: add common driver API to get efx family
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (6 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
@ 2021-03-16  8:58   ` Andrew Rybchenko
  2021-03-16 11:26   ` [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
  2021-03-16 11:46   ` Ferruh Yigit
  9 siblings, 0 replies; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16  8:58 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Kumar Srivastava

From: Vijay Kumar Srivastava <vsrivast@xilinx.com>

Move function to get efx family from net driver into common driver.

Signed-off-by: Vijay Kumar Srivastava <vsrivast@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/meson.build         |  2 +-
 drivers/common/sfc_efx/meson.build |  6 +++
 drivers/common/sfc_efx/sfc_efx.c   | 56 +++++++++++++++++++++++++++
 drivers/common/sfc_efx/sfc_efx.h   | 10 +++++
 drivers/common/sfc_efx/version.map |  1 +
 drivers/meson.build                |  1 +
 drivers/net/sfc/sfc.c              | 61 ++----------------------------
 7 files changed, 79 insertions(+), 58 deletions(-)

diff --git a/drivers/common/meson.build b/drivers/common/meson.build
index ba6325adf3..66e12143b2 100644
--- a/drivers/common/meson.build
+++ b/drivers/common/meson.build
@@ -6,4 +6,4 @@ if is_windows
 endif
 
 std_deps = ['eal']
-drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2', 'sfc_efx']
+drivers = ['cpt', 'dpaax', 'iavf', 'mvep', 'octeontx', 'octeontx2']
diff --git a/drivers/common/sfc_efx/meson.build b/drivers/common/sfc_efx/meson.build
index d9afcf3eeb..1ca9510733 100644
--- a/drivers/common/sfc_efx/meson.build
+++ b/drivers/common/sfc_efx/meson.build
@@ -5,6 +5,11 @@
 # This software was jointly developed between OKTET Labs (under contract
 # for Solarflare) and Solarflare Communications, Inc.
 
+if is_windows
+	build = false
+	reason = 'not supported on Windows'
+endif
+
 if (arch_subdir != 'x86' or not dpdk_conf.get('RTE_ARCH_64')) and (arch_subdir != 'arm' or not host_machine.cpu_family().startswith('aarch64'))
 	build = false
 	reason = 'only supported on x86_64 and aarch64'
@@ -32,6 +37,7 @@ endforeach
 subdir('base')
 objs = [base_objs]
 
+deps += ['bus_pci']
 sources = files(
 	'sfc_efx.c',
 	'sfc_efx_mcdi.c',
diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c
index a3146db255..0b78933d9f 100644
--- a/drivers/common/sfc_efx/sfc_efx.c
+++ b/drivers/common/sfc_efx/sfc_efx.c
@@ -62,6 +62,62 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)
 	return dev_class;
 }
 
+static efx_rc_t
+sfc_efx_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
+		     efsys_bar_t *barp)
+{
+	efsys_bar_t result;
+	struct rte_pci_device *dev;
+
+	memset(&result, 0, sizeof(result));
+
+	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
+		return -EINVAL;
+
+	dev = configp->espc_dev;
+
+	result.esb_rid = bar_index;
+	result.esb_dev = dev;
+	result.esb_base = dev->mem_resource[bar_index].addr;
+
+	*barp = result;
+
+	return 0;
+}
+
+static efx_rc_t
+sfc_efx_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
+			 efx_dword_t *edp)
+{
+	int rc;
+
+	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
+				 offset);
+
+	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
+}
+
+int
+sfc_efx_family(struct rte_pci_device *pci_dev,
+	       efx_bar_region_t *mem_ebrp, efx_family_t *family)
+{
+	static const efx_pci_ops_t ops = {
+		.epo_config_readd = sfc_efx_pci_config_readd,
+		.epo_find_mem_bar = sfc_efx_find_mem_bar,
+	};
+
+	efsys_pci_config_t espcp;
+	int rc;
+
+	espcp.espc_dev = pci_dev;
+
+	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
+				  pci_dev->id.device_id,
+				  &espcp, &ops, family, mem_ebrp);
+
+	return rc;
+}
+
 RTE_INIT(sfc_efx_register_logtype)
 {
 	int ret;
diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h
index f2aff0b4e8..6b6164cb1f 100644
--- a/drivers/common/sfc_efx/sfc_efx.h
+++ b/drivers/common/sfc_efx/sfc_efx.h
@@ -10,6 +10,11 @@
 #ifndef _SFC_EFX_H_
 #define _SFC_EFX_H_
 
+#include <rte_bus_pci.h>
+
+#include "efx.h"
+#include "efsys.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -27,6 +32,11 @@ enum sfc_efx_dev_class {
 __rte_internal
 enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs);
 
+__rte_internal
+int sfc_efx_family(struct rte_pci_device *pci_dev,
+		   efx_bar_region_t *mem_ebrp,
+		   efx_family_t *family);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map
index a3345d34f7..c3414b760b 100644
--- a/drivers/common/sfc_efx/version.map
+++ b/drivers/common/sfc_efx/version.map
@@ -222,6 +222,7 @@ INTERNAL {
 	efx_txq_size;
 
 	sfc_efx_dev_class_get;
+	sfc_efx_family;
 
 	sfc_efx_mcdi_init;
 	sfc_efx_mcdi_fini;
diff --git a/drivers/meson.build b/drivers/meson.build
index fdf76120ac..9c8eded697 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -7,6 +7,7 @@ subdirs = [
 	'bus',
 	'common/mlx5', # depends on bus.
 	'common/qat', # depends on bus.
+	'common/sfc_efx', # depends on bus.
 	'mempool', # depends on common and bus.
 	'net',     # depends on common, bus, mempool
 	'raw',     # depends on common, bus and net.
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 3135068c39..3477c7530b 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -631,29 +631,6 @@ sfc_close(struct sfc_adapter *sa)
 	sfc_log_init(sa, "done");
 }
 
-static efx_rc_t
-sfc_find_mem_bar(efsys_pci_config_t *configp, int bar_index,
-		 efsys_bar_t *barp)
-{
-	efsys_bar_t result;
-	struct rte_pci_device *dev;
-
-	memset(&result, 0, sizeof(result));
-
-	if (bar_index < 0 || bar_index >= PCI_MAX_RESOURCE)
-		return EINVAL;
-
-	dev = configp->espc_dev;
-
-	result.esb_rid = bar_index;
-	result.esb_dev = dev;
-	result.esb_base = dev->mem_resource[bar_index].addr;
-
-	*barp = result;
-
-	return 0;
-}
-
 static int
 sfc_mem_bar_init(struct sfc_adapter *sa, const efx_bar_region_t *mem_ebrp)
 {
@@ -1095,43 +1072,12 @@ sfc_nic_probe(struct sfc_adapter *sa)
 	return 0;
 }
 
-static efx_rc_t
-sfc_pci_config_readd(efsys_pci_config_t *configp, uint32_t offset,
-		     efx_dword_t *edp)
-{
-	int rc;
-
-	rc = rte_pci_read_config(configp->espc_dev, edp->ed_u32, sizeof(*edp),
-				 offset);
-
-	return (rc < 0 || rc != sizeof(*edp)) ? EIO : 0;
-}
-
-static int
-sfc_family(struct sfc_adapter *sa, efx_bar_region_t *mem_ebrp)
-{
-	struct rte_eth_dev *eth_dev = sa->eth_dev;
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	efsys_pci_config_t espcp;
-	static const efx_pci_ops_t ops = {
-		.epo_config_readd = sfc_pci_config_readd,
-		.epo_find_mem_bar = sfc_find_mem_bar,
-	};
-	int rc;
-
-	espcp.espc_dev = pci_dev;
-
-	rc = efx_family_probe_bar(pci_dev->id.vendor_id,
-				  pci_dev->id.device_id,
-				  &espcp, &ops, &sa->family, mem_ebrp);
-
-	return rc;
-}
-
 int
 sfc_probe(struct sfc_adapter *sa)
 {
 	efx_bar_region_t mem_ebrp;
+	struct rte_eth_dev *eth_dev = sa->eth_dev;
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	efx_nic_t *enp;
 	int rc;
 
@@ -1143,7 +1089,8 @@ sfc_probe(struct sfc_adapter *sa)
 	rte_atomic32_init(&sa->restart_required);
 
 	sfc_log_init(sa, "get family");
-	rc = sfc_family(sa, &mem_ebrp);
+	rc = sfc_efx_family(pci_dev, &mem_ebrp, &sa->family);
+
 	if (rc != 0)
 		goto fail_family;
 	sfc_log_init(sa,
-- 
2.30.1


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (7 preceding siblings ...)
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
@ 2021-03-16 11:26   ` Ferruh Yigit
  2021-03-16 11:30     ` Andrew Rybchenko
  2021-03-16 11:46   ` Ferruh Yigit
  9 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:26 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev

On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
> Update base driver to provide functionality required by vDPA driver.
> 
> Factor out helper functions to be shared by net and vDPA drivers.
> 
> v4:
>   - fix Copyright year
> 
> v3:
>   - one more attempt to fix windows build breakage
> 
> v2:
>   - fix windows build breakage - do not build common/sfc_efx in the case
>     of windows
>   - remove undefined efx_virtio_* functions from version.map (since
>     EFSYS_OPT_VIRTIO is disabled)
> 
> Vijay Kumar Srivastava (6):
>    common/sfc_efx/base: add virtio build dependency
>    common/sfc_efx/base: add support to get virtio features
>    common/sfc_efx/base: add support to verify virtio features
>    common/sfc_efx: add support to get the device class
>    net/sfc: skip driver probe for incompatible device class
>    drivers: add common driver API to get efx family
> 
> Vijay Srivastava (2):
>    common/sfc_efx/base: add base virtio support for vDPA
>    common/sfc_efx/base: add API to get VirtQ doorbell offset
> 

The driver adds vDPA support, I believe it worth mentioning in the driver 
documentation and in the release notes, can you please send a new version with 
documentation updates?

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16 11:26   ` [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
@ 2021-03-16 11:30     ` Andrew Rybchenko
  2021-03-16 11:32       ` Ferruh Yigit
  0 siblings, 1 reply; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16 11:30 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

On 3/16/21 2:26 PM, Ferruh Yigit wrote:
> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>> Update base driver to provide functionality required by vDPA driver.
>>
>> Factor out helper functions to be shared by net and vDPA drivers.
>>
>> v4:
>>   - fix Copyright year
>>
>> v3:
>>   - one more attempt to fix windows build breakage
>>
>> v2:
>>   - fix windows build breakage - do not build common/sfc_efx in the case
>>     of windows
>>   - remove undefined efx_virtio_* functions from version.map (since
>>     EFSYS_OPT_VIRTIO is disabled)
>>
>> Vijay Kumar Srivastava (6):
>>    common/sfc_efx/base: add virtio build dependency
>>    common/sfc_efx/base: add support to get virtio features
>>    common/sfc_efx/base: add support to verify virtio features
>>    common/sfc_efx: add support to get the device class
>>    net/sfc: skip driver probe for incompatible device class
>>    drivers: add common driver API to get efx family
>>
>> Vijay Srivastava (2):
>>    common/sfc_efx/base: add base virtio support for vDPA
>>    common/sfc_efx/base: add API to get VirtQ doorbell offset
>>
>
> The driver adds vDPA support, I believe it worth mentioning in the
> driver documentation and in the release notes, can you please send a
> new version with documentation updates?

No, no. It is just preparations to introduce the vDPA driver.
vDPA drier will be added in a subsequent patches and I'll
ensure that it is mentioned in release notes etc.


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
@ 2021-03-16 11:30     ` Ferruh Yigit
  2021-03-16 11:47       ` Andrew Rybchenko
  0 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:30 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev, Vijay Srivastava

On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
> From: Vijay Srivastava <vijays@solarflare.com>
> 
> In the vDPA mode, only data path is offloaded in the hardware and
> control path still goes through the hypervisor and it configures
> virtqueues via vDPA driver so new virtqueue APIs are required.
> 
> Implement virtio init/fini and virtqueue create/destroy APIs.
> 
> Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

<...>

> diff --git a/drivers/common/sfc_efx/efsys.h b/drivers/common/sfc_efx/efsys.h
> index 663601412e..d133d61b3d 100644
> --- a/drivers/common/sfc_efx/efsys.h
> +++ b/drivers/common/sfc_efx/efsys.h
> @@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
>   
>   #define EFSYS_OPT_MAE 1
>   
> +#define EFSYS_OPT_VIRTIO 0
> +

Hi Andrew,

How this 'efsys.h' works, is it compile time configuration file for the driver?
Is is expected that users change this file?

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16 11:30     ` Andrew Rybchenko
@ 2021-03-16 11:32       ` Ferruh Yigit
  2021-03-16 11:34         ` Ferruh Yigit
  0 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:32 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev

On 3/16/2021 11:30 AM, Andrew Rybchenko wrote:
> On 3/16/21 2:26 PM, Ferruh Yigit wrote:
>> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>>> Update base driver to provide functionality required by vDPA driver.
>>>
>>> Factor out helper functions to be shared by net and vDPA drivers.
>>>
>>> v4:
>>>    - fix Copyright year
>>>
>>> v3:
>>>    - one more attempt to fix windows build breakage
>>>
>>> v2:
>>>    - fix windows build breakage - do not build common/sfc_efx in the case
>>>      of windows
>>>    - remove undefined efx_virtio_* functions from version.map (since
>>>      EFSYS_OPT_VIRTIO is disabled)
>>>
>>> Vijay Kumar Srivastava (6):
>>>     common/sfc_efx/base: add virtio build dependency
>>>     common/sfc_efx/base: add support to get virtio features
>>>     common/sfc_efx/base: add support to verify virtio features
>>>     common/sfc_efx: add support to get the device class
>>>     net/sfc: skip driver probe for incompatible device class
>>>     drivers: add common driver API to get efx family
>>>
>>> Vijay Srivastava (2):
>>>     common/sfc_efx/base: add base virtio support for vDPA
>>>     common/sfc_efx/base: add API to get VirtQ doorbell offset
>>>
>>
>> The driver adds vDPA support, I believe it worth mentioning in the
>> driver documentation and in the release notes, can you please send a
>> new version with documentation updates?
> 
> No, no. It is just preparations to introduce the vDPA driver.
> vDPA drier will be added in a subsequent patches and I'll
> ensure that it is mentioned in release notes etc.
> 

Got it, that answers a few of unused functions too.. Please be sure to document.

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16 11:32       ` Ferruh Yigit
@ 2021-03-16 11:34         ` Ferruh Yigit
  0 siblings, 0 replies; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:34 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev

On 3/16/2021 11:32 AM, Ferruh Yigit wrote:
> On 3/16/2021 11:30 AM, Andrew Rybchenko wrote:
>> On 3/16/21 2:26 PM, Ferruh Yigit wrote:
>>> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>>>> Update base driver to provide functionality required by vDPA driver.
>>>>
>>>> Factor out helper functions to be shared by net and vDPA drivers.
>>>>
>>>> v4:
>>>>    - fix Copyright year
>>>>
>>>> v3:
>>>>    - one more attempt to fix windows build breakage
>>>>
>>>> v2:
>>>>    - fix windows build breakage - do not build common/sfc_efx in the case
>>>>      of windows
>>>>    - remove undefined efx_virtio_* functions from version.map (since
>>>>      EFSYS_OPT_VIRTIO is disabled)
>>>>
>>>> Vijay Kumar Srivastava (6):
>>>>     common/sfc_efx/base: add virtio build dependency
>>>>     common/sfc_efx/base: add support to get virtio features
>>>>     common/sfc_efx/base: add support to verify virtio features
>>>>     common/sfc_efx: add support to get the device class
>>>>     net/sfc: skip driver probe for incompatible device class
>>>>     drivers: add common driver API to get efx family
>>>>
>>>> Vijay Srivastava (2):
>>>>     common/sfc_efx/base: add base virtio support for vDPA
>>>>     common/sfc_efx/base: add API to get VirtQ doorbell offset
>>>>
>>>
>>> The driver adds vDPA support, I believe it worth mentioning in the
>>> driver documentation and in the release notes, can you please send a
>>> new version with documentation updates?
>>
>> No, no. It is just preparations to introduce the vDPA driver.
>> vDPA drier will be added in a subsequent patches and I'll
>> ensure that it is mentioned in release notes etc.
>>
> 
> Got it, that answers a few of unused functions too.. Please be sure to document.

I mean with coming patches, where appropriate.

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver
  2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
                     ` (8 preceding siblings ...)
  2021-03-16 11:26   ` [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
@ 2021-03-16 11:46   ` Ferruh Yigit
  9 siblings, 0 replies; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:46 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev

On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
> Update base driver to provide functionality required by vDPA driver.
> 
> Factor out helper functions to be shared by net and vDPA drivers.
> 
> v4:
>   - fix Copyright year
> 
> v3:
>   - one more attempt to fix windows build breakage
> 
> v2:
>   - fix windows build breakage - do not build common/sfc_efx in the case
>     of windows
>   - remove undefined efx_virtio_* functions from version.map (since
>     EFSYS_OPT_VIRTIO is disabled)
> 
> Vijay Kumar Srivastava (6):
>    common/sfc_efx/base: add virtio build dependency
>    common/sfc_efx/base: add support to get virtio features
>    common/sfc_efx/base: add support to verify virtio features
>    common/sfc_efx: add support to get the device class
>    net/sfc: skip driver probe for incompatible device class
>    drivers: add common driver API to get efx family
> 
> Vijay Srivastava (2):
>    common/sfc_efx/base: add base virtio support for vDPA
>    common/sfc_efx/base: add API to get VirtQ doorbell offset
> 

Series applied to dpdk-next-net/main, thanks.


^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16 11:30     ` Ferruh Yigit
@ 2021-03-16 11:47       ` Andrew Rybchenko
  2021-03-16 11:58         ` Ferruh Yigit
  0 siblings, 1 reply; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16 11:47 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

On 3/16/21 2:30 PM, Ferruh Yigit wrote:
> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>> From: Vijay Srivastava <vijays@solarflare.com>
>>
>> In the vDPA mode, only data path is offloaded in the hardware and
>> control path still goes through the hypervisor and it configures
>> virtqueues via vDPA driver so new virtqueue APIs are required.
>>
>> Implement virtio init/fini and virtqueue create/destroy APIs.
>>
>> Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> 
> <...>
> 
>> diff --git a/drivers/common/sfc_efx/efsys.h
>> b/drivers/common/sfc_efx/efsys.h
>> index 663601412e..d133d61b3d 100644
>> --- a/drivers/common/sfc_efx/efsys.h
>> +++ b/drivers/common/sfc_efx/efsys.h
>> @@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
>>     #define EFSYS_OPT_MAE 1
>>   +#define EFSYS_OPT_VIRTIO 0
>> +
> 
> Hi Andrew,
> 
> How this 'efsys.h' works, is it compile time configuration file for the
> driver?

Yes, it is a compile time configuration of the base driver.

> Is is expected that users change this file?

Client drivers (e.g. net/sfc or vdpa/sfc) change the base
driver configuration when it needs corresponding functionality
from the base driver. Of course, it is not ideal to add code
which is not actually compiled right now, but we always try
to ensure that build finally works fine and no extra patches
will be required to fix the build when corresponding option
is enabled.

In theory we can send longer patch series which includes
the vdpa/sfc driver, but it will be longer patch series which
is harder to chew.

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16 11:47       ` Andrew Rybchenko
@ 2021-03-16 11:58         ` Ferruh Yigit
  2021-03-16 12:14           ` Andrew Rybchenko
  0 siblings, 1 reply; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 11:58 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev, Vijay Srivastava

On 3/16/2021 11:47 AM, Andrew Rybchenko wrote:
> On 3/16/21 2:30 PM, Ferruh Yigit wrote:
>> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>>> From: Vijay Srivastava <vijays@solarflare.com>
>>>
>>> In the vDPA mode, only data path is offloaded in the hardware and
>>> control path still goes through the hypervisor and it configures
>>> virtqueues via vDPA driver so new virtqueue APIs are required.
>>>
>>> Implement virtio init/fini and virtqueue create/destroy APIs.
>>>
>>> Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
>>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>
>> <...>
>>
>>> diff --git a/drivers/common/sfc_efx/efsys.h
>>> b/drivers/common/sfc_efx/efsys.h
>>> index 663601412e..d133d61b3d 100644
>>> --- a/drivers/common/sfc_efx/efsys.h
>>> +++ b/drivers/common/sfc_efx/efsys.h
>>> @@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
>>>      #define EFSYS_OPT_MAE 1
>>>    +#define EFSYS_OPT_VIRTIO 0
>>> +
>>
>> Hi Andrew,
>>
>> How this 'efsys.h' works, is it compile time configuration file for the
>> driver?
> 
> Yes, it is a compile time configuration of the base driver.
> 
>> Is is expected that users change this file?
> 
> Client drivers (e.g. net/sfc or vdpa/sfc) change the base
> driver configuration when it needs corresponding functionality
> from the base driver. Of course, it is not ideal to add code
> which is not actually compiled right now, but we always try
> to ensure that build finally works fine and no extra patches
> will be required to fix the build when corresponding option
> is enabled.
> 
> In theory we can send longer patch series which includes
> the vdpa/sfc driver, but it will be longer patch series which
> is harder to chew.
> 

It is OK to send preparation sets first, that wasn't my point.

My concern is having compile time configuration within driver, my question is if 
end user of the driver need to tweak these config options, if so should it be 
more generic way instead of a PMD specific way...

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16 11:58         ` Ferruh Yigit
@ 2021-03-16 12:14           ` Andrew Rybchenko
  2021-03-16 12:41             ` Ferruh Yigit
  0 siblings, 1 reply; 51+ messages in thread
From: Andrew Rybchenko @ 2021-03-16 12:14 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Vijay Srivastava

On 3/16/21 2:58 PM, Ferruh Yigit wrote:
> On 3/16/2021 11:47 AM, Andrew Rybchenko wrote:
>> On 3/16/21 2:30 PM, Ferruh Yigit wrote:
>>> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>>>> From: Vijay Srivastava <vijays@solarflare.com>
>>>>
>>>> In the vDPA mode, only data path is offloaded in the hardware and
>>>> control path still goes through the hypervisor and it configures
>>>> virtqueues via vDPA driver so new virtqueue APIs are required.
>>>>
>>>> Implement virtio init/fini and virtqueue create/destroy APIs.
>>>>
>>>> Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
>>>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>>
>>> <...>
>>>
>>>> diff --git a/drivers/common/sfc_efx/efsys.h
>>>> b/drivers/common/sfc_efx/efsys.h
>>>> index 663601412e..d133d61b3d 100644
>>>> --- a/drivers/common/sfc_efx/efsys.h
>>>> +++ b/drivers/common/sfc_efx/efsys.h
>>>> @@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
>>>>      #define EFSYS_OPT_MAE 1
>>>>    +#define EFSYS_OPT_VIRTIO 0
>>>> +
>>>
>>> Hi Andrew,
>>>
>>> How this 'efsys.h' works, is it compile time configuration file for the
>>> driver?
>>
>> Yes, it is a compile time configuration of the base driver.
>>
>>> Is is expected that users change this file?
>>
>> Client drivers (e.g. net/sfc or vdpa/sfc) change the base
>> driver configuration when it needs corresponding functionality
>> from the base driver. Of course, it is not ideal to add code
>> which is not actually compiled right now, but we always try
>> to ensure that build finally works fine and no extra patches
>> will be required to fix the build when corresponding option
>> is enabled.
>>
>> In theory we can send longer patch series which includes
>> the vdpa/sfc driver, but it will be longer patch series which
>> is harder to chew.
>>
> 
> It is OK to send preparation sets first, that wasn't my point.

I see.

> My concern is having compile time configuration within driver, my
> question is if end user of the driver need to tweak these config
> options, if so should it be more generic way instead of a PMD specific
> way...

No, it is not a user configuration. It is configuration done by
client (net/sfc, vdpa/sfc) drivers which use the common driver.

^ permalink raw reply	[flat|nested] 51+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA
  2021-03-16 12:14           ` Andrew Rybchenko
@ 2021-03-16 12:41             ` Ferruh Yigit
  0 siblings, 0 replies; 51+ messages in thread
From: Ferruh Yigit @ 2021-03-16 12:41 UTC (permalink / raw)
  To: Andrew Rybchenko; +Cc: dev, Vijay Srivastava

On 3/16/2021 12:14 PM, Andrew Rybchenko wrote:
> On 3/16/21 2:58 PM, Ferruh Yigit wrote:
>> On 3/16/2021 11:47 AM, Andrew Rybchenko wrote:
>>> On 3/16/21 2:30 PM, Ferruh Yigit wrote:
>>>> On 3/16/2021 8:58 AM, Andrew Rybchenko wrote:
>>>>> From: Vijay Srivastava <vijays@solarflare.com>
>>>>>
>>>>> In the vDPA mode, only data path is offloaded in the hardware and
>>>>> control path still goes through the hypervisor and it configures
>>>>> virtqueues via vDPA driver so new virtqueue APIs are required.
>>>>>
>>>>> Implement virtio init/fini and virtqueue create/destroy APIs.
>>>>>
>>>>> Signed-off-by: Vijay Srivastava <vijays@solarflare.com>
>>>>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>>>
>>>> <...>
>>>>
>>>>> diff --git a/drivers/common/sfc_efx/efsys.h
>>>>> b/drivers/common/sfc_efx/efsys.h
>>>>> index 663601412e..d133d61b3d 100644
>>>>> --- a/drivers/common/sfc_efx/efsys.h
>>>>> +++ b/drivers/common/sfc_efx/efsys.h
>>>>> @@ -187,6 +187,8 @@ prefetch_read_once(const volatile void *addr)
>>>>>       #define EFSYS_OPT_MAE 1
>>>>>     +#define EFSYS_OPT_VIRTIO 0
>>>>> +
>>>>
>>>> Hi Andrew,
>>>>
>>>> How this 'efsys.h' works, is it compile time configuration file for the
>>>> driver?
>>>
>>> Yes, it is a compile time configuration of the base driver.
>>>
>>>> Is is expected that users change this file?
>>>
>>> Client drivers (e.g. net/sfc or vdpa/sfc) change the base
>>> driver configuration when it needs corresponding functionality
>>> from the base driver. Of course, it is not ideal to add code
>>> which is not actually compiled right now, but we always try
>>> to ensure that build finally works fine and no extra patches
>>> will be required to fix the build when corresponding option
>>> is enabled.
>>>
>>> In theory we can send longer patch series which includes
>>> the vdpa/sfc driver, but it will be longer patch series which
>>> is harder to chew.
>>>
>>
>> It is OK to send preparation sets first, that wasn't my point.
> 
> I see.
> 
>> My concern is having compile time configuration within driver, my
>> question is if end user of the driver need to tweak these config
>> options, if so should it be more generic way instead of a PMD specific
>> way...
> 
> No, it is not a user configuration. It is configuration done by
> client (net/sfc, vdpa/sfc) drivers which use the common driver.
> 

OK, thanks for clarification.

^ permalink raw reply	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2021-03-16 12:42 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 11:03 [dpdk-dev] [PATCH 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
2021-03-11 11:03 ` [dpdk-dev] [PATCH 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
2021-03-14  0:36   ` Ferruh Yigit
2021-03-15 14:01     ` Andrew Rybchenko
2021-03-15 13:58 ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
2021-03-15 13:58   ` [dpdk-dev] [PATCH v2 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
2021-03-15 15:54   ` [dpdk-dev] [PATCH v2 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
2021-03-16  7:25     ` Andrew Rybchenko
2021-03-16  6:15 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
2021-03-16  6:15   ` [dpdk-dev] [PATCH v3 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
2021-03-16  8:55   ` [dpdk-dev] [PATCH v3 0/8] common/sfc_efx: prepare to introduce vDPA driver Andrew Rybchenko
2021-03-16  8:58 ` [dpdk-dev] [PATCH v4 " Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 1/8] common/sfc_efx/base: add base virtio support for vDPA Andrew Rybchenko
2021-03-16 11:30     ` Ferruh Yigit
2021-03-16 11:47       ` Andrew Rybchenko
2021-03-16 11:58         ` Ferruh Yigit
2021-03-16 12:14           ` Andrew Rybchenko
2021-03-16 12:41             ` Ferruh Yigit
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 2/8] common/sfc_efx/base: add API to get VirtQ doorbell offset Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 3/8] common/sfc_efx/base: add virtio build dependency Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 4/8] common/sfc_efx/base: add support to get virtio features Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 5/8] common/sfc_efx/base: add support to verify " Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 6/8] common/sfc_efx: add support to get the device class Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 7/8] net/sfc: skip driver probe for incompatible " Andrew Rybchenko
2021-03-16  8:58   ` [dpdk-dev] [PATCH v4 8/8] drivers: add common driver API to get efx family Andrew Rybchenko
2021-03-16 11:26   ` [dpdk-dev] [PATCH v4 0/8] common/sfc_efx: prepare to introduce vDPA driver Ferruh Yigit
2021-03-16 11:30     ` Andrew Rybchenko
2021-03-16 11:32       ` Ferruh Yigit
2021-03-16 11:34         ` Ferruh Yigit
2021-03-16 11:46   ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).