Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp11209383imu; Thu, 6 Dec 2018 13:24:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/UKGyr0kukNezY48WENZDFehGifjkHPtNAK48GRfMIxh9dMMJ7qLNyWT90iaGC3W91x1ykd X-Received: by 2002:a62:37c3:: with SMTP id e186mr30952545pfa.251.1544131440895; Thu, 06 Dec 2018 13:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544131440; cv=none; d=google.com; s=arc-20160816; b=cqcFAvZ8s5JZe0saMUX5d4SDKGcpa4IqHXACXJTRNhgoQaSchOiDFYa+BisnsA4C8o ygF3qsaYvjtAdKgXvC0tslXYXSVvIVwSgmMTy6jEArEDN4eHJOfXkwEasm7hJs7Tzvgs t39mnnQKcYHger0SHjDT3uIW92WUk3QZPZiL+vMWCaJEb2MLSH1WvgtMU4yE6KgamQBV R8C7V0RuK3YrKTkMUQ/fLjrKERyGEZHW2aXSmo/WsrkjIZD9C5K420U2l8lsUwFkU9CZ MwB18X7pIUqTmYUogNT0RtnRNr9Nm/uq1IpUAtqqiNvtpwUD2eWwQ9DfQ/yXjzN2uJAr Rg4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6KdGMyekJLhhM6THDxJU6NxCxRI8De9Mytd1OU5dO5Y=; b=jRCvieIzjMeCb8vF+see6SmCsl/VCE4HvY4Z4To02oVA7p+Ee1YGADGgyVIRp4p3dZ gIfyCiDPfaYYcpfQMd26zXdsiXXHYVnXpG2bUaoIT+dEfSNWzetGb5tq/hv57zec8LAR EUKtvG7QUf8lA+ug8r+y6obPdZy0cAiU53ALv1HJJeOyKszpiQMHW/1uGsQUuYfW0HYn YHPiTfru78a1a/9IJrM6cMPnBNc5anaPFndgsygxTxmJt2OK18dm2XImVjvCP8xs6dlh pvDiioN1p7PllCPK4rzNjQaACLKLxnpkqFkggaW0RbU9x/cYB+ZFymz/1B1k1bduFA9K h6zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hnGmv73y; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si1054806pgt.293.2018.12.06.13.23.44; Thu, 06 Dec 2018 13:24:00 -0800 (PST) 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=@kernel.org header.s=default header.b=hnGmv73y; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726056AbeLFVWR (ORCPT + 99 others); Thu, 6 Dec 2018 16:22:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:41516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbeLFVWQ (ORCPT ); Thu, 6 Dec 2018 16:22:16 -0500 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1242E20989; Thu, 6 Dec 2018 21:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544131334; bh=cZ6tmMowWci0xd5MI0B7S0zbMLSctTiSpwTaxd56MIY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hnGmv73ym9UfYGzNpNXSp0r+1tNkKv14olV6qIbPQ/QzjR6USdU7ebdaF4nLDwYnI ZDGQKK3OUYpc1lO8oFwx0nQSG6sAxdeFB8/ZcHXcisHbiJ4e7LkTND2rH+jAhuI+Ba nlrHGVlF+5ZJZis+jfcM93T92EA6m5lEdwpTh4yY= Received: by mail-wm1-f43.google.com with SMTP id q26so2498019wmf.5; Thu, 06 Dec 2018 13:22:14 -0800 (PST) X-Gm-Message-State: AA+aEWb2U4brznfZbrPTz/kKGDP5PG15a8reBkZQogg9bcpa5bunsf8E bAx2wbn6les6qDxmj7lfAOvQb/IxunMLTXSnNPs= X-Received: by 2002:a1c:e18a:: with SMTP id y132mr10063wmg.48.1544131332512; Thu, 06 Dec 2018 13:22:12 -0800 (PST) MIME-Version: 1.0 References: <1543999380-7946-1-git-send-email-long.cheng@mediatek.com> <1543999380-7946-3-git-send-email-long.cheng@mediatek.com> <1544090140.28871.11.camel@mhfsdcap03> In-Reply-To: <1544090140.28871.11.camel@mhfsdcap03> From: Sean Wang Date: Thu, 6 Dec 2018 13:22:01 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/4] dmaengine: mtk_uart_dma: add Mediatek uart DMA support To: long.cheng@mediatek.com Cc: vkoul@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, srv_heupstream@mediatek.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-serial@vger.kernel.org, jslaby@suse.com, Matthias Brugger , yingjoe.chen@mediatek.com, dan.j.williams@intel.com, linux-arm-kernel@lists.infradead.org, yt.shen@mediatek.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 6, 2018 at 1:55 AM Long Cheng wrote: > > On Wed, 2018-12-05 at 13:07 -0800, Sean Wang wrote: > > . > > On Wed, Dec 5, 2018 at 1:31 AM Long Cheng wrote: > > > > > > In DMA engine framework, add 8250 mtk dma to support it. > > > > > > Signed-off-by: Long Cheng > > > --- > > > drivers/dma/mediatek/8250_mtk_dma.c | 894 +++++++++++++++++++++++++++++++++++ > > > drivers/dma/mediatek/Kconfig | 11 + > > > drivers/dma/mediatek/Makefile | 1 + > > > 3 files changed, 906 insertions(+) > > > create mode 100644 drivers/dma/mediatek/8250_mtk_dma.c > > > > > > diff --git a/drivers/dma/mediatek/8250_mtk_dma.c b/drivers/dma/mediatek/8250_mtk_dma.c > > > new file mode 100644 > > > index 0000000..3454679 > > > --- /dev/null > > > +++ b/drivers/dma/mediatek/8250_mtk_dma.c > > > @@ -0,0 +1,894 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * Mediatek 8250 DMA driver. > > > + * > > > + * Copyright (c) 2018 MediaTek Inc. > > > + * Author: Long Cheng > > > + */ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +#include "../virt-dma.h" > > > + > > > +#define MTK_APDMA_DEFAULT_REQUESTS 127 > > > +#define MTK_APDMA_CHANNELS (CONFIG_SERIAL_8250_NR_UARTS * 2) > > > + > > > +#define VFF_EN_B BIT(0) > > > +#define VFF_STOP_B BIT(0) > > > +#define VFF_FLUSH_B BIT(0) > > > +#define VFF_4G_SUPPORT_B BIT(0) > > > +#define VFF_RX_INT_EN0_B BIT(0) /*rx valid size >= vff thre*/ > > > +#define VFF_RX_INT_EN1_B BIT(1) > > > +#define VFF_TX_INT_EN_B BIT(0) /*tx left size >= vff thre*/ > > > +#define VFF_WARM_RST_B BIT(0) > > > +#define VFF_RX_INT_FLAG_CLR_B (BIT(0) | BIT(1)) > > > +#define VFF_TX_INT_FLAG_CLR_B 0 > > > +#define VFF_STOP_CLR_B 0 > > > +#define VFF_FLUSH_CLR_B 0 > > > +#define VFF_INT_EN_CLR_B 0 > > > +#define VFF_4G_SUPPORT_CLR_B 0 > > > + > > > +/* interrupt trigger level for tx */ > > > +#define VFF_TX_THRE(n) ((n) * 7 / 8) > > > +/* interrupt trigger level for rx */ > > > +#define VFF_RX_THRE(n) ((n) * 3 / 4) > > > + > > > +#define MTK_DMA_RING_SIZE 0xffffU > > > +/* invert this bit when wrap ring head again*/ > > > +#define MTK_DMA_RING_WRAP 0x10000U > > > + > > > +#define VFF_INT_FLAG 0x00 > > > +#define VFF_INT_EN 0x04 > > > +#define VFF_EN 0x08 > > > +#define VFF_RST 0x0c > > > +#define VFF_STOP 0x10 > > > +#define VFF_FLUSH 0x14 > > > +#define VFF_ADDR 0x1c > > > +#define VFF_LEN 0x24 > > > +#define VFF_THRE 0x28 > > > +#define VFF_WPT 0x2c > > > +#define VFF_RPT 0x30 > > > +/*TX: the buffer size HW can read. RX: the buffer size SW can read.*/ > > > +#define VFF_VALID_SIZE 0x3c > > > +/*TX: the buffer size SW can write. RX: the buffer size HW can write.*/ > > > +#define VFF_LEFT_SIZE 0x40 > > > +#define VFF_DEBUG_STATUS 0x50 > > > +#define VFF_4G_SUPPORT 0x54 > > > + > > > +struct mtk_dmadev { > > > + struct dma_device ddev; > > > + void __iomem *mem_base[MTK_APDMA_CHANNELS]; > > > + spinlock_t lock; /* dma dev lock */ > > > + struct tasklet_struct task; > > > + struct list_head pending; > > > + struct clk *clk; > > > + unsigned int dma_requests; > > > + bool support_33bits; > > > + unsigned int dma_irq[MTK_APDMA_CHANNELS]; > > > + struct mtk_chan *ch[MTK_APDMA_CHANNELS]; > > > +}; > > > + > > > +struct mtk_chan { > > > + struct virt_dma_chan vc; > > > + struct list_head node; > > > + struct dma_slave_config cfg; > > > + void __iomem *base; > > > + struct mtk_dma_desc *desc; > > > + > > > + bool stop; > > > + bool requested; > > > + > > > + unsigned int dma_sig; > > > > the member can be removed as no real user would refer to it > > > > Ok, i will remove it at next patch > > > > + unsigned int dma_ch; > > > > a chan_id is already included in struct dma_chan, we can reuse it > > > > chan_id is start from 0. but in this driver, dma info is stored to list. > if use port1, in filter_fn function, will set dma_ch to 2, 3(tx, rx). So > can't using chan_id > if you use of_dma_xlate_by_chan_id in of_dma_controller_register, the client device still can get the right channel with the appropriate chan_id expressed in dmas property in dts. > > > + unsigned int sgidx; > > [ ... ] > ok, i will modify it > > > + wpt = mtk_dma_chan_read(c, VFF_WPT); > > > + wrap = wpt & MTK_DMA_RING_WRAP ? 0U : MTK_DMA_RING_WRAP; > > > + > > > + if ((wpt & (len - 1U)) + send < len) > > > + mtk_dma_chan_write(c, VFF_WPT, wpt + send); > > > + else > > > + mtk_dma_chan_write(c, VFF_WPT, > > > + ((wpt + send) & (len - 1U)) > > > + | wrap); > > > + > > > + c->remain_size -= send; > > > > I'm curious why you don't need to set up the hardware from the > > descriptor information > > > > mtk_dma_chan_write is update the hardware. remain_size is length of TX > data. I thought it is not enough to be a full dmaengine. if the driver only supports single continuous data moving for device_prep_slave_sg callback. We could try to turn each sg item information such as source or destination address and data length to be one part of the descriptor. When a descriptor is being issued, and then program VFF_ADDR/LEN and issue the data move by other VFF_* registers rather than assuming the data portion is always the fixed as the user assignment at mtk_dma_slave_config.