From patchwork Mon Jul 8 21:34:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 168691 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7662929ilk; Mon, 8 Jul 2019 14:35:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzOgOuTpEPFx1FskK76W/tg7Xly0n1asU36uIwO/oVITuwDatx5XZbd/oCASMEjtWUoo/0 X-Received: by 2002:a65:500d:: with SMTP id f13mr25839420pgo.151.1562621702458; Mon, 08 Jul 2019 14:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562621702; cv=none; d=google.com; s=arc-20160816; b=OZk7bED5fl/OlRNsgVzbjZUqgP8eIXBdWPNLQXDE31d6UUba+K2ZZrv3KVgBWh9J/z rqPNSDfD/1zVrMXFLpMe84OfYOGYg1Sjc8snNGkKmvRt25s9bPRXjIZYgMToQpvyphuh O3OG8CNJZSs4uVrqkvA9lJTvH5eQxiqnx6rTdpRjR07rScD8J6ykBRtqCFVTm3p1qgyQ xUst7Q57WqZmHx2onfESPW/2a+ertFUlDUI/4pNhv9Hn0XD8X+OqeS9E5Ons17gGydj5 YLv5E1SOBQFm5M4VROmefIdCFk7bqQhg3qUrkdJ/D+5mMSwoo+ObMTRJztf/Eu0HGx3E BZZw== 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=3v0QmJrKMd20DJYv0qL4X2BPmLqZG0NxZOJQQTtv7T8=; b=VLN9HqAb6fZ0jRxCuMTUVJkrEDRe/r4GBbW1XfIQm/caDRk8fiAP0W2WtsQA6XxQRf tO7b44xeHdcYYB8wBzz0H/onUXyHzUVynCc9WY0GuOv1c/CF3QLGu+yxhGLnpICgnoZ9 4gT6DLrbfB/7vH7TP8DuHYAXQeWghlq8DCKR8gdsDpuWSFhu5I/jCElpnarevkqEQFyi KEVrnrS3CY+YIcQhcsEdpLz7kM12mZsShJsWtNYP1t0mrrt1/WOSZAJZTRVenX68pPb+ 7WpKjR0XpFOG17TmtapCw8NHQK6tpa+2/LqkJtmU4vo/Qsr1WZqzdFCoZoKAMWWmDN8r xEYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ekBNtj2e; 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 t25si15761047pgn.160.2019.07.08.14.35.02; Mon, 08 Jul 2019 14:35:02 -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=ekBNtj2e; 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 S2404826AbfGHVen (ORCPT + 5 others); Mon, 8 Jul 2019 17:34:43 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45674 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404537AbfGHVel (ORCPT ); Mon, 8 Jul 2019 17:34:41 -0400 Received: by mail-lf1-f65.google.com with SMTP id u10so11907169lfm.12 for ; Mon, 08 Jul 2019 14:34:39 -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=3v0QmJrKMd20DJYv0qL4X2BPmLqZG0NxZOJQQTtv7T8=; b=ekBNtj2e0yK7B0hx60bsvCHlOLUPqUiNxuff8ENo3o2s1j55tWXtZN3Qc5OwBMp0tB sdkN1NBft9+mBCvNbAz8ovJR/TzWO7MwFNk0O5FrtJo+hKWnZhzlfD27KOvzsX4Y2abL eprUCZY+PMoMxFrrqXW3KwgBZYWx/hVQOUOR/cT99OH8zuXpFhySkuTCzv5XZ0N6Kna4 h9K97DHN9Fo7z0/liUdkOzp6txP6XThQKiIh6aRCuj5mbLiyhkPq0fMEAD0sb8k3UtqX KcAIWhWtudBiydyH4Vw17+4ohhNav0bIX3bwfOXfLzMINQoXmnxDg2yJi3rhsTdQU/L+ sMkg== 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=3v0QmJrKMd20DJYv0qL4X2BPmLqZG0NxZOJQQTtv7T8=; b=SdFPhLLIg4tCh0mxPTU2b2KEVotrqZ2+o548ES3fkERFgDL4x6GRXX6CtxDF4DgVSw Uqw/O7SlQ58FlXSWWWEt+8JV1TizdrhtU5pdnjq0piuwgkXtknet54AyU4KrcZJSFMxw gK14sDO4WDBIcGrf8a8CdHHGNztpdmY6QHkz93Jik7Wfu+M4CjrJYij7S81tttXr0lrR hUX9KIqhxasdT/6On9MhA5mye1+RTcoQCSWFN9D/bbEY9BV16k18QiU3WgBYu4zV6eV/ 7MmtEqeMoIfczXqc/gUc8X3T3TgXbFd4SsXAoe+aag+Q1ETtq1iVjGJxpSmPtRaRwTGl Z+eg== X-Gm-Message-State: APjAAAVXw1kC9Haxp42O6M2I9vm5poflCm+wzHl4Gv1W4xj5XH/Xwt/j ZbwNDzldLNMU7KBHGwreCAEWGQ== X-Received: by 2002:a19:f24e:: with SMTP id d14mr10233792lfk.184.1562621678441; Mon, 08 Jul 2019 14:34:38 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id o24sm3883096ljg.6.2019.07.08.14.34.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:34:37 -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 v9 net-next 2/5] net: ethernet: ti: davinci_cpdma: add dma mapped submit Date: Tue, 9 Jul 2019 00:34:29 +0300 Message-Id: <20190708213432.8525-3-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708213432.8525-1-ivan.khoronzhuk@linaro.org> References: <20190708213432.8525-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 --- v8..v9: - fix warnings on arm64 caused by typos in type casting 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..4e693c3aab27 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 = (dma_addr_t)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 *)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 *)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);