crypto: qat - consolidate services structure
authorGiovanni Cabiddu <giovanni.cabiddu@intel.com>
Thu, 14 Sep 2023 14:14:12 +0000 (15:14 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:59:23 +0000 (11:59 +0100)
[ Upstream commit 71713766380712c8ab2d604605e7b0b20f977801 ]

The data structure that associates a service id with its name is
replicated across the driver.
Remove duplication by moving this data structure to a new include file,
adf_cfg_services.h in order to have consistency across the drivers.

Note that the data structure is re-instantiated every time the new
include is added to a compilation unit.

Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: a238487f7965 ("crypto: qat - fix ring to service map for QAT GEN4")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/intel/qat/qat_4xxx/adf_4xxx_hw_data.c
drivers/crypto/intel/qat/qat_4xxx/adf_drv.c
drivers/crypto/intel/qat/qat_common/adf_cfg_services.h [new file with mode: 0644]
drivers/crypto/intel/qat/qat_common/adf_sysfs.c

index dd4464b7e00b18763f02b06ea90560a447fb739d..cc2285b9f17b4ae313511d743a728c9b00f3c363 100644 (file)
@@ -11,6 +11,7 @@
 #include <adf_gen4_pm.h>
 #include <adf_gen4_timer.h>
 #include "adf_4xxx_hw_data.h"
+#include "adf_cfg_services.h"
 #include "icp_qat_hw.h"
 
 enum adf_fw_objs {
@@ -100,30 +101,6 @@ static struct adf_hw_device_class adf_4xxx_class = {
        .instances = 0,
 };
 
-enum dev_services {
-       SVC_CY = 0,
-       SVC_CY2,
-       SVC_DC,
-       SVC_SYM,
-       SVC_ASYM,
-       SVC_DC_ASYM,
-       SVC_ASYM_DC,
-       SVC_DC_SYM,
-       SVC_SYM_DC,
-};
-
-static const char *const dev_cfg_services[] = {
-       [SVC_CY] = ADF_CFG_CY,
-       [SVC_CY2] = ADF_CFG_ASYM_SYM,
-       [SVC_DC] = ADF_CFG_DC,
-       [SVC_SYM] = ADF_CFG_SYM,
-       [SVC_ASYM] = ADF_CFG_ASYM,
-       [SVC_DC_ASYM] = ADF_CFG_DC_ASYM,
-       [SVC_ASYM_DC] = ADF_CFG_ASYM_DC,
-       [SVC_DC_SYM] = ADF_CFG_DC_SYM,
-       [SVC_SYM_DC] = ADF_CFG_SYM_DC,
-};
-
 static int get_service_enabled(struct adf_accel_dev *accel_dev)
 {
        char services[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0};
@@ -137,7 +114,7 @@ static int get_service_enabled(struct adf_accel_dev *accel_dev)
                return ret;
        }
 
-       ret = match_string(dev_cfg_services, ARRAY_SIZE(dev_cfg_services),
+       ret = match_string(adf_cfg_services, ARRAY_SIZE(adf_cfg_services),
                           services);
        if (ret < 0)
                dev_err(&GET_DEV(accel_dev),
index 6d4e2e139ffa24575198ec564fe6671aa8ab907d..204a00a204f2dd480020cd9494819e2301fdc6b1 100644 (file)
@@ -11,6 +11,7 @@
 #include <adf_heartbeat.h>
 
 #include "adf_4xxx_hw_data.h"
+#include "adf_cfg_services.h"
 #include "qat_compression.h"
 #include "qat_crypto.h"
 #include "adf_transport_access_macros.h"
@@ -23,30 +24,6 @@ static const struct pci_device_id adf_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, adf_pci_tbl);
 
-enum configs {
-       DEV_CFG_CY = 0,
-       DEV_CFG_DC,
-       DEV_CFG_SYM,
-       DEV_CFG_ASYM,
-       DEV_CFG_ASYM_SYM,
-       DEV_CFG_ASYM_DC,
-       DEV_CFG_DC_ASYM,
-       DEV_CFG_SYM_DC,
-       DEV_CFG_DC_SYM,
-};
-
-static const char * const services_operations[] = {
-       ADF_CFG_CY,
-       ADF_CFG_DC,
-       ADF_CFG_SYM,
-       ADF_CFG_ASYM,
-       ADF_CFG_ASYM_SYM,
-       ADF_CFG_ASYM_DC,
-       ADF_CFG_DC_ASYM,
-       ADF_CFG_SYM_DC,
-       ADF_CFG_DC_SYM,
-};
-
 static void adf_cleanup_accel(struct adf_accel_dev *accel_dev)
 {
        if (accel_dev->hw_device) {
@@ -292,16 +269,16 @@ int adf_gen4_dev_config(struct adf_accel_dev *accel_dev)
        if (ret)
                goto err;
 
-       ret = sysfs_match_string(services_operations, services);
+       ret = sysfs_match_string(adf_cfg_services, services);
        if (ret < 0)
                goto err;
 
        switch (ret) {
-       case DEV_CFG_CY:
-       case DEV_CFG_ASYM_SYM:
+       case SVC_CY:
+       case SVC_CY2:
                ret = adf_crypto_dev_config(accel_dev);
                break;
-       case DEV_CFG_DC:
+       case SVC_DC:
                ret = adf_comp_dev_config(accel_dev);
                break;
        default:
diff --git a/drivers/crypto/intel/qat/qat_common/adf_cfg_services.h b/drivers/crypto/intel/qat/qat_common/adf_cfg_services.h
new file mode 100644 (file)
index 0000000..7fcb3b8
--- /dev/null
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2023 Intel Corporation */
+#ifndef _ADF_CFG_SERVICES_H_
+#define _ADF_CFG_SERVICES_H_
+
+#include "adf_cfg_strings.h"
+
+enum adf_services {
+       SVC_CY = 0,
+       SVC_CY2,
+       SVC_DC,
+       SVC_SYM,
+       SVC_ASYM,
+       SVC_DC_ASYM,
+       SVC_ASYM_DC,
+       SVC_DC_SYM,
+       SVC_SYM_DC,
+};
+
+static const char *const adf_cfg_services[] = {
+       [SVC_CY] = ADF_CFG_CY,
+       [SVC_CY2] = ADF_CFG_ASYM_SYM,
+       [SVC_DC] = ADF_CFG_DC,
+       [SVC_SYM] = ADF_CFG_SYM,
+       [SVC_ASYM] = ADF_CFG_ASYM,
+       [SVC_DC_ASYM] = ADF_CFG_DC_ASYM,
+       [SVC_ASYM_DC] = ADF_CFG_ASYM_DC,
+       [SVC_DC_SYM] = ADF_CFG_DC_SYM,
+       [SVC_SYM_DC] = ADF_CFG_SYM_DC,
+};
+
+#endif
index 8880af1aa1b5bfc76595253bfcd88e82b1232b60..8f04b0d3c5ac890a987d854bb8af8caf1eedc8b4 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/pci.h>
 #include "adf_accel_devices.h"
 #include "adf_cfg.h"
+#include "adf_cfg_services.h"
 #include "adf_common_drv.h"
 
 static const char * const state_operations[] = {
@@ -84,18 +85,6 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-static const char * const services_operations[] = {
-       ADF_CFG_CY,
-       ADF_CFG_DC,
-       ADF_CFG_SYM,
-       ADF_CFG_ASYM,
-       ADF_CFG_ASYM_SYM,
-       ADF_CFG_ASYM_DC,
-       ADF_CFG_DC_ASYM,
-       ADF_CFG_SYM_DC,
-       ADF_CFG_DC_SYM,
-};
-
 static ssize_t cfg_services_show(struct device *dev, struct device_attribute *attr,
                                 char *buf)
 {
@@ -130,7 +119,7 @@ static ssize_t cfg_services_store(struct device *dev, struct device_attribute *a
        struct adf_accel_dev *accel_dev;
        int ret;
 
-       ret = sysfs_match_string(services_operations, buf);
+       ret = sysfs_match_string(adf_cfg_services, buf);
        if (ret < 0)
                return ret;
 
@@ -144,7 +133,7 @@ static ssize_t cfg_services_store(struct device *dev, struct device_attribute *a
                return -EINVAL;
        }
 
-       ret = adf_sysfs_update_dev_config(accel_dev, services_operations[ret]);
+       ret = adf_sysfs_update_dev_config(accel_dev, adf_cfg_services[ret]);
        if (ret < 0)
                return ret;