From: Thomas Monjalon <thomas@monjalon.net>
To: Ferruh Yigit <ferruh.yigit@intel.com>,
Andrew Rybchenko <arybchenko@solarflare.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 1/3] ethdev: identify SR-IOV VF from host
Date: Tue, 29 Oct 2019 19:50:49 +0100 [thread overview]
Message-ID: <20191029185051.32203-2-thomas@monjalon.net> (raw)
In-Reply-To: <20191029185051.32203-1-thomas@monjalon.net>
In a virtual environment, the network controller may have to configure
some SR-IOV VF parameters for security reasons.
When the PF (host port) is driven by DPDK (OVS-DPDK case),
we face two different cases:
- driver is bifurcated (Mellanox case),
so the VF can be configured via the kernel.
- driver is on top of UIO or VFIO, so DPDK API is required,
and PMD-specific APIs were used.
This new generic API will avoid vendors fragmentation.
In order to target a VF (which has no port ID in the host),
the higher bit of port ID is reserved to be used
with port representor ID in existing functions.
Summary:
representor ID + VF bit == VF ID
If a function is not expected to do VF configuration,
or if the port does not control any VF configuration,
it returns -EINVAL or -ENODEV.
If a function can do VF configuration,
but the PMD does not support it, then -ENOTSUP should be returned.
The port can allow the use of the VF bit per function
by adding the implementation to its vf_ops.
The new macro RTE_ETH_VALID_ID_OR_ERR_RET must be called
instead of RTE_ETH_VALID_PORTID_OR_ERR_RET
to allow the use of the VF bit.
The new macro CALL_OP_OR_ERR_RET can be used to help
calling the right function in dev_ops or vf_ops,
depending on the VF bit.
No feature is enabled in this commit.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
lib/librte_ethdev/rte_ethdev.c | 44 ++++++++++++++++++++++--
lib/librte_ethdev/rte_ethdev.h | 38 ++++++++++++++++++++
lib/librte_ethdev/rte_ethdev_core.h | 1 +
lib/librte_ethdev/rte_ethdev_version.map | 1 +
4 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7743205d38..fb3da4dcc3 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -593,11 +593,36 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
int
rte_eth_dev_is_valid_port(uint16_t port_id)
{
+ /* legacy behaviour - without VF flag */
+ return rte_eth_dev_is_valid(port_id, 0);
+}
+
+static uint16_t
+port_id_parse(uint16_t port_id, bool *is_vf)
+{
+ *is_vf = (port_id & RTE_ETH_PORT_VF_FLAG) != 0;
+ return port_id & RTE_ETH_PORT_ID_MASK;
+}
+
+int
+rte_eth_dev_is_valid(uint16_t port_id, char allow_vf)
+{
+ bool is_vf;
+
+ port_id = port_id_parse(port_id, &is_vf);
+ if (is_vf && !allow_vf)
+ return 0; /* unallowed VF */
+
if (port_id >= RTE_MAX_ETHPORTS ||
(rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
- return 0;
- else
- return 1;
+ return 0; /* invalid port */
+
+ if (!is_vf)
+ return 1; /* valid port */
+
+ if (rte_eth_devices[port_id].vf_ops == NULL)
+ return 0; /* VF flag applies only to port controlling a VF */
+ return 2; /* VF connected to a valid port on the host */
}
static int
@@ -851,6 +876,19 @@ eth_err(uint16_t port_id, int ret)
return ret;
}
+static inline const struct eth_dev_ops *
+eth_dev_ops_get(const struct rte_eth_dev *dev, bool is_vf)
+{
+ if (is_vf)
+ return dev->vf_ops;
+ return dev->dev_ops;
+}
+
+#define ETH_DEV_OP_CALL(dev, vf, op, ...) ({ \
+ RTE_FUNC_PTR_OR_ERR_RET((eth_dev_ops_get(dev, vf)->op), -ENOTSUP); \
+ (eth_dev_ops_get(dev, vf)->op)(dev, ## __VA_ARGS__); \
+})
+
static int
rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
{
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index c36c1b631f..a410a195ce 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -1345,6 +1345,13 @@ struct rte_eth_dcb_info {
#define RTE_ETH_ALL RTE_MAX_ETHPORTS
/* Macros to check for valid port */
+#define RTE_ETH_VALID_ID_OR_ERR_RET(port_id, retval) do { \
+ if (!rte_eth_dev_is_valid(port_id, 1)) { \
+ RTE_ETHDEV_LOG(ERR, "Invalid port_id=%u\n", port_id); \
+ return retval; \
+ } \
+} while (0)
+
#define RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
if (!rte_eth_dev_is_valid_port(port_id)) { \
RTE_ETHDEV_LOG(ERR, "Invalid port_id=%u\n", port_id); \
@@ -1468,6 +1475,17 @@ struct rte_eth_dev_owner {
/** Device does not support MAC change after started */
#define RTE_ETH_DEV_NOLIVE_MAC_ADDR 0x0020
+/**
+ * Highest bit of port ID is reserved for targeting controlled VF.
+ * This bit can be combined with the port ID of a representor
+ * which implements some vf_ops.
+ * The meaning is to target the VF connected with the representor port
+ * instead of the representor port itself.
+ */
+#define RTE_ETH_PORT_VF_FLAG (1 << 15)
+/** Mask to get representor port ID from VF ID, excluding VF flag. */
+#define RTE_ETH_PORT_ID_MASK (RTE_ETH_PORT_VF_FLAG - 1)
+
/**
* Iterates over valid ethdev ports owned by a specific owner.
*
@@ -1909,6 +1927,26 @@ int rte_eth_dev_socket_id(uint16_t port_id);
*/
int rte_eth_dev_is_valid_port(uint16_t port_id);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Check if port_id of device is attached.
+ * The port_id can represent a VF connected to port
+ * implementing some vf_ops.
+ *
+ * @param port_id
+ * The port identifier of the Ethernet device.
+ * @param allow_vf
+ * The bit RTE_ETH_PORT_VF_FLAG is considered valid.
+ * @return
+ * - 0 if port is not attached or unallowed VF
+ * - 1 if device is attached and not representing a VF
+ * - 2 if is a remote VF connected to a port implementing vf_ops
+ */
+__rte_experimental
+int rte_eth_dev_is_valid(uint16_t port_id, char allow_vf);
+
/**
* Start specified RX queue of a port. It is used when rx_deferred_start
* flag of the specified queue is true.
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 392aea8e6b..46bc01926d 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -682,6 +682,7 @@ struct rte_eth_dev {
struct rte_eth_dev_data *data; /**< Pointer to device data. */
void *process_private; /**< Pointer to per-process device data. */
const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
+ const struct eth_dev_ops *vf_ops; /**< Functions for VF control */
struct rte_device *device; /**< Backing device */
struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
/** User application callbacks for NIC interrupts */
diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map
index e59d51648f..09670d4bb3 100644
--- a/lib/librte_ethdev/rte_ethdev_version.map
+++ b/lib/librte_ethdev/rte_ethdev_version.map
@@ -285,6 +285,7 @@ EXPERIMENTAL {
rte_eth_read_clock;
# added in 19.11
+ rte_eth_dev_is_valid;
rte_eth_rx_burst_mode_get;
rte_eth_tx_burst_mode_get;
rte_eth_burst_mode_option_name;
--
2.23.0
next prev parent reply other threads:[~2019-10-29 18:51 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-15 15:06 [dpdk-dev] [RFC] ethdev: configure " Thomas Monjalon
2019-08-15 15:34 ` Jerin Jacob Kollanukkaran
2019-08-15 17:59 ` Thomas Monjalon
2019-08-29 15:02 ` Iremonger, Bernard
2019-09-04 8:23 ` Thomas Monjalon
2019-10-29 18:50 ` [dpdk-dev] [PATCH v2 0/3] " Thomas Monjalon
2019-10-29 18:50 ` Thomas Monjalon [this message]
2019-10-29 18:50 ` [dpdk-dev] [PATCH v2 2/3] ethdev: set VF MAC address " Thomas Monjalon
2019-11-01 0:18 ` [dpdk-dev] [RFC PATCH] net/i[xgb|40]e: " Thomas Monjalon
2019-10-29 18:50 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: " Thomas Monjalon
2019-10-30 4:08 ` [dpdk-dev] [PATCH v2 0/3] ethdev: configure SR-IOV VF " Jerin Jacob
2019-10-30 7:22 ` Shahaf Shuler
2019-10-30 9:24 ` Jerin Jacob
2019-11-01 0:24 ` Thomas Monjalon
2019-11-01 9:06 ` Ilya Maximets
2019-11-01 9:56 ` Ilya Maximets
2019-10-30 8:56 ` Thomas Monjalon
2019-10-30 9:15 ` Jerin Jacob
2019-11-01 0:33 ` Thomas Monjalon
2019-11-01 11:01 ` Jerin Jacob
2019-11-01 13:25 ` Jerin Jacob
2019-11-03 6:31 ` Shahaf Shuler
2019-10-30 15:07 ` Ilya Maximets
2019-10-30 15:49 ` Thomas Monjalon
2019-10-30 16:09 ` Ilya Maximets
2019-10-30 21:42 ` Thomas Monjalon
2019-11-01 9:32 ` Ilya Maximets
2019-11-03 6:48 ` Shahaf Shuler
2019-11-03 15:27 ` Ananyev, Konstantin
2019-11-03 22:09 ` Thomas Monjalon
2019-11-07 14:44 ` Thomas Monjalon
2019-11-04 10:28 ` Ilya Maximets
2019-11-04 14:30 ` Asaf Penso
2019-11-04 14:58 ` Ilya Maximets
2019-11-04 20:33 ` Shahaf Shuler
2019-11-05 12:15 ` Ilya Maximets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191029185051.32203-2-thomas@monjalon.net \
--to=thomas@monjalon.net \
--cc=arybchenko@solarflare.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).