2022-09-20 08:04:51

by Peter Harliman Liem

[permalink] [raw]
Subject: [PATCH 1/3] crypto: inside-secure - Expand soc data structure

Currently platform data is assigned directly to
version string(instead of struct). To make it more
scalable, we move it to use data struct instead.
This allows customization for individual platforms other
than version string.

Signed-off-by: Peter Harliman Liem <[email protected]>
---
drivers/crypto/inside-secure/safexcel.c | 49 +++++++++++++++++--------
drivers/crypto/inside-secure/safexcel.h | 6 ++-
2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/inside-secure/safexcel.c b/drivers/crypto/inside-secure/safexcel.c
index ad0d8c4a71ac..02c103da09a9 100644
--- a/drivers/crypto/inside-secure/safexcel.c
+++ b/drivers/crypto/inside-secure/safexcel.c
@@ -410,20 +410,25 @@ static int eip197_load_firmwares(struct safexcel_crypto_priv *priv)
int i, j, ret = 0, pe;
int ipuesz, ifppsz, minifw = 0;

- if (priv->version == EIP197D_MRVL)
- dir = "eip197d";
- else if (priv->version == EIP197B_MRVL ||
- priv->version == EIP197_DEVBRD)
+ switch (priv->data->version) {
+ case EIP197_DEVBRD:
+ case EIP197B_MRVL:
dir = "eip197b";
- else
- return -ENODEV;
+ break;
+ case EIP197D_MRVL:
+ dir = "eip197d";
+ break;
+ default:
+ /* generic case */
+ dir = "";
+ }

retry_fw:
for (i = 0; i < FW_NB; i++) {
snprintf(fw_path, 37, "inside-secure/%s/%s", dir, fw_name[i]);
ret = firmware_request_nowarn(&fw[i], fw_path, priv->dev);
if (ret) {
- if (minifw || priv->version != EIP197B_MRVL)
+ if (minifw || priv->data->version != EIP197B_MRVL)
goto release_fw;

/* Fallback to the old firmware location for the
@@ -1597,7 +1602,7 @@ static int safexcel_probe_generic(void *pdev,

safexcel_configure(priv);

- if (IS_ENABLED(CONFIG_PCI) && priv->version == EIP197_DEVBRD) {
+ if (IS_ENABLED(CONFIG_PCI) && priv->data->version == EIP197_DEVBRD) {
/*
* Request MSI vectors for global + 1 per ring -
* or just 1 for older dev images
@@ -1731,7 +1736,7 @@ static int safexcel_probe(struct platform_device *pdev)
return -ENOMEM;

priv->dev = dev;
- priv->version = (enum safexcel_eip_version)of_device_get_match_data(dev);
+ priv->data = (struct safexcel_of_data *)of_device_get_match_data(dev);

platform_set_drvdata(pdev, priv);

@@ -1806,27 +1811,39 @@ static int safexcel_remove(struct platform_device *pdev)
return 0;
}

+static const struct safexcel_of_data eip97ies_mrvl_data = {
+ .version = EIP97IES_MRVL,
+};
+
+static const struct safexcel_of_data eip197b_mrvl_data = {
+ .version = EIP197B_MRVL,
+};
+
+static const struct safexcel_of_data eip197d_mrvl_data = {
+ .version = EIP197D_MRVL,
+};
+
static const struct of_device_id safexcel_of_match_table[] = {
{
.compatible = "inside-secure,safexcel-eip97ies",
- .data = (void *)EIP97IES_MRVL,
+ .data = &eip97ies_mrvl_data,
},
{
.compatible = "inside-secure,safexcel-eip197b",
- .data = (void *)EIP197B_MRVL,
+ .data = &eip197b_mrvl_data,
},
{
.compatible = "inside-secure,safexcel-eip197d",
- .data = (void *)EIP197D_MRVL,
+ .data = &eip197d_mrvl_data,
},
/* For backward compatibility and intended for generic use */
{
.compatible = "inside-secure,safexcel-eip97",
- .data = (void *)EIP97IES_MRVL,
+ .data = &eip97ies_mrvl_data,
},
{
.compatible = "inside-secure,safexcel-eip197",
- .data = (void *)EIP197B_MRVL,
+ .data = &eip197b_mrvl_data,
},
{},
};
@@ -1862,7 +1879,7 @@ static int safexcel_pci_probe(struct pci_dev *pdev,
return -ENOMEM;

priv->dev = dev;
- priv->version = (enum safexcel_eip_version)ent->driver_data;
+ priv->data = (struct safexcel_of_data *)ent->driver_data;

pci_set_drvdata(pdev, priv);

@@ -1881,7 +1898,7 @@ static int safexcel_pci_probe(struct pci_dev *pdev,
}
priv->base = pcim_iomap_table(pdev)[0];

- if (priv->version == EIP197_DEVBRD) {
+ if (priv->data->version == EIP197_DEVBRD) {
dev_dbg(dev, "Device identified as FPGA based development board - applying HW reset\n");

rc = pcim_iomap_regions(pdev, 4, "crypto_safexcel");
diff --git a/drivers/crypto/inside-secure/safexcel.h b/drivers/crypto/inside-secure/safexcel.h
index 797ff91512e0..1b8ccb33202b 100644
--- a/drivers/crypto/inside-secure/safexcel.h
+++ b/drivers/crypto/inside-secure/safexcel.h
@@ -733,6 +733,10 @@ enum safexcel_eip_version {
EIP197_DEVBRD
};

+struct safexcel_of_data {
+ enum safexcel_eip_version version;
+};
+
/* Priority we use for advertising our algorithms */
#define SAFEXCEL_CRA_PRIORITY 300

@@ -815,7 +819,7 @@ struct safexcel_crypto_priv {
struct clk *reg_clk;
struct safexcel_config config;

- enum safexcel_eip_version version;
+ struct safexcel_of_data *data;
struct safexcel_register_offsets offsets;
struct safexcel_hwconfig hwconfig;
u32 flags;
--
2.17.1


2022-09-23 09:18:45

by Antoine Tenart

[permalink] [raw]
Subject: Re: [PATCH 1/3] crypto: inside-secure - Expand soc data structure

Quoting Peter Harliman Liem (2022-09-20 10:01:37)
> @@ -410,20 +410,25 @@ static int eip197_load_firmwares(struct safexcel_crypto_priv *priv)
> int i, j, ret = 0, pe;
> int ipuesz, ifppsz, minifw = 0;
>
> - if (priv->version == EIP197D_MRVL)
> - dir = "eip197d";
> - else if (priv->version == EIP197B_MRVL ||
> - priv->version == EIP197_DEVBRD)
> + switch (priv->data->version) {
> + case EIP197_DEVBRD:
> + case EIP197B_MRVL:
> dir = "eip197b";
> - else
> - return -ENODEV;
> + break;
> + case EIP197D_MRVL:
> + dir = "eip197d";
> + break;
> + default:
> + /* generic case */
> + dir = "";
> + }

Why "generic case"? We shouldn't end up in this case and the logic
changed after this patch: an error was returned before.

The if vs switch is mostly a question of taste here, I don't have
anything against it but it's also not necessary as we're not supporting
lots of versions. So you could keep it as-is and keep the patch
restricted to its topic.

> +static const struct safexcel_of_data eip97ies_mrvl_data = {
> + .version = EIP97IES_MRVL,
> +};
> +
> +static const struct safexcel_of_data eip197b_mrvl_data = {
> + .version = EIP197B_MRVL,
> +};
> +
> +static const struct safexcel_of_data eip197d_mrvl_data = {
> + .version = EIP197D_MRVL,
> +};
> +
> static const struct of_device_id safexcel_of_match_table[] = {
> {
> .compatible = "inside-secure,safexcel-eip97ies",
> - .data = (void *)EIP97IES_MRVL,
> + .data = &eip97ies_mrvl_data,
> },
> {
> .compatible = "inside-secure,safexcel-eip197b",
> - .data = (void *)EIP197B_MRVL,
> + .data = &eip197b_mrvl_data,
> },
> {
> .compatible = "inside-secure,safexcel-eip197d",
> - .data = (void *)EIP197D_MRVL,
> + .data = &eip197d_mrvl_data,
> },
> /* For backward compatibility and intended for generic use */
> {
> .compatible = "inside-secure,safexcel-eip97",
> - .data = (void *)EIP97IES_MRVL,
> + .data = &eip97ies_mrvl_data,
> },
> {
> .compatible = "inside-secure,safexcel-eip197",
> - .data = (void *)EIP197B_MRVL,
> + .data = &eip197b_mrvl_data,
> },
> {},
> };

The pci_device_id counterpart update is missing.

> +++ b/drivers/crypto/inside-secure/safexcel.h
> @@ -733,6 +733,10 @@ enum safexcel_eip_version {
> EIP197_DEVBRD
> };
>
> +struct safexcel_of_data {
> + enum safexcel_eip_version version;
> +};

The driver supports both of and PCI ids, you can rename this to
safexcel_priv_data.

Thanks!
Antoine

2022-09-27 03:25:35

by Peter Harliman Liem

[permalink] [raw]
Subject: Re: [PATCH 1/3] crypto: inside-secure - Expand soc data structure

On 23/9/2022 5:09 pm, Antoine Tenart wrote:
> Quoting Peter Harliman Liem (2022-09-20 10:01:37)
>> + default:
>> + /* generic case */
>> + dir = "";
>> + }
>
> Why "generic case"? We shouldn't end up in this case and the logic
> changed after this patch: an error was returned before.
>
> The if vs switch is mostly a question of taste here, I don't have
> anything against it but it's also not necessary as we're not supporting
> lots of versions. So you could keep it as-is and keep the patch
> restricted to its topic.

This change has been removed in v2.

>> {
>> .compatible = "inside-secure,safexcel-eip197",
>> - .data = (void *)EIP197B_MRVL,
>> + .data = &eip197b_mrvl_data,
>> },
>> {},
>> };
>
> The pci_device_id counterpart update is missing.

I missed that. Thanks for catching.
Updated in v2.

>> +struct safexcel_of_data {
>> + enum safexcel_eip_version version;
>> +};
>
> The driver supports both of and PCI ids, you can rename this to
> safexcel_priv_data.

Updated in v2.

Thanks!

-Peter-