pengqianheng / rpms / kernel

Forked from rpms/kernel a year ago
Clone
24d93b
From a372b29ab979095c323d33ab922062015d459ddd Mon Sep 17 00:00:00 2001
24d93b
From: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
24d93b
Date: Wed, 26 Oct 2016 13:34:34 +0530
24d93b
Subject: [PATCH 03/11] scsi: mpt3sas: Implement device_remove_in_progress
24d93b
 check in IOCTL path
24d93b
24d93b
When device missing event arrives, device_remove_in_progress bit will be
24d93b
set and hence driver has to stop sending IOCTL commands.Now the check has
24d93b
been added in IOCTL path to test device_remove_in_progress bit is set, if
24d93b
so then IOCTL will be failed printing failure message.
24d93b
24d93b
Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
24d93b
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
24d93b
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
24d93b
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
24d93b
---
24d93b
 drivers/scsi/mpt3sas/mpt3sas_base.c  | 19 +++++++++++++++
24d93b
 drivers/scsi/mpt3sas/mpt3sas_base.h  |  5 ++++
24d93b
 drivers/scsi/mpt3sas/mpt3sas_ctl.c   | 46 ++++++++++++++++++++++++++++++------
24d93b
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 24 ++++++++++++++++++-
24d93b
 4 files changed, 86 insertions(+), 8 deletions(-)
24d93b
24d93b
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
24d93b
index 2319db8..ac87e12 100644
24d93b
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
24d93b
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
24d93b
@@ -5368,6 +5368,21 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
24d93b
 		goto out_free_resources;
24d93b
 	}
24d93b
 
24d93b
+	/* allocate memory for pending OS device add list */
24d93b
+	ioc->pend_os_device_add_sz = (ioc->facts.MaxDevHandle / 8);
24d93b
+	if (ioc->facts.MaxDevHandle % 8)
24d93b
+		ioc->pend_os_device_add_sz++;
24d93b
+	ioc->pend_os_device_add = kzalloc(ioc->pend_os_device_add_sz,
24d93b
+	    GFP_KERNEL);
24d93b
+	if (!ioc->pend_os_device_add)
24d93b
+		goto out_free_resources;
24d93b
+
24d93b
+	ioc->device_remove_in_progress_sz = ioc->pend_os_device_add_sz;
24d93b
+	ioc->device_remove_in_progress =
24d93b
+		kzalloc(ioc->device_remove_in_progress_sz, GFP_KERNEL);
24d93b
+	if (!ioc->device_remove_in_progress)
24d93b
+		goto out_free_resources;
24d93b
+
24d93b
 	ioc->fwfault_debug = mpt3sas_fwfault_debug;
24d93b
 
24d93b
 	/* base internal command bits */
24d93b
@@ -5450,6 +5465,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
24d93b
 		kfree(ioc->reply_post_host_index);
24d93b
 	kfree(ioc->pd_handles);
24d93b
 	kfree(ioc->blocking_handles);
24d93b
+	kfree(ioc->device_remove_in_progress);
24d93b
+	kfree(ioc->pend_os_device_add);
24d93b
 	kfree(ioc->tm_cmds.reply);
24d93b
 	kfree(ioc->transport_cmds.reply);
24d93b
 	kfree(ioc->scsih_cmds.reply);
24d93b
@@ -5491,6 +5508,8 @@ mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc)
24d93b
 		kfree(ioc->reply_post_host_index);
24d93b
 	kfree(ioc->pd_handles);
24d93b
 	kfree(ioc->blocking_handles);
24d93b
+	kfree(ioc->device_remove_in_progress);
24d93b
+	kfree(ioc->pend_os_device_add);
24d93b
 	kfree(ioc->pfacts);
24d93b
 	kfree(ioc->ctl_cmds.reply);
24d93b
 	kfree(ioc->ctl_cmds.sense);
24d93b
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
24d93b
index 1a614d7..241a660 100644
24d93b
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
24d93b
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
24d93b
@@ -1093,6 +1093,9 @@ struct MPT3SAS_ADAPTER {
24d93b
 	void		*pd_handles;
24d93b
 	u16		pd_handles_sz;
24d93b
 
24d93b
+	void		*pend_os_device_add;
24d93b
+	u16		pend_os_device_add_sz;
24d93b
+
24d93b
 	/* config page */
24d93b
 	u16		config_page_sz;
24d93b
 	void		*config_page;
24d93b
@@ -1201,6 +1204,8 @@ struct MPT3SAS_ADAPTER {
24d93b
 	struct SL_WH_EVENT_TRIGGERS_T diag_trigger_event;
24d93b
 	struct SL_WH_SCSI_TRIGGERS_T diag_trigger_scsi;
24d93b
 	struct SL_WH_MPI_TRIGGERS_T diag_trigger_mpi;
24d93b
+	void		*device_remove_in_progress;
24d93b
+	u16		device_remove_in_progress_sz;
24d93b
 };
24d93b
 
24d93b
 typedef u8 (*MPT_CALLBACK)(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
24d93b
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
24d93b
index 7d00f09..a75f8a3 100644
24d93b
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
24d93b
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
24d93b
@@ -655,6 +655,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
24d93b
 	size_t data_in_sz = 0;
24d93b
 	long ret;
24d93b
 	u16 wait_state_count;
24d93b
+	u16 device_handle = MPT3SAS_INVALID_DEVICE_HANDLE;
24d93b
 
24d93b
 	issue_reset = 0;
24d93b
 
24d93b
@@ -739,10 +740,13 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
24d93b
 	data_in_sz = karg.data_in_size;
24d93b
 
24d93b
 	if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
24d93b
-	    mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
24d93b
-		if (!le16_to_cpu(mpi_request->FunctionDependent1) ||
24d93b
-		    le16_to_cpu(mpi_request->FunctionDependent1) >
24d93b
-		    ioc->facts.MaxDevHandle) {
24d93b
+	    mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
24d93b
+	    mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT ||
24d93b
+	    mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH) {
24d93b
+
24d93b
+		device_handle = le16_to_cpu(mpi_request->FunctionDependent1);
24d93b
+		if (!device_handle || (device_handle >
24d93b
+		    ioc->facts.MaxDevHandle)) {
24d93b
 			ret = -EINVAL;
24d93b
 			mpt3sas_base_free_smid(ioc, smid);
24d93b
 			goto out;
24d93b
@@ -798,12 +802,18 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
24d93b
 		scsiio_request->SenseBufferLowAddress =
24d93b
 		    mpt3sas_base_get_sense_buffer_dma(ioc, smid);
24d93b
 		memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
24d93b
+		if (test_bit(device_handle, ioc->device_remove_in_progress)) {
24d93b
+			dtmprintk(ioc, pr_info(MPT3SAS_FMT
24d93b
+				"handle(0x%04x) :ioctl failed due to device removal in progress\n",
24d93b
+				ioc->name, device_handle));
24d93b
+			mpt3sas_base_free_smid(ioc, smid);
24d93b
+			ret = -EINVAL;
24d93b
+			goto out;
24d93b
+		}
24d93b
 		ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
24d93b
 		    data_in_dma, data_in_sz);
24d93b
-
24d93b
 		if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
24d93b
-			mpt3sas_base_put_smid_scsi_io(ioc, smid,
24d93b
-			    le16_to_cpu(mpi_request->FunctionDependent1));
24d93b
+			mpt3sas_base_put_smid_scsi_io(ioc, smid, device_handle);
24d93b
 		else
24d93b
 			mpt3sas_base_put_smid_default(ioc, smid);
24d93b
 		break;
24d93b
@@ -828,6 +838,14 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
24d93b
 			}
24d93b
 		}
24d93b
 
24d93b
+		if (test_bit(device_handle, ioc->device_remove_in_progress)) {
24d93b
+			dtmprintk(ioc, pr_info(MPT3SAS_FMT
24d93b
+				"handle(0x%04x) :ioctl failed due to device removal in progress\n",
24d93b
+				ioc->name, device_handle));
24d93b
+			mpt3sas_base_free_smid(ioc, smid);
24d93b
+			ret = -EINVAL;
24d93b
+			goto out;
24d93b
+		}
24d93b
 		mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu(
24d93b
 		    tm_request->DevHandle));
24d93b
 		ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
24d93b
@@ -867,6 +885,20 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
24d93b
 		break;
24d93b
 	}
24d93b
 	case MPI2_FUNCTION_SATA_PASSTHROUGH:
24d93b
+	{
24d93b
+		if (test_bit(device_handle, ioc->device_remove_in_progress)) {
24d93b
+			dtmprintk(ioc, pr_info(MPT3SAS_FMT
24d93b
+				"handle(0x%04x) :ioctl failed due to device removal in progress\n",
24d93b
+				ioc->name, device_handle));
24d93b
+			mpt3sas_base_free_smid(ioc, smid);
24d93b
+			ret = -EINVAL;
24d93b
+			goto out;
24d93b
+		}
24d93b
+		ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
24d93b
+		    data_in_sz);
24d93b
+		mpt3sas_base_put_smid_default(ioc, smid);
24d93b
+		break;
24d93b
+	}
24d93b
 	case MPI2_FUNCTION_FW_DOWNLOAD:
24d93b
 	case MPI2_FUNCTION_FW_UPLOAD:
24d93b
 	{
24d93b
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
24d93b
index 9c61476..c6aa172 100644
24d93b
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
24d93b
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
24d93b
@@ -785,6 +785,11 @@ _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
24d93b
 	list_add_tail(&sas_device->list, &ioc->sas_device_list);
24d93b
 	spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
24d93b
 
24d93b
+	if (ioc->hide_drives) {
24d93b
+		clear_bit(sas_device->handle, ioc->pend_os_device_add);
24d93b
+		return;
24d93b
+	}
24d93b
+
24d93b
 	if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
24d93b
 	     sas_device->sas_address_parent)) {
24d93b
 		_scsih_sas_device_remove(ioc, sas_device);
24d93b
@@ -800,7 +805,8 @@ _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
24d93b
 			    sas_device->sas_address_parent);
24d93b
 			_scsih_sas_device_remove(ioc, sas_device);
24d93b
 		}
24d93b
-	}
24d93b
+	} else
24d93b
+		clear_bit(sas_device->handle, ioc->pend_os_device_add);
24d93b
 }
24d93b
 
24d93b
 /**
24d93b
@@ -3189,6 +3195,8 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
24d93b
 	if (test_bit(handle, ioc->pd_handles))
24d93b
 		return;
24d93b
 
24d93b
+	clear_bit(handle, ioc->pend_os_device_add);
24d93b
+
24d93b
 	spin_lock_irqsave(&ioc->sas_device_lock, flags);
24d93b
 	sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
24d93b
 	if (sas_device && sas_device->starget &&
24d93b
@@ -3243,6 +3251,7 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
24d93b
 	mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
24d93b
 	mpi_request->DevHandle = cpu_to_le16(handle);
24d93b
 	mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
24d93b
+	set_bit(handle, ioc->device_remove_in_progress);
24d93b
 	mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
24d93b
 	mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
24d93b
 
24d93b
@@ -3377,6 +3386,11 @@ _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
24d93b
 		ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
24d93b
 		le16_to_cpu(mpi_reply->IOCStatus),
24d93b
 		le32_to_cpu(mpi_reply->IOCLogInfo)));
24d93b
+		if (le16_to_cpu(mpi_reply->IOCStatus) ==
24d93b
+		     MPI2_IOCSTATUS_SUCCESS) {
24d93b
+			clear_bit(le16_to_cpu(mpi_reply->DevHandle),
24d93b
+			    ioc->device_remove_in_progress);
24d93b
+		}
24d93b
 	} else {
24d93b
 		pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
24d93b
 		    ioc->name, __FILE__, __LINE__, __func__);
24d93b
@@ -5506,6 +5520,7 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
24d93b
 	device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
24d93b
 	if (!(_scsih_is_end_device(device_info)))
24d93b
 		return -1;
24d93b
+	set_bit(handle, ioc->pend_os_device_add);
24d93b
 	sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
24d93b
 
24d93b
 	/* check if device is present */
24d93b
@@ -5524,6 +5539,7 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
24d93b
 	sas_device = mpt3sas_get_sdev_by_addr(ioc,
24d93b
 					sas_address);
24d93b
 	if (sas_device) {
24d93b
+		clear_bit(handle, ioc->pend_os_device_add);
24d93b
 		sas_device_put(sas_device);
24d93b
 		return -1;
24d93b
 	}
24d93b
@@ -5846,6 +5862,9 @@ _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
24d93b
 			_scsih_check_device(ioc, sas_address, handle,
24d93b
 			    phy_number, link_rate);
24d93b
 
24d93b
+			if (!test_bit(handle, ioc->pend_os_device_add))
24d93b
+				break;
24d93b
+
24d93b
 
24d93b
 		case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
24d93b
 
24d93b
@@ -7766,6 +7785,9 @@ mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
24d93b
 			complete(&ioc->tm_cmds.done);
24d93b
 		}
24d93b
 
24d93b
+		memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
24d93b
+		memset(ioc->device_remove_in_progress, 0,
24d93b
+		       ioc->device_remove_in_progress_sz);
24d93b
 		_scsih_fw_event_cleanup_queue(ioc);
24d93b
 		_scsih_flush_running_cmds(ioc);
24d93b
 		break;
24d93b
-- 
24d93b
1.8.3.1
24d93b