crypto: qat - preserve ADF_GENERAL_SEC
authorAdam Guerin <adam.guerin@intel.com>
Wed, 17 Jul 2024 11:44:56 +0000 (07:44 -0400)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Aug 2024 13:11:20 +0000 (21:11 +0800)
The ADF_GENERAL_SEC configuration section contains values that must be
preserved during state transitions (down -> up, up -> down).
This patch modifies the logic in adf_dev_shutdown() to maintain all
key values within this section, rather than selectively saving and
restoring only the ADF_SERVICES_ENABLED attribute.

To achieve this, a new function has been introduced that deletes all
configuration sections except for the one specified by name.
This function is invoked during adf_dev_down(), with ADF_GENERAL_SEC
as the argument. Consequently, the adf_dev_shutdown_cache_cfg() function
has been removed as it is now redundant.

Additionally, this patch eliminates the cache_config parameter from
the adf_dev_down() function since ADF_GENERAL_SEC should always be
retained. This change does not cause any side effects because all
entries in the key-value store are cleared when a module is unloaded.

Signed-off-by: Adam Guerin <adam.guerin@intel.com>
Co-developed-by: Michal Witwicki <michal.witwicki@intel.com>
Signed-off-by: Michal Witwicki <michal.witwicki@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
17 files changed:
drivers/crypto/intel/qat/qat_420xx/adf_drv.c
drivers/crypto/intel/qat/qat_4xxx/adf_drv.c
drivers/crypto/intel/qat/qat_c3xxx/adf_drv.c
drivers/crypto/intel/qat/qat_c3xxxvf/adf_drv.c
drivers/crypto/intel/qat/qat_c62x/adf_drv.c
drivers/crypto/intel/qat/qat_c62xvf/adf_drv.c
drivers/crypto/intel/qat/qat_common/adf_aer.c
drivers/crypto/intel/qat/qat_common/adf_cfg.c
drivers/crypto/intel/qat/qat_common/adf_cfg.h
drivers/crypto/intel/qat/qat_common/adf_common_drv.h
drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c
drivers/crypto/intel/qat/qat_common/adf_init.c
drivers/crypto/intel/qat/qat_common/adf_sriov.c
drivers/crypto/intel/qat/qat_common/adf_sysfs.c
drivers/crypto/intel/qat/qat_common/adf_vf_isr.c
drivers/crypto/intel/qat/qat_dh895xcc/adf_drv.c
drivers/crypto/intel/qat/qat_dh895xccvf/adf_drv.c

index 2a35984..f49818a 100644 (file)
@@ -163,7 +163,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err:
        adf_cleanup_accel(accel_dev);
        return ret;
@@ -177,7 +177,7 @@ static void adf_remove(struct pci_dev *pdev)
                pr_err("QAT: Driver removal failed\n");
                return;
        }
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
 }
 
index d26564c..659905e 100644 (file)
@@ -165,7 +165,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err:
        adf_cleanup_accel(accel_dev);
        return ret;
@@ -179,7 +179,7 @@ static void adf_remove(struct pci_dev *pdev)
                pr_err("QAT: Driver removal failed\n");
                return;
        }
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
 }
 
index 956a4c8..4d18057 100644 (file)
@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
                pr_err("QAT: Driver removal failed\n");
                return;
        }
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);
index a8de9cd..f0023cf 100644 (file)
@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
                return;
        }
        adf_flush_vf_wq(accel_dev);
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);
index ad0ca43..e6b5de5 100644 (file)
@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
                pr_err("QAT: Driver removal failed\n");
                return;
        }
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);
index 53b8ddb..2bd5b0f 100644 (file)
@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
                return;
        }
        adf_flush_vf_wq(accel_dev);
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);
index 04260f6..ec7913a 100644 (file)
@@ -44,7 +44,7 @@ static pci_ers_result_t adf_error_detected(struct pci_dev *pdev,
        adf_pf2vf_notify_restarting(accel_dev);
        adf_pf2vf_wait_for_restarting_complete(accel_dev);
        pci_clear_master(pdev);
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 
        return PCI_ERS_RESULT_NEED_RESET;
 }
index 2cf102a..b0fc453 100644 (file)
@@ -100,6 +100,8 @@ void adf_cfg_dev_dbgfs_rm(struct adf_accel_dev *accel_dev)
 }
 
 static void adf_cfg_section_del_all(struct list_head *head);
+static void adf_cfg_section_del_all_except(struct list_head *head,
+                                          const char *section_name);
 
 void adf_cfg_del_all(struct adf_accel_dev *accel_dev)
 {
@@ -111,6 +113,17 @@ void adf_cfg_del_all(struct adf_accel_dev *accel_dev)
        clear_bit(ADF_STATUS_CONFIGURED, &accel_dev->status);
 }
 
+void adf_cfg_del_all_except(struct adf_accel_dev *accel_dev,
+                           const char *section_name)
+{
+       struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
+
+       down_write(&dev_cfg_data->lock);
+       adf_cfg_section_del_all_except(&dev_cfg_data->sec_list, section_name);
+       up_write(&dev_cfg_data->lock);
+       clear_bit(ADF_STATUS_CONFIGURED, &accel_dev->status);
+}
+
 /**
  * adf_cfg_dev_remove() - Clears acceleration device configuration table.
  * @accel_dev:  Pointer to acceleration device.
@@ -185,6 +198,22 @@ static void adf_cfg_section_del_all(struct list_head *head)
        }
 }
 
+static void adf_cfg_section_del_all_except(struct list_head *head,
+                                          const char *section_name)
+{
+       struct list_head *list, *tmp;
+       struct adf_cfg_section *ptr;
+
+       list_for_each_prev_safe(list, tmp, head) {
+               ptr = list_entry(list, struct adf_cfg_section, list);
+               if (!strcmp(ptr->name, section_name))
+                       continue;
+               adf_cfg_keyval_del_all(&ptr->param_head);
+               list_del(list);
+               kfree(ptr);
+       }
+}
+
 static struct adf_cfg_key_val *adf_cfg_key_value_find(struct adf_cfg_section *s,
                                                      const char *key)
 {
index c0c9052..2afa6f0 100644 (file)
@@ -35,6 +35,8 @@ void adf_cfg_dev_dbgfs_add(struct adf_accel_dev *accel_dev);
 void adf_cfg_dev_dbgfs_rm(struct adf_accel_dev *accel_dev);
 int adf_cfg_section_add(struct adf_accel_dev *accel_dev, const char *name);
 void adf_cfg_del_all(struct adf_accel_dev *accel_dev);
+void adf_cfg_del_all_except(struct adf_accel_dev *accel_dev,
+                           const char *section_name);
 int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
                                const char *section_name,
                                const char *key, const void *val,
index 3bec9e2..f7ecabd 100644 (file)
@@ -56,7 +56,7 @@ int adf_service_register(struct service_hndl *service);
 int adf_service_unregister(struct service_hndl *service);
 
 int adf_dev_up(struct adf_accel_dev *accel_dev, bool init_config);
-int adf_dev_down(struct adf_accel_dev *accel_dev, bool cache_config);
+int adf_dev_down(struct adf_accel_dev *accel_dev);
 int adf_dev_restart(struct adf_accel_dev *accel_dev);
 
 void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
index 26a1662..70fa0f6 100644 (file)
@@ -247,7 +247,7 @@ static void adf_ctl_stop_devices(u32 id)
                        if (!accel_dev->is_vf)
                                continue;
 
-                       adf_dev_down(accel_dev, false);
+                       adf_dev_down(accel_dev);
                }
        }
 
@@ -256,7 +256,7 @@ static void adf_ctl_stop_devices(u32 id)
                        if (!adf_dev_started(accel_dev))
                                continue;
 
-                       adf_dev_down(accel_dev, false);
+                       adf_dev_down(accel_dev);
                }
        }
 }
@@ -319,7 +319,7 @@ static int adf_ctl_ioctl_dev_start(struct file *fp, unsigned int cmd,
        if (ret) {
                dev_err(&GET_DEV(accel_dev), "Failed to start qat_dev%d\n",
                        ctl_data->device_id);
-               adf_dev_down(accel_dev, false);
+               adf_dev_down(accel_dev);
        }
 out:
        kfree(ctl_data);
index 74f0818..593fe9a 100644 (file)
@@ -393,9 +393,9 @@ static void adf_dev_shutdown(struct adf_accel_dev *accel_dev)
                clear_bit(ADF_STATUS_IRQ_ALLOCATED, &accel_dev->status);
        }
 
-       /* Delete configuration only if not restarting */
+       /* If not restarting, delete all cfg sections except for GENERAL */
        if (!test_bit(ADF_STATUS_RESTARTING, &accel_dev->status))
-               adf_cfg_del_all(accel_dev);
+               adf_cfg_del_all_except(accel_dev, ADF_GENERAL_SEC);
 
        if (hw_data->exit_arb)
                hw_data->exit_arb(accel_dev);
@@ -445,33 +445,7 @@ void adf_error_notifier(struct adf_accel_dev *accel_dev)
        }
 }
 
-static int adf_dev_shutdown_cache_cfg(struct adf_accel_dev *accel_dev)
-{
-       char services[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0};
-       int ret;
-
-       ret = adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC,
-                                     ADF_SERVICES_ENABLED, services);
-
-       adf_dev_stop(accel_dev);
-       adf_dev_shutdown(accel_dev);
-
-       if (!ret) {
-               ret = adf_cfg_section_add(accel_dev, ADF_GENERAL_SEC);
-               if (ret)
-                       return ret;
-
-               ret = adf_cfg_add_key_value_param(accel_dev, ADF_GENERAL_SEC,
-                                                 ADF_SERVICES_ENABLED,
-                                                 services, ADF_STR);
-               if (ret)
-                       return ret;
-       }
-
-       return 0;
-}
-
-int adf_dev_down(struct adf_accel_dev *accel_dev, bool reconfig)
+int adf_dev_down(struct adf_accel_dev *accel_dev)
 {
        int ret = 0;
 
@@ -480,15 +454,9 @@ int adf_dev_down(struct adf_accel_dev *accel_dev, bool reconfig)
 
        mutex_lock(&accel_dev->state_lock);
 
-       if (reconfig) {
-               ret = adf_dev_shutdown_cache_cfg(accel_dev);
-               goto out;
-       }
-
        adf_dev_stop(accel_dev);
        adf_dev_shutdown(accel_dev);
 
-out:
        mutex_unlock(&accel_dev->state_lock);
        return ret;
 }
@@ -535,7 +503,7 @@ int adf_dev_restart(struct adf_accel_dev *accel_dev)
        if (!accel_dev)
                return -EFAULT;
 
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 
        ret = adf_dev_up(accel_dev, false);
        /* if device is already up return success*/
index 8d645e7..baf2e1c 100644 (file)
@@ -192,7 +192,7 @@ int adf_sriov_configure(struct pci_dev *pdev, int numvfs)
                        return -EBUSY;
                }
 
-               ret = adf_dev_down(accel_dev, true);
+               ret = adf_dev_down(accel_dev);
                if (ret)
                        return ret;
        }
index 4e7f70d..4fcd61f 100644 (file)
@@ -62,7 +62,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
                        break;
                }
 
-               ret = adf_dev_down(accel_dev, true);
+               ret = adf_dev_down(accel_dev);
                if (ret)
                        return ret;
 
@@ -76,7 +76,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
                } else if (ret) {
                        dev_err(dev, "Failed to start device qat_dev%d\n",
                                accel_id);
-                       adf_dev_down(accel_dev, true);
+                       adf_dev_down(accel_dev);
                        return ret;
                }
                break;
index cdbb2d6..783ee8c 100644 (file)
@@ -71,7 +71,7 @@ static void adf_dev_stop_async(struct work_struct *work)
        struct adf_accel_dev *accel_dev = stop_data->accel_dev;
 
        adf_dev_restarting_notify(accel_dev);
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 
        /* Re-enable PF2VF interrupts */
        adf_enable_pf2vf_interrupts(accel_dev);
index 40b456b..2a50cce 100644 (file)
@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
                pr_err("QAT: Driver removal failed\n");
                return;
        }
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);
index d59cb1b..7cb015b 100644 (file)
@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        return ret;
 
 out_err_dev_stop:
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
 out_err_free_reg:
        pci_release_regions(accel_pci_dev->pci_dev);
 out_err_disable:
@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
                return;
        }
        adf_flush_vf_wq(accel_dev);
-       adf_dev_down(accel_dev, false);
+       adf_dev_down(accel_dev);
        adf_cleanup_accel(accel_dev);
        adf_cleanup_pci_dev(accel_dev);
        kfree(accel_dev);