Commit 4e190a57 authored by Adam Guerin's avatar Adam Guerin Committed by Herbert Xu

crypto: qat - preserve ADF_GENERAL_SEC

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: default avatarAdam Guerin <adam.guerin@intel.com>
Co-developed-by: default avatarMichal Witwicki <michal.witwicki@intel.com>
Signed-off-by: default avatarMichal Witwicki <michal.witwicki@intel.com>
Reviewed-by: default avatarGiovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: default avatarPrzemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 47d96252
...@@ -163,7 +163,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -163,7 +163,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err: out_err:
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
return ret; return ret;
...@@ -177,7 +177,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -177,7 +177,7 @@ static void adf_remove(struct pci_dev *pdev)
pr_err("QAT: Driver removal failed\n"); pr_err("QAT: Driver removal failed\n");
return; return;
} }
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
} }
......
...@@ -165,7 +165,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -165,7 +165,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err: out_err:
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
return ret; return ret;
...@@ -179,7 +179,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -179,7 +179,7 @@ static void adf_remove(struct pci_dev *pdev)
pr_err("QAT: Driver removal failed\n"); pr_err("QAT: Driver removal failed\n");
return; return;
} }
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
} }
......
...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
pr_err("QAT: Driver removal failed\n"); pr_err("QAT: Driver removal failed\n");
return; return;
} }
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
return; return;
} }
adf_flush_vf_wq(accel_dev); adf_flush_vf_wq(accel_dev);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
pr_err("QAT: Driver removal failed\n"); pr_err("QAT: Driver removal failed\n");
return; return;
} }
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
return; return;
} }
adf_flush_vf_wq(accel_dev); adf_flush_vf_wq(accel_dev);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
...@@ -44,7 +44,7 @@ static pci_ers_result_t adf_error_detected(struct pci_dev *pdev, ...@@ -44,7 +44,7 @@ static pci_ers_result_t adf_error_detected(struct pci_dev *pdev,
adf_pf2vf_notify_restarting(accel_dev); adf_pf2vf_notify_restarting(accel_dev);
adf_pf2vf_wait_for_restarting_complete(accel_dev); adf_pf2vf_wait_for_restarting_complete(accel_dev);
pci_clear_master(pdev); pci_clear_master(pdev);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
return PCI_ERS_RESULT_NEED_RESET; return PCI_ERS_RESULT_NEED_RESET;
} }
......
...@@ -100,6 +100,8 @@ void adf_cfg_dev_dbgfs_rm(struct adf_accel_dev *accel_dev) ...@@ -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(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) 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) ...@@ -111,6 +113,17 @@ void adf_cfg_del_all(struct adf_accel_dev *accel_dev)
clear_bit(ADF_STATUS_CONFIGURED, &accel_dev->status); 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. * adf_cfg_dev_remove() - Clears acceleration device configuration table.
* @accel_dev: Pointer to acceleration device. * @accel_dev: Pointer to acceleration device.
...@@ -185,6 +198,22 @@ static void adf_cfg_section_del_all(struct list_head *head) ...@@ -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, static struct adf_cfg_key_val *adf_cfg_key_value_find(struct adf_cfg_section *s,
const char *key) const char *key)
{ {
......
...@@ -35,6 +35,8 @@ void adf_cfg_dev_dbgfs_add(struct adf_accel_dev *accel_dev); ...@@ -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); 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); 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(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, int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
const char *section_name, const char *section_name,
const char *key, const void *val, const char *key, const void *val,
......
...@@ -56,7 +56,7 @@ int adf_service_register(struct service_hndl *service); ...@@ -56,7 +56,7 @@ int adf_service_register(struct service_hndl *service);
int adf_service_unregister(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_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); int adf_dev_restart(struct adf_accel_dev *accel_dev);
void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data); void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
......
...@@ -247,7 +247,7 @@ static void adf_ctl_stop_devices(u32 id) ...@@ -247,7 +247,7 @@ static void adf_ctl_stop_devices(u32 id)
if (!accel_dev->is_vf) if (!accel_dev->is_vf)
continue; continue;
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
} }
} }
...@@ -256,7 +256,7 @@ static void adf_ctl_stop_devices(u32 id) ...@@ -256,7 +256,7 @@ static void adf_ctl_stop_devices(u32 id)
if (!adf_dev_started(accel_dev)) if (!adf_dev_started(accel_dev))
continue; 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, ...@@ -319,7 +319,7 @@ static int adf_ctl_ioctl_dev_start(struct file *fp, unsigned int cmd,
if (ret) { if (ret) {
dev_err(&GET_DEV(accel_dev), "Failed to start qat_dev%d\n", dev_err(&GET_DEV(accel_dev), "Failed to start qat_dev%d\n",
ctl_data->device_id); ctl_data->device_id);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
} }
out: out:
kfree(ctl_data); kfree(ctl_data);
......
...@@ -393,9 +393,9 @@ static void adf_dev_shutdown(struct adf_accel_dev *accel_dev) ...@@ -393,9 +393,9 @@ static void adf_dev_shutdown(struct adf_accel_dev *accel_dev)
clear_bit(ADF_STATUS_IRQ_ALLOCATED, &accel_dev->status); 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)) 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) if (hw_data->exit_arb)
hw_data->exit_arb(accel_dev); hw_data->exit_arb(accel_dev);
...@@ -445,33 +445,7 @@ void adf_error_notifier(struct adf_accel_dev *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) int adf_dev_down(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 ret = 0; int ret = 0;
...@@ -480,15 +454,9 @@ int adf_dev_down(struct adf_accel_dev *accel_dev, bool reconfig) ...@@ -480,15 +454,9 @@ int adf_dev_down(struct adf_accel_dev *accel_dev, bool reconfig)
mutex_lock(&accel_dev->state_lock); 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_stop(accel_dev);
adf_dev_shutdown(accel_dev); adf_dev_shutdown(accel_dev);
out:
mutex_unlock(&accel_dev->state_lock); mutex_unlock(&accel_dev->state_lock);
return ret; return ret;
} }
...@@ -535,7 +503,7 @@ int adf_dev_restart(struct adf_accel_dev *accel_dev) ...@@ -535,7 +503,7 @@ int adf_dev_restart(struct adf_accel_dev *accel_dev)
if (!accel_dev) if (!accel_dev)
return -EFAULT; return -EFAULT;
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
ret = adf_dev_up(accel_dev, false); ret = adf_dev_up(accel_dev, false);
/* if device is already up return success*/ /* if device is already up return success*/
......
...@@ -192,7 +192,7 @@ int adf_sriov_configure(struct pci_dev *pdev, int numvfs) ...@@ -192,7 +192,7 @@ int adf_sriov_configure(struct pci_dev *pdev, int numvfs)
return -EBUSY; return -EBUSY;
} }
ret = adf_dev_down(accel_dev, true); ret = adf_dev_down(accel_dev);
if (ret) if (ret)
return ret; return ret;
} }
......
...@@ -62,7 +62,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, ...@@ -62,7 +62,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
break; break;
} }
ret = adf_dev_down(accel_dev, true); ret = adf_dev_down(accel_dev);
if (ret) if (ret)
return ret; return ret;
...@@ -76,7 +76,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, ...@@ -76,7 +76,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
} else if (ret) { } else if (ret) {
dev_err(dev, "Failed to start device qat_dev%d\n", dev_err(dev, "Failed to start device qat_dev%d\n",
accel_id); accel_id);
adf_dev_down(accel_dev, true); adf_dev_down(accel_dev);
return ret; return ret;
} }
break; break;
......
...@@ -71,7 +71,7 @@ static void adf_dev_stop_async(struct work_struct *work) ...@@ -71,7 +71,7 @@ static void adf_dev_stop_async(struct work_struct *work)
struct adf_accel_dev *accel_dev = stop_data->accel_dev; struct adf_accel_dev *accel_dev = stop_data->accel_dev;
adf_dev_restarting_notify(accel_dev); adf_dev_restarting_notify(accel_dev);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
/* Re-enable PF2VF interrupts */ /* Re-enable PF2VF interrupts */
adf_enable_pf2vf_interrupts(accel_dev); adf_enable_pf2vf_interrupts(accel_dev);
......
...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -202,7 +202,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -221,7 +221,7 @@ static void adf_remove(struct pci_dev *pdev)
pr_err("QAT: Driver removal failed\n"); pr_err("QAT: Driver removal failed\n");
return; return;
} }
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -176,7 +176,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return ret; return ret;
out_err_dev_stop: out_err_dev_stop:
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
out_err_free_reg: out_err_free_reg:
pci_release_regions(accel_pci_dev->pci_dev); pci_release_regions(accel_pci_dev->pci_dev);
out_err_disable: out_err_disable:
...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev) ...@@ -196,7 +196,7 @@ static void adf_remove(struct pci_dev *pdev)
return; return;
} }
adf_flush_vf_wq(accel_dev); adf_flush_vf_wq(accel_dev);
adf_dev_down(accel_dev, false); adf_dev_down(accel_dev);
adf_cleanup_accel(accel_dev); adf_cleanup_accel(accel_dev);
adf_cleanup_pci_dev(accel_dev); adf_cleanup_pci_dev(accel_dev);
kfree(accel_dev); kfree(accel_dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment