From nobody Sun Nov 24 01:26:06 2024 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (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 7C02A1E0DAC; Fri, 8 Nov 2024 10:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731061776; cv=none; b=FdQXbKrKi7J1umZjVzAjXHMR20QehApG7ms/odfFS0nQECiD7kqz641121s7RS0QozRDy5dfrPwobMi6uP10KWaNdkeuMc5TV0QyDa5D+qpEHGvRLEcI7DHNh+DheoxC91r8Ghn3hclBpXkauYabqBibJ/iblU+pDyw/cVsRIYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731061776; c=relaxed/simple; bh=X2H+XrbQ/GrQDJB0Xc9tQVfKae/vZngNpsMz83vReb0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YDo0mepLRBntgm/BHHd2jkJaspEKgh8BM9DJPr2o4G/6W7Hz6B/MG6ZHPJo4NPgHKhS6FRCt/Kf9JSEi2rAFEOPPA7bO1lQ1mg0eYu5oQLpc7rIhnqXqOBRK2teVWdcuXKEfiGxcGM5pUptlhlPumbGOjtcZw2giGXvvqs5V8aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=VIWEhO0v; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="VIWEhO0v" Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 2C03012002E; Fri, 8 Nov 2024 13:29:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 2C03012002E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1731061765; bh=WFuAArP6J98eZb/1JhFy1BBqp0mr+GrAAmxwASrRsUI=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=VIWEhO0vQE3PJyg3XT/wxB10Kg/BJllw5SNZU3cmnVRIr7XZdMcXiOjXWM5M2vJEQ JCo7gD+SY58c9dQdZ1gO3FxcTkryeuOM+1aPG1+E1YZhQaclcr/8jtlG0xEITr42xi IHoJnmcE8ZOK7yw25S0P5LSDtlGsgON49hT8UbsGbo6Dd2q9O2eC5fDmbRtuLSk/h/ q15wyeG6o5sE7vjGtRPS9im7O5dZW/8hB5nuDKQYZ8H3ElbWTom7RI4m7J1VaMH5uY kIuZDVaAdspGDs8V/n9qiJom48oHxhBLCi3rEaSXWEopoPJw8ESZ9Bc2OKOuFoeJli a7NfzKbDaSO9g== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 8 Nov 2024 13:29:25 +0300 (MSK) From: Alexey Romanov To: , , , , , , , , , , , CC: , , , , , , "Alexey Romanov" Subject: [PATCH v10 01/22] crypto: amlogic - Don't hardcode IRQ count Date: Fri, 8 Nov 2024 13:28:46 +0300 Message-ID: <20241108102907.1788584-2-avromanov@salutedevices.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108102907.1788584-1-avromanov@salutedevices.com> References: <20241108102907.1788584-1-avromanov@salutedevices.com> 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-ClientProxiedBy: p-i-exch-a-m2.sberdevices.ru (172.24.196.120) To p-i-exch-a-m1.sberdevices.ru (172.24.196.116) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 189039 [Nov 08 2024] X-KSMG-AntiSpam-Version: 6.1.1.7 X-KSMG-AntiSpam-Envelope-From: avromanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 41 0.3.41 623e98d5198769c015c72f45fabbb9f77bdb702b, {Tracking_from_domain_doesnt_match_to}, salutedevices.com:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;smtp.sberdevices.ru:7.1.1,5.0.1;127.0.0.199:7.1.2, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/11/08 08:34:00 #26834472 X-KSMG-AntiVirus-Status: Clean, skipped Content-Type: text/plain; charset="utf-8" IRQ count is no longer hardcoded, and make it part of struct meson_flow. We need this for extend driver support for other Amlogic SoC's. Signed-off-by: Alexey Romanov --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 47 ++++++++++++--------- drivers/crypto/amlogic/amlogic-gxl.h | 8 ++-- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/a= mlogic/amlogic-gxl-cipher.c index 29048da6f50a..b19032f92415 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -19,7 +19,7 @@ =20 static int get_engine_number(struct meson_dev *mc) { - return atomic_inc_return(&mc->flow) % MAXFLOW; + return atomic_inc_return(&mc->flow) % mc->flow_cnt; } =20 static bool meson_cipher_need_fallback(struct skcipher_request *areq) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/aml= ogic/amlogic-gxl-core.c index 1c18a5b8470e..dc35d7304eb0 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -28,8 +28,8 @@ static irqreturn_t meson_irq_handler(int irq, void *data) int flow; u32 p; =20 - for (flow =3D 0; flow < MAXFLOW; flow++) { - if (mc->irqs[flow] =3D=3D irq) { + for (flow =3D 0; flow < mc->flow_cnt; flow++) { + if (mc->chanlist[flow].irq =3D=3D irq) { p =3D readl(mc->base + ((0x04 + flow) << 2)); if (p) { writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2)); @@ -110,7 +110,7 @@ static int meson_debugfs_show(struct seq_file *seq, voi= d *v) struct meson_dev *mc __maybe_unused =3D seq->private; int i; =20 - for (i =3D 0; i < MAXFLOW; i++) + for (i =3D 0; i < mc->flow_cnt; i++) seq_printf(seq, "Channel %d: nreq %lu\n", i, #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->chanlist[i].stat_req); @@ -153,14 +153,32 @@ static void meson_free_chanlist(struct meson_dev *mc,= int i) */ static int meson_allocate_chanlist(struct meson_dev *mc) { + struct platform_device *pdev =3D to_platform_device(mc->dev); int i, err; =20 - mc->chanlist =3D devm_kcalloc(mc->dev, MAXFLOW, + mc->flow_cnt =3D platform_irq_count(pdev); + if (mc->flow_cnt <=3D 0) { + dev_err(mc->dev, "No IRQs defined\n"); + return -ENODEV; + } + + mc->chanlist =3D devm_kcalloc(mc->dev, mc->flow_cnt, sizeof(struct meson_flow), GFP_KERNEL); if (!mc->chanlist) return -ENOMEM; =20 - for (i =3D 0; i < MAXFLOW; i++) { + for (i =3D 0; i < mc->flow_cnt; i++) { + mc->chanlist[i].irq =3D platform_get_irq(pdev, i); + if (mc->chanlist[i].irq < 0) + return mc->chanlist[i].irq; + + err =3D devm_request_irq(mc->dev, mc->chanlist[i].irq, + meson_irq_handler, 0, "aml-crypto", mc); + if (err < 0) { + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); + return err; + } + init_completion(&mc->chanlist[i].complete); =20 mc->chanlist[i].engine =3D crypto_engine_alloc_init(mc->dev, true); @@ -230,7 +248,7 @@ static void meson_unregister_algs(struct meson_dev *mc) static int meson_crypto_probe(struct platform_device *pdev) { struct meson_dev *mc; - int err, i; + int err; =20 mc =3D devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); if (!mc) @@ -250,19 +268,6 @@ static int meson_crypto_probe(struct platform_device *= pdev) return err; } =20 - for (i =3D 0; i < MAXFLOW; i++) { - mc->irqs[i] =3D platform_get_irq(pdev, i); - if (mc->irqs[i] < 0) - return mc->irqs[i]; - - err =3D devm_request_irq(&pdev->dev, mc->irqs[i], meson_irq_handler, 0, - "gxl-crypto", mc); - if (err < 0) { - dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); - return err; - } - } - err =3D clk_prepare_enable(mc->busclk); if (err !=3D 0) { dev_err(&pdev->dev, "Cannot prepare_enable busclk\n"); @@ -292,7 +297,7 @@ static int meson_crypto_probe(struct platform_device *p= dev) error_alg: meson_unregister_algs(mc); error_flow: - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); clk_disable_unprepare(mc->busclk); return err; } @@ -307,7 +312,7 @@ static void meson_crypto_remove(struct platform_device = *pdev) =20 meson_unregister_algs(mc); =20 - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); =20 clk_disable_unprepare(mc->busclk); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/= amlogic-gxl.h index d68094ffb70a..9f1ef87333ae 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -22,8 +22,6 @@ #define MESON_OPMODE_ECB 0 #define MESON_OPMODE_CBC 1 =20 -#define MAXFLOW 2 - #define MAXDESC 64 =20 #define DESC_LAST BIT(18) @@ -62,6 +60,7 @@ struct meson_desc { * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done + * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow * @stat_req: number of request done by this flow @@ -70,6 +69,7 @@ struct meson_flow { struct crypto_engine *engine; struct completion complete; int status; + int irq; unsigned int keylen; dma_addr_t t_phy; struct meson_desc *tl; @@ -85,7 +85,7 @@ struct meson_flow { * @dev: the platform device * @chanlist: array of all flow * @flow: flow to use in next request - * @irqs: IRQ numbers for amlogic-crypto + * @flow_cnt: flow count for amlogic-crypto * @dbgfs_dir: Debugfs dentry for statistic directory * @dbgfs_stats: Debugfs dentry for statistic counters */ @@ -95,7 +95,7 @@ struct meson_dev { struct device *dev; struct meson_flow *chanlist; atomic_t flow; - int irqs[MAXFLOW]; + int flow_cnt; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG struct dentry *dbgfs_dir; #endif --=20 2.34.1