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 8A05C41C25; Mon, 6 Feb 2023 21:25:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FD7D42D3F; Mon, 6 Feb 2023 21:25:24 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 894AD42D17 for ; Mon, 6 Feb 2023 21:25:22 +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 316F9xin017823; Mon, 6 Feb 2023 12:25:22 -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=kMcZgKjliFakLPiotmVXQ4dE+jODjKjowaup/D+dZvA=; b=jEhx3G52VNeDz/8VhHWzMwHZ+TKHfG6P3YJzwODfEegrbdrnKxdCeXnzdPvDjBmn6Z4E GzU8XYfGPw88D9IpmFDQkQvGYiaV5ZsPMPjhaSdd5IYdniFQIF3P8ANSc0eAO7+8jkQ4 x73OmbQYjiuI24yfA092kUyRvpeiUCrpEIkLqsxazZhWdj5rsfT1AJgWbtHkEea2Cri8 3dLi2F/SO0V762tqabhJkHRikrJbs+jh246TRNpgqjbF2FnBFfNjwIMOrlsxHY2+qYQU FgnS6eFzmNe96H3DgPlxOjUdtqZwmmK32ezJ09YaeXRVVpJ/aC6IAZrPQFEP/twztnuj Hw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nhqrte0q8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 06 Feb 2023 12:25:21 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 6 Feb 2023 12:25:19 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Mon, 6 Feb 2023 12:25:19 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id D821B3F70A5; Mon, 6 Feb 2023 12:25:16 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v2 03/12] mldev: support ML device handling functions Date: Tue, 7 Feb 2023 01:54:44 +0530 Message-ID: <20230206202453.336280-4-jerinj@marvell.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206202453.336280-1-jerinj@marvell.com> References: <20221114120238.2143832-1-jerinj@marvell.com> <20230206202453.336280-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: CuXZIe9qX-zQeYvPx6K4JfrqFOP0pKRH X-Proofpoint-ORIG-GUID: CuXZIe9qX-zQeYvPx6K4JfrqFOP0pKRH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,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 ML 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 | 8 ++ 3 files changed, 290 insertions(+) diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c index 06396de680..ddbd371bc9 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -134,4 +134,179 @@ 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)) { + RTE_MLDEV_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)) { + RTE_MLDEV_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) { + RTE_MLDEV_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)) { + RTE_MLDEV_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) { + RTE_MLDEV_LOG(ERR, "Device %d must be stopped to allow configuration", dev_id); + return -EBUSY; + } + + if (config == NULL) { + RTE_MLDEV_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) { + RTE_MLDEV_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)) { + RTE_MLDEV_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) { + RTE_MLDEV_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)) { + RTE_MLDEV_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) { + RTE_MLDEV_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)) { + RTE_MLDEV_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) { + RTE_MLDEV_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; +} + RTE_LOG_REGISTER_DEFAULT(rte_ml_dev_logtype, INFO); diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h index 1c989a5ecf..f4ed5badfb 100644 --- a/lib/mldev/rte_mldev_core.h +++ b/lib/mldev/rte_mldev_core.h @@ -31,6 +31,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 * @@ -78,6 +182,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 98a5e7d117..a2b3163c97 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -1,7 +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_logtype; + rte_ml_dev_socket_id; + rte_ml_dev_start; + rte_ml_dev_stop; local: *; }; -- 2.39.1