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 2CE70A04C0; Fri, 25 Sep 2020 13:12:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D3B5D1E951; Fri, 25 Sep 2020 13:10:22 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 1E4071E8C3 for ; Fri, 25 Sep 2020 13:10:18 +0200 (CEST) IronPort-SDR: A1qge9BvneUQ4ZNf20zbPNHY/f4IXEwydIS7BiXWnQOFw6+w04kkDXqBc4tngDcSVe0poKYLKq PKkYOUGXvtuw== X-IronPort-AV: E=McAfee;i="6000,8403,9754"; a="160760147" X-IronPort-AV: E=Sophos;i="5.77,301,1596524400"; d="scan'208";a="160760147" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 04:10:18 -0700 IronPort-SDR: /jD4Ta2zeg09x3H+y4guKQeipQWIeXsZ7y8C21BewIw+60VD03dv+EbLhROrufhUXSOhnq6TFB BO449TokO4zw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,301,1596524400"; d="scan'208";a="455788013" Received: from unknown (HELO silpixa00399126.ir.intel.com) ([10.237.222.4]) by orsmga004.jf.intel.com with ESMTP; 25 Sep 2020 04:10:17 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: patrick.fu@intel.com, Kevin Laatz , Bruce Richardson Date: Fri, 25 Sep 2020 12:09:00 +0100 Message-Id: <20200925110910.284098-16-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925110910.284098-1-bruce.richardson@intel.com> References: <20200721095140.719297-1-bruce.richardson@intel.com> <20200925110910.284098-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 15/25] raw/ioat: create rawdev instances for idxd vdevs 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" From: Kevin Laatz For each vdev (DSA work queue) instance, create a rawdev instance. Signed-off-by: Kevin Laatz Signed-off-by: Bruce Richardson --- drivers/raw/ioat/idxd_vdev.c | 106 +++++++++++++++++++++++++++++++- drivers/raw/ioat/ioat_private.h | 4 ++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/drivers/raw/ioat/idxd_vdev.c b/drivers/raw/ioat/idxd_vdev.c index 0509fc084..d2d588916 100644 --- a/drivers/raw/ioat/idxd_vdev.c +++ b/drivers/raw/ioat/idxd_vdev.c @@ -2,6 +2,12 @@ * Copyright(c) 2020 Intel Corporation */ +#include +#include +#include +#include + +#include #include #include #include @@ -24,6 +30,36 @@ struct idxd_vdev_args { uint8_t wq_id; }; +static const struct rte_rawdev_ops idxd_vdev_ops = { + .dev_close = idxd_rawdev_close, + .dev_selftest = idxd_rawdev_test, +}; + +static void * +idxd_vdev_mmap_wq(struct idxd_vdev_args *args) +{ + void *addr; + char path[PATH_MAX]; + int fd; + + snprintf(path, sizeof(path), "/dev/dsa/wq%u.%u", + args->device_id, args->wq_id); + fd = open(path, O_RDWR); + if (fd < 0) { + IOAT_PMD_ERR("Failed to open device path"); + return NULL; + } + + addr = mmap(NULL, 0x1000, PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0); + close(fd); + if (addr == MAP_FAILED) { + IOAT_PMD_ERR("Failed to mmap device"); + return NULL; + } + + return addr; +} + static int idxd_rawdev_parse_wq(const char *key __rte_unused, const char *value, void *extra_args) @@ -70,10 +106,32 @@ idxd_vdev_parse_params(struct rte_kvargs *kvlist, struct idxd_vdev_args *args) return -EINVAL; } +static int +idxd_vdev_get_max_batches(struct idxd_vdev_args *args) +{ + char sysfs_path[PATH_MAX]; + FILE *f; + int ret; + + snprintf(sysfs_path, sizeof(sysfs_path), + "/sys/bus/dsa/devices/wq%u.%u/size", + args->device_id, args->wq_id); + f = fopen(sysfs_path, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%d", &ret) != 1) + ret = -1; + + fclose(f); + return ret; +} + static int idxd_rawdev_probe_vdev(struct rte_vdev_device *vdev) { struct rte_kvargs *kvlist; + struct idxd_rawdev idxd = {0}; struct idxd_vdev_args vdev_args; const char *name; int ret = 0; @@ -96,13 +154,32 @@ idxd_rawdev_probe_vdev(struct rte_vdev_device *vdev) return -EINVAL; } + idxd.qid = vdev_args.wq_id; + idxd.u.vdev.dsa_id = vdev_args.device_id; + idxd.max_batches = idxd_vdev_get_max_batches(&vdev_args); + + idxd.public.portal = idxd_vdev_mmap_wq(&vdev_args); + if (idxd.public.portal == NULL) { + IOAT_PMD_ERR("WQ mmap failed"); + return -ENOENT; + } + + ret = idxd_rawdev_create(name, &vdev->device, &idxd, &idxd_vdev_ops); + if (ret) { + IOAT_PMD_ERR("Failed to create rawdev %s", name); + return ret; + } + return 0; } static int idxd_rawdev_remove_vdev(struct rte_vdev_device *vdev) { + struct idxd_rawdev *idxd; const char *name; + struct rte_rawdev *rdev; + int ret = 0; name = rte_vdev_device_name(vdev); if (name == NULL) @@ -110,7 +187,34 @@ idxd_rawdev_remove_vdev(struct rte_vdev_device *vdev) IOAT_PMD_INFO("Remove DSA vdev %p", name); - return 0; + rdev = rte_rawdev_pmd_get_named_dev(name); + if (!rdev) { + IOAT_PMD_ERR("Invalid device name (%s)", name); + return -EINVAL; + } + + idxd = rdev->dev_private; + + /* free context and memory */ + if (rdev->dev_private != NULL) { + IOAT_PMD_DEBUG("Freeing device driver memory"); + rdev->dev_private = NULL; + + if (munmap(idxd->public.portal, 0x1000) < 0) { + IOAT_PMD_ERR("Error unmapping portal"); + ret = -errno; + } + + rte_free(idxd->public.batch_ring); + rte_free(idxd->public.hdl_ring); + + rte_memzone_free(idxd->mz); + } + + if (rte_rawdev_pmd_release(rdev)) + IOAT_PMD_ERR("Device cleanup failed"); + + return ret; } struct rte_vdev_driver idxd_rawdev_drv_vdev = { diff --git a/drivers/raw/ioat/ioat_private.h b/drivers/raw/ioat/ioat_private.h index 53f00a9f3..6f7bdb499 100644 --- a/drivers/raw/ioat/ioat_private.h +++ b/drivers/raw/ioat/ioat_private.h @@ -45,6 +45,10 @@ struct idxd_rawdev { uint16_t max_batches; union { + struct { + unsigned int dsa_id; + } vdev; + struct idxd_pci_common *pci; } u; }; -- 2.25.1