Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1740393pxj; Sat, 5 Jun 2021 01:34:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjWTojKbSpcC8KHjur2g89eAvn28xNZmaoXcXVH7wPpWseEka2Eq925EogWjWowhDZrxWR X-Received: by 2002:a17:906:2f91:: with SMTP id w17mr8363366eji.443.1622882042516; Sat, 05 Jun 2021 01:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622882042; cv=none; d=google.com; s=arc-20160816; b=LbhqRK6894TPfsh89VfqLiJjmDol+YXi0mZwEW3syvnSPXN+7LXZbBx2//zLZCBnNW mxW1M33TYmEapVhAA81gVeFDRvCcFY76Wa6HcUf8fPZMz1bvcFYDODFt/Y2PCL9EOiMQ WKncW8nO8s41OEQHqUM+MKnEbyscKkcUexN3obN183o1RPg8iTdwZNY6brHCPXb7S8+y j4nyO60uyDbCHLATVe1wBMR+usdBgPuI/gv8cu94x9mS1nYQ3Gu0ciI2JMd6kzFxQpQ0 HPq8tr/zKa2Ce5TgcgkNNI2azlFAp0Ig3zGdo8bS7dn1ym0z7d+T0FZ0bh0xhKES3QOH 6b7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xotmvldeiH2nvjCl/SbEJZu3HovTS9rXIMr+8EDJUGs=; b=CNXaA3EVdQRUN5Dj1/zPJBPvRJk1sqTgA9ikC0vWyCxfzTQtd80Uhg8OOckk0eIwrR flAYfb03m3jGmvW8/B7WGmWNG2UCguiWTEbcXU90kLi1+wfWHvtG03Hbfybwl17Wg6th /6G32FPpxBzijo6FrTYdkmvQEHZDxrrbvjyYm0hi6H8i7S5tYgbgX/b6tbA/hSkNMiqK M8mXok5WAH1es8RKgqVt8S2gPrS8G7gza+P1QvuG4i/QM1drgTLmjoNr5WrXWjC54veO /eeqwWFla/gqh/5nLrooiSBgGeAmbOWKi1LYYnaqo7IyqeO8Toek1R6nNeta2Xo4l3yn JVIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GkZkiIXL; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si6739411edx.169.2021.06.05.01.33.38; Sat, 05 Jun 2021 01:34:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GkZkiIXL; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbhFEIeE (ORCPT + 99 others); Sat, 5 Jun 2021 04:34:04 -0400 Received: from mail-oi1-f179.google.com ([209.85.167.179]:40670 "EHLO mail-oi1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbhFEIeD (ORCPT ); Sat, 5 Jun 2021 04:34:03 -0400 Received: by mail-oi1-f179.google.com with SMTP id r17so2036918oic.7 for ; Sat, 05 Jun 2021 01:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xotmvldeiH2nvjCl/SbEJZu3HovTS9rXIMr+8EDJUGs=; b=GkZkiIXLSc9IYvsZt5bHxw1XquCV0h6dyXndU3IdFYXRet08kPIUHWIdJnp1w4+ujd WUQtLGkKtK8BZ34Gcm1qeW0aVCFlQuAjd0IUDauK9RCOKj9Jmpwf8H91IsPE8y185n2i HDdiLaG1ruahA79NvlpdcvspmOT2oaLjN3bTI0aeZoeftRHwzt+fGUayWizf6Lc1U585 hYxx/014JgUSSIPKxpgzbpN/8Qf1Rn0tOiFtn2ig8EE8PEiD1e00/o0EWG5rM39M3585 BfVbfgP8Jtr7Anh0iZnw6NFO5xvs4mYaNRg8whPrrIgmDYXNWiPWa1Dzc//dtnTv+Tg/ pj/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xotmvldeiH2nvjCl/SbEJZu3HovTS9rXIMr+8EDJUGs=; b=hen/ItHDA2j2zuBcCUzBpzPxJN5mBtwMYRXfyZve+LzSqPwEMYQlIpSxHIGdDHHhmR izZVtumekAOEoi7yKUZQGxDM7Yef/jq0ZmUCnkXvcBC9rJFezclX8skaZoNiqJVNd+DX uz6w02Tz1ful4EVG3o63JnfFAmfoWsfakVCWvxXiW5e/jttLew7J5oVx+NKDJXm6hjQR Wcww3ISpaNoaS68e0IIuc49BZUedi41DhiG+wQXw5YmJgCLqvCbZZmN6QV5O9AMJJf0Z 2zY4EFdiDGwy3WOMdwk2fUSWOA6Skh5wV/FdrTlQJOKmszcsuneywGt/WV+gM9MJ3XPB uDug== X-Gm-Message-State: AOAM530jL58tuwKZKQ0NvYf29lsyVIaZTdNVnO30wMb7jnzykL3tCYVQ EebsECvhU9z2G80fSBUJixB5NS0Ffp6sKby9Rr5YDXBCBEYSfw== X-Received: by 2002:a54:438e:: with SMTP id u14mr12136616oiv.126.1622881876215; Sat, 05 Jun 2021 01:31:16 -0700 (PDT) MIME-Version: 1.0 References: <20210519143700.27392-1-bhupesh.sharma@linaro.org> <20210519143700.27392-14-bhupesh.sharma@linaro.org> <125e1f83-e340-9cd3-91a8-cd1ee3ee8b7f@linaro.org> In-Reply-To: <125e1f83-e340-9cd3-91a8-cd1ee3ee8b7f@linaro.org> From: Bhupesh Sharma Date: Sat, 5 Jun 2021 14:01:05 +0530 Message-ID: Subject: Re: [PATCH v3 13/17] crypto: qce: core: Make clocks optional To: Thara Gopinath Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Andy Gross , Herbert Xu , "David S . Miller" , Stephen Boyd , Michael Turquette , Vinod Koul , dmaengine@vger.kernel.org, linux-clk@vger.kernel.org, linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bhupesh.linux@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Thara On Fri, 21 May 2021 at 07:41, Thara Gopinath wrote: > > Hi Bhupesh, > > On 5/19/21 10:36 AM, Bhupesh Sharma wrote: > > From: Thara Gopinath > > > > On certain Snapdragon processors, the crypto engine clocks are enabled by > > default by security firmware and the driver need not handle the > > clocks. Make acquiring of all the clocks optional in crypto enginer driver > > so that the driver intializes properly even if no clocks are specified in > > the dt. > > > > Cc: Bjorn Andersson > > Cc: Rob Herring > > Cc: Andy Gross > > Cc: Herbert Xu > > Cc: David S. Miller > > Cc: Stephen Boyd > > Cc: Michael Turquette > > Cc: Vinod Koul > > Cc: dmaengine@vger.kernel.org > > Cc: linux-clk@vger.kernel.org > > Cc: linux-crypto@vger.kernel.org > > Cc: devicetree@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Cc: bhupesh.linux@gmail.com > > Signed-off-by: Thara Gopinath > > [ bhupesh.sharma@linaro.org: Make clock enablement optional only for qcom parts where > > firmware has already initialized them, using a bool variable and fix > > error paths ] > > Signed-off-by: Bhupesh Sharma > > --- > > drivers/crypto/qce/core.c | 89 +++++++++++++++++++++++++-------------- > > drivers/crypto/qce/core.h | 2 + > > 2 files changed, 59 insertions(+), 32 deletions(-) > > > > diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c > > index 905378906ac7..8c3c68ba579e 100644 > > --- a/drivers/crypto/qce/core.c > > +++ b/drivers/crypto/qce/core.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -184,10 +185,20 @@ static int qce_check_version(struct qce_device *qce) > > return 0; > > } > > > > +static const struct of_device_id qce_crypto_of_match[] = { > > + { .compatible = "qcom,ipq6018-qce", }, > > + { .compatible = "qcom,sdm845-qce", }, > > + { .compatible = "qcom,sm8250-qce", }, > > Adding qcom,sm8250-qce does not belong in this patch. It deserves a > separate patch of it's own. Ok, I will fix it in v4. > > + {} > > +}; > > +MODULE_DEVICE_TABLE(of, qce_crypto_of_match); > > + > > static int qce_crypto_probe(struct platform_device *pdev) > > { > > struct device *dev = &pdev->dev; > > struct qce_device *qce; > > + const struct of_device_id *of_id = > > + of_match_device(qce_crypto_of_match, &pdev->dev); > > int ret; > > > > qce = devm_kzalloc(dev, sizeof(*qce), GFP_KERNEL); > > @@ -198,45 +209,65 @@ static int qce_crypto_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, qce); > > > > qce->base = devm_platform_ioremap_resource(pdev, 0); > > - if (IS_ERR(qce->base)) > > - return PTR_ERR(qce->base); > > + if (IS_ERR(qce->base)) { > > + ret = PTR_ERR(qce->base); > > + goto err_out; > > + } > > I don't see the reason for change in error handling here or below. But > ,for whatever reason this is changed, it has to be a separate patch. Ok, I will fix it in v4. > > ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); > > if (ret < 0) > > - return ret; > > + goto err_out; > > > > qce->mem_path = devm_of_icc_get(qce->dev, "memory"); > > if (IS_ERR(qce->mem_path)) > > return dev_err_probe(dev, PTR_ERR(qce->mem_path), > > "Failed to get mem path\n"); > > > > - qce->core = devm_clk_get(qce->dev, "core"); > > - if (IS_ERR(qce->core)) > > - return PTR_ERR(qce->core); > > - > > - qce->iface = devm_clk_get(qce->dev, "iface"); > > - if (IS_ERR(qce->iface)) > > - return PTR_ERR(qce->iface); > > - > > - qce->bus = devm_clk_get(qce->dev, "bus"); > > - if (IS_ERR(qce->bus)) > > - return PTR_ERR(qce->bus); > > - > > ret = icc_set_bw(qce->mem_path, QCE_DEFAULT_MEM_BANDWIDTH, QCE_DEFAULT_MEM_BANDWIDTH); > > if (ret) > > - return ret; > > + goto err_out; > > > > - ret = clk_prepare_enable(qce->core); > > - if (ret) > > - return ret; > > + /* On some qcom parts the crypto clocks are already configured by > > + * the firmware running before linux. In such cases we don't need to > > + * enable/configure them again. Check here for the same. > > + */ > > + if (!strcmp(of_id->compatible, "qcom,ipq6018-qce") || > > + !strcmp(of_id->compatible, "qcom,sdm845-qce")) > > You can avoid this and most of this patch by using > devm_clk_get_optional. This patch can be like just three lines of code > change. clk_prepare_enable returns 0 if the clock is null. There is no > need to check for the compatibles above. Use devm_clk_get_optional > instead of devm_clk_get and everything else can be left as is. Ok, I will fix it in v4. Thanks, Bhupesh > Warm Regards > Thara > > > + qce->clks_configured_by_fw = false; > > + else > > + qce->clks_configured_by_fw = true; > > + > > + if (!qce->clks_configured_by_fw) { > > + qce->core = devm_clk_get(qce->dev, "core"); > > + if (IS_ERR(qce->core)) { > > + ret = PTR_ERR(qce->core); > > + goto err_out; > > + } > > + > > + qce->iface = devm_clk_get(qce->dev, "iface"); > > + if (IS_ERR(qce->iface)) { > > + ret = PTR_ERR(qce->iface); > > + goto err_out; > > + } > > + > > + qce->bus = devm_clk_get(qce->dev, "bus"); > > + if (IS_ERR(qce->bus)) { > > + ret = PTR_ERR(qce->bus); > > + goto err_out; > > + } > > + > > + ret = clk_prepare_enable(qce->core); > > + if (ret) > > + goto err_out; > > > > - ret = clk_prepare_enable(qce->iface); > > - if (ret) > > - goto err_clks_core; > > + ret = clk_prepare_enable(qce->iface); > > + if (ret) > > + goto err_clks_core; > > > > - ret = clk_prepare_enable(qce->bus); > > - if (ret) > > - goto err_clks_iface; > > + ret = clk_prepare_enable(qce->bus); > > + if (ret) > > + goto err_clks_iface; > > + } > > > > ret = qce_dma_request(qce->dev, &qce->dma); > > if (ret) > > @@ -268,6 +299,7 @@ static int qce_crypto_probe(struct platform_device *pdev) > > clk_disable_unprepare(qce->iface); > > err_clks_core: > > clk_disable_unprepare(qce->core); > > +err_out: > > return ret; > > } > > > > @@ -284,13 +316,6 @@ static int qce_crypto_remove(struct platform_device *pdev) > > return 0; > > } > > > > -static const struct of_device_id qce_crypto_of_match[] = { > > - { .compatible = "qcom,ipq6018-qce", }, > > - { .compatible = "qcom,sdm845-qce", }, > > - {} > > -}; > > -MODULE_DEVICE_TABLE(of, qce_crypto_of_match); > > - > > static struct platform_driver qce_crypto_driver = { > > .probe = qce_crypto_probe, > > .remove = qce_crypto_remove, > > diff --git a/drivers/crypto/qce/core.h b/drivers/crypto/qce/core.h > > index 228fcd69ec51..d9bf05babecc 100644 > > --- a/drivers/crypto/qce/core.h > > +++ b/drivers/crypto/qce/core.h > > @@ -23,6 +23,7 @@ > > * @dma: pointer to dma data > > * @burst_size: the crypto burst size > > * @pipe_pair_id: which pipe pair id the device using > > + * @clks_configured_by_fw: clocks are already configured by fw > > * @async_req_enqueue: invoked by every algorithm to enqueue a request > > * @async_req_done: invoked by every algorithm to finish its request > > */ > > @@ -39,6 +40,7 @@ struct qce_device { > > struct qce_dma_data dma; > > int burst_size; > > unsigned int pipe_pair_id; > > + bool clks_configured_by_fw; > > int (*async_req_enqueue)(struct qce_device *qce, > > struct crypto_async_request *req); > > void (*async_req_done)(struct qce_device *qce, int ret); > > > >