* [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support
@ 2025-01-15 10:29 Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read Md Sadre Alam
` (12 more replies)
0 siblings, 13 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Requirements:
In QCE crypto driver we are accessing the crypto engine registers
directly via CPU read/write. Trust Zone could possibly to perform some
crypto operations simultaneously, a race condition will be created and
this could result in undefined behavior.
To avoid this behavior we need to use BAM HW LOCK/UNLOCK feature on BAM
pipes, and this LOCK/UNLOCK will be set via sending a command descriptor,
where the HLOS/TZ QCE crypto driver prepares a command descriptor with a
dummy write operation on one of the QCE crypto engine register and pass
the LOCK/UNLOCK flag along with it.
This feature tested with tcrypt.ko and "libkcapi" with all the AES
algorithm supported by QCE crypto engine. Tested on IPQ9574 and
qcm6490.LE chipset.
insmod tcrypt.ko mode=101
insmod tcrypt.ko mode=102
insmod tcrypt.ko mode=155
insmod tcrypt.ko mode=180
insmod tcrypt.ko mode=181
insmod tcrypt.ko mode=182
insmod tcrypt.ko mode=185
insmod tcrypt.ko mode=186
insmod tcrypt.ko mode=212
insmod tcrypt.ko mode=216
insmod tcrypt.ko mode=403
insmod tcrypt.ko mode=404
insmod tcrypt.ko mode=500
insmod tcrypt.ko mode=501
insmod tcrypt.ko mode=502
insmod tcrypt.ko mode=600
insmod tcrypt.ko mode=601
insmod tcrypt.ko mode=602
Encryption command line:
./kcapi -x 1 -e -c "cbc(aes)" -k
8d7dd9b0170ce0b5f2f8e1aa768e01e91da8bfc67fd486d081b28254c99eb423 -i
7fbc02ebf5b93322329df9bfccb635af -p 48981da18e4bb9ef7e2e3162d16b1910
* 8b19050f66582cb7f7e4b6c873819b71
*
Decryption command line:
* $ ./kcapi -x 1 -c "cbc(aes)" -k
3023b2418ea59a841757dcf07881b3a8def1c97b659a4dad -i
95aa5b68130be6fcf5cabe7d9f898a41 -q c313c6b50145b69a77b33404cb422598
* 836de0065f9d6f6a3dd2c53cd17e33a
* $ ./kcapi -x 3 -c sha256 -p 38f86d
* cc42f645c5aa76ac3154b023359b665375fc3ae42f025fe961fb0f65205ad70e
* $ ./kcapi -x 3 -c sha256 -p bbb300ac5eda9d
* 61f7b48577a613fbdfe0d6d90b49985e07a42c99e7a439b6efb76d5ec71b3d30
./kcapi -x 12 -c "hmac(sha256)" -k
0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b -i
000102030405060708090a0b0c -p f0f1f2f3f4f5f6f7f8f9 -b 42
*
3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf3400720
8d5b887185865
Paraller test with two different EE's (Execution Environment)
EE1 (Trust Zone) EE2 (HLOS)
There is a TZ application which "libkcapi" or "tcrypt.ko" will run in
will do continuous enc/dec with continuous loop to do enc/dec with
different AES algorithm supported different algorithm supported QCE
by QCE crypto engine. crypto engine.
1) dummy write with LOCK bit set 1) dummy write with LOCK bit set
2) bam will lock all other pipes 2) bam will lock all other pipes which
which not belongs to current not belongs to current EE's, i.e tz
EE's, i.e HLOS pipe and keep pipe and keep handling current
handling current pipe only. pipe only.
3) hlos prepare data descriptor and
3) tz prepare data descriptor submit to CE5
and submit to CE5 4) dummy write with UNLOCK bit set
4) dummy write with UNLOCK bit 5) bam will release all the locked
set pipes
5) bam will release all the locked
pipes
Upon encountering a descriptor 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 Un-Lock set (then it will release all
locked pipes). The actual locking is done on the new descriptor fetching
for publishing, i.e. locked pipe will not fetch new descriptors even if
it got event/events adding more descriptors for this pipe.
v6:
* change "BAM" to "DMA"
* Ensured this series is compilable with the current Linux-next tip of
the tree (TOT).
v5:
* Added DMA_PREP_LOCK and DMA_PREP_UNLOCK flag support in separate patch
* Removed DMA_PREP_LOCK & DMA_PREP_UNLOCK flag
* Added FIELD_GET and GENMASK macro to extract major and minor version
v4:
* Added feature description and test hardware
with test command
* Fixed patch version numbering
* Dropped dt-binding patch
* Dropped device tree changes
* Added BAM_SW_VERSION register read
* Handled the error path for the api dma_map_resource()
in probe
* updated the commit messages for batter redability
* Squash the change where qce_bam_acquire_lock() and
qce_bam_release_lock() api got introduce to the change where
the lock/unlock flag get introced
* changed cover letter subject heading to
"dmaengine: qcom: bam_dma: add cmd descriptor support"
* Added the very initial post for BAM lock/unlock patch link
as v1 to track this feature
v3:
* https://lore.kernel.org/lkml/183d4f5e-e00a-8ef6-a589-f5704bc83d4a@quicinc.com/
* Addressed all the comments from v2
* Added the dt-binding
* Fix alignment issue
* Removed type casting from qce_write_reg_dma()
and qce_read_reg_dma()
* Removed qce_bam_txn = dma->qce_bam_txn; line from
qce_alloc_bam_txn() api and directly returning
dma->qce_bam_txn
v2:
* https://lore.kernel.org/lkml/20231214114239.2635325-1-quic_mdalam@quicinc.com/
* Initial set of patches for cmd descriptor support
* Add client driver to use BAM lock/unlock feature
* Added register read/write via BAM in QCE Crypto driver
to use BAM lock/unlock feature
v1:
* https://lore.kernel.org/all/1608215842-15381-1-git-send-email-mdalam@codeaurora.org/
* Initial support for LOCK/UNLOCK in bam_dma driver
Md Sadre Alam (12):
dmaengine: qcom: bam_dma: Add bam_sw_version register read
dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag
dmaengine: qcom: bam_dma: add bam_pipe_lock flag support
crypto: qce - Add support for crypto address read
crypto: qce - Add bam dma support for crypto register r/w
crypto: qce - Convert register r/w for skcipher via BAM/DMA
crypto: qce - Convert register r/w for sha via BAM/DMA
crypto: qce - Convert register r/w for aead via BAM/DMA
crypto: qce - Add LOCK and UNLOCK flag support
crypto: qce - Add support for lock/unlock in skcipher
crypto: qce - Add support for lock/unlock in sha
crypto: qce - Add support for lock/unlock in aead
.../driver-api/dmaengine/provider.rst | 15 ++
drivers/crypto/qce/aead.c | 4 +
drivers/crypto/qce/common.c | 141 +++++++----
drivers/crypto/qce/core.c | 16 +-
drivers/crypto/qce/core.h | 12 +
drivers/crypto/qce/dma.c | 231 ++++++++++++++++++
drivers/crypto/qce/dma.h | 26 ++
drivers/crypto/qce/sha.c | 4 +
drivers/crypto/qce/skcipher.c | 4 +
drivers/dma/qcom/bam_dma.c | 29 ++-
include/linux/dmaengine.h | 6 +
11 files changed, 444 insertions(+), 44 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-01-16 17:06 ` Stephan Gerhold
2025-01-15 10:29 ` [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag Md Sadre Alam
` (11 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add bam_sw_version register read. This will help to
differentiate b/w some new BAM features across multiple
BAM IP, feature like LOCK/UNLOCK of BAM pipe.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
change in [v6]
* No change
change in [v5]
* No change
change in [v4]
* Added BAM_SW_VERSION register read
change in [v3]
* This patch was not included in [v3]
change in [v2]
* This patch was not included in [v2]
change in [v1]
* This patch was not included in [v1]
drivers/dma/qcom/bam_dma.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index c14557efd577..daeacd5cb8e9 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -83,6 +83,7 @@ struct bam_async_desc {
enum bam_reg {
BAM_CTRL,
BAM_REVISION,
+ BAM_SW_VERSION,
BAM_NUM_PIPES,
BAM_DESC_CNT_TRSHLD,
BAM_IRQ_SRCS,
@@ -117,6 +118,7 @@ struct reg_offset_data {
static const struct reg_offset_data bam_v1_3_reg_info[] = {
[BAM_CTRL] = { 0x0F80, 0x00, 0x00, 0x00 },
[BAM_REVISION] = { 0x0F84, 0x00, 0x00, 0x00 },
+ [BAM_SW_VERSION] = { 0x0F88, 0x00, 0x00, 0x00 },
[BAM_NUM_PIPES] = { 0x0FBC, 0x00, 0x00, 0x00 },
[BAM_DESC_CNT_TRSHLD] = { 0x0F88, 0x00, 0x00, 0x00 },
[BAM_IRQ_SRCS] = { 0x0F8C, 0x00, 0x00, 0x00 },
@@ -146,6 +148,7 @@ static const struct reg_offset_data bam_v1_3_reg_info[] = {
static const struct reg_offset_data bam_v1_4_reg_info[] = {
[BAM_CTRL] = { 0x0000, 0x00, 0x00, 0x00 },
[BAM_REVISION] = { 0x0004, 0x00, 0x00, 0x00 },
+ [BAM_SW_VERSION] = { 0x0008, 0x00, 0x00, 0x00 },
[BAM_NUM_PIPES] = { 0x003C, 0x00, 0x00, 0x00 },
[BAM_DESC_CNT_TRSHLD] = { 0x0008, 0x00, 0x00, 0x00 },
[BAM_IRQ_SRCS] = { 0x000C, 0x00, 0x00, 0x00 },
@@ -175,6 +178,7 @@ static const struct reg_offset_data bam_v1_4_reg_info[] = {
static const struct reg_offset_data bam_v1_7_reg_info[] = {
[BAM_CTRL] = { 0x00000, 0x00, 0x00, 0x00 },
[BAM_REVISION] = { 0x01000, 0x00, 0x00, 0x00 },
+ [BAM_SW_VERSION] = { 0x01004, 0x00, 0x00, 0x00 },
[BAM_NUM_PIPES] = { 0x01008, 0x00, 0x00, 0x00 },
[BAM_DESC_CNT_TRSHLD] = { 0x00008, 0x00, 0x00, 0x00 },
[BAM_IRQ_SRCS] = { 0x03010, 0x00, 0x00, 0x00 },
@@ -393,6 +397,7 @@ struct bam_device {
bool controlled_remotely;
bool powered_remotely;
u32 active_channels;
+ u32 bam_sw_version;
const struct reg_offset_data *layout;
@@ -1306,6 +1311,9 @@ static int bam_dma_probe(struct platform_device *pdev)
return ret;
}
+ bdev->bam_sw_version = readl_relaxed(bam_addr(bdev, 0, BAM_SW_VERSION));
+ dev_info(bdev->dev, "BAM software version:0x%08x\n", bdev->bam_sw_version);
+
ret = bam_init(bdev);
if (ret)
goto err_disable_clk;
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-03-10 20:36 ` Vinod Koul
2025-01-15 10:29 ` [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support Md Sadre Alam
` (10 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add lock and unlock flag support on command descriptor.
Once lock set in requester pipe, then the bam controller
will lock all others pipe and process the request only
from requester pipe. Unlocking only can be performed from
the same pipe.
If DMA_PREP_LOCK flag passed in command descriptor then requester
of this transaction wanted to lock the BAM controller for this
transaction so BAM driver should set LOCK bit for the HW descriptor.
If DMA_PREP_UNLOCK flag passed in command descriptor then requester
of this transaction wanted to unlock the BAM controller.so BAM driver
should set UNLOCK bit for the HW descriptor.
BAM IP version 1.4.0 and above only supports this LOCK/UNLOCK
feature.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* Change "BAM" to "DAM"
Change in [v5]
* Added DMA_PREP_LOCK and DMA_PREP_UNLOCK flag support
Change in [v4]
* This patch was not included in v4
Change in [v3]
* This patch was not included in v3
Change in [v2]
* This patch was not included in v2
Change in [v1]
* This patch was not included in v1
Documentation/driver-api/dmaengine/provider.rst | 15 +++++++++++++++
include/linux/dmaengine.h | 6 ++++++
2 files changed, 21 insertions(+)
diff --git a/Documentation/driver-api/dmaengine/provider.rst b/Documentation/driver-api/dmaengine/provider.rst
index 3085f8b460fa..a032e55d0a4f 100644
--- a/Documentation/driver-api/dmaengine/provider.rst
+++ b/Documentation/driver-api/dmaengine/provider.rst
@@ -628,6 +628,21 @@ DMA_CTRL_REUSE
- This flag is only supported if the channel reports the DMA_LOAD_EOT
capability.
+- DMA_PREP_LOCK
+
+ - If set, the DMA will lock all other pipes not related to the current
+ pipe group, and keep handling the current pipe only.
+
+ - All pipes not within this group will be locked by this pipe upon lock
+ event.
+
+ - only pipes which are in the same group and relate to the same Environment
+ Execution(EE) will not be locked by a certain pipe.
+
+- DMA_PREP_UNLOCK
+
+ - If set, DMA will release all locked pipes
+
General Design Notes
====================
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 346251bf1026..8ebd43a998a7 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -200,6 +200,10 @@ struct dma_vec {
* transaction is marked with DMA_PREP_REPEAT will cause the new transaction
* to never be processed and stay in the issued queue forever. The flag is
* ignored if the previous transaction is not a repeated transaction.
+ * @DMA_PREP_LOCK: tell the driver that there is a lock bit set on command
+ * descriptor.
+ * @DMA_PREP_UNLOCK: tell the driver that there is a un-lock bit set on command
+ * descriptor.
*/
enum dma_ctrl_flags {
DMA_PREP_INTERRUPT = (1 << 0),
@@ -212,6 +216,8 @@ enum dma_ctrl_flags {
DMA_PREP_CMD = (1 << 7),
DMA_PREP_REPEAT = (1 << 8),
DMA_PREP_LOAD_EOT = (1 << 9),
+ DMA_PREP_LOCK = (1 << 10),
+ DMA_PREP_UNLOCK = (1 << 11),
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-03-07 13:37 ` Bartosz Golaszewski
2025-01-15 10:29 ` [PATCH v6 04/12] crypto: qce - Add support for crypto address read Md Sadre Alam
` (9 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
BAM IP version 1.4.0 and above only supports this LOCK/UNLOCK
feature. So adding check for the same and setting bam_pipe_lock
based on BAM SW Version.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* Removed DMA_PREP_LOCK & DMA_PREP_UNLOCK flag
* Added FIELD_GET and GENMASK macro to extract major
and minor version
Change in [v4]
* Added BAM_SW_VERSION read for major & minor
version
* Added bam_pipe_lock flag
Change in [v3]
* Moved lock/unlock bit set inside loop
Change in [v2]
* No change
Change in [v1]
* Added initial support for BAM pipe lock/unlock
drivers/dma/qcom/bam_dma.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index daeacd5cb8e9..f50d88ad4f6d 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -53,11 +53,18 @@ struct bam_desc_hw {
#define BAM_DMA_AUTOSUSPEND_DELAY 100
+#define SW_VERSION_MAJOR_MASK GENMASK(31, 28)
+#define SW_VERSION_MINOR_MASK GENMASK(27, 16)
+#define SW_MAJOR_1 0x1
+#define SW_VERSION_4 0x4
+
#define DESC_FLAG_INT BIT(15)
#define DESC_FLAG_EOT BIT(14)
#define DESC_FLAG_EOB BIT(13)
#define DESC_FLAG_NWD BIT(12)
#define DESC_FLAG_CMD BIT(11)
+#define DESC_FLAG_LOCK BIT(10)
+#define DESC_FLAG_UNLOCK BIT(9)
#define BAM_NDP_REVISION_START 0x20
#define BAM_NDP_REVISION_END 0x27
@@ -396,6 +403,7 @@ struct bam_device {
u32 ee;
bool controlled_remotely;
bool powered_remotely;
+ bool bam_pipe_lock;
u32 active_channels;
u32 bam_sw_version;
@@ -702,8 +710,13 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,
unsigned int curr_offset = 0;
do {
- if (flags & DMA_PREP_CMD)
+ if (flags & DMA_PREP_CMD) {
desc->flags |= cpu_to_le16(DESC_FLAG_CMD);
+ if (bdev->bam_pipe_lock && flags & DMA_PREP_LOCK)
+ desc->flags |= cpu_to_le16(DESC_FLAG_LOCK);
+ else if (bdev->bam_pipe_lock && flags & DMA_PREP_UNLOCK)
+ desc->flags |= cpu_to_le16(DESC_FLAG_UNLOCK);
+ }
desc->addr = cpu_to_le32(sg_dma_address(sg) +
curr_offset);
@@ -1250,6 +1263,7 @@ static int bam_dma_probe(struct platform_device *pdev)
{
struct bam_device *bdev;
const struct of_device_id *match;
+ u32 sw_major, sw_minor;
int ret, i;
bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
@@ -1313,6 +1327,11 @@ static int bam_dma_probe(struct platform_device *pdev)
bdev->bam_sw_version = readl_relaxed(bam_addr(bdev, 0, BAM_SW_VERSION));
dev_info(bdev->dev, "BAM software version:0x%08x\n", bdev->bam_sw_version);
+ sw_major = FIELD_GET(SW_VERSION_MAJOR_MASK, bdev->bam_sw_version);
+ sw_minor = FIELD_GET(SW_VERSION_MINOR_MASK, bdev->bam_sw_version);
+
+ if (sw_major == SW_MAJOR_1 && sw_minor >= SW_VERSION_4)
+ bdev->bam_pipe_lock = true;
ret = bam_init(bdev);
if (ret)
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 04/12] crypto: qce - Add support for crypto address read
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (2 preceding siblings ...)
2025-01-15 10:29 ` [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 05/12] crypto: qce - Add bam dma support for crypto register r/w Md Sadre Alam
` (8 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Get crypto base address from DT. This will use for
command descriptor support for crypto register r/w
via BAM/DMA.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No Change
Change in [v5]
* No Change
Change in [v4]
* Added error handling path for dma_map_resource()
Change in [v3]
* Added dma_unmap_resource() in qce_crypto_remove()
Change in [v2]
* Added crypto added read from device tree
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/core.c | 16 ++++++++++++++--
drivers/crypto/qce/core.h | 1 +
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c
index e95e84486d9a..ba856cd0c2d8 100644
--- a/drivers/crypto/qce/core.c
+++ b/drivers/crypto/qce/core.c
@@ -191,6 +191,7 @@ static int qce_crypto_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct qce_device *qce;
+ struct resource *res;
int ret;
qce = devm_kzalloc(dev, sizeof(*qce), GFP_KERNEL);
@@ -200,7 +201,7 @@ static int qce_crypto_probe(struct platform_device *pdev)
qce->dev = dev;
platform_set_drvdata(pdev, qce);
- qce->base = devm_platform_ioremap_resource(pdev, 0);
+ qce->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(qce->base))
return PTR_ERR(qce->base);
@@ -246,7 +247,18 @@ static int qce_crypto_probe(struct platform_device *pdev)
qce->async_req_enqueue = qce_async_request_enqueue;
qce->async_req_done = qce_async_request_done;
- return devm_qce_register_algs(qce);
+ ret = devm_qce_register_algs(qce);
+ if (ret)
+ return ret;
+
+ qce->base_dma = dma_map_resource(dev, res->start,
+ resource_size(res),
+ DMA_BIDIRECTIONAL, 0);
+ ret = dma_mapping_error(dev, qce->base_dma);
+ if (ret)
+ return ret;
+
+ return 0;
}
static const struct of_device_id qce_crypto_of_match[] = {
diff --git a/drivers/crypto/qce/core.h b/drivers/crypto/qce/core.h
index eb6fa7a8b64a..0b6350b6076e 100644
--- a/drivers/crypto/qce/core.h
+++ b/drivers/crypto/qce/core.h
@@ -42,6 +42,7 @@ struct qce_device {
struct qce_dma_data dma;
int burst_size;
unsigned int pipe_pair_id;
+ dma_addr_t base_dma;
int (*async_req_enqueue)(struct qce_device *qce,
struct crypto_async_request *req);
void (*async_req_done)(struct qce_device *qce, int ret);
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 05/12] crypto: qce - Add bam dma support for crypto register r/w
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (3 preceding siblings ...)
2025-01-15 10:29 ` [PATCH v6 04/12] crypto: qce - Add support for crypto address read Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 06/12] crypto: qce - Convert register r/w for skcipher via BAM/DMA Md Sadre Alam
` (7 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add BAM/DMA support for crypto register read/write.
With this change multiple crypto register will get
Written/Read using bam in one go.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No Change
Change in [v5]
* No Change
Change in [v4]
* No change
Change in [v3]
* Fixed alignment issue
* Removed type casting in qce_read_reg_dma()
and qce_write_reg_dma()
Change in [v2]
* Added initial support for bam api for
register read/write
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/core.h | 10 ++
drivers/crypto/qce/dma.c | 226 ++++++++++++++++++++++++++++++++++++++
drivers/crypto/qce/dma.h | 24 ++++
3 files changed, 260 insertions(+)
diff --git a/drivers/crypto/qce/core.h b/drivers/crypto/qce/core.h
index 0b6350b6076e..4559232bdf71 100644
--- a/drivers/crypto/qce/core.h
+++ b/drivers/crypto/qce/core.h
@@ -43,6 +43,8 @@ struct qce_device {
int burst_size;
unsigned int pipe_pair_id;
dma_addr_t base_dma;
+ __le32 *reg_read_buf;
+ dma_addr_t reg_buf_phys;
int (*async_req_enqueue)(struct qce_device *qce,
struct crypto_async_request *req);
void (*async_req_done)(struct qce_device *qce, int ret);
@@ -62,4 +64,12 @@ struct qce_algo_ops {
int (*async_req_handle)(struct crypto_async_request *async_req);
};
+int qce_write_reg_dma(struct qce_device *qce, unsigned int offset, u32 val,
+ int cnt);
+int qce_read_reg_dma(struct qce_device *qce, unsigned int offset, void *buff,
+ int cnt);
+void qce_clear_bam_transaction(struct qce_device *qce);
+int qce_submit_cmd_desc(struct qce_device *qce, unsigned long flags);
+struct qce_bam_transaction *qce_alloc_bam_txn(struct qce_dma_data *dma);
+
#endif /* _CORE_H_ */
diff --git a/drivers/crypto/qce/dma.c b/drivers/crypto/qce/dma.c
index 1dec7aea852d..225ac5619249 100644
--- a/drivers/crypto/qce/dma.c
+++ b/drivers/crypto/qce/dma.c
@@ -5,21 +5,233 @@
#include <linux/device.h>
#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
#include <crypto/scatterwalk.h>
+#include "core.h"
#include "dma.h"
+#define QCE_REG_BUF_DMA_ADDR(qce, vaddr) \
+ ((qce)->reg_buf_phys + \
+ ((uint8_t *)(vaddr) - (uint8_t *)(qce)->reg_read_buf))
+
+void qce_clear_bam_transaction(struct qce_device *qce)
+{
+ struct qce_bam_transaction *qce_bam_txn = qce->dma.qce_bam_txn;
+
+ memset(&qce_bam_txn->qce_bam_ce_index, 0, sizeof(u32) * 8);
+}
+
+static int qce_dma_prep_cmd_sg(struct qce_device *qce, struct dma_chan *chan,
+ struct scatterlist *qce_bam_sgl,
+ int qce_sgl_cnt, unsigned long flags,
+ enum dma_transfer_direction dir_eng,
+ dma_async_tx_callback cb, void *cb_param)
+{
+ struct dma_async_tx_descriptor *dma_desc;
+ struct qce_desc_info *desc;
+ dma_cookie_t cookie;
+
+ desc = qce->dma.qce_bam_txn->qce_desc;
+
+ if (dir_eng == DMA_MEM_TO_DEV)
+ desc->dir = DMA_TO_DEVICE;
+ if (dir_eng == DMA_DEV_TO_MEM)
+ desc->dir = DMA_FROM_DEVICE;
+
+ if (!qce_bam_sgl || !qce_sgl_cnt)
+ return -EINVAL;
+
+ if (!dma_map_sg(qce->dev, qce_bam_sgl,
+ qce_sgl_cnt, desc->dir)) {
+ dev_err(qce->dev, "failure in mapping sgl for cmd desc\n");
+ return -ENOMEM;
+ }
+
+ dma_desc = dmaengine_prep_slave_sg(chan, qce_bam_sgl, qce_sgl_cnt,
+ dir_eng, flags);
+ if (!dma_desc) {
+ pr_err("%s:failure in prep cmd desc\n", __func__);
+ dma_unmap_sg(qce->dev, qce_bam_sgl, qce_sgl_cnt, desc->dir);
+ kfree(desc);
+ return -EINVAL;
+ }
+
+ desc->dma_desc = dma_desc;
+ desc->dma_desc->callback = cb;
+ desc->dma_desc->callback_param = cb_param;
+
+ cookie = dmaengine_submit(desc->dma_desc);
+
+ return dma_submit_error(cookie);
+}
+
+int qce_submit_cmd_desc(struct qce_device *qce, unsigned long flags)
+{
+ struct qce_bam_transaction *qce_bam_txn = qce->dma.qce_bam_txn;
+ struct dma_chan *chan = qce->dma.rxchan;
+ unsigned long desc_flags;
+ int ret = 0;
+
+ desc_flags = DMA_PREP_CMD;
+
+ /* For command descriptor always use consumer pipe
+ * it recommended as per HPG
+ */
+
+ if (qce_bam_txn->qce_read_sgl_cnt) {
+ ret = qce_dma_prep_cmd_sg(qce, chan, qce_bam_txn->qce_reg_read_sgl,
+ qce_bam_txn->qce_read_sgl_cnt,
+ desc_flags, DMA_DEV_TO_MEM,
+ NULL, NULL);
+ if (ret) {
+ pr_err("error while submitting cmd desc for rx\n");
+ return ret;
+ }
+ }
+
+ if (qce_bam_txn->qce_write_sgl_cnt) {
+ ret = qce_dma_prep_cmd_sg(qce, chan, qce_bam_txn->qce_reg_write_sgl,
+ qce_bam_txn->qce_write_sgl_cnt,
+ desc_flags, DMA_MEM_TO_DEV,
+ NULL, NULL);
+ }
+
+ if (ret) {
+ pr_err("error while submitting cmd desc for tx\n");
+ return ret;
+ }
+
+ qce_dma_issue_pending(&qce->dma);
+
+ if (qce_bam_txn->qce_read_sgl_cnt)
+ dma_unmap_sg(qce->dev, qce_bam_txn->qce_reg_read_sgl,
+ qce_bam_txn->qce_read_sgl_cnt,
+ DMA_FROM_DEVICE);
+ if (qce_bam_txn->qce_write_sgl_cnt)
+ dma_unmap_sg(qce->dev, qce_bam_txn->qce_reg_write_sgl,
+ qce_bam_txn->qce_write_sgl_cnt,
+ DMA_TO_DEVICE);
+
+ return ret;
+}
+
+static void qce_prep_dma_command_desc(struct qce_device *qce, struct qce_dma_data *dma,
+ bool read, unsigned int addr, void *buff, int size)
+{
+ struct qce_bam_transaction *qce_bam_txn = dma->qce_bam_txn;
+ struct bam_cmd_element *qce_bam_ce_buffer;
+ int qce_bam_ce_size, cnt, index;
+
+ index = qce_bam_txn->qce_bam_ce_index;
+ qce_bam_ce_buffer = &qce_bam_txn->qce_bam_ce[index];
+ if (read)
+ bam_prep_ce(qce_bam_ce_buffer, addr, BAM_READ_COMMAND,
+ QCE_REG_BUF_DMA_ADDR(qce,
+ (unsigned int *)buff));
+ else
+ bam_prep_ce_le32(qce_bam_ce_buffer, addr, BAM_WRITE_COMMAND,
+ *((__le32 *)buff));
+
+ if (read) {
+ cnt = qce_bam_txn->qce_read_sgl_cnt;
+ qce_bam_ce_buffer = &qce_bam_txn->qce_bam_ce
+ [qce_bam_txn->qce_pre_bam_ce_index];
+ qce_bam_txn->qce_bam_ce_index += size;
+ qce_bam_ce_size = (qce_bam_txn->qce_bam_ce_index -
+ qce_bam_txn->qce_pre_bam_ce_index) *
+ sizeof(struct bam_cmd_element);
+
+ sg_set_buf(&qce_bam_txn->qce_reg_read_sgl[cnt],
+ qce_bam_ce_buffer,
+ qce_bam_ce_size);
+
+ ++qce_bam_txn->qce_read_sgl_cnt;
+ qce_bam_txn->qce_pre_bam_ce_index =
+ qce_bam_txn->qce_bam_ce_index;
+ } else {
+ cnt = qce_bam_txn->qce_write_sgl_cnt;
+ qce_bam_ce_buffer = &qce_bam_txn->qce_bam_ce
+ [qce_bam_txn->qce_pre_bam_ce_index];
+ qce_bam_txn->qce_bam_ce_index += size;
+ qce_bam_ce_size = (qce_bam_txn->qce_bam_ce_index -
+ qce_bam_txn->qce_pre_bam_ce_index) *
+ sizeof(struct bam_cmd_element);
+
+ sg_set_buf(&qce_bam_txn->qce_reg_write_sgl[cnt],
+ qce_bam_ce_buffer,
+ qce_bam_ce_size);
+
+ ++qce_bam_txn->qce_write_sgl_cnt;
+ qce_bam_txn->qce_pre_bam_ce_index =
+ qce_bam_txn->qce_bam_ce_index;
+ }
+}
+
+int qce_write_reg_dma(struct qce_device *qce,
+ unsigned int offset, u32 val, int cnt)
+{
+ qce_prep_dma_command_desc(qce, &qce->dma, false, (qce->base_dma + offset),
+ &val, cnt);
+ return 0;
+}
+
+int qce_read_reg_dma(struct qce_device *qce,
+ unsigned int offset, void *buff, int cnt)
+{
+ qce_prep_dma_command_desc(qce, &qce->dma, true, (qce->base_dma + offset),
+ qce->reg_read_buf, cnt);
+ memcpy(buff, qce->reg_read_buf, 4);
+
+ return 0;
+}
+
+struct qce_bam_transaction *qce_alloc_bam_txn(struct qce_dma_data *dma)
+{
+ struct qce_bam_transaction *qce_bam_txn;
+
+ dma->qce_bam_txn = kmalloc(sizeof(*qce_bam_txn), GFP_KERNEL);
+ if (!dma->qce_bam_txn)
+ return NULL;
+
+ dma->qce_bam_txn->qce_desc = kzalloc(sizeof(*dma->qce_bam_txn->qce_desc),
+ GFP_KERNEL);
+ if (!dma->qce_bam_txn->qce_desc) {
+ kfree(dma->qce_bam_txn);
+ return NULL;
+ }
+
+ sg_init_table(dma->qce_bam_txn->qce_reg_write_sgl,
+ QCE_BAM_CMD_SGL_SIZE);
+
+ sg_init_table(dma->qce_bam_txn->qce_reg_read_sgl,
+ QCE_BAM_CMD_SGL_SIZE);
+
+ return dma->qce_bam_txn;
+}
+
static void qce_dma_release(void *data)
{
struct qce_dma_data *dma = data;
+ struct qce_device *qce = container_of(dma,
+ struct qce_device, dma);
dma_release_channel(dma->txchan);
dma_release_channel(dma->rxchan);
kfree(dma->result_buf);
+ if (qce->reg_read_buf)
+ dmam_free_coherent(qce->dev, QCE_MAX_REG_READ *
+ sizeof(*qce->reg_read_buf),
+ qce->reg_read_buf,
+ qce->reg_buf_phys);
+ kfree(dma->qce_bam_txn->qce_desc);
+ kfree(dma->qce_bam_txn);
+
}
int devm_qce_dma_request(struct device *dev, struct qce_dma_data *dma)
{
+ struct qce_device *qce = container_of(dma, struct qce_device, dma);
int ret;
dma->txchan = dma_request_chan(dev, "tx");
@@ -41,6 +253,20 @@ int devm_qce_dma_request(struct device *dev, struct qce_dma_data *dma)
dma->ignore_buf = dma->result_buf + QCE_RESULT_BUF_SZ;
+ dma->qce_bam_txn = qce_alloc_bam_txn(dma);
+ if (!dma->qce_bam_txn) {
+ pr_err("Failed to allocate bam transaction\n");
+ return -ENOMEM;
+ }
+
+ qce->reg_read_buf = dmam_alloc_coherent(qce->dev, QCE_MAX_REG_READ *
+ sizeof(*qce->reg_read_buf),
+ &qce->reg_buf_phys, GFP_KERNEL);
+ if (!qce->reg_read_buf) {
+ pr_err("Failed to allocate reg_read_buf\n");
+ return -ENOMEM;
+ }
+
return devm_add_action_or_reset(dev, qce_dma_release, dma);
error_nomem:
diff --git a/drivers/crypto/qce/dma.h b/drivers/crypto/qce/dma.h
index 31629185000e..2ec04e3df4ba 100644
--- a/drivers/crypto/qce/dma.h
+++ b/drivers/crypto/qce/dma.h
@@ -7,6 +7,7 @@
#define _DMA_H_
#include <linux/dmaengine.h>
+#include <linux/dma/qcom_bam_dma.h>
/* maximum data transfer block size between BAM and CE */
#define QCE_BAM_BURST_SIZE 64
@@ -14,6 +15,11 @@
#define QCE_AUTHIV_REGS_CNT 16
#define QCE_AUTH_BYTECOUNT_REGS_CNT 4
#define QCE_CNTRIV_REGS_CNT 4
+#define QCE_BAM_CMD_SGL_SIZE 64
+#define QCE_BAM_CMD_ELEMENT_SIZE 64
+#define QCE_DMA_DESC_FLAG_BAM_NWD (0x0004)
+#define QCE_MAX_REG_READ 8
+
struct qce_result_dump {
u32 auth_iv[QCE_AUTHIV_REGS_CNT];
@@ -27,13 +33,30 @@ struct qce_result_dump {
#define QCE_RESULT_BUF_SZ \
ALIGN(sizeof(struct qce_result_dump), QCE_BAM_BURST_SIZE)
+struct qce_bam_transaction {
+ struct bam_cmd_element qce_bam_ce[QCE_BAM_CMD_ELEMENT_SIZE];
+ struct scatterlist qce_reg_write_sgl[QCE_BAM_CMD_SGL_SIZE];
+ struct scatterlist qce_reg_read_sgl[QCE_BAM_CMD_SGL_SIZE];
+ struct qce_desc_info *qce_desc;
+ u32 qce_bam_ce_index;
+ u32 qce_pre_bam_ce_index;
+ u32 qce_write_sgl_cnt;
+ u32 qce_read_sgl_cnt;
+};
+
struct qce_dma_data {
struct dma_chan *txchan;
struct dma_chan *rxchan;
struct qce_result_dump *result_buf;
+ struct qce_bam_transaction *qce_bam_txn;
void *ignore_buf;
};
+struct qce_desc_info {
+ struct dma_async_tx_descriptor *dma_desc;
+ enum dma_data_direction dir;
+};
+
int devm_qce_dma_request(struct device *dev, struct qce_dma_data *dma);
int qce_dma_prep_sgs(struct qce_dma_data *dma, struct scatterlist *sg_in,
int in_ents, struct scatterlist *sg_out, int out_ents,
@@ -44,4 +67,5 @@ struct scatterlist *
qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add,
unsigned int max_len);
+void qce_dma_issue_cmd_desc_pending(struct qce_dma_data *dma, bool read);
#endif /* _DMA_H_ */
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 06/12] crypto: qce - Convert register r/w for skcipher via BAM/DMA
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (4 preceding siblings ...)
2025-01-15 10:29 ` [PATCH v6 05/12] crypto: qce - Add bam dma support for crypto register r/w Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 07/12] crypto: qce - Convert register r/w for sha " Md Sadre Alam
` (6 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Convert register read/write for skcipher via BAM/DMA.
with this change all the crypto register configuration
will be done via BAM/DMA. This change will prepare command
descriptor for all register and write it once.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* No change
Change in [v2]
* Added initial support to read/write crypto
register via BAM for skcipher
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/common.c | 42 ++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/drivers/crypto/qce/common.c b/drivers/crypto/qce/common.c
index 04253a8d3340..d1da6b1938f3 100644
--- a/drivers/crypto/qce/common.c
+++ b/drivers/crypto/qce/common.c
@@ -34,7 +34,7 @@ static inline void qce_write_array(struct qce_device *qce, u32 offset,
int i;
for (i = 0; i < len; i++)
- qce_write(qce, offset + i * sizeof(u32), val[i]);
+ qce_write_reg_dma(qce, offset + i * sizeof(u32), val[i], 1);
}
static inline void
@@ -43,7 +43,7 @@ qce_clear_array(struct qce_device *qce, u32 offset, unsigned int len)
int i;
for (i = 0; i < len; i++)
- qce_write(qce, offset + i * sizeof(u32), 0);
+ qce_write_reg_dma(qce, offset + i * sizeof(u32), 0, 1);
}
static u32 qce_config_reg(struct qce_device *qce, int little)
@@ -86,16 +86,16 @@ static void qce_setup_config(struct qce_device *qce)
config = qce_config_reg(qce, 0);
/* clear status */
- qce_write(qce, REG_STATUS, 0);
- qce_write(qce, REG_CONFIG, config);
+ qce_write_reg_dma(qce, REG_STATUS, 0, 1);
+ qce_write_reg_dma(qce, REG_CONFIG, config, 1);
}
static inline void qce_crypto_go(struct qce_device *qce, bool result_dump)
{
if (result_dump)
- qce_write(qce, REG_GOPROC, BIT(GO_SHIFT) | BIT(RESULTS_DUMP_SHIFT));
+ qce_write_reg_dma(qce, REG_GOPROC, BIT(GO_SHIFT) | BIT(RESULTS_DUMP_SHIFT), 1);
else
- qce_write(qce, REG_GOPROC, BIT(GO_SHIFT));
+ qce_write_reg_dma(qce, REG_GOPROC, BIT(GO_SHIFT), 1);
}
#if defined(CONFIG_CRYPTO_DEV_QCE_SHA) || defined(CONFIG_CRYPTO_DEV_QCE_AEAD)
@@ -308,7 +308,7 @@ static void qce_xtskey(struct qce_device *qce, const u8 *enckey,
/* Set data unit size to cryptlen. Anything else causes
* crypto engine to return back incorrect results.
*/
- qce_write(qce, REG_ENCR_XTS_DU_SIZE, cryptlen);
+ qce_write_reg_dma(qce, REG_ENCR_XTS_DU_SIZE, cryptlen, 1);
}
static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
@@ -325,7 +325,9 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
u32 encr_cfg = 0, auth_cfg = 0, config;
unsigned int ivsize = rctx->ivsize;
unsigned long flags = rctx->flags;
+ int ret;
+ qce_clear_bam_transaction(qce);
qce_setup_config(qce);
if (IS_XTS(flags))
@@ -336,7 +338,7 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
qce_cpu_to_be32p_array(enckey, ctx->enc_key, keylen);
enckey_words = keylen / sizeof(u32);
- qce_write(qce, REG_AUTH_SEG_CFG, auth_cfg);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, auth_cfg, 1);
encr_cfg = qce_encr_cfg(flags, keylen);
@@ -369,25 +371,31 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
if (IS_ENCRYPT(flags))
encr_cfg |= BIT(ENCODE_SHIFT);
- qce_write(qce, REG_ENCR_SEG_CFG, encr_cfg);
- qce_write(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen);
- qce_write(qce, REG_ENCR_SEG_START, 0);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_CFG, encr_cfg, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_START, 0, 1);
if (IS_CTR(flags)) {
- qce_write(qce, REG_CNTR_MASK, ~0);
- qce_write(qce, REG_CNTR_MASK0, ~0);
- qce_write(qce, REG_CNTR_MASK1, ~0);
- qce_write(qce, REG_CNTR_MASK2, ~0);
+ qce_write_reg_dma(qce, REG_CNTR_MASK, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK0, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK1, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK2, ~0, 1);
}
- qce_write(qce, REG_SEG_SIZE, rctx->cryptlen);
+ qce_write_reg_dma(qce, REG_SEG_SIZE, rctx->cryptlen, 1);
/* get little endianness */
config = qce_config_reg(qce, 1);
- qce_write(qce, REG_CONFIG, config);
+ qce_write_reg_dma(qce, REG_CONFIG, config, 1);
qce_crypto_go(qce, true);
+ ret = qce_submit_cmd_desc(qce, 0);
+ if (ret) {
+ dev_err(qce->dev, "Error in skcipher cmd descriptor\n");
+ return ret;
+ }
+
return 0;
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 07/12] crypto: qce - Convert register r/w for sha via BAM/DMA
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (5 preceding siblings ...)
2025-01-15 10:29 ` [PATCH v6 06/12] crypto: qce - Convert register r/w for skcipher via BAM/DMA Md Sadre Alam
@ 2025-01-15 10:29 ` Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 08/12] crypto: qce - Convert register r/w for aead " Md Sadre Alam
` (5 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:29 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Convert register read/write for sha via BAM/DMA.
with this change all the crypto register configuration
will be done via BAM/DMA. This change will prepare command
descriptor for all register and write it once.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* No change
Change in [v2]
* Added initial support to read/write crypto
register via BAM for SHA
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/common.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/crypto/qce/common.c b/drivers/crypto/qce/common.c
index d1da6b1938f3..d485762a3fdc 100644
--- a/drivers/crypto/qce/common.c
+++ b/drivers/crypto/qce/common.c
@@ -157,17 +157,19 @@ static int qce_setup_regs_ahash(struct crypto_async_request *async_req)
__be32 mackey[QCE_SHA_HMAC_KEY_SIZE / sizeof(__be32)] = {0};
u32 auth_cfg = 0, config;
unsigned int iv_words;
+ int ret;
/* if not the last, the size has to be on the block boundary */
if (!rctx->last_blk && req->nbytes % blocksize)
return -EINVAL;
+ qce_clear_bam_transaction(qce);
qce_setup_config(qce);
if (IS_CMAC(rctx->flags)) {
- qce_write(qce, REG_AUTH_SEG_CFG, 0);
- qce_write(qce, REG_ENCR_SEG_CFG, 0);
- qce_write(qce, REG_ENCR_SEG_SIZE, 0);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, 0, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_CFG, 0, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_SIZE, 0, 1);
qce_clear_array(qce, REG_AUTH_IV0, 16);
qce_clear_array(qce, REG_AUTH_KEY0, 16);
qce_clear_array(qce, REG_AUTH_BYTECNT0, 4);
@@ -213,18 +215,24 @@ static int qce_setup_regs_ahash(struct crypto_async_request *async_req)
auth_cfg &= ~BIT(AUTH_FIRST_SHIFT);
go_proc:
- qce_write(qce, REG_AUTH_SEG_CFG, auth_cfg);
- qce_write(qce, REG_AUTH_SEG_SIZE, req->nbytes);
- qce_write(qce, REG_AUTH_SEG_START, 0);
- qce_write(qce, REG_ENCR_SEG_CFG, 0);
- qce_write(qce, REG_SEG_SIZE, req->nbytes);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, auth_cfg, 1);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_SIZE, req->nbytes, 1);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_START, 0, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_CFG, 0, 1);
+ qce_write_reg_dma(qce, REG_SEG_SIZE, req->nbytes, 1);
/* get little endianness */
config = qce_config_reg(qce, 1);
- qce_write(qce, REG_CONFIG, config);
+ qce_write_reg_dma(qce, REG_CONFIG, config, 1);
qce_crypto_go(qce, true);
+ ret = qce_submit_cmd_desc(qce, 0);
+ if (ret) {
+ dev_err(qce->dev, "Error in sha cmd descriptor\n");
+ return ret;
+ }
+
return 0;
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 08/12] crypto: qce - Convert register r/w for aead via BAM/DMA
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (6 preceding siblings ...)
2025-01-15 10:29 ` [PATCH v6 07/12] crypto: qce - Convert register r/w for sha " Md Sadre Alam
@ 2025-01-15 10:30 ` Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 09/12] crypto: qce - Add LOCK and UNLOCK flag support Md Sadre Alam
` (4 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:30 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Convert register read/write for aead via BAM/DMA.
with this change all the crypto register configuration
will be done via BAM/DMA. This change will prepare command
descriptor for all register and write it once.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* No change
Change in [v2]
* Added initial support to read/write crypto
register via BAM for aead
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/common.c | 38 ++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/drivers/crypto/qce/common.c b/drivers/crypto/qce/common.c
index d485762a3fdc..ff96f6ba1fc5 100644
--- a/drivers/crypto/qce/common.c
+++ b/drivers/crypto/qce/common.c
@@ -454,7 +454,9 @@ static int qce_setup_regs_aead(struct crypto_async_request *async_req)
unsigned long flags = rctx->flags;
u32 encr_cfg, auth_cfg, config, totallen;
u32 iv_last_word;
+ int ret;
+ qce_clear_bam_transaction(qce);
qce_setup_config(qce);
/* Write encryption key */
@@ -467,12 +469,12 @@ static int qce_setup_regs_aead(struct crypto_async_request *async_req)
if (IS_CCM(rctx->flags)) {
iv_last_word = enciv[enciv_words - 1];
- qce_write(qce, REG_CNTR3_IV3, iv_last_word + 1);
+ qce_write_reg_dma(qce, REG_CNTR3_IV3, iv_last_word + 1, 1);
qce_write_array(qce, REG_ENCR_CCM_INT_CNTR0, (u32 *)enciv, enciv_words);
- qce_write(qce, REG_CNTR_MASK, ~0);
- qce_write(qce, REG_CNTR_MASK0, ~0);
- qce_write(qce, REG_CNTR_MASK1, ~0);
- qce_write(qce, REG_CNTR_MASK2, ~0);
+ qce_write_reg_dma(qce, REG_CNTR_MASK, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK0, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK1, ~0, 1);
+ qce_write_reg_dma(qce, REG_CNTR_MASK2, ~0, 1);
}
/* Clear authentication IV and KEY registers of previous values */
@@ -508,7 +510,7 @@ static int qce_setup_regs_aead(struct crypto_async_request *async_req)
encr_cfg = qce_encr_cfg(flags, enc_keylen);
if (IS_ENCRYPT(flags))
encr_cfg |= BIT(ENCODE_SHIFT);
- qce_write(qce, REG_ENCR_SEG_CFG, encr_cfg);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_CFG, encr_cfg, 1);
/* Set up AUTH_SEG_CFG */
auth_cfg = qce_auth_cfg(rctx->flags, auth_keylen, ctx->authsize);
@@ -525,34 +527,40 @@ static int qce_setup_regs_aead(struct crypto_async_request *async_req)
else
auth_cfg |= AUTH_POS_BEFORE << AUTH_POS_SHIFT;
}
- qce_write(qce, REG_AUTH_SEG_CFG, auth_cfg);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, auth_cfg, 1);
totallen = rctx->cryptlen + rctx->assoclen;
/* Set the encryption size and start offset */
if (IS_CCM(rctx->flags) && IS_DECRYPT(rctx->flags))
- qce_write(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen + ctx->authsize);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen + ctx->authsize, 1);
else
- qce_write(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen);
- qce_write(qce, REG_ENCR_SEG_START, rctx->assoclen & 0xffff);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen, 1);
+ qce_write_reg_dma(qce, REG_ENCR_SEG_START, rctx->assoclen & 0xffff, 1);
/* Set the authentication size and start offset */
- qce_write(qce, REG_AUTH_SEG_SIZE, totallen);
- qce_write(qce, REG_AUTH_SEG_START, 0);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_SIZE, totallen, 1);
+ qce_write_reg_dma(qce, REG_AUTH_SEG_START, 0, 1);
/* Write total length */
if (IS_CCM(rctx->flags) && IS_DECRYPT(rctx->flags))
- qce_write(qce, REG_SEG_SIZE, totallen + ctx->authsize);
+ qce_write_reg_dma(qce, REG_SEG_SIZE, totallen + ctx->authsize, 1);
else
- qce_write(qce, REG_SEG_SIZE, totallen);
+ qce_write_reg_dma(qce, REG_SEG_SIZE, totallen, 1);
/* get little endianness */
config = qce_config_reg(qce, 1);
- qce_write(qce, REG_CONFIG, config);
+ qce_write_reg_dma(qce, REG_CONFIG, config, 1);
/* Start the process */
qce_crypto_go(qce, !IS_CCM(flags));
+ ret = qce_submit_cmd_desc(qce, 0);
+ if (ret) {
+ dev_err(qce->dev, "Error in aead cmd descriptor\n");
+ return ret;
+ }
+
return 0;
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 09/12] crypto: qce - Add LOCK and UNLOCK flag support
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (7 preceding siblings ...)
2025-01-15 10:30 ` [PATCH v6 08/12] crypto: qce - Convert register r/w for aead " Md Sadre Alam
@ 2025-01-15 10:30 ` Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 10/12] crypto: qce - Add support for lock/unlock in skcipher Md Sadre Alam
` (3 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:30 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add LOCK and UNLOCK flag support while preparing
command descriptor for writing crypto register.
added qce_bam_acquire_lock() and qce_bam_release_lock()
which will do dummy write to a crypto register for
acquiring lock and releasing lock.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* Added qce_bam_acquire_lock() and qce_bam_release_lock()
api
Change in [v3]
* No change
Change in [v2]
* Added initial support for LOCK/UNLOCK flag
on command descriptor
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/common.c | 35 +++++++++++++++++++++++++++++++++++
drivers/crypto/qce/core.h | 3 ++-
drivers/crypto/qce/dma.c | 7 ++++++-
drivers/crypto/qce/dma.h | 2 ++
4 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/qce/common.c b/drivers/crypto/qce/common.c
index ff96f6ba1fc5..dad12e15905f 100644
--- a/drivers/crypto/qce/common.c
+++ b/drivers/crypto/qce/common.c
@@ -588,6 +588,41 @@ int qce_start(struct crypto_async_request *async_req, u32 type)
#define STATUS_ERRORS \
(BIT(SW_ERR_SHIFT) | BIT(AXI_ERR_SHIFT) | BIT(HSD_ERR_SHIFT))
+int qce_bam_acquire_lock(struct qce_device *qce)
+{
+ int ret;
+
+ qce_clear_bam_transaction(qce);
+
+ /* This is just a dummy write to acquire lock on bam pipe */
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, 0, 1);
+ ret = qce_submit_cmd_desc(qce, QCE_DMA_DESC_FLAG_LOCK);
+ if (ret) {
+ dev_err(qce->dev, "Error in Locking cmd descriptor\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+int qce_bam_release_lock(struct qce_device *qce)
+{
+ int ret;
+
+ qce_clear_bam_transaction(qce);
+
+ /* This just dummy write to release lock on bam pipe*/
+ qce_write_reg_dma(qce, REG_AUTH_SEG_CFG, 0, 1);
+
+ ret = qce_submit_cmd_desc(qce, QCE_DMA_DESC_FLAG_UNLOCK);
+ if (ret) {
+ dev_err(qce->dev, "Error in Un-Locking cmd descriptor\n");
+ return ret;
+ }
+
+ return 0;
+}
+
int qce_check_status(struct qce_device *qce, u32 *status)
{
int ret = 0;
diff --git a/drivers/crypto/qce/core.h b/drivers/crypto/qce/core.h
index 4559232bdf71..8919c6f63163 100644
--- a/drivers/crypto/qce/core.h
+++ b/drivers/crypto/qce/core.h
@@ -71,5 +71,6 @@ int qce_read_reg_dma(struct qce_device *qce, unsigned int offset, void *buff,
void qce_clear_bam_transaction(struct qce_device *qce);
int qce_submit_cmd_desc(struct qce_device *qce, unsigned long flags);
struct qce_bam_transaction *qce_alloc_bam_txn(struct qce_dma_data *dma);
-
+int qce_bam_acquire_lock(struct qce_device *qce);
+int qce_bam_release_lock(struct qce_device *qce);
#endif /* _CORE_H_ */
diff --git a/drivers/crypto/qce/dma.c b/drivers/crypto/qce/dma.c
index 225ac5619249..c039a3d93750 100644
--- a/drivers/crypto/qce/dma.c
+++ b/drivers/crypto/qce/dma.c
@@ -73,7 +73,12 @@ int qce_submit_cmd_desc(struct qce_device *qce, unsigned long flags)
unsigned long desc_flags;
int ret = 0;
- desc_flags = DMA_PREP_CMD;
+ if (flags & QCE_DMA_DESC_FLAG_LOCK)
+ desc_flags = DMA_PREP_CMD | DMA_PREP_LOCK;
+ else if (flags & QCE_DMA_DESC_FLAG_UNLOCK)
+ desc_flags = DMA_PREP_CMD | DMA_PREP_UNLOCK;
+ else
+ desc_flags = DMA_PREP_CMD;
/* For command descriptor always use consumer pipe
* it recommended as per HPG
diff --git a/drivers/crypto/qce/dma.h b/drivers/crypto/qce/dma.h
index 2ec04e3df4ba..198be2deeda5 100644
--- a/drivers/crypto/qce/dma.h
+++ b/drivers/crypto/qce/dma.h
@@ -19,6 +19,8 @@
#define QCE_BAM_CMD_ELEMENT_SIZE 64
#define QCE_DMA_DESC_FLAG_BAM_NWD (0x0004)
#define QCE_MAX_REG_READ 8
+#define QCE_DMA_DESC_FLAG_LOCK (0x0002)
+#define QCE_DMA_DESC_FLAG_UNLOCK (0x0001)
struct qce_result_dump {
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 10/12] crypto: qce - Add support for lock/unlock in skcipher
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (8 preceding siblings ...)
2025-01-15 10:30 ` [PATCH v6 09/12] crypto: qce - Add LOCK and UNLOCK flag support Md Sadre Alam
@ 2025-01-15 10:30 ` Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 11/12] crypto: qce - Add support for lock/unlock in sha Md Sadre Alam
` (2 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:30 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add support for lock/unlock on bam pipe in skcipher.
If multiple EE's(Execution Environment) try to access
the same crypto engine then before accessing the crypto
engine EE's has to lock the bam pipe and then submit the
request to crypto engine. Once request done then EE's has
to unlock the bam pipe so that others EE's can access the
crypto engine.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* Move qce_bam_release_lock() after qca_dma_terminate_all()
api
Change in [v2]
* Added qce_bam_acquire_lock() and qce_bam_release_lock()
api for skcipher
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/skcipher.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c
index ffb334eb5b34..01b7d6125962 100644
--- a/drivers/crypto/qce/skcipher.c
+++ b/drivers/crypto/qce/skcipher.c
@@ -52,6 +52,8 @@ static void qce_skcipher_done(void *data)
sg_free_table(&rctx->dst_tbl);
+ qce_bam_release_lock(qce);
+
error = qce_check_status(qce, &status);
if (error < 0)
dev_dbg(qce->dev, "skcipher operation error (%x)\n", status);
@@ -82,6 +84,8 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req)
dir_src = diff_dst ? DMA_TO_DEVICE : DMA_BIDIRECTIONAL;
dir_dst = diff_dst ? DMA_FROM_DEVICE : DMA_BIDIRECTIONAL;
+ qce_bam_acquire_lock(qce);
+
rctx->src_nents = sg_nents_for_len(req->src, req->cryptlen);
if (diff_dst)
rctx->dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 11/12] crypto: qce - Add support for lock/unlock in sha
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (9 preceding siblings ...)
2025-01-15 10:30 ` [PATCH v6 10/12] crypto: qce - Add support for lock/unlock in skcipher Md Sadre Alam
@ 2025-01-15 10:30 ` Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 12/12] crypto: qce - Add support for lock/unlock in aead Md Sadre Alam
2025-02-20 14:27 ` [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support brgl
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:30 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add support for lock/unlock on bam pipe in sha.
If multiple EE's(Execution Environment) try to access
the same crypto engine then before accessing the crypto
engine EE's has to lock the bam pipe and then submit the
request to crypto engine. Once request done then EE's has
to unlock the bam pipe so that others EE's can access the
crypto engine.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* Move qce_bam_release_lock() after qca_dma_terminate_all()
api
Change in [v2]
* Added qce_bam_acquire_lock() and qce_bam_release_lock()
api for SHA
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/sha.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index 71b748183cfa..e495703031b3 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -60,6 +60,8 @@ static void qce_ahash_done(void *data)
rctx->byte_count[0] = cpu_to_be32(result->auth_byte_count[0]);
rctx->byte_count[1] = cpu_to_be32(result->auth_byte_count[1]);
+ qce_bam_release_lock(qce);
+
error = qce_check_status(qce, &status);
if (error < 0)
dev_dbg(qce->dev, "ahash operation error (%x)\n", status);
@@ -90,6 +92,8 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
rctx->authklen = AES_KEYSIZE_128;
}
+ qce_bam_acquire_lock(qce);
+
rctx->src_nents = sg_nents_for_len(req->src, req->nbytes);
if (rctx->src_nents < 0) {
dev_err(qce->dev, "Invalid numbers of src SG.\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v6 12/12] crypto: qce - Add support for lock/unlock in aead
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (10 preceding siblings ...)
2025-01-15 10:30 ` [PATCH v6 11/12] crypto: qce - Add support for lock/unlock in sha Md Sadre Alam
@ 2025-01-15 10:30 ` Md Sadre Alam
2025-02-20 14:27 ` [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support brgl
12 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-15 10:30 UTC (permalink / raw)
To: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm
Cc: quic_mdalam, quic_utiwari, quic_srichara, quic_varada
Add support for lock/unlock on bam pipe in aead.
If multiple EE's(Execution Environment) try to access
the same crypto engine then before accessing the crypto
engine EE's has to lock the bam pipe and then submit the
request to crypto engine. Once request done then EE's has
to unlock the bam pipe so that others EE's can access the
crypto engine.
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
Change in [v6]
* No change
Change in [v5]
* No change
Change in [v4]
* No change
Change in [v3]
* Move qce_bam_release_lock() after qca_dma_terminate_all()
api
Change in [v2]
* Added qce_bam_acquire_lock() and qce_bam_release_lock()
api for aead
Change in [v1]
* This patch was not included in [v1]
drivers/crypto/qce/aead.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/crypto/qce/aead.c b/drivers/crypto/qce/aead.c
index 97b56e92ea33..cbc2016a8ad0 100644
--- a/drivers/crypto/qce/aead.c
+++ b/drivers/crypto/qce/aead.c
@@ -63,6 +63,8 @@ static void qce_aead_done(void *data)
sg_free_table(&rctx->dst_tbl);
}
+ qce_bam_release_lock(qce);
+
error = qce_check_status(qce, &status);
if (error < 0 && (error != -EBADMSG))
dev_err(qce->dev, "aead operation error (%x)\n", status);
@@ -433,6 +435,8 @@ qce_aead_async_req_handle(struct crypto_async_request *async_req)
else
rctx->assoclen = req->assoclen;
+ qce_bam_acquire_lock(qce);
+
diff_dst = (req->src != req->dst) ? true : false;
dir_src = diff_dst ? DMA_TO_DEVICE : DMA_BIDIRECTIONAL;
dir_dst = diff_dst ? DMA_FROM_DEVICE : DMA_BIDIRECTIONAL;
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read
2025-01-15 10:29 ` [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read Md Sadre Alam
@ 2025-01-16 17:06 ` Stephan Gerhold
2025-01-17 4:32 ` Md Sadre Alam
0 siblings, 1 reply; 19+ messages in thread
From: Stephan Gerhold @ 2025-01-16 17:06 UTC (permalink / raw)
To: Md Sadre Alam
Cc: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm, quic_utiwari, quic_srichara,
quic_varada
On Wed, Jan 15, 2025 at 03:59:53PM +0530, Md Sadre Alam wrote:
> Add bam_sw_version register read. This will help to
> differentiate b/w some new BAM features across multiple
> BAM IP, feature like LOCK/UNLOCK of BAM pipe.
>
> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
> ---
>
> change in [v6]
>
> * No change
>
> change in [v5]
>
> * No change
>
> change in [v4]
>
> * Added BAM_SW_VERSION register read
>
> change in [v3]
>
> * This patch was not included in [v3]
>
> change in [v2]
>
> * This patch was not included in [v2]
>
> change in [v1]
>
> * This patch was not included in [v1]
>
> drivers/dma/qcom/bam_dma.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index c14557efd577..daeacd5cb8e9 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -83,6 +83,7 @@ struct bam_async_desc {
> enum bam_reg {
> BAM_CTRL,
> BAM_REVISION,
> + BAM_SW_VERSION,
> BAM_NUM_PIPES,
> BAM_DESC_CNT_TRSHLD,
> BAM_IRQ_SRCS,
> @@ -117,6 +118,7 @@ struct reg_offset_data {
> static const struct reg_offset_data bam_v1_3_reg_info[] = {
> [BAM_CTRL] = { 0x0F80, 0x00, 0x00, 0x00 },
> [BAM_REVISION] = { 0x0F84, 0x00, 0x00, 0x00 },
> + [BAM_SW_VERSION] = { 0x0F88, 0x00, 0x00, 0x00 },
> [BAM_NUM_PIPES] = { 0x0FBC, 0x00, 0x00, 0x00 },
> [BAM_DESC_CNT_TRSHLD] = { 0x0F88, 0x00, 0x00, 0x00 },
> [BAM_IRQ_SRCS] = { 0x0F8C, 0x00, 0x00, 0x00 },
> @@ -146,6 +148,7 @@ static const struct reg_offset_data bam_v1_3_reg_info[] = {
> static const struct reg_offset_data bam_v1_4_reg_info[] = {
> [BAM_CTRL] = { 0x0000, 0x00, 0x00, 0x00 },
> [BAM_REVISION] = { 0x0004, 0x00, 0x00, 0x00 },
> + [BAM_SW_VERSION] = { 0x0008, 0x00, 0x00, 0x00 },
> [BAM_NUM_PIPES] = { 0x003C, 0x00, 0x00, 0x00 },
> [BAM_DESC_CNT_TRSHLD] = { 0x0008, 0x00, 0x00, 0x00 },
> [BAM_IRQ_SRCS] = { 0x000C, 0x00, 0x00, 0x00 },
> @@ -175,6 +178,7 @@ static const struct reg_offset_data bam_v1_4_reg_info[] = {
> static const struct reg_offset_data bam_v1_7_reg_info[] = {
> [BAM_CTRL] = { 0x00000, 0x00, 0x00, 0x00 },
> [BAM_REVISION] = { 0x01000, 0x00, 0x00, 0x00 },
> + [BAM_SW_VERSION] = { 0x01004, 0x00, 0x00, 0x00 },
> [BAM_NUM_PIPES] = { 0x01008, 0x00, 0x00, 0x00 },
> [BAM_DESC_CNT_TRSHLD] = { 0x00008, 0x00, 0x00, 0x00 },
> [BAM_IRQ_SRCS] = { 0x03010, 0x00, 0x00, 0x00 },
> @@ -393,6 +397,7 @@ struct bam_device {
> bool controlled_remotely;
> bool powered_remotely;
> u32 active_channels;
> + u32 bam_sw_version;
>
> const struct reg_offset_data *layout;
>
> @@ -1306,6 +1311,9 @@ static int bam_dma_probe(struct platform_device *pdev)
> return ret;
> }
>
> + bdev->bam_sw_version = readl_relaxed(bam_addr(bdev, 0, BAM_SW_VERSION));
> + dev_info(bdev->dev, "BAM software version:0x%08x\n", bdev->bam_sw_version);
This will cause crashes for the same reason as your other patch. During
probe(), we can't read from BAM registers if we don't have a clock
assigned. There is no guarantee that the BAM is powered up.
To make this work properly on all platforms, you would need to defer
reading this register until the first channel is requested by the
consumer driver. Or limit this functionality to the if (bdev->bamclk)
case for now.
We should also prioritize fixing the existing regression before adding
new functionality.
Thanks,
Stephan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read
2025-01-16 17:06 ` Stephan Gerhold
@ 2025-01-17 4:32 ` Md Sadre Alam
0 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-01-17 4:32 UTC (permalink / raw)
To: Stephan Gerhold
Cc: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm, quic_utiwari, quic_srichara,
quic_varada
On 1/16/2025 10:36 PM, Stephan Gerhold wrote:
> On Wed, Jan 15, 2025 at 03:59:53PM +0530, Md Sadre Alam wrote:
>> Add bam_sw_version register read. This will help to
>> differentiate b/w some new BAM features across multiple
>> BAM IP, feature like LOCK/UNLOCK of BAM pipe.
>>
>> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
>> ---
>>
>> change in [v6]
>>
>> * No change
>>
>> change in [v5]
>>
>> * No change
>>
>> change in [v4]
>>
>> * Added BAM_SW_VERSION register read
>>
>> change in [v3]
>>
>> * This patch was not included in [v3]
>>
>> change in [v2]
>>
>> * This patch was not included in [v2]
>>
>> change in [v1]
>>
>> * This patch was not included in [v1]
>>
>> drivers/dma/qcom/bam_dma.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
>> index c14557efd577..daeacd5cb8e9 100644
>> --- a/drivers/dma/qcom/bam_dma.c
>> +++ b/drivers/dma/qcom/bam_dma.c
>> @@ -83,6 +83,7 @@ struct bam_async_desc {
>> enum bam_reg {
>> BAM_CTRL,
>> BAM_REVISION,
>> + BAM_SW_VERSION,
>> BAM_NUM_PIPES,
>> BAM_DESC_CNT_TRSHLD,
>> BAM_IRQ_SRCS,
>> @@ -117,6 +118,7 @@ struct reg_offset_data {
>> static const struct reg_offset_data bam_v1_3_reg_info[] = {
>> [BAM_CTRL] = { 0x0F80, 0x00, 0x00, 0x00 },
>> [BAM_REVISION] = { 0x0F84, 0x00, 0x00, 0x00 },
>> + [BAM_SW_VERSION] = { 0x0F88, 0x00, 0x00, 0x00 },
>> [BAM_NUM_PIPES] = { 0x0FBC, 0x00, 0x00, 0x00 },
>> [BAM_DESC_CNT_TRSHLD] = { 0x0F88, 0x00, 0x00, 0x00 },
>> [BAM_IRQ_SRCS] = { 0x0F8C, 0x00, 0x00, 0x00 },
>> @@ -146,6 +148,7 @@ static const struct reg_offset_data bam_v1_3_reg_info[] = {
>> static const struct reg_offset_data bam_v1_4_reg_info[] = {
>> [BAM_CTRL] = { 0x0000, 0x00, 0x00, 0x00 },
>> [BAM_REVISION] = { 0x0004, 0x00, 0x00, 0x00 },
>> + [BAM_SW_VERSION] = { 0x0008, 0x00, 0x00, 0x00 },
>> [BAM_NUM_PIPES] = { 0x003C, 0x00, 0x00, 0x00 },
>> [BAM_DESC_CNT_TRSHLD] = { 0x0008, 0x00, 0x00, 0x00 },
>> [BAM_IRQ_SRCS] = { 0x000C, 0x00, 0x00, 0x00 },
>> @@ -175,6 +178,7 @@ static const struct reg_offset_data bam_v1_4_reg_info[] = {
>> static const struct reg_offset_data bam_v1_7_reg_info[] = {
>> [BAM_CTRL] = { 0x00000, 0x00, 0x00, 0x00 },
>> [BAM_REVISION] = { 0x01000, 0x00, 0x00, 0x00 },
>> + [BAM_SW_VERSION] = { 0x01004, 0x00, 0x00, 0x00 },
>> [BAM_NUM_PIPES] = { 0x01008, 0x00, 0x00, 0x00 },
>> [BAM_DESC_CNT_TRSHLD] = { 0x00008, 0x00, 0x00, 0x00 },
>> [BAM_IRQ_SRCS] = { 0x03010, 0x00, 0x00, 0x00 },
>> @@ -393,6 +397,7 @@ struct bam_device {
>> bool controlled_remotely;
>> bool powered_remotely;
>> u32 active_channels;
>> + u32 bam_sw_version;
>>
>> const struct reg_offset_data *layout;
>>
>> @@ -1306,6 +1311,9 @@ static int bam_dma_probe(struct platform_device *pdev)
>> return ret;
>> }
>>
>> + bdev->bam_sw_version = readl_relaxed(bam_addr(bdev, 0, BAM_SW_VERSION));
>> + dev_info(bdev->dev, "BAM software version:0x%08x\n", bdev->bam_sw_version);
>
> This will cause crashes for the same reason as your other patch. During
> probe(), we can't read from BAM registers if we don't have a clock
> assigned. There is no guarantee that the BAM is powered up.
>
> To make this work properly on all platforms, you would need to defer
> reading this register until the first channel is requested by the
> consumer driver. Or limit this functionality to the if (bdev->bamclk)
> case for now.
Sure thanks for suggestion. Will fix in next revision.
>
> We should also prioritize fixing the existing regression before adding
> new functionality.
Sure, I am working on it will post quickly.
Thanks,
Alam.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
` (11 preceding siblings ...)
2025-01-15 10:30 ` [PATCH v6 12/12] crypto: qce - Add support for lock/unlock in aead Md Sadre Alam
@ 2025-02-20 14:27 ` brgl
12 siblings, 0 replies; 19+ messages in thread
From: brgl @ 2025-02-20 14:27 UTC (permalink / raw)
To: Md Sadre Alam
Cc: quic_utiwari, quic_srichara, quic_varada, vkoul, corbet,
thara.gopinath, herbert, davem, martin.petersen, enghua.yu,
u.kleine-koenig, dmaengine, linux-doc, linux-kernel, linux-crypto,
linux-arm-msm
On Wed, 15 Jan 2025 11:29:52 +0100, Md Sadre Alam
<quic_mdalam@quicinc.com> said:
> Requirements:
> In QCE crypto driver we are accessing the crypto engine registers
> directly via CPU read/write. Trust Zone could possibly to perform some
> crypto operations simultaneously, a race condition will be created and
> this could result in undefined behavior.
>
> To avoid this behavior we need to use BAM HW LOCK/UNLOCK feature on BAM
> pipes, and this LOCK/UNLOCK will be set via sending a command descriptor,
> where the HLOS/TZ QCE crypto driver prepares a command descriptor with a
> dummy write operation on one of the QCE crypto engine register and pass
> the LOCK/UNLOCK flag along with it.
>
On rb3gen2 I'm seeing the following when running cryptsetup benchmark:
# cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1 1452321 iterations per second for 256-bit key
PBKDF2-sha256 2641249 iterations per second for 256-bit key
PBKDF2-sha512 1278751 iterations per second for 256-bit key
PBKDF2-ripemd160 760940 iterations per second for 256-bit key
PBKDF2-whirlpool N/A
argon2i 4 iterations, 1008918 memory, 4 parallel threads (CPUs)
for 256-bit key (requested 2000 ms time)
argon2id 4 iterations, 1048576 memory, 4 parallel threads (CPUs)
for 256-bit key (requested 2000 ms time)
[ 43.558496] NET: Registered PF_ALG protocol family
[ 43.570034] arm-smmu 15000000.iommu: Unhandled context fault:
fsr=0x402, iova=0xfffdf000, fsynr=0x7b0003, cbfrsynra=0x4e4, cb=0
[ 43.582069] arm-smmu 15000000.iommu: FSR = 00000402 [Format=2
TF], SID=0x4e4
[ 43.592758] arm-smmu 15000000.iommu: FSYNR0 = 007b0003 [S1CBNDX=123 PLVL=3]
[ 43.608107] Internal error: synchronous external abort:
0000000096000010 [#1] PREEMPT SMP
[ 43.616509] Modules linked in: algif_skcipher af_alg bluetooth
ecdh_generic ecc ipv6 snd_soc_hdmi_codec phy_qcom_edp venus_dec
venus_enc videobuf2_dma_contig videobuf2_memops nb7vpq904m
lontium_lt9611uxc msm leds_qcom_lpg qcom_battmgr pmic_glink_altmode
aux_hpd_bridge ocmem qcom_pbs venus_core ucsi_glink drm_exec
typec_ucsi qcom_pon qcom_spmi_adc5 led_class_multicolor
qcom_spmi_temp_alarm rtc_pm8xxx gpu_sched v4l2_mem2mem ath11k_ahb
qcom_vadc_common nvmem_qcom_spmi_sdam drm_dp_aux_bus videobuf2_v4l2
qcom_stats dispcc_sc7280 drm_display_helper videodev ath11k
videobuf2_common coresight_stm drm_client_lib camcc_sc7280
videocc_sc7280 mac80211 mc i2c_qcom_geni phy_qcom_qmp_combo stm_core
coresight_replicator aux_bridge coresight_tmc coresight_funnel
llcc_qcom libarc4 gpi icc_bwmon typec phy_qcom_snps_femto_v2 coresight
qcrypto qcom_q6v5_pas authenc qcom_pil_info qcom_q6v5 gpucc_sc7280
ufs_qcom libdes qcom_sysmon qcom_common pinctrl_sc7280_lpass_lpi
qcom_glink_smem mdt_loader phy_qcom_qmp_ufs lpassaudiocc_sc7280
[ 43.616763] pinctrl_lpass_lpi cfg80211 phy_qcom_qmp_pcie
icc_osm_l3 rfkill qcom_rng qrtr nvmem_reboot_mode display_connector
socinfo drm_kms_helper pmic_glink pdr_interface qcom_pdr_msg
qmi_helpers drm backlight
[ 43.727571] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted
6.14.0-rc3-next-20250220-00012-g2a8d60663e03-dirty #53
[ 43.738291] Hardware name: Qualcomm Technologies, Inc. Robotics RB3gen2 (DT)
[ 43.745535] pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 43.752685] pc : bam_dma_irq+0x374/0x3b0
[ 43.756736] lr : bam_dma_irq+0x2c8/0x3b0
[ 43.760781] sp : ffff800080003e90
[ 43.764200] x29: ffff800080003e90 x28: ffffd03eaae84880 x27: 000000009edf8000
[ 43.771543] x26: ffff45a746642c80 x25: 0000000a24f8499b x24: ffff45a742dca080
[ 43.778886] x23: ffff45a742df7600 x22: 000000000000006e x21: ffff8000811c3000
[ 43.786228] x20: ffff45a742df7630 x19: ffff45a742eaab80 x18: 0000000000000001
[ 43.793568] x17: ffff75698e7b4000 x16: ffff800080000000 x15: 0000000000000034
[ 43.800902] x14: 0000000000000038 x13: 0000000000010008 x12: 071c71c71c71c71c
[ 43.808244] x11: 0000000000000040 x10: ffff45a74000a230 x9 : ffff45a74000a228
[ 43.815587] x8 : ffff45a7407a1dd0 x7 : 0000000000000000 x6 : 0000000000000000
[ 43.822920] x5 : ffff45a7407a1da8 x4 : 0000000000000000 x3 : 0000000000000018
[ 43.830253] x2 : ffff8000811c0000 x1 : ffff8000811c0018 x0 : 0000000000000002
[ 43.837594] Call trace:
[ 43.840115] bam_dma_irq+0x374/0x3b0 (P)
[ 43.844163] __handle_irq_event_percpu+0x48/0x140
[ 43.849006] handle_irq_event+0x4c/0xb0
[ 43.852961] handle_fasteoi_irq+0xa0/0x1bc
[ 43.857186] handle_irq_desc+0x34/0x58
[ 43.861054] generic_handle_domain_irq+0x1c/0x28
[ 43.865812] gic_handle_irq+0x4c/0x120
[ 43.869680] call_on_irq_stack+0x24/0x64
[ 43.873728] do_interrupt_handler+0x80/0x84
[ 43.878039] el1_interrupt+0x34/0x68
[ 43.881732] el1h_64_irq_handler+0x18/0x24
[ 43.885955] el1h_64_irq+0x6c/0x70
[ 43.889465] cpuidle_enter_state+0xac/0x320 (P)
[ 43.894133] cpuidle_enter+0x38/0x50
[ 43.897826] do_idle+0x1e4/0x260
[ 43.901151] cpu_startup_entry+0x38/0x3c
[ 43.905195] rest_init+0xdc/0xe0
[ 43.908531] console_on_rootfs+0x0/0x6c
[ 43.912490] __primary_switched+0x88/0x90
[ 43.916621] Code: b9409063 1b047c21 8b030021 8b010041 (b9000020)
[ 43.922881] ---[ end trace 0000000000000000 ]---
[ 43.927633] Kernel panic - not syncing: synchronous external abort:
Fatal exception in interrupt
[ 43.936653] SMP: stopping secondary CPUs
[ 43.941042] Kernel Offset: 0x503e28e00000 from 0xffff800080000000
[ 43.947306] PHYS_OFFSET: 0xfff0ba59c0000000
[ 43.951615] CPU features: 0x300,00000170,00801250,8200720b
[ 43.957257] Memory Limit: none
[ 43.960405] ---[ end Kernel panic - not syncing: synchronous
external abort: Fatal exception in interrupt ]---
Bartosz
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support
2025-01-15 10:29 ` [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support Md Sadre Alam
@ 2025-03-07 13:37 ` Bartosz Golaszewski
0 siblings, 0 replies; 19+ messages in thread
From: Bartosz Golaszewski @ 2025-03-07 13:37 UTC (permalink / raw)
To: Md Sadre Alam
Cc: vkoul, corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm, quic_utiwari, quic_srichara,
quic_varada
On Wed, Jan 15, 2025 at 11:33 AM Md Sadre Alam <quic_mdalam@quicinc.com> wrote:
>
> BAM IP version 1.4.0 and above only supports this LOCK/UNLOCK
> feature. So adding check for the same and setting bam_pipe_lock
> based on BAM SW Version.
>
Why do we need to read it at run-time if we already know the version
of the IP from the compatible?
Bartosz
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag
2025-01-15 10:29 ` [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag Md Sadre Alam
@ 2025-03-10 20:36 ` Vinod Koul
2025-03-11 5:11 ` Md Sadre Alam
0 siblings, 1 reply; 19+ messages in thread
From: Vinod Koul @ 2025-03-10 20:36 UTC (permalink / raw)
To: Md Sadre Alam
Cc: corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm, quic_utiwari, quic_srichara,
quic_varada
On 15-01-25, 15:59, Md Sadre Alam wrote:
> Add lock and unlock flag support on command descriptor.
> Once lock set in requester pipe, then the bam controller
> will lock all others pipe and process the request only
> from requester pipe. Unlocking only can be performed from
> the same pipe.
>
> If DMA_PREP_LOCK flag passed in command descriptor then requester
> of this transaction wanted to lock the BAM controller for this
> transaction so BAM driver should set LOCK bit for the HW descriptor.
>
> If DMA_PREP_UNLOCK flag passed in command descriptor then requester
> of this transaction wanted to unlock the BAM controller.so BAM driver
> should set UNLOCK bit for the HW descriptor.
>
> BAM IP version 1.4.0 and above only supports this LOCK/UNLOCK
> feature.
Have you aligned internally b/w team at Qualcomm to have this as single
approach for LOCK implementation. I would like to see ack from
Mukesh/Bjorn before proceeding ahead with this
>
> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
> ---
>
> Change in [v6]
>
> * Change "BAM" to "DAM"
>
> Change in [v5]
>
> * Added DMA_PREP_LOCK and DMA_PREP_UNLOCK flag support
>
> Change in [v4]
>
> * This patch was not included in v4
>
> Change in [v3]
>
> * This patch was not included in v3
>
> Change in [v2]
>
> * This patch was not included in v2
>
> Change in [v1]
>
> * This patch was not included in v1
>
> Documentation/driver-api/dmaengine/provider.rst | 15 +++++++++++++++
> include/linux/dmaengine.h | 6 ++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/Documentation/driver-api/dmaengine/provider.rst b/Documentation/driver-api/dmaengine/provider.rst
> index 3085f8b460fa..a032e55d0a4f 100644
> --- a/Documentation/driver-api/dmaengine/provider.rst
> +++ b/Documentation/driver-api/dmaengine/provider.rst
> @@ -628,6 +628,21 @@ DMA_CTRL_REUSE
> - This flag is only supported if the channel reports the DMA_LOAD_EOT
> capability.
>
> +- DMA_PREP_LOCK
> +
> + - If set, the DMA will lock all other pipes not related to the current
> + pipe group, and keep handling the current pipe only.
> +
> + - All pipes not within this group will be locked by this pipe upon lock
> + event.
> +
> + - only pipes which are in the same group and relate to the same Environment
> + Execution(EE) will not be locked by a certain pipe.
> +
> +- DMA_PREP_UNLOCK
> +
> + - If set, DMA will release all locked pipes
> +
> General Design Notes
> ====================
>
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 346251bf1026..8ebd43a998a7 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -200,6 +200,10 @@ struct dma_vec {
> * transaction is marked with DMA_PREP_REPEAT will cause the new transaction
> * to never be processed and stay in the issued queue forever. The flag is
> * ignored if the previous transaction is not a repeated transaction.
> + * @DMA_PREP_LOCK: tell the driver that there is a lock bit set on command
> + * descriptor.
> + * @DMA_PREP_UNLOCK: tell the driver that there is a un-lock bit set on command
> + * descriptor.
> */
> enum dma_ctrl_flags {
> DMA_PREP_INTERRUPT = (1 << 0),
> @@ -212,6 +216,8 @@ enum dma_ctrl_flags {
> DMA_PREP_CMD = (1 << 7),
> DMA_PREP_REPEAT = (1 << 8),
> DMA_PREP_LOAD_EOT = (1 << 9),
> + DMA_PREP_LOCK = (1 << 10),
> + DMA_PREP_UNLOCK = (1 << 11),
> };
>
> /**
> --
> 2.34.1
--
~Vinod
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag
2025-03-10 20:36 ` Vinod Koul
@ 2025-03-11 5:11 ` Md Sadre Alam
0 siblings, 0 replies; 19+ messages in thread
From: Md Sadre Alam @ 2025-03-11 5:11 UTC (permalink / raw)
To: Vinod Koul
Cc: corbet, thara.gopinath, herbert, davem, martin.petersen,
enghua.yu, u.kleine-koenig, dmaengine, linux-doc, linux-kernel,
linux-crypto, linux-arm-msm, quic_utiwari, quic_srichara,
quic_varada
On 3/11/2025 2:06 AM, Vinod Koul wrote:
> On 15-01-25, 15:59, Md Sadre Alam wrote:
>> Add lock and unlock flag support on command descriptor.
>> Once lock set in requester pipe, then the bam controller
>> will lock all others pipe and process the request only
>> from requester pipe. Unlocking only can be performed from
>> the same pipe.
>>
>> If DMA_PREP_LOCK flag passed in command descriptor then requester
>> of this transaction wanted to lock the BAM controller for this
>> transaction so BAM driver should set LOCK bit for the HW descriptor.
>>
>> If DMA_PREP_UNLOCK flag passed in command descriptor then requester
>> of this transaction wanted to unlock the BAM controller.so BAM driver
>> should set UNLOCK bit for the HW descriptor.
>>
>> BAM IP version 1.4.0 and above only supports this LOCK/UNLOCK
>> feature.
>
> Have you aligned internally b/w team at Qualcomm to have this as single
> approach for LOCK implementation. I would like to see ack from
> Mukesh/Bjorn before proceeding ahead with this
I have already discuss this internally with Mukesh and he has posted his
response here [1]
[1]
https://lore.kernel.org/all/1566eafb-7286-4f27-922d-0bbaaab8120b@quicinc.com/
>
>>
>> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
>> ---
>>
>> Change in [v6]
>>
>> * Change "BAM" to "DAM"
>>
>> Change in [v5]
>>
>> * Added DMA_PREP_LOCK and DMA_PREP_UNLOCK flag support
>>
>> Change in [v4]
>>
>> * This patch was not included in v4
>>
>> Change in [v3]
>>
>> * This patch was not included in v3
>>
>> Change in [v2]
>>
>> * This patch was not included in v2
>>
>> Change in [v1]
>>
>> * This patch was not included in v1
>>
>> Documentation/driver-api/dmaengine/provider.rst | 15 +++++++++++++++
>> include/linux/dmaengine.h | 6 ++++++
>> 2 files changed, 21 insertions(+)
>>
>> diff --git a/Documentation/driver-api/dmaengine/provider.rst b/Documentation/driver-api/dmaengine/provider.rst
>> index 3085f8b460fa..a032e55d0a4f 100644
>> --- a/Documentation/driver-api/dmaengine/provider.rst
>> +++ b/Documentation/driver-api/dmaengine/provider.rst
>> @@ -628,6 +628,21 @@ DMA_CTRL_REUSE
>> - This flag is only supported if the channel reports the DMA_LOAD_EOT
>> capability.
>>
>> +- DMA_PREP_LOCK
>> +
>> + - If set, the DMA will lock all other pipes not related to the current
>> + pipe group, and keep handling the current pipe only.
>> +
>> + - All pipes not within this group will be locked by this pipe upon lock
>> + event.
>> +
>> + - only pipes which are in the same group and relate to the same Environment
>> + Execution(EE) will not be locked by a certain pipe.
>> +
>> +- DMA_PREP_UNLOCK
>> +
>> + - If set, DMA will release all locked pipes
>> +
>> General Design Notes
>> ====================
>>
>> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
>> index 346251bf1026..8ebd43a998a7 100644
>> --- a/include/linux/dmaengine.h
>> +++ b/include/linux/dmaengine.h
>> @@ -200,6 +200,10 @@ struct dma_vec {
>> * transaction is marked with DMA_PREP_REPEAT will cause the new transaction
>> * to never be processed and stay in the issued queue forever. The flag is
>> * ignored if the previous transaction is not a repeated transaction.
>> + * @DMA_PREP_LOCK: tell the driver that there is a lock bit set on command
>> + * descriptor.
>> + * @DMA_PREP_UNLOCK: tell the driver that there is a un-lock bit set on command
>> + * descriptor.
>> */
>> enum dma_ctrl_flags {
>> DMA_PREP_INTERRUPT = (1 << 0),
>> @@ -212,6 +216,8 @@ enum dma_ctrl_flags {
>> DMA_PREP_CMD = (1 << 7),
>> DMA_PREP_REPEAT = (1 << 8),
>> DMA_PREP_LOAD_EOT = (1 << 9),
>> + DMA_PREP_LOCK = (1 << 10),
>> + DMA_PREP_UNLOCK = (1 << 11),
>> };
>>
>> /**
>> --
>> 2.34.1
>
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2025-03-11 5:11 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-15 10:29 [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 01/12] dmaengine: qcom: bam_dma: Add bam_sw_version register read Md Sadre Alam
2025-01-16 17:06 ` Stephan Gerhold
2025-01-17 4:32 ` Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 02/12] dmaengine: add DMA_PREP_LOCK and DMA_PREP_UNLOCK flag Md Sadre Alam
2025-03-10 20:36 ` Vinod Koul
2025-03-11 5:11 ` Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 03/12] dmaengine: qcom: bam_dma: add bam_pipe_lock flag support Md Sadre Alam
2025-03-07 13:37 ` Bartosz Golaszewski
2025-01-15 10:29 ` [PATCH v6 04/12] crypto: qce - Add support for crypto address read Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 05/12] crypto: qce - Add bam dma support for crypto register r/w Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 06/12] crypto: qce - Convert register r/w for skcipher via BAM/DMA Md Sadre Alam
2025-01-15 10:29 ` [PATCH v6 07/12] crypto: qce - Convert register r/w for sha " Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 08/12] crypto: qce - Convert register r/w for aead " Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 09/12] crypto: qce - Add LOCK and UNLOCK flag support Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 10/12] crypto: qce - Add support for lock/unlock in skcipher Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 11/12] crypto: qce - Add support for lock/unlock in sha Md Sadre Alam
2025-01-15 10:30 ` [PATCH v6 12/12] crypto: qce - Add support for lock/unlock in aead Md Sadre Alam
2025-02-20 14:27 ` [PATCH v6 00/12] dmaengine: qcom: bam_dma: add cmd descriptor support brgl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).