public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND  ioctl
@ 2009-04-17 16:32 Eric Moore
  2009-04-17 17:50 ` Peter Bogdanovic
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Moore @ 2009-04-17 16:32 UTC (permalink / raw)
  To: linux-scsi; +Cc: James.Bottomley

Adding new eh_target_reset_handler for target reset. Change the
eh_device_reset_handler so its sending
MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, instead of
MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET.  Add new function
_scsih_scsi_lookup_find_by_lun as a sanity check to insure I_T_L commands are
completed upon completing lun reset.

Signed-off-by: Eric Moore <eric.moore@lsi.com>

diff -uarpN a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c	2009-04-17 09:04:10.000000000 -0600
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c	2009-04-17 09:07:38.000000000 -0600
@@ -884,6 +884,41 @@ _scsih_scsi_lookup_find_by_target(struct
 }
 
 /**
+ * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
+ * @ioc: per adapter object
+ * @id: target id
+ * @lun: lun number
+ * @channel: channel
+ * Context: This function will acquire ioc->scsi_lookup_lock.
+ *
+ * This will search for a matching channel:id:lun in the scsi_lookup array,
+ * returning 1 if found.
+ */
+static u8
+_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
+    unsigned int lun, int channel)
+{
+	u8 found;
+	unsigned long	flags;
+	int i;
+
+	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+	found = 0;
+	for (i = 0 ; i < ioc->request_depth; i++) {
+		if (ioc->scsi_lookup[i].scmd &&
+		    (ioc->scsi_lookup[i].scmd->device->id == id &&
+		    ioc->scsi_lookup[i].scmd->device->channel == channel &&
+		    ioc->scsi_lookup[i].scmd->device->lun == lun)) {
+			found = 1;
+			goto out;
+		}
+	}
+ out:
+	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+	return found;
+}
+
+/**
  * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
  * @ioc: per adapter object
  * @smid: system request message index
@@ -1889,7 +1924,6 @@ scsih_abort(struct scsi_cmnd *scmd)
 	return r;
 }
 
-
 /**
  * scsih_dev_reset - eh threads main device reset routine
  * @sdev: scsi device struct
@@ -1906,7 +1940,7 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
 	u16	handle;
 	int r;
 
-	printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
+	printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
 	    ioc->name, scmd);
 	scsi_print_command(scmd);
 
@@ -1941,6 +1975,78 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
 
 	mutex_lock(&ioc->tm_cmds.mutex);
 	mpt2sas_scsih_issue_tm(ioc, handle, 0,
+	    MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
+	    30);
+
+	/*
+	 *  sanity check see whether all commands to this device been
+	 *  completed
+	 */
+	if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
+	    scmd->device->lun, scmd->device->channel))
+		r = FAILED;
+	else
+		r = SUCCESS;
+	ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
+	mutex_unlock(&ioc->tm_cmds.mutex);
+
+ out:
+	printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
+	    ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
+	return r;
+}
+
+/**
+ * scsih_target_reset - eh threads main target reset routine
+ * @sdev: scsi device struct
+ *
+ * Returns SUCCESS if command aborted else FAILED
+ */
+static int
+scsih_target_reset(struct scsi_cmnd *scmd)
+{
+	struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
+	struct MPT2SAS_DEVICE *sas_device_priv_data;
+	struct _sas_device *sas_device;
+	unsigned long flags;
+	u16	handle;
+	int r;
+
+	printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
+	    ioc->name, scmd);
+	scsi_print_command(scmd);
+
+	sas_device_priv_data = scmd->device->hostdata;
+	if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
+		printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
+		    ioc->name, scmd);
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		r = SUCCESS;
+		goto out;
+	}
+
+	/* for hidden raid components obtain the volume_handle */
+	handle = 0;
+	if (sas_device_priv_data->sas_target->flags &
+	    MPT_TARGET_FLAGS_RAID_COMPONENT) {
+		spin_lock_irqsave(&ioc->sas_device_lock, flags);
+		sas_device = _scsih_sas_device_find_by_handle(ioc,
+		   sas_device_priv_data->sas_target->handle);
+		if (sas_device)
+			handle = sas_device->volume_handle;
+		spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
+	} else
+		handle = sas_device_priv_data->sas_target->handle;
+
+	if (!handle) {
+		scmd->result = DID_RESET << 16;
+		r = FAILED;
+		goto out;
+	}
+
+	mutex_lock(&ioc->tm_cmds.mutex);
+	mpt2sas_scsih_issue_tm(ioc, handle, 0,
 	    MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
 
 	/*
@@ -5255,6 +5361,7 @@ static struct scsi_host_template scsih_d
 	.change_queue_type		= scsih_change_queue_type,
 	.eh_abort_handler		= scsih_abort,
 	.eh_device_reset_handler	= scsih_dev_reset,
+	.eh_target_reset_handler	= scsih_target_reset,
 	.eh_host_reset_handler		= scsih_host_reset,
 	.bios_param			= scsih_bios_param,
 	.can_queue			= 1,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND  ioctl
  2009-04-17 16:32 [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND ioctl Eric Moore
@ 2009-04-17 17:50 ` Peter Bogdanovic
  2009-04-17 18:00   ` Moore, Eric
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Bogdanovic @ 2009-04-17 17:50 UTC (permalink / raw)
  To: Eric Moore; +Cc: linux-scsi, James.Bottomley

Eric,

This patch appears to be the same as the 10th patch in the series and
the patch to mpt2sas_ctl.c for _ctl_set_task_mid is missing. The 11th in
the series is available from the series you posted on April 14th so it
isn't really holding me back. I just wanted you to know there was a
mistake in the 2nd posting of this series.

Regards,

Peter Bogdanovic 


On Fri, 2009-04-17 at 10:32 -0600, Eric Moore wrote:
> Adding new eh_target_reset_handler for target reset. Change the
> eh_device_reset_handler so its sending
> MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, instead of
> MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET.  Add new function
> _scsih_scsi_lookup_find_by_lun as a sanity check to insure I_T_L commands are
> completed upon completing lun reset.
> 
> Signed-off-by: Eric Moore <eric.moore@lsi.com>
> 
> diff -uarpN a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
> --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c	2009-04-17 09:04:10.000000000 -0600
> +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c	2009-04-17 09:07:38.000000000 -0600
> @@ -884,6 +884,41 @@ _scsih_scsi_lookup_find_by_target(struct
>  }
> 
>  /**
> + * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
> + * @ioc: per adapter object
> + * @id: target id
> + * @lun: lun number
> + * @channel: channel
> + * Context: This function will acquire ioc->scsi_lookup_lock.
> + *
> + * This will search for a matching channel:id:lun in the scsi_lookup array,
> + * returning 1 if found.
> + */
> +static u8
> +_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
> +    unsigned int lun, int channel)
> +{
> +	u8 found;
> +	unsigned long	flags;
> +	int i;
> +
> +	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> +	found = 0;
> +	for (i = 0 ; i < ioc->request_depth; i++) {
> +		if (ioc->scsi_lookup[i].scmd &&
> +		    (ioc->scsi_lookup[i].scmd->device->id == id &&
> +		    ioc->scsi_lookup[i].scmd->device->channel == channel &&
> +		    ioc->scsi_lookup[i].scmd->device->lun == lun)) {
> +			found = 1;
> +			goto out;
> +		}
> +	}
> + out:
> +	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> +	return found;
> +}
> +
> +/**
>   * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
>   * @ioc: per adapter object
>   * @smid: system request message index
> @@ -1889,7 +1924,6 @@ scsih_abort(struct scsi_cmnd *scmd)
>  	return r;
>  }
> 
> -
>  /**
>   * scsih_dev_reset - eh threads main device reset routine
>   * @sdev: scsi device struct
> @@ -1906,7 +1940,7 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
>  	u16	handle;
>  	int r;
> 
> -	printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
> +	printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
>  	    ioc->name, scmd);
>  	scsi_print_command(scmd);
> 
> @@ -1941,6 +1975,78 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
> 
>  	mutex_lock(&ioc->tm_cmds.mutex);
>  	mpt2sas_scsih_issue_tm(ioc, handle, 0,
> +	    MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
> +	    30);
> +
> +	/*
> +	 *  sanity check see whether all commands to this device been
> +	 *  completed
> +	 */
> +	if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
> +	    scmd->device->lun, scmd->device->channel))
> +		r = FAILED;
> +	else
> +		r = SUCCESS;
> +	ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
> +	mutex_unlock(&ioc->tm_cmds.mutex);
> +
> + out:
> +	printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
> +	    ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> +	return r;
> +}
> +
> +/**
> + * scsih_target_reset - eh threads main target reset routine
> + * @sdev: scsi device struct
> + *
> + * Returns SUCCESS if command aborted else FAILED
> + */
> +static int
> +scsih_target_reset(struct scsi_cmnd *scmd)
> +{
> +	struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
> +	struct MPT2SAS_DEVICE *sas_device_priv_data;
> +	struct _sas_device *sas_device;
> +	unsigned long flags;
> +	u16	handle;
> +	int r;
> +
> +	printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
> +	    ioc->name, scmd);
> +	scsi_print_command(scmd);
> +
> +	sas_device_priv_data = scmd->device->hostdata;
> +	if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
> +		printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
> +		    ioc->name, scmd);
> +		scmd->result = DID_NO_CONNECT << 16;
> +		scmd->scsi_done(scmd);
> +		r = SUCCESS;
> +		goto out;
> +	}
> +
> +	/* for hidden raid components obtain the volume_handle */
> +	handle = 0;
> +	if (sas_device_priv_data->sas_target->flags &
> +	    MPT_TARGET_FLAGS_RAID_COMPONENT) {
> +		spin_lock_irqsave(&ioc->sas_device_lock, flags);
> +		sas_device = _scsih_sas_device_find_by_handle(ioc,
> +		   sas_device_priv_data->sas_target->handle);
> +		if (sas_device)
> +			handle = sas_device->volume_handle;
> +		spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
> +	} else
> +		handle = sas_device_priv_data->sas_target->handle;
> +
> +	if (!handle) {
> +		scmd->result = DID_RESET << 16;
> +		r = FAILED;
> +		goto out;
> +	}
> +
> +	mutex_lock(&ioc->tm_cmds.mutex);
> +	mpt2sas_scsih_issue_tm(ioc, handle, 0,
>  	    MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
> 
>  	/*
> @@ -5255,6 +5361,7 @@ static struct scsi_host_template scsih_d
>  	.change_queue_type		= scsih_change_queue_type,
>  	.eh_abort_handler		= scsih_abort,
>  	.eh_device_reset_handler	= scsih_dev_reset,
> +	.eh_target_reset_handler	= scsih_target_reset,
>  	.eh_host_reset_handler		= scsih_host_reset,
>  	.bios_param			= scsih_bios_param,
>  	.can_queue			= 1,
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Peter Bogdanovic
IBM System x Enablement


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND  ioctl
  2009-04-17 17:50 ` Peter Bogdanovic
@ 2009-04-17 18:00   ` Moore, Eric
  0 siblings, 0 replies; 4+ messages in thread
From: Moore, Eric @ 2009-04-17 18:00 UTC (permalink / raw)
  To: pbog@us.ibm.com
  Cc: linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com

On Friday, April 17, 2009 11:51 AM, Peter Bogdanovic wrote:
> This patch appears to be the same as the 10th patch in the series and
> the patch to mpt2sas_ctl.c for _ctl_set_task_mid is missing. 
> The 11th in
> the series is available from the series you posted on April 14th so it
> isn't really holding me back. I just wanted you to know there was a
> mistake in the 2nd posting of this series.
> 

Oops, your right.  I will post the correct patch for [PATCH 11/14]  here shortly.

Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND  ioctl
@ 2009-04-17 18:04 Eric Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Moore @ 2009-04-17 18:04 UTC (permalink / raw)
  To: linux-scsi; +Cc: James.Bottomley

This patch will find an active mid for a query_task request via the ioctl path.

This code is already there for task_abort, so this patch combining code using
the same fuction _ctl_set_task_mid(), previously _ctl_do_task_abort().

Signed-off-by: Eric Moore <eric.moore@lsi.com>

diff -uarpN a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c	2009-04-13 16:33:48.000000000 -0600
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c	2009-04-13 17:21:01.000000000 -0600
@@ -473,7 +473,7 @@ _ctl_poll(struct file *filep, poll_table
 }
 
 /**
- * _ctl_do_task_abort - assign an active smid to the abort_task
+ * _ctl_set_task_mid - assign an active smid to tm request
  * @ioc: per adapter object
  * @karg - (struct mpt2_ioctl_command)
  * @tm_request - pointer to mf from user space
@@ -482,7 +482,7 @@ _ctl_poll(struct file *filep, poll_table
  * during failure, the reply frame is filled.
  */
 static int
-_ctl_do_task_abort(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
+_ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
     Mpi2SCSITaskManagementRequest_t *tm_request)
 {
 	u8 found = 0;
@@ -494,6 +494,14 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTE
 	Mpi2SCSITaskManagementReply_t *tm_reply;
 	u32 sz;
 	u32 lun;
+	char *desc = NULL;
+
+	if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
+		desc = "abort_task";
+	else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
+		desc = "query_task";
+	else
+		return 0;
 
 	lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
 
@@ -517,13 +525,13 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTE
 	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 
 	if (!found) {
-		dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ABORT_TASK: "
-		    "DevHandle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
-		    tm_request->DevHandle, lun));
+		dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
+		    "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
+		    desc, tm_request->DevHandle, lun));
 		tm_reply = ioc->ctl_cmds.reply;
 		tm_reply->DevHandle = tm_request->DevHandle;
 		tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
-		tm_reply->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK;
+		tm_reply->TaskType = tm_request->TaskType;
 		tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
 		tm_reply->VP_ID = tm_request->VP_ID;
 		tm_reply->VF_ID = tm_request->VF_ID;
@@ -535,9 +543,9 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTE
 		return 1;
 	}
 
-	dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ABORT_TASK: "
-	    "DevHandle(0x%04x), lun(%d), smid(%d)\n", ioc->name,
-	    tm_request->DevHandle, lun, tm_request->TaskMID));
+	dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
+	    "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
+	    desc, tm_request->DevHandle, lun, tm_request->TaskMID));
 	return 0;
 }
 
@@ -739,8 +747,10 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPT
 		    (Mpi2SCSITaskManagementRequest_t *)mpi_request;
 
 		if (tm_request->TaskType ==
-		    MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
-			if (_ctl_do_task_abort(ioc, &karg, tm_request)) {
+		    MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
+		    tm_request->TaskType ==
+		    MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
+			if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
 				mpt2sas_base_free_smid(ioc, smid);
 				goto out;
 			}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-17 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-17 16:32 [PATCH 11/14 - 2nd post] mpt2sas: add query task support for MPT2COMMAND ioctl Eric Moore
2009-04-17 17:50 ` Peter Bogdanovic
2009-04-17 18:00   ` Moore, Eric
  -- strict thread matches above, loose matches on Subject: below --
2009-04-17 18:04 Eric Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox