From patchwork Tue Oct 29 18:50:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 62176 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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 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; From patchwork Tue Oct 29 18:50:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 62177 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B3467A00BE; Tue, 29 Oct 2019 19:51:21 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D708D1BFAC; Tue, 29 Oct 2019 19:51:11 +0100 (CET) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 06BA01BFAA for ; Tue, 29 Oct 2019 19:51:10 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 790AA20D2B; Tue, 29 Oct 2019 14:51:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 29 Oct 2019 14:51:09 -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=flzSd38kca 61I2uCe+eACpu9XGpzqS6lnjyWN31WCNY=; b=YTqREDVPYD67nOHvFHc7Kr6P8T R2SitxwyYs1o+8IEz+BJE58/JzBlaNasrwaonDw8O/kyb/AbwWIRKqYJxvXxvw0a ZA0kgje0f9ZQqH/X7sPNpOJYW1bhRkMbb8bdyfP5TBYLfj1YW28J3ipQw3HqaHnf mwBzgFYFamLVWggfk= 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=flzSd38kca61I2uCe+eACpu9XGpzqS6lnjyWN31WCNY=; b=tChL9qhI kCiPje+RZQ027Sg2jutpBP88ariuBsWOMSn9UZPMXbkH/wyz7i+d2g3aANj0uP/B PgXRpgmSxGmkTL5y28j/CjqJGUPBHu4Y2t8rRWMfNzgc7mZpSAo5JubmI7geFdxG YCkESn0rBvvrm7Q74zGXvLEl6thbnQ0LhZmF5At9vhPzwhTrpYprU8c2VVh7askb lfsW7vUyV3ve7JqFQisAplfLoatt7eYOVqvV7GG6axBar9aSuXtRUS/gKInkuezB P0TjyqTfyDuUETTBHi3ddVB8fHC3dPSOmjA0cmH472y9vWRVPOh9kEXjXBmASFT8 sSF9oH1b2uAEGA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddtuddgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc fkphepjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpeht hhhomhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgepvd 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 BD6DED60065; Tue, 29 Oct 2019 14:51:08 -0400 (EDT) From: Thomas Monjalon To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Tue, 29 Oct 2019 19:50:50 +0100 Message-Id: <20191029185051.32203-3-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 Subject: [dpdk-dev] [PATCH v2 2/3] ethdev: set VF MAC address 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" The API to set a default MAC address is extended to support a VF ID as port ID. In order to be supported by a driver, the related vf_ops must be implemented. Signed-off-by: Thomas Monjalon --- lib/librte_ethdev/rte_ethdev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index fb3da4dcc3..9cf82ff10b 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -3386,20 +3386,23 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + bool vf; /* true if port_id targets a connected VF */ int ret; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + RTE_ETH_VALID_ID_OR_ERR_RET(port_id, -ENODEV); if (!rte_is_valid_assigned_ether_addr(addr)) return -EINVAL; + port_id = port_id_parse(port_id, &vf); dev = &rte_eth_devices[port_id]; - RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP); - - ret = (*dev->dev_ops->mac_addr_set)(dev, addr); + ret = ETH_DEV_OP_CALL(dev, vf, mac_addr_set, addr); if (ret < 0) return ret; + if (vf) + return 0; + /* Update default address in NIC data structure */ rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); From patchwork Tue Oct 29 18:50:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 62178 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EC741A00BE; Tue, 29 Oct 2019 19:51:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D0B351BFB8; Tue, 29 Oct 2019 19:51:15 +0100 (CET) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 15E491BFB5 for ; Tue, 29 Oct 2019 19:51:14 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B049D20D2B; Tue, 29 Oct 2019 14:51:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 29 Oct 2019 14:51:13 -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=tT5rfB5Lod IUP3znJmWrUJxUFMWSINKfc2yZApapFDI=; b=Q5tY8Tf2nFSB1ajv0PNGS1+svN 2vGP91ekFrzEUOVm+eLeY7PcjCdQSKCFiurUTNG1M3cEpRtNfZFqueY1liyLih0T IhTFH1tV9UElUXJEcioA+ZVi6/P8H9kU3zH0gE5aReEo8WWynev15OEF+DmprQFj e3RY7ISMDtkmqg6eo= 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=tT5rfB5LodIUP3znJmWrUJxUFMWSINKfc2yZApapFDI=; b=qRFN4ftC aZCI+jjcFSiVbRQwKNQ53GYdwMSKNDQfPpgLldl5wjBRoOewlXLJrDXTVZ87+Xgu j5DvaxVDmw31ZiGmOdPoCpJcCBSB5nPanh7Y6x6gwU7G23RpFO/DPke0LqidHbAB YIeSd7vrHQSil9VR9HnIEZiPpNj4lokiC4mOkwemRDcFc/VqzQIvA2PfJzT34+Jh vR+cc1hW3F8Uf8fCJkZQMx2lMb0dg9Ms3E0CsaHJrQLp/WHcMNw0xcbzF0QK8Q+s D5eUFXARxcFc4GJw2FS6QvIqWIeGERUYJUo7JXO7vrmvjjYEUVsHIYuRoeG63+h+ xtREH54cbzxZDQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddtuddgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc fkphepjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpeht hhhomhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgepfe 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 DD7B3D6006B; Tue, 29 Oct 2019 14:51:12 -0400 (EDT) From: Thomas Monjalon To: Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko Cc: dev@dpdk.org Date: Tue, 29 Oct 2019 19:50:51 +0100 Message-Id: <20191029185051.32203-4-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 Subject: [dpdk-dev] [PATCH v2 3/3] net/mlx5: set VF MAC address 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" Allow to configure the default MAC address of a VF via its representor port in the host. This patch is a stub to demonstrate how to implement a VF operation. The real code is not implemented. Signed-off-by: Thomas Monjalon --- drivers/net/mlx5/mlx5.c | 6 ++++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_mac.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index fac510507d..b679b5e299 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1073,6 +1073,11 @@ const struct eth_dev_ops mlx5_dev_ops_isolate = { .get_module_eeprom = mlx5_get_module_eeprom, }; +/* Available operations for VF connected to a representor. */ +const struct eth_dev_ops mlx5_remote_vf_ops = { + .mac_addr_set = mlx5_vf_mac_addr_set, +}; + /** * Verify and store value for device argument. * @@ -2130,6 +2135,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, eth_dev->rx_pkt_burst = removed_rx_burst; eth_dev->tx_pkt_burst = removed_tx_burst; eth_dev->dev_ops = &mlx5_dev_ops; + eth_dev->vf_ops = &mlx5_remote_vf_ops; /* Register MAC address. */ claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); if (config.vf && config.vf_nl_en) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index b6a51b2b4d..e34a24ee7c 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -754,6 +754,7 @@ void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index, uint32_t vmdq); int mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr); +int mlx5_vf_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac); int mlx5_set_mc_addr_list(struct rte_eth_dev *dev, struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr); diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c index 0ffef5c5db..4c4dd55b86 100644 --- a/drivers/net/mlx5/mlx5_mac.c +++ b/drivers/net/mlx5/mlx5_mac.c @@ -202,6 +202,25 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) return mlx5_mac_addr_add(dev, mac_addr, 0, 0); } +/** + * DPDK callback to set primary MAC address of the remote VF. + * + * @param dev + * Pointer to Ethernet device structure of a representor. + * @param mac_addr + * MAC address to register in the remote VF. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int mlx5_vf_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac) +{ + DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address", + dev->data->port_id); + /* TODO: should not be this dev but its VF */ + return mlx5_nl_mac_addr_add(dev, mac, 0); +} + /** * DPDK callback to set multicast addresses list. *