From nobody Mon May 25 06:41:57 2026 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A5B171B1 for ; Sun, 17 May 2026 10:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779015174; cv=none; b=p930XjZ8cHql9/8rCeiEbbUWIKrW16ALM1n9mrGb7aInEftkn2bL1AI2q+84vW5DJRyW7l/hzUOt6TGRhpOaWu4D8x5ueKt4hkBQ3D3r7O/ZoeDoQbrGXHcFGRiyHWSWDxQWWfSsS21qUJRivXoMdrBBValZ0pDxtASJmBwuT34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779015174; c=relaxed/simple; bh=bofMkKfwN9ctze6xbOqcsYnI0AaUdoGqwrGoKBuSq/g=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=VRt7uRS0hf2zhfwFkr0NhFtNvZS8wQ5HkUoyRtoq6C1eZZXFRSQYhNyC2V1i7cgAXJKMtHXL37Iokx09C+B6+yh2PtRX0VZRK3934JPIL8ZDVZk0yMU1jBMs7JRLOzTwg2sUYHuGeo4ROr9LFElOiYOp1In62Za6sZ/dGeArnII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Wa3RZAoK; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ewkaeFkd; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="Wa3RZAoK"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ewkaeFkd" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64GNa37J3129425 for ; Sun, 17 May 2026 10:52:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=tiQ4yxGc+whFXtBAFCGDzzpYFaMe+Q6vzwS 7kB/GqaU=; b=Wa3RZAoKljYyUdzrRjTOtNfE0793v5AUsXZ1RdaJuq/t2ew6vbo A+dtgLXy305l8Yg9IxGbqBZWOGW45Jzd3Gcu1vF6bwwqXPWUYflcijncCLMW5amv Qzj9WEHTshcPHUoKtzVdwJHKnFlgWd+LqMGYkRP5dfyl7GrBEnmBffuR65+cZcMI LACEdou/NQWSnlMBGo/VT0dSgVevF7ZxkLJWst7hRPWQkLacETLrYlkaBzBUwINv bRABvS01PyOL0ChZ4o/02jrJSClplEA0J1uAMuLBM5tvmG4gzkCvIyvVC2WDPV1r wOnf72zBC2Nb5JugdbmXl9C3xIXylqntRUg== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e6hbcampw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sun, 17 May 2026 10:52:52 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-36629e48023so1062852a91.2 for ; Sun, 17 May 2026 03:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779015172; x=1779619972; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tiQ4yxGc+whFXtBAFCGDzzpYFaMe+Q6vzwS7kB/GqaU=; b=ewkaeFkdLjdChzZFb6jZjxM8ZEaaHfW5HTKKYY9JYv6irxYo67WBX1FiiPg/Z/PWxZ HusTvUbHtuEUASEz402xmJ5njz0mnWkvlnYRiBwlYgSSf6UDCETm3s1qX/WfFGZbb8b3 FxwwVQvDhDe+37xkSq5tqDogSEFh4LqsTRXMHbq2jNqEZciHVFa7AMLnrKlAtf3x5iJf z1H+fr2fyy3VaRPzrER99jeYJ4qqKQXZK3AORjhT/HU6AJBxuy7SKZYht2Fo0ZdhBE7A JtMSMGziARaAdeaTsvDtK53fw2kt6glbBl1DUL4KiI35GEEjQS6rPKHsgELfAJ2cMGlT VT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779015172; x=1779619972; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tiQ4yxGc+whFXtBAFCGDzzpYFaMe+Q6vzwS7kB/GqaU=; b=iMWATrExvU1SCKdpxpeHFyVM0ZvyFLygY/hv4ZexTNrCI8iIVTKsQF+jdbctNsFNwI i1p1ArJiN7OZBbmhTo0asTA4aE9qt7QkMtnhcYbhPIZIK9ulhXpEaudwKWvMArbizHOg QNNweIajt4izQDf32PSW+E91XqsRJXA7GLQcykJzqTRCIgEjo3ey1lcXP+kIBG2OdFhY NWXP5bicU9JUEVrv8mdW8Q3ANLn1c2wbLVuOYohYshyvFn2wNomNrXNNGDWGLHUygbFm z/8voSp4GCisp9HLbylQg/dgKjvtaJNsBwQUfd1XeCw1b/qwre+F2oavG/LsmR5MO6qJ c7/A== X-Forwarded-Encrypted: i=1; AFNElJ+tLNbzpEVVgkJ4vZKAakshpXrbENmRzPzEo4nE+oABS9qq5Yd6ffGgokOpRn3XF0llLZr8r22K+s13C8o=@vger.kernel.org X-Gm-Message-State: AOJu0YxoQrdSZor5jBEbe9SXYAILE3iE3V9rQatXeXbeE96flyqlli/q wv44Gq5XCXlGgO8au/rjkQs7SmcYqU60A5ctJevq8VJ3QE5dhLPTawNnJ/aA7Ss9AXHPXNZil3j xPaQZI7tZgroiXrfgW1YBOrfrJk+5pTN+ju+E5v69I514GnUuujadzE1nj3jNg4oIrhc= X-Gm-Gg: Acq92OFUz/dkI5MQ4VldJ0UljksJiO8Rae4+Wm8Qdy6VKS1uEq88dwX6Q2WDy5VVxOC 1nINbIvKosKGD/ZyAtz4v6G0THRX/UbCZtl58mFg5E0jlFDQFYu1lh0hgPbVgAU83Eie2KKS4rs hB4D+gPhweY5aYY5sT+w9cGX26RR+QAcLEwzfy5Fa4bVa2waoS0+poYLitKPDiR+B6WrU7RtQ1C 42vHrMnaGSpCFoJu5tshArB1EmaS9rt0zjPlxUD+awLXHMdKeC+1bGKMysHSLL7BgNHQu4wJ6V8 p5zbYdz5RuUx/M1RgkzM+LTGkvmWuddXlr8dpTpGmX70EcFaPlZdW1I5au1CJoYwwqMdhabHdd9 JCnY0cf0s+isi0PQP4lvTU0nWRTjTxVzjS2iDcCWHGWB4I9rernorE5IsLJZ2uQ== X-Received: by 2002:a17:90b:35c8:b0:356:22ef:57ba with SMTP id 98e67ed59e1d1-369518b669amr11146036a91.7.1779015171571; Sun, 17 May 2026 03:52:51 -0700 (PDT) X-Received: by 2002:a17:90b:35c8:b0:356:22ef:57ba with SMTP id 98e67ed59e1d1-369518b669amr11146021a91.7.1779015170989; Sun, 17 May 2026 03:52:50 -0700 (PDT) Received: from hu-utiwari-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369512424a6sm10132405a91.1.2026.05.17.03.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 03:52:50 -0700 (PDT) From: Udit Tiwari To: konrad.dybcio@oss.qualcomm.com, herbert@gondor.apana.org.au, thara.gopinath@gmail.com, davem@davemloft.net Cc: linux-crypto@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_neersoni@quicinc.com, udit.tiwari@oss.qualcomm.com Subject: [PATCH v8] crypto: qce - Add runtime PM and interconnect bandwidth scaling support Date: Sun, 17 May 2026 16:22:33 +0530 Message-Id: <20260517105233.807935-1-udit.tiwari@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=cuSrVV4i c=1 sm=1 tr=0 ts=6a099e04 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=VwQbUJbxAAAA:8 a=COk6AnOGAAAA:8 a=EUspDBNiAAAA:8 a=OR-uRB0iQuogYzU8RssA:9 a=rl5im9kqc5Lf4LNbBjHf:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTE3MDExNiBTYWx0ZWRfX6TFVTH97vTi/ Pf/Bfy1+WZuFFRs32yXs/XiiQIl42BjbBscZ/LrU+LojI6BGbRqBvMt4MapyhvDg4fl7DeMCjmb qnLvRE68fUh+hR/6Z755FuOZ5456qB7UWC4MVd+y2pBn8y21EquRYKt8DtOtz29sk7Ntj1WCF60 +5CG20CcZULievI33VBGc+FlLXfhxre2G4s5SSRu9RbeFNERnop02l4qiO60aDF/cDs3M+iQLui F3LpC53yHJR0vJlfGaH5493PzYrCrpkrWqEti5JXt3IFOIZiTdhayUY4TD0Ogdapmk+H4jZZnml cND2R52IB0bgb4pTzcTPtNPyfnxdJwAmFOEWPx1GddPIYugHKB4SbdCAYLXSRLdJmvR5A5ssDtu +ic5YFQgUCaBIpTkAFuR2KWEKsNjxqq6MtmYVlPSOYaq22OSiPglMEbPRwLCOk7Yls3YCVWl4nD 0AJzSXFlgeSRWABnoUg== X-Proofpoint-GUID: 8ZoPTDGFT3zXpc7s_VVomjNCld8m0yy2 X-Proofpoint-ORIG-GUID: 8ZoPTDGFT3zXpc7s_VVomjNCld8m0yy2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-17_02,2026-05-15_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 clxscore=1011 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605170116 Content-Type: text/plain; charset="utf-8" The Qualcomm Crypto Engine (QCE) driver currently lacks support for runtime power management (PM) and interconnect bandwidth control. As a result, the hardware remains fully powered and clocks stay enabled even when the device is idle. Additionally, static interconnect bandwidth votes are held indefinitely, preventing the system from reclaiming unused bandwidth. Address this by enabling runtime PM and dynamic interconnect bandwidth scaling to allow the system to suspend the device when idle and scale interconnect usage based on actual demand. Improve overall system efficiency by reducing power usage and optimizing interconnect resource allocation. Signed-off-by: Udit Tiwari --- Tested: - Verify that ICC votes drop to zero after probe and upon request completion. - Confirm that runtime PM usage count increments during active requests and decrements afterward. - Observe that the device correctly enters the suspended state when idle. Changes in v8: - Drop pm_clk framework (devm_pm_clk_create/pm_clk_add/pm_clk_suspend/ pm_clk_resume); use devm_clk_get_optional() and direct clk_prepare_enable()/clk_disable_unprepare() in runtime PM callbacks. This removes the CONFIG_PM_CLK dependency and the build error reported by the kernel test robot. - Replace icc_disable() with icc_set_bw(path, 0, 0) in runtime suspend to avoid corrupting the internal 'enabled' flag, which would cause subsequent icc_set_bw() calls in resume to be silently skipped during aggregation. - Fix ICC vote ordering: cast bandwidth vote before enabling clocks in resume; disable clocks before dropping ICC vote in suspend. - Use PM_RUNTIME_ACQUIRE_AUTOSUSPEND()/PM_RUNTIME_ACQUIRE_ERR() wrapper macros instead of raw ACQUIRE() in both qce_handle_queue() and probe. - Drop __maybe_unused from runtime PM callbacks; use RUNTIME_PM_OPS / SYSTEM_SLEEP_PM_OPS (non-SET_ prefix) and pm_ptr(&qce_crypto_pm_ops). - Drop unnecessary ret =3D 0 initializations in qce_handle_queue() and qce_runtime_resume(). - Extend probe comment to explain ICC + clock ordering rationale. - Link to v7: https://lore.kernel.org/lkml/20260220072818.2921517-1-quic_utiwari@quicin= c.com/ Changes in v7: - Use ACQUIRE guard in probe to simplify runtime PM management and error paths. - Drop redundant icc_enable() call in runtime resume path. - Explicitly call pm_clk_suspend(dev) and pm_clk_resume(dev) within the custom runtime PM callbacks. Since custom callbacks are provided to handle interconnect scaling, the standard PM clock helpers must be invoked manually to ensure clocks are gated/ungated. - Link to v6: https://lore.kernel.org/lkml/20260210061437.2293654-1-quic_utiwari@quicinc= .com/ Changes in v6: - Adopt ACQUIRE(pm_runtime_active_try, ...) for scoped runtime PM management in qce_handle_queue(). This removes the need for manual put calls and goto labels in the error paths, as suggested by Konrad. - Link to v5: https://lore.kernel.org/lkml/20251120062443.2016084-1-quic_utiwari@quicin= c.com/ Changes in v5: - Drop Reported-by and Closes tags for kernel test robot W=3D1 warnings, as the issue was fixed within the same patch series. - Fix a minor comment indentation/style issue. - Link to v4: https://lore.kernel.org/lkml/20251117062737.3946074-1-quic_utiwari@quicin= c.com/ Changes in v4: - Annotate runtime PM callbacks with __maybe_unused to silence W=3D1 warnings. - Add Reported-by and Closes tags for kernel test robot warning. - Link to v3: https://lore.kernel.org/lkml/20251115084851.2750446-1-quic_utiwari@quicin= c.com/ Changes in v3: - Switch from manual clock management to PM clock helpers (devm_pm_clk_create() + pm_clk_add()); no direct clk_* enable/disable in runtime callbacks. - Replace pm_runtime_get_sync() with pm_runtime_resume_and_get(); remove pm_runtime_put_noidle() on error. - Define PM ops using helper macros and reuse runtime callbacks for system sleep via pm_runtime_force_suspend()/pm_runtime_force_resume(). - Link to v2: https://lore.kernel.org/lkml/20250826110917.3383061-1-quic_utiwari@quicin= c.com/ Changes in v2: - Extend suspend/resume support to include runtime PM and ICC scaling. - Register dev_pm_ops and implement runtime_suspend/resume callbacks. - Link to v1: https://lore.kernel.org/lkml/20250606105808.2119280-1-quic_utiwari@quicin= c.com/ --- drivers/crypto/qce/core.c | 99 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c index b966f3365b7d..c43a0e5f56f5 100644 --- a/drivers/crypto/qce/core.c +++ b/drivers/crypto/qce/core.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -88,7 +90,12 @@ static int qce_handle_queue(struct qce_device *qce, struct crypto_async_request *req) { struct crypto_async_request *async_req, *backlog; - int ret =3D 0, err; + int ret, err; + + PM_RUNTIME_ACQUIRE_AUTOSUSPEND(qce->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; =20 scoped_guard(mutex, &qce->lock) { if (req) @@ -207,23 +214,33 @@ static int qce_crypto_probe(struct platform_device *p= dev) if (ret < 0) return ret; =20 - qce->core =3D devm_clk_get_optional_enabled(qce->dev, "core"); + qce->core =3D devm_clk_get_optional(qce->dev, "core"); if (IS_ERR(qce->core)) return PTR_ERR(qce->core); =20 - qce->iface =3D devm_clk_get_optional_enabled(qce->dev, "iface"); + qce->iface =3D devm_clk_get_optional(qce->dev, "iface"); if (IS_ERR(qce->iface)) return PTR_ERR(qce->iface); =20 - qce->bus =3D devm_clk_get_optional_enabled(qce->dev, "bus"); + qce->bus =3D devm_clk_get_optional(qce->dev, "bus"); if (IS_ERR(qce->bus)) return PTR_ERR(qce->bus); =20 - qce->mem_path =3D devm_of_icc_get(qce->dev, "memory"); + qce->mem_path =3D devm_of_icc_get(dev, "memory"); if (IS_ERR(qce->mem_path)) return PTR_ERR(qce->mem_path); =20 - ret =3D icc_set_bw(qce->mem_path, QCE_DEFAULT_MEM_BANDWIDTH, QCE_DEFAULT_= MEM_BANDWIDTH); + /* + * Enable runtime PM after clocks and ICC path are acquired so that + * the resume callback can enable clocks and apply the ICC bandwidth + * vote before any hardware access takes place. + */ + ret =3D devm_pm_runtime_enable(dev); + if (ret) + return ret; + + PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); if (ret) return ret; =20 @@ -245,9 +262,76 @@ static int qce_crypto_probe(struct platform_device *pd= ev) qce->async_req_enqueue =3D qce_async_request_enqueue; qce->async_req_done =3D qce_async_request_done; =20 - return devm_qce_register_algs(qce); + ret =3D devm_qce_register_algs(qce); + if (ret) + return ret; + + /* Configure autosuspend after successful init */ + pm_runtime_set_autosuspend_delay(dev, 100); + pm_runtime_use_autosuspend(dev); + pm_runtime_mark_last_busy(dev); + + return 0; +} + +static int qce_runtime_suspend(struct device *dev) +{ + struct qce_device *qce =3D dev_get_drvdata(dev); + int ret; + + clk_disable_unprepare(qce->core); + clk_disable_unprepare(qce->iface); + clk_disable_unprepare(qce->bus); + + ret =3D icc_set_bw(qce->mem_path, 0, 0); + if (ret) { + clk_prepare_enable(qce->bus); + clk_prepare_enable(qce->iface); + clk_prepare_enable(qce->core); + return ret; + } + + return 0; } =20 +static int qce_runtime_resume(struct device *dev) +{ + struct qce_device *qce =3D dev_get_drvdata(dev); + int ret; + + ret =3D icc_set_bw(qce->mem_path, QCE_DEFAULT_MEM_BANDWIDTH, + QCE_DEFAULT_MEM_BANDWIDTH); + if (ret) + return ret; + + ret =3D clk_prepare_enable(qce->core); + if (ret) + goto err_core; + + ret =3D clk_prepare_enable(qce->iface); + if (ret) + goto err_iface; + + ret =3D clk_prepare_enable(qce->bus); + if (ret) + goto err_bus; + + return 0; + +err_bus: + clk_disable_unprepare(qce->iface); +err_iface: + clk_disable_unprepare(qce->core); +err_core: + icc_set_bw(qce->mem_path, 0, 0); + return ret; +} + +static const struct dev_pm_ops qce_crypto_pm_ops =3D { + RUNTIME_PM_OPS(qce_runtime_suspend, qce_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) +}; + static const struct of_device_id qce_crypto_of_match[] =3D { { .compatible =3D "qcom,crypto-v5.1", }, { .compatible =3D "qcom,crypto-v5.4", }, @@ -261,6 +345,7 @@ static struct platform_driver qce_crypto_driver =3D { .driver =3D { .name =3D KBUILD_MODNAME, .of_match_table =3D qce_crypto_of_match, + .pm =3D pm_ptr(&qce_crypto_pm_ops), }, }; module_platform_driver(qce_crypto_driver); --=20 2.34.1