From patchwork Mon Jul 22 16:39:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gagandeep Singh X-Patchwork-Id: 142623 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2155A45683; Mon, 22 Jul 2024 18:40:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ADBED40DF8; Mon, 22 Jul 2024 18:39:56 +0200 (CEST) Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011067.outbound.protection.outlook.com [52.101.65.67]) by mails.dpdk.org (Postfix) with ESMTP id 6343B40DF8 for ; Mon, 22 Jul 2024 18:39:55 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GncSJ3ZRlhiLYlThRqNiq4inXcJ+XL6Zd0+SxEr9C4pvocyPCh2C3iFcVz1pubam1/Ojz/MJWfjIu6BxSMscn2lrzw/Dg43UC2meHZRcjtEX/DGcD4E0lKMdBatOpHUid920G7QatUqi64aElKKZccMh28WhdJa990PVtn7fI8pdQp/vyfSOQ307AZofD/4lTfGlqFgPqnrhlof8tMD6lkjZQsrI9DwQaWbxWzLROSJIl3H4pz2M22oh2bTZCc6mfjPH4Gl1wT0ljIbbewYtngG3wr8wPgLRPqji7k7KMePYWOxsFE0oOLiaa6CFW7O5pVD+fKotFoxSi3S8Tj5elw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l3Xd4OjWpAFo+pBPiyFTnEN14vPPwuB9mSI5bxrn+Vk=; b=MRWwf5PdfkiHUhyhEa8Ud4M5Nv59aTlx6A8TU+51rmSvfGoHvgVFF8uyYbxjvujW4p6SJEzrWy2pZHG2Q9ubLLyCZZrZ3qHIiEyeSJtyP12ilxIDlZYzjO7DY2Xg75RK0z+zBQWwD47jTZi7ethUp/XVsSWTyXcRM/87xvKyF3TQPYRjeU+9Dxy7Zj+30ZLJj1PqoJVaZRGRwrxdoKCOznV0dv6FL70wRcXAHFAM6wbbgadivfFtw6inCJq3Di7Td4/aIEycuDTjsLveKBp4r3SK6UALxW4S9feQ+A3dCaZ9yzohBVMdtSFwy9slEg2YXCHUDAxUIs/iZis8VCrDmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l3Xd4OjWpAFo+pBPiyFTnEN14vPPwuB9mSI5bxrn+Vk=; b=ox29AnxK2YstZ5X8vt4kdnvGkiezz9tPfibvpHa+FDx7pFbNUh8HBjw2rzV1mLnSvuYiCnROxAya8UJuvaC4k4lERA9sfYf9MciP6Z/Ts1k0iQ9TVk8JXkv5a4ZvR5B3XEb/CL2jhNR69R7p6wefue25umHSKknIqt9kBOeMtsU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8SPR01MB0024.eurprd04.prod.outlook.com (2603:10a6:20b:3d0::24) by VI1PR04MB6798.eurprd04.prod.outlook.com (2603:10a6:803:131::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Mon, 22 Jul 2024 16:39:52 +0000 Received: from AS8SPR01MB0024.eurprd04.prod.outlook.com ([fe80::c634:479e:8f8a:a325]) by AS8SPR01MB0024.eurprd04.prod.outlook.com ([fe80::c634:479e:8f8a:a325%7]) with mapi id 15.20.7784.017; Mon, 22 Jul 2024 16:39:52 +0000 From: Gagandeep Singh To: dev@dpdk.org, Hemant Agrawal , Anatoly Burakov Cc: Jun Yang Subject: [v3 04/30] dma/dpaa2: multiple process support Date: Mon, 22 Jul 2024 22:09:04 +0530 Message-Id: <20240722163930.2171568-5-g.singh@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240722163930.2171568-1-g.singh@nxp.com> References: <20240722115843.1830105-1-g.singh@nxp.com> <20240722163930.2171568-1-g.singh@nxp.com> X-ClientProxiedBy: SG3P274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::26) To AS8SPR01MB0024.eurprd04.prod.outlook.com (2603:10a6:20b:3d0::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8SPR01MB0024:EE_|VI1PR04MB6798:EE_ X-MS-Office365-Filtering-Correlation-Id: ec838236-6a6f-4cd1-01bf-08dcaa6ce915 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: nien4M0G9yswAHYHeGJ0dQ8cIk/Yoso/ME6JF+bwt86zUIxlC9BTVGtidM8FpcBdSQd6gmoEs1vg4F84CiG3NmBEdFHfmAxDvpTVlbzQsDSLf0jUia/Ep+nCG7Dg1SQt03Fh8RdEhGSYUB2vMOHff1Wm6V2GnCodPknPdfvkl/6mgAwZE87GopePZfWtGawFL95oUKpv5OEdyP1m8SFWHPAG7G86++CTKRr9mTg40A4PrFesnooqgKZfYCIs38BDZr5Pta+w+l1MoHg/gijBLw4Ps0f3CZ+0fMtJA2m5nskndYBMZw+Vta/bFCKa6atI+X1rg3nCDLjNtmijegyaJny4K8U5cqgynO69aKv8f0cMvDBwb0SSlm6l6wItyxeD20Y7udNfJMDQKjzJQpC8nS2YJ8avpZ2n9RIB3wp6JiTsbf4cKDSRJowOV7D8VRqGOrMCCRDYBpJWKZUgF4INj+rQUPT7BxIpuhVK97TSu6lUOro3sP1ssflJLhBmBuQL9RTkcjUK5TkXu6SlAEDPxLUabbozIKsmqM8tKXHruPQVdt03PLAI5CzlBqqZaYhctA4wJAhxZEN+hK8ABy4uCDh9IeYqefCX8+k0NHsoZag9meKuuLdCDJjo9J4d3wzo1mbF8y62G3InEfSgTf9TvxA6nT2S4e1eNZHVqZB9u6nPYdduxKnGptwqnWGbjsR8T0mvvQlHNBIYBKHmp0E11zs3oGY9AiYPaFsKEUMY0xqBwUUPG1JOXB7FayHXaPf5WWUAB6TvsqCCmdpXIm+8KRo69Wi1Mwse3/cWrcftzIxH9Pd9UArothlwLKkho0UCmOXl0OzJYTSizNLmoMBfNf7xn1t75Tmt0YFKS2UwEz0/eJLTwhvfQcyxTkqDvtlKjY8HvxOoItfoM8jASGbNImHILwnF+fv4bWdbMgG1k9gC6jdClpptPdavyGK0BqvvHHnbnqjWk+dj+VtWsWyaEp9Sz6bdAtWwK/TMOd2KBVk8sCOr2RwtFItY0Ie3G+/PNkSctLAiuKZFYp0BK5SreurzRhKOqoZZDxdpKbRyk6k+pjcUIBw4tkcmdfcEXVUDZ2XcRA0e9ldNDRcGKiayDTOmvv/yeF5dyIZYYIXUp6BdqncktvMkXuT7AwP4CZQibqV1mxBAXr9xfLbCrxYNmyrCmfX4LxD1ODDx7LzT2/1n1W/nYx5q8cNd4g8suK7qeEThAPmmqIHJL4kzS9gD7C3nj4UawLcyw2mOdPoIUbP9BR6HEgkVWYJlzjCLSraQ9CzW8yzMf+Rb/p/mcAGtPviWEKkTCk+4TwyQ/2scjrxCEmTM5mmBZyQHcOvDpyBwSGvXffmgifHTdTDWw2zSN3QPy74jwivin2uXZubvmNDhpuyJBdNFQimcnVK/aKvhZ7WufCKT7an++xGJdAxDrg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8SPR01MB0024.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TD5XQ8FXsp7GYP4MrVsVxv5iCvqQw5+hbhGpHkxlwgCB95Zd/SDPyRlu/hTDEprkWDpRdcfMwlbcinGQ3wbEF8oUm0bAhN9RHKitv//WBVKzE6sOTs/dsttvBgL655evsng8Ipc9QPUY/q2EoK2Poc3vuz0xHZzzs8x5ccHiEm55VwXcwlXjo8tE+jR8foR1x8rj9e3SiFIvKKCXyVUcdLsFPaPyMgsb2SFnkbfQWtKq3WBiHQQ4aw3UrWEl3ntvw0xOgXE3j6F2DJCrMjrr43I0D9CMj8I7qffXLYRaz2zEpaZx0CwVMxFF3kHdVrkviiDTVDsE9F9HeYGHTpKQj8EtaRNYY/7IIJiIh8q5KjFxiuRYUanE6/4cgv/FCuJY7C7mLfOJ26JJcLIcdMm/pz/6HZGmPxXwNMRBN9JcnUFKDNLR8W6iE++lAz92VM3gQecm8KtnTODqtVytCsclcQxlkwDp8Ycl4GjYZrx7U0Fa6pCuzt9CICDe8if7Kh+w2qPKz7zxpFwgdu9sN/4S4iPyFppdhLz/PQD4+djf6o7QmQVD7vj4vHB2TALPiIeCZqwEAIcrsQu72l1n6aZl9KY+VinxGMK0dO8ll4dyDj23Lli6rvbq8Tfw0RHVpAMYwCTh5ix40bvPVpkateu7PJ4wqwKn89AqEjYk954BYW5Ho5gAjh5c8eVJEfAYr8SBbqG6UANdcQJf9e33nbmfE5ocb9h99enku2X9Yq2Y2lCIeGIrpc8om2LE5zQjw271w8s0yH//0NPLgiNsgDWj73aZ1i1j7x+VIwr/OG4fJfmUmOMx0vb6JsXIraU5TxhIY19slEHWIU9hkNsdDNDb65wUctDlxIRSN0jFnhNlsTW3NefrKC+cjHvgB4YDgjDFXXMdRZnhv3FAa+o96Mb8UBSlj02z2tk332t2+4xSZ4+sI8+JP0b7uuELzv75FRLR/qRhHJxykjHHJjXc1PbaOtP2ir1Ve50WT+QxAad+srIRg1XM3Pp2rX3aLOo4fM8dMZQ0Q6O4pJ8E7zf4H/tUz5eP8tTVruFUCz4fqFdW+oNiP6i3ag5xU5XsI2x9WkAklXzl5Ly+f/f3jFqtniqWoFyNrNwLgTqWWfv1lne/ZUWX0Ct9yMPGRnNOPif3GzNtIDem5PTSpu8dStT8L2ElK9crJ075H52fi/uZ3CxUvj7DVHB7ckQG3rDZ+72nlPG+zoG65jtJrkumto7SXkVUHfeGikk10pfJbRRKE5TFm1dUs+dMctnjcdp1sN7IuJiCZw1t02sWIPBmPz4Ms02UBB1kZwYsRVKAq/i/5mo4xclc8y/wm6F/Jokk3tYccA0tx9rfDqrz1PmgJ73/SRWCi5CYgdoogKHzlg2oB+vxIDkxX79alAmF8lnScAnLj1AnoGqwSBfezGN7anE28LM41uNSLTFNtJPwGMAg56RqildAR973uKAQ/6/OXfnT5jfOfgqS3G6ZkxnJ0ub/UZv1M0KNIBB0crJr3szQoreDrop5UROVvqtNDAcnRYY4gZO67QlkyQO50KmjnahGy8D8zbDinYgmAi+GH7ps77jGifDmB4Ey0YBkahGEXqoyJPJG X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec838236-6a6f-4cd1-01bf-08dcaa6ce915 X-MS-Exchange-CrossTenant-AuthSource: AS8SPR01MB0024.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2024 16:39:52.5137 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bm+4sU44iMh4NnerRarTGqpEza+ZSrDeGsIJjfVGpbPtY/a73EGBq6P91XM8F6vU X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6798 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: Jun Yang Support multiple processes for dpaa2 dma. 1) Move queue configuration procedure from init function to device configuration function which is called by user. 2) Instances of dpaa2_dpdmai_dev and qdma_device are allocated from primary process and shared between multiple processes. 3) MC reg is per process mapped. 4) User is responsible to check vq number configured before using dma device to identify if this device is occupied by other process. Signed-off-by: Jun Yang --- drivers/dma/dpaa2/dpaa2_qdma.c | 405 ++++++++++++++++++++------------- drivers/dma/dpaa2/dpaa2_qdma.h | 6 +- 2 files changed, 254 insertions(+), 157 deletions(-) diff --git a/drivers/dma/dpaa2/dpaa2_qdma.c b/drivers/dma/dpaa2/dpaa2_qdma.c index 15d3776603..44b82c139e 100644 --- a/drivers/dma/dpaa2/dpaa2_qdma.c +++ b/drivers/dma/dpaa2/dpaa2_qdma.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright 2018-2022 NXP + * Copyright 2018-2023 NXP */ #include @@ -19,6 +19,8 @@ static uint32_t dpaa2_coherent_no_alloc_cache; static uint32_t dpaa2_coherent_alloc_cache; +static struct fsl_mc_io s_proc_mc_reg; + static inline int qdma_cntx_idx_ring_eq(struct qdma_cntx_idx_ring *ring, const uint16_t *elem, uint16_t nb, @@ -960,6 +962,9 @@ dpaa2_qdma_info_get(const struct rte_dma_dev *dev, dev_info->max_vchans = dpdmai_dev->num_queues; dev_info->max_desc = DPAA2_QDMA_MAX_DESC; dev_info->min_desc = DPAA2_QDMA_MIN_DESC; + dev_info->dev_name = dev->device->name; + if (dpdmai_dev->qdma_dev) + dev_info->nb_vchans = dpdmai_dev->qdma_dev->num_vqs; return 0; } @@ -969,25 +974,102 @@ dpaa2_qdma_configure(struct rte_dma_dev *dev, const struct rte_dma_conf *dev_conf, uint32_t conf_sz) { - char name[32]; /* RTE_MEMZONE_NAMESIZE = 32 */ struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; uint16_t i; + struct dpdmai_rx_queue_cfg rx_queue_cfg; + struct dpdmai_rx_queue_attr rx_attr; + struct dpdmai_tx_queue_attr tx_attr; + struct dpaa2_queue *rxq; + int ret = 0; DPAA2_QDMA_FUNC_TRACE(); RTE_SET_USED(conf_sz); - /* In case QDMA device is not in stopped state, return -EBUSY */ - if (qdma_dev->state == 1) { - DPAA2_QDMA_ERR("%s Not stopped, configure failed.", - dev->data->dev_name); - return -EBUSY; + if (dev_conf->nb_vchans > dpdmai_dev->num_queues) { + DPAA2_QDMA_ERR("%s config queues(%d) > hw queues(%d)", + dev->data->dev_name, dev_conf->nb_vchans, + dpdmai_dev->num_queues); + + return -ENOTSUP; + } + + if (qdma_dev->vqs) { + DPAA2_QDMA_DEBUG("%s: queues de-config(%d)/re-config(%d)", + dev->data->dev_name, + qdma_dev->num_vqs, dev_conf->nb_vchans); + for (i = 0; i < qdma_dev->num_vqs; i++) { + if ((qdma_dev->vqs[i].num_enqueues != + qdma_dev->vqs[i].num_dequeues) && + !qdma_dev->is_silent) { + DPAA2_QDMA_ERR("VQ(%d) %"PRIu64" jobs in dma.", + i, qdma_dev->vqs[i].num_enqueues - + qdma_dev->vqs[i].num_dequeues); + return -EBUSY; + } + } + for (i = 0; i < qdma_dev->num_vqs; i++) { + if (qdma_dev->vqs[i].fle_pool) { + rte_mempool_free(qdma_dev->vqs[i].fle_pool); + qdma_dev->vqs[i].fle_pool = NULL; + } + if (qdma_dev->vqs[i].ring_cntx_idx) { + rte_free(qdma_dev->vqs[i].ring_cntx_idx); + qdma_dev->vqs[i].ring_cntx_idx = NULL; + } + rxq = &dpdmai_dev->rx_queue[i]; + if (rxq->q_storage) { + DPAA2_QDMA_DEBUG("%s rxq[%d] re-configure", + dev->data->dev_name, i); + dpaa2_free_dq_storage(rxq->q_storage); + rte_free(rxq->q_storage); + rxq->q_storage = NULL; + } + } + rte_free(qdma_dev->vqs); + qdma_dev->vqs = NULL; + qdma_dev->num_vqs = 0; + } + + /* Set up Rx Queues */ + for (i = 0; i < dev_conf->nb_vchans; i++) { + memset(&rx_queue_cfg, 0, sizeof(struct dpdmai_rx_queue_cfg)); + rxq = &dpdmai_dev->rx_queue[i]; + ret = dpdmai_set_rx_queue(&s_proc_mc_reg, + CMD_PRI_LOW, + dpdmai_dev->token, + i, 0, &rx_queue_cfg); + if (ret) { + DPAA2_QDMA_ERR("%s RXQ%d set failed(%d)", + dev->data->dev_name, i, ret); + return ret; + } + } + + /* Get Rx and Tx queues FQID's */ + for (i = 0; i < dev_conf->nb_vchans; i++) { + ret = dpdmai_get_rx_queue(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token, i, 0, &rx_attr); + if (ret) { + DPAA2_QDMA_ERR("Get DPDMAI%d-RXQ%d failed(%d)", + dpdmai_dev->dpdmai_id, i, ret); + return ret; + } + dpdmai_dev->rx_queue[i].fqid = rx_attr.fqid; + + ret = dpdmai_get_tx_queue(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token, i, 0, &tx_attr); + if (ret) { + DPAA2_QDMA_ERR("Get DPDMAI%d-TXQ%d failed(%d)", + dpdmai_dev->dpdmai_id, i, ret); + return ret; + } + dpdmai_dev->tx_queue[i].fqid = tx_attr.fqid; } /* Allocate Virtual Queues */ - sprintf(name, "qdma_%d_vq", dev->data->dev_id); - qdma_dev->vqs = rte_malloc(name, + qdma_dev->vqs = rte_zmalloc(NULL, (sizeof(struct qdma_virt_queue) * dev_conf->nb_vchans), RTE_CACHE_LINE_SIZE); if (!qdma_dev->vqs) { @@ -995,13 +1077,50 @@ dpaa2_qdma_configure(struct rte_dma_dev *dev, dev->data->dev_name, dev_conf->nb_vchans); return -ENOMEM; } - for (i = 0; i < dev_conf->nb_vchans; i++) + for (i = 0; i < dev_conf->nb_vchans; i++) { qdma_dev->vqs[i].vq_id = i; + rxq = &dpdmai_dev->rx_queue[i]; + /* Allocate DQ storage for the DPDMAI Rx queues */ + rxq->q_storage = rte_zmalloc(NULL, + sizeof(struct queue_storage_info_t), + RTE_CACHE_LINE_SIZE); + if (!rxq->q_storage) { + DPAA2_QDMA_ERR("%s Q[%d] storage alloc failed", + dev->data->dev_name, i); + ret = -ENOMEM; + goto alloc_failed; + } + + memset(rxq->q_storage, 0, sizeof(struct queue_storage_info_t)); + ret = dpaa2_alloc_dq_storage(rxq->q_storage); + if (ret) { + DPAA2_QDMA_ERR("%s Q[%d] dq storage alloc failed", + dev->data->dev_name, i); + ret = -ENOMEM; + goto alloc_failed; + } + } qdma_dev->num_vqs = dev_conf->nb_vchans; qdma_dev->is_silent = dev_conf->enable_silent; return 0; + +alloc_failed: + for (i = 0; i < dev_conf->nb_vchans; i++) { + rxq = &dpdmai_dev->rx_queue[i]; + if (rxq->q_storage) { + dpaa2_free_dq_storage(rxq->q_storage); + rte_free(rxq->q_storage); + rxq->q_storage = NULL; + } + } + + rte_free(qdma_dev->vqs); + qdma_dev->vqs = NULL; + qdma_dev->num_vqs = 0; + + return ret; } static int @@ -1130,11 +1249,17 @@ static int dpaa2_qdma_start(struct rte_dma_dev *dev) { struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; - struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; + int ret; DPAA2_QDMA_FUNC_TRACE(); - qdma_dev->state = 1; + /* Enable the device */ + ret = dpdmai_enable(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token); + if (ret) { + DPAA2_QDMA_ERR("Enabling device failed with err: %d", ret); + return ret; + } return 0; } @@ -1143,30 +1268,33 @@ static int dpaa2_qdma_stop(struct rte_dma_dev *dev) { struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; - struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; + int ret; DPAA2_QDMA_FUNC_TRACE(); - qdma_dev->state = 0; + /* Disable the device */ + ret = dpdmai_disable(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token); + if (ret) { + DPAA2_QDMA_ERR("Disable device failed with err: %d", ret); + return ret; + } return 0; } static int -dpaa2_qdma_reset(struct rte_dma_dev *dev) +dpaa2_qdma_close(struct rte_dma_dev *dev) { struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; + struct dpaa2_queue *rxq; int i; DPAA2_QDMA_FUNC_TRACE(); - /* In case QDMA device is not in stopped state, return -EBUSY */ - if (qdma_dev->state == 1) { - DPAA2_QDMA_ERR("%s Not stopped, reset failed.", - dev->data->dev_name); - return -EBUSY; - } + if (!qdma_dev) + return 0; /* In case there are pending jobs on any VQ, return -EBUSY */ for (i = 0; i < qdma_dev->num_vqs; i++) { @@ -1180,8 +1308,31 @@ dpaa2_qdma_reset(struct rte_dma_dev *dev) } } - rte_free(qdma_dev->vqs); - qdma_dev->vqs = NULL; + /* Free RXQ storages */ + for (i = 0; i < qdma_dev->num_vqs; i++) { + rxq = &dpdmai_dev->rx_queue[i]; + if (rxq->q_storage) { + dpaa2_free_dq_storage(rxq->q_storage); + rte_free(rxq->q_storage); + rxq->q_storage = NULL; + } + } + + if (qdma_dev->vqs) { + /* Free RXQ fle pool */ + for (i = 0; i < qdma_dev->num_vqs; i++) { + if (qdma_dev->vqs[i].fle_pool) { + rte_mempool_free(qdma_dev->vqs[i].fle_pool); + qdma_dev->vqs[i].fle_pool = NULL; + } + if (qdma_dev->vqs[i].ring_cntx_idx) { + rte_free(qdma_dev->vqs[i].ring_cntx_idx); + qdma_dev->vqs[i].ring_cntx_idx = NULL; + } + } + rte_free(qdma_dev->vqs); + qdma_dev->vqs = NULL; + } /* Reset QDMA device structure */ qdma_dev->num_vqs = 0; @@ -1190,18 +1341,8 @@ dpaa2_qdma_reset(struct rte_dma_dev *dev) } static int -dpaa2_qdma_close(__rte_unused struct rte_dma_dev *dev) -{ - DPAA2_QDMA_FUNC_TRACE(); - - dpaa2_qdma_reset(dev); - - return 0; -} - -static int -dpaa2_qdma_stats_get(const struct rte_dma_dev *dmadev, uint16_t vchan, - struct rte_dma_stats *rte_stats, uint32_t size) +dpaa2_qdma_stats_get(const struct rte_dma_dev *dmadev, + uint16_t vchan, struct rte_dma_stats *rte_stats, uint32_t size) { struct dpaa2_dpdmai_dev *dpdmai_dev = dmadev->data->dev_private; struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; @@ -1256,56 +1397,97 @@ static int dpaa2_dpdmai_dev_uninit(struct rte_dma_dev *dev) { struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; - struct dpaa2_queue *rxq; - int ret, i; + struct qdma_device *qdma_dev = dpdmai_dev->qdma_dev; + int ret; DPAA2_QDMA_FUNC_TRACE(); - ret = dpdmai_disable(&dpdmai_dev->dpdmai, CMD_PRI_LOW, - dpdmai_dev->token); - if (ret) { - DPAA2_QDMA_ERR("dpdmai(%d) disable failed", + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + DPAA2_QDMA_DEBUG("Un-attach DMA(%d) in the 2nd proess.", dpdmai_dev->dpdmai_id); - } - - /* Set up the DQRR storage for Rx */ - for (i = 0; i < dpdmai_dev->num_queues; i++) { - rxq = &dpdmai_dev->rx_queue[i]; - if (rxq->q_storage) { - dpaa2_free_dq_storage(rxq->q_storage); - rte_free(rxq->q_storage); - } + return 0; } /* Close the device at underlying layer*/ - ret = dpdmai_close(&dpdmai_dev->dpdmai, CMD_PRI_LOW, dpdmai_dev->token); + ret = dpdmai_close(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token); if (ret) { - DPAA2_QDMA_ERR("dpdmai(%d) close failed", - dpdmai_dev->dpdmai_id); + DPAA2_QDMA_ERR("dpdmai(%d) close failed(%d)", + dpdmai_dev->dpdmai_id, ret); + + return ret; + } + + if (qdma_dev) { + rte_free(qdma_dev); + dpdmai_dev->qdma_dev = NULL; } return ret; } static int -dpaa2_dpdmai_dev_init(struct rte_dma_dev *dev, int dpdmai_id) +dpaa2_dpdmai_dev_init(struct rte_dma_dev *dev, uint32_t dpdmai_id) { struct dpaa2_dpdmai_dev *dpdmai_dev = dev->data->dev_private; - struct dpdmai_rx_queue_cfg rx_queue_cfg; struct dpdmai_attr attr; - struct dpdmai_rx_queue_attr rx_attr; - struct dpdmai_tx_queue_attr tx_attr; - struct dpaa2_queue *rxq; - int ret, i; + int ret, err; DPAA2_QDMA_FUNC_TRACE(); + if (!dpaa2_coherent_no_alloc_cache) { + if (dpaa2_svr_family == SVR_LX2160A) { + dpaa2_coherent_no_alloc_cache = + DPAA2_LX2_COHERENT_NO_ALLOCATE_CACHE; + dpaa2_coherent_alloc_cache = + DPAA2_LX2_COHERENT_ALLOCATE_CACHE; + } else { + dpaa2_coherent_no_alloc_cache = + DPAA2_COHERENT_NO_ALLOCATE_CACHE; + dpaa2_coherent_alloc_cache = + DPAA2_COHERENT_ALLOCATE_CACHE; + } + } + + if (!s_proc_mc_reg.regs) + s_proc_mc_reg.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX); + + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + DPAA2_QDMA_DEBUG("Attach DMA(%d) in the 2nd proess.", + dpdmai_id); + if (dpdmai_id != dpdmai_dev->dpdmai_id) { + DPAA2_QDMA_ERR("Fatal: Attach DMA(%d) to DMA(%d)", + dpdmai_id, dpdmai_dev->dpdmai_id); + return -EINVAL; + } + if (!dpdmai_dev->qdma_dev) { + DPAA2_QDMA_ERR("Fatal: DMA(%d) qdma_dev NOT allocated", + dpdmai_id); + return -ENOMEM; + } + if (dpdmai_dev->qdma_dev->num_vqs) { + DPAA2_QDMA_WARN("DMA(%d) %d vqs were configured", + dpdmai_id, dpdmai_dev->qdma_dev->num_vqs); + } + + return 0; + } + /* Open DPDMAI device */ dpdmai_dev->dpdmai_id = dpdmai_id; - dpdmai_dev->dpdmai.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX); - dpdmai_dev->qdma_dev = rte_malloc(NULL, + + if (dpdmai_dev->qdma_dev) { + rte_free(dpdmai_dev->qdma_dev); + dpdmai_dev->qdma_dev = NULL; + } + dpdmai_dev->qdma_dev = rte_zmalloc(NULL, sizeof(struct qdma_device), RTE_CACHE_LINE_SIZE); - ret = dpdmai_open(&dpdmai_dev->dpdmai, CMD_PRI_LOW, + if (!dpdmai_dev->qdma_dev) { + DPAA2_QDMA_ERR("DMA(%d) alloc memory failed", + dpdmai_id); + return -ENOMEM; + } + ret = dpdmai_open(&s_proc_mc_reg, CMD_PRI_LOW, dpdmai_dev->dpdmai_id, &dpdmai_dev->token); if (ret) { DPAA2_QDMA_ERR("%s: dma(%d) open failed(%d)", @@ -1314,105 +1496,24 @@ dpaa2_dpdmai_dev_init(struct rte_dma_dev *dev, int dpdmai_id) } /* Get DPDMAI attributes */ - ret = dpdmai_get_attributes(&dpdmai_dev->dpdmai, CMD_PRI_LOW, + ret = dpdmai_get_attributes(&s_proc_mc_reg, CMD_PRI_LOW, dpdmai_dev->token, &attr); if (ret) { DPAA2_QDMA_ERR("%s: dma(%d) get attributes failed(%d)", __func__, dpdmai_dev->dpdmai_id, ret); - goto init_err; - } - dpdmai_dev->num_queues = attr.num_of_queues; - - /* Set up Rx Queues */ - for (i = 0; i < dpdmai_dev->num_queues; i++) { - memset(&rx_queue_cfg, 0, sizeof(struct dpdmai_rx_queue_cfg)); - ret = dpdmai_set_rx_queue(&dpdmai_dev->dpdmai, - CMD_PRI_LOW, - dpdmai_dev->token, - i, 0, &rx_queue_cfg); - if (ret) { - DPAA2_QDMA_ERR("%s Q%d set failed(%d)", - dev->data->dev_name, i, ret); - goto init_err; - } - - /* Allocate DQ storage for the DPDMAI Rx queues */ - rxq = &dpdmai_dev->rx_queue[i]; - rxq->q_storage = rte_malloc("dq_storage", - sizeof(struct queue_storage_info_t), - RTE_CACHE_LINE_SIZE); - if (!rxq->q_storage) { - DPAA2_QDMA_ERR("%s DQ info(Q%d) alloc failed", - dev->data->dev_name, i); - ret = -ENOMEM; - goto init_err; - } - - memset(rxq->q_storage, 0, sizeof(struct queue_storage_info_t)); - ret = dpaa2_alloc_dq_storage(rxq->q_storage); - if (ret) { - DPAA2_QDMA_ERR("%s DQ storage(Q%d) alloc failed(%d)", - dev->data->dev_name, i, ret); - goto init_err; - } - } - - /* Get Rx and Tx queues FQID's */ - for (i = 0; i < dpdmai_dev->num_queues; i++) { - ret = dpdmai_get_rx_queue(&dpdmai_dev->dpdmai, CMD_PRI_LOW, - dpdmai_dev->token, i, 0, &rx_attr); - if (ret) { - DPAA2_QDMA_ERR("Get DPDMAI%d-RXQ%d failed(%d)", - dpdmai_dev->dpdmai_id, i, ret); - goto init_err; - } - dpdmai_dev->rx_queue[i].fqid = rx_attr.fqid; - - ret = dpdmai_get_tx_queue(&dpdmai_dev->dpdmai, CMD_PRI_LOW, - dpdmai_dev->token, i, 0, &tx_attr); - if (ret) { - DPAA2_QDMA_ERR("Get DPDMAI%d-TXQ%d failed(%d)", - dpdmai_dev->dpdmai_id, i, ret); - goto init_err; - } - dpdmai_dev->tx_queue[i].fqid = tx_attr.fqid; - } - - /* Enable the device */ - ret = dpdmai_enable(&dpdmai_dev->dpdmai, CMD_PRI_LOW, - dpdmai_dev->token); - if (ret) { - DPAA2_QDMA_ERR("Enabling device failed with err: %d", ret); - goto init_err; - } - - if (!dpaa2_coherent_no_alloc_cache) { - if (dpaa2_svr_family == SVR_LX2160A) { - dpaa2_coherent_no_alloc_cache = - DPAA2_LX2_COHERENT_NO_ALLOCATE_CACHE; - dpaa2_coherent_alloc_cache = - DPAA2_LX2_COHERENT_ALLOCATE_CACHE; - } else { - dpaa2_coherent_no_alloc_cache = - DPAA2_COHERENT_NO_ALLOCATE_CACHE; - dpaa2_coherent_alloc_cache = - DPAA2_COHERENT_ALLOCATE_CACHE; + err = dpdmai_close(&s_proc_mc_reg, CMD_PRI_LOW, + dpdmai_dev->token); + if (err) { + DPAA2_QDMA_ERR("dpdmai(%d) close failed(%d)", + dpdmai_dev->dpdmai_id, err); } + return ret; } + dpdmai_dev->num_queues = attr.num_of_queues; - DPAA2_QDMA_DEBUG("Initialized dpdmai object successfully"); - - /* Reset the QDMA device */ - ret = dpaa2_qdma_reset(dev); - if (ret) { - DPAA2_QDMA_ERR("Resetting QDMA failed"); - goto init_err; - } + DPAA2_QDMA_DEBUG("DMA(%d) is initialized.", dpdmai_id); return 0; -init_err: - dpaa2_dpdmai_dev_uninit(dev); - return ret; } static int diff --git a/drivers/dma/dpaa2/dpaa2_qdma.h b/drivers/dma/dpaa2/dpaa2_qdma.h index ee34532408..743a43fa14 100644 --- a/drivers/dma/dpaa2/dpaa2_qdma.h +++ b/drivers/dma/dpaa2/dpaa2_qdma.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright 2018-2022 NXP + * Copyright 2018-2023 NXP */ #ifndef _DPAA2_QDMA_H_ @@ -200,8 +200,6 @@ struct qdma_cntx_long { struct dpaa2_dpdmai_dev { /** Pointer to Next device instance */ TAILQ_ENTRY(dpaa2_qdma_device) next; - /** handle to DPDMAI object */ - struct fsl_mc_io dpdmai; /** HW ID for DPDMAI object */ uint32_t dpdmai_id; /** Tocken of this device */ @@ -267,8 +265,6 @@ struct qdma_device { struct qdma_virt_queue *vqs; /** Total number of VQ's */ uint16_t num_vqs; - /** Device state - started or stopped */ - uint8_t state; uint8_t is_silent; };