Skip to contentSkip to conversation

libata: support the ata host which implements a queue depth less than 32

PATCH Superseded Kevin Hao 4 participants 10 messages Jul 11, 2014 – Jul 12, 2014 libata

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH v3 1/1 libata: support the ata host which implements a queue depth less than 32

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")

---
v3: Use ap->scsi_host->can_queue for the queue depth implemented by hardware.
Patch 2 in v2 is also dropped due to this change.

v2: Remove the changes for the ata tag helper functions

Hi Tejun,

I didn't get explicit objection for the codes at http://marc.info/?l=linux-ide&m=140478830920334&w=2
So I assume that you are OK wit it. The code in this patch is the same as that,
just add the commit log.

 drivers/ata/libata-core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +6 -3
index 8f3043165048..4792fea79acf 100644
@@ -4728,14 +4728,17 @@ 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;
+	WARN_ON_ONCE(max_queue > ATA_MAX_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)
Signature · 1 line
1.9.3
#1 lore raw

Hello.

Quoted 39 lines · Kevin Hao

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")

---
v3: Use ap->scsi_host->can_queue for the queue depth implemented by hardware.
Patch 2 in v2 is also dropped due to this change.

v2: Remove the changes for the ata tag helper functions

Hi Tejun,

I didn't get explicit objection for the codes at http://marc.info/?l=linux-ide&m=140478830920334&w=2
So I assume that you are OK wit it. The code in this patch is the same as that,
just add the commit log.

  drivers/ata/libata-core.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +3 -1
index 8f3043165048..4792fea79acf 100644
@@ -4728,14 +4728,17 @@ 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;

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4741

Quoted 10 lines
drivers/ata/libata-core.c +3 -2
+	WARN_ON_ONCE(max_queue > ATA_MAX_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;

Assigning 'tag' back to 'tag' is quite stupid, don't you think? Why not:

		if (tag >= max_queue)
			tag = 0;

MBR, Sergei

#2 lore raw
Quoted 9 lines · Sergei Shtylyov

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4741

Quoted 4 lines
drivers/ata/libata-core.c +2 -2
-	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;

Assigning 'tag' back to 'tag' is quite stupid, don't you think? Why not:

		if (tag >= max_queue)
			tag = 0;

I don't really mind it and the explicit if block isn't more readable in any way.

Thanks.

Signature · 1 line
tejun
#5 lore raw
In reply to Kevin Hao

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4734

Quoted 8 lines · Kevin Hao

static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) {

drivers/ata/libata-core.c +4 -1
 	struct ata_queued_cmd *qc = NULL;
-	unsigned int i, tag;
+	unsigned int i, tag, max_queue;
+
+	max_queue = ap->scsi_host->can_queue;
+	WARN_ON_ONCE(max_queue > ATA_MAX_QUEUE);

Let's move the WARN_ON_ONCE() to ata_host_register(). Also, let's please update the function comment explaining why we're allocating tags the way we do.

Other than that, it looks good to me.

Thanks.

Signature · 1 line
tejun
#7 lore raw
In reply to Kevin Hao

Hi,

Quoted 32 lines · Kevin Hao

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")

---
v3: Use ap->scsi_host->can_queue for the queue depth implemented by hardware.
Patch 2 in v2 is also dropped due to this change.

v2: Remove the changes for the ata tag helper functions

Hi Tejun,

I didn't get explicit objection for the codes at http://marc.info/?l=linux-ide&m=140478830920334&w=2
So I assume that you are OK wit it. The code in this patch is the same as that,
just add the commit log.

 drivers/ata/libata-core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +0 -0
index 8f3043165048..4792fea79acf 100644

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4734

Quoted 8 lines
drivers/ata/libata-core.c +4 -1
@@ -4728,14 +4728,17 @@ 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;
+	WARN_ON_ONCE(max_queue > ATA_MAX_QUEUE);

Why not handle this properly by just doing what ata_dev_config_ncq() does and using

	min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);

for obtaining max_queue?

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4744

Quoted 11 lines
drivers/ata/libata-core.c +2 -2
 	/* 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)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

#8 lore raw
Quoted 48 lines · Bartlomiej Zolnierkiewicz

Hi,

Quoted 32 lines · Kevin Hao

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")

---
v3: Use ap->scsi_host->can_queue for the queue depth implemented by hardware.
Patch 2 in v2 is also dropped due to this change.

v2: Remove the changes for the ata tag helper functions

Hi Tejun,

I didn't get explicit objection for the codes at http://marc.info/?l=linux-ide&m=140478830920334&w=2
So I assume that you are OK wit it. The code in this patch is the same as that,
just add the commit log.

 drivers/ata/libata-core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +0 -0
index 8f3043165048..4792fea79acf 100644

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4734

Quoted 8 lines
drivers/ata/libata-core.c +4 -1
@@ -4728,14 +4728,17 @@ 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;
+	WARN_ON_ONCE(max_queue > ATA_MAX_QUEUE);

Why not handle this properly by just doing what ata_dev_config_ncq() does and using

Quoted 1 line
	min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);

actually this should be

	min(ap->scsi_host->can_queue, ATA_MAX_QUEUE);

in this function

Quoted 6 lines

for obtaining max_queue?

Quoted 4 lines
drivers/ata/libata-core.c +0 -0
 	/* no command while frozen */
 	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
 		return NULL;
 
Quoted 7 lines

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4744

Quoted 7 lines
drivers/ata/libata-core.c +2 -2
-	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)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

author
#3 lore raw
In reply to Sergei Shtylyov
Quoted 9 lines · Sergei Shtylyov

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4741

Quoted 4 lines
drivers/ata/libata-core.c +2 -2
-	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;

Assigning 'tag' back to 'tag' is quite stupid, don't you think? Why not:

		if (tag >= max_queue)
			tag = 0;

Since I am an idiot, it is very possible for me to write stupid code. But I don't believe this is one. I don't think the above code is more readable.

Thanks,
Kevin

author
#6 lore raw
In reply to Tejun Heo
Quoted 13 lines · Tejun Heo

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4734

Quoted 8 lines · Kevin Hao

static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) {

drivers/ata/libata-core.c +4 -1
 	struct ata_queued_cmd *qc = NULL;
-	unsigned int i, tag;
+	unsigned int i, tag, max_queue;
+
+	max_queue = ap->scsi_host->can_queue;
+	WARN_ON_ONCE(max_queue > ATA_MAX_QUEUE);

Let's move the WARN_ON_ONCE() to ata_host_register(). Also, let's please update the function comment explaining why we're allocating tags the way we do.

OK, will do.

Thanks,
Kevin

#4 lore raw
In reply to Kevin Hao
Quoted 7 lines · Kevin Hao
Quoted 6 lines

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4741

Quoted 4 lines
drivers/ata/libata-core.c +2 -2
-	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;

Assigning 'tag' back to 'tag' is quite stupid, don't you think? Why not:

Quoted 5 lines
Quoted 2 lines
		if (tag >= max_queue)
			tag = 0;

Since I am an idiot, it is very possible for me to write stupid code. But I don't believe this is one. I don't think the above code is more readable.

Perhaps I'm an idiot (I even seldom doubt it) but to me it looks like
clear abuse of the ?: operator. But that's probably just me...

Quoted 2 lines

Thanks,
Kevin

MBR, Sergei

author
#9 lore raw
In reply to Bartlomiej Zolnierkiewicz
Quoted 7 lines · Bartlomiej Zolnierkiewicz
Quoted 6 lines · Bartlomiej Zolnierkiewicz

drivers/ata/libata-core.c void swap_buf_le16(u16 *buf, unsigned int buf_words) · line 4734

Quoted 2 lines
drivers/ata/libata-core.c +2 -0
+	max_queue = ap->scsi_host->can_queue;
+	WARN_ON_ONCE(max_queue > ATA_MAX_QUEUE);

Why not handle this properly by just doing what ata_dev_config_ncq() does and using

Quoted 9 lines
Quoted 1 line
	min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);

actually this should be

	min(ap->scsi_host->can_queue, ATA_MAX_QUEUE);

in this function

Quoted 1 line

for obtaining max_queue?

Actually the ap->scsi_host->can_queue is the max queue supported by the hardware. It should be a bug if it is greater than ATA_MAX_QUEUE. So we don't need to use min() to get the max queue here. As pointed out by Tejun, it makes no sense to do the sanity check for each qc requesting, so I will move the WARN_ON_ONCE() to ata_host_register().

I have a pending patch to free the command tag reserved by the internal command. In that patch the above code in ata_dev_config_ncq() will change to:

  hdepth = ap->scsi_host->can_queue;

Thanks,
Kevin