Commit 44abbaf6 authored by Shivasharan S's avatar Shivasharan S Committed by Martin K. Petersen

scsi: megaraid_sas: Rework device add code in AEN path

In preparation of adding support for the DEVICE_LIST DCMD, this patch
refactors the code in the AEN event handling path.  Add new function to
update the PD and LD list in driver.  Move the code to scan PD and VD
channels into separate function.
Signed-off-by: default avatarShivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent daa06811
...@@ -7884,6 +7884,103 @@ static inline void megasas_remove_scsi_device(struct scsi_device *sdev) ...@@ -7884,6 +7884,103 @@ static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
scsi_device_put(sdev); scsi_device_put(sdev);
} }
/**
* megasas_update_device_list - Update the PD and LD device list from FW
* after an AEN event notification
* @instance: Adapter soft state
* @event_type: Indicates type of event (PD or LD event)
*
* @return: Success or failure
*
* Issue DCMDs to Firmware to update the internal device list in driver.
*/
static
int megasas_update_device_list(struct megasas_instance *instance,
int event_type)
{
int dcmd_ret = DCMD_SUCCESS;
if (event_type & SCAN_PD_CHANNEL) {
dcmd_ret = megasas_get_pd_list(instance);
if (dcmd_ret != DCMD_SUCCESS)
goto out;
}
if (event_type & SCAN_VD_CHANNEL) {
if (!instance->requestorId ||
(instance->requestorId &&
megasas_get_ld_vf_affiliation(instance, 0))) {
dcmd_ret = megasas_ld_list_query(instance,
MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
if (dcmd_ret != DCMD_SUCCESS)
goto out;
}
}
out:
return dcmd_ret;
}
/**
* megasas_add_remove_devices - Add/remove devices to SCSI mid-layer
* after an AEN event notification
* @instance: Adapter soft state
* @scan_type: Indicates type of devices (PD/LD) to add
* @return void
*/
static
void megasas_add_remove_devices(struct megasas_instance *instance,
int scan_type)
{
int i, j;
u16 pd_index = 0;
u16 ld_index = 0;
struct Scsi_Host *host;
struct scsi_device *sdev1;
host = instance->host;
if (scan_type & SCAN_PD_CHANNEL) {
for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j;
sdev1 = scsi_device_lookup(host, i, j, 0);
if (instance->pd_list[pd_index].driveState ==
MR_PD_STATE_SYSTEM) {
if (!sdev1)
scsi_add_device(host, i, j, 0);
else
scsi_device_put(sdev1);
} else {
if (sdev1)
megasas_remove_scsi_device(sdev1);
}
}
}
}
if (scan_type & SCAN_VD_CHANNEL) {
for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
sdev1 = scsi_device_lookup(host,
MEGASAS_MAX_PD_CHANNELS + i, j, 0);
if (instance->ld_ids[ld_index] != 0xff) {
if (!sdev1)
scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
else
scsi_device_put(sdev1);
} else {
if (sdev1)
megasas_remove_scsi_device(sdev1);
}
}
}
}
}
static void static void
megasas_aen_polling(struct work_struct *work) megasas_aen_polling(struct work_struct *work)
{ {
...@@ -7891,11 +7988,7 @@ megasas_aen_polling(struct work_struct *work) ...@@ -7891,11 +7988,7 @@ megasas_aen_polling(struct work_struct *work)
container_of(work, struct megasas_aen_event, hotplug_work.work); container_of(work, struct megasas_aen_event, hotplug_work.work);
struct megasas_instance *instance = ev->instance; struct megasas_instance *instance = ev->instance;
union megasas_evt_class_locale class_locale; union megasas_evt_class_locale class_locale;
struct Scsi_Host *host; int event_type = 0;
struct scsi_device *sdev1;
u16 pd_index = 0;
u16 ld_index = 0;
int i, j, doscan = 0;
u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME;
int error; int error;
u8 dcmd_ret = DCMD_SUCCESS; u8 dcmd_ret = DCMD_SUCCESS;
...@@ -7914,7 +8007,6 @@ megasas_aen_polling(struct work_struct *work) ...@@ -7914,7 +8007,6 @@ megasas_aen_polling(struct work_struct *work)
mutex_lock(&instance->reset_mutex); mutex_lock(&instance->reset_mutex);
instance->ev = NULL; instance->ev = NULL;
host = instance->host;
if (instance->evt_detail) { if (instance->evt_detail) {
megasas_decode_evt(instance); megasas_decode_evt(instance);
...@@ -7922,40 +8014,20 @@ megasas_aen_polling(struct work_struct *work) ...@@ -7922,40 +8014,20 @@ megasas_aen_polling(struct work_struct *work)
case MR_EVT_PD_INSERTED: case MR_EVT_PD_INSERTED:
case MR_EVT_PD_REMOVED: case MR_EVT_PD_REMOVED:
dcmd_ret = megasas_get_pd_list(instance); event_type = SCAN_PD_CHANNEL;
if (dcmd_ret == DCMD_SUCCESS)
doscan = SCAN_PD_CHANNEL;
break; break;
case MR_EVT_LD_OFFLINE: case MR_EVT_LD_OFFLINE:
case MR_EVT_CFG_CLEARED: case MR_EVT_CFG_CLEARED:
case MR_EVT_LD_DELETED: case MR_EVT_LD_DELETED:
case MR_EVT_LD_CREATED: case MR_EVT_LD_CREATED:
if (!instance->requestorId || event_type = SCAN_VD_CHANNEL;
(instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0)))
dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
if (dcmd_ret == DCMD_SUCCESS)
doscan = SCAN_VD_CHANNEL;
break; break;
case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
case MR_EVT_FOREIGN_CFG_IMPORTED: case MR_EVT_FOREIGN_CFG_IMPORTED:
case MR_EVT_LD_STATE_CHANGE: case MR_EVT_LD_STATE_CHANGE:
dcmd_ret = megasas_get_pd_list(instance); event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL;
if (dcmd_ret != DCMD_SUCCESS)
break;
if (!instance->requestorId ||
(instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0)))
dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
if (dcmd_ret != DCMD_SUCCESS)
break;
doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL;
dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
instance->host->host_no); instance->host->host_no);
break; break;
...@@ -7971,7 +8043,7 @@ megasas_aen_polling(struct work_struct *work) ...@@ -7971,7 +8043,7 @@ megasas_aen_polling(struct work_struct *work)
} }
break; break;
default: default:
doscan = 0; event_type = 0;
break; break;
} }
} else { } else {
...@@ -7981,44 +8053,13 @@ megasas_aen_polling(struct work_struct *work) ...@@ -7981,44 +8053,13 @@ megasas_aen_polling(struct work_struct *work)
return; return;
} }
mutex_unlock(&instance->reset_mutex); if (event_type)
dcmd_ret = megasas_update_device_list(instance, event_type);
if (doscan & SCAN_PD_CHANNEL) { mutex_unlock(&instance->reset_mutex);
for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j;
sdev1 = scsi_device_lookup(host, i, j, 0);
if (instance->pd_list[pd_index].driveState ==
MR_PD_STATE_SYSTEM) {
if (!sdev1)
scsi_add_device(host, i, j, 0);
else
scsi_device_put(sdev1);
} else {
if (sdev1)
megasas_remove_scsi_device(sdev1);
}
}
}
}
if (doscan & SCAN_VD_CHANNEL) { if (event_type && dcmd_ret == DCMD_SUCCESS)
for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { megasas_add_remove_devices(instance, event_type);
for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
if (instance->ld_ids[ld_index] != 0xff) {
if (!sdev1)
scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
else
scsi_device_put(sdev1);
} else {
if (sdev1)
megasas_remove_scsi_device(sdev1);
}
}
}
}
if (dcmd_ret == DCMD_SUCCESS) if (dcmd_ret == DCMD_SUCCESS)
seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1;
......
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