Re: [PATCH 2/2] scsi: megaraid_sas: Add megasas_dcmd_timeout helper
From: mengfanhui
Date: Thu Jun 13 2024 - 02:51:57 EST
Can someone help review it? Thank you!
在 2024/5/30 17:45, mengfanhui 写道:
> DCMD timeout is handled in many places, it makes sense to
> add a hepler to handle it. This patch adds a new helper
> named megasas_dcmd_timeout() to reduce duplicate code.
>
> Co-developed-by: Jackie Liu <liuyun01@xxxxxxxxxx>
> Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx>
> Signed-off-by: mengfanhui <mengfanhui@xxxxxxxxxx>
> Suggested-by: Geliang Tang <geliang@xxxxxxxxxx>
> ---
> drivers/scsi/megaraid/megaraid_sas.h | 2 +
> drivers/scsi/megaraid/megaraid_sas_base.c | 199 ++++----------------
> drivers/scsi/megaraid/megaraid_sas_fusion.c | 34 +---
> 3 files changed, 38 insertions(+), 197 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
> index 91570c5e8456..d96dc446c3aa 100644
> --- a/drivers/scsi/megaraid/megaraid_sas.h
> +++ b/drivers/scsi/megaraid/megaraid_sas.h
> @@ -2761,5 +2761,7 @@ void megasas_setup_debugfs(struct megasas_instance *instance);
> void megasas_destroy_debugfs(struct megasas_instance *instance);
> int megasas_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
> int dcmd_timeout_ocr_possible(struct megasas_instance *instance);
> +void megasas_dcmd_timeout(struct megasas_instance *instance,
> + struct megasas_cmd *cmd);
>
> #endif /*LSI_MEGARAID_SAS_H */
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
> index ba8061ea2078..9325a011746d 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -4531,6 +4531,30 @@ int dcmd_timeout_ocr_possible(struct megasas_instance *instance)
> return INITIATE_OCR;
> }
>
> +/*
> + * megasas_dcmd_timeout - Classification processing dcmd timeout.
> + * @instance: Adapter soft state
> + */
> +void megasas_dcmd_timeout(struct megasas_instance *instance, struct megasas_cmd *cmd)
> +{
> + switch (dcmd_timeout_ocr_possible(instance)) {
> + case INITIATE_OCR:
> + cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> + mutex_unlock(&instance->reset_mutex);
> + megasas_reset_fusion(instance->host,
> + MFI_IO_TIMEOUT_OCR);
> + mutex_lock(&instance->reset_mutex);
> + break;
> + case KILL_ADAPTER:
> + megaraid_sas_kill_hba(instance);
> + break;
> + case IGNORE_TIMEOUT:
> + dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> + __func__, __LINE__);
> + break;
> + }
> +}
> +
> static void
> megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
> {
> @@ -4582,24 +4606,7 @@ megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
> break;
>
> case DCMD_TIMEOUT:
> -
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> -
> + megasas_dcmd_timeout(instance, cmd);
> break;
> }
>
> @@ -4678,29 +4685,7 @@ megasas_get_pd_list(struct megasas_instance *instance)
> instance->pd_list_not_supported = 1;
> break;
> case DCMD_TIMEOUT:
> -
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - /*
> - * DCMD failed from AEN path.
> - * AEN path already hold reset_mutex to avoid PCI access
> - * while OCR is in progress.
> - */
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n",
> - __func__, __LINE__);
> - break;
> - }
> -
> + megasas_dcmd_timeout(instance, cmd);
> break;
>
> case DCMD_SUCCESS:
> @@ -4805,29 +4790,7 @@ megasas_get_ld_list(struct megasas_instance *instance)
> megaraid_sas_kill_hba(instance);
> break;
> case DCMD_TIMEOUT:
> -
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - /*
> - * DCMD failed from AEN path.
> - * AEN path already hold reset_mutex to avoid PCI access
> - * while OCR is in progress.
> - */
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> -
> + megasas_dcmd_timeout(instance, cmd);
> break;
>
> case DCMD_SUCCESS:
> @@ -4925,28 +4888,7 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
> ret = megasas_get_ld_list(instance);
> break;
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - /*
> - * DCMD failed from AEN path.
> - * AEN path already hold reset_mutex to avoid PCI access
> - * while OCR is in progress.
> - */
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> -
> + megasas_dcmd_timeout(instance, cmd);
> break;
> case DCMD_SUCCESS:
> tgtid_count = le32_to_cpu(ci->count);
> @@ -5081,22 +5023,7 @@ megasas_host_device_list_query(struct megasas_instance *instance,
> break;
>
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> break;
> case DCMD_FAILED:
> dev_err(&instance->pdev->dev,
> @@ -5232,22 +5159,7 @@ void megasas_get_snapdump_properties(struct megasas_instance *instance)
> break;
>
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> }
>
> if (ret != DCMD_TIMEOUT)
> @@ -5372,22 +5284,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance)
> break;
>
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> break;
> case DCMD_FAILED:
> megaraid_sas_kill_hba(instance);
> @@ -5454,20 +5351,8 @@ int megasas_set_crash_dump_params(struct megasas_instance *instance,
> ret = megasas_issue_polled(instance, cmd);
>
> if (ret == DCMD_TIMEOUT) {
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> +
> } else
> megasas_return_cmd(instance, cmd);
>
> @@ -6840,23 +6725,7 @@ megasas_get_target_prop(struct megasas_instance *instance,
>
> switch (ret) {
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev,
> - "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> break;
>
> default:
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index f0aeb1ee83a2..1d0991650062 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -1371,22 +1371,7 @@ megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {
> instance->pd_seq_map_id++;
> break;
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> break;
> case DCMD_FAILED:
> dev_err(&instance->pdev->dev,
> @@ -1476,22 +1461,7 @@ megasas_get_ld_map_info(struct megasas_instance *instance)
>
> switch (ret) {
> case DCMD_TIMEOUT:
> - switch (dcmd_timeout_ocr_possible(instance)) {
> - case INITIATE_OCR:
> - cmd->flags |= DRV_DCMD_SKIP_REFIRE;
> - mutex_unlock(&instance->reset_mutex);
> - megasas_reset_fusion(instance->host,
> - MFI_IO_TIMEOUT_OCR);
> - mutex_lock(&instance->reset_mutex);
> - break;
> - case KILL_ADAPTER:
> - megaraid_sas_kill_hba(instance);
> - break;
> - case IGNORE_TIMEOUT:
> - dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
> - __func__, __LINE__);
> - break;
> - }
> + megasas_dcmd_timeout(instance, cmd);
> break;
> case DCMD_FAILED:
> dev_err(&instance->pdev->dev,