linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] hisi_sas: device id/IPTT collision workaround
@ 2016-04-15 13:36 John Garry
  2016-04-15 13:36 ` [PATCH 1/3] hisi_sas: add device and slot alloc hw methods John Garry
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Garry @ 2016-04-15 13:36 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao,
	John Garry

This patchset introduces a workaround to a hw quirk
in the HiSilicon SAS controller v2 hw.

The quirk is as follows:
When a SATA and SAS frame arrives at the host at
the same time the frames may be swapped under this
condition:
SATA device id bit [10:0] == SAS frame IPTT bit [10:0]
The workaround is to ensure these 2 values never
match. The workaround algorithm is as follows:
- SATA device id bit0 always 0
- SATA IPTT has no restriction
- SAS IPTT bit0 always 1
- SAS device id has no restriction

The major restriction of this workaround is the
SAS IPTT range is halved, but this should be ok
as testing has shown that even using half the IPTT
range does not affect performance.

John Garry (3):
  hisi_sas: add device and slot alloc hw methods
  hisi_sas: add slot_index_alloc_quirk_v2_hw()
  hisi_sas: add alloc_dev_quirk_v2_hw()

 drivers/scsi/hisi_sas/hisi_sas.h       |  3 ++
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 11 +++++--
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 58 ++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)

-- 
1.9.1


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

* [PATCH 1/3] hisi_sas: add device and slot alloc hw methods
  2016-04-15 13:36 [PATCH 0/3] hisi_sas: device id/IPTT collision workaround John Garry
@ 2016-04-15 13:36 ` John Garry
  2016-04-15 13:51   ` Hannes Reinecke
  2016-04-15 13:36 ` [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw() John Garry
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: John Garry @ 2016-04-15 13:36 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao,
	John Garry

Add methods to use HW specific versions of
functions to allocate slot and device.
HW specific methods are permitted to workaround
device id vs IPTT collision issue in v2 hw.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/hisi_sas/hisi_sas.h      |  3 +++
 drivers/scsi/hisi_sas/hisi_sas_main.c | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h
index 0978016..d7cab72 100644
--- a/drivers/scsi/hisi_sas/hisi_sas.h
+++ b/drivers/scsi/hisi_sas/hisi_sas.h
@@ -133,6 +133,9 @@ struct hisi_sas_hw {
 	int (*hw_init)(struct hisi_hba *hisi_hba);
 	void (*setup_itct)(struct hisi_hba *hisi_hba,
 			   struct hisi_sas_device *device);
+	int (*slot_index_alloc)(struct hisi_hba *hisi_hba, int *slot_idx,
+				struct domain_device *device);
+	struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
 	void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
 	int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
 	void (*start_delivery)(struct hisi_hba *hisi_hba);
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 097ab4f..18dd5ea 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -227,7 +227,11 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba,
 	} else
 		n_elem = task->num_scatter;
 
-	rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx);
+	if (hisi_hba->hw->slot_index_alloc)
+		rc = hisi_hba->hw->slot_index_alloc(hisi_hba, &slot_idx,
+						    device);
+	else
+		rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx);
 	if (rc)
 		goto err_out;
 	rc = hisi_hba->hw->get_free_slot(hisi_hba, &dlvry_queue,
@@ -417,7 +421,10 @@ static int hisi_sas_dev_found(struct domain_device *device)
 	struct hisi_sas_device *sas_dev;
 	struct device *dev = &hisi_hba->pdev->dev;
 
-	sas_dev = hisi_sas_alloc_dev(device);
+	if (hisi_hba->hw->alloc_dev)
+		sas_dev = hisi_hba->hw->alloc_dev(device);
+	else
+		sas_dev = hisi_sas_alloc_dev(device);
 	if (!sas_dev) {
 		dev_err(dev, "fail alloc dev: max support %d devices\n",
 			HISI_SAS_MAX_DEVICES);
-- 
1.9.1

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

* [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw()
  2016-04-15 13:36 [PATCH 0/3] hisi_sas: device id/IPTT collision workaround John Garry
  2016-04-15 13:36 ` [PATCH 1/3] hisi_sas: add device and slot alloc hw methods John Garry
@ 2016-04-15 13:36 ` John Garry
  2016-04-15 13:51   ` Hannes Reinecke
  2016-04-15 13:36 ` [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw() John Garry
  2016-04-15 20:56 ` [PATCH 0/3] hisi_sas: device id/IPTT collision workaround Martin K. Petersen
  3 siblings, 1 reply; 8+ messages in thread
From: John Garry @ 2016-04-15 13:36 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao,
	John Garry

Add v2 hw custom function slot_index_alloc_quirk_v2_hw().
SAS devices should have IPTT bit0 equal to 1.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
index 4276594..f2966d8 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
@@ -465,6 +465,33 @@ static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
 	return readl(regs);
 }
 
+/* This function needs to be protected from pre-emption. */
+static int
+slot_index_alloc_quirk_v2_hw(struct hisi_hba *hisi_hba, int *slot_idx,
+		       struct domain_device *device)
+{
+	unsigned int index = 0;
+	void *bitmap = hisi_hba->slot_index_tags;
+	int sata_dev = dev_is_sata(device);
+
+	while (1) {
+		index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count,
+					   index);
+		if (index >= hisi_hba->slot_index_count)
+			return -SAS_QUEUE_FULL;
+		/*
+		 * SAS IPTT bit0 should be 1
+		 */
+		if (sata_dev || (index & 1))
+			break;
+		index++;
+	}
+
+	set_bit(index, bitmap);
+	*slot_idx = index;
+	return 0;
+}
+
 static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
 {
 	u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
@@ -2167,6 +2194,7 @@ static int hisi_sas_v2_init(struct hisi_hba *hisi_hba)
 static const struct hisi_sas_hw hisi_sas_v2_hw = {
 	.hw_init = hisi_sas_v2_init,
 	.setup_itct = setup_itct_v2_hw,
+	.slot_index_alloc = slot_index_alloc_quirk_v2_hw,
 	.sl_notify = sl_notify_v2_hw,
 	.get_wideport_bitmap = get_wideport_bitmap_v2_hw,
 	.free_device = free_device_v2_hw,
-- 
1.9.1

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

* [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw()
  2016-04-15 13:36 [PATCH 0/3] hisi_sas: device id/IPTT collision workaround John Garry
  2016-04-15 13:36 ` [PATCH 1/3] hisi_sas: add device and slot alloc hw methods John Garry
  2016-04-15 13:36 ` [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw() John Garry
@ 2016-04-15 13:36 ` John Garry
  2016-04-15 13:52   ` Hannes Reinecke
  2016-04-15 20:56 ` [PATCH 0/3] hisi_sas: device id/IPTT collision workaround Martin K. Petersen
  3 siblings, 1 reply; 8+ messages in thread
From: John Garry @ 2016-04-15 13:36 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao,
	John Garry

Add custom version of function to allocate
device, alloc_dev_quirk_v2_hw().
For sata devices the device id bit0 should be
0.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
index f2966d8..bbe98ec 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
@@ -492,6 +492,35 @@ slot_index_alloc_quirk_v2_hw(struct hisi_hba *hisi_hba, int *slot_idx,
 	return 0;
 }
 
+static struct
+hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device)
+{
+	struct hisi_hba *hisi_hba = device->port->ha->lldd_ha;
+	struct hisi_sas_device *sas_dev = NULL;
+	int i, sata_dev = dev_is_sata(device);
+
+	spin_lock(&hisi_hba->lock);
+	for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
+		/*
+		 * SATA device id bit0 should be 0
+		 */
+		if (sata_dev && (i & 1))
+			continue;
+		if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) {
+			hisi_hba->devices[i].device_id = i;
+			sas_dev = &hisi_hba->devices[i];
+			sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
+			sas_dev->dev_type = device->dev_type;
+			sas_dev->hisi_hba = hisi_hba;
+			sas_dev->sas_device = device;
+			break;
+		}
+	}
+	spin_unlock(&hisi_hba->lock);
+
+	return sas_dev;
+}
+
 static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
 {
 	u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
@@ -2195,6 +2224,7 @@ static const struct hisi_sas_hw hisi_sas_v2_hw = {
 	.hw_init = hisi_sas_v2_init,
 	.setup_itct = setup_itct_v2_hw,
 	.slot_index_alloc = slot_index_alloc_quirk_v2_hw,
+	.alloc_dev = alloc_dev_quirk_v2_hw,
 	.sl_notify = sl_notify_v2_hw,
 	.get_wideport_bitmap = get_wideport_bitmap_v2_hw,
 	.free_device = free_device_v2_hw,
-- 
1.9.1

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

* Re: [PATCH 1/3] hisi_sas: add device and slot alloc hw methods
  2016-04-15 13:36 ` [PATCH 1/3] hisi_sas: add device and slot alloc hw methods John Garry
@ 2016-04-15 13:51   ` Hannes Reinecke
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2016-04-15 13:51 UTC (permalink / raw)
  To: John Garry, jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao

On 04/15/2016 03:36 PM, John Garry wrote:
> Add methods to use HW specific versions of
> functions to allocate slot and device.
> HW specific methods are permitted to workaround
> device id vs IPTT collision issue in v2 hw.
> 
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
>  drivers/scsi/hisi_sas/hisi_sas.h      |  3 +++
>  drivers/scsi/hisi_sas/hisi_sas_main.c | 11 +++++++++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

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] 8+ messages in thread

* Re: [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw()
  2016-04-15 13:36 ` [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw() John Garry
@ 2016-04-15 13:51   ` Hannes Reinecke
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2016-04-15 13:51 UTC (permalink / raw)
  To: John Garry, jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao

On 04/15/2016 03:36 PM, John Garry wrote:
> Add v2 hw custom function slot_index_alloc_quirk_v2_hw().
> SAS devices should have IPTT bit0 equal to 1.
> 
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
>  drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

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] 8+ messages in thread

* Re: [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw()
  2016-04-15 13:36 ` [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw() John Garry
@ 2016-04-15 13:52   ` Hannes Reinecke
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Reinecke @ 2016-04-15 13:52 UTC (permalink / raw)
  To: John Garry, jejb, martin.petersen
  Cc: linuxarm, john.garry2, linux-scsi, linux-kernel, zhangfei.gao

On 04/15/2016 03:36 PM, John Garry wrote:
> Add custom version of function to allocate
> device, alloc_dev_quirk_v2_hw().
> For sata devices the device id bit0 should be
> 0.
> 
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
>  drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

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)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 0/3] hisi_sas: device id/IPTT collision workaround
  2016-04-15 13:36 [PATCH 0/3] hisi_sas: device id/IPTT collision workaround John Garry
                   ` (2 preceding siblings ...)
  2016-04-15 13:36 ` [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw() John Garry
@ 2016-04-15 20:56 ` Martin K. Petersen
  3 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2016-04-15 20:56 UTC (permalink / raw)
  To: John Garry
  Cc: jejb, martin.petersen, linuxarm, john.garry2, linux-scsi,
	linux-kernel, zhangfei.gao

>>>>> "John" == John Garry <john.garry@huawei.com> writes:

John> This patchset introduces a workaround to a hw quirk in the
John> HiSilicon SAS controller v2 hw.

John> The quirk is as follows: When a SATA and SAS frame arrives at the
John> host at the same time the frames may be swapped under this
John> condition: SATA device id bit [10:0] == SAS frame IPTT bit [10:0]
John> The workaround is to ensure these 2 values never match. The
John> workaround algorithm is as follows: - SATA device id bit0 always 0
John> - SATA IPTT has no restriction - SAS IPTT bit0 always 1 - SAS
John> device id has no restriction

John> The major restriction of this workaround is the SAS IPTT range is
John> halved, but this should be ok as testing has shown that even using
John> half the IPTT range does not affect performance.

Applied to 4.7/scsi-queue.

Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2016-04-15 20:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-15 13:36 [PATCH 0/3] hisi_sas: device id/IPTT collision workaround John Garry
2016-04-15 13:36 ` [PATCH 1/3] hisi_sas: add device and slot alloc hw methods John Garry
2016-04-15 13:51   ` Hannes Reinecke
2016-04-15 13:36 ` [PATCH 2/3] hisi_sas: add slot_index_alloc_quirk_v2_hw() John Garry
2016-04-15 13:51   ` Hannes Reinecke
2016-04-15 13:36 ` [PATCH 3/3] hisi_sas: add alloc_dev_quirk_v2_hw() John Garry
2016-04-15 13:52   ` Hannes Reinecke
2016-04-15 20:56 ` [PATCH 0/3] hisi_sas: device id/IPTT collision workaround Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).