From patchwork Thu Jun 14 13:35:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 10463333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 87886600D0 for ; Thu, 14 Jun 2018 05:40:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7540928A3E for ; Thu, 14 Jun 2018 05:40:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6929428A44; Thu, 14 Jun 2018 05:40: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=-1.0 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DATE_IN_FUTURE_06_12,DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CEB2D28A3E for ; Thu, 14 Jun 2018 05:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SXQtpiXOY75caXrBtTXPCRJs5Y1ayuiLN/8GVQ+j5vU=; b=NKC94mZs6YprU6 mUlC0RuE+kZ5kN1zvggudfaJXBdtlnwWOsXxMUq2RMO96Sh1gIkw1Fe27wUbudJZVeyBhiznxDt18 nnq6sE9tpQyICDQA/uLN4WU+T132/Ys1y4TSPYmKUiNskSEQMemh6YCe8AsyXYJUDjPGwkPzKL5L1 TTfti6kfgfZ6ezEkw9fze5Yoaco/s4qCzOLbvwW2x2fHZXFdwqzhscvI3LDDRukWN1rO3/0eL9lzS UXg4FhOfZmMjQeKk2BVl4Iz5ggSCNfMzL0nTV0O+cmU2DStwzI6aPOXeR0x914ncMxmgVR2R37CSA 8aOyPI0JapGRUvK/23ow==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTKzy-0003Lr-Lx; Thu, 14 Jun 2018 05:40:42 +0000 Received: from mail-he1eur01on061d.outbound.protection.outlook.com ([2a01:111:f400:fe1e::61d] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTKwl-0008A3-7f for linux-arm-kernel@lists.infradead.org; Thu, 14 Jun 2018 05:37:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LGaw3XOBxk5cW2PAnV2R51VUhiuMBXL3OI+oxBseZ2k=; b=FSZmZufagyvvI/PaTGu+0j2HkG/peDKqcO8Jcpy0WnuMAilRk5sOokMrG/WBg7G+qQULkLOKz9+g/rXyRfFj7Mj3EkpwY9WKyhyfR/5aNBxG1C1LNGQwB1CUmyehr5ATfF2lL9knHY5ppsy98f3a54zDDHOPO78cqAD2z94e4/Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=yibin.gong@nxp.com; Received: from robin-OptiPlex-790.ap.freescale.net (119.31.174.66) by DB6PR04MB3222.eurprd04.prod.outlook.com (2603:10a6:6:6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.14; Thu, 14 Jun 2018 05:36:51 +0000 From: Robin Gong To: vkoul@kernel.org, s.hauer@pengutronix.de, l.stach@pengutronix.de, dan.j.williams@intel.com Subject: [PATCH v4 6/7] dmaengine: imx-sdma: add sdma_transfer_init to decrease code overlap Date: Thu, 14 Jun 2018 21:35:36 +0800 Message-Id: <1528983337-2726-7-git-send-email-yibin.gong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528983337-2726-1-git-send-email-yibin.gong@nxp.com> References: <1528983337-2726-1-git-send-email-yibin.gong@nxp.com> MIME-Version: 1.0 X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: HK0P153CA0024.APCP153.PROD.OUTLOOK.COM (2603:1096:203:18::36) To DB6PR04MB3222.eurprd04.prod.outlook.com (2603:10a6:6:6::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ab74a214-4ea7-4c84-6505-08d5d1b8d67a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB6PR04MB3222; X-Microsoft-Exchange-Diagnostics: 1; DB6PR04MB3222; 3:RQRhceg7quhb9DwmsyfF7s92ammRkKFREqKv5g+enXSX3PKXmtT77hbkoKjYjICTtXnOCL0kx75r9fwKLv7vJKKywkkBgezj/ZMSTxUDKy3C1BjTmg1LhliJxCnohFxDrawX6VBakJ3CAzLxvwwkeslxk2d/tP3kTvw7lvC9nyV7nhL330C7wS3HevIziOMl2LPxyUkVso2tzL27TYbq07c9V/8og0igSLDdMMPV5iJwIjw+ajc1QvDU1FV4V64E; 25:Ul7FLaR8fSDSMVKAsAUoAUsyv5iKY1pDj07rMt9FIRh2N4sFj7MqWB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/3pP/I/kEhM+ay3HjNw8p543TNkJ+qy/Z6OT4O7jQyWn/J; 4:2UkCmrPwsJuk8Pq/zmwg4FJHY4MJk1kcIlv31nkDd9TkDREvhGoMrcgSm1eIWA+4JY5hKUCGQvPNOkLah66a3mDY+K6od6b2K7PAwyPaKZf/0PT3TpATV8pvcJlUGYIO+zxUPGK8F2ngFb1/hZxtB5Bs67YwureM7ZL6K51MQmkY6oDmRYPI1HC1fTzx/11XD0lZiAWDdh+h3ub9KfMIaGVmn75OuLfGPZH+jzZ4VqpCdL4MDa+w+T4cG/wJqAUJKMVEcDyVHqqpebMgWpKVydmOYo1QrbRXBeRPCpp0ccyqoTzQT0Bh3JOf76gObExd X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DB6PR04MB3222; BCL:0; PCL:0; RULEID:; SRVR:DB6PR04MB3222; X-Forefront-PRVS: 0703B549E4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(376002)(366004)(346002)(199004)(189003)(476003)(6486002)(11346002)(86362001)(16586007)(6666003)(50466002)(48376002)(446003)(25786009)(66066001)(305945005)(956004)(47776003)(97736004)(2616005)(52116002)(51416003)(76176011)(6506007)(386003)(16526019)(486006)(186003)(105586002)(106356001)(36756003)(81156014)(68736007)(3846002)(6116002)(478600001)(53936002)(26005)(6512007)(81166006)(8936002)(2906002)(316002)(8676002)(5660300001)(4326008)(7736002)(50226002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR04MB3222; H:robin-OptiPlex-790.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR04MB3222; 23:QwaCmSz4xTJwaRSgW4//yB4Gs2j/43W4wt72fs4Hn?= =?us-ascii?Q?9JoovTdC2chLQ79wlqR4zDaN0qcuuHT5FvVuGz0N0NQczJrvhqFYdl/MziZb?= =?us-ascii?Q?JKG/hJlfw18UM41bvr9rJmiWKyNvI0Wq1AWzfHbnhXfXDHM/chRhnHrBIssQ?= =?us-ascii?Q?XwIhSAnvOl6QQmMyA0vv9rhMn42wbk5EEM3IfTAb4/fkJKLe4O2O1GukeKTh?= =?us-ascii?Q?MTtQvz4Mg2WURIJh+rQG3+UPxAh0T/hYsRmN+mZ+wHpumK1deH795jtFYPHK?= =?us-ascii?Q?g5ZRYnYLewg2F4Ujg16B3XFFIw4wjKifigGTpdp8qZLFK2h/ZjB25IXpClY4?= =?us-ascii?Q?cSBe8gGfyCPbEjKBO91sscb5LmqSpnyuSjGp27WwGocyTSu8e+S6xMhF6mTb?= =?us-ascii?Q?M/Yxujv3uXeYgSZ8UlZeqQSQSLAl2J7dfkildefTTRu6jQzuXiEOPLJIusBC?= =?us-ascii?Q?ZmUhEydrMn9Zs+hqITPlTRmis0/5uNhtgCeL8bD3hJe9f4SUQvOi2V1bowLo?= =?us-ascii?Q?paXhQ4O83B+OgJh5wrUO/MavjNQlzuErxHlpNkLwUYs8ywIzsueIhPDmXxC9?= =?us-ascii?Q?sFbe9rDF3DQJVYFZYxFV6n43u6Pi8lhkBsR+40emgErQTQjBka1EKhKoQ789?= =?us-ascii?Q?NExZQgoLIuhwAW7+2HRF6ZzgCMVsQUyBRpOtblgl7yK4mbugYC2Tl2jf8WXU?= =?us-ascii?Q?kEbLlcPR+8bZngAaInpZ5Esm2iYb8zgp/gbNF9AcpiqkHy0Bf/YMI9r+31rr?= =?us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WDwPeOfG+MC/EyNgXfzFun7LGSO+3Npy4pDylAFlHSOVh6mngVMw6EA5nNjx7NuIADA0IdbSttWXTjf+LBs6kdTX0jHZfMCcv11sK3jDASGJscI944Pc1lsgXzi4qXVfNVSttRby54GzChvtfBSnnJIdi0VLw==; 5:3+r3X08EwT4XbwsIscpHj1kohUFMKiLBXw5dxLWysnQiGaPLFm3iceeNYevzqynAirrVyHDnGa+T1dgtlxuOH9R4/jwrn5wTQQzBCiT8hqDNi9j7DoHsr6LdVnY9Q+8rB0gey0FTJNsYWZMUbH2oGzNHMI6ApmqS0fG2brNaBdU=; 24:wFVdHhLr4Mxiq/DfGYZA2PbQXQ9ZvrbBuigVfmnYMd1ivhD6MAWBskjkdybOzgfciXaLPZl0KwDxbWBub3gFw0vwtgi6JKuwszRZXk1AApw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR04MB3222; 7:11SoZb5M6E3Zy2qPegSmZcTyATjaTBN3ZdjyS9YewPD2tZNo1Xl5cf6mQgZ5QFHJi8NKaR6y4gqGN1PzAqPuzZgwACCapArbzp8bVvY64samH7UfRtwny77F9Wf0Wu1NXexE/u3o/IpfofHKKELrxGSRULYiHmzeRmI2UWl5gAhF2wQLtXT3rgAZt4fnDr9MNmypC+vSRkBqZN7HCDMHUcduY2mbNCl7lAbwbSpYzqh4WtWyg4lIDrL4/OvAchbC X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2018 05:36:51.4544 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab74a214-4ea7-4c84-6505-08d5d1b8d67a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB3222 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_223723_338276_32E6D2BF X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There are lot of codes overlap between prep_sg and prep_cyclic function. Add sdma_transfer_init() function to elimated the code overlap. Signed-off-by: Robin Gong --- drivers/dma/imx-sdma.c | 83 ++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index f56226f..e0783a2 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -1255,6 +1255,40 @@ static void sdma_free_chan_resources(struct dma_chan *chan) clk_disable(sdma->clk_ahb); } +static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac, + enum dma_transfer_direction direction, u32 bds) +{ + struct sdma_desc *desc; + + desc = kzalloc((sizeof(*desc)), GFP_KERNEL); + if (!desc) + goto err_out; + + sdmac->status = DMA_IN_PROGRESS; + sdmac->direction = direction; + sdmac->flags = 0; + + desc->chn_count = 0; + desc->chn_real_count = 0; + desc->buf_tail = 0; + desc->buf_ptail = 0; + desc->sdmac = sdmac; + desc->num_bd = bds; + + if (sdma_alloc_bd(desc)) + goto err_desc_out; + + if (sdma_load_context(sdmac)) + goto err_desc_out; + + return desc; + +err_desc_out: + kfree(desc); +err_out: + return NULL; +} + static struct dma_async_tx_descriptor *sdma_prep_slave_sg( struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, enum dma_transfer_direction direction, @@ -1267,36 +1301,13 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( struct scatterlist *sg; struct sdma_desc *desc; - if (sdmac->status == DMA_IN_PROGRESS) - return NULL; - sdmac->status = DMA_IN_PROGRESS; - - sdmac->flags = 0; - - desc = kzalloc((sizeof(*desc)), GFP_KERNEL); + desc = sdma_transfer_init(sdmac, direction, sg_len); if (!desc) goto err_out; - desc->buf_tail = 0; - desc->buf_ptail = 0; - desc->sdmac = sdmac; - desc->num_bd = sg_len; - desc->chn_real_count = 0; - - if (sdma_alloc_bd(desc)) { - kfree(desc); - goto err_out; - } - dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n", sg_len, channel); - sdmac->direction = direction; - ret = sdma_load_context(sdmac); - if (ret) - goto err_bd_out; - - desc->chn_count = 0; for_each_sg(sgl, sg, sg_len, i) { struct sdma_buffer_descriptor *bd = &desc->bd[i]; int param; @@ -1372,38 +1383,18 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic( struct sdma_engine *sdma = sdmac->sdma; int num_periods = buf_len / period_len; int channel = sdmac->channel; - int ret, i = 0, buf = 0; + int i = 0, buf = 0; struct sdma_desc *desc; dev_dbg(sdma->dev, "%s channel: %d\n", __func__, channel); - if (sdmac->status == DMA_IN_PROGRESS) - return NULL; - - sdmac->status = DMA_IN_PROGRESS; - - desc = kzalloc((sizeof(*desc)), GFP_KERNEL); + desc = sdma_transfer_init(sdmac, direction, num_periods); if (!desc) goto err_out; - desc->buf_tail = 0; - desc->buf_ptail = 0; - desc->sdmac = sdmac; - desc->num_bd = num_periods; - desc->chn_real_count = 0; desc->period_len = period_len; sdmac->flags |= IMX_DMA_SG_LOOP; - sdmac->direction = direction; - - if (sdma_alloc_bd(desc)) { - kfree(desc); - goto err_bd_out; - } - - ret = sdma_load_context(sdmac); - if (ret) - goto err_bd_out; if (period_len > 0xffff) { dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %zu > %d\n",