Skip to contentSkip to conversation

cxlflash: Base support for IBM CXL Flash Adapter

PATCH Superseded Matthew R. Ochs 3 participants 8 messages Jun 8, 2015 – Jun 9, 2015 SCSI

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 cxlflash: Base support for IBM CXL Flash Adapter

SCSI device driver to support filesystem access on the IBM CXL Flash adapter.

---
 drivers/scsi/Kconfig            |    1 +
 drivers/scsi/Makefile           |    1 +
 drivers/scsi/cxlflash/Kconfig   |   11 +
 drivers/scsi/cxlflash/Makefile  |    2 +
 drivers/scsi/cxlflash/common.h  |  180 ++++
 drivers/scsi/cxlflash/main.c    | 2279 +++++++++++++++++++++++++++++++++++++++
 drivers/scsi/cxlflash/main.h    |  104 ++
 drivers/scsi/cxlflash/sislite.h |  465 ++++++++
 8 files changed, 3043 insertions(+)
 create mode 100644 drivers/scsi/cxlflash/Kconfig
 create mode 100644 drivers/scsi/cxlflash/Makefile
 create mode 100644 drivers/scsi/cxlflash/common.h
 create mode 100644 drivers/scsi/cxlflash/main.c
 create mode 100644 drivers/scsi/cxlflash/main.h
 create mode 100755 drivers/scsi/cxlflash/sislite.h
drivers/scsi/Kconfig +1 -0
index b021bcb..ebb12a7 100644
@@ -345,6 +345,7 @@ source "drivers/scsi/cxgbi/Kconfig"
 source "drivers/scsi/bnx2i/Kconfig"
 source "drivers/scsi/bnx2fc/Kconfig"
 source "drivers/scsi/be2iscsi/Kconfig"
+source "drivers/scsi/cxlflash/Kconfig"
 
 config SGIWD93_SCSI
 	tristate "SGI WD93C93 SCSI Driver"
drivers/scsi/Makefile +1 -0
index dee160a..619f8fb 100644
@@ -101,6 +101,7 @@ obj-$(CONFIG_SCSI_7000FASST)	+= wd7000.o
 obj-$(CONFIG_SCSI_EATA)		+= eata.o
 obj-$(CONFIG_SCSI_DC395x)	+= dc395x.o
 obj-$(CONFIG_SCSI_AM53C974)	+= esp_scsi.o	am53c974.o
+obj-$(CONFIG_CXLFLASH)		+= cxlflash/
 obj-$(CONFIG_MEGARAID_LEGACY)	+= megaraid.o
 obj-$(CONFIG_MEGARAID_NEWGEN)	+= megaraid/
 obj-$(CONFIG_MEGARAID_SAS)	+= megaraid/
drivers/scsi/cxlflash/Kconfig new file +11 -0
new file mode 100644
index 0000000..c707508
@@ -0,0 +1,11 @@
+#
+# IBM CXL-attached Flash Accelerator SCSI Driver
+#
+
+config CXLFLASH
+	tristate "Support for IBM CAPI Flash"
+	depends on PCI && SCSI && CXL
+	default m
+	help
+	  Allows CAPI Accelerated IO to Flash
+	  If unsure, say N.
drivers/scsi/cxlflash/Makefile new file +2 -0
new file mode 100644
index 0000000..dc95e20
@@ -0,0 +1,2 @@
+obj-$(CONFIG_CXLFLASH) += cxlflash.o
+cxlflash-y += main.o
drivers/scsi/cxlflash/common.h new file +180 -0

180 lines not on this page · raw message

drivers/scsi/cxlflash/main.c new file +2279 -0

2,279 lines not on this page · raw message

drivers/scsi/cxlflash/main.h new file +104 -0

104 lines not on this page · raw message

drivers/scsi/cxlflash/sislite.h new file +465 -0

410 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.1.0

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 22 lines · Matthew R. Ochs
drivers/scsi/cxlflash/main.c new file +22 -0
+
+/**
+ * cxlflash_send_cmd() - sends an AFU command
+ * @afu:	AFU associated with the host.
+ * @cmd:	AFU command to send.
+ *
+ * Return:
+ *	0 on success
+ *	-1 on failure
+ */
+int cxlflash_send_cmd(struct afu *afu, struct afu_cmd *cmd)
+{
+	int nretry = 0;
+	int rc = 0;
+	u64 room;
+	long newval;
+
+	/*
+	 * This routine is used by critical users such an AFU sync and to
+	 * send a task management function (TMF). Thus we want to retry a
+	 * bit before returning an error. To avoid the performance penalty
+	 * of MMIO, we spread the update of 'room' over multiple commands.

drivers/scsi/cxlflash/main.c line 1956

Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10 -0
+	 */
+retry:
+	newval = atomic64_dec_if_positive(&afu->room);
+	if (!newval) {
+		do {
+			room = readq_be(&afu->host_map->cmd_room);
+			atomic64_set(&afu->room, room);
+			if (room)
+				goto write_ioarrin;
+		} while (nretry++ < MC_ROOM_RETRY_CNT);

It looks like you removed the udelay here. Was that intentional?

drivers/scsi/cxlflash/main.c line 1960

Quoted 4 lines
drivers/scsi/cxlflash/main.c new file +4 -0
+
+		pr_err("%s: no cmd_room to send 0x%X\n",
+		       __func__, cmd->rcb.cdb[0]);
+		rc = SCSI_MLQUEUE_HOST_BUSY;

If you actually get here, how do you get out of this state? Since now afu->room is zero and anyone that comes through here will go to the else if leg.

drivers/scsi/cxlflash/main.c line 1968

Quoted 8 lines
drivers/scsi/cxlflash/main.c new file +8 -0
+		goto out;
+	} else if (unlikely(newval < 0)) {
+		/* This should be rare. i.e. Only if two threads race and
+		 * decrement before the MMIO read is done. In this case
+		 * just benefit from the other thread having updated
+		 * afu->room.
+		 */
+		if (nretry++ < MC_ROOM_RETRY_CNT)

I'm guessing you'd want the udelay here as well.

Quoted 15 lines
drivers/scsi/cxlflash/main.c new file +15 -0
+			goto retry;
+		else {
+			rc = SCSI_MLQUEUE_HOST_BUSY;
+			goto out;
+		}
+	}
+
+write_ioarrin:
+	writeq_be((u64)&cmd->rcb, &afu->host_map->ioarrin);
+out:
+	pr_debug("%s: cmd=%p len=%d ea=%p rc=%d\n", __func__, cmd,
+		 cmd->rcb.data_len, (void *)cmd->rcb.data_ea, rc);
+	return rc;
+}
+
Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#2 lore raw

Brian:

Thanks for the quick review. Comments below.

- Manoj

Quoted 11 lines · Brian King

drivers/scsi/cxlflash/main.c line 1956

Quoted 9 lines
drivers/scsi/cxlflash/main.c new file +9 -0
+retry:
+	newval = atomic64_dec_if_positive(&afu->room);
+	if (!newval) {
+		do {
+			room = readq_be(&afu->host_map->cmd_room);
+			atomic64_set(&afu->room, room);
+			if (room)
+				goto write_ioarrin;
+		} while (nretry++ < MC_ROOM_RETRY_CNT);

It looks like you removed the udelay here. Was that intentional?

Pulled out going to sleep in the queuecommand path.

Quoted 7 lines

drivers/scsi/cxlflash/main.c line 1960

Quoted 4 lines
drivers/scsi/cxlflash/main.c new file +4 -0
+
+		pr_err("%s: no cmd_room to send 0x%X\n",
+		       __func__, cmd->rcb.cdb[0]);
+		rc = SCSI_MLQUEUE_HOST_BUSY;

If you actually get here, how do you get out of this state? Since now afu->room is zero and anyone that comes through here will go to the else if leg.

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Quoted 10 lines

drivers/scsi/cxlflash/main.c line 1968

Quoted 8 lines
drivers/scsi/cxlflash/main.c new file +8 -0
+		goto out;
+	} else if (unlikely(newval < 0)) {
+		/* This should be rare. i.e. Only if two threads race and
+		 * decrement before the MMIO read is done. In this case
+		 * just benefit from the other thread having updated
+		 * afu->room.
+		 */
+		if (nretry++ < MC_ROOM_RETRY_CNT)

I'm guessing you'd want the udelay here as well.

Same reason as the queuecommand issue above.

#3 lore raw
Quoted 11 lines · Manoj Kumar
Quoted 10 lines · Brian King
Quoted 9 lines
drivers/scsi/cxlflash/main.c new file +9 -0
+retry:
+    newval = atomic64_dec_if_positive(&afu->room);
+    if (!newval) {
+        do {
+            room = readq_be(&afu->host_map->cmd_room);
+            atomic64_set(&afu->room, room);
+            if (room)
+                goto write_ioarrin;
+        } while (nretry++ < MC_ROOM_RETRY_CNT);
Quoted 3 lines
Quoted 1 line

It looks like you removed the udelay here. Was that intentional?

Pulled out going to sleep in the queuecommand path.

udelay doesn't sleep, its a busy wait, so you can still use it in queuecommand, just don't spend too much time, and its probably better to udelay then to just re-read in a tight loop.

Quoted 10 lines
Quoted 8 lines

drivers/scsi/cxlflash/main.c line 1960

Quoted 5 lines
drivers/scsi/cxlflash/main.c new file +4 -0
+
+        pr_err("%s: no cmd_room to send 0x%X\n",
+               __func__, cmd->rcb.cdb[0]);
+        rc = SCSI_MLQUEUE_HOST_BUSY;

If you actually get here, how do you get out of this state? Since now afu->room is zero and anyone that comes through here will go to the else if leg.

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Let's take the simpler scenario of just one thread.

Let's start with afu->room = 1
We call atomic64_dec_if_positive, which results in afu->room going to zero and 0 being returned, so we go into the if leg.

If afu->room is zero every time we read it from the adapter and we exhaust our retries, we return SCSI_MLQUEUE_HOST_BUSY. However, the next time we enter cxlflash_send_cmd, since afu->cmd is now 0, it will no longer get decremented, but the return value will be -1, so we'll go down the else if leg. We'll never get into the if leg again to re-read afu->room from the AFU. The simplest fix might just be to set afu->room = 1 if you ever leave the if leg without having room.

+ newval = atomic64_dec_if_positive(&afu->room);
+ if (!newval) {
+ do {
+ room = readq_be(&afu->host_map->cmd_room);
+ atomic64_set(&afu->room, room);
+ if (room)
+ goto write_ioarrin;
+ } while (nretry++ < MC_ROOM_RETRY_CNT);
+
+ pr_err("%s: no cmd_room to send 0x%X\n",
+ __func__, cmd->rcb.cdb[0]);
+ rc = SCSI_MLQUEUE_HOST_BUSY;
+ goto out;
+ } else if (unlikely(newval < 0)) {
+ /* This should be rare. i.e. Only if two threads race and
+ * decrement before the MMIO read is done. In this case
+ * just benefit from the other thread having updated
+ * afu->room.
+ */
+ if (nretry++ < MC_ROOM_RETRY_CNT)
+ goto retry;
+ else {
+ rc = SCSI_MLQUEUE_HOST_BUSY;
+ goto out;
+ }
+ }

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/scsi/cxlflash/main.c new file +8 -0
+        goto out;
+    } else if (unlikely(newval < 0)) {
+        /* This should be rare. i.e. Only if two threads race and
+         * decrement before the MMIO read is done. In this case
+         * just benefit from the other thread having updated
+         * afu->room.
+         */
+        if (nretry++ < MC_ROOM_RETRY_CNT)
Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#4 lore raw
Quoted 5 lines · Brian King
Quoted 1 line

Pulled out going to sleep in the queuecommand path.

udelay doesn't sleep, its a busy wait, so you can still use it in queuecommand, just don't spend too much time, and its probably better to udelay then to just re-read in a tight loop.

Thanks for the clarification. Will update in the next patch (v6).

Quoted 9 lines
Quoted 2 lines

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Let's take the simpler scenario of just one thread.

Let's start with afu->room = 1
We call atomic64_dec_if_positive, which results in afu->room going to zero and 0 being returned, so we go into the if leg.

Quoted 6 lines

If afu->room is zero every time we read it from the adapter and we exhaust our retries, we return SCSI_MLQUEUE_HOST_BUSY. However, the next time we enter cxlflash_send_cmd, since afu->cmd is now 0, it will no longer get decremented, but the return value will be -1, so we'll go down the else if leg. We'll never get into the if leg again to re-read afu->room from the AFU. The simplest fix might just be to set afu->room = 1 if you ever leave the if leg without having room.

Good suggestion. Will atomic64_set(&afu->room, 1), if we exhaust retries in both legs.

#5 lore raw

Brian/Manoj,

See my alternate proposal below.

-matt

Quoted 11 lines · Manoj Kumar
Quoted 10 lines · Brian King
Quoted 3 lines

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Let's take the simpler scenario of just one thread.

Let's start with afu->room = 1
We call atomic64_dec_if_positive, which results in afu->room going to zero and 0 being returned, so we go into the if leg.

Quoted 8 lines
Quoted 6 lines

If afu->room is zero every time we read it from the adapter and we exhaust our retries, we return SCSI_MLQUEUE_HOST_BUSY. However, the next time we enter cxlflash_send_cmd, since afu->cmd is now 0, it will no longer get decremented, but the return value will be -1, so we'll go down the else if leg. We'll never get into the if leg again to re-read afu->room from the AFU. The simplest fix might just be to set afu->room = 1 if you ever leave the if leg without having room.

Good suggestion. Will atomic64_set(&afu->room, 1), if we exhaust retries in both legs.

While I agree this will work it seems a bit of a kludge.

What if we instead take advantage of our existing work queue and create a new work item that simply MMIO reads and atomically sets afu->room? With this, instead of slamming in a 1 to satisfy our logic such that a subsequent command will MMIO read, we would schedule the new work item and let afu->room be updated with a real value from the card.

The only downside I see with this approach is that it has the potential to relax the window of time that we're 'down' (no room) and sending back busy...although that might not be such a bad thing if we were to get into this condition.

Thoughts?

#6 lore raw
Quoted 29 lines · Matthew R. Ochs

Brian/Manoj,

See my alternate proposal below.

-matt

Quoted 11 lines · Manoj Kumar
Quoted 10 lines · Brian King
Quoted 3 lines

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Let's take the simpler scenario of just one thread.

Let's start with afu->room = 1
We call atomic64_dec_if_positive, which results in afu->room going to zero and 0 being returned, so we go into the if leg.

Quoted 8 lines
Quoted 6 lines

If afu->room is zero every time we read it from the adapter and we exhaust our retries, we return SCSI_MLQUEUE_HOST_BUSY. However, the next time we enter cxlflash_send_cmd, since afu->cmd is now 0, it will no longer get decremented, but the return value will be -1, so we'll go down the else if leg. We'll never get into the if leg again to re-read afu->room from the AFU. The simplest fix might just be to set afu->room = 1 if you ever leave the if leg without having room.

Good suggestion. Will atomic64_set(&afu->room, 1), if we exhaust retries in both legs.

While I agree this will work it seems a bit of a kludge.

Quoted 8 lines

What if we instead take advantage of our existing work queue and create a new work item that simply MMIO reads and atomically sets afu->room? With this, instead of slamming in a 1 to satisfy our logic such that a subsequent command will MMIO read, we would schedule the new work item and let afu->room be updated with a real value from the card.

The only downside I see with this approach is that it has the potential to relax the window of time that we're 'down' (no room) and sending back busy...although that might not be such a bad thing if we were to get into this condition.

Seems reasonable. Would be simpler. I assume you then just schedule the work from cxlflash_send_cmd and just return SCSI_MLQUEUE_HOST_BUSY from cxlflash_send_cmd if you don't have room?

-Brian

Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#7 lore raw
Quoted 30 lines · Brian King
Quoted 29 lines · Matthew R. Ochs
Quoted 11 lines · Manoj Kumar
Quoted 10 lines · Brian King
Quoted 3 lines

This was the optimization to avoid the MMIO for both threads. The other thread that raced should do the atomic set of afu->room to a positive value.

Let's take the simpler scenario of just one thread.

Let's start with afu->room = 1
We call atomic64_dec_if_positive, which results in afu->room going to zero and 0 being returned, so we go into the if leg.

Quoted 8 lines
Quoted 6 lines

If afu->room is zero every time we read it from the adapter and we exhaust our retries, we return SCSI_MLQUEUE_HOST_BUSY. However, the next time we enter cxlflash_send_cmd, since afu->cmd is now 0, it will no longer get decremented, but the return value will be -1, so we'll go down the else if leg. We'll never get into the if leg again to re-read afu->room from the AFU. The simplest fix might just be to set afu->room = 1 if you ever leave the if leg without having room.

Good suggestion. Will atomic64_set(&afu->room, 1), if we exhaust retries in both legs.

While I agree this will work it seems a bit of a kludge.

What if we instead take advantage of our existing work queue and create a new work item that simply MMIO reads and atomically sets afu->room? With this, instead of slamming in a 1 to satisfy our logic such that a subsequent command will MMIO read, we would schedule the new work item and let afu->room be updated with a real value from the card.

Quoted 6 lines
Quoted 3 lines

The only downside I see with this approach is that it has the potential to relax the window of time that we're 'down' (no room) and sending back busy...although that might not be such a bad thing if we were to get into this condition.

Seems reasonable. Would be simpler. I assume you then just schedule the work from cxlflash_send_cmd and just return SCSI_MLQUEUE_HOST_BUSY from cxlflash_send_cmd if you don't have room?

Correct. We'll keep things similar to how they are now (try our best to get room on the queuecommand thread) and then if we're unable to get room (udelay/retries exhausted) we'll schedule the work and return the busy rc.