Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2104950ybm; Thu, 23 May 2019 11:25:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxG0NEnYuXaE0ngZ1Ga2XS2IbjqJZRG7g4xJQvl9yyttg033rItDvnCqWMRmCcs+qh2gd9q X-Received: by 2002:a62:6d47:: with SMTP id i68mr106625982pfc.189.1558635954582; Thu, 23 May 2019 11:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558635954; cv=none; d=google.com; s=arc-20160816; b=D7sa1mQTAvCMXjkVBsvYfAcIfhhpdvUU8UfrMwZkDp9S36ZsqWkD2YRpUXQJTITaRy 6g4d2tbnzhlchTrNs2OtDxyEttcPn4Th3Z6EVCRgY5/7n4XXdaYGXm62jqzbjrv8M19u 6co0nmk94TdVp+lYWsk6juNKxbmm32iKlYS0MaZ36dTCwFz6WVp4KQoVnx5XG5Ab8/q1 PJ7tgAPRPnXMQ73zBjdBYmEzMNr6v3NPg0qtxK5Z0bsh1oWszROfZGdvWz83QPAbpX2P IA/RQp7/Xb/xLAJfugDCec3wwH2uRx/1bwO0N/0bdcqKwMgvMI5dJM1GBt7uIk8Wsf98 U4sQ== 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=ExBErmLKvAHAcEzB9N5VayIpTNJEe2yiC9dz/BkkizE=; b=JJ4sk082JOf7Jgrk0xnw1Sc5Qh3fc/7YnfSdPFg7BCm7cSoW4UcDlaZztwhfZfKJkh TPrlc5OnynN9kfBsx+Ujoreznump6ZmVZZ2j3ce1eRx1KqarY3w8OU9UkE7X0HA4lkIW Hde/ER7T/ES5snXdd6twlJDE2A57mqSjZd8XBiD8OkzovLOvadK18ZzsbMAGoHas8BFW eoQNCkNWF1uLmMAFNY4zqVy6SHAPBdNk8r1io44tJq9BU6ZEoembK3EeQc2hoLEcp98J MlnhPd5JBhT4APjfEd9OSHPgsdimdBvauNcPBmvThPrtB2BKwi8DnD0NnrxF+n1I6nIQ GfqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Jt7Fpt/P"; 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 p16si349990pgg.59.2019.05.23.11.25.38; Thu, 23 May 2019 11:25:54 -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="Jt7Fpt/P"; 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 S1731591AbfEWSWY (ORCPT + 99 others); Thu, 23 May 2019 14:22:24 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33858 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731443AbfEWSWH (ORCPT ); Thu, 23 May 2019 14:22:07 -0400 Received: by mail-lf1-f65.google.com with SMTP id v18so5123367lfi.1 for ; Thu, 23 May 2019 11:22:05 -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=ExBErmLKvAHAcEzB9N5VayIpTNJEe2yiC9dz/BkkizE=; b=Jt7Fpt/PNF3rJVbtyZwTEO5En1kS6xwPMi8rxm+kvjTx0YaNdEP90fpTn5S8UqN2GI cHhg8f+t3VUw7xaVF2rKqUOuJN67s1dhzPuonwuom5jTwbKnbLeGDUeE/K3ONRS8MDZS Hi6qhk3MwbxCyUwhOiw2TnjlfbgM4yq/A2SjIMlBBw62Zqh8qp360MkN9XlAeAj0ggrx hW71K8v27oymqy5rtlzb36//GOX8GNMGTZaebKQz+wyYjBniLNAjLH4uITknVDQk2NLv fwHHXizcIebDh4VnLStsKgwFHHCQrtL8yUnbKLbKuBoOXDKMtZLrz2iP7EFQwwETks+a HuvQ== 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=ExBErmLKvAHAcEzB9N5VayIpTNJEe2yiC9dz/BkkizE=; b=mV5HsgUF6zviYUVedD3uqczkwsO3liZbhnXhX1HTvfvafVZGmzNdWwKWyAgaMOWYw4 vYOiXwvDjnqvBEDb1pRnXbTjMdXjtpkAlCIVt83UyBmapC4MGaAtk5n6DPlH4FwEQaVy YG1MPLvXZwkbPm7U8MdxufD0a3reg7LkPAPtr8d8t2dgbTh8+isDgkk/wrwbo04iGPT0 kUjOyQgmMgVrzsGWh5AGPckuc9v2QmlJesgIusP1xmKRGMP/XgsHNLutzUyYltr2csn2 bAqKV7rru0vIc/zoVlSPp0Y5v3aUcLRisP/efiKpPdaM0441MUMWyhlVIo/NezImp4ei breA== X-Gm-Message-State: APjAAAXZwTHJwxZrYoxa4UqDqbuceOu3w4sLmJDE/M+VnZqAxNtCLWxE 2go4Vip7Txemx0/TOr7hEDz0hw== X-Received: by 2002:ac2:51d1:: with SMTP id u17mr7278737lfm.151.1558635724585; Thu, 23 May 2019 11:22:04 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id n26sm59904lfi.90.2019.05.23.11.22.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 11:22:04 -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 net-next 1/3] net: ethernet: ti: davinci_cpdma: add dma mapped submit Date: Thu, 23 May 2019 21:20:33 +0300 Message-Id: <20190523182035.9283-2-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523182035.9283-1-ivan.khoronzhuk@linaro.org> References: <20190523182035.9283-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 | 88 ++++++++++++++++++++----- drivers/net/ethernet/ti/davinci_cpdma.h | 2 + 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 35bf14d8e7af..7f89b2299f05 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -125,6 +125,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; @@ -176,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; @@ -1002,10 +1013,12 @@ 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; + int swlen = len; struct cpdma_desc __iomem *desc; dma_addr_t buffer; unsigned long flags; @@ -1037,16 +1050,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); + 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); + ret = -EINVAL; + goto unlock_ret; + } + } /* Relaxed IO accessors can be used here as there is read barrier * at the end of write sequence. @@ -1055,9 +1074,9 @@ 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); + writel_relaxed(swlen, &desc->sw_len); desc_read(desc, sw_len); __cpdma_chan_submit(chan, desc); @@ -1072,6 +1091,38 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, 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, + dma_addr_t data, int len, int directed) +{ + struct submit_info si; + + si.chan = chan; + si.token = token; + si.data = (void *)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; @@ -1097,10 +1148,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 10376062dafa..8f6f27185c63 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.h +++ b/drivers/net/ethernet/ti/davinci_cpdma.h @@ -77,6 +77,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, + 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_process(struct cpdma_chan *chan, int quota); -- 2.17.1