All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv4 00/12] mpt3sas: lockless command submission
@ 2017-02-22 10:31 Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors Hannes Reinecke
                   ` (11 more replies)
  0 siblings, 12 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke

Hi all,

this is the first part of my patchset to enable scsi multiqueue for the
mpt3sas driver.
While the HBA only has a single mailbox register for submitting commands,
it does have individual receive queues per MSI-X interrupt and as such
does benefit from converting it to full multiqueue support.

On request from Broadcom the patchset has been split in two parts, one
to enable lockless command submission and a secondary one for exposing
all hardware queues to the OS.

As usual, comments and reviews are welcome.

Changes to v1:
- Include reviews from Christoph
- Use reserved commands for ioctl passthrough commands
- Include reviews from Sreekanth

Changes to v2:
- Rework ioctl code to not use blk_mq_busy_iter
- Open-code mpt3sas_scsi_direct_io_(get,set)

Changes to v3:
- Simplify task management code
- Simplify _wait_for_commands_to_complete
- Use first reserved smid for ioctl passthrough

Hannes Reinecke (12):
  mpt3sas: switch to pci_alloc_irq_vectors
  mpt3sas: set default value for cb_idx
  mpt3sas: use 'list_splice_init()'
  mpt3sas: separate out _base_recovery_check()
  mpt3sas: open-code _scsih_scsi_lookup_get()
  mpt3sas: Introduce mpt3sas_get_st_from_smid()
  mpt3sas: check command status before attempting abort
  mpt3sas: always use first reserved smid for ioctl passthrough
  mpt3sas: simplify task management functions
  mpt3sas: simplify mpt3sas_scsi_issue_tm()
  mpt3sas: simplify _wait_for_commands_to_complete()
  mpt3sas: lockless command submission

 drivers/scsi/mpt3sas/mpt3sas_base.c      | 277 ++++++++++++++---------------
 drivers/scsi/mpt3sas/mpt3sas_base.h      |  29 ++--
 drivers/scsi/mpt3sas/mpt3sas_ctl.c       |  31 ++--
 drivers/scsi/mpt3sas/mpt3sas_scsih.c     | 289 +++++++------------------------
 drivers/scsi/mpt3sas/mpt3sas_warpdrive.c |  33 +---
 5 files changed, 220 insertions(+), 439 deletions(-)

-- 
1.8.5.6

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

* [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-23 22:04   ` Martin K. Petersen
  2017-02-22 10:31 ` [PATCHv4 02/12] mpt3sas: set default value for cb_idx Hannes Reinecke
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Cleanup the MSI-X handling allowing us to use
the PCI-layer provided vector allocation.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 105 +++++++++++++++++-------------------
 drivers/scsi/mpt3sas/mpt3sas_base.h |   2 -
 2 files changed, 48 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index a3fe1fb..5b7aec5 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -1148,7 +1148,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 		/* TMs are on msix_index == 0 */
 		if (reply_q->msix_index == 0)
 			continue;
-		synchronize_irq(reply_q->vector);
+		synchronize_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index));
 	}
 }
 
@@ -1837,11 +1837,8 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 
 	list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
 		list_del(&reply_q->list);
-		if (smp_affinity_enable) {
-			irq_set_affinity_hint(reply_q->vector, NULL);
-			free_cpumask_var(reply_q->affinity_hint);
-		}
-		free_irq(reply_q->vector, reply_q);
+		free_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index),
+			 reply_q);
 		kfree(reply_q);
 	}
 }
@@ -1850,13 +1847,13 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
  * _base_request_irq - request irq
  * @ioc: per adapter object
  * @index: msix index into vector table
- * @vector: irq vector
  *
  * Inserting respective reply_queue into the list.
  */
 static int
-_base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
+_base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index)
 {
+	struct pci_dev *pdev = ioc->pdev;
 	struct adapter_reply_queue *reply_q;
 	int r;
 
@@ -1868,14 +1865,6 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	}
 	reply_q->ioc = ioc;
 	reply_q->msix_index = index;
-	reply_q->vector = vector;
-
-	if (smp_affinity_enable) {
-		if (!zalloc_cpumask_var(&reply_q->affinity_hint, GFP_KERNEL)) {
-			kfree(reply_q);
-			return -ENOMEM;
-		}
-	}
 
 	atomic_set(&reply_q->busy, 0);
 	if (ioc->msix_enable)
@@ -1884,12 +1873,11 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	else
 		snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
 		    ioc->driver_name, ioc->id);
-	r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
-	    reply_q);
+	r = request_irq(pci_irq_vector(pdev, index), _base_interrupt,
+			IRQF_SHARED, reply_q->name, reply_q);
 	if (r) {
 		pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n",
-		    reply_q->name, vector);
-		free_cpumask_var(reply_q->affinity_hint);
+		       reply_q->name, pci_irq_vector(pdev, index));
 		kfree(reply_q);
 		return -EBUSY;
 	}
@@ -1925,6 +1913,21 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	if (!nr_msix)
 		return;
 
+	if (smp_affinity_enable) {
+		list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
+			const cpumask_t *mask = pci_irq_get_affinity(ioc->pdev,
+							reply_q->msix_index);
+			if (!mask) {
+				pr_warn(MPT3SAS_FMT "no affinity for msi %x\n",
+					ioc->name, reply_q->msix_index);
+				continue;
+			}
+
+			for_each_cpu(cpu, mask)
+				ioc->cpu_msix_table[cpu] = reply_q->msix_index;
+		}
+		return;
+	}
 	cpu = cpumask_first(cpu_online_mask);
 
 	list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
@@ -1938,18 +1941,9 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 			group++;
 
 		for (i = 0 ; i < group ; i++) {
-			ioc->cpu_msix_table[cpu] = index;
-			if (smp_affinity_enable)
-				cpumask_or(reply_q->affinity_hint,
-				   reply_q->affinity_hint, get_cpu_mask(cpu));
+			ioc->cpu_msix_table[cpu] = reply_q->msix_index;
 			cpu = cpumask_next(cpu, cpu_online_mask);
 		}
-		if (smp_affinity_enable)
-			if (irq_set_affinity_hint(reply_q->vector,
-					   reply_q->affinity_hint))
-				dinitprintk(ioc, pr_info(MPT3SAS_FMT
-				 "Err setting affinity hint to irq vector %d\n",
-				 ioc->name, reply_q->vector));
 		index++;
 	}
 }
@@ -1976,10 +1970,10 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 static int
 _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
 {
-	struct msix_entry *entries, *a;
 	int r;
 	int i, local_max_msix_vectors;
 	u8 try_msix = 0;
+	unsigned int irq_flags = PCI_IRQ_MSIX;
 
 	if (msix_disable == -1 || msix_disable == 0)
 		try_msix = 1;
@@ -1991,7 +1985,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 		goto try_ioapic;
 
 	ioc->reply_queue_count = min_t(int, ioc->cpu_count,
-	    ioc->msix_vector_count);
+		ioc->msix_vector_count);
 
 	printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores"
 	  ": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count,
@@ -2002,56 +1996,51 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	else
 		local_max_msix_vectors = max_msix_vectors;
 
-	if (local_max_msix_vectors > 0) {
+	if (local_max_msix_vectors > 0)
 		ioc->reply_queue_count = min_t(int, local_max_msix_vectors,
 			ioc->reply_queue_count);
-		ioc->msix_vector_count = ioc->reply_queue_count;
-	} else if (local_max_msix_vectors == 0)
+	else if (local_max_msix_vectors == 0)
 		goto try_ioapic;
 
 	if (ioc->msix_vector_count < ioc->cpu_count)
 		smp_affinity_enable = 0;
 
-	entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
-	    GFP_KERNEL);
-	if (!entries) {
-		dfailprintk(ioc, pr_info(MPT3SAS_FMT
-			"kcalloc failed @ at %s:%d/%s() !!!\n",
-			ioc->name, __FILE__, __LINE__, __func__));
-		goto try_ioapic;
-	}
+	if (smp_affinity_enable)
+		irq_flags |= PCI_IRQ_AFFINITY;
 
-	for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
-		a->entry = i;
-
-	r = pci_enable_msix_exact(ioc->pdev, entries, ioc->reply_queue_count);
-	if (r) {
+	r = pci_alloc_irq_vectors(ioc->pdev, 1, ioc->reply_queue_count,
+				  irq_flags);
+	if (r < 0) {
 		dfailprintk(ioc, pr_info(MPT3SAS_FMT
-			"pci_enable_msix_exact failed (r=%d) !!!\n",
+			"pci_alloc_irq_vectors failed (r=%d) !!!\n",
 			ioc->name, r));
-		kfree(entries);
 		goto try_ioapic;
 	}
 
 	ioc->msix_enable = 1;
-	for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
-		r = _base_request_irq(ioc, i, a->vector);
+	ioc->reply_queue_count = r;
+	for (i = 0; i < ioc->reply_queue_count; i++) {
+		r = _base_request_irq(ioc, i);
 		if (r) {
 			_base_free_irq(ioc);
 			_base_disable_msix(ioc);
-			kfree(entries);
 			goto try_ioapic;
 		}
 	}
 
-	kfree(entries);
 	return 0;
 
 /* failback to io_apic interrupt routing */
  try_ioapic:
 
 	ioc->reply_queue_count = 1;
-	r = _base_request_irq(ioc, 0, ioc->pdev->irq);
+	r = pci_alloc_irq_vectors(ioc->pdev, 1, 1, PCI_IRQ_LEGACY);
+	if (r < 0) {
+		dfailprintk(ioc, pr_info(MPT3SAS_FMT
+			"pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n",
+			ioc->name, r));
+	} else
+		r = _base_request_irq(ioc, 0);
 
 	return r;
 }
@@ -2222,7 +2211,8 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
 		pr_info(MPT3SAS_FMT "%s: IRQ %d\n",
 		    reply_q->name,  ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
-		    "IO-APIC enabled"), reply_q->vector);
+		    "IO-APIC enabled"),
+		    pci_irq_vector(ioc->pdev, reply_q->msix_index));
 
 	pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
 	    ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
@@ -5357,7 +5347,8 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 		    sizeof(resource_size_t *), GFP_KERNEL);
 		if (!ioc->reply_post_host_index) {
 			dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation "
-				"for cpu_msix_table failed!!!\n", ioc->name));
+				"for reply_post_host_index failed!!!\n",
+				ioc->name));
 			r = -ENOMEM;
 			goto out_free_resources;
 		}
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index b2f3e24..1f460f2 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -719,12 +719,10 @@ struct _event_ack_list {
 struct adapter_reply_queue {
 	struct MPT3SAS_ADAPTER	*ioc;
 	u8			msix_index;
-	unsigned int		vector;
 	u32			reply_post_host_index;
 	Mpi2ReplyDescriptorsUnion_t *reply_post_free;
 	char			name[MPT_NAME_LENGTH];
 	atomic_t		busy;
-	cpumask_var_t		affinity_hint;
 	struct list_head	list;
 };
 
-- 
1.8.5.6

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

* [PATCHv4 02/12] mpt3sas: set default value for cb_idx
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 03/12] mpt3sas: use 'list_splice_init()' Hannes Reinecke
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

No functional change.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 5b7aec5..3062171 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -873,7 +873,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
 	int i;
-	u8 cb_idx;
+	u8 cb_idx = 0xFF;
 
 	if (smid < ioc->hi_priority_smid) {
 		i = smid - 1;
@@ -884,8 +884,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	} else if (smid <= ioc->hba_queue_depth) {
 		i = smid - ioc->internal_smid;
 		cb_idx = ioc->internal_lookup[i].cb_idx;
-	} else
-		cb_idx = 0xFF;
+	}
 	return cb_idx;
 }
 
-- 
1.8.5.6

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

* [PATCHv4 03/12] mpt3sas: use 'list_splice_init()'
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 02/12] mpt3sas: set default value for cb_idx Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 04/12] mpt3sas: separate out _base_recovery_check() Hannes Reinecke
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Use 'list_splice_init()' instead of hand-crafted function.
No functional change.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 3062171..6229eda 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2395,20 +2395,13 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 {
 	unsigned long flags;
 	int i;
-	struct chain_tracker *chain_req, *next;
 
 	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
 	if (smid < ioc->hi_priority_smid) {
 		/* scsiio queue */
 		i = smid - 1;
-		if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
-			list_for_each_entry_safe(chain_req, next,
-			    &ioc->scsi_lookup[i].chain_list, tracker_list) {
-				list_del_init(&chain_req->tracker_list);
-				list_add(&chain_req->tracker_list,
-				    &ioc->free_chain_list);
-			}
-		}
+		list_splice_init(&ioc->scsi_lookup[i].chain_list,
+				 &ioc->free_chain_list);
 		ioc->scsi_lookup[i].cb_idx = 0xFF;
 		ioc->scsi_lookup[i].scmd = NULL;
 		ioc->scsi_lookup[i].direct_io = 0;
-- 
1.8.5.6

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

* [PATCHv4 04/12] mpt3sas: separate out _base_recovery_check()
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (2 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 03/12] mpt3sas: use 'list_splice_init()' Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 05/12] mpt3sas: open-code _scsih_scsi_lookup_get() Hannes Reinecke
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

No functional change.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 6229eda..0133e7c 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2383,6 +2383,19 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	return smid;
 }
 
+static void
+_base_recovery_check(struct MPT3SAS_ADAPTER *ioc)
+{
+	/*
+	 * See _wait_for_commands_to_complete() call with regards to this code.
+	 */
+	if (ioc->shost_recovery && ioc->pending_io_count) {
+		if (ioc->pending_io_count == 1)
+			wake_up(&ioc->reset_wq);
+		ioc->pending_io_count--;
+	}
+}
+
 /**
  * mpt3sas_base_free_smid - put smid back on free_list
  * @ioc: per adapter object
@@ -2408,15 +2421,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 		list_add(&ioc->scsi_lookup[i].tracker_list, &ioc->free_list);
 		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 
-		/*
-		 * See _wait_for_commands_to_complete() call with regards
-		 * to this code.
-		 */
-		if (ioc->shost_recovery && ioc->pending_io_count) {
-			if (ioc->pending_io_count == 1)
-				wake_up(&ioc->reset_wq);
-			ioc->pending_io_count--;
-		}
+		_base_recovery_check(ioc);
 		return;
 	} else if (smid < ioc->internal_smid) {
 		/* hi-priority */
-- 
1.8.5.6

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

* [PATCHv4 05/12] mpt3sas: open-code _scsih_scsi_lookup_get()
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (3 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 04/12] mpt3sas: separate out _base_recovery_check() Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 06/12] mpt3sas: Introduce mpt3sas_get_st_from_smid() Hannes Reinecke
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Just a wrapper around the scsi lookup array and only used
in one place, so open-code it.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index b8cd0a1..52de355 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1061,19 +1061,6 @@ struct _sas_node *
 }
 
 /**
- * _scsih_scsi_lookup_get - returns scmd entry
- * @ioc: per adapter object
- * @smid: system request message index
- *
- * Returns the smid stored scmd pointer.
- */
-static struct scsi_cmnd *
-_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
-{
-	return ioc->scsi_lookup[smid - 1].scmd;
-}
-
-/**
  * __scsih_scsi_lookup_get_clear - returns scmd entry without
  *						holding any lock.
  * @ioc: per adapter object
@@ -6126,7 +6113,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
 		if (ioc->shost_recovery)
 			goto out;
-		scmd = _scsih_scsi_lookup_get(ioc, smid);
+		scmd = ioc->scsi_lookup[smid - 1].scmd;
 		if (!scmd)
 			continue;
 		sdev = scmd->device;
-- 
1.8.5.6

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

* [PATCHv4 06/12] mpt3sas: Introduce mpt3sas_get_st_from_smid()
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (4 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 05/12] mpt3sas: open-code _scsih_scsi_lookup_get() Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 07/12] mpt3sas: check command status before attempting abort Hannes Reinecke
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Abstract accesses to the scsi_lookup array by introducing
mpt3sas_get_st_from_smid().

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c      | 22 ++++++++++++++++++----
 drivers/scsi/mpt3sas/mpt3sas_base.h      |  2 ++
 drivers/scsi/mpt3sas/mpt3sas_scsih.c     |  7 ++++---
 drivers/scsi/mpt3sas/mpt3sas_warpdrive.c |  4 +++-
 4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 0133e7c..3f9148c 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -862,6 +862,15 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	return 1;
 }
 
+struct scsiio_tracker *
+mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
+{
+	if (WARN_ON(!smid) ||
+	    WARN_ON(smid >= ioc->hi_priority_smid))
+		return NULL;
+	return &ioc->scsi_lookup[smid - 1];
+}
+
 /**
  * _base_get_cb_idx - obtain the callback index
  * @ioc: per adapter object
@@ -876,8 +885,11 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	u8 cb_idx = 0xFF;
 
 	if (smid < ioc->hi_priority_smid) {
-		i = smid - 1;
-		cb_idx = ioc->scsi_lookup[i].cb_idx;
+		struct scsiio_tracker *st;
+
+		st = mpt3sas_get_st_from_smid(ioc, smid);
+		if (st)
+			cb_idx = st->cb_idx;
 	} else if (smid < ioc->internal_smid) {
 		i = smid - ioc->hi_priority_smid;
 		cb_idx = ioc->hpr_lookup[i].cb_idx;
@@ -1268,6 +1280,7 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
 	struct chain_tracker *chain_req;
+	struct scsiio_tracker *st;
 	unsigned long flags;
 
 	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
@@ -1280,8 +1293,9 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 	chain_req = list_entry(ioc->free_chain_list.next,
 	    struct chain_tracker, tracker_list);
 	list_del_init(&chain_req->tracker_list);
-	list_add_tail(&chain_req->tracker_list,
-	    &ioc->scsi_lookup[smid - 1].chain_list);
+	st = mpt3sas_get_st_from_smid(ioc, smid);
+	if (st)
+		list_add_tail(&chain_req->tracker_list, &st->chain_list);
 	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 	return chain_req;
 }
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 1f460f2..74186e3 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1247,6 +1247,8 @@ __le32 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc,
 u16 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
 u16 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
 	struct scsi_cmnd *scmd);
+struct scsiio_tracker * mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc,
+	u16 smid);
 
 u16 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
 void mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 52de355..6bc9291 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2269,7 +2269,7 @@ struct _sas_node *
 	}
 
 	if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
-		scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
+		scsi_lookup = mpt3sas_get_st_from_smid(ioc, smid_task);
 
 	dtmprintk(ioc, pr_info(MPT3SAS_FMT
 		"sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
@@ -2287,7 +2287,8 @@ struct _sas_node *
 	mpt3sas_scsih_set_tm_flag(ioc, handle);
 	init_completion(&ioc->tm_cmds.done);
 	if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
-			(scsi_lookup->msix_io < ioc->reply_queue_count))
+	    scsi_lookup &&
+	    (scsi_lookup->msix_io < ioc->reply_queue_count))
 		msix_task = scsi_lookup->msix_io;
 	else
 		msix_task = 0;
@@ -2328,7 +2329,7 @@ struct _sas_node *
 	switch (type) {
 	case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
 		rc = SUCCESS;
-		if (scsi_lookup->scmd == NULL)
+		if (scsi_lookup && scsi_lookup->scmd == NULL)
 			break;
 		rc = FAILED;
 		break;
diff --git a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
index 540bd50..06e3f7d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
@@ -270,7 +270,9 @@
 inline u8
 mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
-	return ioc->scsi_lookup[smid - 1].direct_io;
+	struct scsiio_tracker *st = mpt3sas_get_st_from_smid(ioc, smid);
+
+	return st ? st->direct_io : 0;
 }
 
 /**
-- 
1.8.5.6

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

* [PATCHv4 07/12] mpt3sas: check command status before attempting abort
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (5 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 06/12] mpt3sas: Introduce mpt3sas_get_st_from_smid() Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 08/12] mpt3sas: always use first reserved smid for ioctl passthrough Hannes Reinecke
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

When attempting a command abort we should check the command status
prior to sending the abort; the command might've been completed
already.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 6bc9291..1c45fb3 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2261,6 +2261,14 @@ struct _sas_node *
 		return (!rc) ? SUCCESS : FAILED;
 	}
 
+	if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
+		scsi_lookup = mpt3sas_get_st_from_smid(ioc, smid_task);
+		if (!scsi_lookup)
+			return FAILED;
+		if (scsi_lookup->cb_idx == 0xFF)
+			return SUCCESS;
+	}
+
 	smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
 	if (!smid) {
 		pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
@@ -2268,9 +2276,6 @@ struct _sas_node *
 		return FAILED;
 	}
 
-	if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
-		scsi_lookup = mpt3sas_get_st_from_smid(ioc, smid_task);
-
 	dtmprintk(ioc, pr_info(MPT3SAS_FMT
 		"sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
 		ioc->name, handle, type, smid_task));
-- 
1.8.5.6

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

* [PATCHv4 08/12] mpt3sas: always use first reserved smid for ioctl passthrough
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (6 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 07/12] mpt3sas: check command status before attempting abort Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 09/12] mpt3sas: simplify task management functions Hannes Reinecke
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

ioctl passthrough commands require a SCSIIO smid, but cannot
easily integrate with the block layer. But the driver already
has reserved some SCSIIO smids and we're only ever allowing
one ioctl command at a time we can use the first reserved smid
for ioctl commands.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 19 +++++++++++++------
 drivers/scsi/mpt3sas/mpt3sas_ctl.c  | 10 ++--------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 3f9148c..e6aafa5 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -882,14 +882,18 @@ struct scsiio_tracker *
 _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
 	int i;
+	u16 ctl_smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1;
 	u8 cb_idx = 0xFF;
 
 	if (smid < ioc->hi_priority_smid) {
 		struct scsiio_tracker *st;
 
-		st = mpt3sas_get_st_from_smid(ioc, smid);
-		if (st)
-			cb_idx = st->cb_idx;
+		if (smid < ctl_smid) {
+			st = mpt3sas_get_st_from_smid(ioc, smid);
+			if (st)
+				cb_idx = st->cb_idx;
+		} else if (smid == ctl_smid)
+			cb_idx = ioc->ctl_cb_idx;
 	} else if (smid < ioc->internal_smid) {
 		i = smid - ioc->hi_priority_smid;
 		cb_idx = ioc->hpr_lookup[i].cb_idx;
@@ -2432,7 +2436,9 @@ struct scsiio_tracker *
 		ioc->scsi_lookup[i].cb_idx = 0xFF;
 		ioc->scsi_lookup[i].scmd = NULL;
 		ioc->scsi_lookup[i].direct_io = 0;
-		list_add(&ioc->scsi_lookup[i].tracker_list, &ioc->free_list);
+		if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
+			list_add(&ioc->scsi_lookup[i].tracker_list,
+				 &ioc->free_list);
 		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 
 		_base_recovery_check(ioc);
@@ -5174,8 +5180,9 @@ struct scsiio_tracker *
 		ioc->scsi_lookup[i].smid = smid;
 		ioc->scsi_lookup[i].scmd = NULL;
 		ioc->scsi_lookup[i].direct_io = 0;
-		list_add_tail(&ioc->scsi_lookup[i].tracker_list,
-		    &ioc->free_list);
+		if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
+			list_add_tail(&ioc->scsi_lookup[i].tracker_list,
+				      &ioc->free_list);
 	}
 
 	/* hi-priority queue */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 02fe1c4..4476bba 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -719,14 +719,8 @@ enum block_state {
 			goto out;
 		}
 	} else {
-
-		smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL);
-		if (!smid) {
-			pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
-			    ioc->name, __func__);
-			ret = -EAGAIN;
-			goto out;
-		}
+		/* Use first reserved smid for passthrough ioctls */
+		smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1;
 	}
 
 	ret = 0;
-- 
1.8.5.6

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

* [PATCHv4 09/12] mpt3sas: simplify task management functions
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (7 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 08/12] mpt3sas: always use first reserved smid for ioctl passthrough Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-03-06  5:16   ` Sreekanth Reddy
  2017-02-22 10:31 ` [PATCHv4 10/12] mpt3sas: simplify mpt3sas_scsi_issue_tm() Hannes Reinecke
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

One can simply check 'target_busy' or 'device_busy' when figuring
out if there are outstanding commands; no need to painstakingly
counting them by hand.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 88 +++---------------------------------
 1 file changed, 7 insertions(+), 81 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 1c45fb3..e0cb35d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1133,74 +1133,6 @@ struct _sas_node *
 }
 
 /**
- * _scsih_scsi_lookup_find_by_target - search for matching channel:id
- * @ioc: per adapter object
- * @id: target id
- * @channel: channel
- * Context: This function will acquire ioc->scsi_lookup_lock.
- *
- * This will search for a matching channel:id in the scsi_lookup array,
- * returning 1 if found.
- */
-static u8
-_scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
-	int channel)
-{
-	u8 found;
-	unsigned long	flags;
-	int i;
-
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	found = 0;
-	for (i = 0 ; i < ioc->scsiio_depth; i++) {
-		if (ioc->scsi_lookup[i].scmd &&
-		    (ioc->scsi_lookup[i].scmd->device->id == id &&
-		    ioc->scsi_lookup[i].scmd->device->channel == channel)) {
-			found = 1;
-			goto out;
-		}
-	}
- out:
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-	return found;
-}
-
-/**
- * _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 MPT3SAS_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->scsiio_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_change_queue_depth - setting device queue depth
  * @sdev: scsi device struct
  * @qdepth: requested queue depth
@@ -2339,19 +2271,9 @@ struct _sas_node *
 		rc = FAILED;
 		break;
 
-	case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
-		if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
-			rc = FAILED;
-		else
-			rc = SUCCESS;
-		break;
 	case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
 	case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
-		if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
-			rc = FAILED;
-		else
-			rc = SUCCESS;
-		break;
+	case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
 	case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
 		rc = SUCCESS;
 		break;
@@ -2554,7 +2476,9 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
 	    scmd->device->id, scmd->device->lun,
 	    MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
-
+	/* Check for busy commands after reset */
+	if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
+		r = FAILED;
  out:
 	sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
 	    ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
@@ -2616,7 +2540,9 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
 	    scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
 	    30);
-
+	/* Check for busy commands after reset */
+	if (r == SUCCESS && atomic_read(&starget->target_busy))
+		r = FAILED;
  out:
 	starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
 	    ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
-- 
1.8.5.6

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

* [PATCHv4 10/12] mpt3sas: simplify mpt3sas_scsi_issue_tm()
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (8 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 09/12] mpt3sas: simplify task management functions Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete() Hannes Reinecke
  2017-02-22 10:31 ` [PATCHv4 12/12] mpt3sas: lockless command submission Hannes Reinecke
  11 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Move the check for outstanding commands out of the function
allowing us to simplify the overall code.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.h  |   6 +-
 drivers/scsi/mpt3sas/mpt3sas_ctl.c   |   4 +-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 106 ++++++++++++-----------------------
 3 files changed, 41 insertions(+), 75 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 74186e3..4ecc2c1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1289,11 +1289,9 @@ u8 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
 void mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase);
 
 int mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
-	uint channel, uint id, uint lun, u8 type, u16 smid_task,
-	ulong timeout);
+	u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout);
 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
-	uint channel, uint id, uint lun, u8 type, u16 smid_task,
-	ulong timeout);
+	u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout);
 
 void mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle);
 void mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 4476bba..dd03d2c 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -1027,8 +1027,8 @@ enum block_state {
 				le16_to_cpu(mpi_request->FunctionDependent1));
 			mpt3sas_halt_firmware(ioc);
 			mpt3sas_scsih_issue_locked_tm(ioc,
-			    le16_to_cpu(mpi_request->FunctionDependent1), 0, 0,
-			    0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
+			    le16_to_cpu(mpi_request->FunctionDependent1), 0,
+			    MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, 30);
 		} else
 			mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
 	}
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index e0cb35d..f114ef7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1111,25 +1111,24 @@ struct _sas_node *
  * This will search for a scmd pointer in the scsi_lookup array,
  * returning the revelent smid.  A returned value of zero means invalid.
  */
-static u16
+struct scsiio_tracker *
 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
 	*scmd)
 {
-	u16 smid;
-	unsigned long	flags;
+	struct scsiio_tracker *st = NULL;
+	unsigned long flags;
 	int i;
 
 	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	smid = 0;
 	for (i = 0; i < ioc->scsiio_depth; i++) {
 		if (ioc->scsi_lookup[i].scmd == scmd) {
-			smid = ioc->scsi_lookup[i].smid;
+			st = &ioc->scsi_lookup[i];
 			goto out;
 		}
 	}
  out:
 	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-	return smid;
+	return st;
 }
 
 /**
@@ -2136,32 +2135,30 @@ struct _sas_node *
 /**
  * mpt3sas_scsih_issue_tm - main routine for sending tm requests
  * @ioc: per adapter struct
- * @device_handle: device handle
- * @channel: the channel assigned by the OS
- * @id: the id assigned by the OS
+ * @handle: device handle
  * @lun: lun number
  * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  * @smid_task: smid assigned to the task
+ * @msix_task: MSIX table index supplied by the OS
  * @timeout: timeout in seconds
  * Context: user
  *
  * A generic API for sending task management requests to firmware.
  *
  * The callback index is set inside `ioc->tm_cb_idx`.
+ * The caller is responsible to check for outstanding commands.
  *
  * Return SUCCESS or FAILED.
  */
 int
-mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
-	uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
+mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
+	u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout)
 {
 	Mpi2SCSITaskManagementRequest_t *mpi_request;
 	Mpi2SCSITaskManagementReply_t *mpi_reply;
 	u16 smid = 0;
 	u32 ioc_state;
-	struct scsiio_tracker *scsi_lookup = NULL;
 	int rc;
-	u16 msix_task = 0;
 
 	lockdep_assert_held(&ioc->tm_cmds.mutex);
 
@@ -2193,14 +2190,6 @@ struct _sas_node *
 		return (!rc) ? SUCCESS : FAILED;
 	}
 
-	if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
-		scsi_lookup = mpt3sas_get_st_from_smid(ioc, smid_task);
-		if (!scsi_lookup)
-			return FAILED;
-		if (scsi_lookup->cb_idx == 0xFF)
-			return SUCCESS;
-	}
-
 	smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
 	if (!smid) {
 		pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
@@ -2223,12 +2212,6 @@ struct _sas_node *
 	int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
 	mpt3sas_scsih_set_tm_flag(ioc, handle);
 	init_completion(&ioc->tm_cmds.done);
-	if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
-	    scsi_lookup &&
-	    (scsi_lookup->msix_io < ioc->reply_queue_count))
-		msix_task = scsi_lookup->msix_io;
-	else
-		msix_task = 0;
 	ioc->put_smid_hi_priority(ioc, smid, msix_task);
 	wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
 	if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
@@ -2262,25 +2245,7 @@ struct _sas_node *
 				    sizeof(Mpi2SCSITaskManagementRequest_t)/4);
 		}
 	}
-
-	switch (type) {
-	case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
-		rc = SUCCESS;
-		if (scsi_lookup && scsi_lookup->scmd == NULL)
-			break;
-		rc = FAILED;
-		break;
-
-	case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
-	case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
-	case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
-	case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
-		rc = SUCCESS;
-		break;
-	default:
-		rc = FAILED;
-		break;
-	}
+	rc = SUCCESS;
 
 out:
 	mpt3sas_scsih_clear_tm_flag(ioc, handle);
@@ -2289,13 +2254,13 @@ struct _sas_node *
 }
 
 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
-	uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
+	u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout)
 {
 	int ret;
 
 	mutex_lock(&ioc->tm_cmds.mutex);
-	ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type,
-			smid_task, timeout);
+	ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task,
+			msix_task, timeout);
 	mutex_unlock(&ioc->tm_cmds.mutex);
 
 	return ret;
@@ -2376,7 +2341,7 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 {
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
 	struct MPT3SAS_DEVICE *sas_device_priv_data;
-	u16 smid;
+	struct scsiio_tracker *st = NULL;
 	u16 handle;
 	int r;
 
@@ -2395,8 +2360,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 	}
 
 	/* search for the command */
-	smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
-	if (!smid) {
+	st = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
+	if (!st) {
 		scmd->result = DID_RESET << 16;
 		r = SUCCESS;
 		goto out;
@@ -2414,10 +2379,12 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 	mpt3sas_halt_firmware(ioc);
 
 	handle = sas_device_priv_data->sas_target->handle;
-	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
-	    scmd->device->id, scmd->device->lun,
-	    MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
-
+	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
+		MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
+		st->smid, st->msix_io, 30);
+	/* Command must be cleared after abort */
+	if (r == SUCCESS && st->scmd)
+		r = FAILED;
  out:
 	sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
 	    ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
@@ -2473,9 +2440,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 		goto out;
 	}
 
-	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
-	    scmd->device->id, scmd->device->lun,
-	    MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
+	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
+		MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, 30);
 	/* Check for busy commands after reset */
 	if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
 		r = FAILED;
@@ -2537,9 +2503,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 		goto out;
 	}
 
-	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
-	    scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
-	    30);
+	r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0,
+		MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, 30);
 	/* Check for busy commands after reset */
 	if (r == SUCCESS && atomic_read(&starget->target_busy))
 		r = FAILED;
@@ -6004,6 +5969,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 {
 	struct scsi_cmnd *scmd;
 	struct scsi_device *sdev;
+	struct scsiio_tracker *st;
 	u16 smid, handle;
 	u32 lun;
 	struct MPT3SAS_DEVICE *sas_device_priv_data;
@@ -6045,7 +6011,8 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
 		if (ioc->shost_recovery)
 			goto out;
-		scmd = ioc->scsi_lookup[smid - 1].scmd;
+		st = &ioc->scsi_lookup[smid - 1];
+		scmd = st->scmd;
 		if (!scmd)
 			continue;
 		sdev = scmd->device;
@@ -6069,8 +6036,9 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 			goto out;
 
 		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-		r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
-		    MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
+		r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
+			MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid,
+			st->msix_io, 30);
 		if (r == FAILED) {
 			sdev_printk(KERN_WARNING, sdev,
 			    "mpt3sas_scsih_issue_tm: FAILED when sending "
@@ -6109,10 +6077,10 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 		if (ioc->shost_recovery)
 			goto out_no_lock;
 
-		r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
-		    sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
-		    30);
-		if (r == FAILED) {
+		r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
+			MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
+			st->msix_io, 30);
+		if (r == FAILED || st->scmd) {
 			sdev_printk(KERN_WARNING, sdev,
 			    "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
 			    "scmd(%p)\n", scmd);
-- 
1.8.5.6

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

* [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete()
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (9 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 10/12] mpt3sas: simplify mpt3sas_scsi_issue_tm() Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-03-03 11:57   ` Sreekanth Reddy
  2017-02-22 10:31 ` [PATCHv4 12/12] mpt3sas: lockless command submission Hannes Reinecke
  11 siblings, 1 reply; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Use 'host_busy' instead of counting outstanding commands by hand.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index e6aafa5..169d185 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2408,9 +2408,9 @@ struct scsiio_tracker *
 	 * See _wait_for_commands_to_complete() call with regards to this code.
 	 */
 	if (ioc->shost_recovery && ioc->pending_io_count) {
-		if (ioc->pending_io_count == 1)
+		ioc->pending_io_count = atomic_read(&ioc->shost->host_busy);
+		if (ioc->pending_io_count == 0)
 			wake_up(&ioc->reset_wq);
-		ioc->pending_io_count--;
 	}
 }
 
@@ -5687,15 +5687,13 @@ struct scsiio_tracker *
  * _wait_for_commands_to_complete - reset controller
  * @ioc: Pointer to MPT_ADAPTER structure
  *
- * This function waiting(3s) for all pending commands to complete
+ * This function is waiting 10s for all pending commands to complete
  * prior to putting controller in reset.
  */
 static void
 _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc)
 {
 	u32 ioc_state;
-	unsigned long flags;
-	u16 i;
 
 	ioc->pending_io_count = 0;
 
@@ -5704,11 +5702,7 @@ struct scsiio_tracker *
 		return;
 
 	/* pending command count */
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	for (i = 0; i < ioc->scsiio_depth; i++)
-		if (ioc->scsi_lookup[i].cb_idx != 0xFF)
-			ioc->pending_io_count++;
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+	ioc->pending_io_count = atomic_read(&ioc->shost->host_busy);
 
 	if (!ioc->pending_io_count)
 		return;
-- 
1.8.5.6

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

* [PATCHv4 12/12] mpt3sas: lockless command submission
  2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
                   ` (10 preceding siblings ...)
  2017-02-22 10:31 ` [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete() Hannes Reinecke
@ 2017-02-22 10:31 ` Hannes Reinecke
  2017-03-03 12:32   ` Sreekanth Reddy
  11 siblings, 1 reply; 20+ messages in thread
From: Hannes Reinecke @ 2017-02-22 10:31 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Sreekanth Reddy,
	Kashyap Desai, Sathya Prakash, Hannes Reinecke, Hannes Reinecke

Instead of holding 'struct scsiio_tracker' in its own pool we
can embed it into the payload of the scsi command. This allows
us to get rid of the lock when submitting and receiving commands
and streamline operations.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c      | 120 +++++++++++++------------------
 drivers/scsi/mpt3sas/mpt3sas_base.h      |  23 +++---
 drivers/scsi/mpt3sas/mpt3sas_ctl.c       |  17 +++--
 drivers/scsi/mpt3sas/mpt3sas_scsih.c     | 118 +++++++++---------------------
 drivers/scsi/mpt3sas/mpt3sas_warpdrive.c |  35 +--------
 5 files changed, 105 insertions(+), 208 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 169d185..966a775 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -863,12 +863,19 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
 }
 
 struct scsiio_tracker *
-mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
+_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
+	struct scsi_cmnd *cmd;
+
 	if (WARN_ON(!smid) ||
 	    WARN_ON(smid >= ioc->hi_priority_smid))
 		return NULL;
-	return &ioc->scsi_lookup[smid - 1];
+
+	cmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
+	if (cmd)
+		return scsi_cmd_priv(cmd);
+
+	return NULL;
 }
 
 /**
@@ -889,7 +896,7 @@ struct scsiio_tracker *
 		struct scsiio_tracker *st;
 
 		if (smid < ctl_smid) {
-			st = mpt3sas_get_st_from_smid(ioc, smid);
+			st = _get_st_from_smid(ioc, smid);
 			if (st)
 				cb_idx = st->cb_idx;
 		} else if (smid == ctl_smid)
@@ -1276,15 +1283,16 @@ struct scsiio_tracker *
 /**
  * _base_get_chain_buffer_tracker - obtain chain tracker
  * @ioc: per adapter object
- * @smid: smid associated to an IO request
+ * @scmd: SCSI commands of the IO request
  *
  * Returns chain tracker(from ioc->free_chain_list)
  */
 static struct chain_tracker *
-_base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid)
+_base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc,
+			       struct scsi_cmnd *scmd)
 {
 	struct chain_tracker *chain_req;
-	struct scsiio_tracker *st;
+	struct scsiio_tracker *st = scsi_cmd_priv(scmd);
 	unsigned long flags;
 
 	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
@@ -1297,9 +1305,7 @@ struct scsiio_tracker *
 	chain_req = list_entry(ioc->free_chain_list.next,
 	    struct chain_tracker, tracker_list);
 	list_del_init(&chain_req->tracker_list);
-	st = mpt3sas_get_st_from_smid(ioc, smid);
-	if (st)
-		list_add_tail(&chain_req->tracker_list, &st->chain_list);
+	list_add_tail(&chain_req->tracker_list, &st->chain_list);
 	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 	return chain_req;
 }
@@ -1485,7 +1491,7 @@ struct scsiio_tracker *
 
 	/* initializing the chain flags and pointers */
 	chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
-	chain_req = _base_get_chain_buffer_tracker(ioc, smid);
+	chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
 	if (!chain_req)
 		return -1;
 	chain = chain_req->chain_buffer;
@@ -1525,7 +1531,7 @@ struct scsiio_tracker *
 			sges_in_segment--;
 		}
 
-		chain_req = _base_get_chain_buffer_tracker(ioc, smid);
+		chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
 		if (!chain_req)
 			return -1;
 		chain = chain_req->chain_buffer;
@@ -1619,7 +1625,7 @@ struct scsiio_tracker *
 	}
 
 	/* initializing the pointers */
-	chain_req = _base_get_chain_buffer_tracker(ioc, smid);
+	chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
 	if (!chain_req)
 		return -1;
 	chain = chain_req->chain_buffer;
@@ -1650,7 +1656,7 @@ struct scsiio_tracker *
 			sges_in_segment--;
 		}
 
-		chain_req = _base_get_chain_buffer_tracker(ioc, smid);
+		chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
 		if (!chain_req)
 			return -1;
 		chain = chain_req->chain_buffer;
@@ -2349,26 +2355,15 @@ struct scsiio_tracker *
 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
 	struct scsi_cmnd *scmd)
 {
-	unsigned long flags;
-	struct scsiio_tracker *request;
+	struct scsiio_tracker *request = scsi_cmd_priv(scmd);
+	unsigned int tag = scmd->request->tag;
 	u16 smid;
 
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	if (list_empty(&ioc->free_list)) {
-		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-		pr_err(MPT3SAS_FMT "%s: smid not available\n",
-		    ioc->name, __func__);
-		return 0;
-	}
-
-	request = list_entry(ioc->free_list.next,
-	    struct scsiio_tracker, tracker_list);
-	request->scmd = scmd;
+	smid = tag + 1;
 	request->cb_idx = cb_idx;
-	smid = request->smid;
 	request->msix_io = _base_get_msix_index(ioc);
-	list_del(&request->tracker_list);
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+	request->smid = smid;
+	INIT_LIST_HEAD(&request->chain_list);
 	return smid;
 }
 
@@ -2414,6 +2409,22 @@ struct scsiio_tracker *
 	}
 }
 
+void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
+			   struct scsiio_tracker *st)
+{
+	if (WARN_ON(st->smid == 0))
+		return;
+	st->cb_idx = 0xFF;
+	st->direct_io = 0;
+	if (!list_empty(&st->chain_list)) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+		list_splice_init(&st->chain_list, &ioc->free_chain_list);
+		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+	}
+}
+
 /**
  * mpt3sas_base_free_smid - put smid back on free_list
  * @ioc: per adapter object
@@ -2427,23 +2438,21 @@ struct scsiio_tracker *
 	unsigned long flags;
 	int i;
 
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
 	if (smid < ioc->hi_priority_smid) {
-		/* scsiio queue */
-		i = smid - 1;
-		list_splice_init(&ioc->scsi_lookup[i].chain_list,
-				 &ioc->free_chain_list);
-		ioc->scsi_lookup[i].cb_idx = 0xFF;
-		ioc->scsi_lookup[i].scmd = NULL;
-		ioc->scsi_lookup[i].direct_io = 0;
-		if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
-			list_add(&ioc->scsi_lookup[i].tracker_list,
-				 &ioc->free_list);
-		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+		struct scsiio_tracker *st;
 
+		st = _get_st_from_smid(ioc, smid);
+		if (!st) {
+			_base_recovery_check(ioc);
+			return;
+		}
+		mpt3sas_base_clear_st(ioc, st);
 		_base_recovery_check(ioc);
 		return;
-	} else if (smid < ioc->internal_smid) {
+	}
+
+	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+	if (smid < ioc->internal_smid) {
 		/* hi-priority */
 		i = smid - ioc->hi_priority_smid;
 		ioc->hpr_lookup[i].cb_idx = 0xFF;
@@ -3276,10 +3285,6 @@ struct scsiio_tracker *
 		    ioc->config_page, ioc->config_page_dma);
 	}
 
-	if (ioc->scsi_lookup) {
-		free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
-		ioc->scsi_lookup = NULL;
-	}
 	kfree(ioc->hpr_lookup);
 	kfree(ioc->internal_lookup);
 	if (ioc->chain_lookup) {
@@ -3573,16 +3578,6 @@ struct scsiio_tracker *
 	    ioc->name, (unsigned long long) ioc->request_dma));
 	total_sz += sz;
 
-	sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
-	ioc->scsi_lookup_pages = get_order(sz);
-	ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
-	    GFP_KERNEL, ioc->scsi_lookup_pages);
-	if (!ioc->scsi_lookup) {
-		pr_err(MPT3SAS_FMT "scsi_lookup: get_free_pages failed, sz(%d)\n",
-			ioc->name, (int)sz);
-		goto out;
-	}
-
 	dinitprintk(ioc, pr_info(MPT3SAS_FMT "scsiio(0x%p): depth(%d)\n",
 		ioc->name, ioc->request, ioc->scsiio_depth));
 
@@ -5170,20 +5165,7 @@ struct scsiio_tracker *
 		kfree(delayed_event_ack);
 	}
 
-	/* initialize the scsi lookup free list */
 	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	INIT_LIST_HEAD(&ioc->free_list);
-	smid = 1;
-	for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
-		INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
-		ioc->scsi_lookup[i].cb_idx = 0xFF;
-		ioc->scsi_lookup[i].smid = smid;
-		ioc->scsi_lookup[i].scmd = NULL;
-		ioc->scsi_lookup[i].direct_io = 0;
-		if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
-			list_add_tail(&ioc->scsi_lookup[i].tracker_list,
-				      &ioc->free_list);
-	}
 
 	/* hi-priority queue */
 	INIT_LIST_HEAD(&ioc->hpr_free_list);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 4ecc2c1..08ddf08 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -646,19 +646,16 @@ struct chain_tracker {
 /**
  * struct scsiio_tracker - scsi mf request tracker
  * @smid: system message id
- * @scmd: scsi request pointer
  * @cb_idx: callback index
  * @direct_io: To indicate whether I/O is direct (WARPDRIVE)
- * @tracker_list: list of free request (ioc->free_list)
+ * @chain_list: list of associated firmware chain tracker
  * @msix_io: IO's msix
  */
 struct scsiio_tracker {
 	u16	smid;
-	struct scsi_cmnd *scmd;
 	u8	cb_idx;
 	u8	direct_io;
 	struct list_head chain_list;
-	struct list_head tracker_list;
 	u16     msix_io;
 };
 
@@ -1100,10 +1097,7 @@ struct MPT3SAS_ADAPTER {
 	u8		*request;
 	dma_addr_t	request_dma;
 	u32		request_dma_sz;
-	struct scsiio_tracker *scsi_lookup;
-	ulong		scsi_lookup_pages;
 	spinlock_t	scsi_lookup_lock;
-	struct list_head free_list;
 	int		pending_io_count;
 	wait_queue_head_t reset_wq;
 
@@ -1247,8 +1241,8 @@ __le32 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc,
 u16 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
 u16 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
 	struct scsi_cmnd *scmd);
-struct scsiio_tracker * mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc,
-	u16 smid);
+void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
+			   struct scsiio_tracker *st);
 
 u16 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
 void mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid);
@@ -1284,6 +1278,8 @@ void mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc,
 
 
 /* scsih shared API */
+struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc,
+	u16 smid);
 u8 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
 	u32 reply);
 void mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase);
@@ -1300,6 +1296,8 @@ void mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
 	u64 sas_address);
 u8 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc,
 	u16 smid);
+struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc,
+	u16 smid);
 
 struct _sas_node *mpt3sas_scsih_expander_find_by_handle(
 	struct MPT3SAS_ADAPTER *ioc, u16 handle);
@@ -1451,14 +1449,9 @@ void mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status,
 u8 mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc);
 void mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
 	struct _raid_device *raid_device);
-u8
-mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid);
-void
-mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io);
 void
 mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
-	struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
-	u16 smid);
+	struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request);
 
 /* NCQ Prio Handling Check */
 bool scsih_ncq_prio_supp(struct scsi_device *sdev);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index dd03d2c..7bbc5b1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -563,11 +563,10 @@ enum block_state {
 	Mpi2SCSITaskManagementRequest_t *tm_request)
 {
 	u8 found = 0;
-	u16 i;
+	u16 smid;
 	u16 handle;
 	struct scsi_cmnd *scmd;
 	struct MPT3SAS_DEVICE *priv_data;
-	unsigned long flags;
 	Mpi2SCSITaskManagementReply_t *tm_reply;
 	u32 sz;
 	u32 lun;
@@ -583,11 +582,11 @@ enum block_state {
 	lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
 
 	handle = le16_to_cpu(tm_request->DevHandle);
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	for (i = ioc->scsiio_depth; i && !found; i--) {
-		scmd = ioc->scsi_lookup[i - 1].scmd;
-		if (scmd == NULL || scmd->device == NULL ||
-		    scmd->device->hostdata == NULL)
+	for (smid = ioc->scsiio_depth; smid && !found; smid--) {
+		struct scsiio_tracker *st;
+
+		scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
+		if (!scmd)
 			continue;
 		if (lun != scmd->device->lun)
 			continue;
@@ -596,10 +595,10 @@ enum block_state {
 			continue;
 		if (priv_data->sas_target->handle != handle)
 			continue;
-		tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
+		st = scsi_cmd_priv(scmd);
+		tm_request->TaskMID = cpu_to_le16(st->smid);
 		found = 1;
 	}
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 
 	if (!found) {
 		dctlprintk(ioc, pr_info(MPT3SAS_FMT
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index f114ef7..8177519 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1061,74 +1061,31 @@ struct _sas_node *
 }
 
 /**
- * __scsih_scsi_lookup_get_clear - returns scmd entry without
- *						holding any lock.
+ * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
  * @ioc: per adapter object
  * @smid: system request message index
  *
  * Returns the smid stored scmd pointer.
  * Then will dereference the stored scmd pointer.
  */
-static inline struct scsi_cmnd *
-__scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc,
-		u16 smid)
+struct scsi_cmnd *
+mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
 {
 	struct scsi_cmnd *scmd = NULL;
+	struct scsiio_tracker *st;
 
-	swap(scmd, ioc->scsi_lookup[smid - 1].scmd);
-
-	return scmd;
-}
-
-/**
- * _scsih_scsi_lookup_get_clear - returns scmd entry
- * @ioc: per adapter object
- * @smid: system request message index
- *
- * Returns the smid stored scmd pointer.
- * Then will derefrence the stored scmd pointer.
- */
-static inline struct scsi_cmnd *
-_scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
-{
-	unsigned long flags;
-	struct scsi_cmnd *scmd;
-
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-
-	return scmd;
-}
-
-/**
- * _scsih_scsi_lookup_find_by_scmd - scmd lookup
- * @ioc: per adapter object
- * @smid: system request message index
- * @scmd: pointer to scsi command object
- * Context: This function will acquire ioc->scsi_lookup_lock.
- *
- * This will search for a scmd pointer in the scsi_lookup array,
- * returning the revelent smid.  A returned value of zero means invalid.
- */
-struct scsiio_tracker *
-_scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
-	*scmd)
-{
-	struct scsiio_tracker *st = NULL;
-	unsigned long flags;
-	int i;
+	if (smid > 0  &&
+	    smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
+		u32 unique_tag = smid - 1;
 
-	spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-	for (i = 0; i < ioc->scsiio_depth; i++) {
-		if (ioc->scsi_lookup[i].scmd == scmd) {
-			st = &ioc->scsi_lookup[i];
-			goto out;
+		scmd = scsi_host_find_tag(ioc->shost, unique_tag);
+		if (scmd) {
+			st = scsi_cmd_priv(scmd);
+			if (st->cb_idx == 0xFF)
+				scmd = NULL;
 		}
 	}
- out:
-	spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-	return st;
+	return scmd;
 }
 
 /**
@@ -2341,7 +2298,7 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 {
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
 	struct MPT3SAS_DEVICE *sas_device_priv_data;
-	struct scsiio_tracker *st = NULL;
+	struct scsiio_tracker *st = scsi_cmd_priv(scmd);
 	u16 handle;
 	int r;
 
@@ -2359,9 +2316,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 		goto out;
 	}
 
-	/* search for the command */
-	st = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
-	if (!st) {
+	/* check for completed command */
+	if (st->cb_idx == 0xFF); {
 		scmd->result = DID_RESET << 16;
 		r = SUCCESS;
 		goto out;
@@ -2383,7 +2339,7 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
 		MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
 		st->smid, st->msix_io, 30);
 	/* Command must be cleared after abort */
-	if (r == SUCCESS && st->scmd)
+	if (r == SUCCESS && st->cb_idx != 0xFF)
 		r = FAILED;
  out:
 	sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
@@ -3820,18 +3776,20 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
 {
 	struct scsi_cmnd *scmd;
+	struct scsiio_tracker *st;
 	u16 smid;
-	u16 count = 0;
+	int count = 0;
 
 	for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
-		scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
+		scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
 		if (!scmd)
 			continue;
 		count++;
 		if (ata_12_16_cmd(scmd))
 			scsi_internal_device_unblock(scmd->device,
 							SDEV_RUNNING);
-		mpt3sas_base_free_smid(ioc, smid);
+		st = scsi_cmd_priv(scmd);
+		mpt3sas_base_clear_st(ioc, st);
 		scsi_dma_unmap(scmd);
 		if (ioc->pci_error_recovery)
 			scmd->result = DID_NO_CONNECT << 16;
@@ -4074,8 +4032,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 
 	raid_device = sas_target_priv_data->raid_device;
 	if (raid_device && raid_device->direct_io_enabled)
-		mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
-		    smid);
+		mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request);
 
 	if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
 		if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
@@ -4539,6 +4496,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	Mpi2SCSIIORequest_t *mpi_request;
 	Mpi2SCSIIOReply_t *mpi_reply;
 	struct scsi_cmnd *scmd;
+	struct scsiio_tracker *st;
 	u16 ioc_status;
 	u32 xfer_cnt;
 	u8 scsi_state;
@@ -4546,16 +4504,10 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	u32 log_info;
 	struct MPT3SAS_DEVICE *sas_device_priv_data;
 	u32 response_code = 0;
-	unsigned long flags;
 
 	mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
 
-	if (ioc->broadcast_aen_busy || ioc->pci_error_recovery ||
-			ioc->got_task_abort_from_ioctl)
-		scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
-	else
-		scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
-
+	scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
 	if (scmd == NULL)
 		return 1;
 
@@ -4581,13 +4533,11 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	 * WARPDRIVE: If direct_io is set then it is directIO,
 	 * the failed direct I/O should be redirected to volume
 	 */
-	if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
+	st = scsi_cmd_priv(scmd);
+	if (st->direct_io &&
 	     ((ioc_status & MPI2_IOCSTATUS_MASK)
 	      != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
-		spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-		ioc->scsi_lookup[smid - 1].scmd = scmd;
-		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
-		mpt3sas_scsi_direct_io_set(ioc, smid, 0);
+		st->direct_io = 0;
 		memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
 		mpi_request->DevHandle =
 		    cpu_to_le16(sas_device_priv_data->sas_target->handle);
@@ -6011,10 +5961,10 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 	for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
 		if (ioc->shost_recovery)
 			goto out;
-		st = &ioc->scsi_lookup[smid - 1];
-		scmd = st->scmd;
+		scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
 		if (!scmd)
 			continue;
+		st = scsi_cmd_priv(scmd);
 		sdev = scmd->device;
 		sas_device_priv_data = sdev->hostdata;
 		if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
@@ -6037,7 +5987,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 
 		spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
 		r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
-			MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid,
+			MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
 			st->msix_io, 30);
 		if (r == FAILED) {
 			sdev_printk(KERN_WARNING, sdev,
@@ -6078,9 +6028,9 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
 			goto out_no_lock;
 
 		r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
-			MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
+			MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
 			st->msix_io, 30);
-		if (r == FAILED || st->scmd) {
+		if (r == FAILED || st->cb_idx != 0xFF) {
 			sdev_printk(KERN_WARNING, sdev,
 			    "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
 			    "scmd(%p)\n", scmd);
@@ -8512,6 +8462,7 @@ static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
 	.shost_attrs			= mpt3sas_host_attrs,
 	.sdev_attrs			= mpt3sas_dev_attrs,
 	.track_queue_depth		= 1,
+	.cmd_size			= sizeof(struct scsiio_tracker),
 };
 
 /* raid transport support for SAS 2.0 HBA devices */
@@ -8550,6 +8501,7 @@ static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
 	.shost_attrs			= mpt3sas_host_attrs,
 	.sdev_attrs			= mpt3sas_dev_attrs,
 	.track_queue_depth		= 1,
+	.cmd_size			= sizeof(struct scsiio_tracker),
 };
 
 /* raid transport support for SAS 3.0 HBA devices */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
index 06e3f7d..9e5309d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
@@ -261,35 +261,6 @@
 }
 
 /**
- * mpt3sas_scsi_direct_io_get - returns direct io flag
- * @ioc: per adapter object
- * @smid: system request message index
- *
- * Returns the smid stored scmd pointer.
- */
-inline u8
-mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
-{
-	struct scsiio_tracker *st = mpt3sas_get_st_from_smid(ioc, smid);
-
-	return st ? st->direct_io : 0;
-}
-
-/**
- * mpt3sas_scsi_direct_io_set - sets direct io flag
- * @ioc: per adapter object
- * @smid: system request message index
- * @direct_io: Zero or non-zero value to set in the direct_io flag
- *
- * Returns Nothing.
- */
-inline void
-mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
-{
-	ioc->scsi_lookup[smid - 1].direct_io = direct_io;
-}
-
-/**
  * mpt3sas_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
  * @ioc: per adapter object
  * @scmd: pointer to scsi command object
@@ -301,12 +272,12 @@
  */
 void
 mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
-	struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
-	u16 smid)
+	struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request)
 {
 	sector_t v_lba, p_lba, stripe_off, column, io_size;
 	u32 stripe_sz, stripe_exp;
 	u8 num_pds, cmd = scmd->cmnd[0];
+	struct scsiio_tracker *st = scsi_cmd_priv(scmd);
 
 	if (cmd != READ_10 && cmd != WRITE_10 &&
 	    cmd != READ_16 && cmd != WRITE_16)
@@ -342,5 +313,5 @@
 	else
 		put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
 
-	mpt3sas_scsi_direct_io_set(ioc, smid, 1);
+	st->direct_io = 1;
 }
-- 
1.8.5.6

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

* Re: [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors
  2017-02-22 10:31 ` [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors Hannes Reinecke
@ 2017-02-23 22:04   ` Martin K. Petersen
  0 siblings, 0 replies; 20+ messages in thread
From: Martin K. Petersen @ 2017-02-23 22:04 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Sreekanth Reddy, Kashyap Desai, Sathya Prakash,
	Hannes Reinecke

>>>>> "Hannes" == Hannes Reinecke <hare@suse.de> writes:

Hannes> Cleanup the MSI-X handling allowing us to use the PCI-layer
Hannes> provided vector allocation.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete()
  2017-02-22 10:31 ` [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete() Hannes Reinecke
@ 2017-03-03 11:57   ` Sreekanth Reddy
  2017-03-03 13:53     ` Hannes Reinecke
  0 siblings, 1 reply; 20+ messages in thread
From: Sreekanth Reddy @ 2017-03-03 11:57 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

On Wed, Feb 22, 2017 at 4:01 PM, Hannes Reinecke <hare@suse.de> wrote:
> Use 'host_busy' instead of counting outstanding commands by hand.
>
> Suggested-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index e6aafa5..169d185 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -2408,9 +2408,9 @@ struct scsiio_tracker *
>          * See _wait_for_commands_to_complete() call with regards to this code.
>          */
>         if (ioc->shost_recovery && ioc->pending_io_count) {
> -               if (ioc->pending_io_count == 1)
> +               ioc->pending_io_count = atomic_read(&ioc->shost->host_busy);

This won't consider the scsi IO issued from ioctl path. If that scsi
io is still outstanding then here we will return without waiting for
it to complete.

> +               if (ioc->pending_io_count == 0)
>                         wake_up(&ioc->reset_wq);
> -               ioc->pending_io_count--;
>         }
>  }
>
> @@ -5687,15 +5687,13 @@ struct scsiio_tracker *
>   * _wait_for_commands_to_complete - reset controller
>   * @ioc: Pointer to MPT_ADAPTER structure
>   *
> - * This function waiting(3s) for all pending commands to complete
> + * This function is waiting 10s for all pending commands to complete
>   * prior to putting controller in reset.
>   */
>  static void
>  _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc)
>  {
>         u32 ioc_state;
> -       unsigned long flags;
> -       u16 i;
>
>         ioc->pending_io_count = 0;
>
> @@ -5704,11 +5702,7 @@ struct scsiio_tracker *
>                 return;
>
>         /* pending command count */
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       for (i = 0; i < ioc->scsiio_depth; i++)
> -               if (ioc->scsi_lookup[i].cb_idx != 0xFF)
> -                       ioc->pending_io_count++;
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> +       ioc->pending_io_count = atomic_read(&ioc->shost->host_busy);
>
>         if (!ioc->pending_io_count)
>                 return;
> --
> 1.8.5.6
>

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

* Re: [PATCHv4 12/12] mpt3sas: lockless command submission
  2017-02-22 10:31 ` [PATCHv4 12/12] mpt3sas: lockless command submission Hannes Reinecke
@ 2017-03-03 12:32   ` Sreekanth Reddy
  2017-03-03 13:59     ` Hannes Reinecke
  0 siblings, 1 reply; 20+ messages in thread
From: Sreekanth Reddy @ 2017-03-03 12:32 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

On Wed, Feb 22, 2017 at 4:01 PM, Hannes Reinecke <hare@suse.de> wrote:
> Instead of holding 'struct scsiio_tracker' in its own pool we
> can embed it into the payload of the scsi command. This allows
> us to get rid of the lock when submitting and receiving commands
> and streamline operations.
>
> Signed-off-by: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c      | 120 +++++++++++++------------------
>  drivers/scsi/mpt3sas/mpt3sas_base.h      |  23 +++---
>  drivers/scsi/mpt3sas/mpt3sas_ctl.c       |  17 +++--
>  drivers/scsi/mpt3sas/mpt3sas_scsih.c     | 118 +++++++++---------------------
>  drivers/scsi/mpt3sas/mpt3sas_warpdrive.c |  35 +--------
>  5 files changed, 105 insertions(+), 208 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 169d185..966a775 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -863,12 +863,19 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
>  }
>
>  struct scsiio_tracker *
> -mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
> +_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)

Can we rename the name of this function as  _base_get_st_from_smid(),
Since we always try to follow below notations,
 * prefix with "_<filenamePart(i.e. base)>" if the function is used
within this file other wise prefix with "mpt3sas_<filename>" if this
function is shared between more than one file.

>  {
> +       struct scsi_cmnd *cmd;
> +
>         if (WARN_ON(!smid) ||
>             WARN_ON(smid >= ioc->hi_priority_smid))
>                 return NULL;
> -       return &ioc->scsi_lookup[smid - 1];
> +
> +       cmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
> +       if (cmd)
> +               return scsi_cmd_priv(cmd);
> +
> +       return NULL;
>  }
>
>  /**
> @@ -889,7 +896,7 @@ struct scsiio_tracker *
>                 struct scsiio_tracker *st;
>
>                 if (smid < ctl_smid) {
> -                       st = mpt3sas_get_st_from_smid(ioc, smid);
> +                       st = _get_st_from_smid(ioc, smid);
>                         if (st)
>                                 cb_idx = st->cb_idx;

I think, here we can safely assign "cb_idx"  as "ioc->scsi_io_cb_idx",
no need to get it from scsiio_tracker. since all the smid's below
ctl_smid will we used for SCSI IO's recieved from scsih_qcmd.

>                 } else if (smid == ctl_smid)
> @@ -1276,15 +1283,16 @@ struct scsiio_tracker *
>  /**
>   * _base_get_chain_buffer_tracker - obtain chain tracker
>   * @ioc: per adapter object
> - * @smid: smid associated to an IO request
> + * @scmd: SCSI commands of the IO request
>   *
>   * Returns chain tracker(from ioc->free_chain_list)
>   */
>  static struct chain_tracker *
> -_base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid)
> +_base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc,
> +                              struct scsi_cmnd *scmd)
>  {
>         struct chain_tracker *chain_req;
> -       struct scsiio_tracker *st;
> +       struct scsiio_tracker *st = scsi_cmd_priv(scmd);
>         unsigned long flags;
>
>         spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> @@ -1297,9 +1305,7 @@ struct scsiio_tracker *
>         chain_req = list_entry(ioc->free_chain_list.next,
>             struct chain_tracker, tracker_list);
>         list_del_init(&chain_req->tracker_list);
> -       st = mpt3sas_get_st_from_smid(ioc, smid);
> -       if (st)
> -               list_add_tail(&chain_req->tracker_list, &st->chain_list);
> +       list_add_tail(&chain_req->tracker_list, &st->chain_list);
>         spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);

Still we have this lock in the IO path. May be we can remove this lock
too by allocating "ioc->ioc->chains_needed_per_io * shost->can_queue"
number of chain buffers and we can acces the required chain buffer
using scmd's tag pluse chain_offset_per_io coressponding to that
repective tag.

May be we will post a separate patch for this after some time.

>         return chain_req;
>  }
> @@ -1485,7 +1491,7 @@ struct scsiio_tracker *
>
>         /* initializing the chain flags and pointers */
>         chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
> -       chain_req = _base_get_chain_buffer_tracker(ioc, smid);
> +       chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
>         if (!chain_req)
>                 return -1;
>         chain = chain_req->chain_buffer;
> @@ -1525,7 +1531,7 @@ struct scsiio_tracker *
>                         sges_in_segment--;
>                 }
>
> -               chain_req = _base_get_chain_buffer_tracker(ioc, smid);
> +               chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
>                 if (!chain_req)
>                         return -1;
>                 chain = chain_req->chain_buffer;
> @@ -1619,7 +1625,7 @@ struct scsiio_tracker *
>         }
>
>         /* initializing the pointers */
> -       chain_req = _base_get_chain_buffer_tracker(ioc, smid);
> +       chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
>         if (!chain_req)
>                 return -1;
>         chain = chain_req->chain_buffer;
> @@ -1650,7 +1656,7 @@ struct scsiio_tracker *
>                         sges_in_segment--;
>                 }
>
> -               chain_req = _base_get_chain_buffer_tracker(ioc, smid);
> +               chain_req = _base_get_chain_buffer_tracker(ioc, scmd);
>                 if (!chain_req)
>                         return -1;
>                 chain = chain_req->chain_buffer;
> @@ -2349,26 +2355,15 @@ struct scsiio_tracker *
>  mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
>         struct scsi_cmnd *scmd)
>  {
> -       unsigned long flags;
> -       struct scsiio_tracker *request;
> +       struct scsiio_tracker *request = scsi_cmd_priv(scmd);
> +       unsigned int tag = scmd->request->tag;
>         u16 smid;
>
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       if (list_empty(&ioc->free_list)) {
> -               spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> -               pr_err(MPT3SAS_FMT "%s: smid not available\n",
> -                   ioc->name, __func__);
> -               return 0;
> -       }
> -
> -       request = list_entry(ioc->free_list.next,
> -           struct scsiio_tracker, tracker_list);
> -       request->scmd = scmd;
> +       smid = tag + 1;
>         request->cb_idx = cb_idx;
> -       smid = request->smid;
>         request->msix_io = _base_get_msix_index(ioc);
> -       list_del(&request->tracker_list);
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> +       request->smid = smid;
> +       INIT_LIST_HEAD(&request->chain_list);
>         return smid;
>  }
>
> @@ -2414,6 +2409,22 @@ struct scsiio_tracker *
>         }
>  }
>
> +void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
> +                          struct scsiio_tracker *st)
> +{
> +       if (WARN_ON(st->smid == 0))
> +               return;
> +       st->cb_idx = 0xFF;
> +       st->direct_io = 0;
> +       if (!list_empty(&st->chain_list)) {
> +               unsigned long flags;
> +
> +               spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> +               list_splice_init(&st->chain_list, &ioc->free_chain_list);
> +               spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> +       }
> +}
> +
>  /**
>   * mpt3sas_base_free_smid - put smid back on free_list
>   * @ioc: per adapter object
> @@ -2427,23 +2438,21 @@ struct scsiio_tracker *
>         unsigned long flags;
>         int i;
>
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
>         if (smid < ioc->hi_priority_smid) {
> -               /* scsiio queue */
> -               i = smid - 1;
> -               list_splice_init(&ioc->scsi_lookup[i].chain_list,
> -                                &ioc->free_chain_list);
> -               ioc->scsi_lookup[i].cb_idx = 0xFF;
> -               ioc->scsi_lookup[i].scmd = NULL;
> -               ioc->scsi_lookup[i].direct_io = 0;
> -               if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
> -                       list_add(&ioc->scsi_lookup[i].tracker_list,
> -                                &ioc->free_list);
> -               spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> +               struct scsiio_tracker *st;
>
> +               st = _get_st_from_smid(ioc, smid);
> +               if (!st) {
> +                       _base_recovery_check(ioc);
> +                       return;
> +               }
> +               mpt3sas_base_clear_st(ioc, st);
>                 _base_recovery_check(ioc);
>                 return;
> -       } else if (smid < ioc->internal_smid) {
> +       }
> +
> +       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> +       if (smid < ioc->internal_smid) {
>                 /* hi-priority */
>                 i = smid - ioc->hi_priority_smid;
>                 ioc->hpr_lookup[i].cb_idx = 0xFF;
> @@ -3276,10 +3285,6 @@ struct scsiio_tracker *
>                     ioc->config_page, ioc->config_page_dma);
>         }
>
> -       if (ioc->scsi_lookup) {
> -               free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
> -               ioc->scsi_lookup = NULL;
> -       }
>         kfree(ioc->hpr_lookup);
>         kfree(ioc->internal_lookup);
>         if (ioc->chain_lookup) {
> @@ -3573,16 +3578,6 @@ struct scsiio_tracker *
>             ioc->name, (unsigned long long) ioc->request_dma));
>         total_sz += sz;
>
> -       sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
> -       ioc->scsi_lookup_pages = get_order(sz);
> -       ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
> -           GFP_KERNEL, ioc->scsi_lookup_pages);
> -       if (!ioc->scsi_lookup) {
> -               pr_err(MPT3SAS_FMT "scsi_lookup: get_free_pages failed, sz(%d)\n",
> -                       ioc->name, (int)sz);
> -               goto out;
> -       }
> -
>         dinitprintk(ioc, pr_info(MPT3SAS_FMT "scsiio(0x%p): depth(%d)\n",
>                 ioc->name, ioc->request, ioc->scsiio_depth));
>
> @@ -5170,20 +5165,7 @@ struct scsiio_tracker *
>                 kfree(delayed_event_ack);
>         }
>
> -       /* initialize the scsi lookup free list */
>         spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       INIT_LIST_HEAD(&ioc->free_list);
> -       smid = 1;
> -       for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
> -               INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
> -               ioc->scsi_lookup[i].cb_idx = 0xFF;
> -               ioc->scsi_lookup[i].smid = smid;
> -               ioc->scsi_lookup[i].scmd = NULL;
> -               ioc->scsi_lookup[i].direct_io = 0;
> -               if (i < ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT)
> -                       list_add_tail(&ioc->scsi_lookup[i].tracker_list,
> -                                     &ioc->free_list);
> -       }
>
>         /* hi-priority queue */
>         INIT_LIST_HEAD(&ioc->hpr_free_list);
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
> index 4ecc2c1..08ddf08 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.h
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
> @@ -646,19 +646,16 @@ struct chain_tracker {
>  /**
>   * struct scsiio_tracker - scsi mf request tracker
>   * @smid: system message id
> - * @scmd: scsi request pointer
>   * @cb_idx: callback index
>   * @direct_io: To indicate whether I/O is direct (WARPDRIVE)
> - * @tracker_list: list of free request (ioc->free_list)
> + * @chain_list: list of associated firmware chain tracker
>   * @msix_io: IO's msix
>   */
>  struct scsiio_tracker {
>         u16     smid;
> -       struct scsi_cmnd *scmd;
>         u8      cb_idx;
>         u8      direct_io;
>         struct list_head chain_list;
> -       struct list_head tracker_list;
>         u16     msix_io;
>  };
>
> @@ -1100,10 +1097,7 @@ struct MPT3SAS_ADAPTER {
>         u8              *request;
>         dma_addr_t      request_dma;
>         u32             request_dma_sz;
> -       struct scsiio_tracker *scsi_lookup;
> -       ulong           scsi_lookup_pages;
>         spinlock_t      scsi_lookup_lock;
> -       struct list_head free_list;
>         int             pending_io_count;
>         wait_queue_head_t reset_wq;
>
> @@ -1247,8 +1241,8 @@ __le32 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc,
>  u16 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
>  u16 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
>         struct scsi_cmnd *scmd);
> -struct scsiio_tracker * mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc,
> -       u16 smid);
> +void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
> +                          struct scsiio_tracker *st);
>
>  u16 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);
>  void mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid);
> @@ -1284,6 +1278,8 @@ void mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc,
>
>
>  /* scsih shared API */
> +struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc,
> +       u16 smid);
>  u8 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
>         u32 reply);
>  void mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase);
> @@ -1300,6 +1296,8 @@ void mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
>         u64 sas_address);
>  u8 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc,
>         u16 smid);
> +struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc,
> +       u16 smid);
>
>  struct _sas_node *mpt3sas_scsih_expander_find_by_handle(
>         struct MPT3SAS_ADAPTER *ioc, u16 handle);
> @@ -1451,14 +1449,9 @@ void mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status,
>  u8 mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc);
>  void mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
>         struct _raid_device *raid_device);
> -u8
> -mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid);
> -void
> -mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io);
>  void
>  mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
> -       struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
> -       u16 smid);
> +       struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request);
>
>  /* NCQ Prio Handling Check */
>  bool scsih_ncq_prio_supp(struct scsi_device *sdev);
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index dd03d2c..7bbc5b1 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -563,11 +563,10 @@ enum block_state {
>         Mpi2SCSITaskManagementRequest_t *tm_request)
>  {
>         u8 found = 0;
> -       u16 i;
> +       u16 smid;
>         u16 handle;
>         struct scsi_cmnd *scmd;
>         struct MPT3SAS_DEVICE *priv_data;
> -       unsigned long flags;
>         Mpi2SCSITaskManagementReply_t *tm_reply;
>         u32 sz;
>         u32 lun;
> @@ -583,11 +582,11 @@ enum block_state {
>         lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
>
>         handle = le16_to_cpu(tm_request->DevHandle);
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       for (i = ioc->scsiio_depth; i && !found; i--) {
> -               scmd = ioc->scsi_lookup[i - 1].scmd;
> -               if (scmd == NULL || scmd->device == NULL ||
> -                   scmd->device->hostdata == NULL)
> +       for (smid = ioc->scsiio_depth; smid && !found; smid--) {
> +               struct scsiio_tracker *st;
> +
> +               scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
> +               if (!scmd)
>                         continue;
>                 if (lun != scmd->device->lun)
>                         continue;
> @@ -596,10 +595,10 @@ enum block_state {
>                         continue;
>                 if (priv_data->sas_target->handle != handle)
>                         continue;
> -               tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
> +               st = scsi_cmd_priv(scmd);
> +               tm_request->TaskMID = cpu_to_le16(st->smid);
>                 found = 1;
>         }
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
>
>         if (!found) {
>                 dctlprintk(ioc, pr_info(MPT3SAS_FMT
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index f114ef7..8177519 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> @@ -1061,74 +1061,31 @@ struct _sas_node *
>  }
>
>  /**
> - * __scsih_scsi_lookup_get_clear - returns scmd entry without
> - *                                             holding any lock.
> + * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
>   * @ioc: per adapter object
>   * @smid: system request message index
>   *
>   * Returns the smid stored scmd pointer.
>   * Then will dereference the stored scmd pointer.
>   */
> -static inline struct scsi_cmnd *
> -__scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc,
> -               u16 smid)
> +struct scsi_cmnd *
> +mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
>  {
>         struct scsi_cmnd *scmd = NULL;
> +       struct scsiio_tracker *st;
>
> -       swap(scmd, ioc->scsi_lookup[smid - 1].scmd);
> -
> -       return scmd;
> -}
> -
> -/**
> - * _scsih_scsi_lookup_get_clear - returns scmd entry
> - * @ioc: per adapter object
> - * @smid: system request message index
> - *
> - * Returns the smid stored scmd pointer.
> - * Then will derefrence the stored scmd pointer.
> - */
> -static inline struct scsi_cmnd *
> -_scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
> -{
> -       unsigned long flags;
> -       struct scsi_cmnd *scmd;
> -
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> -
> -       return scmd;
> -}
> -
> -/**
> - * _scsih_scsi_lookup_find_by_scmd - scmd lookup
> - * @ioc: per adapter object
> - * @smid: system request message index
> - * @scmd: pointer to scsi command object
> - * Context: This function will acquire ioc->scsi_lookup_lock.
> - *
> - * This will search for a scmd pointer in the scsi_lookup array,
> - * returning the revelent smid.  A returned value of zero means invalid.
> - */
> -struct scsiio_tracker *
> -_scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
> -       *scmd)
> -{
> -       struct scsiio_tracker *st = NULL;
> -       unsigned long flags;
> -       int i;
> +       if (smid > 0  &&
> +           smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
> +               u32 unique_tag = smid - 1;
>
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       for (i = 0; i < ioc->scsiio_depth; i++) {
> -               if (ioc->scsi_lookup[i].scmd == scmd) {
> -                       st = &ioc->scsi_lookup[i];
> -                       goto out;
> +               scmd = scsi_host_find_tag(ioc->shost, unique_tag);
> +               if (scmd) {
> +                       st = scsi_cmd_priv(scmd);
> +                       if (st->cb_idx == 0xFF)
> +                               scmd = NULL;
>                 }
>         }
> - out:
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> -       return st;
> +       return scmd;
>  }
>
>  /**
> @@ -2341,7 +2298,7 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>  {
>         struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
>         struct MPT3SAS_DEVICE *sas_device_priv_data;
> -       struct scsiio_tracker *st = NULL;
> +       struct scsiio_tracker *st = scsi_cmd_priv(scmd);
>         u16 handle;
>         int r;
>
> @@ -2359,9 +2316,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>                 goto out;
>         }
>
> -       /* search for the command */
> -       st = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
> -       if (!st) {
> +       /* check for completed command */
> +       if (st->cb_idx == 0xFF); {

";" should be removed from above line, otherwise always we return task
abort TM with "SUCCESS" status without issueing the TM to Firmware.


Thanks,
Sreekanth
>                 scmd->result = DID_RESET << 16;
>                 r = SUCCESS;
>                 goto out;
> @@ -2383,7 +2339,7 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>                 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
>                 st->smid, st->msix_io, 30);
>         /* Command must be cleared after abort */
> -       if (r == SUCCESS && st->scmd)
> +       if (r == SUCCESS && st->cb_idx != 0xFF)
>                 r = FAILED;
>   out:
>         sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
> @@ -3820,18 +3776,20 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>  _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
>  {
>         struct scsi_cmnd *scmd;
> +       struct scsiio_tracker *st;
>         u16 smid;
> -       u16 count = 0;
> +       int count = 0;
>
>         for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
> -               scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
> +               scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
>                 if (!scmd)
>                         continue;
>                 count++;
>                 if (ata_12_16_cmd(scmd))
>                         scsi_internal_device_unblock(scmd->device,
>                                                         SDEV_RUNNING);
> -               mpt3sas_base_free_smid(ioc, smid);
> +               st = scsi_cmd_priv(scmd);
> +               mpt3sas_base_clear_st(ioc, st);
>                 scsi_dma_unmap(scmd);
>                 if (ioc->pci_error_recovery)
>                         scmd->result = DID_NO_CONNECT << 16;
> @@ -4074,8 +4032,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>
>         raid_device = sas_target_priv_data->raid_device;
>         if (raid_device && raid_device->direct_io_enabled)
> -               mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
> -                   smid);
> +               mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request);
>
>         if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
>                 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
> @@ -4539,6 +4496,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>         Mpi2SCSIIORequest_t *mpi_request;
>         Mpi2SCSIIOReply_t *mpi_reply;
>         struct scsi_cmnd *scmd;
> +       struct scsiio_tracker *st;
>         u16 ioc_status;
>         u32 xfer_cnt;
>         u8 scsi_state;
> @@ -4546,16 +4504,10 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>         u32 log_info;
>         struct MPT3SAS_DEVICE *sas_device_priv_data;
>         u32 response_code = 0;
> -       unsigned long flags;
>
>         mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
>
> -       if (ioc->broadcast_aen_busy || ioc->pci_error_recovery ||
> -                       ioc->got_task_abort_from_ioctl)
> -               scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
> -       else
> -               scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
> -
> +       scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
>         if (scmd == NULL)
>                 return 1;
>
> @@ -4581,13 +4533,11 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>          * WARPDRIVE: If direct_io is set then it is directIO,
>          * the failed direct I/O should be redirected to volume
>          */
> -       if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
> +       st = scsi_cmd_priv(scmd);
> +       if (st->direct_io &&
>              ((ioc_status & MPI2_IOCSTATUS_MASK)
>               != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
> -               spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -               ioc->scsi_lookup[smid - 1].scmd = scmd;
> -               spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> -               mpt3sas_scsi_direct_io_set(ioc, smid, 0);
> +               st->direct_io = 0;
>                 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
>                 mpi_request->DevHandle =
>                     cpu_to_le16(sas_device_priv_data->sas_target->handle);
> @@ -6011,10 +5961,10 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>         for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
>                 if (ioc->shost_recovery)
>                         goto out;
> -               st = &ioc->scsi_lookup[smid - 1];
> -               scmd = st->scmd;
> +               scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
>                 if (!scmd)
>                         continue;
> +               st = scsi_cmd_priv(scmd);
>                 sdev = scmd->device;
>                 sas_device_priv_data = sdev->hostdata;
>                 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
> @@ -6037,7 +5987,7 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>
>                 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
>                 r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
> -                       MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid,
> +                       MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
>                         st->msix_io, 30);
>                 if (r == FAILED) {
>                         sdev_printk(KERN_WARNING, sdev,
> @@ -6078,9 +6028,9 @@ static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
>                         goto out_no_lock;
>
>                 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
> -                       MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
> +                       MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
>                         st->msix_io, 30);
> -               if (r == FAILED || st->scmd) {
> +               if (r == FAILED || st->cb_idx != 0xFF) {
>                         sdev_printk(KERN_WARNING, sdev,
>                             "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
>                             "scmd(%p)\n", scmd);
> @@ -8512,6 +8462,7 @@ static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
>         .shost_attrs                    = mpt3sas_host_attrs,
>         .sdev_attrs                     = mpt3sas_dev_attrs,
>         .track_queue_depth              = 1,
> +       .cmd_size                       = sizeof(struct scsiio_tracker),
>  };
>
>  /* raid transport support for SAS 2.0 HBA devices */
> @@ -8550,6 +8501,7 @@ static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
>         .shost_attrs                    = mpt3sas_host_attrs,
>         .sdev_attrs                     = mpt3sas_dev_attrs,
>         .track_queue_depth              = 1,
> +       .cmd_size                       = sizeof(struct scsiio_tracker),
>  };
>
>  /* raid transport support for SAS 3.0 HBA devices */
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
> index 06e3f7d..9e5309d 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
> @@ -261,35 +261,6 @@
>  }
>
>  /**
> - * mpt3sas_scsi_direct_io_get - returns direct io flag
> - * @ioc: per adapter object
> - * @smid: system request message index
> - *
> - * Returns the smid stored scmd pointer.
> - */
> -inline u8
> -mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
> -{
> -       struct scsiio_tracker *st = mpt3sas_get_st_from_smid(ioc, smid);
> -
> -       return st ? st->direct_io : 0;
> -}
> -
> -/**
> - * mpt3sas_scsi_direct_io_set - sets direct io flag
> - * @ioc: per adapter object
> - * @smid: system request message index
> - * @direct_io: Zero or non-zero value to set in the direct_io flag
> - *
> - * Returns Nothing.
> - */
> -inline void
> -mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
> -{
> -       ioc->scsi_lookup[smid - 1].direct_io = direct_io;
> -}
> -
> -/**
>   * mpt3sas_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
>   * @ioc: per adapter object
>   * @scmd: pointer to scsi command object
> @@ -301,12 +272,12 @@
>   */
>  void
>  mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
> -       struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
> -       u16 smid)
> +       struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request)
>  {
>         sector_t v_lba, p_lba, stripe_off, column, io_size;
>         u32 stripe_sz, stripe_exp;
>         u8 num_pds, cmd = scmd->cmnd[0];
> +       struct scsiio_tracker *st = scsi_cmd_priv(scmd);
>
>         if (cmd != READ_10 && cmd != WRITE_10 &&
>             cmd != READ_16 && cmd != WRITE_16)
> @@ -342,5 +313,5 @@
>         else
>                 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
>
> -       mpt3sas_scsi_direct_io_set(ioc, smid, 1);
> +       st->direct_io = 1;
>  }
> --
> 1.8.5.6
>

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

* Re: [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete()
  2017-03-03 11:57   ` Sreekanth Reddy
@ 2017-03-03 13:53     ` Hannes Reinecke
  0 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-03-03 13:53 UTC (permalink / raw)
  To: Sreekanth Reddy
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

On 03/03/2017 12:57 PM, Sreekanth Reddy wrote:
> On Wed, Feb 22, 2017 at 4:01 PM, Hannes Reinecke <hare@suse.de> wrote:
>> Use 'host_busy' instead of counting outstanding commands by hand.
>>
>> Suggested-by: Christoph Hellwig <hch@lst.de>
>> Signed-off-by: Hannes Reinecke <hare@suse.com>
>> ---
>>  drivers/scsi/mpt3sas/mpt3sas_base.c | 14 ++++----------
>>  1 file changed, 4 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> index e6aafa5..169d185 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> @@ -2408,9 +2408,9 @@ struct scsiio_tracker *
>>          * See _wait_for_commands_to_complete() call with regards to this code.
>>          */
>>         if (ioc->shost_recovery && ioc->pending_io_count) {
>> -               if (ioc->pending_io_count == 1)
>> +               ioc->pending_io_count = atomic_read(&ioc->shost->host_busy);
>
> This won't consider the scsi IO issued from ioctl path. If that scsi
> io is still outstanding then here we will return without waiting for
> it to complete.
>
True. Will be fixing it up.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [PATCHv4 12/12] mpt3sas: lockless command submission
  2017-03-03 12:32   ` Sreekanth Reddy
@ 2017-03-03 13:59     ` Hannes Reinecke
  0 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-03-03 13:59 UTC (permalink / raw)
  To: Sreekanth Reddy
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

On 03/03/2017 01:32 PM, Sreekanth Reddy wrote:
> On Wed, Feb 22, 2017 at 4:01 PM, Hannes Reinecke <hare@suse.de> wrote:
>> Instead of holding 'struct scsiio_tracker' in its own pool we
>> can embed it into the payload of the scsi command. This allows
>> us to get rid of the lock when submitting and receiving commands
>> and streamline operations.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.com>
>> ---
>>  drivers/scsi/mpt3sas/mpt3sas_base.c      | 120 +++++++++++++------------------
>>  drivers/scsi/mpt3sas/mpt3sas_base.h      |  23 +++---
>>  drivers/scsi/mpt3sas/mpt3sas_ctl.c       |  17 +++--
>>  drivers/scsi/mpt3sas/mpt3sas_scsih.c     | 118 +++++++++---------------------
>>  drivers/scsi/mpt3sas/mpt3sas_warpdrive.c |  35 +--------
>>  5 files changed, 105 insertions(+), 208 deletions(-)
>>
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> index 169d185..966a775 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> @@ -863,12 +863,19 @@ static int mpt3sas_remove_dead_ioc_func(void *arg)
>>  }
>>
>>  struct scsiio_tracker *
>> -mpt3sas_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
>> +_get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
>
> Can we rename the name of this function as  _base_get_st_from_smid(),
> Since we always try to follow below notations,
>  * prefix with "_<filenamePart(i.e. base)>" if the function is used
> within this file other wise prefix with "mpt3sas_<filename>" if this
> function is shared between more than one file.
>
Sure, will do.

>>  {
>> +       struct scsi_cmnd *cmd;
>> +
>>         if (WARN_ON(!smid) ||
>>             WARN_ON(smid >= ioc->hi_priority_smid))
>>                 return NULL;
>> -       return &ioc->scsi_lookup[smid - 1];
>> +
>> +       cmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
>> +       if (cmd)
>> +               return scsi_cmd_priv(cmd);
>> +
>> +       return NULL;
>>  }
>>
>>  /**
>> @@ -889,7 +896,7 @@ struct scsiio_tracker *
>>                 struct scsiio_tracker *st;
>>
>>                 if (smid < ctl_smid) {
>> -                       st = mpt3sas_get_st_from_smid(ioc, smid);
>> +                       st = _get_st_from_smid(ioc, smid);
>>                         if (st)
>>                                 cb_idx = st->cb_idx;
>
> I think, here we can safely assign "cb_idx"  as "ioc->scsi_io_cb_idx",
> no need to get it from scsiio_tracker. since all the smid's below
> ctl_smid will we used for SCSI IO's recieved from scsih_qcmd.
>
In theory, yes.
However, 'cb_idx' get reset to 0xFF once we're done with the command,
so this serves the dual purpose of getting us the callback index _and_ 
telling us if the command is in flight.

[ .. ]
>> @@ -1297,9 +1305,7 @@ struct scsiio_tracker *
>>         chain_req = list_entry(ioc->free_chain_list.next,
>>             struct chain_tracker, tracker_list);
>>         list_del_init(&chain_req->tracker_list);
>> -       st = mpt3sas_get_st_from_smid(ioc, smid);
>> -       if (st)
>> -               list_add_tail(&chain_req->tracker_list, &st->chain_list);
>> +       list_add_tail(&chain_req->tracker_list, &st->chain_list);
>>         spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
>
> Still we have this lock in the IO path. May be we can remove this lock
> too by allocating "ioc->ioc->chains_needed_per_io * shost->can_queue"
> number of chain buffers and we can acces the required chain buffer
> using scmd's tag pluse chain_offset_per_io coressponding to that
> repective tag.
>
> May be we will post a separate patch for this after some time.
>
Actually, I tried this (and I have a patch to move that to use sbitmap), 
but didn't notice any significant improvement.
(But then as I only ran against a middle-range SSD setup this wasn't 
really surprising).
But sure, I can dig it up and include in this patchset.

[ .. ]
>> @@ -2359,9 +2316,8 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>>                 goto out;
>>         }
>>
>> -       /* search for the command */
>> -       st = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
>> -       if (!st) {
>> +       /* check for completed command */
>> +       if (st->cb_idx == 0xFF); {
>
> ";" should be removed from above line, otherwise always we return task
> abort TM with "SUCCESS" status without issueing the TM to Firmware.
>
>
Ouch. Of course. Thanks for catching this.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [PATCHv4 09/12] mpt3sas: simplify task management functions
  2017-02-22 10:31 ` [PATCHv4 09/12] mpt3sas: simplify task management functions Hannes Reinecke
@ 2017-03-06  5:16   ` Sreekanth Reddy
  2017-03-13 15:15     ` Hannes Reinecke
  0 siblings, 1 reply; 20+ messages in thread
From: Sreekanth Reddy @ 2017-03-06  5:16 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

I feel that using these flags are not working as expected. From the
driver's prospective it should return status of the TM based on
whether it has cleared reference of the timed out IO in the driver or
not (i.e. if it is successfully able to clear the reference (i.e.
cleared from scsi lookup) of the timed out IO from driver, firmware
then return success status otherwise return failure status). It should
not check for it's above layer reference.

On Wed, Feb 22, 2017 at 4:01 PM, Hannes Reinecke <hare@suse.de> wrote:
> One can simply check 'target_busy' or 'device_busy' when figuring
> out if there are outstanding commands; no need to painstakingly
> counting them by hand.
>
> Suggested-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_scsih.c | 88 +++---------------------------------
>  1 file changed, 7 insertions(+), 81 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 1c45fb3..e0cb35d 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> @@ -1133,74 +1133,6 @@ struct _sas_node *
>  }
>
>  /**
> - * _scsih_scsi_lookup_find_by_target - search for matching channel:id
> - * @ioc: per adapter object
> - * @id: target id
> - * @channel: channel
> - * Context: This function will acquire ioc->scsi_lookup_lock.
> - *
> - * This will search for a matching channel:id in the scsi_lookup array,
> - * returning 1 if found.
> - */
> -static u8
> -_scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
> -       int channel)
> -{
> -       u8 found;
> -       unsigned long   flags;
> -       int i;
> -
> -       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
> -       found = 0;
> -       for (i = 0 ; i < ioc->scsiio_depth; i++) {
> -               if (ioc->scsi_lookup[i].scmd &&
> -                   (ioc->scsi_lookup[i].scmd->device->id == id &&
> -                   ioc->scsi_lookup[i].scmd->device->channel == channel)) {
> -                       found = 1;
> -                       goto out;
> -               }
> -       }
> - out:
> -       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
> -       return found;
> -}
> -
> -/**
> - * _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 MPT3SAS_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->scsiio_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_change_queue_depth - setting device queue depth
>   * @sdev: scsi device struct
>   * @qdepth: requested queue depth
> @@ -2339,19 +2271,9 @@ struct _sas_node *
>                 rc = FAILED;
>                 break;
>
> -       case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
> -               if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
> -                       rc = FAILED;
> -               else
> -                       rc = SUCCESS;
> -               break;
>         case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
>         case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
> -               if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
> -                       rc = FAILED;
> -               else
> -                       rc = SUCCESS;
> -               break;
> +       case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
>         case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
>                 rc = SUCCESS;
>                 break;
> @@ -2554,7 +2476,9 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>         r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
>             scmd->device->id, scmd->device->lun,
>             MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
> -
> +       /* Check for busy commands after reset */
> +       if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
> +               r = FAILED;

For an experiment, I have mocked driver to return 'task abort' with
fail status even though it was able to abort the IO. I have done this
so that we can test whether device reset is working fine or not.

I have started the IO's on a drive and using lsiutil utility I have
done link reset for that drive. Then I observe that some IO's got
timedout and received task abort TM for these timedout. As I have
hard-coded task abort TM to return with failure status, so after some
time driver has received device reset TM. after processing device TM,
in the driver still we observe that 'device_busy' value is non-zero
and driver returns this TM with failure status, even though their is
no references for the timedout IO in the driver(i.e. driver has
returned the timed out IO back to SML).

Even without modifying anything in the driver. Run the IO's on one
drive and issue device reset TM using sg_util and we observe the
device_busy for this device will be non-zero (even it has aborted all
the outstanding IOs at that time for that device) and eventually
target reset TM is received by the driver.

>   out:
>         sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
>             ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> @@ -2616,7 +2540,9 @@ int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>         r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
>             scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
>             30);
> -
> +       /* Check for busy commands after reset */
> +       if (r == SUCCESS && atomic_read(&starget->target_busy))

I have printed this 'target_busy' variable just before issuing target
reset TM to firmware and I always observe that this variable value is
zero, as shown below,

[ +16.424120] scsi target11:0:4: attempting target reset! scmd(ffff883ede7b4a80)
[  +0.000005] sd 11:0:4:0: CDB: Test Unit Ready
[  +0.000005] scsi target11:0:4: handle(0x0015),
sas_address(0x500003956c88df5b), phy(12)
[  +0.000002] scsi target11:0:4:
enclosure_logical_id(0x500605b012345600), slot(6)
[  +0.000002] scsi target11:0:4: enclosure level(0x0000),connector name(C1  )
[  +0.000002] LSI debug.. target_busy count: 0
[  +0.000004] mpt3sas_cm1: sending tm: handle(0x0015), task_type(0x03), smid(0)
[  +0.249457] sd 11:0:4:0: [sdj] tag#294 CDB: Read(10) 28 00 08 49 9e
80 00 0a 00 00
[  +0.000002] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(295)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(1310720)
[  +0.000000] mpt3sas_cm1:     tag(8473), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000003] sd 11:0:4:0: [sdj] tag#209 CDB: Read(10) 28 00 08 5b ec
c0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(210)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(7828), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#123 CDB: Read(10) 28 00 08 56 03
a0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(124)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(7106), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#0 CDB: Read(10) 28 00 08 cc 0f 80
00 03 40 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(1)
[  +0.000000] mpt3sas_cm1:     request_len(425984), underflow(425984),
resid(425984)
[  +0.000001] mpt3sas_cm1:     tag(7042), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#33 CDB: Read(10) 28 00 08 cc 1e
e0 00 03 80 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(34)
[  +0.000001] mpt3sas_cm1:     request_len(458752), underflow(458752),
resid(458752)
[  +0.000000] mpt3sas_cm1:     tag(7026), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#221 CDB: Read(10) 28 00 08 50 cc
e0 00 01 c0 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(222)
[  +0.000001] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(183296)
[  +0.000000] mpt3sas_cm1:     tag(5505), transfer_count(46080),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#36 CDB: Read(10) 28 00 08 91 c3
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(37)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(262144)
[  +0.000001] mpt3sas_cm1:     tag(5337), transfer_count(1048576),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#17 CDB: Read(10) 28 00 08 cc 18
a0 00 03 20 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(18)
[  +0.000000] mpt3sas_cm1:     request_len(409600), underflow(409600),
resid(409600)
[  +0.000001] mpt3sas_cm1:     tag(5129), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#191 CDB: Read(10) 28 00 08 92 19
40 00 0a 00 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(192)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(5109), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#41 CDB: Read(10) 28 00 08 50 ce
a0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(42)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(1310720)
[  +0.000001] mpt3sas_cm1:     tag(5086), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#199 CDB: Read(10) 28 00 08 92 da
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(200)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000001] mpt3sas_cm1:     tag(5055), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#195 CDB: Read(10) 28 00 08 5b f6
c0 00 01 c0 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(196)
[  +0.000001] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000000] mpt3sas_cm1:     tag(4755), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#108 CDB: Read(10) 28 00 08 cc 0d
40 00 02 40 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(109)
[  +0.000000] mpt3sas_cm1:     request_len(294912), underflow(294912),
resid(294912)
[  +0.000001] mpt3sas_cm1:     tag(4706), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#40 CDB: Read(10) 28 00 08 55 ef
a0 00 0a 00 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(41)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(4446), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#219 CDB: Read(10) 28 00 08 50 c2
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(220)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000001] mpt3sas_cm1:     tag(4301), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#21 CDB: Read(10) 28 00 08 92 37
40 00 01 c0 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(22)
[  +0.000000] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000001] mpt3sas_cm1:     tag(4261), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#154 CDB: Read(10) 28 00 08 91 cf
a0 00 01 c0 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(155)
[  +0.000000] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000001] mpt3sas_cm1:     tag(4246), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#201 CDB: Read(10) 28 00 08 92 e4
e0 00 0a 00 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(202)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(4068), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#26 CDB: Read(10) 28 00 08 cc 1b
c0 00 03 20 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(27)
[  +0.000001] mpt3sas_cm1:     request_len(409600), underflow(409600),
resid(409600)
[  +0.000000] mpt3sas_cm1:     tag(3989), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000002] sd 11:0:4:0: [sdj] tag#60 CDB: Read(10) 28 00 08 49 8a
80 00 0a 00 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(61)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(1310720)
[  +0.000000] mpt3sas_cm1:     tag(3974), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#196 CDB: Read(10) 28 00 08 92 23
40 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(197)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000001] mpt3sas_cm1:     tag(3704), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#179 CDB: Read(10) 28 00 08 92 ee
e0 00 01 c0 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(180)
[  +0.000000] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000001] mpt3sas_cm1:     tag(3491), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#37 CDB: Read(10) 28 00 08 5b d8
c0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(38)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(3363), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#19 CDB: Read(10) 28 00 08 91 af
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(20)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(262144)
[  +0.000000] mpt3sas_cm1:     tag(3329), transfer_count(1048576),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#32 CDB: Read(10) 28 00 08 91 b9
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(33)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(262144)
[  +0.000001] mpt3sas_cm1:     tag(3075), transfer_count(1048576),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#16 CDB: Read(10) 28 00 08 cc 12
c0 00 05 e0 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(17)
[  +0.000000] mpt3sas_cm1:     request_len(770048), underflow(770048),
resid(770048)
[  +0.000001] mpt3sas_cm1:     tag(3017), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#200 CDB: Read(10) 28 00 08 56 0d
a0 00 01 c0 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(201)
[  +0.000000] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000001] mpt3sas_cm1:     tag(2588), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#207 CDB: Read(10) 28 00 08 5b e2
c0 00 0a 00 00
[  +0.000000] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(208)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(2355), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#5 CDB: Read(10) 28 00 08 cc 05 20
00 02 c0 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(6)
[  +0.000000] mpt3sas_cm1:     request_len(360448), underflow(360448),
resid(360448)
[  +0.000000] mpt3sas_cm1:     tag(2337), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#86 CDB: Read(10) 28 00 08 55 f9
a0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(87)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(2068), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#13 CDB: Read(10) 28 00 08 cc 07
e0 00 05 60 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(14)
[  +0.000000] mpt3sas_cm1:     request_len(704512), underflow(704512),
resid(704512)
[  +0.000000] mpt3sas_cm1:     tag(1860), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#230 CDB: Read(10) 28 00 08 49 94
80 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(231)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(1310720)
[  +0.000000] mpt3sas_cm1:     tag(1813), transfer_count(0),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#35 CDB: Read(10) 28 00 08 92 2d
40 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(36)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(1310720)
[  +0.000001] mpt3sas_cm1:     tag(1764), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#91 CDB: Read(10) 28 00 08 49 a8
80 00 01 c0 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(92)
[  +0.000000] mpt3sas_cm1:     request_len(229376), underflow(229376),
resid(229376)
[  +0.000001] mpt3sas_cm1:     tag(1654), transfer_count(0),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#197 CDB: Read(10) 28 00 08 92 d0
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(198)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000001] mpt3sas_cm1:     tag(1353), transfer_count(524288),
sc->result(0x00080000)
[  +0.000000] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000001] sd 11:0:4:0: [sdj] tag#146 CDB: Read(10) 28 00 08 50 b8
e0 00 0a 00 00
[  +0.000001] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000000] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015), ioc_status(scsi task
terminated)(0x0048), smid(147)
[  +0.000000] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(786432)
[  +0.000000] mpt3sas_cm1:     tag(1177), transfer_count(524288),
sc->result(0x00080000)
[  +0.000001] mpt3sas_cm1:     scsi_status(good)(0x00),
scsi_state(state terminated no status )(0x0c)
[  +0.000038] mpt3sas_cm1: complete tm: ioc_status(0x0000),
loginfo(0x00000000), term_count(0x00000024)
[  +0.000002] mpt3sas_cm1: response_code(0x0): task management request completed
[  +0.000007] scsi target11:0:4: target reset: SUCCESS scmd(ffff883ede7b4a80)
[  +0.000674] sd 11:0:4:0: tag#50 CDB: Test Unit Ready 00 00 00 00 00 00
[  +0.000002] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000002] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015),
ioc_status(success)(0x0000), smid(51)
[  +0.000001] mpt3sas_cm1:     request_len(0), underflow(0), resid(0)
[  +0.000002] mpt3sas_cm1:     tag(0), transfer_count(0), sc->result(0x00000000)
[  +0.000002] mpt3sas_cm1:     scsi_status(check condition)(0x02),
scsi_state(autosense valid )(0x01)
[  +0.000003] mpt3sas_cm1:     [sense_key,asc,ascq]: [0x06,0x29,0x02], count(96)
[  +0.000003] sd 11:0:4:0: tag#50 CDB: Test Unit Ready 00 00 00 00 00 00
[  +0.000002] mpt3sas_cm1:     sas_address(0x500003956c88df5b), phy(12)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(6)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0015),
ioc_status(success)(0x0000), smid(51)
[  +0.000002] mpt3sas_cm1:     request_len(0), underflow(0), resid(0)
[  +0.000001] mpt3sas_cm1:     tag(0), transfer_count(0), sc->result(0x00000002)
[  +0.000002] mpt3sas_cm1:     scsi_status(check condition)(0x02),
scsi_state(autosense valid )(0x01)
[  +0.000002] mpt3sas_cm1:     [sense_key,asc,ascq]: [0x06,0x29,0x02], count(96)
[  +0.613601] mpt3sas_cm1: Discovery: (start)

[  +0.000019] mpt3sas_cm1: discovery event: (start)

[  +0.000097] mpt3sas_cm1: SAS Topology Change List
[  +0.000004] mpt3sas_cm1: sas topology change: (responding)
[  +0.000001]     handle(0x0000), enclosure_handle(0x0001)
start_phy(12), count(1)
[  +0.000001] mpt3sas_cm1: Discovery: (stop)

[  +0.000017]     phy(12), attached_handle(0x0015): link rate change:
link rate: new(0x0b), old(0x0b)
[  +0.000001] mpt3sas_cm1: updating handles for sas_host(0x500605b012345600)
[  +0.000356] mpt3sas_cm1: discovery event: (stop)

[  +0.740157] sd 11:0:2:0: [sdh] tag#63 CDB: Read(10) 28 00 08 a9 f8
20 00 0a 00 00
[  +0.000003] mpt3sas_cm1:     sas_address(0x500003956c88df9f), phy(10)
[  +0.000000] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(5)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0016), ioc_status(scsi data
underrun)(0x0045), smid(64)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(12288)
[  +0.000001] mpt3sas_cm1:     tag(0), transfer_count(1298432),
sc->result(0x00000002)
[  +0.000001] mpt3sas_cm1:     scsi_status(check condition)(0x02),
scsi_state(autosense valid )(0x01)
[  +0.000001] mpt3sas_cm1:     [sense_key,asc,ascq]: [0x0b,0x4b,0x03], count(96)
[Mar 3 16:00] sd 11:0:2:0: [sdh] tag#61 CDB: Read(10) 28 00 08 fc bd
80 00 0a 00 00
[  +0.000002] mpt3sas_cm1:     sas_address(0x500003956c88df9f), phy(10)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(5)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000000] mpt3sas_cm1:     handle(0x0016), ioc_status(scsi data
underrun)(0x0045), smid(62)
[  +0.000001] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(155648)
[  +0.000001] mpt3sas_cm1:     tag(0), transfer_count(1155072),
sc->result(0x00000002)
[  +0.000001] mpt3sas_cm1:     scsi_status(check condition)(0x02),
scsi_state(autosense valid )(0x01)
[  +0.000000] mpt3sas_cm1:     [sense_key,asc,ascq]: [0x0b,0x4b,0x03], count(96)
[ +11.430447] sd 11:0:2:0: [sdh] tag#89 CDB: Read(10) 28 00 09 22 1d
80 00 0a 00 00
[  +0.000004] mpt3sas_cm1:     sas_address(0x500003956c88df9f), phy(10)
[  +0.000001] mpt3sas_cm1:     enclosure_logical_id(0x500605b012345600),slot(5)
[  +0.000001] mpt3sas_cm1:     enclosure level(0x0000), connector name( C1  )
[  +0.000001] mpt3sas_cm1:     handle(0x0016), ioc_status(scsi data
underrun)(0x0045), smid(90)
[  +0.000002] mpt3sas_cm1:     request_len(1310720),
underflow(1310720), resid(806912)
[  +0.000001] mpt3sas_cm1:     tag(0), transfer_count(503808),
sc->result(0x00000002)
[  +0.000001] mpt3sas_cm1:     scsi_status(check condition)(0x02),
scsi_state(autosense valid )(0x01)
[  +0.000001] mpt3sas_cm1:     [sense_key,asc,ascq]: [0x0b,0x4b,0x03], count(96)


Thanks,
Sreekanth

> +               r = FAILED;
>   out:
>         starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
>             ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
> --
> 1.8.5.6
>

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

* Re: [PATCHv4 09/12] mpt3sas: simplify task management functions
  2017-03-06  5:16   ` Sreekanth Reddy
@ 2017-03-13 15:15     ` Hannes Reinecke
  0 siblings, 0 replies; 20+ messages in thread
From: Hannes Reinecke @ 2017-03-13 15:15 UTC (permalink / raw)
  To: Sreekanth Reddy
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Kashyap Desai, Sathya Prakash, Hannes Reinecke

On 03/06/2017 06:16 AM, Sreekanth Reddy wrote:
> I feel that using these flags are not working as expected. From the
> driver's prospective it should return status of the TM based on
> whether it has cleared reference of the timed out IO in the driver or
> not (i.e. if it is successfully able to clear the reference (i.e.
> cleared from scsi lookup) of the timed out IO from driver, firmware
> then return success status otherwise return failure status). It should
> not check for it's above layer reference.
> 
Looking into it you are actually right.

The SCSI midlayer will only decrease a 'device_busy' and the like if the
commands are completed, ie after ->scsi_done() has been called.
But the whole point of the error handler OTOH is that ->scsi_done() is
_not_ called, but rather the commands are left alone until SCSI EH
completed, and only _then_ calling ->scsi_done().

Hence 'device_busy' et al trivially can never be zero while SCSI EH is
running.

I'll be rewriting that for the next submission.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

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

end of thread, other threads:[~2017-03-13 15:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22 10:31 [PATCHv4 00/12] mpt3sas: lockless command submission Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors Hannes Reinecke
2017-02-23 22:04   ` Martin K. Petersen
2017-02-22 10:31 ` [PATCHv4 02/12] mpt3sas: set default value for cb_idx Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 03/12] mpt3sas: use 'list_splice_init()' Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 04/12] mpt3sas: separate out _base_recovery_check() Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 05/12] mpt3sas: open-code _scsih_scsi_lookup_get() Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 06/12] mpt3sas: Introduce mpt3sas_get_st_from_smid() Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 07/12] mpt3sas: check command status before attempting abort Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 08/12] mpt3sas: always use first reserved smid for ioctl passthrough Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 09/12] mpt3sas: simplify task management functions Hannes Reinecke
2017-03-06  5:16   ` Sreekanth Reddy
2017-03-13 15:15     ` Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 10/12] mpt3sas: simplify mpt3sas_scsi_issue_tm() Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 11/12] mpt3sas: simplify _wait_for_commands_to_complete() Hannes Reinecke
2017-03-03 11:57   ` Sreekanth Reddy
2017-03-03 13:53     ` Hannes Reinecke
2017-02-22 10:31 ` [PATCHv4 12/12] mpt3sas: lockless command submission Hannes Reinecke
2017-03-03 12:32   ` Sreekanth Reddy
2017-03-03 13:59     ` Hannes Reinecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.