Add the hardware initialize logic.
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Signed-off-by: Shujing Dong <shujing.dong@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/vdpa/nfp/meson.build | 1 +
drivers/vdpa/nfp/nfp_vdpa.c | 10 ++++++
drivers/vdpa/nfp/nfp_vdpa_core.c | 54 ++++++++++++++++++++++++++++++++
drivers/vdpa/nfp/nfp_vdpa_core.h | 32 +++++++++++++++++++
4 files changed, 97 insertions(+)
create mode 100644 drivers/vdpa/nfp/nfp_vdpa_core.c
create mode 100644 drivers/vdpa/nfp/nfp_vdpa_core.h
@@ -8,6 +8,7 @@ endif
sources = files(
'nfp_vdpa.c',
+ 'nfp_vdpa_core.c',
'nfp_vdpa_log.c',
)
@@ -10,6 +10,7 @@
#include <rte_vfio.h>
#include <vdpa_driver.h>
+#include "nfp_vdpa_core.h"
#include "nfp_vdpa_log.h"
#define NFP_VDPA_DRIVER_NAME nfp_vdpa
@@ -17,11 +18,14 @@
struct nfp_vdpa_dev {
struct rte_pci_device *pci_dev;
struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_hw hw;
int vfio_container_fd;
int vfio_group_fd;
int vfio_dev_fd;
int iommu_group;
+
+ uint16_t max_queues;
};
struct nfp_vdpa_dev_node {
@@ -135,6 +139,12 @@ nfp_vdpa_pci_probe(struct rte_pci_device *pci_dev)
if (ret != 0)
goto free_device;
+ ret = nfp_vdpa_hw_init(&device->hw, pci_dev);
+ if (ret != 0)
+ goto vfio_teardown;
+
+ device->max_queues = NFP_VDPA_MAX_QUEUES;
+
device->vdev = rte_vdpa_register_device(&pci_dev->device, &nfp_vdpa_ops);
if (device->vdev == NULL) {
DRV_VDPA_LOG(ERR, "Failed to register device %s", pci_dev->name);
new file mode 100644
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Corigine, Inc.
+ * All rights reserved.
+ */
+
+#include "nfp_vdpa_core.h"
+
+#include <rte_vhost.h>
+
+#include "nfp_vdpa_log.h"
+
+/* Available and used descs are in same order */
+#ifndef VIRTIO_F_IN_ORDER
+#define VIRTIO_F_IN_ORDER 35
+#endif
+
+int
+nfp_vdpa_hw_init(struct nfp_vdpa_hw *vdpa_hw,
+ struct rte_pci_device *pci_dev)
+{
+ uint32_t queue;
+ struct nfp_hw *hw;
+ uint8_t *notify_base;
+
+ hw = &vdpa_hw->super;
+ hw->ctrl_bar = pci_dev->mem_resource[0].addr;
+ if (hw->ctrl_bar == NULL) {
+ DRV_CORE_LOG(ERR, "hw->ctrl_bar is NULL. BAR0 not configured.");
+ return -ENODEV;
+ }
+
+ notify_base = hw->ctrl_bar + NFP_VDPA_NOTIFY_ADDR_BASE;
+ for (queue = 0; queue < NFP_VDPA_MAX_QUEUES; queue++) {
+ uint32_t idx = queue * 2;
+
+ /* RX */
+ vdpa_hw->notify_addr[idx] = notify_base;
+ notify_base += NFP_VDPA_NOTIFY_ADDR_INTERVAL;
+ /* TX */
+ vdpa_hw->notify_addr[idx + 1] = notify_base;
+ notify_base += NFP_VDPA_NOTIFY_ADDR_INTERVAL;
+
+ vdpa_hw->notify_region = queue;
+ DRV_CORE_LOG(DEBUG, "notify_addr[%d] at %p, notify_addr[%d] at %p",
+ idx, vdpa_hw->notify_addr[idx],
+ idx + 1, vdpa_hw->notify_addr[idx + 1]);
+ }
+
+ vdpa_hw->features = (1ULL << VIRTIO_F_VERSION_1) |
+ (1ULL << VIRTIO_F_IN_ORDER) |
+ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Corigine, Inc.
+ * All rights reserved.
+ */
+
+#ifndef __NFP_VDPA_CORE_H__
+#define __NFP_VDPA_CORE_H__
+
+#include <bus_pci_driver.h>
+#include <nfp_common.h>
+#include <rte_ether.h>
+
+#define NFP_VDPA_MAX_QUEUES 1
+
+#define NFP_VDPA_NOTIFY_ADDR_BASE 0x4000
+#define NFP_VDPA_NOTIFY_ADDR_INTERVAL 0x1000
+
+struct nfp_vdpa_hw {
+ struct nfp_hw super;
+
+ uint64_t features;
+ uint64_t req_features;
+
+ uint8_t *notify_addr[NFP_VDPA_MAX_QUEUES * 2];
+
+ uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
+ uint8_t notify_region;
+};
+
+int nfp_vdpa_hw_init(struct nfp_vdpa_hw *vdpa_hw, struct rte_pci_device *dev);
+
+#endif /* __NFP_VDPA_CORE_H__ */