From patchwork Wed Apr 17 17:49:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 162407 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5787508jan; Wed, 17 Apr 2019 10:50:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2/Gd5FkXW+ircX2jDfOw3wf/TQue7ZPbIZKJSEWxTnHT6yexEGaz2QoEGRdCJt/YO7Pqk X-Received: by 2002:a62:fb0a:: with SMTP id x10mr91794442pfm.179.1555523413610; Wed, 17 Apr 2019 10:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555523413; cv=none; d=google.com; s=arc-20160816; b=t+GmXqE5xKshHaRtVDi/5zjT3bUOdcqXpJhSyspUeADo/bVFj85OFU3LUi1jGqQs51 VyCPE7VuvsQEs/3JwBYPl1JzEfZnQSpTngBeQcFSlL9KOfmagpTY4D7PryubIMR4OEFC WT1mZg1Dy1ma11gzTHDz9ZLWIIDSAvvzmxJd6l1urUVW/8SFmdSTSAL3rGKikGeGNsIN lsuJqOENyDRq2IwDjzavGJ2h9gsWkR9NiH2uifAuiUgYVv2qZBhgzvTe7RrrvpEVDPG1 ETCKwJ0LUoacSe2zhnfoYYEV3FlF0MdHzjmY1R1Tj5F5p/+oYpqs87w2vke+AftucYX5 uapw== 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=l/8RWz1sFCy2pYyWFCkyCF9aMFvlsg0DvtWaIJqPbpo=; b=E+FVLguH4yXpSVb5AOcEmWufZqf3uc7KNsd2iUX5IKb5fF62PVUTGyF8qyk09zeQPg C0lHLeNAhU1EH6pqmDdBgrUVVll101/ktIpOnShkNcqCOt5QXV06PZmYo5E38CH6hUR1 5QH+lXtd5gTmxgfg6Qjt05S05sqC5A5w3ROoA9Z4Vm1jR0Q+LwIpUeKto1nn0aMOG0VN ICL1rIopwI3YAljllyNfgp3+0RGTvMZWpppWN2p+TFtqoIKVAUpDz2Ytzey8lQKkDMAK 29c5aO2xA+L4NU2Vo6gAQw1cOu3WRE+z5uhVvTZFNVXFNWNzUzyyil5xMifhRwjdsK16 e7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wrF2JBXu; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 g31si37236399plg.154.2019.04.17.10.50.13; Wed, 17 Apr 2019 10:50:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-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=wrF2JBXu; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 S1733177AbfDQRuM (ORCPT + 5 others); Wed, 17 Apr 2019 13:50:12 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34093 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733151AbfDQRuK (ORCPT ); Wed, 17 Apr 2019 13:50:10 -0400 Received: by mail-lj1-f196.google.com with SMTP id j89so23284030ljb.1 for ; Wed, 17 Apr 2019 10:50: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=l/8RWz1sFCy2pYyWFCkyCF9aMFvlsg0DvtWaIJqPbpo=; b=wrF2JBXu9XGL9wJ/iPCe8UgDfd03WKnhdro+OjS7M6pxd/614QE+kWjqqq8Zcz1VUS 9xF2dFudI0pd2bfPeLbyuILW5twC+Or+O+C7TeQu9zvWXnsrJZz0YPz9ezUI6vykHaqr Yj7ypQgKtpoIjv5seyBOSzdmBG0YGxU0H/cHuEbPWSUf34s5YwaocsYUAq6WJdtkBEQE TXFEu/87+GRuJkxS4eI/+7zJpYrIkgHRPUGC+M13ewbYltCV9LUhIjTVi73nLYOwOLWQ QdsvUgdsXCd3oo6GCzWTOX3kpjMEJtEwjIjrjC52WYhXRSKaVD/S5DjF+Cb60U6qCB/q qZ+Q== 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=l/8RWz1sFCy2pYyWFCkyCF9aMFvlsg0DvtWaIJqPbpo=; b=dFaTmc1cs9br/YqiDjjV0Q/LydNhfw/pNALgP70abC/MSCwZECgiVufOTjBZyQST7P pLGqztiOMKMchmYdNtxKzykc0ATlyC+5AZ3RWalPdfMixnynlCl+GtOxL+vIxnyVD2RB 9Rd4vCJaSrg66kSeXpLFTg3gT5nzpdJJ8fYmXvmCKSwQvlotLRVzBJWYAhOaiPNRZtB8 zYqgZclBacn+ROAW4qW62agsq+6SBKXvI1bgnRATicDtwV68zrg4bQNmbzoIVj+gmEjP NzBHudFvbBRi35rbkCJ8SrQlkJXtmVOaPjFpA76Xic/NCkL3f5d09VCD5qZdfqcMY8a7 4YZw== X-Gm-Message-State: APjAAAWAIhUCj1WahVWh5gRE1xNZde7+g6YR8+CYpIM8Pf1b+BLEesxf J0xk/KDRMyQZk1GqiJvNeIIaCA== X-Received: by 2002:a2e:204e:: with SMTP id g75mr14249387ljg.92.1555523407854; Wed, 17 Apr 2019 10:50:07 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id f4sm11197173ljg.37.2019.04.17.10.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 10:50:07 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, ilias.apalodimas@linaro.org, hawk@kernel.org, xdp-newbies@vger.kernel.org, ast@kernel.org, aniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, Ivan Khoronzhuk Subject: [RFC PATCH 1/3] net: ethernet: ti: davinci_cpdma: add dma mapped submit Date: Wed, 17 Apr 2019 20:49:40 +0300 Message-Id: <20190417174942.11811-2-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190417174942.11811-1-ivan.khoronzhuk@linaro.org> References: <20190417174942.11811-1-ivan.khoronzhuk@linaro.org> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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 | 84 ++++++++++++++++++++----- drivers/net/ethernet/ti/davinci_cpdma.h | 2 + 2 files changed, 72 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 4236dcdd5634..96ec1d9d8f47 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -132,6 +132,15 @@ struct cpdma_chan { u32 rate; }; +struct submit_info { + struct cpdma_chan *chan; + int directed; + void *token; + void *data; + int flags; + int len; +}; + struct cpdma_control_info { u32 reg; u32 shift, mask; @@ -183,6 +192,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; @@ -1026,10 +1037,11 @@ static void __cpdma_chan_submit(struct cpdma_chan *chan, } } -int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, - int len, int directed) +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; struct cpdma_desc __iomem *desc; dma_addr_t buffer; unsigned long flags; @@ -1061,16 +1073,22 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, chan->stats.runt_transmit_buff++; } - buffer = dma_map_single(ctlr->dev, data, len, chan->dir); - ret = dma_mapping_error(ctlr->dev, buffer); - if (ret) { - cpdma_desc_free(ctlr->pool, desc, 1); - ret = -EINVAL; - goto unlock_ret; - } - mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; - cpdma_desc_to_port(chan, mode, directed); + cpdma_desc_to_port(chan, mode, si->directed); + + if (si->flags & CPDMA_DMA_EXT_MAP) { + buffer = (dma_addr_t)si->data; + dma_sync_single_for_device(ctlr->dev, buffer, len, chan->dir); + len |= 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); + ret = -EINVAL; + goto unlock_ret; + } + } /* Relaxed IO accessors can be used here as there is read barrier * at the end of write sequence. @@ -1079,7 +1097,7 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, writel_relaxed(buffer, &desc->hw_buffer); writel_relaxed(len, &desc->hw_len); writel_relaxed(mode | len, &desc->hw_mode); - writel_relaxed((uintptr_t)token, &desc->sw_token); + writel_relaxed((uintptr_t)si->token, &desc->sw_token); writel_relaxed(buffer, &desc->sw_buffer); writel_relaxed(len, &desc->sw_len); desc_read(desc, sw_len); @@ -1095,8 +1113,39 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, spin_unlock_irqrestore(&chan->lock, flags); return ret; } + +int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, + int directed) +{ + struct submit_info si; + + si.chan = chan; + si.token = token; + si.data = data; + si.len = len; + si.directed = directed; + si.flags = 0; + + return cpdma_chan_submit_si(&si); +} EXPORT_SYMBOL_GPL(cpdma_chan_submit); +int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token, void *data, + int len, int directed) +{ + struct submit_info si; + + si.chan = chan; + si.token = token; + si.data = data; + si.len = len; + si.directed = directed; + si.flags = CPDMA_DMA_EXT_MAP; + + return cpdma_chan_submit_si(&si); +} +EXPORT_SYMBOL_GPL(cpdma_chan_submit_mapped); + bool cpdma_check_free_tx_desc(struct cpdma_chan *chan) { struct cpdma_ctlr *ctlr = chan->ctlr; @@ -1123,10 +1172,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 d399af5389b8..20e4d43df6d1 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -84,6 +84,8 @@ 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, void *data, + int len, int directed); int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int len, int directed); int cpdma_chan_process(struct cpdma_chan *chan, int quota);