Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3599564pxb; Sun, 31 Jan 2021 22:38:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPEpwfZIMMsV5ryPD4/KB9GMj3xsDZv/D/i9pWvVPFDw7MX3OCeuZzDBucU1LXnaphDZ2M X-Received: by 2002:a17:906:259a:: with SMTP id m26mr16539593ejb.399.1612161508193; Sun, 31 Jan 2021 22:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612161508; cv=none; d=google.com; s=arc-20160816; b=zhGQRJAx5ZPK4W1bZNjjJI+32WxgcwA/N+KKS2AxFccs8PV+ObesDpQ8EPxSggi4gP 9S9VrWtVT+ooOlzlRHJHEvLtOVmagwAAU5RyRuypzHUMfKTCIqef7DeWyd+q/Pw9GiUp 8NAxBG2emjAMDsrk76+GX5g6taeC16WI75O5fvwHIpsp7ziVt0/ys6p81RDDgU8Oe+KW SAF2tMq+a3KzVlY4xGTWRlc1yuZyN+e2PSDOWIBIinOMsYNVy7Z+l1aQxS1k1P9JjBbd J01+xUM7zNO2kDKkETiN+0NnK9fXYX1m6vDk7CrSqS9syK2IbiLE8TkyeHEb/veGPw8o yRvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=ZjOKSuEmG5oI5YdY/ZLS031+4Hs/j21RMaHWa9FSN8k=; b=FF3SXkvbyvqtf8Syd/mXUZjCs4Or9dIjy7C3ENCZwM0j+FsQYFPaBTzsJplzfAshB8 s6FMzUCim321UJayozVKIH/XrVC7rfV7cpDi2f6zV07iUQHnK8lLkj69Kp+i+kHBWL+h rmWsG/0i5z1lB19G0yujiidNh11kvVCyWRTqIUERAopL+AmdR4mKHYpRYLn836gMTiw6 Lmb4lbBpPuuOuflBfClBLHZegbG1ykD/s1lhSdTKz7O/rAVAji9Gdug5hKTp/tjqh94n bShXObxipsatuGNHbMNeZhS3kXqQQLsfJGtId//8vJdX6vum0dBpOv1QR4xPZYrlAT1X 6W9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=t0VXQULk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y19si9909428edu.188.2021.01.31.22.38.04; Sun, 31 Jan 2021 22:38:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=t0VXQULk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232239AbhBAGgZ (ORCPT + 99 others); Mon, 1 Feb 2021 01:36:25 -0500 Received: from so15.mailgun.net ([198.61.254.15]:37624 "EHLO so15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbhBAGYM (ORCPT ); Mon, 1 Feb 2021 01:24:12 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1612160583; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=ZjOKSuEmG5oI5YdY/ZLS031+4Hs/j21RMaHWa9FSN8k=; b=t0VXQULkTqusn45Do+GSXFACQpV1dAmhmX6VJzPQTgtz/x1AToLsnKquy5E5GQzz2X+82x3B 2IuL2Yz/7ZlgqQaAhk+QQi7EHKy/+o9uhnijvI35lvS6yo8SdYV7RIbd7YQ23589XGxeKKs5 0z0Gjinx6PiAuF4/sCCHhjXDAa0= X-Mailgun-Sending-Ip: 198.61.254.15 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-east-1.postgun.com with SMTP id 60179e224ee30634eb23f457 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 01 Feb 2021 06:22:26 GMT Sender: mdalam=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 0D4F1C433CA; Mon, 1 Feb 2021 06:22:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mdalam) by smtp.codeaurora.org (Postfix) with ESMTPSA id C66F6C433C6; Mon, 1 Feb 2021 06:22:24 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 01 Feb 2021 11:52:24 +0530 From: mdalam@codeaurora.org To: Vinod Koul Cc: corbet@lwn.net, agross@kernel.org, bjorn.andersson@linaro.org, dan.j.williams@intel.com, dmaengine@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, sricharan@codeaurora.org, mdalam=codeaurora.org@codeaurora.org Subject: Re: [PATCH] dmaengine: qcom: bam_dma: Add LOCK and UNLOCK flag bit support In-Reply-To: <20210201060508.GK2771@vkoul-mobl> References: <1608215842-15381-1-git-send-email-mdalam@codeaurora.org> <20201221092355.GA3323@vkoul-mobl> <20210112101056.GI2771@vkoul-mobl> <20210115055806.GE2771@vkoul-mobl> <97ce29b230164a5848a38f6448d1be60@codeaurora.org> <20210119164511.GE2771@vkoul-mobl> <534308caab7c18730ad0cc25248d116f@codeaurora.org> <20210201060508.GK2771@vkoul-mobl> Message-ID: <9d33d73682f24d92338757e1823ccd88@codeaurora.org> X-Sender: mdalam@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-02-01 11:35, Vinod Koul wrote: > On 27-01-21, 23:56, mdalam@codeaurora.org wrote: >> On 2021-01-19 22:15, Vinod Koul wrote: >> > On 18-01-21, 09:21, mdalam@codeaurora.org wrote: >> > > On 2021-01-15 11:28, Vinod Koul wrote: >> > > > On 14-01-21, 01:20, mdalam@codeaurora.org wrote: >> > > > > On 2021-01-12 15:40, Vinod Koul wrote: >> > > > > > On 12-01-21, 15:01, mdalam@codeaurora.org wrote: >> > > > > > > On 2020-12-21 23:03, mdalam@codeaurora.org wrote: >> > > > > > > > On 2020-12-21 14:53, Vinod Koul wrote: >> > > > > > > > > Hello, >> > > > > > > > > >> > > > > > > > > On 17-12-20, 20:07, Md Sadre Alam wrote: >> > > > > > > > > > This change will add support for LOCK & UNLOCK flag bit support >> > > > > > > > > > on CMD descriptor. >> > > > > > > > > > >> > > > > > > > > > If DMA_PREP_LOCK flag passed in prep_slave_sg then requester of this >> > > > > > > > > > transaction wanted to lock the DMA controller for this transaction so >> > > > > > > > > > BAM driver should set LOCK bit for the HW descriptor. >> > > > > > > > > > >> > > > > > > > > > If DMA_PREP_UNLOCK flag passed in prep_slave_sg then requester >> > > > > > > > > > of this >> > > > > > > > > > transaction wanted to unlock the DMA controller.so BAM driver >> > > > > > > > > > should set >> > > > > > > > > > UNLOCK bit for the HW descriptor. >> > > > > > > > > >> > > > > > > > > Can you explain why would we need to first lock and then unlock..? How >> > > > > > > > > would this be used in real world. >> > > > > > > > > >> > > > > > > > > I have read a bit of documentation but is unclear to me. Also should >> > > > > > > > > this be exposed as an API to users, sounds like internal to driver..? >> > > > > > > > > >> > > > > > > > >> > > > > > > > IPQ5018 SoC having only one Crypto Hardware Engine. This Crypto Hardware >> > > > > > > > Engine >> > > > > > > > will be shared between A53 core & ubi32 core. There is two separate >> > > > > > > > driver dedicated >> > > > > > > > to A53 core and ubi32 core. So to use Crypto Hardware Engine >> > > > > > > > parallelly for encryption/description >> > > > > > > > we need bam locking mechanism. if one driver will submit the request >> > > > > > > > for encryption/description >> > > > > > > > to Crypto then first it has to set LOCK flag bit on command descriptor >> > > > > > > > so that other pipes will >> > > > > > > > get locked. >> > > > > > > > >> > > > > > > > The Pipe Locking/Unlocking will be only on command-descriptor. Upon >> > > > > > > > encountering a command descriptor >> > > > > > >> > > > > > Can you explain what is a cmd descriptor? >> > > > > >> > > > > In BAM pipe descriptor structure there is a field called CMD >> > > > > (Command >> > > > > descriptor). >> > > > > CMD allows the SW to create descriptors of type Command which does >> > > > > not >> > > > > generate any data transmissions >> > > > > but configures registers in the Peripheral (write operations, and >> > > > > read >> > > > > registers operations ). >> > > > > Using command descriptor enables the SW to queue new configurations >> > > > > between data transfers in advance. >> > > > >> > > > What and when is the CMD descriptor used for..? >> > > >> > > CMD descriptor is mainly used for configuring controller register. >> > > We can read/write controller register via BAM using CMD descriptor >> > > only. >> > > CMD descriptor use command pipe for the transaction. >> > >> > In which use cases would you need to issue cmd descriptors..? >> >> In IPQ5018 there is only one Crypto engine and it will get shared >> between UBI32 core & A53 core. So here we need to use command >> descriptor in-order to perform LOCKING/UNLOCKING mechanism. Since >> LOCK/ULOCK flag we can set only on CMD descriptor. > > So when will lock/unlock be performed? Can you please explain that.. LOCK/UNLOCK will be performed when two different driver wanted to use the same HW. eg. In IPQ5018 there is only one Crypto engine and it will be shared b/w UBI32 core driver and A53 core driver. When A53 core wanted to submit request to crypto engine via BAM then first it has to LOCK all other pipes (pipe dedicated to UBI32 core) and then trigger the transaction start. Once all the transaction will be completed the A53 core crypto driver will release the LOCK from all the pipes. Same sequence will be applicable for UBI32 core crypto driver as well. It depends whose request will come first to the crypto HW. > >> > >> > > > >> > > > > > >> > > > > > > > with LOCK bit set, The BAM will lock all other pipes not related to >> > > > > > > > the current pipe group, and keep >> > > > > > > > handling the current pipe only until it sees the UNLOCK set then it >> > > > > > > > will release all locked pipes. >> > > > > > > > locked pipe will not fetch new descriptors even if it got event/events >> > > > > > > > adding more descriptors for >> > > > > > > > this pipe (locked pipe). >> > > > > > > > >> > > > > > > > No need to expose as an API to user because its internal to driver, so >> > > > > > > > while preparing command descriptor >> > > > > > > > just we have to update the LOCK/UNLOCK flag. >> > > > > > >> > > > > > So IIUC, no api right? it would be internal to driver..? >> > > > > >> > > > > Yes its totally internal to deriver. >> > > > >> > > > So no need for this patch then, right? >> > > >> > > This patch is needed , because if some hardware will shared between >> > > multiple core like A53 and ubi32 for example. In IPQ5018 there is >> > > only one crypto engine and this will be shared between A53 core and >> > > ubi32 core and in A53 core & ubi32 core there are different drivers >> > > is getting used. So if encryption/decryption request come at same >> > > time from both the driver then things will get messed up. So here we >> > > need LOCKING mechanism. If first request is from A53 core driver >> > > then this driver should lock all the pipes other than pipe dedicated >> > > to A53 core. So while preparing CMD descriptor driver should used >> > > this flag "DMA_PREP_LOCK", Since LOCK and UNLOCK flag bit we can set >> > > only on CMD descriptor. Once request processed then driver will set >> > > UNLOCK flag on CMD descriptor. Driver should use this flag >> > > "DMA_PREP_UNLOCK" while preparing CMD descriptor. Same logic will be >> > > apply for ubi32 core driver as well. >> > >> > Why cant this be applied at driver level, based on txn being issued it >> > can lock issue the txn and then unlock when done. I am not convinced yet >> > that this needs to be exported to users and can be managed by dmaengine >> > driver. >> >> The actual LOCK/UNLOCK flag should be set on hardware command >> descriptor. >> so this flag setting should be done in DMA engine driver. The user >> of the >> DMA >> driver like (in case of IPQ5018) Crypto can use flag "DMA_PREP_LOCK" >> & >> "DMA_PREP_UNLOCK" >> while preparing CMD descriptor before submitting to the DMA engine. >> In DMA >> engine driver >> we are checking these flasgs on CMD descriptor and setting actual >> LOCK/UNLOCK flag on hardware >> descriptor. > > > I am not sure I comprehend this yet.. when is that we would need to do > this... is this for each txn submitted to dmaengine.. or something > else.. Its not for each transaction submitted to dmaengine. We have to set this only once on CMD descriptor. So when A53 crypto driver need to change the crypto configuration then first it will lock the all other pipes using setting the LOCK flag bit on CMD descriptor and then it can start the transaction , on data descriptor this flag will not get set once all transaction will be completed the A53 crypto driver release the lock on all other pipes using UNLOCK flag on CMD descriptor. So LOCK/UNLOCK will be only once and not for the each transaction. > >> >> if (flags & DMA_PREP_CMD) { <== check for descriptor type >> if (flags & DMA_PREP_LOCK) >> desc->flags |= cpu_to_le16(DESC_FLAG_LOCK); <== Actual LOCK flag >> setting >> on HW descriptor. >> if (flags & DMA_PREP_UNLOCK) >> desc->flags |= cpu_to_le16(DESC_FLAG_UNLOCK); <== Actual UNLOCK >> flag >> setting on HW descriptor. >> } >> > >> > Thanks