Re: [PATCH 3.12 81/94] libata: support the ata host which implements a queue depth less than 32

2014-07-30 Thread Thomas Backlund

Jiri Slaby skrev den 30.7.2014 15:15:

From: Kevin Hao 

3.12-stable review patch.  If anyone has any objections, please let me know.

===

commit 1871ee134b73fb4cadab75752a7152ed2813c751 upstream.

The sata on fsl mpc8315e is broken after the commit 8a4aeec8d2d6
("libata/ahci: accommodate tag ordered controllers"). The reason is
that the ata controller on this SoC only implement a queue depth of
16. When issuing the commands in tag order, all the commands in tag
16 ~ 31 are mapped to tag 0 unconditionally and then causes the sata
malfunction. It makes no senses to use a 32 queue in software while
the hardware has less queue depth. So consider the queue depth
implemented by the hardware when requesting a command tag.

Fixes: 8a4aeec8d2d6 ("libata/ahci: accommodate tag ordered controllers")
Signed-off-by: Kevin Hao 
Acked-by: Dan Williams 
Signed-off-by: Tejun Heo 
Signed-off-by: Jiri Slaby 


As you have added this to 3.12 branch, you also need to add this to 
avoid SAS breakage:


commit 1a112d10f03e83fb3a2fdc4c9165865dec8a3ca6
Author: Tejun Heo 
Date:   Wed Jul 23 09:05:27 2014 -0400

libata: introduce ata_host->n_tags to avoid oops on SAS controllers

1871ee134b73 ("libata: support the ata host which implements a queue
depth less than 32") directly used ata_port->scsi_host->can_queue from
ata_qc_new() to determine the number of tags supported by the host;
unfortunately, SAS controllers doing SATA don't initialize ->scsi_host
leading to the following oops.

--

Thomas

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3.12 81/94] libata: support the ata host which implements a queue depth less than 32

2014-07-30 Thread Jiri Slaby
From: Kevin Hao 

3.12-stable review patch.  If anyone has any objections, please let me know.

===

commit 1871ee134b73fb4cadab75752a7152ed2813c751 upstream.

The sata on fsl mpc8315e is broken after the commit 8a4aeec8d2d6
("libata/ahci: accommodate tag ordered controllers"). The reason is
that the ata controller on this SoC only implement a queue depth of
16. When issuing the commands in tag order, all the commands in tag
16 ~ 31 are mapped to tag 0 unconditionally and then causes the sata
malfunction. It makes no senses to use a 32 queue in software while
the hardware has less queue depth. So consider the queue depth
implemented by the hardware when requesting a command tag.

Fixes: 8a4aeec8d2d6 ("libata/ahci: accommodate tag ordered controllers")
Signed-off-by: Kevin Hao 
Acked-by: Dan Williams 
Signed-off-by: Tejun Heo 
Signed-off-by: Jiri Slaby 
---
 drivers/ata/libata-core.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index d2eb9df3da3d..97b5e01a6814 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4787,6 +4787,10 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
  * ata_qc_new - Request an available ATA command, for queueing
  * @ap: target port
  *
+ * Some ATA host controllers may implement a queue depth which is less
+ * than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond
+ * the hardware limitation.
+ *
  * LOCKING:
  * None.
  */
@@ -4794,14 +4798,16 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
 static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
 {
struct ata_queued_cmd *qc = NULL;
-   unsigned int i, tag;
+   unsigned int i, tag, max_queue;
+
+   max_queue = ap->scsi_host->can_queue;
 
/* no command while frozen */
if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
return NULL;
 
-   for (i = 0; i < ATA_MAX_QUEUE; i++) {
-   tag = (i + ap->last_tag + 1) % ATA_MAX_QUEUE;
+   for (i = 0, tag = ap->last_tag + 1; i < max_queue; i++, tag++) {
+   tag = tag < max_queue ? tag : 0;
 
/* the last tag is reserved for internal command. */
if (tag == ATA_TAG_INTERNAL)
@@ -6184,6 +6190,16 @@ int ata_host_register(struct ata_host *host, struct 
scsi_host_template *sht)
 {
int i, rc;
 
+   /*
+* The max queue supported by hardware must not be greater than
+* ATA_MAX_QUEUE.
+*/
+   if (sht->can_queue > ATA_MAX_QUEUE) {
+   dev_err(host->dev, "BUG: the hardware max queue is too 
large\n");
+   WARN_ON(1);
+   return -EINVAL;
+   }
+
/* host must have been started */
if (!(host->flags & ATA_HOST_STARTED)) {
dev_err(host->dev, "BUG: trying to register unstarted host\n");
-- 
2.0.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3.12 81/94] libata: support the ata host which implements a queue depth less than 32

2014-07-30 Thread Jiri Slaby
From: Kevin Hao haoke...@gmail.com

3.12-stable review patch.  If anyone has any objections, please let me know.

===

commit 1871ee134b73fb4cadab75752a7152ed2813c751 upstream.

The sata on fsl mpc8315e is broken after the commit 8a4aeec8d2d6
(libata/ahci: accommodate tag ordered controllers). The reason is
that the ata controller on this SoC only implement a queue depth of
16. When issuing the commands in tag order, all the commands in tag
16 ~ 31 are mapped to tag 0 unconditionally and then causes the sata
malfunction. It makes no senses to use a 32 queue in software while
the hardware has less queue depth. So consider the queue depth
implemented by the hardware when requesting a command tag.

Fixes: 8a4aeec8d2d6 (libata/ahci: accommodate tag ordered controllers)
Signed-off-by: Kevin Hao haoke...@gmail.com
Acked-by: Dan Williams dan.j.willi...@intel.com
Signed-off-by: Tejun Heo t...@kernel.org
Signed-off-by: Jiri Slaby jsl...@suse.cz
---
 drivers/ata/libata-core.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index d2eb9df3da3d..97b5e01a6814 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4787,6 +4787,10 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
  * ata_qc_new - Request an available ATA command, for queueing
  * @ap: target port
  *
+ * Some ATA host controllers may implement a queue depth which is less
+ * than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond
+ * the hardware limitation.
+ *
  * LOCKING:
  * None.
  */
@@ -4794,14 +4798,16 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
 static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
 {
struct ata_queued_cmd *qc = NULL;
-   unsigned int i, tag;
+   unsigned int i, tag, max_queue;
+
+   max_queue = ap-scsi_host-can_queue;
 
/* no command while frozen */
if (unlikely(ap-pflags  ATA_PFLAG_FROZEN))
return NULL;
 
-   for (i = 0; i  ATA_MAX_QUEUE; i++) {
-   tag = (i + ap-last_tag + 1) % ATA_MAX_QUEUE;
+   for (i = 0, tag = ap-last_tag + 1; i  max_queue; i++, tag++) {
+   tag = tag  max_queue ? tag : 0;
 
/* the last tag is reserved for internal command. */
if (tag == ATA_TAG_INTERNAL)
@@ -6184,6 +6190,16 @@ int ata_host_register(struct ata_host *host, struct 
scsi_host_template *sht)
 {
int i, rc;
 
+   /*
+* The max queue supported by hardware must not be greater than
+* ATA_MAX_QUEUE.
+*/
+   if (sht-can_queue  ATA_MAX_QUEUE) {
+   dev_err(host-dev, BUG: the hardware max queue is too 
large\n);
+   WARN_ON(1);
+   return -EINVAL;
+   }
+
/* host must have been started */
if (!(host-flags  ATA_HOST_STARTED)) {
dev_err(host-dev, BUG: trying to register unstarted host\n);
-- 
2.0.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3.12 81/94] libata: support the ata host which implements a queue depth less than 32

2014-07-30 Thread Thomas Backlund

Jiri Slaby skrev den 30.7.2014 15:15:

From: Kevin Hao haoke...@gmail.com

3.12-stable review patch.  If anyone has any objections, please let me know.

===

commit 1871ee134b73fb4cadab75752a7152ed2813c751 upstream.

The sata on fsl mpc8315e is broken after the commit 8a4aeec8d2d6
(libata/ahci: accommodate tag ordered controllers). The reason is
that the ata controller on this SoC only implement a queue depth of
16. When issuing the commands in tag order, all the commands in tag
16 ~ 31 are mapped to tag 0 unconditionally and then causes the sata
malfunction. It makes no senses to use a 32 queue in software while
the hardware has less queue depth. So consider the queue depth
implemented by the hardware when requesting a command tag.

Fixes: 8a4aeec8d2d6 (libata/ahci: accommodate tag ordered controllers)
Signed-off-by: Kevin Hao haoke...@gmail.com
Acked-by: Dan Williams dan.j.willi...@intel.com
Signed-off-by: Tejun Heo t...@kernel.org
Signed-off-by: Jiri Slaby jsl...@suse.cz


As you have added this to 3.12 branch, you also need to add this to 
avoid SAS breakage:


commit 1a112d10f03e83fb3a2fdc4c9165865dec8a3ca6
Author: Tejun Heo t...@kernel.org
Date:   Wed Jul 23 09:05:27 2014 -0400

libata: introduce ata_host-n_tags to avoid oops on SAS controllers

1871ee134b73 (libata: support the ata host which implements a queue
depth less than 32) directly used ata_port-scsi_host-can_queue from
ata_qc_new() to determine the number of tags supported by the host;
unfortunately, SAS controllers doing SATA don't initialize -scsi_host
leading to the following oops.

--

Thomas

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/