From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,T_DKIMWL_WL_HIGH,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B94D5C04A6B for ; Wed, 8 May 2019 05:41:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 841CC2053B for ; Wed, 8 May 2019 05:41:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pz2aYj1F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 841CC2053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=27ovUNbPyAhcsiRHOHPuyAxbl/aIxCOz0yqY9b3p80Q=; b=pz2aYj1FRkBHNF tFQzMlDe+5Ev5OibfYUBR1v/CHmjwZbt9cfTiNch32l8m6NhpQ/RoP0qc22Px9N8etR6L1ccfwy7R sWmiPzpgKN6bgoWyfovcCfGAPsTPfMkL9WoLZtq2vX5Rvswz/LrLalPFezqrevaIbQ3Jrs+SzyoeK 5zFXdmmy6Cjip993DrQpOXFmpxYnCRWxCmk8u6MbEkMoBAh4vk6dcxXIht/HzSmoF+KF/xMD9TQ+e eFDKNyjGCaUMwhxYZos84E9x/N5mMomQhQ75HXqONb6BC9fx+QKe2WGCLI6HrjWewD6VWtVg4qAB8 QWk1mY0XIJPfhx2hiYWw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOFK5-00033U-OJ; Wed, 08 May 2019 05:40:57 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOFK2-00032e-LM; Wed, 08 May 2019 05:40:56 +0000 X-UUID: c5d3dd65ea80446b9db813ee823d5cc0-20190507 X-UUID: c5d3dd65ea80446b9db813ee823d5cc0-20190507 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 459681260; Tue, 07 May 2019 21:40:49 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 7 May 2019 22:40:48 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 8 May 2019 13:40:46 +0800 Received: from [172.21.77.4] (172.21.77.4) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 8 May 2019 13:40:46 +0800 Message-ID: <1557294046.3936.14.camel@mtksdaap41> Subject: Re: [PATCH v5 08/12] soc: mediatek: cmdq: define the instruction struct From: CK Hu To: Bibby Hsieh Date: Wed, 8 May 2019 13:40:46 +0800 In-Reply-To: <20190507081355.52630-9-bibby.hsieh@mediatek.com> References: <20190507081355.52630-1-bibby.hsieh@mediatek.com> <20190507081355.52630-9-bibby.hsieh@mediatek.com> X-Mailer: Evolution 3.10.4-0ubuntu2 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190507_224054_706902_0EA99FAE X-CRM114-Status: GOOD ( 20.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Nicolas Boichat , Philipp Zabel , srv_heupstream@mediatek.com, kendrick.hsu@mediatek.com, Daoyuan Huang , Sascha Hauer , Jassi Brar , linux-kernel@vger.kernel.org, Daniel Kurtz , Dennis-YC Hsieh , YT Shen , Rob Herring , linux-mediatek@lists.infradead.org, Houlong Wei , Sascha Hauer , Matthias Brugger , Jiaguang Zhang , Frederic Chen , linux-arm-kernel@lists.infradead.org, ginny.chen@mediatek.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, Bibby: On Tue, 2019-05-07 at 16:13 +0800, Bibby Hsieh wrote: > Define a instruction structure for gce driver to append command. I would like you to describe _WHY_ do this. I think you do this for 'code readability'. > > Signed-off-by: Bibby Hsieh > --- > drivers/soc/mediatek/mtk-cmdq-helper.c | 113 +++++++++++++++-------- > include/linux/mailbox/mtk-cmdq-mailbox.h | 2 + > include/linux/soc/mediatek/mtk-cmdq.h | 14 +-- > 3 files changed, 84 insertions(+), 45 deletions(-) > > diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c > index ff9fef5a032b..17ee8196fb3d 100644 > --- a/drivers/soc/mediatek/mtk-cmdq-helper.c > +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c > @@ -9,12 +9,24 @@ > #include > #include > > -#define CMDQ_ARG_A_WRITE_MASK 0xffff > #define CMDQ_WRITE_ENABLE_MASK BIT(0) > #define CMDQ_EOC_IRQ_EN BIT(0) > #define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \ > << 32 | CMDQ_EOC_IRQ_EN) > > +struct cmdq_instruction { > + union { > + u32 value; > + u32 mask; > + }; > + union { > + u16 offset; > + u16 event; > + }; > + u8 subsys; > + u8 op; > +}; > + > static void cmdq_client_timeout(struct timer_list *t) > { > struct cmdq_client *client = from_timer(client, t, timer); > @@ -110,10 +122,8 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt) > } > EXPORT_SYMBOL(cmdq_pkt_destroy); > > -static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, > - u32 arg_a, u32 arg_b) > +static struct cmdq_instruction *cmdq_pkt_append_command(struct cmdq_pkt *pkt) > { > - u64 *cmd_ptr; > > if (unlikely(pkt->cmd_buf_size + CMDQ_INST_SIZE > pkt->buf_size)) { > /* > @@ -127,81 +137,108 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, > pkt->cmd_buf_size += CMDQ_INST_SIZE; > WARN_ONCE(1, "%s: buffer size %u is too small !\n", > __func__, (u32)pkt->buf_size); > - return -ENOMEM; > + return NULL; > } > - cmd_ptr = pkt->va_base + pkt->cmd_buf_size; > - (*cmd_ptr) = (u64)((code << CMDQ_OP_CODE_SHIFT) | arg_a) << 32 | arg_b; > + > pkt->cmd_buf_size += CMDQ_INST_SIZE; > > - return 0; > + return pkt->va_base + pkt->cmd_buf_size - CMDQ_INST_SIZE; > } > > -int cmdq_pkt_write(struct cmdq_pkt *pkt, u32 value, u32 subsys, u32 offset) > +int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value) > { > - u32 arg_a = (offset & CMDQ_ARG_A_WRITE_MASK) | > - (subsys << CMDQ_SUBSYS_SHIFT); > + struct cmdq_instruction *inst; > + > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > + > + inst->op = CMDQ_CODE_WRITE; > + inst->value = value; > + inst->offset = offset; > + inst->subsys = subsys; > > - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WRITE, arg_a, value); > + return 0; > } > EXPORT_SYMBOL(cmdq_pkt_write); > > -int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, > - u32 subsys, u32 offset, u32 mask) > +int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, u16 offset, > + u32 value, u32 mask) > { > + struct cmdq_instruction *inst; > u32 offset_mask = offset; > - int err = 0; > > if (mask != 0xffffffff) { > - err = cmdq_pkt_append_command(pkt, CMDQ_CODE_MASK, 0, ~mask); > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > + > + inst->op = CMDQ_CODE_MASK; > + inst->mask = ~mask; > offset_mask |= CMDQ_WRITE_ENABLE_MASK; > } > - err |= cmdq_pkt_write(pkt, value, subsys, offset_mask); > > - return err; > + return cmdq_pkt_write(pkt, subsys, offset_mask, value); > } > EXPORT_SYMBOL(cmdq_pkt_write_mask); > > -int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event) > +int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event) > { > - u32 arg_b; > + struct cmdq_instruction *inst; > > if (event >= CMDQ_MAX_EVENT) > return -EINVAL; > > - /* > - * WFE arg_b > - * bit 0-11: wait value > - * bit 15: 1 - wait, 0 - no wait > - * bit 16-27: update value > - * bit 31: 1 - update, 0 - no update > - */ > - arg_b = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE; > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > + > + inst->op = CMDQ_CODE_WFE; > + inst->value = CMDQ_WFE_OPTION; > + inst->event = event; > > - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, arg_b); > + return 0; > } > EXPORT_SYMBOL(cmdq_pkt_wfe); > > -int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u32 event) > +int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event) > { > + struct cmdq_instruction *inst; > + > if (event >= CMDQ_MAX_EVENT) > return -EINVAL; > > - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, > - CMDQ_WFE_UPDATE); > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > + > + inst->op = CMDQ_CODE_WFE; > + inst->value = CMDQ_WFE_UPDATE; > + inst->event = event; > + > + return 0; > } > EXPORT_SYMBOL(cmdq_pkt_clear_event); > > static int cmdq_pkt_finalize(struct cmdq_pkt *pkt) > { > - int err; > + struct cmdq_instruction *inst; > + > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > > - /* insert EOC and generate IRQ for each command iteration */ > - err = cmdq_pkt_append_command(pkt, CMDQ_CODE_EOC, 0, CMDQ_EOC_IRQ_EN); > + inst->op = CMDQ_CODE_EOC; > + inst->value = CMDQ_EOC_IRQ_EN; > > - /* JUMP to end */ > - err |= cmdq_pkt_append_command(pkt, CMDQ_CODE_JUMP, 0, CMDQ_JUMP_PASS); > + inst = cmdq_pkt_append_command(pkt); > + if (!inst) > + return -ENOMEM; > + > + inst->op = CMDQ_CODE_JUMP; > + inst->value = CMDQ_JUMP_PASS; > > - return err; > + return 0; > } > > static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data) > diff --git a/include/linux/mailbox/mtk-cmdq-mailbox.h b/include/linux/mailbox/mtk-cmdq-mailbox.h > index 911475da7a53..f21801d32a3a 100644 > --- a/include/linux/mailbox/mtk-cmdq-mailbox.h > +++ b/include/linux/mailbox/mtk-cmdq-mailbox.h > @@ -19,6 +19,8 @@ > #define CMDQ_WFE_UPDATE BIT(31) > #define CMDQ_WFE_WAIT BIT(15) > #define CMDQ_WFE_WAIT_VALUE 0x1 > +#define CMDQ_WFE_OPTION (CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | \ Use a 'tab' to replace 8 white space. > + CMDQ_WFE_WAIT_VALUE) > /** cmdq event maximum */ > #define CMDQ_MAX_EVENT 0x3ff > > diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h > index 4e8899972db4..52f69c8db8de 100644 > --- a/include/linux/soc/mediatek/mtk-cmdq.h > +++ b/include/linux/soc/mediatek/mtk-cmdq.h > @@ -60,26 +60,26 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt); > /** > * cmdq_pkt_write() - append write command to the CMDQ packet > * @pkt: the CMDQ packet > - * @value: the specified target register value > * @subsys: the CMDQ sub system code > * @offset: register offset from CMDQ sub system > + * @value: the specified target register value > * > * Return: 0 for success; else the error code is returned > */ > -int cmdq_pkt_write(struct cmdq_pkt *pkt, u32 value, u32 subsys, u32 offset); > +int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value); > > /** > * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet > * @pkt: the CMDQ packet > - * @value: the specified target register value > * @subsys: the CMDQ sub system code > * @offset: register offset from CMDQ sub system > + * @value: the specified target register value > * @mask: the specified target register mask > * > * Return: 0 for success; else the error code is returned > */ > -int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, > - u32 subsys, u32 offset, u32 mask); > +int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, u16 offset, > + u32 value, u32 mask); Is the changing of parameter position about 'code readability'? > > /** > * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet > @@ -88,7 +88,7 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, > * > * Return: 0 for success; else the error code is returned > */ > -int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event); > +int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event); Is the changing from u32 to u16 about 'code readability'? Regards, CK > > /** > * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet > @@ -97,7 +97,7 @@ int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event); > * > * Return: 0 for success; else the error code is returned > */ > -int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u32 event); > +int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event); > > /** > * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel