diff mbox series

[2/3] megaraid_sas: Rework device add code in AEN path

Message ID 1547831500-26751-3-git-send-email-shivasharan.srikanteshwara@broadcom.com (mailing list archive)
State Superseded
Headers show
Series megaraid_sas: Add support for FW device list DCMD | expand

Commit Message

Shivasharan Srikanteshwara Jan. 18, 2019, 5:11 p.m. UTC
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: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 172 ++++++++++++++++++------------
 1 file changed, 106 insertions(+), 66 deletions(-)

Comments

Dan Carpenter Jan. 21, 2019, 8:06 p.m. UTC | #1
Hi Shivasharan,

I love your patch! Perhaps something to improve:

url:    https://github.com/0day-ci/linux/commits/Shivasharan-S/megaraid_sas-Rework-code-to-get-PD-and-LD-list/20190121-132655

New smatch warnings:
drivers/scsi/megaraid/megaraid_sas_base.c:7919 megasas_update_device_list() error: uninitialized symbol 'dcmd_ret'.

Old smatch warnings:
drivers/scsi/megaraid/megaraid_sas_base.c:1855 megasas_set_dynamic_target_properties() warn: if statement not indented
drivers/scsi/megaraid/megaraid_sas_base.c:3319 megasas_complete_cmd() error: we previously assumed 'cmd->scmd' could be null (see line 3286)
drivers/scsi/megaraid/megaraid_sas_base.c:5613 megasas_init_fw() error: we previously assumed 'fusion' could be null (see line 5473)
drivers/scsi/megaraid/megaraid_sas_base.c:7924 megasas_update_device_list() error: uninitialized symbol 'dcmd_ret'.

# https://github.com/0day-ci/linux/commit/3ee216cd5eece3e0480372c229cac0d992460d69
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 3ee216cd5eece3e0480372c229cac0d992460d69
vim +/dcmd_ret +7919 drivers/scsi/megaraid/megaraid_sas_base.c

b4a42213a Shivasharan S 2017-02-10  7889  
3ee216cd5 Shivasharan S 2019-01-18  7890  /*
3ee216cd5 Shivasharan S 2019-01-18  7891   * megasas_update_device_list -	Update the PD and LD device list from FW
3ee216cd5 Shivasharan S 2019-01-18  7892   *				after an AEN event notification
3ee216cd5 Shivasharan S 2019-01-18  7893   * @instance:			Adapter soft state
3ee216cd5 Shivasharan S 2019-01-18  7894   * @event_type:			Indicates type of event (PD or LD event)
3ee216cd5 Shivasharan S 2019-01-18  7895   *
3ee216cd5 Shivasharan S 2019-01-18  7896   * @return:			Success or failure
3ee216cd5 Shivasharan S 2019-01-18  7897   *
3ee216cd5 Shivasharan S 2019-01-18  7898   * Issue DCMDs to Firmware to update the internal device list in driver.
3ee216cd5 Shivasharan S 2019-01-18  7899   */
3ee216cd5 Shivasharan S 2019-01-18  7900  static
3ee216cd5 Shivasharan S 2019-01-18  7901  int megasas_update_device_list(struct megasas_instance *instance,
3ee216cd5 Shivasharan S 2019-01-18  7902  			       int event_type)
3ee216cd5 Shivasharan S 2019-01-18  7903  {
3ee216cd5 Shivasharan S 2019-01-18  7904  	int dcmd_ret;
3ee216cd5 Shivasharan S 2019-01-18  7905  
3ee216cd5 Shivasharan S 2019-01-18  7906  	if (event_type & SCAN_PD_CHANNEL) {
3ee216cd5 Shivasharan S 2019-01-18  7907  		dcmd_ret = megasas_get_pd_list(instance);
3ee216cd5 Shivasharan S 2019-01-18  7908  
3ee216cd5 Shivasharan S 2019-01-18  7909  		if (dcmd_ret != DCMD_SUCCESS)
3ee216cd5 Shivasharan S 2019-01-18  7910  			goto out;
3ee216cd5 Shivasharan S 2019-01-18  7911  	}
3ee216cd5 Shivasharan S 2019-01-18  7912  
3ee216cd5 Shivasharan S 2019-01-18  7913  	if (event_type & SCAN_VD_CHANNEL) {
3ee216cd5 Shivasharan S 2019-01-18  7914  		if (!instance->requestorId ||
3ee216cd5 Shivasharan S 2019-01-18  7915  		    (instance->requestorId &&
3ee216cd5 Shivasharan S 2019-01-18  7916  		     megasas_get_ld_vf_affiliation(instance, 0)))
3ee216cd5 Shivasharan S 2019-01-18  7917  			dcmd_ret = megasas_ld_list_query(instance,
3ee216cd5 Shivasharan S 2019-01-18  7918  					MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
3ee216cd5 Shivasharan S 2019-01-18 @7919  		if (dcmd_ret != DCMD_SUCCESS)
                                                            ^^^^^^^^^^^^^^^^^^^^^^^

Not necessarily initialized.  Probably add curly braces and indent this
etc.

3ee216cd5 Shivasharan S 2019-01-18  7920  			goto out;
3ee216cd5 Shivasharan S 2019-01-18  7921  	}
3ee216cd5 Shivasharan S 2019-01-18  7922  
3ee216cd5 Shivasharan S 2019-01-18  7923  out:
3ee216cd5 Shivasharan S 2019-01-18  7924  	return dcmd_ret;
3ee216cd5 Shivasharan S 2019-01-18  7925  }
3ee216cd5 Shivasharan S 2019-01-18  7926  

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index c16f8533c8a8..115f4826832c 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7887,6 +7887,102 @@  static inline void megasas_remove_scsi_device(struct scsi_device *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;
+
+	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
 megasas_aen_polling(struct work_struct *work)
 {
@@ -7894,11 +7990,7 @@  megasas_aen_polling(struct work_struct *work)
 		container_of(work, struct megasas_aen_event, hotplug_work.work);
 	struct megasas_instance *instance = ev->instance;
 	union megasas_evt_class_locale class_locale;
-	struct  Scsi_Host *host;
-	struct  scsi_device *sdev1;
-	u16     pd_index = 0;
-	u16	ld_index = 0;
-	int     i, j, doscan = 0;
+	int event_type = 0;
 	u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME;
 	int error;
 	u8  dcmd_ret = DCMD_SUCCESS;
@@ -7917,7 +8009,6 @@  megasas_aen_polling(struct work_struct *work)
 	mutex_lock(&instance->reset_mutex);
 
 	instance->ev = NULL;
-	host = instance->host;
 	if (instance->evt_detail) {
 		megasas_decode_evt(instance);
 
@@ -7925,40 +8016,20 @@  megasas_aen_polling(struct work_struct *work)
 
 		case MR_EVT_PD_INSERTED:
 		case MR_EVT_PD_REMOVED:
-			dcmd_ret = megasas_get_pd_list(instance);
-			if (dcmd_ret == DCMD_SUCCESS)
-				doscan = SCAN_PD_CHANNEL;
+			event_type = SCAN_PD_CHANNEL;
 			break;
 
 		case MR_EVT_LD_OFFLINE:
 		case MR_EVT_CFG_CLEARED:
 		case MR_EVT_LD_DELETED:
 		case MR_EVT_LD_CREATED:
-			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)
-				doscan = SCAN_VD_CHANNEL;
-
+			event_type = SCAN_VD_CHANNEL;
 			break;
 
 		case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
 		case MR_EVT_FOREIGN_CFG_IMPORTED:
 		case MR_EVT_LD_STATE_CHANGE:
-			dcmd_ret = megasas_get_pd_list(instance);
-
-			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;
+			event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL;
 			dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
 				instance->host->host_no);
 			break;
@@ -7974,7 +8045,7 @@  megasas_aen_polling(struct work_struct *work)
 			}
 			break;
 		default:
-			doscan = 0;
+			event_type = 0;
 			break;
 		}
 	} else {
@@ -7984,44 +8055,13 @@  megasas_aen_polling(struct work_struct *work)
 		return;
 	}
 
-	mutex_unlock(&instance->reset_mutex);
+	if (event_type)
+		dcmd_ret = megasas_update_device_list(instance, event_type);
 
-	if (doscan & 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);
-				}
-			}
-		}
-	}
+	mutex_unlock(&instance->reset_mutex);
 
-	if (doscan & 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);
-				}
-			}
-		}
-	}
+	if (event_type && dcmd_ret == DCMD_SUCCESS)
+		megasas_add_remove_devices(instance, event_type);
 
 	if (dcmd_ret == DCMD_SUCCESS)
 		seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1;