cxlflash: Enhancements, cleanup and fixes
v2 cover cxlflash: Enhancements, cleanup and fixes
This patch series includes an enhancement to support a new command queuing model and also cleans up prints throughout the driver. The last patch in the series fixes a racing issue.
The series is based upon v4.10-rc2, intended for 4.11 and is bisectable.
v2 Changes:
- Fixed SOBs for all the submitted patches
Matthew R. Ochs (3):
cxlflash: Refactor context reset to share reset logic
cxlflash: Support SQ Command Mode
cxlflash: Cleanup prints
Uma Krishnan (1):
cxlflash: Cancel scheduled workers before stopping AFU
drivers/scsi/cxlflash/common.h | 32 ++- drivers/scsi/cxlflash/lunmgt.c | 31 +-- drivers/scsi/cxlflash/main.c | 465 +++++++++++++++++++++---------------- drivers/scsi/cxlflash/sislite.h | 19 +- drivers/scsi/cxlflash/superpipe.c | 183 ++++++++------- drivers/scsi/cxlflash/vlun.c | 169 +++++++------- include/uapi/scsi/cxlflash_ioctl.h | 1 + 7 files changed, 518 insertions(+), 382 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 1/4 cxlflash: Refactor context reset to share reset logic
From: "Matthew R. Ochs" <[email protected]>
As staging for supporting hardware with different context reset registers but a similar reset procedure, refactor the existing context reset routine to move the reset logic to a common routine. This will allow hardware with a different reset register to leverage existing code.
--- drivers/scsi/cxlflash/main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/scsi/cxlflash/main.c +16 -4
@@ -188,10 +188,11 @@ static void cmd_complete(struct afu_cmd *cmd) }/** -* context_reset_ioarrin() - reset command owner context via IOARRIN register +* context_reset() - reset command owner context via specified register * @cmd: AFU command that timed out. +* @reset_reg: MMIO register to perform reset. */ -static void context_reset_ioarrin (struct afu_cmd *cmd) +static void context_reset (struct afu_cmd *cmd,__be64 __iomem *reset_reg) {int nretry =0 ;u64 rrin =0x1 ;
@@ -201,9 +202,9 @@ static void context_reset_ioarrin(struct afu_cmd *cmd)pr_debug ("%s: cmd=%p\n" , __func__, cmd); -writeq_be (rrin, &afu->host_map->ioarrin); +writeq_be (rrin, reset_reg); do { - rrin = readq_be(&afu->host_map->ioarrin); + rrin = readq_be(reset_reg); if (rrin != 0x1) break; /* Double delay each time */
@@ -215,6 +216,17 @@ static void context_reset_ioarrin(struct afu_cmd *cmd) }/** +* context_reset_ioarrin() - reset command owner context via IOARRIN register +* @cmd: AFU command that timed out. +*/ +static void context_reset_ioarrin (struct afu_cmd *cmd) +{ +struct afu *afu = cmd->parent; + +context_reset (cmd, &afu->host_map->ioarrin); +} + +/** * send_cmd_ioarrin() - sends an AFU command via IOARRIN register * @afu: AFU associated with the host. * @cmd: AFU command to send.
Signature · 1 line
2.1.0
PATCH v2 2/4 cxlflash: Support SQ Command Mode
In reply to Uma KrishnanFrom: "Matthew R. Ochs" <[email protected]>
The SISLite specification outlines a new queuing model to improve over the MMIO-based IOARRIN model that exists today. This new model uses a submission queue that exists in host memory and is shared with the device. Each entry in the queue is an IOARCB that describes a transfer request. When requests are submitted, IOARCBs ('current' position tracked in host software) are populated and the submission queue tail pointer is then updated via MMIO to make the device aware of the requests.
--- drivers/scsi/cxlflash/common.h | 30 +++++++++++- drivers/scsi/cxlflash/main.c | 98 ++++++++++++++++++++++++++++++++++++-- drivers/scsi/cxlflash/sislite.h | 19 +++++++- drivers/scsi/cxlflash/superpipe.c | 18 +++++-- include/uapi/scsi/cxlflash_ioctl.h | 1 + 5 files changed, 153 insertions(+), 13 deletions(-)
drivers/scsi/cxlflash/common.h +28 -2
@@ -54,6 +54,9 @@ extern const struct file_operations cxlflash_cxl_fops;/* RRQ for master issued cmds */ #define NUM_RRQ_ENTRY CXLFLASH_MAX_CMDS +/* SQ for master issued cmds */ +#define NUM_SQ_ENTRY CXLFLASH_MAX_CMDS +static inline void check_sizes (void ) {
@@ -155,8 +158,8 @@ static inline struct afu_cmd *sc_to_afucz(struct scsi_cmnd *sc)struct afu {/* Stuff requiring alignment go first. */ - -u64 rrq_entry[NUM_RRQ_ENTRY ];/* 2K RRQ */ +struct sisl_ioarcb sq[NUM_SQ_ENTRY ];/* 16K SQ */ +u64 rrq_entry[NUM_RRQ_ENTRY ];/* 2K RRQ */ /* Beware of alignment till here. Preferably introduce new * fields after this point
@@ -174,6 +177,12 @@ struct afu {struct kref mapcount;ctx_hndl_t ctx_hndl;/* master's context handle */ + +atomic_t hsq_credits; +spinlock_t hsq_slock; +struct sisl_ioarcb *hsq_start; +struct sisl_ioarcb *hsq_end; +struct sisl_ioarcb *hsq_curr;u64 *hrrq_start;u64 *hrrq_end;u64 *hrrq_curr;
@@ -191,6 +200,23 @@ struct afu { }; +static inline bool afu_is_cmd_mode (struct afu *afu,u64 cmd_mode) +{ +u64 afu_cap = afu->interface_version >>SISL_INTVER_CAP_SHIFT ; + +return afu_cap & cmd_mode; +} + +static inline bool afu_is_sq_cmd_mode (struct afu *afu) +{ +return afu_is_cmd_mode (afu,SISL_INTVER_CAP_SQ_CMD_MODE ); +} + +static inline bool afu_is_ioarrin_cmd_mode (struct afu *afu) +{ +return afu_is_cmd_mode (afu,SISL_INTVER_CAP_IOARRIN_CMD_MODE ); +} +static inline u64 lun_to_lunid (u64 lun) {__be64 lun_id;
drivers/scsi/cxlflash/main.c +93 -5
155 lines not on this page · raw message
drivers/scsi/cxlflash/sislite.h +18 -1
@@ -72,7 +72,10 @@ struct sisl_ioarcb {u16 timeout;/* in units specified by req_flags */ u32 rsvd1;u8 cdb[16 ];/* must be in big endian */ -u64 reserved;/* Reserved area */ +union { +u64 reserved;/* Reserved for IOARRIN mode */ +struct sisl_ioasa *ioasa;/* IOASA EA for SQ Mode */ + }; } __packed;struct sisl_rc {
@@ -260,6 +263,11 @@ struct sisl_host_map {__be64 cmd_room;__be64 ctx_ctrl;/* least significant byte or b56:63 is LISN# */ __be64 mbox_w;/* restricted use */ +__be64 sq_start;/* Submission Queue (R/W): write sequence and */ +__be64 sq_end;/* inclusion semantics are the same as RRQ */ +__be64 sq_head;/* Submission Queue Head (R): for debugging */ +__be64 sq_tail;/* Submission Queue TAIL (R/W): next IOARCB */ +__be64 sq_ctx_reset;/* Submission Queue Context Reset (R/W) */ };/* per context provisioning & control MMIO */
@@ -348,6 +356,15 @@ struct sisl_global_regs {__be64 rsvd[0xf8 ];__le64 afu_version;__be64 interface_version; +#define SISL_INTVER_CAP_SHIFT 16 +#define SISL_INTVER_MAJ_SHIFT 8 +#define SISL_INTVER_CAP_MASK 0xFFFFFFFF00000000ULL +#define SISL_INTVER_MAJ_MASK 0x00000000FFFF0000ULL +#define SISL_INTVER_MIN_MASK 0x000000000000FFFFULL +#define SISL_INTVER_CAP_IOARRIN_CMD_MODE 0x800000000000ULL +#define SISL_INTVER_CAP_SQ_CMD_MODE 0x400000000000ULL +#define SISL_INTVER_CAP_RESERVED_CMD_MODE_A 0x200000000000ULL +#define SISL_INTVER_CAP_RESERVED_CMD_MODE_B 0x100000000000ULL };#define CXLFLASH_NUM_FC_PORTS 2
drivers/scsi/cxlflash/superpipe.c +13 -5
@@ -1287,6 +1287,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev,int rc =0 ;u32 perms;int ctxid =-1 ; +u64 flags =0UL ;u64 rctxid =0UL ;struct file *file =NULL ;
@@ -1426,10 +1427,11 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, out_attach:if (fd !=-1 ) - attach->hdr.return_flags =DK_CXLFLASH_APP_CLOSE_ADAP_FD ; -else - attach->hdr.return_flags =0 ; + flags |=DK_CXLFLASH_APP_CLOSE_ADAP_FD ; +if (afu_is_sq_cmd_mode (afu)) + flags |=DK_CXLFLASH_CONTEXT_SQ_CMD_MODE ; + attach->hdr.return_flags = flags; attach->context_id = ctxi->ctxid; attach->block_size = gli->blk_len; attach->mmio_size =sizeof (afu->afu_map->hosts[0 ].harea);
@@ -1617,6 +1619,7 @@ static int cxlflash_afu_recover(struct scsi_device *sdev,struct afu *afu = cfg->afu;struct ctx_info *ctxi =NULL ;struct mutex *mutex = &cfg->ctx_recovery_mutex; +u64 flags;u64 ctxid =DECODE_CTXID (recover->context_id), rctxid = recover->context_id;long reg;
@@ -1672,11 +1675,16 @@ static int cxlflash_afu_recover(struct scsi_device *sdev, } ctxi->err_recovery_active = false; + + flags =DK_CXLFLASH_APP_CLOSE_ADAP_FD | +DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET ; +if (afu_is_sq_cmd_mode (afu)) + flags |=DK_CXLFLASH_CONTEXT_SQ_CMD_MODE ; + + recover->hdr.return_flags = flags; recover->context_id = ctxi->ctxid; recover->adap_fd = new_adap_fd; recover->mmio_size =sizeof (afu->afu_map->hosts[0 ].harea); - recover->hdr.return_flags =DK_CXLFLASH_APP_CLOSE_ADAP_FD | -DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET ; goto out; }
include/uapi/scsi/cxlflash_ioctl.h +1 -0
@@ -40,6 +40,7 @@ struct dk_cxlflash_hdr {*/ #define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL +#define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL/* * General Notes:
Signature · 1 line
2.1.0
PATCH v2 3/4 cxlflash: Cleanup prints
In reply to Uma KrishnanFrom: "Matthew R. Ochs" <[email protected]>
The usage of prints within the cxlflash driver is inconsistent. This hinders debug and makes the driver source and log output appear sloppy.
The following cleanups help unify the prints within cxlflash:
- move all prints to dev-* where possible
- transition all hex prints to lowercase
- standardize variable prints in debug output
- derive pointers in a consistent manner
- change int to bool where appropriate
- remove superfluous data from prints and print statements that do not make sense
--- drivers/scsi/cxlflash/lunmgt.c | 31 ++-- drivers/scsi/cxlflash/main.c | 319 ++++++++++++++++++-------------------- drivers/scsi/cxlflash/superpipe.c | 165 ++++++++++---------- drivers/scsi/cxlflash/vlun.c | 169 ++++++++++---------- 4 files changed, 346 insertions(+), 338 deletions(-)
drivers/scsi/cxlflash/lunmgt.c +18 -13
@@ -32,11 +32,13 @@*/ static struct llun_info *create_local (struct scsi_device *sdev,u8 *wwid) { +struct cxlflash_cfg *cfg =shost_priv (sdev->host); +struct device *dev = &cfg->dev->dev;struct llun_info *lli =NULL ; lli =kzalloc (sizeof (*lli),GFP_KERNEL );if (unlikely (!lli)) { -pr_err ("%s: could not allocate lli\n" , __func__); +dev_err (dev,"%s: could not allocate lli\n" , __func__); goto out; }
@@ -58,11 +60,13 @@ static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)*/ static struct glun_info *create_global (struct scsi_device *sdev,u8 *wwid) { +struct cxlflash_cfg *cfg =shost_priv (sdev->host); +struct device *dev = &cfg->dev->dev;struct glun_info *gli =NULL ; gli =kzalloc (sizeof (*gli),GFP_KERNEL );if (unlikely (!gli)) { -pr_err ("%s: could not allocate gli\n" , __func__); +dev_err (dev,"%s: could not allocate gli\n" , __func__); goto out; }
@@ -129,10 +133,10 @@ static struct glun_info *lookup_global(u8 *wwid)*/ static struct llun_info *find_and_create_lun (struct scsi_device *sdev,u8 *wwid) { +struct cxlflash_cfg *cfg =shost_priv (sdev->host); +struct device *dev = &cfg->dev->dev;struct llun_info *lli =NULL ;struct glun_info *gli =NULL ; -struct Scsi_Host *shost = sdev->host; -struct cxlflash_cfg *cfg =shost_priv (shost);if (unlikely (!wwid)) goto out;
@@ -165,7 +169,7 @@ static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid)list_add (&gli->list, &global.gluns); out: -pr_debug ("%s: returning %p\n" , __func__, lli); +dev_dbg (dev,"%s: returning lli=%p, gli=%p\n" , __func__, lli, gli);return lli; }
@@ -225,17 +229,18 @@ void cxlflash_term_global_luns(void)int cxlflash_manage_lun (struct scsi_device *sdev,struct dk_cxlflash_manage_lun *manage) { -int rc =0 ; +struct cxlflash_cfg *cfg =shost_priv (sdev->host); +struct device *dev = &cfg->dev->dev;struct llun_info *lli =NULL ; +int rc =0 ;u64 flags = manage->hdr.flags;u32 chan = sdev->channel;mutex_lock (&global.mutex); lli =find_and_create_lun (sdev, manage->wwid); -pr_debug ("%s: ENTER: WWID = %016llX%016llX, flags = %016llX li = %p\n" , - __func__,get_unaligned_be64 (&manage->wwid[0 ]), -get_unaligned_be64 (&manage->wwid[8 ]), - manage->hdr.flags, lli); +dev_dbg (dev,"%s: WWID=%016llx%016llx, flags=%016llx lli=%p\n" , + __func__,get_unaligned_be64 (&manage->wwid[0 ]), +get_unaligned_be64 (&manage->wwid[8 ]), manage->hdr.flags, lli);if (unlikely (!lli)) { rc = -ENOMEM ; goto out;
@@ -265,11 +270,11 @@ int cxlflash_manage_lun(struct scsi_device *sdev, } } -pr_debug ("%s: port_sel = %08X chan = %u lun_id = %016llX\n" , __func__, - lli->port_sel, chan, lli->lun_id[chan]); +dev_dbg (dev,"%s: port_sel=%08x chan=%u lun_id=%016llx\n" , + __func__, lli->port_sel, chan, lli->lun_id[chan]); out:mutex_unlock (&global.mutex); -pr_debug ("%s: returning rc=%d\n" , __func__, rc); +dev_dbg (dev,"%s: returning rc=%d\n" , __func__, rc);return rc; }
drivers/scsi/cxlflash/main.c +152 -167
920 lines not on this page · raw message
drivers/scsi/cxlflash/superpipe.c +86 -79
581 lines not on this page · raw message
drivers/scsi/cxlflash/vlun.c +90 -79
495 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v2 4/4 cxlflash: Cancel scheduled workers before stopping AFU
In reply to Uma KrishnanWhen processing an AFU asynchronous interrupt, if the action results in an operation that requires off level processing (a link reset for example), the worker thread is scheduled. In the meantime a reset event (i.e.: EEH) could unmap the AFU to recover. This results in an Oops when the worker thread tries to access the AFU mapping.
[c000000f17e03b90] d000000007cd5978 cxlflash_worker_thread+0x268/0x550 [c000000f17e03c40] c00000000011883c process_one_work+0x1dc/0x680 [c000000f17e03ce0] c000000000118e80 worker_thread+0x1a0/0x520 [c000000f17e03d80] c000000000126174 kthread+0xf4/0x100 [c000000f17e03e30] c00000000000a47c ret_from_kernel_thread+0x5c/0xe0
In an effort to avoid this, a mapcount was introduced in
commit b45cdbaf9f7f ("cxlflash: Resolve oops in wait_port_offline") but due to the race condition described above, this solution is incomplete.
In order to fully resolve this problem and to simplify things, this commit removes the mapcount solution. Instead, the scheduled worker thread is cancelled after interrupts have been disabled and prior to the mapping being freed.
--- drivers/scsi/cxlflash/common.h | 2 -- drivers/scsi/cxlflash/main.c | 34 ++++++---------------------------- 2 files changed, 6 insertions(+), 30 deletions(-)
drivers/scsi/cxlflash/common.h +0 -2
@@ -174,8 +174,6 @@ struct afu {struct sisl_host_map __iomem *host_map;/* MC host map */ struct sisl_ctrl_map __iomem *ctrl_map;/* MC control map */ -struct kref mapcount; -ctx_hndl_t ctx_hndl;/* master's context handle */ atomic_t hsq_credits;
drivers/scsi/cxlflash/main.c +6 -28
@@ -419,16 +419,6 @@ static int send_tmf(struct afu *afu, struct scsi_cmnd *scp, u64 tmfcmd)return rc; } -static void afu_unmap (struct kref *ref) -{ - struct afu *afu = container_of(ref, struct afu, mapcount); - -if (likely (afu->afu_map)) { -cxl_psa_unmap ((void __iomem *)afu->afu_map); - afu->afu_map =NULL ; - } -} -/** * cxlflash_driver_info() - information handler for this host driver * @host: SCSI host associated with device.
@@ -459,7 +449,6 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)ulong lock_flags;int nseg =0 ;int rc =0 ; -int kref_got =0 ; dev_dbg_ratelimited(dev, "%s: (scp=%p) %d/%d/%d/%llu " "cdb=(%08x-%08x-%08x-%08x)\n",
@@ -497,9 +486,6 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)break ; } -kref_get (&cfg->afu->mapcount); - kref_got =1 ; -if (likely (sg)) { nseg =scsi_dma_map (scp);if (unlikely (nseg <0 )) {
@@ -530,8 +516,6 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)if (unlikely (rc))scsi_dma_unmap (scp); out: -if (kref_got) -kref_put (&afu->mapcount, afu_unmap);return rc; }
@@ -569,13 +553,15 @@ static void free_mem(struct cxlflash_cfg *cfg)* * Safe to call with AFU in a partially allocated/initialized state. * -* Waits for any active internal AFU commands to timeout and then unmaps -* the MMIO space. +* Cancels scheduled worker threads, waits for any active internal AFU +* commands to timeout and then unmaps the MMIO space. */ static void stop_afu (struct cxlflash_cfg *cfg) {struct afu *afu = cfg->afu; +cancel_work_sync (&cfg->work_q); +if (likely (afu)) {while (atomic_read (&afu->cmds_active))ssleep (1 );
@@ -583,7 +569,6 @@ static void stop_afu(struct cxlflash_cfg *cfg)cxl_psa_unmap ((void __iomem *)afu->afu_map); afu->afu_map =NULL ; } -kref_put (&afu->mapcount, afu_unmap); } }
@@ -767,7 +752,6 @@ static void cxlflash_remove(struct pci_dev *pdev)scsi_remove_host (cfg->host);/* fall through */ case INIT_STATE_AFU : -cancel_work_sync (&cfg->work_q);term_afu (cfg);case INIT_STATE_PCI :pci_disable_device (pdev);
@@ -1277,7 +1261,6 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) __func__, port); cfg->lr_state =LINK_RESET_REQUIRED ; cfg->lr_port = port; -kref_get (&cfg->afu->mapcount);schedule_work (&cfg->work_q); }
@@ -1298,7 +1281,6 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data)if (info->action &SCAN_HOST ) {atomic_inc (&cfg->scan_host_needed); -kref_get (&cfg->afu->mapcount);schedule_work (&cfg->work_q); } }
@@ -1704,7 +1686,6 @@ static int init_afu(struct cxlflash_cfg *cfg) rc = -ENOMEM ; goto err1; } -kref_init (&afu->mapcount);/* No byte reverse on reading afu_version or string will be backwards */ reg =readq (&afu->afu_map->global.regs.afu_version);
@@ -1716,7 +1697,7 @@ static int init_afu(struct cxlflash_cfg *cfg)"interface version %016llx\n" , afu->version, afu->interface_version); rc = -EINVAL ; - goto err2; + goto err1; }if (afu_is_sq_cmd_mode (afu)) {
@@ -1733,7 +1714,7 @@ static int init_afu(struct cxlflash_cfg *cfg) rc =start_afu (cfg);if (rc) {dev_err (dev,"%s: start_afu failed, rc=%d\n" , __func__, rc); - goto err2; + goto err1; }afu_err_intr_init (cfg->afu);
@@ -1746,8 +1727,6 @@ static int init_afu(struct cxlflash_cfg *cfg)dev_dbg (dev,"%s: returning rc=%d\n" , __func__, rc);return rc; -err2: -kref_put (&afu->mapcount, afu_unmap); err1:term_intr (cfg,UNMAP_THREE );term_mc (cfg);
@@ -2341,7 +2320,6 @@ static void cxlflash_worker_thread(struct work_struct *work)if (atomic_dec_if_positive (&cfg->scan_host_needed) >=0 )scsi_scan_host (cfg->host); -kref_put (&afu->mapcount, afu_unmap); }/**
Signature · 1 line
2.1.0
Martin K. Petersen
AppliedQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Uma" == Uma Krishnan <[email protected]> writes:
Uma> This patch series includes an enhancement to support a new command Uma> queuing model and also cleans up prints throughout the driver. The Uma> last patch in the series fixes a racing issue.
Applied to 4.11/scsi-queue.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering