From patchwork Mon Mar 7 22:47:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51351C433EF for ; Mon, 7 Mar 2022 22:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236822AbiCGWtM (ORCPT ); Mon, 7 Mar 2022 17:49:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343869AbiCGWtM (ORCPT ); Mon, 7 Mar 2022 17:49:12 -0500 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30049.outbound.protection.outlook.com [40.107.3.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 671B0641D; Mon, 7 Mar 2022 14:48:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b2Jredeux9diQ6ujESHEye1wu46tMcmfZQQI6BCZTp7BtUwY/vFEP3csXzvngCWAOd+opHmGQLAo2z3wqSqTHDpPRH+GcA2teuxdZsHJ+OJIGV8dwek2eL40Kz7tcGr4nzLju0t6EIo3yLx0xtNc4/XM/+ks9U5t8zHldS8PSUda4uPAZTd8ZZdeHTQsX297sVgXxQfB76To3CCkmitphvKM78aChqwO7vBmWcGUZkniQHye8s7y/MGH74VG8SfJzbJ/0GNfB8lUpLZQCFZO4YpmQ2jLGN/QWX+OGDn/0IwWYihuqJHLptssDrd4K2tCmrEO6Jy13C1fapfUxaBUsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=uZJ8P6i6nW7geaUWXGlygn5GEoit4xRthIO/Uahb3+g=; b=VIpRnAHz26nHP9XEaXhl9UuA7aYBK4/9YUYV35whAkC1SHsmaKdDTQ/3sRJQCSbQO7yEzsQv2J3IcaEM7VKiDC5fsNL+NTlxFyjBmdhPuhqgTqXcOtmduZTCQRC6+BZWg4WIq6S6bXwUx0O42iT1uYqglYnZd+YFf33zLsMAH9uShZmJYJYlhRFubDoU8AktA6iQ0uThZjOBXR5SMvd1QMJta9YgjGda1eeJbI7eVNqDvAJllEfB4bPAbxTxPymUY7N9ad+eXEI7BL3tjtEssLU4ZMT8P5S6ww5LzvOGrk/Yc6qgEPAinEA45tqwreZVNCdj5KjLN2H9Zz8oMEmltQ== 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=uZJ8P6i6nW7geaUWXGlygn5GEoit4xRthIO/Uahb3+g=; b=p0NvVU1RJLdQxU9ML7AyAm2ZStSNevTliA3PRmPluvzM1SR1nXvVeGG48jR6sjpKvnaR4nU4imf8S0bwQoMFCjhEv7sz2L38OltcxGLAHiChrN2lKRc4H56snMZwVsqM4TAi5nQcfYDfhrIJLG3OSk2q2XcidM0B+MjYQJAwcSc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:11 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:10 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 1/6] dmaengine: dw-edma: fix dw_edma_probe() can't be call globally Date: Mon, 7 Mar 2022 16:47:45 -0600 Message-Id: <20220307224750.18055-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f608747-821e-44d4-82ff-08da008c8e19 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WiRNRBGmx6xNSilZx7MlLOPvI/FeVZNpVsTf1rtiX8anNrTqs2fpMehPv2IkUUua/+NklqcAZPa6rYE2kMzYhAni3FIeJQMU0IYApW5JH7tRqk1+8S1TN1Pbga+jK/NUGCHdFTaqHySefd6SkSC+KyVgcomL2hvB8x0javn7OnJEFEnZWoLc2ML3jq6O4/WKo8Jh3Dgd5t6OXNtvnb5kserwrp+db8gS7F/ut4YZy9UrSrcGKcQOR+xM3r698oBROQv9RM1uB8P4Lt2Pb9T0fpQIBIYFvoxl3BzcGO+5MXugnF/VOXB2eUPAoW9VvTvBOcEn2vYGK+HxAOI5eTb3Wm+5brrT7BCpF3lFgzyNE9/Np4h8U0hEwHnOt3MNzf9z6XWEBP8xyKp2fpO67CoGSUu2VJET6+9zw0eOCQ9t1TbcLD3D46qabwmE/4fmq1XqGk1eO0kxwcRhjgN+yaayiAQoZIdzrLjJMkvcDgK/8yOhdWxjleUZFfqD5CmLnjVVqnA6uB8UA9CVLbQEZQdQWZZQODUccrCwHc1hZY3fFGLT7zmzZiu7q3bY4+y+sZ6dPXSjvk2ApgumOM4ky1UB/VRA6+DmugTTsNWF+iRrqQe1IIRIUPMXqpN4NByeeiocA5UZb6LcNkrSr9KU66byRnI9mokrfQE9CCejWi75HFyQKqgYkJIXoUq9Yic0LxjcL4ZebvzZaCKGed1nJBFlqg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(30864003)(8676002)(498600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l0clYozaxaP21I/EIbH7j3KAyBQKVQW4wyXMFRaZA7HbvRKGR9hqq9UhP0yqd9rwNQwvHEGPeSBe4uEzPaz6mq1+TbDt4yCA80LnFwMreYUE1p3J9DSSyh2u6k+m4nZMOBdTB89aEQUrfpkc7mcIvNGqEfu2yEXF44l303dPtfqj+V10MKBpvls4zZl+F9A3OYG+V0GY5J0RD3cTKn9QKJINx4EO9dpIl43QU5wt0vYShdiMA2+aRxXTvF/7IO2FYXPHOOpIrSjzI6bIHV6xlxlGbs5xnJLQ5MPuZ0+WeBir8MZ/CBT5L1mryONNPUZ2U+yInO6139Ex+Zv+jL+7SqaNhAmpW+VpZ8DWJkkgSD5MFE9c/Cum1PGpX240vQyXkcaRdJwhhFIGUn47c7VWUxom+QSqfDuFMmbPmJIcKviqNbWXMeKTR70xQMO1sJBrYmiPOq7Hx7S+PhWXMy5yCpdtjqkV089X3Cqrna5NFujOCEEOdBHJ1P5LleYM9pbmKuI9OTB6fo0XhXAhnkrz/jgGtPJ2LWHpFjcluLyOznSVIDrGGfvLMaKj6tYqcc0UHR/+EO95rThMy54sM7CtaKARweI/fyLjqxuQ3jQAfPjNKyRG8/H7gWLas1RBN6zSR6Wz+YCLgXCQxV+pBoxUZ7WXKVlB5sbrTuFNVYF1KPCRDC3hF5Fm2VTasTpmVzsx0LfTwTxbdyMHoelkswjVh07APs7ccuPtuNSJZ9Iygte3CqKS0bWGnaFENpyw+ToerRNh/jcyiaw69W0nzvrsGSRIQ/wOlNBkBxtINZhgpAASMCFPOE/Pjb9qtVt4lh5cs40T1RYs+PSZA13sFNIGzXcNY2O3sjlRJ4zBxAM2ZG8zNz5rE1kJGQdJHH8FvYp025S4hiE1niq5J+K/pJF6pxkY+3Py787fDYogkBozhFy5bKgp0UI/HVFzqYaNsIdPN982aGyxId5L+n4wAfXZqdo4EvIUXXkFZEczOVcivhhwf4Fvpljme3AzC389FrXFgWcEbZJxger4IcQsFJ12jHkH2Cd1CuRVsalD6Uo0G8+V/3wsA6LbnDZFhidFBbCMUMwSroGAcE11dOIw6A5KB9hDAZmSa2/UHk3kpGGHNtYqTAh0lcX7/f420a6bAD0DuyXC0jLcprXMLLZo0W5u3HFgW+VmQBydBeHAc1Hcos4bLNQzZRJq86tZ9o5w/20harUnYlFWfgrx9t/YnvjMk5gidA18gFgXTAgso83ji8yZdTfyf1aYXJiMtgmAS7QEpDFK9GmW33y6b4P9+Id5HyHi0qvnA88O0m/RUBQq/ePD7/k9vDm96vzB1LzP3a55kPYvl11Kla0rSVycSiZVh7hlMAdxGzxj44WIIqElJ9Xp51LZGRr6Eu8aYTkFTZ+08MPXB43AuQP1jkHD4fG6ych8t+JpOjCvEDfMtBtbiaCR7jGpec0CvJQRd3RLwa8x8nLr9fvN9jlValBIMZvQrMleKfB+2w4S1B3s+4Aw7hN7J9xes7fhTosoMhx6rnNX2ree4y30xmF1g5rwZPWh2palTsQbtKz8zvgNMqUeTx4KCI8hKLfZa3ZQ3JQN8rMYbBVWjSb5fizh7Lpbp6mvwGrTOCNi3ogTgo30Bk8y0bQ= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f608747-821e-44d4-82ff-08da008c8e19 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:10.9241 (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: orjaSJdbWmmFMRCnYRhLoeCG7ww3eXI0ZGZgdAXrK+PJHP4bBC2tynJSI4Aby7Mn1QCxZ4uElra82bdvnAZiig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org "struct dw_edma_chip" contains an internal structure "struct dw_edma" that is used by the eDMA core internally. This structure should not be touched by the eDMA controller drivers themselves. But currently, the eDMA controller drivers like "dw-edma-pci" allocates and populates this internal structure then passes it on to eDMA core. The eDMA core further populates the structure and uses it. This is wrong! Hence, move all the "struct dw_edma" specifics from controller drivers to the eDMA core. Signed-off-by: Frank Li --- Resend added dmaengine@vger.kernel.org Change from v2 to v3 - none Change from v1 to v2 - rework commit message - remove duplicate field in struct dw_edma drivers/dma/dw-edma/dw-edma-core.c | 91 +++++----- drivers/dma/dw-edma/dw-edma-core.h | 30 +--- drivers/dma/dw-edma/dw-edma-v0-core.c | 206 ++++++++++++----------- drivers/dma/dw-edma/dw-edma-v0-core.h | 8 +- drivers/dma/dw-edma/dw-edma-v0-debugfs.c | 37 ++-- include/linux/dma/edma.h | 47 +++++- 6 files changed, 230 insertions(+), 189 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 53289927dd0d6..0cb66434f9e14 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -65,7 +65,7 @@ static struct dw_edma_burst *dw_edma_alloc_burst(struct dw_edma_chunk *chunk) static struct dw_edma_chunk *dw_edma_alloc_chunk(struct dw_edma_desc *desc) { struct dw_edma_chan *chan = desc->chan; - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; struct dw_edma_chunk *chunk; chunk = kzalloc(sizeof(*chunk), GFP_NOWAIT); @@ -82,11 +82,11 @@ static struct dw_edma_chunk *dw_edma_alloc_chunk(struct dw_edma_desc *desc) */ chunk->cb = !(desc->chunks_alloc % 2); if (chan->dir == EDMA_DIR_WRITE) { - chunk->ll_region.paddr = dw->ll_region_wr[chan->id].paddr; - chunk->ll_region.vaddr = dw->ll_region_wr[chan->id].vaddr; + chunk->ll_region.paddr = chip->ll_region_wr[chan->id].paddr; + chunk->ll_region.vaddr = chip->ll_region_wr[chan->id].vaddr; } else { - chunk->ll_region.paddr = dw->ll_region_rd[chan->id].paddr; - chunk->ll_region.vaddr = dw->ll_region_rd[chan->id].vaddr; + chunk->ll_region.paddr = chip->ll_region_rd[chan->id].paddr; + chunk->ll_region.vaddr = chip->ll_region_rd[chan->id].vaddr; } if (desc->chunk) { @@ -601,7 +601,8 @@ static void dw_edma_abort_interrupt(struct dw_edma_chan *chan) static irqreturn_t dw_edma_interrupt(int irq, void *data, bool write) { struct dw_edma_irq *dw_irq = data; - struct dw_edma *dw = dw_irq->dw; + struct dw_edma_chip *chip = dw_irq->chip; + struct dw_edma *dw = chip->dw; unsigned long total, pos, val; unsigned long off; u32 mask; @@ -616,7 +617,7 @@ static irqreturn_t dw_edma_interrupt(int irq, void *data, bool write) mask = dw_irq->rd_mask; } - val = dw_edma_v0_core_status_done_int(dw, write ? + val = dw_edma_v0_core_status_done_int(chip, write ? EDMA_DIR_WRITE : EDMA_DIR_READ); val &= mask; @@ -626,7 +627,7 @@ static irqreturn_t dw_edma_interrupt(int irq, void *data, bool write) dw_edma_done_interrupt(chan); } - val = dw_edma_v0_core_status_abort_int(dw, write ? + val = dw_edma_v0_core_status_abort_int(chip, write ? EDMA_DIR_WRITE : EDMA_DIR_READ); val &= mask; @@ -718,7 +719,7 @@ static int dw_edma_channel_setup(struct dw_edma_chip *chip, bool write, } INIT_LIST_HEAD(&dma->channels); - for (j = 0; (alloc || dw->nr_irqs == 1) && j < cnt; j++, i++) { + for (j = 0; (alloc || chip->nr_irqs == 1) && j < cnt; j++, i++) { chan = &dw->chan[i]; dt_region = devm_kzalloc(dev, sizeof(*dt_region), GFP_KERNEL); @@ -735,15 +736,15 @@ static int dw_edma_channel_setup(struct dw_edma_chip *chip, bool write, chan->status = EDMA_ST_IDLE; if (write) - chan->ll_max = (dw->ll_region_wr[j].sz / EDMA_LL_SZ); + chan->ll_max = (chip->ll_region_wr[j].sz / EDMA_LL_SZ); else - chan->ll_max = (dw->ll_region_rd[j].sz / EDMA_LL_SZ); + chan->ll_max = (chip->ll_region_rd[j].sz / EDMA_LL_SZ); chan->ll_max -= 1; dev_vdbg(dev, "L. List:\tChannel %s[%u] max_cnt=%u\n", write ? "write" : "read", j, chan->ll_max); - if (dw->nr_irqs == 1) + if (chip->nr_irqs == 1) pos = 0; else pos = off_alloc + (j % alloc); @@ -755,7 +756,7 @@ static int dw_edma_channel_setup(struct dw_edma_chip *chip, bool write, else irq->rd_mask |= BIT(j); - irq->dw = dw; + irq->chip = chip; memcpy(&chan->msi, &irq->msi, sizeof(chan->msi)); dev_vdbg(dev, "MSI:\t\tChannel %s[%u] addr=0x%.8x%.8x, data=0x%.8x\n", @@ -767,13 +768,13 @@ static int dw_edma_channel_setup(struct dw_edma_chip *chip, bool write, vchan_init(&chan->vc, dma); if (write) { - dt_region->paddr = dw->dt_region_wr[j].paddr; - dt_region->vaddr = dw->dt_region_wr[j].vaddr; - dt_region->sz = dw->dt_region_wr[j].sz; + dt_region->paddr = chip->dt_region_wr[j].paddr; + dt_region->vaddr = chip->dt_region_wr[j].vaddr; + dt_region->sz = chip->dt_region_wr[j].sz; } else { - dt_region->paddr = dw->dt_region_rd[j].paddr; - dt_region->vaddr = dw->dt_region_rd[j].vaddr; - dt_region->sz = dw->dt_region_rd[j].sz; + dt_region->paddr = chip->dt_region_rd[j].paddr; + dt_region->vaddr = chip->dt_region_rd[j].vaddr; + dt_region->sz = chip->dt_region_rd[j].sz; } dw_edma_v0_core_device_config(chan); @@ -840,16 +841,16 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt; - if (dw->nr_irqs < 1) + if (chip->nr_irqs < 1) return -EINVAL; - if (dw->nr_irqs == 1) { + if (chip->nr_irqs == 1) { /* Common IRQ shared among all channels */ - irq = dw->ops->irq_vector(dev, 0); + irq = chip->ops->irq_vector(dev, 0); err = request_irq(irq, dw_edma_interrupt_common, IRQF_SHARED, dw->name, &dw->irq[0]); if (err) { - dw->nr_irqs = 0; + chip->nr_irqs = 0; return err; } @@ -857,7 +858,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, get_cached_msi_msg(irq, &dw->irq[0].msi); } else { /* Distribute IRQs equally among all channels */ - int tmp = dw->nr_irqs; + int tmp = chip->nr_irqs; while (tmp && (*wr_alloc + *rd_alloc) < ch_cnt) { dw_edma_dec_irq_alloc(&tmp, wr_alloc, dw->wr_ch_cnt); @@ -868,7 +869,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt); for (i = 0; i < (*wr_alloc + *rd_alloc); i++) { - irq = dw->ops->irq_vector(dev, i); + irq = chip->ops->irq_vector(dev, i); err = request_irq(irq, i < *wr_alloc ? dw_edma_interrupt_write : @@ -876,7 +877,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, IRQF_SHARED, dw->name, &dw->irq[i]); if (err) { - dw->nr_irqs = i; + chip->nr_irqs = i; return err; } @@ -884,7 +885,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, get_cached_msi_msg(irq, &dw->irq[i].msi); } - dw->nr_irqs = i; + chip->nr_irqs = i; } return err; @@ -905,18 +906,24 @@ int dw_edma_probe(struct dw_edma_chip *chip) if (!dev) return -EINVAL; - dw = chip->dw; - if (!dw || !dw->irq || !dw->ops || !dw->ops->irq_vector) + dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL); + if (!dw) + return -ENOMEM; + + chip->dw = dw; + + if (!chip->nr_irqs || !chip->ops) return -EINVAL; raw_spin_lock_init(&dw->lock); - dw->wr_ch_cnt = min_t(u16, dw->wr_ch_cnt, - dw_edma_v0_core_ch_count(dw, EDMA_DIR_WRITE)); + + dw->wr_ch_cnt = min_t(u16, chip->ll_wr_cnt, + dw_edma_v0_core_ch_count(chip, EDMA_DIR_WRITE)); dw->wr_ch_cnt = min_t(u16, dw->wr_ch_cnt, EDMA_MAX_WR_CH); - dw->rd_ch_cnt = min_t(u16, dw->rd_ch_cnt, - dw_edma_v0_core_ch_count(dw, EDMA_DIR_READ)); + dw->rd_ch_cnt = min_t(u16, chip->ll_rd_cnt, + dw_edma_v0_core_ch_count(chip, EDMA_DIR_READ)); dw->rd_ch_cnt = min_t(u16, dw->rd_ch_cnt, EDMA_MAX_RD_CH); if (!dw->wr_ch_cnt && !dw->rd_ch_cnt) @@ -934,7 +941,11 @@ int dw_edma_probe(struct dw_edma_chip *chip) snprintf(dw->name, sizeof(dw->name), "dw-edma-core:%d", chip->id); /* Disable eDMA, only to establish the ideal initial conditions */ - dw_edma_v0_core_off(dw); + dw_edma_v0_core_off(chip); + + dw->irq = devm_kcalloc(dev, chip->nr_irqs, sizeof(*dw->irq), GFP_KERNEL); + if (!dw->irq) + return -ENOMEM; /* Request IRQs */ err = dw_edma_irq_request(chip, &wr_alloc, &rd_alloc); @@ -960,10 +971,10 @@ int dw_edma_probe(struct dw_edma_chip *chip) return 0; err_irq_free: - for (i = (dw->nr_irqs - 1); i >= 0; i--) - free_irq(dw->ops->irq_vector(dev, i), &dw->irq[i]); + for (i = (chip->nr_irqs - 1); i >= 0; i--) + free_irq(chip->ops->irq_vector(dev, i), &dw->irq[i]); - dw->nr_irqs = 0; + chip->nr_irqs = 0; return err; } @@ -977,11 +988,11 @@ int dw_edma_remove(struct dw_edma_chip *chip) int i; /* Disable eDMA */ - dw_edma_v0_core_off(dw); + dw_edma_v0_core_off(chip); /* Free irqs */ - for (i = (dw->nr_irqs - 1); i >= 0; i--) - free_irq(dw->ops->irq_vector(dev, i), &dw->irq[i]); + for (i = (chip->nr_irqs - 1); i >= 0; i--) + free_irq(chip->ops->irq_vector(dev, i), &dw->irq[i]); /* Power management */ pm_runtime_disable(dev); diff --git a/drivers/dma/dw-edma/dw-edma-core.h b/drivers/dma/dw-edma/dw-edma-core.h index 60316d408c3e0..885f6719c9462 100644 --- a/drivers/dma/dw-edma/dw-edma-core.h +++ b/drivers/dma/dw-edma/dw-edma-core.h @@ -15,20 +15,12 @@ #include "../virt-dma.h" #define EDMA_LL_SZ 24 -#define EDMA_MAX_WR_CH 8 -#define EDMA_MAX_RD_CH 8 enum dw_edma_dir { EDMA_DIR_WRITE = 0, EDMA_DIR_READ }; -enum dw_edma_map_format { - EDMA_MF_EDMA_LEGACY = 0x0, - EDMA_MF_EDMA_UNROLL = 0x1, - EDMA_MF_HDMA_COMPAT = 0x5 -}; - enum dw_edma_request { EDMA_REQ_NONE = 0, EDMA_REQ_STOP, @@ -57,12 +49,6 @@ struct dw_edma_burst { u32 sz; }; -struct dw_edma_region { - phys_addr_t paddr; - void __iomem *vaddr; - size_t sz; -}; - struct dw_edma_chunk { struct list_head list; struct dw_edma_chan *chan; @@ -106,11 +92,7 @@ struct dw_edma_irq { struct msi_msg msi; u32 wr_mask; u32 rd_mask; - struct dw_edma *dw; -}; - -struct dw_edma_core_ops { - int (*irq_vector)(struct device *dev, unsigned int nr); + struct dw_edma_chip *chip; }; struct dw_edma { @@ -122,19 +104,9 @@ struct dw_edma { struct dma_device rd_edma; u16 rd_ch_cnt; - struct dw_edma_region rg_region; /* Registers */ - struct dw_edma_region ll_region_wr[EDMA_MAX_WR_CH]; - struct dw_edma_region ll_region_rd[EDMA_MAX_RD_CH]; - struct dw_edma_region dt_region_wr[EDMA_MAX_WR_CH]; - struct dw_edma_region dt_region_rd[EDMA_MAX_RD_CH]; - struct dw_edma_irq *irq; - int nr_irqs; - - enum dw_edma_map_format mf; struct dw_edma_chan *chan; - const struct dw_edma_core_ops *ops; raw_spinlock_t lock; /* Only for legacy */ #ifdef CONFIG_DEBUG_FS diff --git a/drivers/dma/dw-edma/dw-edma-v0-core.c b/drivers/dma/dw-edma/dw-edma-v0-core.c index 329fc2e57b703..6e2f83e31a03a 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-core.c +++ b/drivers/dma/dw-edma/dw-edma-v0-core.c @@ -23,92 +23,94 @@ enum dw_edma_control { DW_EDMA_V0_LLE = BIT(9), }; -static inline struct dw_edma_v0_regs __iomem *__dw_regs(struct dw_edma *dw) +static inline struct dw_edma_v0_regs __iomem *__dw_regs(struct dw_edma_chip *chip) { - return dw->rg_region.vaddr; + return chip->reg_base; } -#define SET_32(dw, name, value) \ - writel(value, &(__dw_regs(dw)->name)) +#define SET_32(chip, name, value) \ + writel(value, &(__dw_regs(chip)->name)) -#define GET_32(dw, name) \ - readl(&(__dw_regs(dw)->name)) +#define GET_32(chip, name) \ + readl(&(__dw_regs(chip)->name)) -#define SET_RW_32(dw, dir, name, value) \ +#define SET_RW_32(chip, dir, name, value) \ do { \ if ((dir) == EDMA_DIR_WRITE) \ - SET_32(dw, wr_##name, value); \ + SET_32(chip, wr_##name, value); \ else \ - SET_32(dw, rd_##name, value); \ + SET_32(chip, rd_##name, value); \ } while (0) -#define GET_RW_32(dw, dir, name) \ +#define GET_RW_32(chip, dir, name) \ ((dir) == EDMA_DIR_WRITE \ - ? GET_32(dw, wr_##name) \ - : GET_32(dw, rd_##name)) + ? GET_32(chip, wr_##name) \ + : GET_32(chip, rd_##name)) -#define SET_BOTH_32(dw, name, value) \ +#define SET_BOTH_32(chip, name, value) \ do { \ - SET_32(dw, wr_##name, value); \ - SET_32(dw, rd_##name, value); \ + SET_32(chip, wr_##name, value); \ + SET_32(chip, rd_##name, value); \ } while (0) #ifdef CONFIG_64BIT -#define SET_64(dw, name, value) \ - writeq(value, &(__dw_regs(dw)->name)) +#define SET_64(chip, name, value) \ + writeq(value, &(__dw_regs(chip)->name)) -#define GET_64(dw, name) \ - readq(&(__dw_regs(dw)->name)) +#define GET_64(chip, name) \ + readq(&(__dw_regs(chip)->name)) -#define SET_RW_64(dw, dir, name, value) \ +#define SET_RW_64(chip, dir, name, value) \ do { \ if ((dir) == EDMA_DIR_WRITE) \ - SET_64(dw, wr_##name, value); \ + SET_64(chip, wr_##name, value); \ else \ - SET_64(dw, rd_##name, value); \ + SET_64(chip, rd_##name, value); \ } while (0) -#define GET_RW_64(dw, dir, name) \ +#define GET_RW_64(chip, dir, name) \ ((dir) == EDMA_DIR_WRITE \ - ? GET_64(dw, wr_##name) \ - : GET_64(dw, rd_##name)) + ? GET_64(chip, wr_##name) \ + : GET_64(chip, rd_##name)) -#define SET_BOTH_64(dw, name, value) \ +#define SET_BOTH_64(chip, name, value) \ do { \ - SET_64(dw, wr_##name, value); \ - SET_64(dw, rd_##name, value); \ + SET_64(chip, wr_##name, value); \ + SET_64(chip, rd_##name, value); \ } while (0) #endif /* CONFIG_64BIT */ -#define SET_COMPAT(dw, name, value) \ - writel(value, &(__dw_regs(dw)->type.unroll.name)) +#define SET_COMPAT(chip, name, value) \ + writel(value, &(__dw_regs(chip)->type.unroll.name)) -#define SET_RW_COMPAT(dw, dir, name, value) \ +#define SET_RW_COMPAT(chip, dir, name, value) \ do { \ if ((dir) == EDMA_DIR_WRITE) \ - SET_COMPAT(dw, wr_##name, value); \ + SET_COMPAT(chip, wr_##name, value); \ else \ - SET_COMPAT(dw, rd_##name, value); \ + SET_COMPAT(chip, rd_##name, value); \ } while (0) static inline struct dw_edma_v0_ch_regs __iomem * -__dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch) +__dw_ch_regs(struct dw_edma_chip *chip, enum dw_edma_dir dir, u16 ch) { - if (dw->mf == EDMA_MF_EDMA_LEGACY) - return &(__dw_regs(dw)->type.legacy.ch); + if (chip->mf == EDMA_MF_EDMA_LEGACY) + return &(__dw_regs(chip)->type.legacy.ch); if (dir == EDMA_DIR_WRITE) - return &__dw_regs(dw)->type.unroll.ch[ch].wr; + return &__dw_regs(chip)->type.unroll.ch[ch].wr; - return &__dw_regs(dw)->type.unroll.ch[ch].rd; + return &__dw_regs(chip)->type.unroll.ch[ch].rd; } -static inline void writel_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, +static inline void writel_ch(struct dw_edma_chip *chip, enum dw_edma_dir dir, u16 ch, u32 value, void __iomem *addr) { - if (dw->mf == EDMA_MF_EDMA_LEGACY) { + struct dw_edma *dw = chip->dw; + + if (chip->mf == EDMA_MF_EDMA_LEGACY) { u32 viewport_sel; unsigned long flags; @@ -119,7 +121,7 @@ static inline void writel_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, viewport_sel |= BIT(31); writel(viewport_sel, - &(__dw_regs(dw)->type.legacy.viewport_sel)); + &(__dw_regs(chip)->type.legacy.viewport_sel)); writel(value, addr); raw_spin_unlock_irqrestore(&dw->lock, flags); @@ -128,12 +130,13 @@ static inline void writel_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, } } -static inline u32 readl_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, +static inline u32 readl_ch(struct dw_edma_chip *chip, enum dw_edma_dir dir, u16 ch, const void __iomem *addr) { + struct dw_edma *dw = chip->dw; u32 value; - if (dw->mf == EDMA_MF_EDMA_LEGACY) { + if (chip->mf == EDMA_MF_EDMA_LEGACY) { u32 viewport_sel; unsigned long flags; @@ -144,7 +147,7 @@ static inline u32 readl_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, viewport_sel |= BIT(31); writel(viewport_sel, - &(__dw_regs(dw)->type.legacy.viewport_sel)); + &(__dw_regs(chip)->type.legacy.viewport_sel)); value = readl(addr); raw_spin_unlock_irqrestore(&dw->lock, flags); @@ -166,10 +169,12 @@ static inline u32 readl_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, #ifdef CONFIG_64BIT -static inline void writeq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, +static inline void writeq_ch(struct dw_edma_chip *chip, enum dw_edma_dir dir, u16 ch, u64 value, void __iomem *addr) { - if (dw->mf == EDMA_MF_EDMA_LEGACY) { + struct dw_edma *dw = chip->dw; + + if (chip->mf == EDMA_MF_EDMA_LEGACY) { u32 viewport_sel; unsigned long flags; @@ -180,7 +185,7 @@ static inline void writeq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, viewport_sel |= BIT(31); writel(viewport_sel, - &(__dw_regs(dw)->type.legacy.viewport_sel)); + &(__dw_regs(chip)->type.legacy.viewport_sel)); writeq(value, addr); raw_spin_unlock_irqrestore(&dw->lock, flags); @@ -189,12 +194,13 @@ static inline void writeq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, } } -static inline u64 readq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, +static inline u64 readq_ch(struct dw_edma_chip *chip, enum dw_edma_dir dir, u16 ch, const void __iomem *addr) { + struct dw_edma *dw = chip->dw; u32 value; - if (dw->mf == EDMA_MF_EDMA_LEGACY) { + if (chip->mf == EDMA_MF_EDMA_LEGACY) { u32 viewport_sel; unsigned long flags; @@ -205,7 +211,7 @@ static inline u64 readq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, viewport_sel |= BIT(31); writel(viewport_sel, - &(__dw_regs(dw)->type.legacy.viewport_sel)); + &(__dw_regs(chip)->type.legacy.viewport_sel)); value = readq(addr); raw_spin_unlock_irqrestore(&dw->lock, flags); @@ -228,25 +234,25 @@ static inline u64 readq_ch(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch, #endif /* CONFIG_64BIT */ /* eDMA management callbacks */ -void dw_edma_v0_core_off(struct dw_edma *dw) +void dw_edma_v0_core_off(struct dw_edma_chip *chip) { - SET_BOTH_32(dw, int_mask, + SET_BOTH_32(chip, int_mask, EDMA_V0_DONE_INT_MASK | EDMA_V0_ABORT_INT_MASK); - SET_BOTH_32(dw, int_clear, + SET_BOTH_32(chip, int_clear, EDMA_V0_DONE_INT_MASK | EDMA_V0_ABORT_INT_MASK); - SET_BOTH_32(dw, engine_en, 0); + SET_BOTH_32(chip, engine_en, 0); } -u16 dw_edma_v0_core_ch_count(struct dw_edma *dw, enum dw_edma_dir dir) +u16 dw_edma_v0_core_ch_count(struct dw_edma_chip *chip, enum dw_edma_dir dir) { u32 num_ch; if (dir == EDMA_DIR_WRITE) num_ch = FIELD_GET(EDMA_V0_WRITE_CH_COUNT_MASK, - GET_32(dw, ctrl)); + GET_32(chip, ctrl)); else num_ch = FIELD_GET(EDMA_V0_READ_CH_COUNT_MASK, - GET_32(dw, ctrl)); + GET_32(chip, ctrl)); if (num_ch > EDMA_V0_MAX_NR_CH) num_ch = EDMA_V0_MAX_NR_CH; @@ -256,11 +262,11 @@ u16 dw_edma_v0_core_ch_count(struct dw_edma *dw, enum dw_edma_dir dir) enum dma_status dw_edma_v0_core_ch_status(struct dw_edma_chan *chan) { - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; u32 tmp; tmp = FIELD_GET(EDMA_V0_CH_STATUS_MASK, - GET_CH_32(dw, chan->dir, chan->id, ch_control1)); + GET_CH_32(chip, chan->dir, chan->id, ch_control1)); if (tmp == 1) return DMA_IN_PROGRESS; @@ -272,30 +278,30 @@ enum dma_status dw_edma_v0_core_ch_status(struct dw_edma_chan *chan) void dw_edma_v0_core_clear_done_int(struct dw_edma_chan *chan) { - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; - SET_RW_32(dw, chan->dir, int_clear, + SET_RW_32(chip, chan->dir, int_clear, FIELD_PREP(EDMA_V0_DONE_INT_MASK, BIT(chan->id))); } void dw_edma_v0_core_clear_abort_int(struct dw_edma_chan *chan) { - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; - SET_RW_32(dw, chan->dir, int_clear, + SET_RW_32(chip, chan->dir, int_clear, FIELD_PREP(EDMA_V0_ABORT_INT_MASK, BIT(chan->id))); } -u32 dw_edma_v0_core_status_done_int(struct dw_edma *dw, enum dw_edma_dir dir) +u32 dw_edma_v0_core_status_done_int(struct dw_edma_chip *chip, enum dw_edma_dir dir) { return FIELD_GET(EDMA_V0_DONE_INT_MASK, - GET_RW_32(dw, dir, int_status)); + GET_RW_32(chip, dir, int_status)); } -u32 dw_edma_v0_core_status_abort_int(struct dw_edma *dw, enum dw_edma_dir dir) +u32 dw_edma_v0_core_status_abort_int(struct dw_edma_chip *chip, enum dw_edma_dir dir) { return FIELD_GET(EDMA_V0_ABORT_INT_MASK, - GET_RW_32(dw, dir, int_status)); + GET_RW_32(chip, dir, int_status)); } static void dw_edma_v0_core_write_chunk(struct dw_edma_chunk *chunk) @@ -357,109 +363,109 @@ static void dw_edma_v0_core_write_chunk(struct dw_edma_chunk *chunk) void dw_edma_v0_core_start(struct dw_edma_chunk *chunk, bool first) { struct dw_edma_chan *chan = chunk->chan; - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; u32 tmp; dw_edma_v0_core_write_chunk(chunk); if (first) { /* Enable engine */ - SET_RW_32(dw, chan->dir, engine_en, BIT(0)); - if (dw->mf == EDMA_MF_HDMA_COMPAT) { + SET_RW_32(chip, chan->dir, engine_en, BIT(0)); + if (chip->mf == EDMA_MF_HDMA_COMPAT) { switch (chan->id) { case 0: - SET_RW_COMPAT(dw, chan->dir, ch0_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch0_pwr_en, BIT(0)); break; case 1: - SET_RW_COMPAT(dw, chan->dir, ch1_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch1_pwr_en, BIT(0)); break; case 2: - SET_RW_COMPAT(dw, chan->dir, ch2_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch2_pwr_en, BIT(0)); break; case 3: - SET_RW_COMPAT(dw, chan->dir, ch3_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch3_pwr_en, BIT(0)); break; case 4: - SET_RW_COMPAT(dw, chan->dir, ch4_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch4_pwr_en, BIT(0)); break; case 5: - SET_RW_COMPAT(dw, chan->dir, ch5_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch5_pwr_en, BIT(0)); break; case 6: - SET_RW_COMPAT(dw, chan->dir, ch6_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch6_pwr_en, BIT(0)); break; case 7: - SET_RW_COMPAT(dw, chan->dir, ch7_pwr_en, + SET_RW_COMPAT(chip, chan->dir, ch7_pwr_en, BIT(0)); break; } } /* Interrupt unmask - done, abort */ - tmp = GET_RW_32(dw, chan->dir, int_mask); + tmp = GET_RW_32(chip, chan->dir, int_mask); tmp &= ~FIELD_PREP(EDMA_V0_DONE_INT_MASK, BIT(chan->id)); tmp &= ~FIELD_PREP(EDMA_V0_ABORT_INT_MASK, BIT(chan->id)); - SET_RW_32(dw, chan->dir, int_mask, tmp); + SET_RW_32(chip, chan->dir, int_mask, tmp); /* Linked list error */ - tmp = GET_RW_32(dw, chan->dir, linked_list_err_en); + tmp = GET_RW_32(chip, chan->dir, linked_list_err_en); tmp |= FIELD_PREP(EDMA_V0_LINKED_LIST_ERR_MASK, BIT(chan->id)); - SET_RW_32(dw, chan->dir, linked_list_err_en, tmp); + SET_RW_32(chip, chan->dir, linked_list_err_en, tmp); /* Channel control */ - SET_CH_32(dw, chan->dir, chan->id, ch_control1, + SET_CH_32(chip, chan->dir, chan->id, ch_control1, (DW_EDMA_V0_CCS | DW_EDMA_V0_LLE)); /* Linked list */ #ifdef CONFIG_64BIT - SET_CH_64(dw, chan->dir, chan->id, llp.reg, + SET_CH_64(chip, chan->dir, chan->id, llp.reg, chunk->ll_region.paddr); #else /* CONFIG_64BIT */ - SET_CH_32(dw, chan->dir, chan->id, llp.lsb, + SET_CH_32(chip, chan->dir, chan->id, llp.lsb, lower_32_bits(chunk->ll_region.paddr)); - SET_CH_32(dw, chan->dir, chan->id, llp.msb, + SET_CH_32(chip, chan->dir, chan->id, llp.msb, upper_32_bits(chunk->ll_region.paddr)); #endif /* CONFIG_64BIT */ } /* Doorbell */ - SET_RW_32(dw, chan->dir, doorbell, + SET_RW_32(chip, chan->dir, doorbell, FIELD_PREP(EDMA_V0_DOORBELL_CH_MASK, chan->id)); } int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) { - struct dw_edma *dw = chan->chip->dw; + struct dw_edma_chip *chip = chan->chip; u32 tmp = 0; /* MSI done addr - low, high */ - SET_RW_32(dw, chan->dir, done_imwr.lsb, chan->msi.address_lo); - SET_RW_32(dw, chan->dir, done_imwr.msb, chan->msi.address_hi); + SET_RW_32(chip, chan->dir, done_imwr.lsb, chan->msi.address_lo); + SET_RW_32(chip, chan->dir, done_imwr.msb, chan->msi.address_hi); /* MSI abort addr - low, high */ - SET_RW_32(dw, chan->dir, abort_imwr.lsb, chan->msi.address_lo); - SET_RW_32(dw, chan->dir, abort_imwr.msb, chan->msi.address_hi); + SET_RW_32(chip, chan->dir, abort_imwr.lsb, chan->msi.address_lo); + SET_RW_32(chip, chan->dir, abort_imwr.msb, chan->msi.address_hi); /* MSI data - low, high */ switch (chan->id) { case 0: case 1: - tmp = GET_RW_32(dw, chan->dir, ch01_imwr_data); + tmp = GET_RW_32(chip, chan->dir, ch01_imwr_data); break; case 2: case 3: - tmp = GET_RW_32(dw, chan->dir, ch23_imwr_data); + tmp = GET_RW_32(chip, chan->dir, ch23_imwr_data); break; case 4: case 5: - tmp = GET_RW_32(dw, chan->dir, ch45_imwr_data); + tmp = GET_RW_32(chip, chan->dir, ch45_imwr_data); break; case 6: case 7: - tmp = GET_RW_32(dw, chan->dir, ch67_imwr_data); + tmp = GET_RW_32(chip, chan->dir, ch67_imwr_data); break; } @@ -478,22 +484,22 @@ int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) switch (chan->id) { case 0: case 1: - SET_RW_32(dw, chan->dir, ch01_imwr_data, tmp); + SET_RW_32(chip, chan->dir, ch01_imwr_data, tmp); break; case 2: case 3: - SET_RW_32(dw, chan->dir, ch23_imwr_data, tmp); + SET_RW_32(chip, chan->dir, ch23_imwr_data, tmp); break; case 4: case 5: - SET_RW_32(dw, chan->dir, ch45_imwr_data, tmp); + SET_RW_32(chip, chan->dir, ch45_imwr_data, tmp); break; case 6: case 7: - SET_RW_32(dw, chan->dir, ch67_imwr_data, tmp); + SET_RW_32(chip, chan->dir, ch67_imwr_data, tmp); break; } diff --git a/drivers/dma/dw-edma/dw-edma-v0-core.h b/drivers/dma/dw-edma/dw-edma-v0-core.h index 2afa626b8300c..01a29c74c0c43 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-core.h +++ b/drivers/dma/dw-edma/dw-edma-v0-core.h @@ -12,13 +12,13 @@ #include /* eDMA management callbacks */ -void dw_edma_v0_core_off(struct dw_edma *chan); -u16 dw_edma_v0_core_ch_count(struct dw_edma *chan, enum dw_edma_dir dir); +void dw_edma_v0_core_off(struct dw_edma_chip *chip); +u16 dw_edma_v0_core_ch_count(struct dw_edma_chip *chip, enum dw_edma_dir dir); enum dma_status dw_edma_v0_core_ch_status(struct dw_edma_chan *chan); void dw_edma_v0_core_clear_done_int(struct dw_edma_chan *chan); void dw_edma_v0_core_clear_abort_int(struct dw_edma_chan *chan); -u32 dw_edma_v0_core_status_done_int(struct dw_edma *chan, enum dw_edma_dir dir); -u32 dw_edma_v0_core_status_abort_int(struct dw_edma *chan, enum dw_edma_dir dir); +u32 dw_edma_v0_core_status_done_int(struct dw_edma_chip *chip, enum dw_edma_dir dir); +u32 dw_edma_v0_core_status_abort_int(struct dw_edma_chip *chip, enum dw_edma_dir dir); void dw_edma_v0_core_start(struct dw_edma_chunk *chunk, bool first); int dw_edma_v0_core_device_config(struct dw_edma_chan *chan); /* eDMA debug fs callbacks */ diff --git a/drivers/dma/dw-edma/dw-edma-v0-debugfs.c b/drivers/dma/dw-edma/dw-edma-v0-debugfs.c index 4b3bcffd15ef1..5819a64aceb0f 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-debugfs.c +++ b/drivers/dma/dw-edma/dw-edma-v0-debugfs.c @@ -38,7 +38,7 @@ #define CHANNEL_STR "channel" #define REGISTERS_STR "registers" -static struct dw_edma *dw; +static struct dw_edma_chip *chip; static struct dw_edma_v0_regs __iomem *regs; static struct { @@ -53,8 +53,10 @@ struct debugfs_entries { static int dw_edma_debugfs_u32_get(void *data, u64 *val) { + struct dw_edma *dw = chip->dw; + void __iomem *reg = (void __force __iomem *)data; - if (dw->mf == EDMA_MF_EDMA_LEGACY && + if (chip->mf == EDMA_MF_EDMA_LEGACY && reg >= (void __iomem *)®s->type.legacy.ch) { void __iomem *ptr = ®s->type.legacy.ch; u32 viewport_sel = 0; @@ -127,6 +129,8 @@ static void dw_edma_debugfs_regs_ch(struct dw_edma_v0_ch_regs __iomem *regs, static void dw_edma_debugfs_regs_wr(struct dentry *dir) { + struct dw_edma *dw = chip->dw; + const struct debugfs_entries debugfs_regs[] = { /* eDMA global registers */ WR_REGISTER(engine_en), @@ -173,7 +177,7 @@ static void dw_edma_debugfs_regs_wr(struct dentry *dir) nr_entries = ARRAY_SIZE(debugfs_regs); dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir); - if (dw->mf == EDMA_MF_HDMA_COMPAT) { + if (chip->mf == EDMA_MF_HDMA_COMPAT) { nr_entries = ARRAY_SIZE(debugfs_unroll_regs); dw_edma_debugfs_create_x32(debugfs_unroll_regs, nr_entries, regs_dir); @@ -195,6 +199,8 @@ static void dw_edma_debugfs_regs_wr(struct dentry *dir) static void dw_edma_debugfs_regs_rd(struct dentry *dir) { + struct dw_edma *dw = chip->dw; + const struct debugfs_entries debugfs_regs[] = { /* eDMA global registers */ RD_REGISTER(engine_en), @@ -242,7 +248,7 @@ static void dw_edma_debugfs_regs_rd(struct dentry *dir) nr_entries = ARRAY_SIZE(debugfs_regs); dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir); - if (dw->mf == EDMA_MF_HDMA_COMPAT) { + if (chip->mf == EDMA_MF_HDMA_COMPAT) { nr_entries = ARRAY_SIZE(debugfs_unroll_regs); dw_edma_debugfs_create_x32(debugfs_unroll_regs, nr_entries, regs_dir); @@ -264,6 +270,7 @@ static void dw_edma_debugfs_regs_rd(struct dentry *dir) static void dw_edma_debugfs_regs(void) { + struct dw_edma *dw = chip->dw; const struct debugfs_entries debugfs_regs[] = { REGISTER(ctrl_data_arb_prior), REGISTER(ctrl), @@ -282,13 +289,15 @@ static void dw_edma_debugfs_regs(void) dw_edma_debugfs_regs_rd(regs_dir); } -void dw_edma_v0_debugfs_on(struct dw_edma_chip *chip) +void dw_edma_v0_debugfs_on(struct dw_edma_chip *p) { - dw = chip->dw; - if (!dw) + struct dw_edma *dw; + chip = p; + if (!chip) return; - regs = dw->rg_region.vaddr; + dw = chip->dw; + regs = chip->reg_base; if (!regs) return; @@ -296,19 +305,19 @@ void dw_edma_v0_debugfs_on(struct dw_edma_chip *chip) if (!dw->debugfs) return; - debugfs_create_u32("mf", 0444, dw->debugfs, &dw->mf); + debugfs_create_u32("mf", 0444, dw->debugfs, &chip->mf); debugfs_create_u16("wr_ch_cnt", 0444, dw->debugfs, &dw->wr_ch_cnt); debugfs_create_u16("rd_ch_cnt", 0444, dw->debugfs, &dw->rd_ch_cnt); dw_edma_debugfs_regs(); } -void dw_edma_v0_debugfs_off(struct dw_edma_chip *chip) +void dw_edma_v0_debugfs_off(struct dw_edma_chip *p) { - dw = chip->dw; - if (!dw) + chip = p; + if (!chip) return; - debugfs_remove_recursive(dw->debugfs); - dw->debugfs = NULL; + debugfs_remove_recursive(chip->dw->debugfs); + chip->dw->debugfs = NULL; } diff --git a/include/linux/dma/edma.h b/include/linux/dma/edma.h index cab6e18773dad..fcfbc0f47f83d 100644 --- a/include/linux/dma/edma.h +++ b/include/linux/dma/edma.h @@ -12,19 +12,62 @@ #include #include +#define EDMA_MAX_WR_CH 8 +#define EDMA_MAX_RD_CH 8 + struct dw_edma; +struct dw_edma_region { + phys_addr_t paddr; + void __iomem *vaddr; + size_t sz; +}; + +struct dw_edma_core_ops { + int (*irq_vector)(struct device *dev, unsigned int nr); +}; + +enum dw_edma_map_format { + EDMA_MF_EDMA_LEGACY = 0x0, + EDMA_MF_EDMA_UNROLL = 0x1, + EDMA_MF_HDMA_COMPAT = 0x5 +}; + /** * struct dw_edma_chip - representation of DesignWare eDMA controller hardware * @dev: struct device of the eDMA controller * @id: instance ID - * @irq: irq line + * @nr_irqs: total dma irq number + * reg64bit if support 64bit write to register + * @ops DMA channel to IRQ number mapping + * @wr_ch_cnt DMA write channel number + * @rd_ch_cnt DMA read channel number + * @rg_region DMA register region + * @ll_region_wr DMA descriptor link list memory for write channel + * @ll_region_rd DMA descriptor link list memory for read channel + * @mf DMA register map format * @dw: struct dw_edma that is filed by dw_edma_probe() */ struct dw_edma_chip { struct device *dev; int id; - int irq; + int nr_irqs; + const struct dw_edma_core_ops *ops; + + void __iomem *reg_base; + + u16 ll_wr_cnt; + u16 ll_rd_cnt; + /* link list address */ + struct dw_edma_region ll_region_wr[EDMA_MAX_WR_CH]; + struct dw_edma_region ll_region_rd[EDMA_MAX_RD_CH]; + + /* data region */ + struct dw_edma_region dt_region_wr[EDMA_MAX_WR_CH]; + struct dw_edma_region dt_region_rd[EDMA_MAX_RD_CH]; + + enum dw_edma_map_format mf; + struct dw_edma *dw; }; From patchwork Mon Mar 7 22:47:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772682 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09F8DC43217 for ; Mon, 7 Mar 2022 22:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343862AbiCGWtP (ORCPT ); Mon, 7 Mar 2022 17:49:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343868AbiCGWtP (ORCPT ); Mon, 7 Mar 2022 17:49:15 -0500 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30049.outbound.protection.outlook.com [40.107.3.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36498427DA; Mon, 7 Mar 2022 14:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JoB3HFnnIVy49Lee6AIBwXMnpPXVqbKyrs9hqsRWMEGFLKjigvBQjtDCWkG68tCwMLNC0uX1RUJNe4TJPt/+baljHfh8yt6iYCFpRwb3ZUP3xXh/jhiqKcr+lJGfLV3cqGRqj+2FAtTvmPLSgXefh/lu5BxRlbB+87xgQJHqrwAXKz1m5wdum17hkhKrq6jp5k0KniFwC4fQD+zGKoQGpYB0F9C2Bfmj1nLLA3vutTENe0LhvEzc/HegKrihdThuQGszLrF4VHqjtSV3IsmCaqxdaMbjCYHqjMcbTVLTtDy1QDwVmdbKuz1pMlMN9isKogjJFfBGgfFaY2dOrmCkXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Na2Jn1mnd+uVQ/dr1ZxQQdm3fD6ZbASMttQxtoRvPJI=; b=RzqCMYkjvfTdSyaVTcAJLOeM6dn75qDu02zdrlAOPHHycesiieEo8i4WbSXmqRtYWU2o3llOoiQcge+4l/VGrDXATelqTtk4XYDsFVc/VESo1nJAuF6w2pDhN34XL2fcRu0eMP5zZZoIxb8wpz4+xP14uPkY7g4Fmk/IG5DAsxZ8DHCCdAkfCeXTQduefoNNsd8WhDseE4nVejkiSp3wiyo0PE86ZfpCayy/cGyqyPw6QpI4HRRNm73SbQkiBxNV8UNXHMQSAialgbYTdaGsv3L3LU3Gi2KeoHGeng/T9IEL+zuepVS4HjEwknzZVM2q3usSSPtvK3Ci7uv/pE+/JQ== 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=Na2Jn1mnd+uVQ/dr1ZxQQdm3fD6ZbASMttQxtoRvPJI=; b=brlk1T7UYpjoJG4U499rfvjE6QQT67guAwjtwx61D8VpPKkRbq9xQWJ8NtVSB/BqPdH2nFyoVDiVm9lWB0D7G7iXf4N9z2KZoS5tRZ3uydXOpQ965hm+vFQXj/IUVy9ZEx6Z10LtvCuxBiE4R0XY2zxOWiIcm3ewQObPLbzrPzM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:15 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:14 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 2/6] dmaengine: dw-edma-pcie: don't touch internal struct dw_edma Date: Mon, 7 Mar 2022 16:47:46 -0600 Message-Id: <20220307224750.18055-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20220307224750.18055-1-Frank.Li@nxp.com> References: <20220307224750.18055-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9fda10d0-f38c-4262-d720-08da008c9079 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tslT/+DgEQvAw/i9Lnni0ngrvC5Tj/89MLTLJBEjan6oK9ncAf4CY6Wdl/DhpB5wm42Pdw/SBxoxfv/n7D9lP+I5DU7v0EA4mP+M+PS3eXDYHD33kxQ9GDNDBagpMiVtEnHSNMWLn8p3FtehDi3kQDqGsib4I+w7TZiiNdGAUm3TVIUDttgqdh1Q9UhZldAPR40uQib4mn4zYYQdG8loHXdZvs7iYGJYSkAkRPXJG9X6TOkpidIejHo1kSahdFHWcxpsSgKqVBffESzV2lrY936EPgFclJsb4UeUMDZiCMWaWlOwpXRQaMDxl7/JOQ8R+oT3JllVmStvvl5fYtdbtx4tW6lkFUfLdZ9yun8yYTpBxxkoO42cPXD5Mrw0WYsbmyTxRuL3nBR4BkMFkjzszyE8J3L8XScSsWySPetAXjOtAuEr3m3+IWadUUOh9hLMGqv0OZlP3BpdtAapNYumBpm0RXow8OB0tXGn5E2//zVNOce/cc/SPeWfwCPQTkLSNMrHueLAah5UUmlLLDcxd4ygXKPNGu10dTxKAs0DwxU+Ay7ZMXGeCLzqV3vs38wOpiQSJ74bYmp4eV4zFDjCn70yg9kb+zZrcszNwrZg2nFlSg5ecDSAqhZ5+rjlZV4RIyERhaIWJjed1axGnE2hyXtGPUZhmZ3kxQWT/5cFFXi4wjqzu9DUB82glustkaBRMJei6DDdc9alAU4kP8ULIg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(8676002)(508600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(316002)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WSGkPGDG3zekNQQNocsYSsvk/VPeZI7To9Ft6rwLlTd2xvf9/RW3XmJ+3vndfojnnQaMqheDxa2xweiWIxDGbqhNvUVpqB425BsiuQAhWjJXajaw6PfFLhpgb/eDclC1lMmqTiCfNbOn60FCKL8kkZI5AkI3R1/FFOcNvAgZbIUWDcaRbCtD2Rxc3yceHpuE0suru7fBJbjTB+k/WbLNvo3OhNmwwmqYaxvtu6ZynLEKU4tytTUCQ+muwimcZOOstSB8FzmiXZZ7xWiJqYVjIArKpy//AdDmU5yhK6CV7H6qIyYXzcKBu1QNof/t0jbnmyuhBDcArRzxji5yVn7lAgwd2l7rOECnVEQAWjS6wW9a91vjhVCB+eR9tZMuLaF9acVY3Pw8aZIUGkhES1GGg/n4OzTxa7dGneyUytd4rjSWQoqvmExfbvrjv3Dc9MG+09e+mWcAJPTglIBpPOVV7ORIyTB4QRblZMFCU8gnAFJ0Udes1020fd1D2Ktz4a1GQPdvQZfT+jm+LafGrAofR4djNvDuECURXzHTBmgqD+R/HOyfVTIl2cwyJXBNc7iNq8KZ3k/nMQy4RslHVmTAazMg3yY6C9K7uH5lbwzcaM9/UpdhkPc/DNwUb/N7RFNk/XGpdIfqRiDUNQdpqcCjK0+g9LOUcYMF9E3A/qspMyoSYdN8RTaSEcXq5Py1Je4AOtMywDmnKRhQRnl7t3tx9kOoVF/SG8v+TiwZH/ZMWzm2pwx9OGEPHVk6sImyobo1ze5++GmkXEQGaSpBYw4ZNwcWRwJj4s8GWIoYCuBDd6uEC0X8UdiG1F+ZC6fCckmEsk0cmAa+yYbPu+VIY+ABC2oEuRk53KU/dzVajY0scb+r37vNq1oV7NVr6PrLo/v/8MwruofopxAajEQuidflMsRq/HwArlqTFJ86Gw3ZTkxsIGV/2aK5dBdjKthPh3Yc/KZfC4tSR9nwBtRfSHx7KddT6if4d1xBsywdxYT3iiAKf6rbQjGPR+UM0cUhMHjvuS16Q2XF0Q5Be6BEJG0jx/Whwafg6wFmoyLLqklxiKclSI7myfV2VBMAf2NNl/ThETw9TFU3hP+1vSxzbKg5t9akVZ+mLuReAlFGUgfKyufdRxnNcBxj76cuR/zxapmni4MkFgc7YF9jME+y34p3aMEJIClHIBDsJm/cgQomxwl9fQwQQfxjEVlRVUL8uK1UgZdw7Ls8Sm5FQz75ifscA1mR4jTica+1lHVt8o7gSEBAaM+qJVc6xARq2Bcisz7dsXOCNwccJhemx+//CydS25DFHDsP2s2GvODlwtQKuiiUAKVu7lfZXwFGbiXIzgxhxvH2rIhopnq1kTbKtsbGSpKGLDWOVnN8Zr+PxmHLW7NjcowG43KwX3lVZ2q7l+HW7r93fBtY6/DW4IpHzLzGHlzjnjpW/Yi0/AvKdFVu/tHjdm/t/h5F8CgILTdSKvKuH8Rlbe9nTm7XL11tm8dJtiIZgyBdJEYRdG7ubR8UlLqO5TKJsodJcXGqRsbnal65Q6mh+LMy/v65Kud7uT2u3tegFI+sz2fU/PDp0ocFrqzBd7OFYb5009Hbey2euB/U0YDgdyDziOzBNpSbt7+uN1hOwunlOn0IIU0M9jWRfdg= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fda10d0-f38c-4262-d720-08da008c9079 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:14.8786 (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: OevbTJxXdo99utnPYKH/MPQjTaDObJn1IN8+HSiYlFPuqT809sR6K2gPqK78IAK0ZRCuKDgji2GVwbspXct0+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org "struct dw_edma" is an internal structure of the eDMA core. This should not be used by the eDMA controllers like "dw-edma-pcie" for passing the controller specific information to the core. Instead, use the fields local to the "struct dw_edma_chip" for passing the controller specific info to the core. Signed-off-by: Frank Li --- Resend added dmaengine@vger.kernel.org Change from v2 to v3: None Change from v1 to v2: - rework commit message - rg_region only use virtual address. using chip->reg_base instead drivers/dma/dw-edma/dw-edma-pcie.c | 83 ++++++++++++------------------ 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-pcie.c b/drivers/dma/dw-edma/dw-edma-pcie.c index 44f6e09bdb531..7732537f96086 100644 --- a/drivers/dma/dw-edma/dw-edma-pcie.c +++ b/drivers/dma/dw-edma/dw-edma-pcie.c @@ -148,7 +148,6 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, struct dw_edma_pcie_data vsec_data; struct device *dev = &pdev->dev; struct dw_edma_chip *chip; - struct dw_edma *dw; int err, nr_irqs; int i, mask; @@ -214,10 +213,6 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, if (!chip) return -ENOMEM; - dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL); - if (!dw) - return -ENOMEM; - /* IRQs allocation */ nr_irqs = pci_alloc_irq_vectors(pdev, 1, vsec_data.irqs, PCI_IRQ_MSI | PCI_IRQ_MSIX); @@ -228,29 +223,23 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, } /* Data structure initialization */ - chip->dw = dw; chip->dev = dev; chip->id = pdev->devfn; - chip->irq = pdev->irq; - dw->mf = vsec_data.mf; - dw->nr_irqs = nr_irqs; - dw->ops = &dw_edma_pcie_core_ops; - dw->wr_ch_cnt = vsec_data.wr_ch_cnt; - dw->rd_ch_cnt = vsec_data.rd_ch_cnt; + chip->mf = vsec_data.mf; + chip->nr_irqs = nr_irqs; + chip->ops = &dw_edma_pcie_core_ops; - dw->rg_region.vaddr = pcim_iomap_table(pdev)[vsec_data.rg.bar]; - if (!dw->rg_region.vaddr) - return -ENOMEM; + chip->ll_wr_cnt = vsec_data.wr_ch_cnt; + chip->ll_rd_cnt = vsec_data.rd_ch_cnt; - dw->rg_region.vaddr += vsec_data.rg.off; - dw->rg_region.paddr = pdev->resource[vsec_data.rg.bar].start; - dw->rg_region.paddr += vsec_data.rg.off; - dw->rg_region.sz = vsec_data.rg.sz; + chip->reg_base = pcim_iomap_table(pdev)[vsec_data.rg.bar]; + if (!chip->reg_base) + return -ENOMEM; - for (i = 0; i < dw->wr_ch_cnt; i++) { - struct dw_edma_region *ll_region = &dw->ll_region_wr[i]; - struct dw_edma_region *dt_region = &dw->dt_region_wr[i]; + for (i = 0; i < chip->ll_wr_cnt; i++) { + struct dw_edma_region *ll_region = &chip->ll_region_wr[i]; + struct dw_edma_region *dt_region = &chip->dt_region_wr[i]; struct dw_edma_block *ll_block = &vsec_data.ll_wr[i]; struct dw_edma_block *dt_block = &vsec_data.dt_wr[i]; @@ -273,9 +262,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, dt_region->sz = dt_block->sz; } - for (i = 0; i < dw->rd_ch_cnt; i++) { - struct dw_edma_region *ll_region = &dw->ll_region_rd[i]; - struct dw_edma_region *dt_region = &dw->dt_region_rd[i]; + for (i = 0; i < chip->ll_rd_cnt; i++) { + struct dw_edma_region *ll_region = &chip->ll_region_rd[i]; + struct dw_edma_region *dt_region = &chip->dt_region_rd[i]; struct dw_edma_block *ll_block = &vsec_data.ll_rd[i]; struct dw_edma_block *dt_block = &vsec_data.dt_rd[i]; @@ -299,45 +288,45 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, } /* Debug info */ - if (dw->mf == EDMA_MF_EDMA_LEGACY) - pci_dbg(pdev, "Version:\teDMA Port Logic (0x%x)\n", dw->mf); - else if (dw->mf == EDMA_MF_EDMA_UNROLL) - pci_dbg(pdev, "Version:\teDMA Unroll (0x%x)\n", dw->mf); - else if (dw->mf == EDMA_MF_HDMA_COMPAT) - pci_dbg(pdev, "Version:\tHDMA Compatible (0x%x)\n", dw->mf); + if (chip->mf == EDMA_MF_EDMA_LEGACY) + pci_dbg(pdev, "Version:\teDMA Port Logic (0x%x)\n", chip->mf); + else if (chip->mf == EDMA_MF_EDMA_UNROLL) + pci_dbg(pdev, "Version:\teDMA Unroll (0x%x)\n", chip->mf); + else if (chip->mf == EDMA_MF_HDMA_COMPAT) + pci_dbg(pdev, "Version:\tHDMA Compatible (0x%x)\n", chip->mf); else - pci_dbg(pdev, "Version:\tUnknown (0x%x)\n", dw->mf); + pci_dbg(pdev, "Version:\tUnknown (0x%x)\n", chip->mf); - pci_dbg(pdev, "Registers:\tBAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p, p=%pa)\n", + pci_dbg(pdev, "Registers:\tBAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p)\n", vsec_data.rg.bar, vsec_data.rg.off, vsec_data.rg.sz, - dw->rg_region.vaddr, &dw->rg_region.paddr); + chip->reg_base); - for (i = 0; i < dw->wr_ch_cnt; i++) { + for (i = 0; i < chip->ll_wr_cnt; i++) { pci_dbg(pdev, "L. List:\tWRITE CH%.2u, BAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p, p=%pa)\n", i, vsec_data.ll_wr[i].bar, - vsec_data.ll_wr[i].off, dw->ll_region_wr[i].sz, - dw->ll_region_wr[i].vaddr, &dw->ll_region_wr[i].paddr); + vsec_data.ll_wr[i].off, chip->ll_region_wr[i].sz, + chip->ll_region_wr[i].vaddr, &chip->ll_region_wr[i].paddr); pci_dbg(pdev, "Data:\tWRITE CH%.2u, BAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p, p=%pa)\n", i, vsec_data.dt_wr[i].bar, - vsec_data.dt_wr[i].off, dw->dt_region_wr[i].sz, - dw->dt_region_wr[i].vaddr, &dw->dt_region_wr[i].paddr); + vsec_data.dt_wr[i].off, chip->dt_region_wr[i].sz, + chip->dt_region_wr[i].vaddr, &chip->dt_region_wr[i].paddr); } - for (i = 0; i < dw->rd_ch_cnt; i++) { + for (i = 0; i < chip->ll_rd_cnt; i++) { pci_dbg(pdev, "L. List:\tREAD CH%.2u, BAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p, p=%pa)\n", i, vsec_data.ll_rd[i].bar, - vsec_data.ll_rd[i].off, dw->ll_region_rd[i].sz, - dw->ll_region_rd[i].vaddr, &dw->ll_region_rd[i].paddr); + vsec_data.ll_rd[i].off, chip->ll_region_rd[i].sz, + chip->ll_region_rd[i].vaddr, &chip->ll_region_rd[i].paddr); pci_dbg(pdev, "Data:\tREAD CH%.2u, BAR=%u, off=0x%.8lx, sz=0x%zx bytes, addr(v=%p, p=%pa)\n", i, vsec_data.dt_rd[i].bar, - vsec_data.dt_rd[i].off, dw->dt_region_rd[i].sz, - dw->dt_region_rd[i].vaddr, &dw->dt_region_rd[i].paddr); + vsec_data.dt_rd[i].off, chip->dt_region_rd[i].sz, + chip->dt_region_rd[i].vaddr, &chip->dt_region_rd[i].paddr); } - pci_dbg(pdev, "Nr. IRQs:\t%u\n", dw->nr_irqs); + pci_dbg(pdev, "Nr. IRQs:\t%u\n", chip->nr_irqs); /* Validating if PCI interrupts were enabled */ if (!pci_dev_msi_enabled(pdev)) { @@ -345,10 +334,6 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, return -EPERM; } - dw->irq = devm_kcalloc(dev, nr_irqs, sizeof(*dw->irq), GFP_KERNEL); - if (!dw->irq) - return -ENOMEM; - /* Starting eDMA driver */ err = dw_edma_probe(chip); if (err) { From patchwork Mon Mar 7 22:47:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6954C433FE for ; Mon, 7 Mar 2022 22:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343872AbiCGWtS (ORCPT ); Mon, 7 Mar 2022 17:49:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343870AbiCGWtR (ORCPT ); Mon, 7 Mar 2022 17:49:17 -0500 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30049.outbound.protection.outlook.com [40.107.3.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FFB4496B9; Mon, 7 Mar 2022 14:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CfbVL+Z5/dXzplanOlbof0dgh2m1BciRfTb2DL195mR2GRlTqMNIrNcvkp6L+I3uwf9kTrpro8Hj5odNcPrXRjZCqE6lxepdo54zc5ss7Fju+8NhayaxpmFVn0uISRnZT2xi1Ff76lOZlF+FObCWoMc4fS1w2em3mG8qHWTvB7F+Y8XMnR3TPhp4ZjYofBlANXVb6Z0klDJVdpExUvG7qjc4i8gnQqdS6XsvIb2AUiZ+tIRXO3zj+m2wGDDHne+NEFnbppqZILo2dgfmfduToaVKnqZxd/R2ATYU2hQXfZKGZSAzb148My1IhN2xsvsRtl2lmtdLOCOz1NuvkdU0qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=mm5Nao0dQd84uxVyUjyUfIocDzQS3Lopu4mkKoG1/6k=; b=Tf01hKISM+WpExh7K4NHyr24SleyLbxYkHseKrJ0+4GDCwHR9LNV/gfHpxANUke/y7lKaRalN+pz9l/UpDn787XAH4wzvk/2fFmWdHLVnUu15GPu5Gl+N6+cxikH7CnHQrdExL9R6v9xSZgY75eFxnP/4iFnyPUEyI97klV4cvfy2tVQapX4u5CQvmdqDN4s/23Ek72djxAbUaP9jAG2kAozTEY83DR+exYODkfX4TdJ16DXmOru5OgeXibo4J31mPlMSl5s3LGVzX5IGp9kS879jcs67SQkG+iiVQqNcx9AnjjJSMCH82WBP+iohmT0uDObqAluBYmiK1C0nN/ZnA== 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=mm5Nao0dQd84uxVyUjyUfIocDzQS3Lopu4mkKoG1/6k=; b=HfIAJb0bkDJFb1cD49YUi3ylgPYCkNoXS8mx8QYGhQy2rPfJiAVuk2sbZIQF3caSki8jP29ZxHWHH35HdZL6pfzdfnRfFYFnyAkDz9XtAz/F0I3EELSKid9rP5A78zFeuumAMS/BBdh/j1Jzn7YzrzFvcbScMjL26q7CeDlpqqE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:18 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:18 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 3/6] dmaengine: dw-edma: Fix programming the source & dest addresses for ep Date: Mon, 7 Mar 2022 16:47:47 -0600 Message-Id: <20220307224750.18055-3-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20220307224750.18055-1-Frank.Li@nxp.com> References: <20220307224750.18055-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c94affd4-c8ef-4b42-83f2-08da008c92c4 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uyu2OS9R+XdpMYd/iBjeswNkUF5T+e3Gr7QeraKr5ojPjVrIuIk0ArE+K5y/sa+ldc0/T/w7voex7r0J0ISsNxnUaXQ9VjuW/arc4pZJhDEly6dWKqzPcE+amEzFjiOJN66sfmQ8rt8Z1X5Sv4zNaXXLpEbsslJ+ssPa2fgGWPvEfBAttToa6wtRhpd2FIcSLsq46rwWutD1OEZKbHRrnXBQ/ID+0ExrrPho+Tv7LEiM9xZPTcWSNOrajTPg4x/q/Fk4/vSFX20omJs84K3YuqIeAj2JHymFpKcTL3iZzwrIpD/3Q4mpUqn3nbdoinU8KCKFvf8qqglE/Cbjdnqk07flkjaFBbTI+yW5HVkv3lIh5zaPYSvEZ/mIWxqapUFeySRBfxoZIq/QKWm7f+XaCSkLv7+YcEsjQ6cJDXNLoW8gN2P4mKOwQUEvn2LTikLiBNQX7nDHGy/qdFpILVQmPUwEK4t4i73qCr6/KxgoWaiEGr7fUkbXKkS7P1W0NeayAUQ0cVYOi2WoQ2rFZwqRI4vrGohZ4lnTZt3aK7QjS3gXGN1QTZUDfcKXVWiH7hULuNcx59GLz747e/9GcpJvzo0QZS2scy3k6ydld4b9ZI/SUgxAg/4G9XYVBxzH+0W2T+nJzeJZv4p4825qKaRvKLTIWz1QAZbxTZ+wu1ODHjLA0Fjau0sk8TaqSe+te57gEyg3ulXg9xQLixye9RzpzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(8676002)(508600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(316002)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LxBoU50vRUYXsU/9e8979OAqi80LzV6tevL904DKh0OIc2Zb58G6m0oNX2BLqzbhof6Y56dgaclIrZrdjV5BqP6pIOPezDb1R6mvlLWoKFArCMEsjONML+XNLrmQv/+kIdNT7SwlynNVH7y0gWoOYtvhMtpnRBHE7Sx3RmdZzQkonGeO76nzIeOahankN2sBx5AIhpTHSj9fqhTFkBxbWlhFCO1ygv0QJ7S9ar1AEVYCeEdVu+s5eN14jHFoo0XboEde3Z89JnfgJKjQEb2B2LhNYvbAwpAhh2A9KjJEhKtlBef8At228qmQCFyIMqDKXcOTEJBDDyRbY4wFkm1PBexuwfjNf9b1h5oIC4mMu4y2jyReByEGoIjaxHAQmOlPyAeMEccKEdMzJ3i+jl0IAiTy5K4CfdOqzK5cPITmHZWDitXB2yQeEwA0+Qd8r/zsWPqNFrhKtk9dwgkbBC4X7L/4z1kzeuY7wDX5y7EHoKw5PUHzZM4NaZMuKWbBSTRpNCV838V+jXu8guGBipqdFR2t7agAl/6WQkiXo1eN5a8/ibqgUTxLY0t9xqMKgXGTxIb7IXpc8sOpqMP7277zfSbMYzr2CUDeKHfSq0GGx2D6XNLv8nBd/689gX4H1F8XyNP/0CklPM6np2+3dCNo5UKpyIxdhbCq9+Kp1VtwYq5kHASFYDYz0VIglvljRjz3odjM52PB93R62sV1xmk8p5hat9xb6KgKOxzCk47zai1XdUI8hLK0tZdCiOi1+1d9EOPh98PucyULxMzscXWXUDam8H7Ni0navB+9hW06DB0i6DeO8ah3UbkWucybtqfdC7HmFZIzCXLEhAriZqb/4PeeYgquIy8lKgfNneJotE4+EhtBwrU3wAYwiz6LC9W9h7TSCW5mogYjTA7hE5fjzKZ9H3qBtnYj3pxUL6PVM6fPCV6WMPCzN0K0MxqiZV7q0PrDyp63p0ajZg+4kjHaxTe8PqMYQIrtYK6fOsrL5fSDNzo7COBSl5RhBUHtvp2DBtRXmmfCElJcXic0PIEwn6eRS8brNILXtrYb/SOniIMFrVaeA+DroI7QeJc6jccU7dlYmxGMjBURNlSAs0ogC03e3oXmrl/P1SPsBudtAGgoO+g8T6urjv+bYerPVCuY0uZIITZmtCNWzl3bObPtytLml4/ZrFZHjnMgP6dRtJm9L1raNXUPylBrvl08cQgdMGphjtCuZpsyVV1jMdT/W5npYAMsK3BsWTVlo4TPk+saDfmFWXUn1xgdjBRHicGEPx2eLkuGO1l2HxAREvfvGa/1bB8yj39mSXp+WddEiEJGs96kEDkMr+7zght8gNI0ARmvLtnxJxD8RfX235EpljVy/J8Z+eEKKy8E9Mb9RRrihOuCIh0jUONtGFZ9aLtDQjacgr6ExjZUxpzYzaLnoZxoGaE7g2ChdkQ1WExwttHSouJ7M+tDnkU16gs6FOesk88JsapXMCAnYJLEZ7pxpiSLfk9fGWC+S6auPcIGsZ0ojDIp4FfmkSQgk4bdkLWiOrWNPfQ2f+0H4DECLQwyBAOHlRcXfUahEUaSwlz+xMU59fAWew3xZQ1W4yIfG7JjN838CBTeggK/GjgnnnvQy5mEXKdF7PbL/rx+MidgOdc= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c94affd4-c8ef-4b42-83f2-08da008c92c4 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:18.5838 (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: Pwg/n63VriCax0aSLs8w/D4SxfaKPkl5+0vOhE6j37XB7MltWhvcOkwqa5mrC+/sg6uzg7FgFwbBAqJDP1OArw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Manivannan Sadhasivam When eDMA is controlled by the Endpoint (EP), the current logic incorrectly programs the source and destination addresses for read and write. Since the Root complex and Endpoint uses the opposite channels for read/write, fix the issue by finding out the read operation first and program the eDMA accordingly. Cc: stable@vger.kernel.org Fixes: bd96f1b2f43a ("dmaengine: dw-edma: support local dma device transfer semantics") Fixes: e63d79d1ffcd ("dmaengine: Add Synopsys eDMA IP core driver") Signed-off-by: Manivannan Sadhasivam --- Resend added dmaengine@vger.kernel.org Change from V1-v3 - Direct pick up from Manivannan drivers/dma/dw-edma/dw-edma-core.c | 32 +++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 0cb66434f9e14..3636c48f5df15 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -334,6 +334,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) struct dw_edma_chunk *chunk; struct dw_edma_burst *burst; struct dw_edma_desc *desc; + bool read = false; u32 cnt = 0; int i; @@ -424,7 +425,36 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) chunk->ll_region.sz += burst->sz; desc->alloc_sz += burst->sz; - if (chan->dir == EDMA_DIR_WRITE) { + /**************************************************************** + * + * Root Complex Endpoint + * +-----------------------+ +----------------------+ + * | | TX CH | | + * | | | | + * | DEV_TO_MEM <-------------+ MEM_TO_DEV | + * | | | | + * | | | | + * | MEM_TO_DEV +-------------> DEV_TO_MEM | + * | | | | + * | | RX CH | | + * +-----------------------+ +----------------------+ + * + * If eDMA is controlled by the Root complex, TX channel + * (EDMA_DIR_WRITE) is used for memory read (DEV_TO_MEM) and RX + * channel (EDMA_DIR_READ) is used for memory write (MEM_TO_DEV). + * + * If eDMA is controlled by the endpoint, RX channel + * (EDMA_DIR_READ) is used for memory read (DEV_TO_MEM) and TX + * channel (EDMA_DIR_WRITE) is used for memory write (MEM_TO_DEV). + * + ****************************************************************/ + + if ((dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ) || + (dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_WRITE)) + read = true; + + /* Program the source and destination addresses for DMA read/write */ + if (read) { burst->sar = src_addr; if (xfer->type == EDMA_XFER_CYCLIC) { burst->dar = xfer->xfer.cyclic.paddr; From patchwork Mon Mar 7 22:47:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AA4AC433FE for ; Mon, 7 Mar 2022 22:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343868AbiCGWtV (ORCPT ); Mon, 7 Mar 2022 17:49:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343876AbiCGWtU (ORCPT ); Mon, 7 Mar 2022 17:49:20 -0500 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10056.outbound.protection.outlook.com [40.107.1.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B3CAE40; Mon, 7 Mar 2022 14:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYyEk6cMIh/fw5rxnaUaX58A1pMD+x7by5fJxvdA/wKRM3iuJNimuSUyqlHRUgO2ZDqS5enXT9qMH37eMpQH6Y0xPx9nzVpNhawaz/tCT8e66iyzgZMFU8PhWKeLfaEACss6f41YPoevD8n9pcVTZqBOch52hUZPKigpIWbIvtVcXaQ1Sknl8LC21PRVGdidIxfn9/VdKpte4p02HqKcTMCC5mY0SZLmCZCAiBs5qe+Qg4jGrFxYKZnFEuc1rkQXr7fTTgCCoUYjPPPo/Te5F/9XVtxXi+QoGTvPJbkpuYtI4SakUglagZcBY70gqRxu+O6gI0RkwrFOqmrG8+IlIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=OZr0kME42/GY0AQp2i5YqL9e9h+9es8joiFWTrpgRNU=; b=a248+LPZvNv+Y0LsRNfcx9OmLhTWSGh4rufLLGy8Z9nlNTkMa5bhASy67v1yDblmaDEscgDDLRLV6tarMzRr2AEL3WPK6q5vhKYElRv0gqL0xQ6dIWLO+NoGFfX2/MjcJEnRigvTfhmpVDW3IwdurlAy9SkfVHTikBXTJkYwR/EPzYtuIkUSsscEJih516ERK6gc96rOWEq32jWESiYuFbJ4XpZ/VxFF9SBAnTp3z71sjGMyNMZKRQXiKu2XgayHYzHuVkpKe47+or3h/fIGnAzPkWLTsrqLdgIauSU10BtdWzUiuFVjddQLS0hj/FoE/TMMaT058q3k+1ZeBmD1Uw== 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=OZr0kME42/GY0AQp2i5YqL9e9h+9es8joiFWTrpgRNU=; b=Di/YN5myasvgfFceRU/fDNmkTBpbApAz2keyM/dr07gliPWIzupim3bUaF2zwyA1MrE3pH26I8ad/vQiCqhX8xMn9ZSOMjgh2Llgq60FufAWfDRl61FPxpiWnVJWzdGtCuW/ALuo81hpOaOfEmS9x3aDU2HQQfdZ3xESXvoxXr0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:22 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:22 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 4/6] dmaengine: dw-edma: Don't rely on the deprecated "direction" member Date: Mon, 7 Mar 2022 16:47:48 -0600 Message-Id: <20220307224750.18055-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20220307224750.18055-1-Frank.Li@nxp.com> References: <20220307224750.18055-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bdd930e0-2b0d-4454-4408-08da008c9525 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rmMT7pWWkc21ncygTnIzwJW7IsYDCkN29h5bCy2GHBQQULrzjJtTt1Cr3Oa/cJLjQSy9sApertA68w0g+FwNXKPP2tC6DiKYq+EUMlY2vVfziU0SQKTL4VAsGqdNeRSQ053/9YpNbp37OwjZfykzQ2ol0Hi8aioff4o+oXcXnig5al+jhe91si3XfpqovCN55haRzV7xBDKiAN8VhoRzEoCh/Jq6gj4mFrtXeNPeAey2HMEJRdJdp44ZQRF1OZ0JIbYcR3vRavo4jx+oXFj5fsVuBNtFZ0Odev38jjnHRUbhLfiVeLF3bGr3VVtaLEDszIL5JGxNF5jIG1eN2E1Mtmv6Sc0IkhispsGbx9DPeTZcYu+cSkMlZ1bb3jKrYq2sXpLMfTLUplc+VJB1hj5etH25y7KlQpc5htGvNzPMFrVASk9+9HGhaln4wCA8fyALgclzy4g9wKZgKwA03XcqTkELDTQ8uLeAd7fnQ2GCzLwbnzQPR6w+2/HoZewby09VCebAm8I7SCmlSyjNicHiTyI/EW+5E3DShWK2jx5fBidyWGqekRu6Qi6t6jDQM6Z3BLu03aU8yZzBo74PEdYR0c7SSGPP6uiQ60yAMonsb0MTDg8Ojk9boamR9CEoYUMwY+GheSNk6qxZAuW8wdLi2xDU/vt5X4Uia27tQlfP48UdSG4q8TdVbSTKRs9WOdR0kf/iFpyRU3TpC88OLiYXuQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(8676002)(508600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(316002)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vVxnVPJRBytgBSEsdOBo5mwCfFrZfIOgu381dBO5r1528u9S/WvVY0mzpebjbRVPH331rvDSUokPBaVuLl3OhmP4dOf2GIz1u3yF1pVjYALbnuai+huLOfOVqKKU4zjVEIQmAHCTXB5AXbsdq4o/wR4+aqn+dOAJEj5flULCURcOGwRnHbCL3uO6Zo8Meau2OKNSnV8t7cgCLoWAQPa/gm7dfGE3xGw6h09WeRQMKbjVp3/2Wpy4bOs5XI2IdK1pTF2/Qey0bJhEeA8nPTuwpXBaaitP0uw9S8G3LFB4pPBZ3tzdLr4HmX5PBD2brmWsevePvnz8hd4ApYLLmp/HkY9lPsO1E9MdaYso9L1Y8+EhYxtnGzoRQcjGoZ/pxexUWzHujJhLeyfxb2ROV4Mh8kEN2ElB+xPl4dNWbiRf7s2L+kO3uECcti5itu637OOsEkcmW+2rgapyqLlDTqpov99O5p6WTdg+GTwz40n2DH/Rhh4UI/Yu3etY5n7L6dGh+Swsu3SQ7qlVbFXW5eHB4+u3C38jhN+cvu1iDnHhzvdSpeCNJTq98kzUrwKWWXm5YSoMVPomSQo9ytqUYHUvN8eeOxSPvijmY9D+JMpI3/f8uZNJALn6IhB/6UQaXZSU11BoJdpTObsZKexP36vzNS5CMj0PPFdeapfxH51IvsgFMuTvGX3pzBj4X3gRNk3jtoaGtQLoZiC0qk3OOr4FrDlOaBWVsmAX/q2pbzR7Zh286OGamXqkf9usPW0PJ+pykRwF8YPzqXDEWe/rGbUrdT3sgefLJUaZsOS0mDnXVsLBBVFmMawcG6cf1BScgq1ywRNgGl1Kae0GVIj087o+oXWmKcViNA9IGz7Gv9S26gR2yWlrn6ToNwq933sVgVGt248K17xufGpy53JpMitiN7paimKW8GRgarmiOHSfGQjwmS3af8iz6BWBRAmGVbLjfyCbVVSgZc5VM1l7O4lcj9CKxdO8aVTc1BhM92WoT6DFdpwRqjJ7uud3axjzPeAU9iLMKukY66n1cGCM5cIleg/1pHZnB4qtHmOkhwpRUe9Zhj5U4H5xP6CLnxx3YSl1oY7x6EZf4LCxyhz3TYRZDc7RI7K03M3TRJhvUcMcU+IWZt8oov7Y0Q3ubIf7T4TTEdWZHCr1vuMsq9nTZubFVTZfotxAeASeFOUv0Mc3bVWjdI/LspFbtJS0kFZI3p2N5Cn6/8FV/OSH6Vo3L/gSwtCNh+sGuXB9a4m3BsU35hahXy7Gg87gE9Iu7wFBCnLUo2NF9xyKAAREI4h1yht9t+q9WAWbrz8aHac4LtRCXaT2Q1Ifv/X89MMEY6HEMU8m61AVn/s9G5KfVZa2EyYwsm5JwNpvgHQFkHIehv2vET8eSyoDrpbTdqo0Jfx5sUc9E9tUrARJCegtLPhyIeMnIQKkoNSW6rJs3D0yPUc+pR6oPXkhuGVIoS+MDmnF1OhzGiFTae6T6CxlAL+G4KyuD4U034p3mddfkw0stx1c6sRWKO5q3ptdk9f6US2OylbcjJcGr+3TJmORB/zfoCjfC+6WexqFjGwiV9n+ScJyG6DbNUJwQVOljcVQulDd5HCLr4UmK4EEcvG5tHnVRcQQ2t43/LYkm2oOU4xnn905Sa4= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdd930e0-2b0d-4454-4408-08da008c9525 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:22.5577 (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: obikCPHB2etMIBswy4drpFypsuMR7Uvph4qQRfwkuy5nosrCm1s/9aSfqy/fV3i5RDGCqPZSSIdnHQ40IkR6Nw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Manivannan Sadhasivam The "direction" member of the "dma_slave_config" structure is deprecated. The clients no longer use this field to specify the direction of the slave channel. But in the eDMA core, this field is used to differentiate between the Root complex (remote) and Endpoint (local) DMA accesses. Nevertheless, we can't differentiate between local and remote accesses without a dedicated flag. So let's get rid of the old check and add a new check for verifying the DMA operation between local and remote memory instead. Signed-off-by: Manivannan Sadhasivam --- Resend added dmaengine@vger.kernel.org Change from v1 to v3 - direct pick up from Manivannan drivers/dma/dw-edma/dw-edma-core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 3636c48f5df15..0635157d260c1 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -341,22 +341,9 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer) if (!chan->configured) return NULL; - switch (chan->config.direction) { - case DMA_DEV_TO_MEM: /* local DMA */ - if (dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ) - break; - return NULL; - case DMA_MEM_TO_DEV: /* local DMA */ - if (dir == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) - break; + /* eDMA supports only read and write between local and remote memory */ + if (dir != DMA_DEV_TO_MEM && dir != DMA_MEM_TO_DEV) return NULL; - default: /* remote DMA */ - if (dir == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_READ) - break; - if (dir == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_WRITE) - break; - return NULL; - } if (xfer->type == EDMA_XFER_CYCLIC) { if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt) From patchwork Mon Mar 7 22:47:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 390E2C433EF for ; Mon, 7 Mar 2022 22:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343881AbiCGWtZ (ORCPT ); Mon, 7 Mar 2022 17:49:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343878AbiCGWtY (ORCPT ); Mon, 7 Mar 2022 17:49:24 -0500 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30074.outbound.protection.outlook.com [40.107.3.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C55DA12758; Mon, 7 Mar 2022 14:48:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f42hTJt6/TF+/37pv1TPUn8rSw2r1vukp4B1a6lKaW+Y+iyMJYTUqvwtRyvoX68MVhuCkHgm+gaYXFsW4+eJKTJ5UfIqgTKbUE+gaKBrTIxS0ZQ8uIask/p3rthTcgHDpPZv2Kr0OAcwaDopwafFmwTCJigUhTo/FfZvbo1PCGHeEpu9vh9N0snf8gXQfO3XS5ADUuKSaJjqkXxhv7CRcuhc3EUj0mqZJK7Ggd1CqLsX/01VHdxvI8o6VYYNsgpiV8FPzuqkbxSmNmyVat0cvkBjN/cWnKGohwDUosWSbemIsYcj1gURXfSMjKjycfGosb4+HvrpQ2nST7ALDAONJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=TcaCCHVkKGxXZb2OKOc55fVGaX/JIbPTLoSBI7vJyOU=; b=M442/W5CMGAIyaQ5ft5cqFu0QaTouQtf7YgUIuEKef9wBBEBXaLK0MZZsZzjCwYRsXqCA85qV6sc9IQoma7RUmabMimkq+3SmT0d+cmzDgaUwDkHaLCKjeLJYIScflSnlVpWJtWfG+QVu5MjB2VZfrDY9fGR04dp2cF2vAuNOHReICiuWwNPT9aXh6DPOeEHDrAAOfpk0M+ubQziI4JPOStAST78He5Hmw6bfHlFD2gUMqhyQ/Cb8p2oVSfwFf1rudezH/1egxkj1LCoATd5ioPDUgyXIEOjBc5NYuYVn99a09RfraD8Rho+GKqIuJUFcS1tukrCDZdMgoZhh6kwvQ== 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=TcaCCHVkKGxXZb2OKOc55fVGaX/JIbPTLoSBI7vJyOU=; b=cLiW45Cf17ug1NLnld1cvcNUZPeoDOFIEriTJLl1G7qwbpygIK0XFEzOIVvwXmn8xMc6UFLI2WqqVJ0TbixAu2JXM3L0adIVhYGzU1b0XdzGySD60mMKaPTVKRI78f+MvI0laxR8poSpgIvXen4k2lvshhmhx08J6X4iBQOvboo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:26 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:26 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 5/6] dmaengine: dw-edma: add flags at struct dw_edma_chip Date: Mon, 7 Mar 2022 16:47:49 -0600 Message-Id: <20220307224750.18055-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20220307224750.18055-1-Frank.Li@nxp.com> References: <20220307224750.18055-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78e7548c-2fe6-4dd6-1327-08da008c9758 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PMuEpAFXdihQF5F7uj71qaVTDagHFsmfQy9bQqBA2DuGsf5OYSmXe4ccVRa9HXGuLWsq2+3Slr1aZoI4o2bsRbYMIj9YuBEfGM+5HUe93cvY44Px5mJzZuAJi6U1fuXX4sWr67Lds6tETgkXQ6GN7DkgVmjvKZ+58KEeg7+37Msn3Cu/3jrvPf8fAOnP8SeIfvzhXpu1pkP/yZaKYtnidRdP1HKcbQexRo/BU2cnoaj/Q6+EZy25mHw63Fv8g/bL9z1bCcZYqOiV04d1sptg0DJCxKT/iAklYdSxyzQhp5wJ7rYmUa4C3EXIjr8A4hfglptTPeZ9pIFnO/ww6wKMmNyAF7XjkS2VpJE3CwinD7LLbiIxY6ATLJdN68K7km1MSsyVxqDYdl83WcrAqwW16rXFvh8gTEnAeUV+oJEbMLQYv/3vKPuQuXszghkqfDVh6FFwklFORr7BYEBVxo7VaUCzPhr+nHNASX2C+fg40I7YjHRHQLHxfJby6v3y0cGVSlpqUQRBL2fjS+JmrNM2OtIJ/IqEtwuUot/R8SrkQcHJt8t5iOo4MkMPSDFOh9CGpjuJ/6w0dMk9/W7adkPUL5Lj0OvpBp6+mgR7GClDnfw8zjo9HmJlfM58TGgtEO1br0nX8j+kvh+wZnTJHy2VUINN5zLUH9/fVoF0L8vhfBi6/Q8B6cDlEsWFtwClqWXi+XrsEsyAH7SzACQo+Fouvw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(8676002)(508600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(316002)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TqSXmEyKqBm/nubOKxL/AePrw4RKufagtMS31Wsnp+M/9A/SC4qJi1czErt35o9PMCsIimjSBQxx78c9IA2DCOonftoFjI5p6rbDuy1Hhu671SZVrB1g6ol3xNCW+QJtZ+4D48e/mHjubWCJlRqx3oV7287DE4NIvltW/RNNQ2NdQ+ta9mQEaNX8LiIbpK6aLS9EqQ5QyE9TjcFQYLESxVosdMHiNRKG+ZB1ICQkUvqfeqv7I3vSlrrKsZPijKiTXwCvdAQnRfUK2kYmF4388bQRpdlDTm7iyvlSkees1mF0Brow368s1bFcC/W/HmWgxr+toIPlqBxsD1Zfsao031ToCmSjV4e65cOWb3SC2xFvh3x0FAQDEG3NEBXddkEqclcgbm02lcsleHYm5XcKnYtfOZDZpkeWeTsTl4KmkCiI0Boh8GKj03SvbFRP8Oz8rf5jG+xmZvyJ42TXZZ6wjWloF4gZyjySQ/hg39OSMZ0oEzGh8kgS7FjCXWu5/EjrPqrs4iccW9JXxf7ICKYu6nUYOjyF/hB/26nFjEvhrBWBgN7lmx+gaEJBOwZheRGBR3V5gEW/z/FbxSlYn+0ncgoAvLilz5uDciAPKjTFNgahcNVgoSX7KfpH3wuzgpAdYo86TXRJ8vrZZzcKIUJtVN5KBy9ckZ+ADKCt1lGDrwZbuNr9WRziqf5+7EhKyKBC4dGM89sCdxSFPj1VzGskKMinkUeW1U2UPVmet2hsE0cGFXKQTXTNfcvpKzuUH2fh7GjJeFscIxZMteD3aL4620M6xST8A+AdU/oCKGuCUUSMA37P9+TAXj0tOXK4asQBLKTxqCkClSCdS8xTJrsDisN6MHdnj1BmEDESatq/WqeB1REMkIdsQd5B+dKrl5TLVw8BTXlaM1GUpzVhJ1J61oH98q2wjh+E5SacNj2fLpKuUztc8EtNnHZnLj8U9WsgPnt8yLLLXS47HKxrkb4tITW45kfBgXnTV7MHUhg4NeVWy7Pb6rW+UHzs6YjwQf5auu/Lc47ebXUzgF/JFD1G8unyK9Nl4TjKymgHe6C6anHv1a/nPvGM76nhDXhcFKbyQDHNsgnXj/X1oPmQHsLnhbyrQGdm1YndV+5rs7dB/5XOLd20nFC5G/DC6iVJwI0NqbBThaBZN9UQrn2NaczPmbFhIX/rVpuLZaslM2lDyq4HuJkHF+mFn9QNEyJsqMhYP66N1sH2rEBCHWLMVYsBCfFalHr4vmdOHh0P6xVwgBYHVQqh2YACPdtKbW44WI7INEQ66E8TCXAU3zi9a2Chkxt5nj61lFUUN3Hlx0O5Aktq5u34vitTt8q2PREZVhdq9RCLyXm6JSQHTDd66uwRKE/jQTg1KpTddTLfKvgYw+UhF5vHIj4aMV0qVTbN7T4akrDK/P96pE71ZZtSCARmRAk/OorX30ZYoumAVux0RzNKSMkKoH3uvPvpdac1P7vHA0mPS90EKQooWPH9TDCDnbeFcx8PU4p5yq86coUxDRl9915zRg4a8SJ/K6g+lao4PI+FcTKQjLDwQMzy8pUa4cDVc/GDdU0OMewjkK/pfcqNyV9bd7vvH0rNR0jfuB4MD8L+nybEEtHpw4XDOQmu5fAwmD63ZGBswL+kjUhnefE= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78e7548c-2fe6-4dd6-1327-08da008c9758 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:26.2461 (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: orOPDlt04iX/N0ZKKbB3TE1tlrgxPsPwaWhOnVRGcyvzVf4iDyhmMRXn/Wf8vjfVJO50+MaA3ayVqIiOEjmWHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Allow PCI EP probe DMA locally and prevent use of remote MSI to remote PCI host. Add option to force 32bit DBI register access even on 64-bit systems. i.MX8 hardware only allowed 32bit register access. Signed-off-by: Frank Li --- Resend added dmaengine@vger.kernel.org Change from v2 to v3 - rework commit message - Change to DW_EDMA_CHIP_32BIT_DBI - using DW_EDMA_CHIP_LOCAL control msi - Apply Bjorn's comments, if (!j) { control |= DW_EDMA_V0_LIE; if (!(chan->chip->flags & DW_EDMA_CHIP_LOCAL)) control |= DW_EDMA_V0_RIE; } if ((chan->chip->flags & DW_EDMA_CHIP_REG32BIT) || !IS_ENABLED(CONFIG_64BIT)) { SET_CH_32(...); SET_CH_32(...); } else { SET_CH_64(...); } Change from v1 to v2 - none drivers/dma/dw-edma/dw-edma-v0-core.c | 20 ++++++++++++-------- include/linux/dma/edma.h | 9 +++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-v0-core.c b/drivers/dma/dw-edma/dw-edma-v0-core.c index 6e2f83e31a03a..081cd7997348d 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-core.c +++ b/drivers/dma/dw-edma/dw-edma-v0-core.c @@ -307,6 +307,7 @@ u32 dw_edma_v0_core_status_abort_int(struct dw_edma_chip *chip, enum dw_edma_dir static void dw_edma_v0_core_write_chunk(struct dw_edma_chunk *chunk) { struct dw_edma_burst *child; + struct dw_edma_chan *chan = chunk->chan; struct dw_edma_v0_lli __iomem *lli; struct dw_edma_v0_llp __iomem *llp; u32 control = 0, i = 0; @@ -320,9 +321,11 @@ static void dw_edma_v0_core_write_chunk(struct dw_edma_chunk *chunk) j = chunk->bursts_alloc; list_for_each_entry(child, &chunk->burst->list, list) { j--; - if (!j) - control |= (DW_EDMA_V0_LIE | DW_EDMA_V0_RIE); - + if (!j) { + control |= DW_EDMA_V0_LIE; + if (!(chan->chip->flags & DW_EDMA_CHIP_LOCAL)) + control |= DW_EDMA_V0_RIE; + } /* Channel control */ SET_LL_32(&lli[i].control, control); /* Transfer size */ @@ -420,15 +423,16 @@ void dw_edma_v0_core_start(struct dw_edma_chunk *chunk, bool first) SET_CH_32(chip, chan->dir, chan->id, ch_control1, (DW_EDMA_V0_CCS | DW_EDMA_V0_LLE)); /* Linked list */ - #ifdef CONFIG_64BIT - SET_CH_64(chip, chan->dir, chan->id, llp.reg, - chunk->ll_region.paddr); - #else /* CONFIG_64BIT */ + if ((chan->chip->flags & DW_EDMA_CHIP_32BIT_DBI) || + !IS_ENABLED(CONFIG_64BIT)) { SET_CH_32(chip, chan->dir, chan->id, llp.lsb, lower_32_bits(chunk->ll_region.paddr)); SET_CH_32(chip, chan->dir, chan->id, llp.msb, upper_32_bits(chunk->ll_region.paddr)); - #endif /* CONFIG_64BIT */ + } else { + SET_CH_64(chip, chan->dir, chan->id, llp.reg, + chunk->ll_region.paddr); + } } /* Doorbell */ SET_RW_32(chip, chan->dir, doorbell, diff --git a/include/linux/dma/edma.h b/include/linux/dma/edma.h index fcfbc0f47f83d..4321f6378ef66 100644 --- a/include/linux/dma/edma.h +++ b/include/linux/dma/edma.h @@ -33,6 +33,12 @@ enum dw_edma_map_format { EDMA_MF_HDMA_COMPAT = 0x5 }; +/* Probe EDMA engine locally and prevent generate MSI to host side*/ +#define DW_EDMA_CHIP_LOCAL BIT(0) + +/* Only support 32bit DBI register access */ +#define DW_EDMA_CHIP_32BIT_DBI BIT(1) + /** * struct dw_edma_chip - representation of DesignWare eDMA controller hardware * @dev: struct device of the eDMA controller @@ -40,6 +46,8 @@ enum dw_edma_map_format { * @nr_irqs: total dma irq number * reg64bit if support 64bit write to register * @ops DMA channel to IRQ number mapping + * @flags - DW_EDMA_CHIP_LOCAL + * - DW_EDMA_CHIP_32BIT_DBI * @wr_ch_cnt DMA write channel number * @rd_ch_cnt DMA read channel number * @rg_region DMA register region @@ -53,6 +61,7 @@ struct dw_edma_chip { int id; int nr_irqs; const struct dw_edma_core_ops *ops; + u32 flags; void __iomem *reg_base; From patchwork Mon Mar 7 22:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12772687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 998E2C433FE for ; Mon, 7 Mar 2022 22:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343883AbiCGWt2 (ORCPT ); Mon, 7 Mar 2022 17:49:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343874AbiCGWt2 (ORCPT ); Mon, 7 Mar 2022 17:49:28 -0500 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30057.outbound.protection.outlook.com [40.107.3.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA44512758; Mon, 7 Mar 2022 14:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cb0vmAjMuJEheB4uJk2eqWaZNJmRbyg2mX0r60CUCpiIHKUOdXfL/klR03taH7daX6hnw/+d11u3vDuauVMpUKOu6ihNhzVpX/MgoYqeawlU6rUZu6ia5im6JbuzcosbL52naBW8exg1o3DDNT/Z281TPMhItsD40Ou4EIth9HNNi6JzSd9r2w/yzB4sQ1yLpFRrFTiA/aE/P9tAjasOZm4i/pDCsOnmkRX4Em8nZegg6dLRmyLKCIwSsN9RDzuzAg4gFYtDmKP+w8UYhxKprkmzz37qliyiwY6kq9oM8EYvQT8hc4fVs06eq4tLFcgG7kh6cv1GeFGDhXCdkRbIow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=JJsK8o8oPKxVJur6QrbRbhKIRvsRU4Om1INrgQTBMOc=; b=cODQtFGQn/BHGWhlX7eqwpnIIrxhwdvGFEH6gz0mkozo6GBVSDWa+5gpftButa3PIw58bsa1jygsxVlWl0JAJSHiPGHCyJiJvjwJ6+0KeirVrdq0B45aLO61aP2jbg9aaMeX4XLMOyE/S0qSxCB4heFMmughaKU/6YVanbhUErnuNSwgPF0hfzbFCBCtEjhUEV8D4LHGgxNYX/G73NfZyvUBMO7EENGtK6T+VHTz8JnXND+4+wKDE35fPpC2XnONgzDBHjUJjX7ktwx8WAz9wfRK76fSw4AHrM/TJUtzOjIT9HHOE20G825TCkf1VtC/Q5xyZO30lmsGdZZOx+smEw== 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=JJsK8o8oPKxVJur6QrbRbhKIRvsRU4Om1INrgQTBMOc=; b=LldicASiZhaKbqLKZPNo/idjW4PDXgFjnclxRB4qzgJqfH2KvujRyAPhVDVIwsgrVCvl3BLKjdAncRsy+JoJpSofPsPA16NDwY4cqiMFJqFybZH5YPnQlN2IO3zTWNBoB435vNi8Guf84/yU7tz4QKhO7JfxAXPp/NRuUn2v844= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM0PR04MB4946.eurprd04.prod.outlook.com (2603:10a6:208:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Mon, 7 Mar 2022 22:48:30 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c897:1bdf:e643:aef8%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 22:48:30 +0000 From: Frank Li To: gustavo.pimentel@synopsys.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, linux-imx@nxp.com, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, lznuaa@gmail.com Cc: vkoul@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, shawnguo@kernel.org, manivannan.sadhasivam@linaro.org Subject: [PATCH v3 6/6] PCI: endpoint: functions/pci-epf-test: Support PCI controller DMA Date: Mon, 7 Mar 2022 16:47:50 -0600 Message-Id: <20220307224750.18055-6-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20220307224750.18055-1-Frank.Li@nxp.com> References: <20220307224750.18055-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45e7cd7c-24b4-4762-52f5-08da008c9991 X-MS-TrafficTypeDiagnostic: AM0PR04MB4946:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rBl0Gt4lsPfdV8wh6LkGt2tKSQUMTplsJq6yqZ5a+m+nV/0y8GIVI0IviXkCuFg32Zp8ZHfs2yMDPdonvJHJMGnjgfojTx9Ip1VRT3NSRViSTpBRbLNx1/zhMLwt8UyZSfBX9xeUquErP72CjexoT1YBrio+w7vFzYNpmHq0yVxFcIOv7UUlRwHq8JAtniJyEjEyg0i94f0LoFQZmw3SIm3ED+KRrWzNKakgQSQy/dnbrAJt4lzEqVXUU7UPNcsvTSkJt33h2y3E2Y24DtoSqTUIAVmA1pdfYT/m6afc2xS93C0qTgz7/+F9Zl4suiY9kEun6ywwHbZCWDpJ0qFFhquwqdp2YMGn3kMzPF4JaKcI0aPzex1t7TgRqBBw+v3D7E3VjuLv+kch3ChniS23uZ8vtJowrcYlLJFGHOgQpGuALmwCo1bLfa4BAtFZ2A56Ik5Y60mD7hIKrPNyReH3bNfZ/0tK4mJ1OGv3a2OHPwQOSYOQuZOGzXa6AGHkES8tzbp5gepJqk5voMfD1mGiqfOqJdnPJQCe3klNtoA1oEbgBi0EFGTrKFEg97R50o440mYvg4HywHQ9mi6D4ac2tS13I+MFdHUHXBs/RfRAygwxMCzTAuWgBM4R3n1TEW8s2uL626b9ZY7uKFGzh1AlGcrVwQGcYdX1v6wwrOKHyQKRQx+ml3hE+pksRFJuZlhkd6zd6IMzlNnHyTZFpLdv4w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2906002)(5660300002)(86362001)(8676002)(508600001)(7416002)(66476007)(66946007)(66556008)(4326008)(6512007)(8936002)(6486002)(6666004)(6506007)(52116002)(83380400001)(38350700002)(1076003)(186003)(26005)(36756003)(316002)(2616005)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AUbzKksp7jb1JJ59YMdibeSgz4+hkpDdha0Rpv61im5SMoyuTnXfX/WDsYObGd3Hcf9uOuUazbzU+s8PtGC0pnDfQtoRKHcQf8OmhLJMO4qf7uq6xPMtO0OVZWRUeYEl9PIyJMTQAKjoxNI1Z4Xmf/V3SZBT2yj9s/7Mar6aGKP+1zHONAjt3X4jHcgYGbCQWwz0rRlBK6/o3cLwCLbo/q8p4a3lLkgUH3YMbnZp8TJF13UAXPUAyNmni6GRVtTFso0VsMGwV36nYYoRIqB6y9Go3VyIk1gDwSBpsugDUyUUVZx3KnGaBs9HxlpnLHGl0WTRZY8BNMP3kOWfVucG9fBIjth2Vynsi+WAfO7iOdTq8ZPljbmzHSQ2POx7kUb10dI77xyk/AFfxu/VdWJY/2jhiAnx3WGIzU/UXF7Ef9JME4vjAavK8DGFxglvIIN2x1phDJm66e+l1+1UrhdrvxLBJaRnSBC43CO5XMpBOwa01cdZcIlGU9yQTgeTsQzOMBykSG1MrDMMt24zHrBnei4kj6ouQDtFinckXnujdw1u4RZvdauXyZPs1YOQ5yK84JSNZ76Bpmrn/GR+zqCMriMWTGO/fxb7DyMOrQKRTq3KAZVDepd19KtuZlrTv0lqM7HgXaBxV5+Xx2GmMfMYIXx7oMvl2hcZYfwn6vKhRP/G2JnUmXryqqApOkIyfTcnECzAj8n1CSW9EKukCeRtEGPk+YtiiTk1+8Q1QNncLvN+bwrQLmTSkcIcfnKm3WgHxgqGuIGhrG74BTrBk2t0fVqHIOwaklxQBOqo9ZKKG+PNUceIxtY4s7VbakEf9+qp/icuhkzhqP0v+8Vy2o/KCR68nIeX0EUVb7iKQB/hQogfgjrcCPruq5lTIsVJpQOT7wky0q1vZmG91A0d9FW2PVCVXjPf325z3FVuU0cA11TqOt49UlIMWPFkndL/LSZIH3+usRWKd3KxohonzoKjOmVnH04FB9ePNeCKJunzOufclLKiGfkRSjoozb7J2B1R0ey+GAtYcLzpeG3O+nnDPlUmt0j1T+1U7cRtfH7r2fyI4EdBpjMlE/b/DZ77xYNwI0jHqv72LizVDpxM3LyyizMnRC4LGn0t29z1AaY6+l2E4E15OWx77UKi2P9/x4OoObAKn9GHk5Hn0w5yFOOrCTexvJPVuFFZ0yCbwa5oZBdfiNewHhVusdl+3CjoiCJiWfG6nEL7mN7dDORGeTXbfWKs4CRkKajeNsOZybeidcXWehvwhd7x3QgH1Zs9QU2Oi1ymg9pUt+Noz3JsmTH/gCi8uKhEqE8D0HJKTZ6ZxMTm45mnC6xYkk+9A7tfIpqzMJ87cAw2NZ0PEvG9MeLpVts0IwgPvz97CyoFFb8CWI7yhZRKBIfGg4EySdkiktlqr/ze7BWDfyRct6Ia6eE2la19fCnoa8w+o/ZLcPgBuQT1vCfw/6ZZVvNAcAn3tFAOyDlRQ7fe9WQDhMZei5s93sIKjlG9wJuw2BCkdLzA0+ARBgsZEuy6Hi0KvdpuKg7Dx3H/5LOi2PVYrT8s0DF/rogRLPVFsbVMIDFrKuGJTTkCZDWAoKqB8xiiadCYhvJopMBFBkNUtd7WjE2b3NAXEWNuXGDXa/oInoOiWK2lhLw= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45e7cd7c-24b4-4762-52f5-08da008c9991 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 22:48:30.1186 (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: lJ4dx+lWl91OqB0kBQPbuMrDhaHXqdf6bvNJoMJZ2K+tV0uc6VtJulttUJKYbmC4bNG8LnTgLRuwuwT7kkmzKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4946 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Designware provided DMA support in controller. This enabled use this DMA controller to transfer data. The whole flow align with standard DMA usage module 1. Using dma_request_channel() and filter function to find correct RX and TX Channel. 2. dmaengine_slave_config() config remote side physcial address. 3. using dmaengine_prep_slave_single() create transfer descriptor 4. tx_submit(); 5. dma_async_issue_pending(); Tested at i.MX8DXL platform. root@imx8qmmek:~# /usr/bin/pcitest -d -w WRITE ( 102400 bytes): OKAY root@imx8qmmek:~# /usr/bin/pcitest -d -r READ ( 102400 bytes): OKAY WRITE => Size: 102400 bytes DMA: YES Time: 0.000180145 seconds Rate: 555108 KB/s READ => Size: 102400 bytes DMA: YES Time: 0.000194397 seconds Rate: 514411 KB/s READ => Size: 102400 bytes DMA: NO Time: 0.013532597 seconds Rate: 7389 KB/s WRITE => Size: 102400 bytes DMA: NO Time: 0.000857090 seconds Rate: 116673 KB/s Signed-off-by: Frank Li --- Resend added dmaengine@vger.kernel.org Change from v1 to v3 - none drivers/pci/endpoint/functions/pci-epf-test.c | 106 ++++++++++++++++-- 1 file changed, 96 insertions(+), 10 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 90d84d3bc868f..22ae420c30693 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -52,9 +52,11 @@ struct pci_epf_test { enum pci_barno test_reg_bar; size_t msix_table_offset; struct delayed_work cmd_handler; - struct dma_chan *dma_chan; + struct dma_chan *dma_chan_tx; + struct dma_chan *dma_chan_rx; struct completion transfer_complete; bool dma_supported; + bool dma_private; const struct pci_epc_features *epc_features; }; @@ -105,14 +107,17 @@ static void pci_epf_test_dma_callback(void *param) */ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, dma_addr_t dma_dst, dma_addr_t dma_src, - size_t len) + size_t len, dma_addr_t remote, + enum dma_transfer_direction dir) { enum dma_ctrl_flags flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; - struct dma_chan *chan = epf_test->dma_chan; + struct dma_chan *chan = (dir == DMA_DEV_TO_MEM) ? epf_test->dma_chan_tx : epf_test->dma_chan_rx; struct pci_epf *epf = epf_test->epf; struct dma_async_tx_descriptor *tx; struct device *dev = &epf->dev; dma_cookie_t cookie; + struct dma_slave_config sconf; + dma_addr_t local = (dir == DMA_MEM_TO_DEV) ? dma_src : dma_dst; int ret; if (IS_ERR_OR_NULL(chan)) { @@ -120,7 +125,20 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, return -EINVAL; } - tx = dmaengine_prep_dma_memcpy(chan, dma_dst, dma_src, len, flags); + if (epf_test->dma_private) { + memset(&sconf, 0, sizeof(sconf)); + sconf.direction = dir; + if (dir == DMA_MEM_TO_DEV) + sconf.dst_addr = remote; + else + sconf.src_addr = remote; + + dmaengine_slave_config(chan, &sconf); + tx = dmaengine_prep_slave_single(chan, local, len, dir, flags); + } else { + tx = dmaengine_prep_dma_memcpy(chan, dma_dst, dma_src, len, flags); + } + if (!tx) { dev_err(dev, "Failed to prepare DMA memcpy\n"); return -EIO; @@ -148,6 +166,23 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, return 0; } +struct epf_dma_filter { + struct device *dev; + u32 dma_mask; +}; + +static bool epf_dma_filter_fn(struct dma_chan *chan, void *node) +{ + struct epf_dma_filter *filter = node; + struct dma_slave_caps caps; + + memset(&caps, 0, sizeof(caps)); + dma_get_slave_caps(chan, &caps); + + return chan->device->dev == filter->dev + && (filter->dma_mask & caps.directions); +} + /** * pci_epf_test_init_dma_chan() - Function to initialize EPF test DMA channel * @epf_test: the EPF test device that performs data transfer operation @@ -160,8 +195,42 @@ static int pci_epf_test_init_dma_chan(struct pci_epf_test *epf_test) struct device *dev = &epf->dev; struct dma_chan *dma_chan; dma_cap_mask_t mask; + struct epf_dma_filter filter; int ret; + filter.dev = epf->epc->dev.parent; + filter.dma_mask = BIT(DMA_DEV_TO_MEM); + + dma_cap_zero(mask); + dma_cap_set(DMA_SLAVE, mask); + dma_chan = dma_request_channel(mask, epf_dma_filter_fn, &filter); + if (IS_ERR(dma_chan)) { + dev_info(dev, "Failure get built-in DMA channel, fail back to try allocate general DMA channel\n"); + goto fail_back_tx; + } + + epf_test->dma_chan_rx = dma_chan; + + filter.dma_mask = BIT(DMA_MEM_TO_DEV); + dma_chan = dma_request_channel(mask, epf_dma_filter_fn, &filter); + + if (IS_ERR(dma_chan)) { + dev_info(dev, "Failure get built-in DMA channel, fail back to try allocate general DMA channel\n"); + goto fail_back_rx; + } + + epf_test->dma_chan_tx = dma_chan; + epf_test->dma_private = true; + + init_completion(&epf_test->transfer_complete); + + return 0; + +fail_back_rx: + dma_release_channel(epf_test->dma_chan_rx); + epf_test->dma_chan_tx = NULL; + +fail_back_tx: dma_cap_zero(mask); dma_cap_set(DMA_MEMCPY, mask); @@ -174,7 +243,7 @@ static int pci_epf_test_init_dma_chan(struct pci_epf_test *epf_test) } init_completion(&epf_test->transfer_complete); - epf_test->dma_chan = dma_chan; + epf_test->dma_chan_tx = epf_test->dma_chan_rx = dma_chan; return 0; } @@ -190,8 +259,17 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test) if (!epf_test->dma_supported) return; - dma_release_channel(epf_test->dma_chan); - epf_test->dma_chan = NULL; + dma_release_channel(epf_test->dma_chan_tx); + if (epf_test->dma_chan_tx == epf_test->dma_chan_rx) { + epf_test->dma_chan_tx = NULL; + epf_test->dma_chan_rx = NULL; + return; + } + + dma_release_channel(epf_test->dma_chan_rx); + epf_test->dma_chan_rx = NULL; + + return; } static void pci_epf_test_print_rate(const char *ops, u64 size, @@ -280,8 +358,14 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) goto err_map_addr; } + if (epf_test->dma_private) { + dev_err(dev, "Cannot transfer data using DMA\n"); + ret = -EINVAL; + goto err_map_addr; + } + ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr, - src_phys_addr, reg->size); + src_phys_addr, reg->size, 0, DMA_MEM_TO_MEM); if (ret) dev_err(dev, "Data transfer failed\n"); } else { @@ -363,7 +447,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) ktime_get_ts64(&start); ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr, - phys_addr, reg->size); + phys_addr, reg->size, + reg->src_addr, DMA_DEV_TO_MEM); if (ret) dev_err(dev, "Data transfer failed\n"); ktime_get_ts64(&end); @@ -453,8 +538,9 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) } ktime_get_ts64(&start); + ret = pci_epf_test_data_transfer(epf_test, phys_addr, - src_phys_addr, reg->size); + src_phys_addr, reg->size, reg->dst_addr, DMA_MEM_TO_DEV); if (ret) dev_err(dev, "Data transfer failed\n"); ktime_get_ts64(&end);