fedoraproject@6speed.de / rpms / kernel

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