cxlflash: Base support for IBM CXL Flash Adapter
PATCH v4 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 | 2263 +++++++++++++++++++++++++++++++++++++++ drivers/scsi/cxlflash/main.h | 104 ++ drivers/scsi/cxlflash/sislite.h | 465 ++++++++ 8 files changed, 3027 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
@@ -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
@@ -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
@@ -0,0 +1,11 @@ +# +# IBM CXL-attached Flash Accelerator SCSI Driver +# + +config CXLFLASH + tristate "Support for IBM CAPI Flash" + depends on CXL + default m + help + Allows CAPI Accelerated IO to Flash + If unsure, say N.
drivers/scsi/cxlflash/Makefile new file +2 -0
@@ -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 +2263 -0
2,263 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
426 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.
Quoted 1 line · Matthew R. Ochs
SCSI device driver to support filesystem access on the IBM CXL Flash adapter.
Few minor nits below but other than that it looks good to me. The CXL parts are good and the rest of the driver is looking decent. FWIW:
The core cxl changes needed for this are in mpe's powerpc next branch queued up for 4.2. They are in linux next-20150605. To compile this you'll need to pull in mpe's powerpc tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.git next
drivers/scsi/cxlflash/Kconfig line 7
Quoted 13 lines
drivers/scsi/cxlflash/Kconfig new file +7
-0@@ -0,0 +1,11 @@ +# +# IBM CXL-attached Flash Accelerator SCSI Driver +# + +config CXLFLASH + tristate "Support for IBM CAPI Flash" + depends on CXL
This should be depends on SCSI too?
Quoted 1 line
drivers/scsi/cxlflash/Kconfig new file +1
-0+struct afu {
< snip>
drivers/scsi/cxlflash/Kconfig
Quoted 1 line
drivers/scsi/cxlflash/Kconfig new file +1
-0+ u64 interface_version;
This doesn't seem to be used anywhere except for in init_afu where it's only used local to that function.
drivers/scsi/cxlflash/Kconfig
Quoted 11 lines
drivers/scsi/cxlflash/Kconfig new file +11
-0+ struct cxlflash_cfg *parent; /* Pointer back to parent cxlflash_cfg */ + +}; + +static inline u64 lun_to_lunid(u64 lun) +{ + u64 lun_id; + + int_to_scsilun(lun, (struct scsi_lun *)&lun_id); + return swab64(lun_id); +}
This is only used in main.c. Why is it not just in there?
Quoted 10 lines
drivers/scsi/cxlflash/Kconfig new file +10
-0+/** + * cxlflash_probe() - PCI entry point to add host + * @pdev: PCI device associated with the host. + * @dev_id: PCI device id associated with device. + * + * Return: 0 on success / non-zero on failure + */ +static int cxlflash_probe(struct pci_dev *pdev, + const struct pci_device_id *dev_id) +{
<snip>
drivers/scsi/cxlflash/Kconfig
Quoted 4 lines
drivers/scsi/cxlflash/Kconfig new file +4
-0+ phys_dev = cxl_get_phys_dev(pdev); + if (!dev_is_pci(phys_dev)) { + pr_err("%s: not a pci dev\n", __func__); + rc = ENODEV;
-ENODEV;
Looking pretty good. A few more comments.
Thanks,
Brian
Quoted 28 lines · Matthew R. Ochs
drivers/scsi/cxlflash/main.c new file +28
-0+/** +* cxlflash_queuecommand() - sends a mid-layer request +* @host: SCSI host associated with device. +* @scp: SCSI command to send. +* +* Return: +* 0 on success +* SCSI_MLQUEUE_HOST_BUSY when host is busy +*/ +static int cxlflash_queuecommand (struct Scsi_Host *host,struct scsi_cmnd *scp) +{ +struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; +struct afu *afu = cfg->afu; +struct pci_dev *pdev = cfg->dev; +struct afu_cmd *cmd; +u32 port_sel = scp->device->channel +1 ; +int nseg, i, ncount; +struct scatterlist *sg; +ulong lock_flags; +short lflag =0 ; +int rc =0 ; + + pr_debug("%s: (scp=%p) %d/%d/%d/%llu cdb=(%08X-%08X-%08X-%08X)\n", + __func__, scp, host->host_no, scp->device->channel, + scp->device->id, scp->device->lun, + get_unaligned_be32(&((u32 *)scp->cmnd)[0]), + get_unaligned_be32(&((u32 *)scp->cmnd)[1]), + get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
drivers/scsi/cxlflash/main.c line 379
Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10
-0+ get_unaligned_be32(&((u32 *)scp->cmnd)[3])); + +/* If a Task Management Function is active, wait for it to complete +* before continuing with regular commands. +*/ +spin_lock_irqsave (&cfg->tmf_waitq.lock, lock_flags); +if (cfg->tmf_active) +wait_event_interruptible_locked_irq (cfg->tmf_waitq, + !cfg->tmf_active); +spin_unlock_irqrestore (&cfg->tmf_waitq.lock, lock_flags);
This needs to return SCSI_MLQUEUE_HOST_BUSY instead of sleeping. You can't sleep in queuecommand.
Quoted 69 lines
drivers/scsi/cxlflash/main.c new file +69
-0+ + cmd =cxlflash_cmd_checkout (afu); +if (unlikely (!cmd)) { +pr_err ("%s: could not get a free command\n" , __func__); + rc =SCSI_MLQUEUE_HOST_BUSY ; + goto out; + } + + cmd->rcb.ctx_id = afu->ctx_hndl; + cmd->rcb.port_sel = port_sel; + cmd->rcb.lun_id =lun_to_lunid (scp->device->lun); + +if (scp->sc_data_direction ==DMA_TO_DEVICE ) + lflag =SISL_REQ_FLAGS_HOST_WRITE ; +else + lflag =SISL_REQ_FLAGS_HOST_READ ; + + cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID | +SISL_REQ_FLAGS_SUP_UNDERRUN | lflag); + +/* Stash the scp in the reserved field, for reuse during interrupt */ + cmd->rcb.scp = scp; + + nseg =scsi_dma_map (scp); +if (unlikely (nseg <0 )) { +dev_err (&pdev->dev,"%s: Fail DMA map! nseg=%d\n" , + __func__, nseg); + rc =SCSI_MLQUEUE_HOST_BUSY ; + goto out; + } + + ncount =scsi_sg_count (scp); +scsi_for_each_sg (scp, sg, ncount, i) { + cmd->rcb.data_len =sg_dma_len (sg); + cmd->rcb.data_ea =sg_dma_address (sg); + } + +/* Copy the CDB from the scsi_cmnd passed in */ +memcpy (cmd->rcb.cdb, scp->cmnd,sizeof (cmd->rcb.cdb)); + +/* Send the command */ + rc =cxlflash_send_cmd (afu, cmd); +if (unlikely (rc)) { +cxlflash_cmd_checkin (cmd); +scsi_dma_unmap (scp); + } + +out: +return rc; +} + +/** +* cxlflash_eh_device_reset_handler() - reset a single LUN +* @scp: SCSI command to send. +* +* Return: +* SUCCESS as defined in scsi/scsi.h +* FAILED as defined in scsi/scsi.h +*/ +static int cxlflash_eh_device_reset_handler (struct scsi_cmnd *scp) +{ +int rc =SUCCESS ; +struct Scsi_Host *host = scp->device->host; +struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; +struct afu *afu = cfg->afu; +int rcr =0 ; + + pr_debug("%s: (scp=%p) %d/%d/%d/%llu " + "cdb=(%08X-%08X-%08X-%08X)\n", __func__, scp,
drivers/scsi/cxlflash/main.c line 458
Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10
-0+ host->host_no, scp->device->channel, + scp->device->id, scp->device->lun, +get_unaligned_be32 (&((u32 *)scp->cmnd)[0 ]), +get_unaligned_be32 (&((u32 *)scp->cmnd)[1 ]), +get_unaligned_be32 (&((u32 *)scp->cmnd)[2 ]), + get_unaligned_be32(&((u32 *)scp->cmnd)[3])); + + rcr =send_tmf (afu, scp,TMF_LUN_RESET ); +if (unlikely (rcr)) + rc =FAILED ;
Do you need to wait for all commands to the LUN to be returned before returning from here? You could put a simple loop here, polling until there are no ops outstanding to this LUN, if needed...
Quoted 19 lines
drivers/scsi/cxlflash/main.c new file +18
-0+ +pr_debug ("%s: returning rc=%d\n" , __func__, rc); +return rc; +} + + +/** +* 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 ;
drivers/scsi/cxlflash/main.c line 1945
Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10
-0+int rc =0 ; +u64 room; + +/* +* 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. +*/ +if (atomic64_dec_and_test (&afu->room)) {
If you have two threads executing this code concurrently you could have a problem. If afu->room = 1 and thread 1 decrements it and the return value is 0, we go into this leg. If a second thread then comes in right after afu->room goes to zero, afu->room will then get decremented to -1, and you'll send the command, regardless of whether the AFU has room or not. Either the AFU will have room and afu->room will then end up being off by one, or it won't have room and you'll send a command when it does not have room.
I think if you use atomic_dec_if_positive instead, you can get rid of this race condition. You'd then need to check the return value. If its positive, there is room, if it zero, you are out of room and you are the thread that will reset afu->room from the AFU. If it is negative, then you have to either return host busy, or wait for the other thread to reset afu->room and simply try the atomic_dec_if_positive again in the loop here instead of reading from the adapter and trying to set it from two threads.
Quoted 22 lines
drivers/scsi/cxlflash/main.c new file +22
-0+do { + room =readq_be (&afu->host_map->cmd_room); +atomic64_set (&afu->room, room); +if (room) + goto write_ioarrin; +udelay (nretry); + }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; + } + +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
Quoted 2 lines · Michael Neuling
Reviewed-by Michael Neuling <[email protected]>
Thanks again for helping us to review the code.
Quoted 6 lines
The core cxl changes needed for this are in mpe's powerpc next branch queued up for 4.2. They are in linux next-20150605. To compile this you'll need to pull in mpe's powerpc tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux.gitnext
I went ahead and did a test build against this tree, everything worked.
Quoted 5 lines
drivers/scsi/cxlflash/Kconfig line 7
Quoted 3 lines
drivers/scsi/cxlflash/Kconfig new file +3
-0+config CXLFLASH + tristate "Support for IBM CAPI Flash" + depends on CXLThis should be depends on SCSI too?
Yep, and PCI. Will fix in v5.
Quoted 7 lines
Quoted 2 lines
+struct afu {
< snip>
drivers/scsi/cxlflash/common.h line 159
Quoted 1 line
drivers/scsi/cxlflash/common.h new file +1
-0+u64 interface_version;This doesn't seem to be used anywhere except for in
init_afuwhere it's only used local to that function.
True, the intention here is to save it off in case it is needed in a debug scenario. We may even make it retrievable via a sysfs attribute at some point.
Quoted 10 lines
drivers/scsi/cxlflash/common.h line 171
Quoted 8 lines
drivers/scsi/cxlflash/common.h new file +8
-0+ +static inline u64 lun_to_lunid (u64 lun) +{ +u64 lun_id; + +int_to_scsilun (lun, (struct scsi_lun *)&lun_id); +return swab64 (lun_id); +}This is only used in
main.c. Why is it not just in there?
We use it in other places within the driver that have not been submitted. Rather than migrating it around we decided to keep it defined in the common header.
Quoted 12 lines
Quoted 11 lines
drivers/scsi/cxlflash/main.c new file +10
-0+/** +* cxlflash_probe() - PCI entry point to add host +* @pdev: PCI device associated with the host. +* @dev_id: PCI device id associated with device. +* +* Return: 0 on success / non-zero on failure +*/ +static int cxlflash_probe (struct pci_dev *pdev, +const struct pci_device_id *dev_id) +{<snip>
Quoted 6 lines
drivers/scsi/cxlflash/main.c line 2190
Quoted 4 lines
drivers/scsi/cxlflash/main.c new file +4
-0+ phys_dev =cxl_get_phys_dev (pdev); +if (!dev_is_pci (phys_dev)) { +pr_err ("%s: not a pci dev\n" , __func__); + rc =ENODEV ;
-ENODEV;
Good catch! Will fix in v5.
Brian:
Thank you for your review. Comments are inline.
- Manoj
Quoted 6 lines · Brian King
Looking pretty good. A few more comments.
Thanks,
Brian
Quoted 9 lines
drivers/scsi/cxlflash/main.c line 297
Quoted 5 lines
drivers/scsi/cxlflash/main.c new file +5
-0+spin_lock_irqsave (&cfg->tmf_waitq.lock, lock_flags); +if (cfg->tmf_active) +wait_event_interruptible_locked_irq (cfg->tmf_waitq, + !cfg->tmf_active); +spin_unlock_irqrestore (&cfg->tmf_waitq.lock, lock_flags);This needs to return
SCSI_MLQUEUE_HOST_BUSYinstead of sleeping. You can't sleep in queuecommand.
Okay, will revise in v5 to return an error instead of sleeping.
Quoted 10 lines
drivers/scsi/cxlflash/main.c line 1945
Quoted 1 line
drivers/scsi/cxlflash/main.c new file +1
-0+if (atomic64_dec_and_test (&afu->room)) {If you have two threads executing this code concurrently you could have a problem. If
afu->room= 1 and thread 1 decrements it and the return value is 0, we go into this leg. If a second thread then comes in right afterafu->roomgoes to zero,afu->roomwill then get decremented to -1, and you'll send the command, regardless of whether the AFU has room or not. Either the AFU will have room andafu->roomwill then end up being off by one, or it won't have room and you'll send a command when it does not have room.
Quoted 7 lines
I think if you use
atomic_dec_if_positiveinstead, you can get rid of this race condition. You'd then need to check the return value. If its positive, there is room, if it zero, you are out of room and you are the thread that will resetafu->roomfrom the AFU. If it is negative, then you have to either return host busy, or wait for the other thread to resetafu->roomand simply try theatomic_dec_if_positiveagain in the loop here instead of reading from the adapter and trying to set it from two threads.
Good catch. Will switch to atomic_dec_if_positive() in v5 to avoid the race.
Quoted 8 lines · Brian King
drivers/scsi/cxlflash/main.c line 458
Quoted 4 lines
drivers/scsi/cxlflash/main.c new file +4
-0+ + rcr =send_tmf (afu, scp,TMF_LUN_RESET ); +if (unlikely (rcr)) + rc =FAILED ;Do you need to wait for all commands to the LUN to be returned before returning from here? You could put a simple loop here, polling until there are no ops outstanding to this LUN, if needed...
Brian:
Good suggestion. Would it be acceptable to add this capability in a future patch?
- Manoj
Quoted 7 lines · Manoj Kumar
Quoted 5 lines · Brian King
Quoted 4 lines
drivers/scsi/cxlflash/main.c new file +4
-0+ + rcr =send_tmf (afu, scp,TMF_LUN_RESET ); +if (unlikely (rcr)) + rc =FAILED ;
Quoted 7 lines
Quoted 3 lines
Do you need to wait for all commands to the LUN to be returned before returning from here? You could put a simple loop here, polling until there are no ops outstanding to this LUN, if needed...
Brian:
Good suggestion. Would it be acceptable to add this capability in a future patch?
That's fine with me.
Thanks,
Brian
Signature · 3 lines
Brian King Power Linux I/O IBM Linux Technology Center
Hi
I just wanted to add support for this patchset. There are others considering implementing block IO devices that use the CAPI (CXL) interface and having this patch-set upstream will be very useful in the future.
Cheers
Stephen
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Matthew R. Ochs
Sent: Friday, June 5, 2015 3:46 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Manoj N. Kumar
Subject: [PATCH v4] 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 | 2263 +++++++++++++++++++++++++++++++++++++++ drivers/scsi/cxlflash/main.h | 104 ++ drivers/scsi/cxlflash/sislite.h | 465 ++++++++ 8 files changed, 3027 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
@@ -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
@@ -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
@@ -0,0 +1,11 @@ +# +# IBM CXL-attached Flash Accelerator SCSI Driver +# + +config CXLFLASH + tristate "Support for IBM CAPI Flash" + depends on CXL + default m + help + Allows CAPI Accelerated IO to Flash + If unsure, say N.
drivers/scsi/cxlflash/Makefile new file +2 -0
@@ -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 +2263 -0
2,263 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
426 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.