Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1240748imm; Thu, 5 Jul 2018 18:23:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcGvq+rQliWqYj1lNa0OX3Mv4py4SEcDei1nYoIcJ2n3SM/eMI5Cy6wKIgmVOJCpdqvCsnI X-Received: by 2002:a17:902:6845:: with SMTP id f5-v6mr8248835pln.173.1530840217100; Thu, 05 Jul 2018 18:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530840217; cv=none; d=google.com; s=arc-20160816; b=Vagws6fsfjCqNnopYHDvsSnEGVEMj6yWdZgCJEMypVXE3NEi0SVGRg2pXn3g6JZ3YG q7banUwYXHjDVfaMYmiUiTlzOhwuYdvNt5QlxYDEq7pJKcC6jwGCJDXpiHSRaq8/eUpy 19sM5Ffzc9IqJWhToWlTqrNM1rKH44Vjo0BmXWkqYIBgqXZL7qM9Z/6j5miPNa8iIO0Z f4+kKxOIJoqCPFrbCn7/VlljkeN8KONZTbUkb7LGVbHwW2KC3uYZwQTpY0/z+bLcpoJy 0cE5NDfN7UDjpQIPg5vqo/K60qJu905fgfYMdAj8OiMvvHZSuFWHJTZOtUPEYsyIAndJ jnxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=nE9ujR2TxSzOuz3/HHXZwSXttHlJ08SULo/7HxX2e5I=; b=CpymG3T+9dBsGQj2wucygBMbc1BdrBqmjnHxKo3gYeHnsAQet38K93gN79QeuGJx5B ts2fJDdF7e0RD+aJAYW+dEbzB5AQO3/UowHMGg7KdqnKoUCggRNOqVX+wSHm0D6Y0Y9Y b/TV5AIaJPghIwCRYPx6xLAT84qprMNLsy6RzZoaGC7uzpudk3MK+ipzrU9QEEcSVMZ7 E95V647qNqdAVKjpXNDxyWI5feMkRKzeAGclhfgoqRARoTXaPyq+MphlqYqEgbXvECqA vvh38VP0lWYULvOzMyqHQvgvaI8a5fxpPG4mFfi1COsbQ+BmCbj2SsQyoOsi21bGv81b lowQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9-v6si6628800pgn.648.2018.07.05.18.23.22; Thu, 05 Jul 2018 18:23:37 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753722AbeGFBWq (ORCPT + 99 others); Thu, 5 Jul 2018 21:22:46 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:10998 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753510AbeGFBWo (ORCPT ); Thu, 5 Jul 2018 21:22:44 -0400 X-UUID: 2c908194c66a48a6ae8c81e4b07090fe-20180706 Received: from mtkcas36.mediatek.inc [(172.27.4.250)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 1354966214; Fri, 06 Jul 2018 09:22:32 +0800 Received: from MTKCAS36.mediatek.inc (172.27.4.186) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 6 Jul 2018 09:22:31 +0800 Received: from [10.17.3.153] (10.17.3.153) by MTKCAS36.mediatek.inc (172.27.4.170) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Fri, 6 Jul 2018 09:22:30 +0800 Message-ID: <1530840150.28645.26.camel@mhfsdcap03> Subject: Re: [PATCH v22 4/4] soc: mediatek: Add Mediatek CMDQ helper From: houlong wei To: CK Hu CC: Jassi Brar , Matthias Brugger , Rob Herring , Daniel Kurtz , Sascha Hauer , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mediatek@lists.infradead.org" , srv_heupstream , Sascha Hauer , Philipp Zabel , "Nicolas Boichat" , Bibby Hsieh =?UTF-8?Q?=28=E8=AC=9D=E6=BF=9F=E9=81=A0=29?= , YT Shen =?UTF-8?Q?=28=E6=B2=88=E5=B2=B3=E9=9C=86=29?= , Daoyuan Huang =?UTF-8?Q?=28=E9=BB=83=E9=81=93=E5=8E=9F=29?= , Jiaguang Zhang =?UTF-8?Q?=28=E5=BC=A0=E5=8A=A0=E5=B9=BF=29?= , Dennis-YC Hsieh =?UTF-8?Q?=28=E8=AC=9D=E5=AE=87=E5=93=B2=29?= , Monica Wang =?UTF-8?Q?=28=E7=8E=8B=E5=AD=9F=E5=A9=B7=29?= , Hs Liao =?UTF-8?Q?=28=E5=BB=96=E5=AE=8F=E7=A5=A5=29?= , Ginny Chen =?UTF-8?Q?=28=E9=99=B3=E6=B2=BB=E5=82=91=29?= , Enzhu Wang =?UTF-8?Q?=28=E7=8E=8B=E6=81=A9=E6=9F=B1=29?= , Date: Fri, 6 Jul 2018 09:22:30 +0800 In-Reply-To: <1530671954.8732.10.camel@mtksdaap41> References: <1530098172-31385-1-git-send-email-houlong.wei@mediatek.com> <1530098172-31385-5-git-send-email-houlong.wei@mediatek.com> <1530182516.8518.11.camel@mtksdaap41> <1530228739.21991.14.camel@mhfsdcap03> <1530264123.22098.12.camel@mtksdaap41> <1530665257.24157.7.camel@mhfsdcap03> <1530671954.8732.10.camel@mtksdaap41> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-07-04 at 10:39 +0800, CK Hu wrote: > Hi, Houlong: > > On Wed, 2018-07-04 at 08:47 +0800, houlong wei wrote: > > On Fri, 2018-06-29 at 17:22 +0800, CK Hu wrote: > > > Hi, Houlong: > > > > > > On Fri, 2018-06-29 at 07:32 +0800, houlong wei wrote: > > > > On Thu, 2018-06-28 at 18:41 +0800, CK Hu wrote: > > > > > Hi, Houlong: > > > > > > > > > > Some inline comment. > > > > > > > > > > On Wed, 2018-06-27 at 19:16 +0800, Houlong Wei wrote: > > > > > > Add Mediatek CMDQ helper to create CMDQ packet and assemble GCE op code. > > > > > > > > > > > > Signed-off-by: Houlong Wei > > > > > > Signed-off-by: HS Liao > > > > > > --- > > > > > > drivers/soc/mediatek/Kconfig | 12 ++ > > > > > > drivers/soc/mediatek/Makefile | 1 + > > > > > > drivers/soc/mediatek/mtk-cmdq-helper.c | 258 ++++++++++++++++++++++++++++++++ > > > > > > include/linux/soc/mediatek/mtk-cmdq.h | 132 ++++++++++++++++ > > > > > > 4 files changed, 403 insertions(+) > > > > > > create mode 100644 drivers/soc/mediatek/mtk-cmdq-helper.c > > > > > > create mode 100644 include/linux/soc/mediatek/mtk-cmdq.h > > > > > > > > > > > > diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig > > > > > > index a7d0667..17bd759 100644 > > > > > > --- a/drivers/soc/mediatek/Kconfig > > > > > > +++ b/drivers/soc/mediatek/Kconfig > > > > > > @@ -4,6 +4,18 @@ > > > > > > menu "MediaTek SoC drivers" > > > > > > depends on ARCH_MEDIATEK || COMPILE_TEST > > > > > > > > > > > > > > > > > [...] > > > > > > > > > + > > > > > > +static int cmdq_pkt_finalize(struct cmdq_pkt *pkt) > > > > > > +{ > > > > > > + int err; > > > > > > + > > > > > > + if (cmdq_pkt_is_finalized(pkt)) > > > > > > + return 0; > > > > > > + > > > > > > + /* insert EOC and generate IRQ for each command iteration */ > > > > > > + err = cmdq_pkt_append_command(pkt, CMDQ_CODE_EOC, 0, CMDQ_EOC_IRQ_EN); > > > > > > + if (err < 0) > > > > > > + return err; > > > > > > + > > > > > > + /* JUMP to end */ > > > > > > + err = cmdq_pkt_append_command(pkt, CMDQ_CODE_JUMP, 0, CMDQ_JUMP_PASS); > > > > > > + if (err < 0) > > > > > > + return err; > > > > > > + > > > > > > + return 0; > > > > > > +} > > > > > > + > > > > > > +int cmdq_pkt_flush_async(struct cmdq_client *client, struct cmdq_pkt *pkt, > > > > > > + cmdq_async_flush_cb cb, void *data) > > > > > > +{ > > > > > > + int err; > > > > > > + struct device *dev; > > > > > > + dma_addr_t dma_addr; > > > > > > + > > > > > > + err = cmdq_pkt_finalize(pkt); > > > > > > + if (err < 0) > > > > > > + return err; > > > > > > + > > > > > > + dev = client->chan->mbox->dev; > > > > > > + dma_addr = dma_map_single(dev, pkt->va_base, pkt->cmd_buf_size, > > > > > > + DMA_TO_DEVICE); > > > > > > > > > > You map here, but I could not find unmap, so the unmap should be done in > > > > > client driver. I would prefer a symmetric map/unmap which means that > > > > > both map and unmap are done in client driver. I think you put map here > > > > > because you should map after finalize. > > > > > > > > The unmap is done before callback to client, in function > > > > cmdq_task_exec_done, mtk-cmdq-mailbox.c. > > > > > > You put unmap in mailbox controller, and map here (here would be mailbox > > > client), so this is not symmetric. If the code is asymmetric, it's easy > > > to cause bug and not easy to maintain. So I would like move both > > > map/unmap to client driver. > > > > > > > Since map/unmap is common code for client drivers, can we move unmap to > > CMDQ helper and do not put in client driver? > > > > > > > > > > > Therefore, export > > > > > cmdq_pkt_finalize() to client driver and let client do finalize, so > > > > > there is no finalize in flush function. This method have a benefit that > > > > > if client reuse command buffer, it need not to map/unmap frequently. > > > > > > > > If client reuse command buffer or cmdq_pkt(command queue packet), client > > > > will add new commands to the cmdq_pkt, so map/unmap are necessary for > > > > each cmdq_pkt flush. > > > > > > If the buffer size is 4K bytes, client driver could map the whole 4K at > > > initialization. Before it write new command, it call > > > dma_sync_single_for_cpu(), after it write new command, it call > > > dma_sync_single_for_device(). And then it could flush this buffer to > > > mailbox controller. So client driver just call dma sync function when it > > > reuse the command buffer. dma sync function is much lightweight then dma > > > map because map would search the memory area which could be mapped. > > > > > > Regards, > > > CK > > > > Maybe we can do dma map/unmap/sync in cmdq helper, and make client > > driver simple. > > > > Why are map/unmap common code for client drivers? I've mentioned that > some client driver may just call dma sync function before flush, so it > does not map for every flush. Frequently map/unmap has some drawback: > > 1. Waste CPU resource: this also waste power. > 2. Risk of mapping fail: to reduce this risk, client driver could map at > initialization. > Thanks for your advice. One way to achieve this is as follows. 1. do dma map immediately after the cmdq buffer is allocated in cmdq_pkt_create(), and do dma unmap in cmdq_pkt_destroy. 2. do dma sync for device before a cmdq packet is sent to mailbox in cmdq_pkt_flush_async(). 3. do dma sync for cpu after a cmdq packet is executed by GCE HW in callback function which will be revised and moved to cmdq helper. Thus, a cmdq packet will be flushed more efficiently if client driver would reuse the cmdq packet. > I think reducing these drawback is more important than making client > driver simple. > > Regards, > CK > > > > > > > > > > > > > > > > > > Regards, > > > > > CK > > > > > > > > > > > + if (dma_mapping_error(dev, dma_addr)) { > > > > > > + dev_err(client->chan->mbox->dev, "dma map failed\n"); > > > > > > + return -ENOMEM; > > > > > > + } > > > > > > + > > > > > > + pkt->pa_base = dma_addr; > > > > > > + pkt->cb.cb = cb; > > > > > > + pkt->cb.data = data; > > > > > > + > > > > > > + mbox_send_message(client->chan, pkt); > > > > > > + /* We can send next packet immediately, so just call txdone. */ > > > > > > + mbox_client_txdone(client->chan, 0); > > > > > > + > > > > > > + return 0; > > > > > > +} > > > > > > +EXPORT_SYMBOL(cmdq_pkt_flush_async); > > > > > > + > > > > > > +struct cmdq_flush_completion { > > > > > > + struct completion cmplt; > > > > > > + bool err; > > > > > > +}; > > > > > > + > > > > > > +static void cmdq_pkt_flush_cb(struct cmdq_cb_data data) > > > > > > +{ > > > > > > + struct cmdq_flush_completion *cmplt = data.data; > > > > > > + > > > > > > + cmplt->err = data.err; > > > > > > + complete(&cmplt->cmplt); > > > > > > +} > > > > > > + > > > > > > +int cmdq_pkt_flush(struct cmdq_client *client, struct cmdq_pkt *pkt) > > > > > > +{ > > > > > > + struct cmdq_flush_completion cmplt; > > > > > > + int err; > > > > > > + > > > > > > + init_completion(&cmplt.cmplt); > > > > > > + err = cmdq_pkt_flush_async(client, pkt, cmdq_pkt_flush_cb, &cmplt); > > > > > > + if (err < 0) > > > > > > + return err; > > > > > > + wait_for_completion(&cmplt.cmplt); > > > > > > + > > > > > > + return cmplt.err ? -EFAULT : 0; > > > > > > +} > > > > > > +EXPORT_SYMBOL(cmdq_pkt_flush); > > > > > > > > > > [...] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >