From patchwork Wed Mar 6 12:21:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10841077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 911F81669 for ; Wed, 6 Mar 2019 12:21:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 751712D76E for ; Wed, 6 Mar 2019 12:21:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 638C02D771; Wed, 6 Mar 2019 12:21:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DB3F2D76E for ; Wed, 6 Mar 2019 12:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727367AbfCFMVt (ORCPT ); Wed, 6 Mar 2019 07:21:49 -0500 Received: from mail-eopbgr780089.outbound.protection.outlook.com ([40.107.78.89]:34944 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729305AbfCFMVs (ORCPT ); Wed, 6 Mar 2019 07:21:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rXg151cThNz6toLK/BWw0aEWd9WV7Fg+6wNfqx5POPE=; b=L1qxL+5isom12L09v0OrNkjxLld4kWtI+2uNVMPw8cIIyOHyxKMlaQcyg+KAcvpMCNgZjLGHhztXsUvEdowZYa/W2U0/M1abnDq7S1jo6fOkg+R06x38JRmMikm71zR+URsuLD81N8Fz3U8ekloPsvhIASFA7cgv2I78aelZPKg= Received: from MWHPR03CA0006.namprd03.prod.outlook.com (2603:10b6:300:117::16) by BN3PR03MB2259.namprd03.prod.outlook.com (2a01:111:e400:7bba::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.18; Wed, 6 Mar 2019 12:21:44 +0000 Received: from CY1NAM02FT005.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::207) by MWHPR03CA0006.outlook.office365.com (2603:10b6:300:117::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1686.17 via Frontend Transport; Wed, 6 Mar 2019 12:21:44 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta2.analog.com; Received: from nwd2mta2.analog.com (137.71.25.57) by CY1NAM02FT005.mail.protection.outlook.com (10.152.74.117) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1643.11 via Frontend Transport; Wed, 6 Mar 2019 12:21:43 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id x26CLg4E027104 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Wed, 6 Mar 2019 04:21:42 -0800 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Wed, 6 Mar 2019 07:21:42 -0500 From: Alexandru Ardelean To: , CC: , Lars-Peter Clausen Subject: [V3 PATCH] dmaengine: axi-dmac: Split too large segments Date: Wed, 6 Mar 2019 14:21:40 +0200 Message-ID: <20190306122140.24271-1-alex.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(376002)(346002)(396003)(39860400002)(2980300002)(199004)(189003)(54534003)(43544003)(476003)(2616005)(305945005)(486006)(316002)(36756003)(966005)(110136005)(246002)(54906003)(106002)(86362001)(426003)(72206003)(16586007)(7636002)(126002)(8676002)(336012)(6306002)(478600001)(48376002)(50226002)(51416003)(77096007)(8936002)(47776003)(50466002)(26005)(186003)(2906002)(7696005)(5660300002)(106466001)(1076003)(53416004)(4326008)(356004);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR03MB2259;H:nwd2mta2.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b138e646-7338-417c-156b-08d6a22e4baf X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4608103)(4709054)(2017052603328)(7153060);SRVR:BN3PR03MB2259; X-MS-TrafficTypeDiagnostic: BN3PR03MB2259: X-MS-Exchange-PUrlCount: 1 X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2259;20:k4uSojn4W6eD5o4ANVaVM6oKXP9E+c8ymBogf51WUNacoF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ZUv9B3OsCkEwPKAaxHsB497Prw2TMkjq2993y9x0SzyPH9sS9qLu/dJY4xZn2Xt9Imx7bZ3eqfnvV7E8h7hnJObZxinAB0bJ25NlnqybPMEkPonAdDyLrko8sNAhZ8EvWGPyMZzWkFk+086dC/0lHnZEbnpdv3cS604pG8KANiV07PV1YdYULDe4aOxLjnkibuDq79M26aeza6T3djyTyCmy6pypO5vc/KbYbvOvMXi6oDn2qaGPQ9TTVaLXjbQ0cAho+N9zx0IlSQPmRSAIIfL4EQvYirpDEMhG1Ld5gRaSLWWFf0QiTds9h7YvFz/wLeoYLmWndNHZwIJI03MQHd/Bo89OOj3iBTLYdzEFuiKTwtQPi4xro2Pd6DtabQC/+dHf4yqV4VSrVCNOkCIMyaQeSOx3NEey2jzcHajS2fONDDc8iXa0Z6vfy3/coEEfEwPBNhkbMp1xzNj6lnNG8jtwtkYwBi9r/eHq7WzO79+R34SMkRf+HdXoOI3/7zjvXAK2dVCZNCEtortmNeMUWqmlJM= X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: cu0RuSy66LTHUIzGHcPg1M+SJKQUnWLyIgoO+u3LKv60op7cKORGeuP4KUxfT5Npymjtui+C81KH5u9pgoNz8jrCvXuzyIGbLMZDIsoT8YJ9ebWp+/knT8Sw15+WfbftsqbmROB+mwGYllrZgSbjwdtapEe98BkAdTH+FKqhppPYcTGrmorNGMPZYtCAGVlb2lJQBmV61dRr8kzBHfOaA2Z+92xycXs6Ohce1sZBr7oyW75+OTImXWAPObJxLpL3yH1MvuqD1u5Kb/DyHpzziISxzi8HAJrGKPlD8OB9SPjrV1Ctr5VC3lFwJvK5jKk5AY5FlEGe/aKqw0jBXyP+1rrqo7jsBqjqj1cnf3ZqN65VMmdr3c3uUiEe+ZqbcAVJuAEkDOtNW1SNA8H8GrRWZ3BgBskyCyBDX3jYMlEUf8g= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2019 12:21:43.6210 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b138e646-7338-417c-156b-08d6a22e4baf X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.57];Helo=[nwd2mta2.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB2259 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lars-Peter Clausen The axi-dmac driver currently rejects transfers with segments that are larger than what the hardware can handle. Re-work the driver so that these large segments are split into multiple segments instead where each segment is smaller or equal to the maximum segment size. This allows the driver to handle transfers with segments of arbitrary size. Signed-off-by: Lars-Peter Clausen --- Changelog V1->V2: * reworked this patch to not use the `sg_nents_for_dma()` helper from https://patchwork.kernel.org/patch/9389821/ After some discussion with Andy Shevchenko and some thought about it, it probably does not make sense to have this helper for this driver only, since a more generic solution could be implemented via DMAEngine API. This generic solution is not yet implemented (as I understood it from the discussion). Changelog V2->V3: * removed adding `last` field ; patch V2 was adding a `last` field to the `struct axi_dmac_sg`, which wasn't being used (neither in later patch); also it wasn't properly set drivers/dma/dma-axi-dmac.c | 81 ++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c index ffc0adc2f6ce..4bece437bbbe 100644 --- a/drivers/dma/dma-axi-dmac.c +++ b/drivers/dma/dma-axi-dmac.c @@ -166,7 +166,7 @@ static int axi_dmac_dest_is_mem(struct axi_dmac_chan *chan) static bool axi_dmac_check_len(struct axi_dmac_chan *chan, unsigned int len) { - if (len == 0 || len > chan->max_length) + if (len == 0) return false; if ((len & chan->align_mask) != 0) /* Not aligned */ return false; @@ -379,6 +379,49 @@ static struct axi_dmac_desc *axi_dmac_alloc_desc(unsigned int num_sgs) return desc; } +static struct axi_dmac_sg *axi_dmac_fill_linear_sg(struct axi_dmac_chan *chan, + enum dma_transfer_direction direction, dma_addr_t addr, + unsigned int num_periods, unsigned int period_len, + struct axi_dmac_sg *sg) +{ + unsigned int num_segments, i; + unsigned int segment_size; + unsigned int len; + + /* Split into multiple equally sized segments if necessary */ + num_segments = DIV_ROUND_UP(period_len, chan->max_length); + segment_size = DIV_ROUND_UP(period_len, num_segments); + /* Take care of alignment */ + segment_size = ((segment_size - 1) | chan->align_mask) + 1; + + for (i = 0; i < num_periods; i++) { + len = period_len; + + while (len > segment_size) { + if (direction == DMA_DEV_TO_MEM) + sg->dest_addr = addr; + else + sg->src_addr = addr; + sg->x_len = segment_size; + sg->y_len = 1; + sg++; + addr += segment_size; + len -= segment_size; + } + + if (direction == DMA_DEV_TO_MEM) + sg->dest_addr = addr; + else + sg->src_addr = addr; + sg->x_len = len; + sg->y_len = 1; + sg++; + addr += len; + } + + return sg; +} + static struct dma_async_tx_descriptor *axi_dmac_prep_slave_sg( struct dma_chan *c, struct scatterlist *sgl, unsigned int sg_len, enum dma_transfer_direction direction, @@ -386,16 +429,24 @@ static struct dma_async_tx_descriptor *axi_dmac_prep_slave_sg( { struct axi_dmac_chan *chan = to_axi_dmac_chan(c); struct axi_dmac_desc *desc; + struct axi_dmac_sg *dsg; struct scatterlist *sg; + unsigned int num_sgs; unsigned int i; if (direction != chan->direction) return NULL; - desc = axi_dmac_alloc_desc(sg_len); + num_sgs = 0; + for_each_sg(sgl, sg, sg_len, i) + num_sgs += DIV_ROUND_UP(sg_dma_len(sg), chan->max_length); + + desc = axi_dmac_alloc_desc(num_sgs); if (!desc) return NULL; + dsg = desc->sg; + for_each_sg(sgl, sg, sg_len, i) { if (!axi_dmac_check_addr(chan, sg_dma_address(sg)) || !axi_dmac_check_len(chan, sg_dma_len(sg))) { @@ -403,12 +454,8 @@ static struct dma_async_tx_descriptor *axi_dmac_prep_slave_sg( return NULL; } - if (direction == DMA_DEV_TO_MEM) - desc->sg[i].dest_addr = sg_dma_address(sg); - else - desc->sg[i].src_addr = sg_dma_address(sg); - desc->sg[i].x_len = sg_dma_len(sg); - desc->sg[i].y_len = 1; + dsg = axi_dmac_fill_linear_sg(chan, direction, sg_dma_address(sg), 1, + sg_dma_len(sg), dsg); } desc->cyclic = false; @@ -423,7 +470,7 @@ static struct dma_async_tx_descriptor *axi_dmac_prep_dma_cyclic( { struct axi_dmac_chan *chan = to_axi_dmac_chan(c); struct axi_dmac_desc *desc; - unsigned int num_periods, i; + unsigned int num_periods, num_segments; if (direction != chan->direction) return NULL; @@ -436,20 +483,14 @@ static struct dma_async_tx_descriptor *axi_dmac_prep_dma_cyclic( return NULL; num_periods = buf_len / period_len; + num_segments = DIV_ROUND_UP(period_len, chan->max_length); - desc = axi_dmac_alloc_desc(num_periods); + desc = axi_dmac_alloc_desc(num_periods * num_segments); if (!desc) return NULL; - for (i = 0; i < num_periods; i++) { - if (direction == DMA_DEV_TO_MEM) - desc->sg[i].dest_addr = buf_addr; - else - desc->sg[i].src_addr = buf_addr; - desc->sg[i].x_len = period_len; - desc->sg[i].y_len = 1; - buf_addr += period_len; - } + axi_dmac_fill_linear_sg(chan, direction, buf_addr, num_periods, + buf_len, desc->sg); desc->cyclic = true; @@ -647,7 +688,7 @@ static int axi_dmac_probe(struct platform_device *pdev) of_node_put(of_channels); pdev->dev.dma_parms = &dmac->dma_parms; - dma_set_max_seg_size(&pdev->dev, dmac->chan.max_length); + dma_set_max_seg_size(&pdev->dev, UINT_MAX); dma_dev = &dmac->dma_dev; dma_cap_set(DMA_SLAVE, dma_dev->cap_mask);