From patchwork Fri Jul 5 15:04:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168544 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3692565ilk; Fri, 5 Jul 2019 08:05:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVQmTEet16sKiu0bZv/LV0ni4lO18DPRsBClRVbJcBVUjFrEcMy47DW0bSExv2kDK0n7Ap X-Received: by 2002:a63:1208:: with SMTP id h8mr5874670pgl.377.1562339134476; Fri, 05 Jul 2019 08:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562339134; cv=none; d=google.com; s=arc-20160816; b=U0J11Y2HI5TGBavnCIuJ5ItMa+GoP3gW8kUJ2bhdhgZV6H6730bWMfkku38gTMHeQL ycvjZ4oDIW4okxEMQhP2QuXvC9ZXEVz+xsu/HHYnE/nytI1/9+gbfMQpT9IoO69953Sw bNCHiznEeyazJ7E2IPCMA/SYueP3nNG8YDIv9KXakUKgE/ze484ziy0CEK/i6SUOw63H EWc5jfrcEhuozOEMWHRSiCS0qM4O0MSVvzj3SD2eh7RGpP84FYiZc/bB+aWEY5joVJ8M 5htiKcoJbPACJCLOPeeknwWoRh0tKlTS5YzHwPBjDu7/EANxm4O0Y2gK2ApZeRaPdUvR upAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=F7JFqzRXqxTzUkcqfAtcONZlOP60PRysVxN4UPvDiWY=; b=itqKkTV2hrPK4ysA3d8qw4AjsPLtVgBuiZ0+0niCFi0Rfv36Y34vUZo2iZQIvYyRy9 grtCHyg0x3CTt0wdz2QneYM8DFBdC1GgYjDnaY4g47A/uY+2YgCxEnHYawypmyEJTlLp GOkxB4MXIfGX1FxWPUlBkES0rmenoMS5mqcZHax+0HvlVS5gtpM6uunY+E6J4pLVLybc 4gOTC2yRcMk+YYg3cdv7pwnEn51fj/aPo9+H3kJgCfpRmFY9YxZCfglaCdewk0l3mwtV aHKTLarvJU41TjuOVTqB5iqOYRppFZUr3jS3ZCG2KDBPtrBnHg4bdWvoEXUDSoIjsump Jkig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ieh5tUIF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si9734174pgl.419.2019.07.05.08.05.33; Fri, 05 Jul 2019 08:05:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ieh5tUIF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbfGEPFc (ORCPT + 30 others); Fri, 5 Jul 2019 11:05:32 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36386 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbfGEPFK (ORCPT ); Fri, 5 Jul 2019 11:05:10 -0400 Received: by mail-lf1-f65.google.com with SMTP id q26so6540770lfc.3 for ; Fri, 05 Jul 2019 08:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F7JFqzRXqxTzUkcqfAtcONZlOP60PRysVxN4UPvDiWY=; b=Ieh5tUIFFf4fyOoqWEJgWTVcVPpBHB9GWUbg6g1TUA2M8gjQ9lHzA0I/eb5kRhWVz3 RYuJjOvGeo8cyQV92RuJd1vpnWynzeBBqo3vj4VL8dLfPkHU0L21ZQvx/4oQVVPhJe9n EEYrazIQL+pPqCCVo59R3gRlZClC32lDK20D91FOg85tJRHiEmH7VaHz7JeG/SA0PyaE oFk+6MrEe7d9Q9Nzj8FESl7rYXEq5rePXowIf8A4wf1HuMKVQjUrm4pVmygSH1bEnKC1 UsfSOPQtk9rbfaMJVGmrd2KjZt/Vq4T7UOTGInOikSlCAQvJdO2sCnU5gXosKqHoWRZ7 LQsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F7JFqzRXqxTzUkcqfAtcONZlOP60PRysVxN4UPvDiWY=; b=hTh/cb6ygBCaSdV8tXfcObGq9bMinELmK0Lpy7bycXtc0hE70kokawHnoN7vSv8JMV xy0kfmiqRch2s2WeyOtgJGoPu4zDlP/u9+5tAZG48vBLWquGxvm6Cs1Iov/QK9vg5rEa SHHG0ZAoJ7R4Buz9s787KruCvbJQozL59hiDJGSkLXu8EXKwoOwZeoqxegHFmBwTkh2q 6hRhM2+tOBNRMdc75jCmSgmkMBs2XtNSONTDDevY0NMXhnzRF3ByLLD7hdnTEFXHHKcR jqoksb6ChS8DCTed1YPTQuLLUeIvvk/pepOG2+o/t8bH+xMtzMpgoPomPAfmO/3AykFs x7VQ== X-Gm-Message-State: APjAAAXmZFubn9Av0+k/5SndmCZoXi3ok6hEd0BsgnQ5t7l2sAGVWSst PNtbvG02JvnsjsaM+Cd4AQozTQ== X-Received: by 2002:ac2:5094:: with SMTP id f20mr2375159lfm.186.1562339108040; Fri, 05 Jul 2019 08:05:08 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id y4sm1433660lfc.56.2019.07.05.08.05.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 05 Jul 2019 08:05:07 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net Cc: ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [PATCH v8 net-next 2/5] net: ethernet: ti: davinci_cpdma: add dma mapped submit Date: Fri, 5 Jul 2019 18:04:59 +0300 Message-Id: <20190705150502.6600-3-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190705150502.6600-1-ivan.khoronzhuk@linaro.org> References: <20190705150502.6600-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case if dma mapped packet needs to be sent, like with XDP page pool, the "mapped" submit can be used. This patch adds dma mapped submit based on regular one. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/davinci_cpdma.c | 89 ++++++++++++++++++++++--- drivers/net/ethernet/ti/davinci_cpdma.h | 4 ++ 2 files changed, 83 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 5cf1758d425b..8da46394c0e7 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -139,6 +139,7 @@ struct submit_info { int directed; void *token; void *data; + int flags; int len; }; @@ -184,6 +185,8 @@ static struct cpdma_control_info controls[] = { (directed << CPDMA_TO_PORT_SHIFT)); \ } while (0) +#define CPDMA_DMA_EXT_MAP BIT(16) + static void cpdma_desc_pool_destroy(struct cpdma_ctlr *ctlr) { struct cpdma_desc_pool *pool = ctlr->pool; @@ -1015,6 +1018,7 @@ static int cpdma_chan_submit_si(struct submit_info *si) struct cpdma_chan *chan = si->chan; struct cpdma_ctlr *ctlr = chan->ctlr; int len = si->len; + int swlen = len; struct cpdma_desc __iomem *desc; dma_addr_t buffer; u32 mode; @@ -1036,16 +1040,22 @@ static int cpdma_chan_submit_si(struct submit_info *si) chan->stats.runt_transmit_buff++; } - buffer = dma_map_single(ctlr->dev, si->data, len, chan->dir); - ret = dma_mapping_error(ctlr->dev, buffer); - if (ret) { - cpdma_desc_free(ctlr->pool, desc, 1); - return -EINVAL; - } - mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; cpdma_desc_to_port(chan, mode, si->directed); + if (si->flags & CPDMA_DMA_EXT_MAP) { + buffer = (u32)si->data; + dma_sync_single_for_device(ctlr->dev, buffer, len, chan->dir); + swlen |= CPDMA_DMA_EXT_MAP; + } else { + buffer = dma_map_single(ctlr->dev, si->data, len, chan->dir); + ret = dma_mapping_error(ctlr->dev, buffer); + if (ret) { + cpdma_desc_free(ctlr->pool, desc, 1); + return -EINVAL; + } + } + /* Relaxed IO accessors can be used here as there is read barrier * at the end of write sequence. */ @@ -1055,7 +1065,7 @@ static int cpdma_chan_submit_si(struct submit_info *si) writel_relaxed(mode | len, &desc->hw_mode); writel_relaxed((uintptr_t)si->token, &desc->sw_token); writel_relaxed(buffer, &desc->sw_buffer); - writel_relaxed(len, &desc->sw_len); + writel_relaxed(swlen, &desc->sw_len); desc_read(desc, sw_len); __cpdma_chan_submit(chan, desc); @@ -1079,6 +1089,32 @@ int cpdma_chan_idle_submit(struct cpdma_chan *chan, void *token, void *data, si.data = data; si.len = len; si.directed = directed; + si.flags = 0; + + spin_lock_irqsave(&chan->lock, flags); + if (chan->state == CPDMA_STATE_TEARDOWN) { + spin_unlock_irqrestore(&chan->lock, flags); + return -EINVAL; + } + + ret = cpdma_chan_submit_si(&si); + spin_unlock_irqrestore(&chan->lock, flags); + return ret; +} + +int cpdma_chan_idle_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed) +{ + struct submit_info si; + unsigned long flags; + int ret; + + si.chan = chan; + si.token = token; + si.data = (void *)(u32)data; + si.len = len; + si.directed = directed; + si.flags = CPDMA_DMA_EXT_MAP; spin_lock_irqsave(&chan->lock, flags); if (chan->state == CPDMA_STATE_TEARDOWN) { @@ -1103,6 +1139,32 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, si.data = data; si.len = len; si.directed = directed; + si.flags = 0; + + spin_lock_irqsave(&chan->lock, flags); + if (chan->state != CPDMA_STATE_ACTIVE) { + spin_unlock_irqrestore(&chan->lock, flags); + return -EINVAL; + } + + ret = cpdma_chan_submit_si(&si); + spin_unlock_irqrestore(&chan->lock, flags); + return ret; +} + +int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed) +{ + struct submit_info si; + unsigned long flags; + int ret; + + si.chan = chan; + si.token = token; + si.data = (void *)(u32)data; + si.len = len; + si.directed = directed; + si.flags = CPDMA_DMA_EXT_MAP; spin_lock_irqsave(&chan->lock, flags); if (chan->state != CPDMA_STATE_ACTIVE) { @@ -1140,10 +1202,17 @@ static void __cpdma_chan_free(struct cpdma_chan *chan, uintptr_t token; token = desc_read(desc, sw_token); - buff_dma = desc_read(desc, sw_buffer); origlen = desc_read(desc, sw_len); - dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir); + buff_dma = desc_read(desc, sw_buffer); + if (origlen & CPDMA_DMA_EXT_MAP) { + origlen &= ~CPDMA_DMA_EXT_MAP; + dma_sync_single_for_cpu(ctlr->dev, buff_dma, origlen, + chan->dir); + } else { + dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir); + } + cpdma_desc_free(pool, desc, 1); (*chan->handler)((void *)token, outlen, status); } diff --git a/drivers/net/ethernet/ti/davinci_cpdma.h b/drivers/net/ethernet/ti/davinci_cpdma.h index 9343c8c73c1b..0271a20c2e09 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -77,8 +77,12 @@ int cpdma_chan_stop(struct cpdma_chan *chan); int cpdma_chan_get_stats(struct cpdma_chan *chan, struct cpdma_chan_stats *stats); +int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed); int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, int directed); +int cpdma_chan_idle_submit_mapped(struct cpdma_chan *chan, void *token, + dma_addr_t data, int len, int directed); int cpdma_chan_idle_submit(struct cpdma_chan *chan, void *token, void *data, int len, int directed); int cpdma_chan_process(struct cpdma_chan *chan, int quota);