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 5642BA00C4; Mon, 14 Nov 2022 13:07:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38D7342D1A; Mon, 14 Nov 2022 13:06:57 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 1F02D4014F for ; Mon, 14 Nov 2022 13:06:56 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AE6h1dm008489; Mon, 14 Nov 2022 04:04:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=Ix4V0fCZs0JuxpigVkb+12Xzjfxa8DNlNeAxrAsQ0Pc=; b=VYfi2lkaTvt/HCjL22mRVbXtmWhr5P35mEcDT39g119dHHgW/XxN+F2k019ihNU7aA3y YhljPdX5JDr/6H1dhI83m5PUALMpygYh+a0vWVkhSGT01Z+nml4Cac+t9PMcE2qflusm s3jvYCFkqWEBQEkVMQ34Oqik+NqdyblA3LgdSHxb7ROfj/d9ibpotSH/TqO47WAjx+k/ xf6ZKQpHMamrEmjc9uutepYChoI8NvoZ42Ofn/9pisJwEU6MeRK42uceEKpNvqYWVQZh bgm6JVj284HD9H0HwLnNwBMlbavn7bXxRi4DGt9z0L6g2UiVl8e2/zg6RyXnT0ZJZzwd 1A== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3kugnb0wry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 14 Nov 2022 04:04:37 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 14 Nov 2022 04:04:35 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 14 Nov 2022 04:04:34 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 1E2495C68E2; Mon, 14 Nov 2022 04:04:09 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v1 03/12] mldev: support device handling functions Date: Mon, 14 Nov 2022 17:32:29 +0530 Message-ID: <20221114120238.2143832-4-jerinj@marvell.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114120238.2143832-1-jerinj@marvell.com> References: <20220803132839.2747858-2-jerinj@marvell.com> <20221114120238.2143832-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: fbUNtr5-GCUCzw8Va_rsjHF-JGJc0iXU X-Proofpoint-GUID: fbUNtr5-GCUCzw8Va_rsjHF-JGJc0iXU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_10,2022-11-11_01,2022-06-22_01 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: Srikanth Yalavarthi Added device handling APIs. These APIs are used to get device information, configure, start, stop and close ML devices. Added function prototypes to PMD layer which are used by the ML driver implementations in the poll mode driver. Signed-off-by: Srikanth Yalavarthi Signed-off-by: Jerin Jacob --- lib/mldev/rte_mldev.c | 175 +++++++++++++++++++++++++++++++++++++ lib/mldev/rte_mldev_core.h | 107 +++++++++++++++++++++++ lib/mldev/version.map | 11 +++ 3 files changed, 293 insertions(+) diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c index a4e0b5f94f..651f8b2f7c 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -131,3 +131,178 @@ rte_ml_dev_pmd_release(struct rte_ml_dev *dev) return ret; } + +uint16_t +rte_ml_dev_count(void) +{ + return ml_dev_globals.nb_devs; +} + +int +rte_ml_dev_is_valid_dev(int16_t dev_id) +{ + struct rte_ml_dev *dev = NULL; + + if (dev_id >= ml_dev_globals.max_devs || ml_devices[dev_id].data == NULL) + return 0; + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (dev->attached != ML_DEV_ATTACHED) + return 0; + else + return 1; +} + +int +rte_ml_dev_socket_id(int16_t dev_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + + return dev->data->socket_id; +} + +int +rte_ml_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->dev_info_get == NULL) + return -ENOTSUP; + + if (dev_info == NULL) { + ML_DEV_LOG(ERR, "Dev %d, dev_info cannot be NULL\n", dev_id); + return -EINVAL; + } + memset(dev_info, 0, sizeof(struct rte_ml_dev_info)); + + return (*dev->dev_ops->dev_info_get)(dev, dev_info); +} + +int +rte_ml_dev_configure(int16_t dev_id, const struct rte_ml_dev_config *config) +{ + struct rte_ml_dev_info dev_info; + struct rte_ml_dev *dev; + int ret; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->dev_configure == NULL) + return -ENOTSUP; + + if (dev->data->dev_started) { + ML_DEV_LOG(ERR, "Device %d must be stopped to allow configuration", dev_id); + return -EBUSY; + } + + if (config == NULL) { + ML_DEV_LOG(ERR, "Dev %d, config cannot be NULL\n", dev_id); + return -EINVAL; + } + + ret = rte_ml_dev_info_get(dev_id, &dev_info); + if (ret < 0) + return ret; + + if (config->nb_queue_pairs > dev_info.max_queue_pairs) { + ML_DEV_LOG(ERR, "Device %d num of queues %u > %u\n", dev_id, config->nb_queue_pairs, + dev_info.max_queue_pairs); + return -EINVAL; + } + + return (*dev->dev_ops->dev_configure)(dev, config); +} + +int +rte_ml_dev_close(int16_t dev_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->dev_close == NULL) + return -ENOTSUP; + + /* Device must be stopped before it can be closed */ + if (dev->data->dev_started == 1) { + ML_DEV_LOG(ERR, "Device %d must be stopped before closing", dev_id); + return -EBUSY; + } + + return (*dev->dev_ops->dev_close)(dev); +} + +int +rte_ml_dev_start(int16_t dev_id) +{ + struct rte_ml_dev *dev; + int ret; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->dev_start == NULL) + return -ENOTSUP; + + if (dev->data->dev_started != 0) { + ML_DEV_LOG(ERR, "Device %d is already started", dev_id); + return -EBUSY; + } + + ret = (*dev->dev_ops->dev_start)(dev); + if (ret == 0) + dev->data->dev_started = 1; + + return ret; +} + +int +rte_ml_dev_stop(int16_t dev_id) +{ + struct rte_ml_dev *dev; + int ret; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->dev_stop == NULL) + return -ENOTSUP; + + if (dev->data->dev_started == 0) { + ML_DEV_LOG(ERR, "Device %d is not started", dev_id); + return -EBUSY; + } + + ret = (*dev->dev_ops->dev_stop)(dev); + if (ret == 0) + dev->data->dev_started = 0; + + return ret; +} diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h index b5cb69c5fb..1405cce7f7 100644 --- a/lib/mldev/rte_mldev_core.h +++ b/lib/mldev/rte_mldev_core.h @@ -35,6 +35,110 @@ extern "C" { #define ML_DEV_DETACHED (0) #define ML_DEV_ATTACHED (1) +struct rte_ml_dev; + +/** + * Definitions of all functions exported by a driver through the generic structure of type + * *ml_dev_ops* supplied in the *rte_ml_dev* structure associated with a device. + */ + +/** + * @internal + * + * Function used to get device information. + * + * @param dev + * ML device pointer. + * @param dev_info + * Pointer to info structure. + * + * @return + * - 0 on success. + * - < 0, error code on failure. + */ +typedef int (*mldev_info_get_t)(struct rte_ml_dev *dev, struct rte_ml_dev_info *dev_info); + +/** + * @internal + * + * Function used to configure device. + * + * @param dev + * ML device pointer. + * @param config + * ML device configurations. + * + * @return + * - 0 on success + * - < 0, error code on failure. + */ +typedef int (*mldev_configure_t)(struct rte_ml_dev *dev, const struct rte_ml_dev_config *config); + +/** + * @internal + * + * Function used to close a configured device. + * + * @param dev + * ML device pointer. + * + * @return + * - 0 on success. + * - -EAGAIN if can't close as device is busy. + * - < 0, error code on failure, other than busy. + */ +typedef int (*mldev_close_t)(struct rte_ml_dev *dev); + +/** + * @internal + * + * Function used to start a configured device. + * + * @param dev + * ML device pointer. + * + * @return + * - 0 on success. + * - < 0, error code on failure. + */ +typedef int (*mldev_start_t)(struct rte_ml_dev *dev); + +/** + * @internal + * + * Function used to stop a configured device. + * + * @param dev + * ML device pointer. + * + * @return + * - 0 on success. + * - < 0, error code on failure. + */ +typedef int (*mldev_stop_t)(struct rte_ml_dev *dev); + +/** + * @internal + * + * ML device operations function pointer table. + */ +struct rte_ml_dev_ops { + /** Get device information. */ + mldev_info_get_t dev_info_get; + + /** Configure device. */ + mldev_configure_t dev_configure; + + /** Close device. */ + mldev_close_t dev_close; + + /** Start device. */ + mldev_start_t dev_start; + + /** Stop device. */ + mldev_stop_t dev_stop; +}; + /** * @internal * @@ -82,6 +186,9 @@ struct rte_ml_dev { /** Pointer to device data. */ struct rte_ml_dev_data *data; + /** Functions exported by PMD. */ + struct rte_ml_dev_ops *dev_ops; + /** Backing RTE device. */ struct rte_device *device; diff --git a/lib/mldev/version.map b/lib/mldev/version.map index 82eedfada4..1be508ab5f 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -1,4 +1,15 @@ EXPERIMENTAL { + global: + + rte_ml_dev_close; + rte_ml_dev_configure; + rte_ml_dev_count; + rte_ml_dev_info_get; + rte_ml_dev_is_valid_dev; + rte_ml_dev_socket_id; + rte_ml_dev_start; + rte_ml_dev_stop; + local: *; }; -- 2.38.1