From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 490794573B; Mon, 5 Aug 2024 04:14:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C196C40653; Mon, 5 Aug 2024 04:13:24 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2131.outbound.protection.outlook.com [40.107.237.131]) by mails.dpdk.org (Postfix) with ESMTP id 95B5B40649 for ; Mon, 5 Aug 2024 04:13:23 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j/IV/PFaA0jD59GLuVZo70BsyFloKWbMxPwBiWCw42/wchGNzWLlx6r9vu+aL2eTNQB1WR5GFKkHYdaUBwyrEa/tNwxZbS6E50nZQ80hrtIfEc4KpNqemdF4svP3rWscxjR7gIx4cXqx0tmxCpSIPtKw0UlmrvxjbrSrrFwn+j9Zk7uMuAnblvao+blRxmeTw4ZgwioG2KmnZ4qoP8wjwjHZAWS4w0SlWdOgCPPy7Htrd0bdAHcRZPsXm8K7TDsujFaA0rd/Fh2ALQFjGBj93b4ATdV0taoOL7TpE62c1qMW2iXFLWRrrR3vWXl9/kDOhpa3jM1q/K+yLvTS8VhMtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vo6q78X8KcyEfPsGR+pOb4DulEzjW5jJAJ67/zZlXZs=; b=U8LWn1LUXB0tQ5Zpr/brGa0vfqyAkq6B/TcOegRTZ0ZtuPsEP4rQLMd2XuabdNhsGxt6bneU3/+kDiZusYweKsvNjhEG+gAtK4t9K9sAUwZDJ5GZ0gWM74e05suAo7ZfNRD306z44A2dTjzJS2CNGLs9vNbyOomlgFFjZDLHq9wOwmeW47+4+jn81VSaivO2oXS1uqMoQEL329DoPbZVlBEPyiCVqSGBwOqW/+G9jwlX/QiB62+pTepza1s/5kmW1k0thdpbpkFM2jyJyltZcELtgCDNBGxlxBWkgjDSm5FnFA12gWkUixO/5nR7zV0zA85jk0Mei1U9KGX9YQudPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vo6q78X8KcyEfPsGR+pOb4DulEzjW5jJAJ67/zZlXZs=; b=XREJsv1HQCiq2gRR2AkLZMlEsQTJzDyNHR2UiQY7DB2nf9qsl2e33D5qfqLEQwmSLmq95/QdUgjQ53hLRK9+/w40aIQN6V7VFMoKnq1KzoG3DyCYOSlnnmb2jVWNe4kcr4T054NhKErPreiivfFnnmNKmhlh7V1yJJ8jy/Wp3ZU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by SJ0PR13MB5896.namprd13.prod.outlook.com (2603:10b6:a03:43a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.25; Mon, 5 Aug 2024 02:13:22 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833%4]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 02:13:22 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Xinying Yu , Chaoyong He , Long Wu , Peng Zhang , Maxime Coquelin Subject: [PATCH v4 07/11] vdpa/nfp: setup the VF configure Date: Mon, 5 Aug 2024 10:12:44 +0800 Message-Id: <20240805021248.1051198-8-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240805021248.1051198-1-chaoyong.he@corigine.com> References: <20240617062708.2932037-1-chaoyong.he@corigine.com> <20240805021248.1051198-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BYAPR01CA0050.prod.exchangelabs.com (2603:10b6:a03:94::27) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|SJ0PR13MB5896:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b68c4f8-df94-4851-3a41-08dcb4f42e12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/H419ey6Y3k8cwNbg4Fo7Fh7C+CpqcL/FibUnnDAAyx/ll03TXrSDZAD2YpI?= =?us-ascii?Q?ZQe39kNK99LqcdZ/TvEfaWC3bvXPC0lei/d3urXcmYp7FDtwXPyuR0M83TEa?= =?us-ascii?Q?sRFmc+EJ4o3eAIaY/VSXiqggL1Bop7kmqs/z0iE9G/dkYRiFZ/O5tu7nnlB1?= =?us-ascii?Q?YkhII8Mrdd6syTvZuExuQain8qCzK/i9uwcD+88eUpyQTnaxG+TfwJnHSDAF?= =?us-ascii?Q?qZt8xd4Mg4Zz4EFRMB8h7IFZtCwM8YauxjBudZAXhJn4elZFHP8F228OpIpw?= =?us-ascii?Q?y001etyMfEH37AmC9WWMW66g1iEzZOk4YCxcslemmTSDvuOiAmiZq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BeYlMAn0Kon+d5ef3hv9rda5p6Jq/Bc+H?= =?us-ascii?Q?QtFlHCmOlD6zWm3tm38t4/6xi/YMIKQeLcP9vMD+VzOiusl59+AKLCV3H8eS?= =?us-ascii?Q?N/OvL3jZQlWW3xZ/eEnaQGJnpLvgwYBvZf6FaJwyqfuiZPQkw+tmRwUQeusX?= =?us-ascii?Q?gS7lN8/gLYEZyeTiznz8Txcjy4wRyqcDjH7ZSSDiB7KWr9YfSw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jZ5onqbFrb7dGfRf8otPziYC2HOnC2H21MNckIgDGIlxxA8RicM6NJgUPWfe?= =?us-ascii?Q?GQ+Gu/SRTDSskG8M8Ya/RpL1kbGT7WJ/lb+FQ7kEVzOuME/ovFiTjFWttY+R?= =?us-ascii?Q?900n9OQj8Pv2IIvFI4qWDK8JF1I5ebdvKRMoxD7s1CWjH+wsRKUI+lQPqYMw?= =?us-ascii?Q?lTU6F4fH8/7ES04sUSoBQmTTXbNWH+pxqCfqko35xc6afW7xQ1bGtMN7X7Kw?= =?us-ascii?Q?kP5DsGImXwP+noyk8Yl59bTXdLjnDPErKBe/JJsCWenLaXrM9H0QFdxq+wdX?= =?us-ascii?Q?wzxMUT53Es8tGRat/t4W5HX5g1/QNU/S2e49RDkvXHb2DOLJgYr7l2Wq/34K?= =?us-ascii?Q?TOlrvKwWDiK9zt3Qz55H+JnLbouDYlIoJGuU3bLFL2tYad7c+Ck8IN/2/26M?= =?us-ascii?Q?AnvIGCm1/4c4ELKLEiYF+CZz3qelqNolOXxOHNQZUvO9YnVHwod2VUf1gqC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msvRW3el/dBuEvl3Xw96TiKgKdNK?= =?us-ascii?Q?OyYoBIkUx6Hk1/LVJ0K6xFxVmegk2vfl3DXbHxDpC5YS6M8eW0znB+wZAvg7?= =?us-ascii?Q?F68Fr3/DW0VHtmZVQkJJr2K33vc/V4KmFk4W6JfT3QZFZ+aR6VmlgD2f1Xwf?= =?us-ascii?Q?xFzkqC+lcyE9VpYKrXaJxbD9iw19nCgkMv7XSZf4duje2gAiSVwHOpeU2if9?= =?us-ascii?Q?oxjntnk17LkXH0i5fjbmSGhk3UBsp0qmCSjeQkYc94hGdFhCtRAy7HVl9ivl?= =?us-ascii?Q?Cg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b68c4f8-df94-4851-3a41-08dcb4f42e12 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 02:13:22.0423 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l/GkOpWoHbsTXW2uuXeLlUaVsL3IoSEOCHFPmcMjp/wjsrR9watBeRV9z4D3g43haJsiIXmzRVNm0DzaXYwo2rKs4jV5cbMvCeFlVEQmxzw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR13MB5896 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Xinying Yu Create the relay vring on host and then set the address of Rx used ring to the VF config bar. So the device can DMA the used ring information to host rather than directly to VM. Use 'NFP_NET_CFG_CTRL_LM_RELAY' notify the device side. And enable the MSIX interrupt on device. Tx ring address is not needed to change since the relay vring only assists Rx ring to do the dirty page logging. Signed-off-by: Xinying Yu Reviewed-by: Chaoyong He Reviewed-by: Long Wu Reviewed-by: Peng Zhang Reviewed-by: Maxime Coquelin --- drivers/common/nfp/nfp_common_ctrl.h | 3 + drivers/vdpa/nfp/nfp_vdpa.c | 203 ++++++++++++++++++++++++--- drivers/vdpa/nfp/nfp_vdpa_core.c | 55 ++++++-- drivers/vdpa/nfp/nfp_vdpa_core.h | 8 ++ 4 files changed, 239 insertions(+), 30 deletions(-) diff --git a/drivers/common/nfp/nfp_common_ctrl.h b/drivers/common/nfp/nfp_common_ctrl.h index 1b30f81fdb..8a760ddb4b 100644 --- a/drivers/common/nfp/nfp_common_ctrl.h +++ b/drivers/common/nfp/nfp_common_ctrl.h @@ -207,6 +207,9 @@ struct nfp_net_fw_ver { #define NFP_NET_CFG_CTRL_FLOW_STEER (0x1 << 8) /**< Flow Steering */ #define NFP_NET_CFG_CTRL_VIRTIO (0x1 << 10) /**< Virtio offload */ #define NFP_NET_CFG_CTRL_IN_ORDER (0x1 << 11) /**< Virtio in-order flag */ +#define NFP_NET_CFG_CTRL_LM_RELAY (0x1 << 12) /**< Virtio live migration relay start */ +#define NFP_NET_CFG_CTRL_NOTIFY_DATA (0x1 << 13) /**< Virtio notification data flag */ +#define NFP_NET_CFG_CTRL_SWLM (0x1 << 14) /**< Virtio SW live migration enable */ #define NFP_NET_CFG_CTRL_USO (0x1 << 16) /**< UDP segmentation offload */ #define NFP_NET_CFG_CAP_WORD1 0x00a4 diff --git a/drivers/vdpa/nfp/nfp_vdpa.c b/drivers/vdpa/nfp/nfp_vdpa.c index 1643ebbb8c..983123ba08 100644 --- a/drivers/vdpa/nfp/nfp_vdpa.c +++ b/drivers/vdpa/nfp/nfp_vdpa.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include "nfp_vdpa_core.h" @@ -21,6 +23,9 @@ #define MSIX_IRQ_SET_BUF_LEN (sizeof(struct vfio_irq_set) + \ sizeof(int) * (NFP_VDPA_MAX_QUEUES * 2 + 1)) +#define NFP_VDPA_USED_RING_LEN(size) \ + ((size) * sizeof(struct vring_used_elem) + sizeof(struct vring_used)) + struct nfp_vdpa_dev { struct rte_pci_device *pci_dev; struct rte_vdpa_device *vdev; @@ -261,15 +266,85 @@ nfp_vdpa_qva_to_gpa(int vid, return gpa; } +static void +nfp_vdpa_relay_vring_free(struct nfp_vdpa_dev *device, + uint16_t vring_index) +{ + uint16_t i; + uint64_t size; + struct rte_vhost_vring vring; + uint64_t m_vring_iova = NFP_VDPA_RELAY_VRING; + + for (i = 0; i < vring_index; i++) { + rte_vhost_get_vhost_vring(device->vid, i, &vring); + + size = RTE_ALIGN_CEIL(vring_size(vring.size, rte_mem_page_size()), + rte_mem_page_size()); + rte_vfio_container_dma_unmap(device->vfio_container_fd, + (uint64_t)(uintptr_t)device->hw.m_vring[i].desc, + m_vring_iova, size); + + rte_free(device->hw.m_vring[i].desc); + m_vring_iova += size; + } +} + static int -nfp_vdpa_start(struct nfp_vdpa_dev *device) +nfp_vdpa_relay_vring_alloc(struct nfp_vdpa_dev *device) +{ + int ret; + uint16_t i; + uint64_t size; + void *vring_buf; + uint64_t page_size; + struct rte_vhost_vring vring; + struct nfp_vdpa_hw *vdpa_hw = &device->hw; + uint64_t m_vring_iova = NFP_VDPA_RELAY_VRING; + + page_size = rte_mem_page_size(); + + for (i = 0; i < vdpa_hw->nr_vring; i++) { + rte_vhost_get_vhost_vring(device->vid, i, &vring); + + size = RTE_ALIGN_CEIL(vring_size(vring.size, page_size), page_size); + vring_buf = rte_zmalloc("nfp_vdpa_relay", size, page_size); + if (vring_buf == NULL) + goto vring_free_all; + + vring_init(&vdpa_hw->m_vring[i], vring.size, vring_buf, page_size); + + ret = rte_vfio_container_dma_map(device->vfio_container_fd, + (uint64_t)(uintptr_t)vring_buf, m_vring_iova, size); + if (ret != 0) { + DRV_VDPA_LOG(ERR, "vDPA vring relay dma map failed."); + goto vring_free_one; + } + + m_vring_iova += size; + } + + return 0; + +vring_free_one: + rte_free(device->hw.m_vring[i].desc); +vring_free_all: + nfp_vdpa_relay_vring_free(device, i); + + return -ENOSPC; +} + +static int +nfp_vdpa_start(struct nfp_vdpa_dev *device, + bool relay) { int ret; int vid; uint16_t i; uint64_t gpa; + uint16_t size; struct rte_vhost_vring vring; struct nfp_vdpa_hw *vdpa_hw = &device->hw; + uint64_t m_vring_iova = NFP_VDPA_RELAY_VRING; vid = device->vid; vdpa_hw->nr_vring = rte_vhost_get_vring_num(vid); @@ -278,15 +353,21 @@ nfp_vdpa_start(struct nfp_vdpa_dev *device) if (ret != 0) return ret; + if (relay) { + ret = nfp_vdpa_relay_vring_alloc(device); + if (ret != 0) + return ret; + } + for (i = 0; i < vdpa_hw->nr_vring; i++) { ret = rte_vhost_get_vhost_vring(vid, i, &vring); if (ret != 0) - return ret; + goto relay_vring_free; gpa = nfp_vdpa_qva_to_gpa(vid, (uint64_t)(uintptr_t)vring.desc); if (gpa == 0) { DRV_VDPA_LOG(ERR, "Fail to get GPA for descriptor ring."); - return -1; + goto relay_vring_free; } vdpa_hw->vring[i].desc = gpa; @@ -294,45 +375,123 @@ nfp_vdpa_start(struct nfp_vdpa_dev *device) gpa = nfp_vdpa_qva_to_gpa(vid, (uint64_t)(uintptr_t)vring.avail); if (gpa == 0) { DRV_VDPA_LOG(ERR, "Fail to get GPA for available ring."); - return -1; + goto relay_vring_free; } vdpa_hw->vring[i].avail = gpa; - gpa = nfp_vdpa_qva_to_gpa(vid, (uint64_t)(uintptr_t)vring.used); - if (gpa == 0) { - DRV_VDPA_LOG(ERR, "Fail to get GPA for used ring."); - return -1; - } + /* Direct I/O for Tx queue, relay for Rx queue */ + if (relay && ((i & 1) == 0)) { + vdpa_hw->vring[i].used = m_vring_iova + + (char *)vdpa_hw->m_vring[i].used - + (char *)vdpa_hw->m_vring[i].desc; + + ret = rte_vhost_get_vring_base(vid, i, + &vdpa_hw->m_vring[i].avail->idx, + &vdpa_hw->m_vring[i].used->idx); + if (ret != 0) + goto relay_vring_free; + } else { + gpa = nfp_vdpa_qva_to_gpa(vid, (uint64_t)(uintptr_t)vring.used); + if (gpa == 0) { + DRV_VDPA_LOG(ERR, "Fail to get GPA for used ring."); + goto relay_vring_free; + } - vdpa_hw->vring[i].used = gpa; + vdpa_hw->vring[i].used = gpa; + } vdpa_hw->vring[i].size = vring.size; + if (relay) { + size = RTE_ALIGN_CEIL(vring_size(vring.size, + rte_mem_page_size()), rte_mem_page_size()); + m_vring_iova += size; + } + ret = rte_vhost_get_vring_base(vid, i, &vdpa_hw->vring[i].last_avail_idx, &vdpa_hw->vring[i].last_used_idx); if (ret != 0) - return ret; + goto relay_vring_free; } - return nfp_vdpa_hw_start(&device->hw, vid); + if (relay) + return nfp_vdpa_relay_hw_start(&device->hw, vid); + else + return nfp_vdpa_hw_start(&device->hw, vid); + +relay_vring_free: + if (relay) + nfp_vdpa_relay_vring_free(device, vdpa_hw->nr_vring); + + return -EFAULT; +} + +static void +nfp_vdpa_update_used_ring(struct nfp_vdpa_dev *dev, + uint16_t qid) +{ + rte_vdpa_relay_vring_used(dev->vid, qid, &dev->hw.m_vring[qid]); + rte_vhost_vring_call(dev->vid, qid); } static void -nfp_vdpa_stop(struct nfp_vdpa_dev *device) +nfp_vdpa_relay_stop(struct nfp_vdpa_dev *device) { int vid; uint32_t i; + uint64_t len; + struct rte_vhost_vring vring; struct nfp_vdpa_hw *vdpa_hw = &device->hw; nfp_vdpa_hw_stop(vdpa_hw); vid = device->vid; - for (i = 0; i < vdpa_hw->nr_vring; i++) + for (i = 0; i < vdpa_hw->nr_vring; i++) { + /* Synchronize remaining new used entries if any */ + if ((i & 1) == 0) + nfp_vdpa_update_used_ring(device, i); + + rte_vhost_get_vhost_vring(vid, i, &vring); + len = NFP_VDPA_USED_RING_LEN(vring.size); + vdpa_hw->vring[i].last_avail_idx = vring.avail->idx; + vdpa_hw->vring[i].last_used_idx = vring.used->idx; + rte_vhost_set_vring_base(vid, i, vdpa_hw->vring[i].last_avail_idx, vdpa_hw->vring[i].last_used_idx); + + rte_vhost_log_used_vring(vid, i, 0, len); + + if (vring.used->idx != vring.avail->idx) + rte_atomic_store_explicit( + (unsigned short __rte_atomic *)&vring.used->idx, + vring.avail->idx, rte_memory_order_release); + } + + nfp_vdpa_relay_vring_free(device, vdpa_hw->nr_vring); +} + +static void +nfp_vdpa_stop(struct nfp_vdpa_dev *device, + bool relay) +{ + int vid; + uint32_t i; + struct nfp_vdpa_hw *vdpa_hw = &device->hw; + + nfp_vdpa_hw_stop(vdpa_hw); + + vid = device->vid; + if (relay) + nfp_vdpa_relay_stop(device); + else + for (i = 0; i < vdpa_hw->nr_vring; i++) + rte_vhost_set_vring_base(vid, i, + vdpa_hw->vring[i].last_avail_idx, + vdpa_hw->vring[i].last_used_idx); + } static int @@ -575,7 +734,7 @@ update_datapath(struct nfp_vdpa_dev *device) if (ret != 0) goto dma_map_rollback; - ret = nfp_vdpa_start(device); + ret = nfp_vdpa_start(device, false); if (ret != 0) goto disable_vfio_intr; @@ -591,7 +750,7 @@ update_datapath(struct nfp_vdpa_dev *device) rte_memory_order_relaxed) != 0))) { nfp_vdpa_unset_notify_relay(device); - nfp_vdpa_stop(device); + nfp_vdpa_stop(device, false); ret = nfp_vdpa_disable_vfio_intr(device); if (ret != 0) @@ -608,7 +767,7 @@ update_datapath(struct nfp_vdpa_dev *device) return 0; vdpa_stop: - nfp_vdpa_stop(device); + nfp_vdpa_stop(device, false); disable_vfio_intr: nfp_vdpa_disable_vfio_intr(device); dma_map_rollback: @@ -639,10 +798,17 @@ nfp_vdpa_sw_fallback(struct nfp_vdpa_dev *device) if (ret != 0) goto error; + /* Config the VF */ + ret = nfp_vdpa_start(device, true); + if (ret != 0) + goto unset_intr; + device->hw.sw_fallback_running = true; return 0; +unset_intr: + nfp_vdpa_disable_vfio_intr(device); error: return ret; } @@ -691,6 +857,9 @@ nfp_vdpa_dev_close(int vid) device = node->device; if (device->hw.sw_fallback_running) { + /* Reset VF */ + nfp_vdpa_stop(device, true); + device->hw.sw_fallback_running = false; rte_atomic_store_explicit(&device->dev_attached, 0, diff --git a/drivers/vdpa/nfp/nfp_vdpa_core.c b/drivers/vdpa/nfp/nfp_vdpa_core.c index 50eda4cb2c..2b609dddc2 100644 --- a/drivers/vdpa/nfp/nfp_vdpa_core.c +++ b/drivers/vdpa/nfp/nfp_vdpa_core.c @@ -109,7 +109,8 @@ nfp_vdpa_check_offloads(void) static int nfp_vdpa_vf_config(struct nfp_hw *hw, - int vid) + int vid, + bool relay) { int ret; uint32_t update; @@ -133,6 +134,10 @@ nfp_vdpa_vf_config(struct nfp_hw *hw, nfp_write_mac(hw, (uint8_t *)mac_addr); new_ext_ctrl = nfp_vdpa_check_offloads(); + if (relay) + new_ext_ctrl |= NFP_NET_CFG_CTRL_LM_RELAY; + else + new_ext_ctrl |= NFP_NET_CFG_CTRL_SWLM; update = NFP_NET_CFG_UPDATE_GEN; ret = nfp_ext_reconfig(hw, new_ext_ctrl, update); @@ -149,6 +154,15 @@ nfp_vdpa_vf_config(struct nfp_hw *hw, NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING; + if (relay) { + update |= NFP_NET_CFG_UPDATE_MSIX; + + /* Enable misx interrupt for vdpa relay */ + new_ctrl |= NFP_NET_CFG_CTRL_MSIX_TX_OFF; + + nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(0), 1); + } + ret = nfp_reconfig(hw, new_ctrl, update); if (ret < 0) return -EIO; @@ -164,20 +178,24 @@ nfp_vdpa_vf_config(struct nfp_hw *hw, } static void -nfp_vdpa_queue_config(struct nfp_vdpa_hw *vdpa_hw) +nfp_vdpa_queue_config(struct nfp_vdpa_hw *vdpa_hw, + bool relay) { struct nfp_hw *hw = &vdpa_hw->super; - nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(0), vdpa_hw->vring[1].desc); - nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(0), - rte_log2_u32(vdpa_hw->vring[1].size)); - nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(1), vdpa_hw->vring[1].avail); - nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(2), vdpa_hw->vring[1].used); + if (!relay) { + nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(0), vdpa_hw->vring[1].desc); + nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(0), + rte_log2_u32(vdpa_hw->vring[1].size)); + nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(1), vdpa_hw->vring[1].avail); + nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(2), vdpa_hw->vring[1].used); + + nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(0), vdpa_hw->vring[0].desc); + nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(0), + rte_log2_u32(vdpa_hw->vring[0].size)); + nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(1), vdpa_hw->vring[0].avail); + } - nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(0), vdpa_hw->vring[0].desc); - nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(0), - rte_log2_u32(vdpa_hw->vring[0].size)); - nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(1), vdpa_hw->vring[0].avail); nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(2), vdpa_hw->vring[0].used); rte_wmb(); @@ -189,12 +207,23 @@ nfp_vdpa_hw_start(struct nfp_vdpa_hw *vdpa_hw, { struct nfp_hw *hw = &vdpa_hw->super; - nfp_vdpa_queue_config(vdpa_hw); + nfp_vdpa_queue_config(vdpa_hw, false); nfp_disable_queues(hw); nfp_enable_queues(hw, NFP_VDPA_MAX_QUEUES, NFP_VDPA_MAX_QUEUES); - return nfp_vdpa_vf_config(hw, vid); + return nfp_vdpa_vf_config(hw, vid, false); +} + +int +nfp_vdpa_relay_hw_start(struct nfp_vdpa_hw *vdpa_hw, + int vid) +{ + struct nfp_hw *hw = &vdpa_hw->super; + + nfp_vdpa_queue_config(vdpa_hw, true); + + return nfp_vdpa_vf_config(hw, vid, true); } void diff --git a/drivers/vdpa/nfp/nfp_vdpa_core.h b/drivers/vdpa/nfp/nfp_vdpa_core.h index 0f880fc0c6..a339ace601 100644 --- a/drivers/vdpa/nfp/nfp_vdpa_core.h +++ b/drivers/vdpa/nfp/nfp_vdpa_core.h @@ -9,12 +9,15 @@ #include #include #include +#include #define NFP_VDPA_MAX_QUEUES 1 #define NFP_VDPA_NOTIFY_ADDR_BASE 0x4000 #define NFP_VDPA_NOTIFY_ADDR_INTERVAL 0x1000 +#define NFP_VDPA_RELAY_VRING 0xd0000000 + struct nfp_vdpa_vring { uint64_t desc; uint64_t avail; @@ -40,12 +43,17 @@ struct nfp_vdpa_hw { /** Software Live Migration */ bool sw_lm; bool sw_fallback_running; + + /** Mediated vring for SW fallback */ + struct vring m_vring[NFP_VDPA_MAX_QUEUES * 2]; }; int nfp_vdpa_hw_init(struct nfp_vdpa_hw *vdpa_hw, struct rte_pci_device *dev); int nfp_vdpa_hw_start(struct nfp_vdpa_hw *vdpa_hw, int vid); +int nfp_vdpa_relay_hw_start(struct nfp_vdpa_hw *vdpa_hw, int vid); + void nfp_vdpa_hw_stop(struct nfp_vdpa_hw *vdpa_hw); void nfp_vdpa_notify_queue(struct nfp_vdpa_hw *vdpa_hw, uint16_t qid); -- 2.39.1