linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: cavium: zip: register algorithm only if hardware is present
@ 2022-02-21 11:52 Corentin Labbe
  2022-02-25 13:25 ` Jan Glauber
  2022-03-02 22:58 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Corentin Labbe @ 2022-02-21 11:52 UTC (permalink / raw)
  To: davem, herbert, jglauber; +Cc: linux-crypto, linux-kernel, Corentin Labbe

On my renesas salavator-X, I saw some cavium driver failing crypto
self-tests.
But salvator does not have such hardware.
This is due to cavium/zip driver registering algorithms even if hardware
is not present.
The solution is to move algorithm registration in the probe function.
This permits also to simplify module init/exit by using
module_pci_driver.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---

WARNING: this is boot tested only on salvator-X to be sure that the
cavium/zip driver no longer registers algorithms.
I do not have any cavium hardware unfortunatly.

 drivers/crypto/cavium/zip/zip_main.c | 83 ++++++++++++----------------
 1 file changed, 35 insertions(+), 48 deletions(-)

diff --git a/drivers/crypto/cavium/zip/zip_main.c b/drivers/crypto/cavium/zip/zip_main.c
index 812b4ac9afd6..dc5b7bf7e1fd 100644
--- a/drivers/crypto/cavium/zip/zip_main.c
+++ b/drivers/crypto/cavium/zip/zip_main.c
@@ -55,6 +55,11 @@ static const struct pci_device_id zip_id_table[] = {
 	{ 0, }
 };
 
+static void zip_debugfs_init(void);
+static void zip_debugfs_exit(void);
+static int zip_register_compression_device(void);
+static void zip_unregister_compression_device(void);
+
 void zip_reg_write(u64 val, u64 __iomem *addr)
 {
 	writeq(val, addr);
@@ -235,6 +240,15 @@ static int zip_init_hw(struct zip_device *zip)
 	return 0;
 }
 
+static void zip_reset(struct zip_device *zip)
+{
+	union zip_cmd_ctl cmd_ctl;
+
+	cmd_ctl.u_reg64 = 0x0ull;
+	cmd_ctl.s.reset = 1;  /* Forces ZIP cores to do reset */
+	zip_reg_write(cmd_ctl.u_reg64, (zip->reg_base + ZIP_CMD_CTL));
+}
+
 static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct device *dev = &pdev->dev;
@@ -282,8 +296,21 @@ static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (err)
 		goto err_release_regions;
 
+	/* Register with the Kernel Crypto Interface */
+	err = zip_register_compression_device();
+	if (err < 0) {
+		zip_err("ZIP: Kernel Crypto Registration failed\n");
+		goto err_register;
+	}
+
+	/* comp-decomp statistics are handled with debugfs interface */
+	zip_debugfs_init();
+
 	return 0;
 
+err_register:
+	zip_reset(zip);
+
 err_release_regions:
 	if (zip->reg_base)
 		iounmap(zip->reg_base);
@@ -305,16 +332,17 @@ static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 static void zip_remove(struct pci_dev *pdev)
 {
 	struct zip_device *zip = pci_get_drvdata(pdev);
-	union zip_cmd_ctl cmd_ctl;
 	int q = 0;
 
 	if (!zip)
 		return;
 
+	zip_debugfs_exit();
+
+	zip_unregister_compression_device();
+
 	if (zip->reg_base) {
-		cmd_ctl.u_reg64 = 0x0ull;
-		cmd_ctl.s.reset = 1;  /* Forces ZIP cores to do reset */
-		zip_reg_write(cmd_ctl.u_reg64, (zip->reg_base + ZIP_CMD_CTL));
+		zip_reset(zip);
 		iounmap(zip->reg_base);
 	}
 
@@ -585,7 +613,7 @@ DEFINE_SHOW_ATTRIBUTE(zip_regs);
 /* Root directory for thunderx_zip debugfs entry */
 static struct dentry *zip_debugfs_root;
 
-static void __init zip_debugfs_init(void)
+static void zip_debugfs_init(void)
 {
 	if (!debugfs_initialized())
 		return;
@@ -604,7 +632,7 @@ static void __init zip_debugfs_init(void)
 
 }
 
-static void __exit zip_debugfs_exit(void)
+static void zip_debugfs_exit(void)
 {
 	debugfs_remove_recursive(zip_debugfs_root);
 }
@@ -615,48 +643,7 @@ static void __exit zip_debugfs_exit(void) { }
 #endif
 /* debugfs - end */
 
-static int __init zip_init_module(void)
-{
-	int ret;
-
-	zip_msg("%s\n", DRV_NAME);
-
-	ret = pci_register_driver(&zip_driver);
-	if (ret < 0) {
-		zip_err("ZIP: pci_register_driver() failed\n");
-		return ret;
-	}
-
-	/* Register with the Kernel Crypto Interface */
-	ret = zip_register_compression_device();
-	if (ret < 0) {
-		zip_err("ZIP: Kernel Crypto Registration failed\n");
-		goto err_pci_unregister;
-	}
-
-	/* comp-decomp statistics are handled with debugfs interface */
-	zip_debugfs_init();
-
-	return ret;
-
-err_pci_unregister:
-	pci_unregister_driver(&zip_driver);
-	return ret;
-}
-
-static void __exit zip_cleanup_module(void)
-{
-	zip_debugfs_exit();
-
-	/* Unregister from the kernel crypto interface */
-	zip_unregister_compression_device();
-
-	/* Unregister this driver for pci zip devices */
-	pci_unregister_driver(&zip_driver);
-}
-
-module_init(zip_init_module);
-module_exit(zip_cleanup_module);
+module_pci_driver(zip_driver);
 
 MODULE_AUTHOR("Cavium Inc");
 MODULE_DESCRIPTION("Cavium Inc ThunderX ZIP Driver");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: cavium: zip: register algorithm only if hardware is present
  2022-02-21 11:52 [PATCH] crypto: cavium: zip: register algorithm only if hardware is present Corentin Labbe
@ 2022-02-25 13:25 ` Jan Glauber
  2022-03-02 22:58 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Glauber @ 2022-02-25 13:25 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: David S . Miller, Herbert Xu, Jan Glauber, linux-crypto, linux-kernel

Hi Corentin,
your patch looks good to me, but I also lost access to the hardware.

-- Jan

Am Di., 22. Feb. 2022 um 05:34 Uhr schrieb Corentin Labbe <clabbe@baylibre.com>:
>
> On my renesas salavator-X, I saw some cavium driver failing crypto
> self-tests.
> But salvator does not have such hardware.
> This is due to cavium/zip driver registering algorithms even if hardware
> is not present.
> The solution is to move algorithm registration in the probe function.
> This permits also to simplify module init/exit by using
> module_pci_driver.
>
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
>
> WARNING: this is boot tested only on salvator-X to be sure that the
> cavium/zip driver no longer registers algorithms.
> I do not have any cavium hardware unfortunatly.
>
>  drivers/crypto/cavium/zip/zip_main.c | 83 ++++++++++++----------------
>  1 file changed, 35 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/crypto/cavium/zip/zip_main.c b/drivers/crypto/cavium/zip/zip_main.c
> index 812b4ac9afd6..dc5b7bf7e1fd 100644
> --- a/drivers/crypto/cavium/zip/zip_main.c
> +++ b/drivers/crypto/cavium/zip/zip_main.c
> @@ -55,6 +55,11 @@ static const struct pci_device_id zip_id_table[] = {
>         { 0, }
>  };
>
> +static void zip_debugfs_init(void);
> +static void zip_debugfs_exit(void);
> +static int zip_register_compression_device(void);
> +static void zip_unregister_compression_device(void);
> +
>  void zip_reg_write(u64 val, u64 __iomem *addr)
>  {
>         writeq(val, addr);
> @@ -235,6 +240,15 @@ static int zip_init_hw(struct zip_device *zip)
>         return 0;
>  }
>
> +static void zip_reset(struct zip_device *zip)
> +{
> +       union zip_cmd_ctl cmd_ctl;
> +
> +       cmd_ctl.u_reg64 = 0x0ull;
> +       cmd_ctl.s.reset = 1;  /* Forces ZIP cores to do reset */
> +       zip_reg_write(cmd_ctl.u_reg64, (zip->reg_base + ZIP_CMD_CTL));
> +}
> +
>  static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  {
>         struct device *dev = &pdev->dev;
> @@ -282,8 +296,21 @@ static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>         if (err)
>                 goto err_release_regions;
>
> +       /* Register with the Kernel Crypto Interface */
> +       err = zip_register_compression_device();
> +       if (err < 0) {
> +               zip_err("ZIP: Kernel Crypto Registration failed\n");
> +               goto err_register;
> +       }
> +
> +       /* comp-decomp statistics are handled with debugfs interface */
> +       zip_debugfs_init();
> +
>         return 0;
>
> +err_register:
> +       zip_reset(zip);
> +
>  err_release_regions:
>         if (zip->reg_base)
>                 iounmap(zip->reg_base);
> @@ -305,16 +332,17 @@ static int zip_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  static void zip_remove(struct pci_dev *pdev)
>  {
>         struct zip_device *zip = pci_get_drvdata(pdev);
> -       union zip_cmd_ctl cmd_ctl;
>         int q = 0;
>
>         if (!zip)
>                 return;
>
> +       zip_debugfs_exit();
> +
> +       zip_unregister_compression_device();
> +
>         if (zip->reg_base) {
> -               cmd_ctl.u_reg64 = 0x0ull;
> -               cmd_ctl.s.reset = 1;  /* Forces ZIP cores to do reset */
> -               zip_reg_write(cmd_ctl.u_reg64, (zip->reg_base + ZIP_CMD_CTL));
> +               zip_reset(zip);
>                 iounmap(zip->reg_base);
>         }
>
> @@ -585,7 +613,7 @@ DEFINE_SHOW_ATTRIBUTE(zip_regs);
>  /* Root directory for thunderx_zip debugfs entry */
>  static struct dentry *zip_debugfs_root;
>
> -static void __init zip_debugfs_init(void)
> +static void zip_debugfs_init(void)
>  {
>         if (!debugfs_initialized())
>                 return;
> @@ -604,7 +632,7 @@ static void __init zip_debugfs_init(void)
>
>  }
>
> -static void __exit zip_debugfs_exit(void)
> +static void zip_debugfs_exit(void)
>  {
>         debugfs_remove_recursive(zip_debugfs_root);
>  }
> @@ -615,48 +643,7 @@ static void __exit zip_debugfs_exit(void) { }
>  #endif
>  /* debugfs - end */
>
> -static int __init zip_init_module(void)
> -{
> -       int ret;
> -
> -       zip_msg("%s\n", DRV_NAME);
> -
> -       ret = pci_register_driver(&zip_driver);
> -       if (ret < 0) {
> -               zip_err("ZIP: pci_register_driver() failed\n");
> -               return ret;
> -       }
> -
> -       /* Register with the Kernel Crypto Interface */
> -       ret = zip_register_compression_device();
> -       if (ret < 0) {
> -               zip_err("ZIP: Kernel Crypto Registration failed\n");
> -               goto err_pci_unregister;
> -       }
> -
> -       /* comp-decomp statistics are handled with debugfs interface */
> -       zip_debugfs_init();
> -
> -       return ret;
> -
> -err_pci_unregister:
> -       pci_unregister_driver(&zip_driver);
> -       return ret;
> -}
> -
> -static void __exit zip_cleanup_module(void)
> -{
> -       zip_debugfs_exit();
> -
> -       /* Unregister from the kernel crypto interface */
> -       zip_unregister_compression_device();
> -
> -       /* Unregister this driver for pci zip devices */
> -       pci_unregister_driver(&zip_driver);
> -}
> -
> -module_init(zip_init_module);
> -module_exit(zip_cleanup_module);
> +module_pci_driver(zip_driver);
>
>  MODULE_AUTHOR("Cavium Inc");
>  MODULE_DESCRIPTION("Cavium Inc ThunderX ZIP Driver");
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: cavium: zip: register algorithm only if hardware is present
  2022-02-21 11:52 [PATCH] crypto: cavium: zip: register algorithm only if hardware is present Corentin Labbe
  2022-02-25 13:25 ` Jan Glauber
@ 2022-03-02 22:58 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2022-03-02 22:58 UTC (permalink / raw)
  To: Corentin Labbe; +Cc: davem, jglauber, linux-crypto, linux-kernel

On Mon, Feb 21, 2022 at 11:52:34AM +0000, Corentin Labbe wrote:
> On my renesas salavator-X, I saw some cavium driver failing crypto
> self-tests.
> But salvator does not have such hardware.
> This is due to cavium/zip driver registering algorithms even if hardware
> is not present.
> The solution is to move algorithm registration in the probe function.
> This permits also to simplify module init/exit by using
> module_pci_driver.
> 
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
> 
> WARNING: this is boot tested only on salvator-X to be sure that the
> cavium/zip driver no longer registers algorithms.
> I do not have any cavium hardware unfortunatly.
> 
>  drivers/crypto/cavium/zip/zip_main.c | 83 ++++++++++++----------------
>  1 file changed, 35 insertions(+), 48 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-03  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 11:52 [PATCH] crypto: cavium: zip: register algorithm only if hardware is present Corentin Labbe
2022-02-25 13:25 ` Jan Glauber
2022-03-02 22:58 ` Herbert Xu

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).