Skip to contentSkip to conversation

hisi_sas internal abort support

PATCH Superseded John Garry 2 participants 11 messages Aug 10, 2016 – Aug 22, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Garry

author
#0 lore raw

cover hisi_sas internal abort support

This patchset introduces support for the internal abort feature for the HiSilicon SAS controller.

The internal abort feature allows commands which are active in the controller to be aborted before being sent to the slave device.

Only support will be added for v2 HW since v1 HW has issues in supporting internal abort feature.

John Garry (8):
hisi_sas: add internal abort core code
hisi_sas: for internal abort in hisi_sas_dev_gone()
hisi_sas: add internal abort to hisi_sas_abort_task()
hisi_sas: add prep_abort_v2_hw()
hisi_sas: add v2 hw slot complete internal abort support
hisi_sas: fail tmf task prep when port detached
hisi_sas: add TMF success check
hisi_sas: update version to 1.6

 drivers/scsi/hisi_sas/hisi_sas.h       |   5 +-
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 179 +++++++++++++++++++++++++++++++--
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c |  64 ++++++++++++
 3 files changed, 241 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/8 hisi_sas: add internal abort core code

Add core code for internal abort functionality.

The internal abort features allows the host controller to abort commands which are still active in the controller but have not yet been sent to the slave device.

Typically a command only spends a relatively short time in the controller when compared to the amount of the time after it is sent to the slave device.
Two modes of internal abort are supported:
- device
- individual command

For device, when the internal abort is issued all commands in the host for that device are aborted. For a single command, only that command is aborted if it is still in the host.

In HW the internal abort command is executed similar to any other sort of command, like SSP.

---
 drivers/scsi/hisi_sas/hisi_sas.h      |   3 +
 drivers/scsi/hisi_sas/hisi_sas_main.c | 154 ++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)
drivers/scsi/hisi_sas/hisi_sas.h +3 -0
index 4731d32..4ae864d 100644
@@ -146,6 +146,9 @@ struct hisi_sas_hw {
 			struct hisi_sas_slot *slot);
 	int (*prep_stp)(struct hisi_hba *hisi_hba,
 			struct hisi_sas_slot *slot);
+	int (*prep_abort)(struct hisi_hba *hisi_hba,
+			  struct hisi_sas_slot *slot,
+			  int device_id, int abort_flag, int tag_to_abort);
 	int (*slot_complete)(struct hisi_hba *hisi_hba,
 			     struct hisi_sas_slot *slot, int abort);
 	void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
drivers/scsi/hisi_sas/hisi_sas_main.c +154 -0

172 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#6 lore raw

PATCH 4/8 hisi_sas: add prep_abort_v2_hw()

In reply to John Garry

Add function to prepare the an internal abort
for v2 hw.

---
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +33 -0
index f965604..fec1675 100644
@@ -174,6 +174,10 @@
 /* HW dma structures */
 /* Delivery queue header */
 /* dw0 */
+#define CMD_HDR_ABORT_FLAG_OFF		0
+#define CMD_HDR_ABORT_FLAG_MSK		(0x3 << CMD_HDR_ABORT_FLAG_OFF)
+#define CMD_HDR_ABORT_DEVICE_TYPE_OFF	2
+#define CMD_HDR_ABORT_DEVICE_TYPE_MSK	(0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF)
 #define CMD_HDR_RESP_REPORT_OFF		5
 #define CMD_HDR_RESP_REPORT_MSK		(0x1 << CMD_HDR_RESP_REPORT_OFF)
 #define CMD_HDR_TLR_CTRL_OFF		6
@@ -214,6 +218,8 @@
 #define CMD_HDR_DIF_SGL_LEN_MSK		(0xffff << CMD_HDR_DIF_SGL_LEN_OFF)
 #define CMD_HDR_DATA_SGL_LEN_OFF	16
 #define CMD_HDR_DATA_SGL_LEN_MSK	(0xffff << CMD_HDR_DATA_SGL_LEN_OFF)
+#define CMD_HDR_ABORT_IPTT_OFF		16
+#define CMD_HDR_ABORT_IPTT_MSK		(0xffff << CMD_HDR_ABORT_IPTT_OFF)
 
 /* Completion header */
 /* dw0 */
@@ -1775,6 +1781,32 @@ static int prep_ata_v2_hw(struct hisi_hba *hisi_hba,
 	return 0;
 }
 
+static int prep_abort_v2_hw(struct hisi_hba *hisi_hba,
+		struct hisi_sas_slot *slot,
+		int device_id, int abort_flag, int tag_to_abort)
+{
+	struct sas_task *task = slot->task;
+	struct domain_device *dev = task->dev;
+	struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
+	struct hisi_sas_port *port = slot->port;
+
+	/* dw0 */
+	hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/
+			       (port->id << CMD_HDR_PORT_OFF) |
+			       ((dev_is_sata(dev) ? 1:0) <<
+				CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
+			       (abort_flag << CMD_HDR_ABORT_FLAG_OFF));
+
+	/* dw1 */
+	hdr->dw1 = cpu_to_le32(device_id << CMD_HDR_DEV_ID_OFF);
+
+	/* dw7 */
+	hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF);
+	hdr->transfer_tags = cpu_to_le32(slot->idx);
+
+	return 0;
+}
+
 static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
 {
 	int i, res = 0;
@@ -2239,6 +2271,7 @@ static const struct hisi_sas_hw hisi_sas_v2_hw = {
 	.prep_smp = prep_smp_v2_hw,
 	.prep_ssp = prep_ssp_v2_hw,
 	.prep_stp = prep_ata_v2_hw,
+	.prep_abort = prep_abort_v2_hw,
 	.get_free_slot = get_free_slot_v2_hw,
 	.start_delivery = start_delivery_v2_hw,
 	.slot_complete = slot_complete_v2_hw,
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH 5/8 hisi_sas: add v2 hw slot complete internal abort support

In reply to John Garry

Add code in slot_complete_v2_hw() to deal with the slots which have completed due to internal abort.

The status codes have the following meaning:
- STAT_IO_ABORTED: the IO has been aborted due to
internal abort, whether by device or individual
abort command
- STAT_IO_COMPLETE: internal abort command has
completed successfully for device or individual
abort command
- STAT_IO_NO_DEVICE: internal abort command has
completed for device but cannot find any IO
- STAT_IO_NOT_VALID: internal abort command has
completed for single command but could not
find the command

---
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +31 -0
index fec1675..bf9b693 100644
@@ -227,6 +227,13 @@
 #define CMPLT_HDR_RSPNS_XFRD_MSK	(0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
 #define CMPLT_HDR_ERX_OFF		12
 #define CMPLT_HDR_ERX_MSK		(0x1 << CMPLT_HDR_ERX_OFF)
+#define CMPLT_HDR_ABORT_STAT_OFF	13
+#define CMPLT_HDR_ABORT_STAT_MSK	(0x7 << CMPLT_HDR_ABORT_STAT_OFF)
+/* abort_stat */
+#define STAT_IO_NOT_VALID		0x1
+#define STAT_IO_NO_DEVICE		0x2
+#define STAT_IO_COMPLETE		0x3
+#define STAT_IO_ABORTED			0x4
 /* dw1 */
 #define CMPLT_HDR_IPTT_OFF		0
 #define CMPLT_HDR_IPTT_MSK		(0xffff << CMPLT_HDR_IPTT_OFF)
@@ -1569,6 +1576,30 @@ slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot,
 		goto out;
 	}
 
+	/* Use SAS+TMF status codes */
+	switch ((complete_hdr->dw0 & CMPLT_HDR_ABORT_STAT_MSK)
+			>> CMPLT_HDR_ABORT_STAT_OFF) {
+	case STAT_IO_ABORTED:
+		/* this io has been aborted by abort command */
+		ts->stat = SAS_ABORTED_TASK;
+		goto out;
+	case STAT_IO_COMPLETE:
+		/* internal abort command complete */
+		ts->stat = TMF_RESP_FUNC_COMPLETE;
+		goto out;
+	case STAT_IO_NO_DEVICE:
+		ts->stat = TMF_RESP_FUNC_COMPLETE;
+		goto out;
+	case STAT_IO_NOT_VALID:
+		/* abort single io, controller don't find
+		 * the io need to abort
+		 */
+		ts->stat = TMF_RESP_FUNC_FAILED;
+		goto out;
+	default:
+		break;
+	}
+
 	if ((complete_hdr->dw0 & CMPLT_HDR_ERX_MSK) &&
 		(!(complete_hdr->dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))) {
 
Signature · 1 line
1.9.1
author
#8 lore raw

PATCH 6/8 hisi_sas: fail tmf task prep when port detached

In reply to John Garry

When the port is detached we cannot execute a TMF, as there can be no device attached to the port.

---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +1 -1
index 6c82e07..af92b137 100644
@@ -204,7 +204,7 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba,
 		return rc;
 	}
 	port = device->port->lldd_port;
-	if (port && !port->port_attached && !tmf) {
+	if (port && !port->port_attached) {
 		if (sas_protocol_ata(task->task_proto)) {
 			struct task_status_struct *ts = &task->task_status;
 
Signature · 1 line
1.9.1
author
#9 lore raw

PATCH 7/8 hisi_sas: add TMF success check

In reply to John Garry

When a tmf is issued, various response codes can be returned from the target. For a query tmf the response may be TMF_RESP_FUNC_COMPLETE or TMF_RESP_FUNC_SUCC.
Add a condition for TMF_RESP_FUNC_SUCC to hisi_sas_exec_internal_tmf_task().
This affects query tmf, as the result is success the returned value was for failure.

---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_main.c +6 -0
index af92b137..3ba8dc7 100644
@@ -743,6 +743,12 @@ static int hisi_sas_exec_internal_tmf_task(struct domain_device *device,
 		}
 
 		if (task->task_status.resp == SAS_TASK_COMPLETE &&
+			task->task_status.stat == TMF_RESP_FUNC_SUCC) {
+			res = TMF_RESP_FUNC_SUCC;
+			break;
+		}
+
+		if (task->task_status.resp == SAS_TASK_COMPLETE &&
 		      task->task_status.stat == SAS_DATA_UNDERRUN) {
 			/* no error, but return the number of bytes of
 			 * underrun
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH 3/8 hisi_sas: add internal abort to hisi_sas_abort_task()

In reply to John Garry

Execute an internal abort for executing an internal task abort. This is for case of command still being present in host when abort is executed.

For a SATA internal abort, we set abort for all tasks associated with the device.

---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +10 -5
index 9540953..6c82e07 100644
@@ -840,18 +840,23 @@ static int hisi_sas_abort_task(struct sas_task *task)
 			}
 		}
 
+		hisi_sas_internal_task_abort(hisi_hba, device, 0, tag);
 	} else if (task->task_proto & SAS_PROTOCOL_SATA ||
 		task->task_proto & SAS_PROTOCOL_STP) {
 		if (task->dev->dev_type == SAS_SATA_DEV) {
-			struct hisi_slot_info *slot = task->lldd_task;
+			struct hisi_sas_slot *slot = task->lldd_task;
+			u32 tag = slot->idx;
 
-			dev_notice(dev, "abort task: hba=%p task=%p slot=%p\n",
-				   hisi_hba, task, slot);
-			task->task_state_flags |= SAS_TASK_STATE_ABORTED;
+			hisi_sas_internal_task_abort(hisi_hba, device,
+						     1, tag);
 			rc = TMF_RESP_FUNC_COMPLETE;
-			goto out;
 		}
+	} else if (task->task_proto & SAS_PROTOCOL_SMP) {
+		/* SMP */
+		struct hisi_sas_slot *slot = task->lldd_task;
+		u32 tag = slot->idx;
 
+		hisi_sas_internal_task_abort(hisi_hba, device, 0, tag);
 	}
 
 out:
Signature · 1 line
1.9.1
author
#10 lore raw

PATCH 8/8 hisi_sas: update version to 1.6

In reply to John Garry
---
 drivers/scsi/hisi_sas/hisi_sas.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hisi_sas/hisi_sas.h +1 -1
index 4ae864d..fc51e87 100644
@@ -23,7 +23,7 @@
 #include <scsi/sas_ata.h>
 #include <scsi/libsas.h>
 
-#define DRV_VERSION "v1.5"
+#define DRV_VERSION "v1.6"
 
 #define HISI_SAS_MAX_PHYS	9
 #define HISI_SAS_MAX_QUEUES	32
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH 2/8 hisi_sas: for internal abort in hisi_sas_dev_gone()

In reply to John Garry

Execute an internal abort for that device when it is removed, so that commands for that device are not processed.

---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_main.c +2 -0
index d30ece2..9540953 100644
@@ -621,6 +621,8 @@ static void hisi_sas_dev_gone(struct domain_device *device)
 	dev_info(dev, "found dev[%lld:%x] is gone\n",
 		 sas_dev->device_id, sas_dev->dev_type);
 
+	hisi_sas_internal_task_abort(hisi_hba, device, 1, 0);
+
 	hisi_hba->hw->free_device(hisi_hba, sas_dev);
 	device->lldd_dev = NULL;
 	memset(sas_dev, 0, sizeof(*sas_dev));
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/8] hisi_sas: add internal abort core code

In reply to John Garry
Quoted 34 lines · John Garry

Add core code for internal abort functionality.

The internal abort features allows the host controller to abort commands which are still active in the controller but have not yet been sent to the slave device.

Typically a command only spends a relatively short time in the controller when compared to the amount of the time after it is sent to the slave device.
Two modes of internal abort are supported:
- device
- individual command

For device, when the internal abort is issued all commands in the host for that device are aborted. For a single command, only that command is aborted if it is still in the host.

In HW the internal abort command is executed similar to any other sort of command, like SSP.

---
  drivers/scsi/hisi_sas/hisi_sas.h      |   3 +
  drivers/scsi/hisi_sas/hisi_sas_main.c | 154 ++++++++++++++++++++++++++++++++++
  2 files changed, 157 insertions(+)
drivers/scsi/hisi_sas/hisi_sas.h +0 -0
index 4731d32..4ae864d 100644

drivers/scsi/hisi_sas/hisi_sas.h struct hisi_sas_hw { · line 151

Quoted 6 lines
drivers/scsi/hisi_sas/hisi_sas.h +3 -0
@@ -146,6 +146,9 @@ struct hisi_sas_hw {
  			struct hisi_sas_slot *slot);
  	int (*prep_stp)(struct hisi_hba *hisi_hba,
  			struct hisi_sas_slot *slot);
+	int (*prep_abort)(struct hisi_hba *hisi_hba,
+			  struct hisi_sas_slot *slot,
+			  int device_id, int abort_flag, int tag_to_abort);

How about add comments to abort_flag and tag_to_abort.
As a result, not sure why differently calling in hisi_sas_abort_task hisi_sas_internal_task_abort(hisi_hba, device, 1, tag); hisi_sas_internal_task_abort(hisi_hba, device, 0, tag);

Thanks

author
#3 lore raw

Re: [PATCH 1/8] hisi_sas: add internal abort core code

Quoted 51 lines · zhangfei
Quoted 36 lines · John Garry

Add core code for internal abort functionality.

The internal abort features allows the host controller to abort commands which are still active in the controller but have not yet been sent to the slave device.

Typically a command only spends a relatively short time in the controller when compared to the amount of the time after it is sent to the slave device.
Two modes of internal abort are supported:
- device
- individual command

For device, when the internal abort is issued all commands in the host for that device are aborted. For a single command, only that command is aborted if it is still in the host.

In HW the internal abort command is executed similar to any other sort of command, like SSP.

---
  drivers/scsi/hisi_sas/hisi_sas.h      |   3 +
  drivers/scsi/hisi_sas/hisi_sas_main.c | 154
++++++++++++++++++++++++++++++++++
  2 files changed, 157 insertions(+)
drivers/scsi/hisi_sas/hisi_sas.h +0 -0
index 4731d32..4ae864d 100644

drivers/scsi/hisi_sas/hisi_sas.h struct hisi_sas_hw { · line 151

Quoted 6 lines
drivers/scsi/hisi_sas/hisi_sas.h +3 -0
@@ -146,6 +146,9 @@ struct hisi_sas_hw {
              struct hisi_sas_slot *slot);
      int (*prep_stp)(struct hisi_hba *hisi_hba,
              struct hisi_sas_slot *slot);
+    int (*prep_abort)(struct hisi_hba *hisi_hba,
+              struct hisi_sas_slot *slot,
+              int device_id, int abort_flag, int tag_to_abort);

How about add comments to abort_flag and tag_to_abort.
As a result, not sure why differently calling in hisi_sas_abort_task hisi_sas_internal_task_abort(hisi_hba, device, 1, tag); hisi_sas_internal_task_abort(hisi_hba, device, 0, tag);

Quoted 5 lines

Thanks

.

OK, I can do.

I will add a MACRO for the abort flag, whether device abort or single IO abort modes.

I will also mention for device abort mode that the tag is unused.

Thanks,
John