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 83618A04BA; Wed, 7 Oct 2020 19:20:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B1A211B9EB; Wed, 7 Oct 2020 19:19:21 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id B05CB1B7C0 for ; Wed, 7 Oct 2020 19:19:16 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id g10so1687048pfc.8 for ; Wed, 07 Oct 2020 10:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CgS8iWHVSrcWT14IwRXnVE+A5vHJfswXO8i4hjtcJ60=; b=bOBVlJ3YuWeN26Ixr5oGgHtQqid9JYQU4GbLQO/8J1YixTwiiNf7v/C2GQ60Ni4J6u uOU3rEk7UE7cqyDN6w5GYAjukQdtvqvM7dZf9A3TyzuYM3TWs5ND17WF6ggimIpzgrQc JwI6eWRiclbEhRC1mvPDbzqQMYLtrclyW3Kyg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CgS8iWHVSrcWT14IwRXnVE+A5vHJfswXO8i4hjtcJ60=; b=SvaZsFBuyN5tSviIJfD4haVaeU5MVUVweT5Twe7mpUAMeYeUPm4Xs3Ya2wyLc/wk6n zxljCNR8vByQbXtyKLSSAtxrnv/9gBu1hDCWus84WU4M//e3dsJ5Oku/ryeBlDYOlClZ 3WYF8qJvDJSKg2k2W92Ba59GC7AOWZxFxSnEasyEde5iNZPnA1LK1+TYzZNiKBKfalEw /mOemh9ck65nUwgX2/bXr6doGJNO5P4yxE/CYvotOidOPARLpYGiq86RoqLM50lIDeto GoXon9wYX7SlbnfFqc7VG8Y0VwomBTiCdbr51ynZ52ch0+Ui4aDa1EQKE1PEp13F3GVh mB4g== X-Gm-Message-State: AOAM532VHBXYObXmFVjvBzF2+6+QeLMUXjBrO5Pt+8U6PqvgLft0WJUh MZikYSvGyfmtlG9DuU3BpNBTnlQfXcHnIM4Br5AuZ6IVXCWe1SjshfFowhy+U03zhb31sF8yKgd qqjctCk+yMeTjDzC+F2iRzMLH9gGV2KL002nGGKl3QbozzaeJ4QO/pE+5lx3e X-Google-Smtp-Source: ABdhPJxbY/AIMqey5X5XcR3q1nlslBw2Xu+H5qmKFFgau1cy0x0rBPhYLcR92saTfI/YKq0xY/cHww== X-Received: by 2002:aa7:9f8d:0:b029:152:28de:812a with SMTP id z13-20020aa79f8d0000b029015228de812amr3905870pfr.65.1602091155337; Wed, 07 Oct 2020 10:19:15 -0700 (PDT) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t13sm3846367pfc.1.2020.10.07.10.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 10:19:14 -0700 (PDT) From: Vikas Gupta To: dev@dpdk.org, akhil.goyal@nxp.com Cc: vikram.prakash@broadcom.com, Vikas Gupta , Raveendra Padasalagi Date: Wed, 7 Oct 2020 22:48:54 +0530 Message-Id: <20201007171900.605-3-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007171900.605-1-vikas.gupta@broadcom.com> References: <20201007164539.45097-1-vikas.gupta@broadcom.com> <20201007171900.605-1-vikas.gupta@broadcom.com> Content-Type: text/plain X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] [PATCH v5 2/8] crypto/bcmfs: add vfio support 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" Add VFIO support for BCMFS PMD. The BCMFS PMD functionality is dependent on the VFIO_PRESENT flag, which gets enabled in the rte_vfio.h. If this flag is not enabled in the compiling platform driver will silently return with error, when executed. Signed-off-by: Vikas Gupta Signed-off-by: Raveendra Padasalagi Reviewed-by: Ajit Khaparde --- drivers/crypto/bcmfs/bcmfs_device.c | 5 ++ drivers/crypto/bcmfs/bcmfs_device.h | 6 ++ drivers/crypto/bcmfs/bcmfs_vfio.c | 107 ++++++++++++++++++++++++++++ drivers/crypto/bcmfs/bcmfs_vfio.h | 17 +++++ drivers/crypto/bcmfs/meson.build | 3 +- 5 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/bcmfs/bcmfs_vfio.c create mode 100644 drivers/crypto/bcmfs/bcmfs_vfio.h diff --git a/drivers/crypto/bcmfs/bcmfs_device.c b/drivers/crypto/bcmfs/bcmfs_device.c index f1050ff112..0ccddea202 100644 --- a/drivers/crypto/bcmfs/bcmfs_device.c +++ b/drivers/crypto/bcmfs/bcmfs_device.c @@ -12,6 +12,7 @@ #include "bcmfs_device.h" #include "bcmfs_logs.h" +#include "bcmfs_vfio.h" struct bcmfs_device_attr { const char name[BCMFS_MAX_PATH_LEN]; @@ -72,6 +73,10 @@ fsdev_allocate_one_dev(struct rte_vdev_device *vdev, fsdev->vdev = vdev; + /* attach to VFIO */ + if (bcmfs_attach_vfio(fsdev)) + goto cleanup; + TAILQ_INSERT_TAIL(&fsdev_list, fsdev, next); return fsdev; diff --git a/drivers/crypto/bcmfs/bcmfs_device.h b/drivers/crypto/bcmfs/bcmfs_device.h index 1a4d0cf365..f99d57d4bd 100644 --- a/drivers/crypto/bcmfs/bcmfs_device.h +++ b/drivers/crypto/bcmfs/bcmfs_device.h @@ -38,6 +38,12 @@ struct bcmfs_device { char name[BCMFS_DEV_NAME_LEN]; /* Parent vdev */ struct rte_vdev_device *vdev; + /* vfio handle */ + int vfio_dev_fd; + /* mapped address */ + uint8_t *mmap_addr; + /* mapped size */ + uint32_t mmap_size; }; #endif /* _BCMFS_DEVICE_H_ */ diff --git a/drivers/crypto/bcmfs/bcmfs_vfio.c b/drivers/crypto/bcmfs/bcmfs_vfio.c new file mode 100644 index 0000000000..dc2def580f --- /dev/null +++ b/drivers/crypto/bcmfs/bcmfs_vfio.c @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Broadcom. + * All rights reserved. + */ + +#include +#include +#include + +#include + +#include "bcmfs_device.h" +#include "bcmfs_logs.h" +#include "bcmfs_vfio.h" + +#ifdef VFIO_PRESENT +static int +vfio_map_dev_obj(const char *path, const char *dev_obj, + uint32_t *size, void **addr, int *dev_fd) +{ + int32_t ret; + struct vfio_group_status status = { .argsz = sizeof(status) }; + + struct vfio_device_info d_info = { .argsz = sizeof(d_info) }; + struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) }; + + ret = rte_vfio_setup_device(path, dev_obj, dev_fd, &d_info); + if (ret) { + BCMFS_LOG(ERR, "VFIO Setting for device failed"); + return ret; + } + + /* getting device region info*/ + ret = ioctl(*dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info); + if (ret < 0) { + BCMFS_LOG(ERR, "Error in VFIO getting REGION_INFO"); + goto map_failed; + } + + *addr = mmap(NULL, reg_info.size, + PROT_WRITE | PROT_READ, MAP_SHARED, + *dev_fd, reg_info.offset); + if (*addr == MAP_FAILED) { + BCMFS_LOG(ERR, "Error mapping region (errno = %d)", errno); + ret = errno; + goto map_failed; + } + *size = reg_info.size; + + return 0; + +map_failed: + rte_vfio_release_device(path, dev_obj, *dev_fd); + + return ret; +} + +int +bcmfs_attach_vfio(struct bcmfs_device *dev) +{ + int ret; + int vfio_dev_fd; + void *v_addr = NULL; + uint32_t size = 0; + + ret = vfio_map_dev_obj(dev->dirname, dev->name, + &size, &v_addr, &vfio_dev_fd); + if (ret) + return -1; + + dev->mmap_size = size; + dev->mmap_addr = v_addr; + dev->vfio_dev_fd = vfio_dev_fd; + + return 0; +} + +void +bcmfs_release_vfio(struct bcmfs_device *dev) +{ + int ret; + + if (dev == NULL) + return; + + /* unmap the addr */ + munmap(dev->mmap_addr, dev->mmap_size); + /* release the device */ + ret = rte_vfio_release_device(dev->dirname, dev->name, + dev->vfio_dev_fd); + if (ret < 0) { + BCMFS_LOG(ERR, "cannot release device"); + return; + } +} +#else +int +bcmfs_attach_vfio(struct bcmfs_device *dev __rte_unused) +{ + return -1; +} + +void +bcmfs_release_vfio(struct bcmfs_device *dev __rte_unused) +{ +} +#endif diff --git a/drivers/crypto/bcmfs/bcmfs_vfio.h b/drivers/crypto/bcmfs/bcmfs_vfio.h new file mode 100644 index 0000000000..d0fdf6483f --- /dev/null +++ b/drivers/crypto/bcmfs/bcmfs_vfio.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Broadcom + * All rights reserved. + */ + +#ifndef _BCMFS_VFIO_H_ +#define _BCMFS_VFIO_H_ + +/* Attach the bcmfs device to vfio */ +int +bcmfs_attach_vfio(struct bcmfs_device *dev); + +/* Release the bcmfs device from vfio */ +void +bcmfs_release_vfio(struct bcmfs_device *dev); + +#endif /* _BCMFS_VFIO_H_ */ diff --git a/drivers/crypto/bcmfs/meson.build b/drivers/crypto/bcmfs/meson.build index a4bdd8ee5d..fd39eba20e 100644 --- a/drivers/crypto/bcmfs/meson.build +++ b/drivers/crypto/bcmfs/meson.build @@ -6,5 +6,6 @@ deps += ['eal', 'bus_vdev'] sources = files( 'bcmfs_logs.c', - 'bcmfs_device.c' + 'bcmfs_device.c', + 'bcmfs_vfio.c' ) -- 2.17.1