From patchwork Tue Jul 26 12:02:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 9248053 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 BF17D6077C for ; Tue, 26 Jul 2016 12:02:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0A4A271FD for ; Tue, 26 Jul 2016 12:02:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5B3E272AA; Tue, 26 Jul 2016 12:02:53 +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=-6.9 required=2.0 tests=BAYES_00,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 233CE271FD for ; Tue, 26 Jul 2016 12:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713AbcGZMCp (ORCPT ); Tue, 26 Jul 2016 08:02:45 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:42990 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754689AbcGZMCo (ORCPT ); Tue, 26 Jul 2016 08:02:44 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1bS14C-0004zo-JW; Tue, 26 Jul 2016 14:02:32 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.87) (envelope-from ) id 1bS14C-0003mJ-5H; Tue, 26 Jul 2016 14:02:32 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Mugunthan V N , Grygorii Strashko Cc: linux-omap@vger.kernel.org, netdev@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 2/2] net: davinci_cpdma: reduce time holding chan->lock in cpdma_chan_submit Date: Tue, 26 Jul 2016 14:02:25 +0200 Message-Id: <1469534545-14478-3-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1469534545-14478-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1469534545-14478-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allocating and preparing a dma descriptor doesn't need to happen under the channel's lock. So do this before taking the channel's lock. The only down side is that the dma descriptor might be allocated even though the channel is about to be stopped. This is unlikely though. Signed-off-by: Uwe Kleine-König --- drivers/net/ethernet/ti/davinci_cpdma.c | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 5ffa04a306c6..ba3462707ae3 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -542,24 +542,10 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, u32 mode; int ret = 0; - spin_lock_irqsave(&chan->lock, flags); - - if (chan->state == CPDMA_STATE_TEARDOWN) { - ret = -EINVAL; - goto unlock_ret; - } - - if (chan->count >= chan->desc_num) { - chan->stats.desc_alloc_fail++; - ret = -ENOMEM; - goto unlock_ret; - } - desc = cpdma_desc_alloc(ctlr->pool); if (!desc) { chan->stats.desc_alloc_fail++; - ret = -ENOMEM; - goto unlock_ret; + return -ENOMEM; } if (len < ctlr->params.min_packet_size) { @@ -571,8 +557,7 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, ret = dma_mapping_error(ctlr->dev, buffer); if (ret) { cpdma_desc_free(ctlr->pool, desc, 1); - ret = -EINVAL; - goto unlock_ret; + return -EINVAL; } mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; @@ -586,6 +571,19 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, desc_write(desc, sw_buffer, buffer); desc_write(desc, sw_len, len); + spin_lock_irqsave(&chan->lock, flags); + + if (chan->state == CPDMA_STATE_TEARDOWN) { + ret = -EINVAL; + goto unlock_free; + } + + if (chan->count >= chan->desc_num) { + chan->stats.desc_alloc_fail++; + ret = -ENOMEM; + goto unlock_free; + } + __cpdma_chan_submit(chan, desc); if (chan->state == CPDMA_STATE_ACTIVE && chan->rxfree) @@ -593,8 +591,12 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, chan->count++; -unlock_ret: spin_unlock_irqrestore(&chan->lock, flags); + return 0; + +unlock_free: + spin_unlock_irqrestore(&chan->lock, flags); + cpdma_desc_free(ctlr->pool, desc, 1); return ret; } EXPORT_SYMBOL_GPL(cpdma_chan_submit);