From nobody Wed Nov 27 19:26:04 2024 Received: from mx1.sberdevices.ru (mx1.sberdevices.ru [37.18.73.165]) (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 E0E501E2853; Fri, 8 Nov 2024 10:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.18.73.165 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731061783; cv=none; b=O6Wcyz+0/IM8sLpDtPIKxGwQ31KN7cn7JJuCjl9uYapy8zwqhEWYtUoRLo+yZv3wJPeVgfmCxoWl/nI4O32NRZ1vgqNkw9IZqeWQnhGphXeGqj+qXBCfxHDBOZmbe918a3C2avnyr3PJhECZWSm6McbgvAGmUAqAG1AuDZdPFMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731061783; c=relaxed/simple; bh=bAxKcNa2bho3I+kO6nrHA4pK2Jom8E/BotBICrdllQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DGoE6F6oHk+yDJ2t6r5L7QEjqdbdEmVjiLDIsWdDs+eDbgkb1VcK+1zWgKW7ZDURNl2nwBeWhnXN5q/IlDEmwzQm4KPeHlawB7hEf3bS+Mp/F6/jwq56lc3BW5n+QnUPLkIfzEuEUf752Si9CqjR2GQ9FIOrrHGC/0HFWAKaPvA= 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=P0L5cqE4; arc=none smtp.client-ip=37.18.73.165 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="P0L5cqE4" Received: from p-infra-ksmg-sc-msk01.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id E132C10002E; Fri, 8 Nov 2024 13:29:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru E132C10002E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1731061779; bh=PLbOl6vfaRcS4Zx5JgW50G+KOKQnPem8uZTZjmoFfbY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=P0L5cqE4ZlzA3UrYGxgSlzYFheoniyN+v9/aAyUenQQJ9nYSXEC/9aOCj0BaiUkyl NYgJ+w6nziWoTu7GEnIRJJqVUgFPB0PynzJ2w7QyOv+skkdATJDVv2jCvh8mKGmDaX OxUU4RhW1f3GByTzRFBEhsE6vzMMBCiKY9AA+Zex5vsj1R7j3aW4ubeGdAGJ+EhtWY nJKMVjXNAnhXI/FHv68MoNByWWC0pZJw/3z60nNnT3mzAxEOhZdMKYVe1c10EuxBOi vhtLrAxQGm7d4JH3u+HdY/vtMOBFgNvod9/g6PsQa3/t6Pno2LU1j4Z6DEIiGNYY/W tRHWLtHqDLEVA== 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:39 +0300 (MSK) From: Alexey Romanov To: , , , , , , , , , , , CC: , , , , , , "Alexey Romanov" Subject: [PATCH v10 07/22] crypto: amlogic - Move algs definition and cipher API to cipher.c Date: Fri, 8 Nov 2024 13:28:52 +0300 Message-ID: <20241108102907.1788584-8-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}, smtp.sberdevices.ru:5.0.1,7.1.1;127.0.0.199:7.1.2;salutedevices.com:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, 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" Because that is proper place for them. In particular, it takes less of exported symbol between compiling entities. Signed-off-by: Alexey Romanov Reviewed-by: Neil Armstrong --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 98 +++++++++++++++-- drivers/crypto/amlogic/amlogic-gxl-core.c | 110 ++++---------------- drivers/crypto/amlogic/amlogic-gxl.h | 14 +-- 3 files changed, 119 insertions(+), 103 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/a= mlogic/amlogic-gxl-cipher.c index dc0b100c5de2..bc3092a8a2c2 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -271,7 +271,7 @@ int meson_handle_cipher_request(struct crypto_engine *e= ngine, void *areq) return 0; } =20 -int meson_skdecrypt(struct skcipher_request *areq) +static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm =3D crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op =3D crypto_skcipher_ctx(tfm); @@ -289,7 +289,7 @@ int meson_skdecrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } =20 -int meson_skencrypt(struct skcipher_request *areq) +static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm =3D crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op =3D crypto_skcipher_ctx(tfm); @@ -307,7 +307,7 @@ int meson_skencrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } =20 -int meson_cipher_init(struct crypto_tfm *tfm) +static int meson_cipher_init(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op =3D crypto_tfm_ctx(tfm); struct meson_alg_template *algt; @@ -333,7 +333,7 @@ int meson_cipher_init(struct crypto_tfm *tfm) return 0; } =20 -void meson_cipher_exit(struct crypto_tfm *tfm) +static void meson_cipher_exit(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op =3D crypto_tfm_ctx(tfm); =20 @@ -341,8 +341,8 @@ void meson_cipher_exit(struct crypto_tfm *tfm) crypto_free_skcipher(op->fallback_tfm); } =20 -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen) +static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, + unsigned int keylen) { struct meson_cipher_tfm_ctx *op =3D crypto_skcipher_ctx(tfm); struct meson_dev *mc =3D op->mc; @@ -369,3 +369,89 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, cons= t u8 *key, =20 return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } + +static struct meson_alg_template algs[] =3D { +{ + .type =3D CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode =3D MESON_OPMODE_CBC, + .alg.skcipher.base =3D { + .base =3D { + .cra_name =3D "cbc(aes)", + .cra_driver_name =3D "cbc-aes-gxl", + .cra_priority =3D 400, + .cra_blocksize =3D AES_BLOCK_SIZE, + .cra_flags =3D CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize =3D sizeof(struct meson_cipher_tfm_ctx), + .cra_module =3D THIS_MODULE, + .cra_alignmask =3D 0xf, + .cra_init =3D meson_cipher_init, + .cra_exit =3D meson_cipher_exit, + }, + .min_keysize =3D AES_MIN_KEY_SIZE, + .max_keysize =3D AES_MAX_KEY_SIZE, + .ivsize =3D AES_BLOCK_SIZE, + .setkey =3D meson_aes_setkey, + .encrypt =3D meson_skencrypt, + .decrypt =3D meson_skdecrypt, + }, + .alg.skcipher.op =3D { + .do_one_request =3D meson_handle_cipher_request, + }, +}, +{ + .type =3D CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode =3D MESON_OPMODE_ECB, + .alg.skcipher.base =3D { + .base =3D { + .cra_name =3D "ecb(aes)", + .cra_driver_name =3D "ecb-aes-gxl", + .cra_priority =3D 400, + .cra_blocksize =3D AES_BLOCK_SIZE, + .cra_flags =3D CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize =3D sizeof(struct meson_cipher_tfm_ctx), + .cra_module =3D THIS_MODULE, + .cra_alignmask =3D 0xf, + .cra_init =3D meson_cipher_init, + .cra_exit =3D meson_cipher_exit, + }, + .min_keysize =3D AES_MIN_KEY_SIZE, + .max_keysize =3D AES_MAX_KEY_SIZE, + .setkey =3D meson_aes_setkey, + .encrypt =3D meson_skencrypt, + .decrypt =3D meson_skdecrypt, + }, + .alg.skcipher.op =3D { + .do_one_request =3D meson_handle_cipher_request, + }, +}, +}; + +int meson_cipher_register(struct meson_dev *mc) +{ + return meson_register_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_unregister(struct meson_dev *mc) +{ + meson_unregister_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_debugfs_show(struct seq_file *seq, void *v) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(algs); i++) { + seq_printf(seq, "%s %s %lu %lu\n", + algs[i].alg.skcipher.base.base.cra_driver_name, + algs[i].alg.skcipher.base.base.cra_name, +#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG + algs[i].stat_req, algs[i].stat_fb); +#else + 0ul, 0ul); +#endif + } +} diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/aml= ogic/amlogic-gxl-core.c index 9259ad0417d1..106d4ee2e5e9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -64,66 +64,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data) return IRQ_HANDLED; } =20 -static struct meson_alg_template mc_algs[] =3D { -{ - .type =3D CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode =3D MESON_OPMODE_CBC, - .alg.skcipher.base =3D { - .base =3D { - .cra_name =3D "cbc(aes)", - .cra_driver_name =3D "cbc-aes-gxl", - .cra_priority =3D 400, - .cra_blocksize =3D AES_BLOCK_SIZE, - .cra_flags =3D CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize =3D sizeof(struct meson_cipher_tfm_ctx), - .cra_module =3D THIS_MODULE, - .cra_alignmask =3D 0xf, - .cra_init =3D meson_cipher_init, - .cra_exit =3D meson_cipher_exit, - }, - .min_keysize =3D AES_MIN_KEY_SIZE, - .max_keysize =3D AES_MAX_KEY_SIZE, - .ivsize =3D AES_BLOCK_SIZE, - .setkey =3D meson_aes_setkey, - .encrypt =3D meson_skencrypt, - .decrypt =3D meson_skdecrypt, - }, - .alg.skcipher.op =3D { - .do_one_request =3D meson_handle_cipher_request, - }, -}, -{ - .type =3D CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode =3D MESON_OPMODE_ECB, - .alg.skcipher.base =3D { - .base =3D { - .cra_name =3D "ecb(aes)", - .cra_driver_name =3D "ecb-aes-gxl", - .cra_priority =3D 400, - .cra_blocksize =3D AES_BLOCK_SIZE, - .cra_flags =3D CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize =3D sizeof(struct meson_cipher_tfm_ctx), - .cra_module =3D THIS_MODULE, - .cra_alignmask =3D 0xf, - .cra_init =3D meson_cipher_init, - .cra_exit =3D meson_cipher_exit, - }, - .min_keysize =3D AES_MIN_KEY_SIZE, - .max_keysize =3D AES_MAX_KEY_SIZE, - .setkey =3D meson_aes_setkey, - .encrypt =3D meson_skencrypt, - .decrypt =3D meson_skdecrypt, - }, - .alg.skcipher.op =3D { - .do_one_request =3D meson_handle_cipher_request, - }, -}, -}; - static int meson_debugfs_show(struct seq_file *seq, void *v) { struct meson_dev *mc __maybe_unused =3D seq->private; @@ -137,20 +77,8 @@ static int meson_debugfs_show(struct seq_file *seq, voi= d *v) 0ul); #endif =20 - for (i =3D 0; i < ARRAY_SIZE(mc_algs); i++) { - switch (mc_algs[i].type) { - case CRYPTO_ALG_TYPE_SKCIPHER: - seq_printf(seq, "%s %s %lu %lu\n", - mc_algs[i].alg.skcipher.base.base.cra_driver_name, - mc_algs[i].alg.skcipher.base.base.cra_name, -#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG - mc_algs[i].stat_req, mc_algs[i].stat_fb); -#else - 0ul, 0ul); -#endif - break; - } - } + meson_cipher_debugfs_show(seq, v); + return 0; } DEFINE_SHOW_ATTRIBUTE(meson_debugfs); @@ -227,19 +155,20 @@ static int meson_allocate_chanlist(struct meson_dev *= mc) return err; } =20 -static int meson_register_algs(struct meson_dev *mc) +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *a= lgs, + unsigned int count) { int err, i; =20 - for (i =3D 0; i < ARRAY_SIZE(mc_algs); i++) { - mc_algs[i].mc =3D mc; - switch (mc_algs[i].type) { + for (i =3D 0; i < count; i++) { + algs[i].mc =3D mc; + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - err =3D crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher); + err =3D crypto_engine_register_skcipher(&algs[i].alg.skcipher); if (err) { dev_err(mc->dev, "Fail to register %s\n", - mc_algs[i].alg.skcipher.base.base.cra_name); - mc_algs[i].mc =3D NULL; + algs[i].alg.skcipher.base.base.cra_name); + meson_unregister_algs(mc, algs, count); return err; } break; @@ -249,16 +178,17 @@ static int meson_register_algs(struct meson_dev *mc) return 0; } =20 -static void meson_unregister_algs(struct meson_dev *mc) +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template= *algs, + unsigned int count) { int i; =20 - for (i =3D 0; i < ARRAY_SIZE(mc_algs); i++) { - if (!mc_algs[i].mc) + for (i =3D 0; i < count; i++) { + if (!algs[i].mc) continue; - switch (mc_algs[i].type) { + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher); + crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; } } @@ -288,9 +218,9 @@ static int meson_crypto_probe(struct platform_device *p= dev) if (err) goto error_flow; =20 - err =3D meson_register_algs(mc); + err =3D meson_cipher_register(mc); if (err) - goto error_alg; + goto error_flow; =20 if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { struct dentry *dbgfs_dir; @@ -304,8 +234,6 @@ static int meson_crypto_probe(struct platform_device *p= dev) } =20 return 0; -error_alg: - meson_unregister_algs(mc); error_flow: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; @@ -319,7 +247,7 @@ static void meson_crypto_remove(struct platform_device = *pdev) debugfs_remove_recursive(mc->dbgfs_dir); #endif =20 - meson_unregister_algs(mc); + meson_cipher_unregister(mc); =20 meson_free_chanlist(mc, mc->flow_cnt - 1); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/= amlogic-gxl.h index 0dde7662ae37..f0ccd28545aa 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -163,10 +163,12 @@ int meson_get_engine_number(struct meson_dev *mc); =20 void meson_dma_start(struct meson_dev *mc, int flow); =20 -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen); -int meson_cipher_init(struct crypto_tfm *tfm); -void meson_cipher_exit(struct crypto_tfm *tfm); -int meson_skdecrypt(struct skcipher_request *areq); -int meson_skencrypt(struct skcipher_request *areq); +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *a= lgs, + unsigned int count); +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template= *algs, + unsigned int count); + +int meson_cipher_register(struct meson_dev *mc); +void meson_cipher_unregister(struct meson_dev *mc); +void meson_cipher_debugfs_show(struct seq_file *seq, void *v); int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); --=20 2.34.1