From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 63732A00BE; Tue, 29 Oct 2019 19:51:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8854A1BF97; Tue, 29 Oct 2019 19:51:04 +0100 (CET) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 816491BF94 for ; Tue, 29 Oct 2019 19:51:02 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E478021B62; Tue, 29 Oct 2019 14:51:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 29 Oct 2019 14:51:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=HVX5Q0UIpg XL4HPJQ2znaznYJtCGyL9PiNJti1XbW8I=; b=BEUwlWnGFHJfYSjuM+71/Ak9f+ Z+xIsGYgImBFq3eqdyW+6EwEuHx5lzDQcmLjUnt2fWxU5ipq54qOLmlOr50HeDrw FRSszo242XJmSGvrO27OEVoObRqTmBZXwaZz7SVOXTm/0hTGzXjsFsmxecNEHKmG fehXpBjkrYhlUBuN4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=HVX5Q0UIpgXL4HPJQ2znaznYJtCGyL9PiNJti1XbW8I=; b=KMfxNdHs bvcVmSXtnO1tmA5Az2VlrByFuwQSE5uRX/C1oe+V3rob4n7bZBJlTGAKJNXddBo8 47FFC1PANLizUowD8RWpopvt2kEtjc8a4riPR3kFSzZm2xKxWgBBV3ttE2Zkp0wd g3TeVBNAxVP7Q2xpRPkm3u2umfALa2RTGrc4q3GcisCZwjWOYA+OHvqkOcOMLytZ 77FPPnv/riNw99bEg28xcZM0xT5XSl8DYsdX9yXssUHRyi2vUJR3+PfknqGLaVk/ 4XI1wa5rMft3iJnpxNt2wGnmdsdXjySFEiGVXETPq4+r/BgOlLDYPQAFMFnqqL30 wdPRFMlqP7uO7w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddtuddgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc fkphepjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpeht hhhomhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgepud X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 089A8D6006A; Tue, 29 Oct 2019 14:51:00 -0400 (EDT) From: Thomas Monjalon To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Tue, 29 Oct 2019 19:50:49 +0100 Message-Id: <20191029185051.32203-2-thomas@monjalon.net> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191029185051.32203-1-thomas@monjalon.net> References: <4165509.5enYigmRGf@xps> <20191029185051.32203-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/3] ethdev: identify SR-IOV VF from host X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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