Optimize the hot path in the UFS driver
Subsystems (2)
Bart Van Assche
reviewerv5 cover Optimize the hot path in the UFS driver
Hi Martin,
This patch series optimizes the hot path of the UFS driver by making struct scsi_cmnd and struct ufshcd_lrb adjacent. Making these two data structures adjacent is realized as follows:
@@ -9040,6 +9046,7 @@ static const struct scsi_host_template ufshcd_driver_template = {
.name = UFSHCD,
.proc_name = UFSHCD,
.map_queues = ufshcd_map_queues,
+ .cmd_size = sizeof(struct ufshcd_lrb),
.init_cmd_priv = ufshcd_init_cmd_priv,
.queuecommand = ufshcd_queuecommand,
.mq_poll = ufshcd_poll,The following changes had to be made prior to making these two data structures adjacent:
* Add support for driver-internal and reserved commands in the SCSI core.
* Instead of making the reserved command slot (hba->reserved_slot) invisible to the SCSI core, let the SCSI core allocate a reserved command.
* Remove all UFS data structure members that are no longer needed because struct scsi_cmnd and struct ufshcd_lrb are now adjacent
* Call ufshcd_init_lrb() from inside ufshcd_queuecommand() instead of calling this function before I/O starts. This is necessary because ufshcd_memory_alloc() allocates fewer instances than the block layer allocates requests. See also the following code in the block layer core:
if (blk_mq_init_request(set, hctx->fq->flush_rq, hctx_idx,
hctx->numa_node)) Although the UFS driver could be modified such that ufshcd_init_lrb() is called from ufshcd_init_cmd_priv(), realizing this would require moving the memory allocations that happen from inside ufshcd_memory_alloc() into ufshcd_init_cmd_priv(). That would make this patch series even larger. Although ufshcd_init_lrb() is called for each command, the benefits of reduced indirection and better cache efficiency outweigh the small overhead of per-command lrb initialization.
* ufshcd_add_scsi_host() happens now before any device management commands are submitted. This change is necessary because this patch makes device management command allocation happen when the SCSI host is allocated.
* Allocate as many command slots as the host controller supports. Decrease host->cmds_per_lun if necessary once it is clear whether or not the UFS device supports less command slots than the host controller.
Changes compared to v4:
- Dropped the scsi_execute_cmd() changes.
- Restored patch "scsi: core: Add scsi_{get,put}_internal_cmd() helpers".
- Switched back from scsi_execute_cmd() to blk_execute_rq() for submitting device management commands in the UFS driver.
- As suggested by John Garry, modified the scsi_debug patch such that aborting a SCSI command happens by submitting a reserved command.
Changes compared to v3:
- Fixed a spelling error in patch 1 and left out a superfluous if-statement.
- Left out scsi_host_template.alloc_pseudo_sdev and allocate a pseudo SCSI device if either nr_reserved_cmds > 0 or .queue_reserved_commands has been set.
- Left out the 'pseudo_sdev' local variable from scsi_forget_host().
- Removed a backwards jump from scsi_get_pseudo_dev().
- Included a bug fix for synchronous scanning.
- Skip scsi_track_queue_full() and scsi_handle_queue_ramp_up() for pseudo SCSI devices.
- Extended the scsi_execute_rq() functionality.
- Use scsi_execute_rq() for submitting reserved commands instead of blk_execute_rq().
- Dropped the patch that introduces scsi_get_internal_cmd() and scsi_put_internal_cmd().
Changes compared to v2:
- Removed scsi_host_update_can_queue() and also the UFS driver refactoring patches that were introduced to support this call.
- Added .queue_reserved_command(). Added ufshcd_queue_reserved_command().
- Removed a BUG_ON() statement from ufshcd_get_dev_mgmt_cmd().
- Modified and renamed ufshcd_mcq_decide_queue_depth().
Changes compared to v1:
- Left out the kernel patches related to support for const SCSI command arguments.
- Added SCSI core patches for allocating a pseudo SCSI device and reserved command support.
- Added several kernel patches to switch the UFS driver from a hardcoded reserved slot to calling scsi_get_internal_cmd().
- Enable .alloc_pseudo_sdev in the scsi_debug driver.
Bart Van Assche (24):
scsi: core: Move two statements
scsi: core: Make the budget map optional
scsi_debug: Abort SCSI commands via .queue_reserved_command()
ufs: core: Move an assignment in ufshcd_mcq_process_cqe()
ufs: core: Change the type of one ufshcd_add_cmd_upiu_trace() argument
ufs: core: Only call ufshcd_add_command_trace() for SCSI commands
ufs: core: Change the type of one ufshcd_add_command_trace() argument
ufs: core: Change the type of one ufshcd_send_command() argument
ufs: core: Only call ufshcd_should_inform_monitor() for SCSI commands
ufs: core: Change the monitor function argument types
ufs: core: Rework ufshcd_mcq_compl_pending_transfer()
ufs: core: Rework ufshcd_eh_device_reset_handler()
ufs: core: Rework the SCSI host queue depth calculation code
ufs: core: Allocate the SCSI host earlier
ufs: core: Call ufshcd_init_lrb() later
ufs: core: Use hba->reserved_slot
ufs: core: Make the reserved slot a reserved request
ufs: core: Do not clear driver-private command data
ufs: core: Optimize the hot path
ufs: core: Pass a SCSI pointer instead of an LRB pointer
ufs: core: Remove the ufshcd_lrb task_tag member
ufs: core: Make blk_mq_tagset_busy_iter() skip reserved requests
ufs: core: Move code out of ufshcd_wait_for_dev_cmd()
ufs: core: Switch to scsi_get_internal_cmd()
Hannes Reinecke (3):
scsi: core: Support allocating reserved commands
scsi: core: Support allocating a pseudo SCSI device
scsi: core: Add scsi_{get,put}_internal_cmd() helpers
John Garry (1):
scsi: core: Introduce .queue_reserved_command()
drivers/scsi/hosts.c | 15 + drivers/scsi/scsi.c | 12 +- drivers/scsi/scsi_debug.c | 106 +++- drivers/scsi/scsi_error.c | 3 + drivers/scsi/scsi_lib.c | 145 +++++- drivers/scsi/scsi_priv.h | 2 + drivers/scsi/scsi_scan.c | 77 ++- drivers/scsi/scsi_sysfs.c | 5 +- drivers/ufs/core/ufs-mcq.c | 51 +- drivers/ufs/core/ufshcd-crypto.h | 18 +- drivers/ufs/core/ufshcd-priv.h | 20 +- drivers/ufs/core/ufshcd.c | 808 ++++++++++++++++--------------- include/scsi/scsi_device.h | 23 + include/scsi/scsi_host.h | 33 +- include/ufs/ufshcd.h | 12 - 15 files changed, 861 insertions(+), 469 deletions(-)
Bart Van Assche
reviewerPATCH v5 1/28 scsi: core: Support allocating reserved commands
From: Hannes Reinecke <[email protected]>
Quite some drivers are using management commands internally. These commands typically use the same tag pool as regular SCSI commands. Tags for these management commands are set aside before allocating the block-mq tag bitmap for regular SCSI commands. The block layer already supports this via the reserved tag mechanism. Add a new field 'nr_reserved_cmds' to the SCSI host template to instruct the block layer to set aside a tag space for these management commands by using reserved tags. Exclude reserved commands from .can_queue because .can_queue is visible in sysfs.
[ bvanassche: modified patch title and patch description. Left out the
following statements: "if (sht->nr_reserved_cmds)" and also
"if (sdev->host->nr_reserved_cmds) flags |= BLK_MQ_REQ_RESERVED;". Moved nr_reserved_cmds declarations and statements close to the corresponding can_queue declarations and statements. See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
--- drivers/scsi/hosts.c | 1 + drivers/scsi/scsi_lib.c | 3 ++- include/scsi/scsi_host.h | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-)
drivers/scsi/hosts.c +1 -0
@@ -436,6 +436,7 @@ struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *sht, int priv shost->hostt = sht; shost->this_id = sht->this_id; shost->can_queue = sht->can_queue; + shost->nr_reserved_cmds = sht->nr_reserved_cmds; shost->sg_tablesize = sht->sg_tablesize; shost->sg_prot_tablesize = sht->sg_prot_tablesize; shost->cmd_per_lun = sht->cmd_per_lun;
drivers/scsi/scsi_lib.c +2 -1
@@ -2083,7 +2083,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) tag_set->ops = &scsi_mq_ops_no_commit; tag_set->nr_hw_queues = shost->nr_hw_queues ? :1 ; tag_set->nr_maps = shost->nr_maps ? :1 ; - tag_set->queue_depth = shost->can_queue; + tag_set->queue_depth = shost->can_queue + shost->nr_reserved_cmds; + tag_set->reserved_tags = shost->nr_reserved_cmds; tag_set->cmd_size = cmd_size; tag_set->numa_node =dev_to_node (shost->dma_dev);if (shost->hostt->tag_alloc_policy_rr)
include/scsi/scsi_host.h +20 -1
@@ -375,10 +375,19 @@ struct scsi_host_template {/* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number -* of simultaneous commands a single hw queue in HBA will accept. +* of simultaneous commands a single hw queue in HBA will accept +* excluding internal commands. */ int can_queue; +/* +* This determines how many commands the HBA will set aside +* for internal commands. This number will be added to +* @can_queue to calculate the maximum number of simultaneous +* commands sent to the host. +*/ +int nr_reserved_cmds; +/* * In many instances, especially where disconnect / reconnect are * supported, our host also has an ID on the SCSI bus. If this is
@@ -611,7 +620,17 @@ struct Scsi_Host {unsigned short max_cmd_len;int this_id; + +/* +* Number of commands this host can handle at the same time. +* This excludes reserved commands as specified by nr_reserved_cmds. +*/ int can_queue; +/* +* Number of reserved commands to allocate, if any. +*/ +unsigned int nr_reserved_cmds; +short cmd_per_lun;short unsigned int sg_tablesize;short unsigned int sg_prot_tablesize;
Bart Van Assche
reviewerPATCH v5 2/28 scsi: core: Move two statements
In reply to Bart Van AsscheMove two statements that will be needed for pseudo SCSI devices in front of code that won't be needed for pseudo SCSI devices. No functionality has been changed.
--- drivers/scsi/scsi_scan.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/scsi/scsi_scan.c +4 -3
@@ -347,6 +347,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,kref_get (&sdev->host->tagset_refcnt); sdev->request_queue = q; +scsi_sysfs_device_initialize (sdev); + depth = sdev->host->cmd_per_lun ?:1 ;/*
@@ -363,8 +365,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,scsi_change_queue_depth (sdev, depth); -scsi_sysfs_device_initialize (sdev); -if (shost->hostt->sdev_init) { ret = shost->hostt->sdev_init (sdev);if (ret) {
@@ -1068,6 +1068,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,transport_configure_device (&sdev->sdev_gendev); + sdev->sdev_bflags = *bflags; +/* * No need to freeze the queue as it isn't reachable to anyone else yet. */
@@ -1113,7 +1115,6 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result, sdev->max_queue_depth = sdev->queue_depth;WARN_ON_ONCE (sdev->max_queue_depth > sdev->budget_map.depth); - sdev->sdev_bflags = *bflags;/* * Ok, the device is now all set up, we can
Bart Van Assche
reviewerPATCH v5 3/28 scsi: core: Make the budget map optional
In reply to Bart Van AsschePrepare for not allocating a budget map for pseudo SCSI devices by checking whether a budget map has been allocated before using it.
--- drivers/scsi/scsi.c | 5 +++++ drivers/scsi/scsi_error.c | 3 +++ drivers/scsi/scsi_lib.c | 9 +++++++-- drivers/scsi/scsi_scan.c | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-)
drivers/scsi/scsi.c +5 -0
@@ -216,6 +216,9 @@ int scsi_device_max_queue_depth(struct scsi_device *sdev)*/ int scsi_change_queue_depth (struct scsi_device *sdev,int depth) { +if (WARN_ON_ONCE (!sdev->budget_map.map)) +return -EINVAL ; + depth =min_t (int, depth,scsi_device_max_queue_depth (sdev));if (depth >0 ) {
@@ -255,6 +258,8 @@ EXPORT_SYMBOL(scsi_change_queue_depth);*/ int scsi_track_queue_full (struct scsi_device *sdev,int depth) { +if (!sdev->budget_map.map) +return 0 ;/* * Don't let QUEUE_FULLs on the same
drivers/scsi/scsi_error.c +3 -0
@@ -749,6 +749,9 @@ static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)const struct scsi_host_template *sht = sdev->host->hostt;struct scsi_device *tmp_sdev; +if (!sdev->budget_map.map) +return ; +if (!sht->track_queue_depth || sdev->queue_depth >= sdev->max_queue_depth)return ;
drivers/scsi/scsi_lib.c +7 -2
@@ -396,7 +396,8 @@ void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd)if (starget->can_queue >0 )atomic_dec (&starget->target_busy); -sbitmap_put (&sdev->budget_map, cmd->budget_token); +if (sdev->budget_map.map) +sbitmap_put (&sdev->budget_map, cmd->budget_token); cmd->budget_token =-1 ; }
@@ -1360,6 +1361,9 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, {int token; +if (!sdev->budget_map.map) +return INT_MAX ; + token =sbitmap_get (&sdev->budget_map);if (token <0 )return -1 ;
@@ -1749,7 +1753,8 @@ static void scsi_mq_put_budget(struct request_queue *q, int budget_token) {struct scsi_device *sdev = q->queuedata; -sbitmap_put (&sdev->budget_map, budget_token); +if (sdev->budget_map.map) +sbitmap_put (&sdev->budget_map, budget_token); }/*
drivers/scsi/scsi_scan.c +3 -0
@@ -225,6 +225,9 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,int ret;struct sbitmap sb_backup; +if (WARN_ON_ONCE (!sdev->budget_map.map)) +return -EINVAL ; + depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev));/*
Bart Van Assche
reviewerPATCH v5 4/28 scsi: core: Support allocating a pseudo SCSI device
In reply to Bart Van AsscheFrom: Hannes Reinecke <[email protected]>
Allocate a pseudo SCSI device if 'nr_reserved_cmds' has been set. Pseudo SCSI devices have the SCSI ID <max_id>:U64_MAX so they won't clash with any devices the LLD might create. Pseudo SCSI devices are excluded from scanning and will not show up in sysfs. Additionally, pseudo SCSI devices are skipped by shost_for_each_device(). This prevents that the SCSI error handler tries to submit a reset to a non-existent logical unit.
Do not allocate a budget map for pseudo SCSI devices since the cmd_per_lun limit does not apply to pseudo SCSI devices.
Do not perform queue depth ramp up / ramp down for pseudo SCSI devices.
Pseudo SCSI devices will be used to send internal commands to a storage device.
[ bvanassche: edited patch description / renamed host_sdev into
pseudo_sdev / unexported scsi_get_host_dev() / modified error path in scsi_get_pseudo_dev() / skip pseudo devices in __scsi_iterate_devices() and also when calling sdev_init(), sdev_configure() and sdev_destroy(). See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
--- drivers/scsi/hosts.c | 8 +++++ drivers/scsi/scsi.c | 7 ++-- drivers/scsi/scsi_priv.h | 2 ++ drivers/scsi/scsi_scan.c | 67 +++++++++++++++++++++++++++++++++++++- drivers/scsi/scsi_sysfs.c | 5 ++- include/scsi/scsi_device.h | 16 +++++++++ include/scsi/scsi_host.h | 6 ++++ 7 files changed, 107 insertions(+), 4 deletions(-)
drivers/scsi/hosts.c +8 -0
@@ -307,6 +307,14 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,if (error) goto out_del_dev; +if (sht->nr_reserved_cmds) { + shost->pseudo_sdev =scsi_get_pseudo_dev (shost); +if (!shost->pseudo_sdev) { + error = -ENOMEM ; + goto out_del_dev; + } + } +scsi_proc_host_add (shost);scsi_autopm_put_host (shost);return error;
drivers/scsi/scsi.c +5 -2
@@ -831,8 +831,11 @@ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,spin_lock_irqsave (shost->host_lock, flags);while (list->next != &shost->__devices) { next = list_entry(list->next, struct scsi_device, siblings); -/* skip devices that we can't get a reference to */ -if (!scsi_device_get (next)) +/* +* Skip pseudo devices and also devices for which +* scsi_device_get() fails. +*/ +if (!scsi_device_is_pseudo_dev (next) && !scsi_device_get (next))break ; next =NULL ; list = list->next;
drivers/scsi/scsi_priv.h +2 -0
@@ -135,6 +135,8 @@ extern int scsi_complete_async_scans(void);extern int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int ,u64 ,enum scsi_scan_mode );extern void scsi_forget_host (struct Scsi_Host *); +struct scsi_device *scsi_get_pseudo_dev (struct Scsi_Host *); +bool scsi_device_is_pseudo_dev (struct scsi_device *sdev);/* scsi_sysctl.c */ #ifdef CONFIG_SYSCTL
drivers/scsi/scsi_scan.c +66 -1
96 lines not on this page · raw message
drivers/scsi/scsi_sysfs.c +4 -1
@@ -1406,6 +1406,9 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)int error;struct scsi_target *starget = sdev->sdev_target; +if (WARN_ON_ONCE (scsi_device_is_pseudo_dev (sdev))) +return -EINVAL ; + error =scsi_target_add (starget);if (error)return error;
@@ -1513,7 +1516,7 @@ void __scsi_remove_device(struct scsi_device *sdev)kref_put (&sdev->host->tagset_refcnt, scsi_mq_free_tags);cancel_work_sync (&sdev->requeue_work); -if (sdev->host->hostt->sdev_destroy) +if (!scsi_device_is_pseudo_dev (sdev) && sdev->host->hostt->sdev_destroy) sdev->host->hostt->sdev_destroy (sdev);transport_destroy_device (dev);
include/scsi/scsi_device.h +16 -0
@@ -589,6 +589,22 @@ static inline unsigned int sdev_id(struct scsi_device *sdev)#define scmd_id (scmd) sdev_id((scmd)->device)#define scmd_channel (scmd) sdev_channel((scmd)->device) +/** +* scsi_device_is_pseudo_dev() - Whether a device is a pseudo SCSI device. +* @sdev: SCSI device to examine +* +* A pseudo SCSI device can be used to allocate SCSI commands but does not show +* up in sysfs. Additionally, the logical unit information in *@sdev is made up. +* +* This function tests the LUN number instead of comparing @sdev with +* @sdev->host->pseudo_sdev because this function may be called before +* @sdev->host->pseudo_sdev has been initialized. +*/ +static inline bool scsi_device_is_pseudo_dev (struct scsi_device *sdev) +{ +return sdev->lun ==U64_MAX ; +} +/* * checks for positions of the SCSI state machine */
include/scsi/scsi_host.h +6 -0
@@ -721,6 +721,12 @@ struct Scsi_Host {/* ldm bits */ struct device shost_gendev, shost_dev; +/* +* A SCSI device structure used for sending internal commands to the +* HBA. There is no corresponding logical unit inside the SCSI device. +*/ +struct scsi_device *pseudo_sdev; +/* * Points to the transport data (if any) which is allocated * separately
Re: [PATCH v5 04/28] scsi: core: Support allocating a pseudo SCSI device
drivers/scsi/scsi_priv.h extern int scsi_complete_async_scans(void); · line 139
Quoted 13 lines
next = NULL; list = list->next;drivers/scsi/scsi_priv.h +2
-0@@ -135,6 +135,8 @@ extern int scsi_complete_async_scans(void);extern int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int ,u64 ,enum scsi_scan_mode );extern void scsi_forget_host (struct Scsi_Host *); +struct scsi_device *scsi_get_pseudo_dev (struct Scsi_Host *); +bool scsi_device_is_pseudo_dev (struct scsi_device *sdev);
this is defined in scsi_device.h - why also have a prototype here?
generally looks ok apart from that
Bart Van Assche
reviewerRe: [PATCH v5 04/28] scsi: core: Support allocating a pseudo SCSI device
Quoted 3 lines · John Garry
Quoted 1 line
+bool
scsi_device_is_pseudo_dev(struct scsi_device *sdev);this is defined in
scsi_device.h- why also have a prototype here?
When I changed scsi_device_is_pseudo_dev() from an exported function into an inline function I overlooked that the above line should be removed. I will remove the above declaration before I repost this patch series.
Thanks,
Bart.
Bart Van Assche
reviewerRe: [PATCH v5 04/28] scsi: core: Support allocating a pseudo SCSI device
In reply to Bart Van AsscheQuoted 5 lines · Bart Van Assche
drivers/scsi/hosts.c +0
-0
drivers/scsi/hosts.c int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, · line 316
Quoted 10 lines
drivers/scsi/hosts.c +7
-0@@ -307,6 +307,14 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,if (error) goto out_del_dev; +if (sht->nr_reserved_cmds) { + shost->pseudo_sdev =scsi_get_pseudo_dev (shost); +if (!shost->pseudo_sdev) { + error = -ENOMEM ; + goto out_del_dev; + } + }
(replying to my own email)
Unless anyone objects I will change sht->nr_reserved_cmds into shost->nr_reserved_cmds in the above code.
Bart.
Bart Van Assche
reviewerPATCH v5 5/28 scsi: core: Introduce .queue_reserved_command()
In reply to Bart Van AsscheFrom: John Garry <[email protected]>
Reserved commands will be used by SCSI LLDs for submitting internal commands. Since the SCSI host, target and device limits do not apply to the reserved command use cases, bypass the SCSI host limit checks for reserved commands. Introduce the .queue_reserved_command() callback for reserved commands. Additionally, do not activate the SCSI error handler if a reserved command fails such that reserved commands can be submitted from inside the SCSI error handler.
[ bvanassche: modified patch title and patch description. Renamed
.reserved_queuecommand() into .queue_reserved_command(). Changed
the second argument of __blk_mq_end_request() from 0 into error
code in the completion path if cmd->result != 0. Rewrote the
scsi_queue_rq() changes. See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
--- drivers/scsi/hosts.c | 8 +++++- drivers/scsi/scsi_lib.c | 54 ++++++++++++++++++++++++++++------------ include/scsi/scsi_host.h | 6 +++++ 3 files changed, 51 insertions(+), 17 deletions(-)
drivers/scsi/hosts.c +7 -1
@@ -231,6 +231,12 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, goto fail; } +if (shost->nr_reserved_cmds && !sht->queue_reserved_command) { +shost_printk (KERN_ERR , shost, +"nr_reserved_cmds set but no method to queue\n" ); + goto fail; + } +/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ shost->cmd_per_lun =min_t (int, shost->cmd_per_lun, shost->can_queue);
@@ -307,7 +313,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,if (error) goto out_del_dev; -if (sht->nr_reserved_cmds) { +if (sht->nr_reserved_cmds || sht->queue_reserved_command) { shost->pseudo_sdev =scsi_get_pseudo_dev (shost);if (!shost->pseudo_sdev) { error = -ENOMEM ;
drivers/scsi/scsi_lib.c +38 -16
75 lines not on this page · raw message
include/scsi/scsi_host.h +6 -0
@@ -86,6 +86,12 @@ struct scsi_host_template {*/ int (* queuecommand)(struct Scsi_Host *,struct scsi_cmnd *); +/* +* Queue a reserved command (BLK_MQ_REQ_RESERVED). The .queuecommand() +* documentation also applies to the .queue_reserved_command() callback. +*/ +int (*queue_reserved_command)(struct Scsi_Host *,struct scsi_cmnd *); +/* * The commit_rqs function is used to trigger a hardware * doorbell after some requests have been queued with
Re: [PATCH v5 05/28] scsi: core: Introduce .queue_reserved_command()
Quoted 29 lines · Bart Van Assche
From: John Garry <[email protected]>
Reserved commands will be used by SCSI LLDs for submitting internal commands. Since the SCSI host, target and device limits do not apply to the reserved command use cases, bypass the SCSI host limit checks for reserved commands. Introduce the .queue_reserved_command() callback for reserved commands. Additionally, do not activate the SCSI error handler if a reserved command fails such that reserved commands can be submitted from inside the SCSI error handler.
Signed-off-by John Garry <[email protected]>[ bvanassche: modified patch title and patch description. Renamed
.reserved_queuecommand() into .queue_reserved_command(). Changed the second argument of__blk_mq_end_request()from 0 into error code in the completion path ifcmd->result!= 0. Rewrote thescsi_queue_rq()changes. See alsohttps://urldefense.com/v3/__https://lore.kernel.org/linux-scsi/[email protected]/__;!!ACWV5N9M2RV99hQ!Ku4G8LUl3kt-hX9_3TXoSAPJKn9Wz4_3Bnnz_ahYQYT0tAKkJTwnWZv4av5MhFclGpk6b3N7n06tpzYzyj5X0A$ ] Signed-off-by: Bart Van Assche <[email protected]> --- drivers/scsi/hosts.c | 8 +++++- drivers/scsi/scsi_lib.c | 54 ++++++++++++++++++++++++++++------------ include/scsi/scsi_host.h | 6 +++++ 3 files changed, 51 insertions(+), 17 deletions(-)drivers/scsi/hosts.c +0
-0
drivers/scsi/hosts.c int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, · line 234
Quoted 4 lines
drivers/scsi/hosts.c +1
-0@@ -231,6 +231,12 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, goto fail; } +if (shost->nr_reserved_cmds && !sht->queue_reserved_command) {
But having sht->queue_reserved_command and !shost->nr_reserved_cmds does not make sense. However, I suppose that we should not change the sht when we have a scenario with shost->nr_reserved_cmds == 0, so I suppose that it is ok.
Quoted 9 lines
drivers/scsi/hosts.c +5
-0+shost_printk (KERN_ERR , shost, +"nr_reserved_cmds set but no method to queue\n" ); + goto fail; + } +/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ shost->cmd_per_lun =min_t (int, shost->cmd_per_lun, shost->can_queue);
drivers/scsi/hosts.c int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, · line 316
Quoted 5 lines
drivers/scsi/hosts.c +1
-1@@ -307,7 +313,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,if (error) goto out_del_dev; -if (sht->nr_reserved_cmds) { +if (sht->nr_reserved_cmds || sht->queue_reserved_command) {
But this really should not change, as we cannot have sht->nr_reserved_cmds && !sht->queue_reserved_command (from above)
drivers/scsi/hosts.c int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, · line 319
Quoted 3 lines
drivers/scsi/hosts.c +0
-0shost->pseudo_sdev =scsi_get_pseudo_dev (shost);if (!shost->pseudo_sdev) { error = -ENOMEM ;
generally the rest looks ok
Bart Van Assche
reviewerRe: [PATCH v5 05/28] scsi: core: Introduce .queue_reserved_command()
Quoted 10 lines · John Garry
drivers/scsi/hosts.c int scsi_add_host_with_dma(struct Scsi_Host · line 316
Quoted 6 lines · Bart Van Assche
drivers/scsi/hosts.c +1
-1@@ -307,7 +313,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, if (error) goto out_del_dev; - if (sht->nr_reserved_cmds) { + if (sht->nr_reserved_cmds || sht->queue_reserved_command) {But this really should not change, as we cannot have sht-
Quoted 1 line
(quoted diff) +0
-0nr_reserved_cmds && !sht->queue_reserved_command (from above)
I will drop the above change.
Thanks,
Bart.
Bart Van Assche
reviewerPATCH v5 6/28 scsi: core: Add scsi_{get,put}_internal_cmd() helpers
In reply to Bart Van AsscheFrom: Hannes Reinecke <[email protected]>
Add helper functions to allow LLDDs to allocate and free internal commands.
[ bvanassche: changed the 'nowait' argument into a 'flags' argument /
added scsi_get_internal_cmd_hctx(). See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
--- drivers/scsi/scsi_lib.c | 79 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_device.h | 7 ++++ 2 files changed, 86 insertions(+)
drivers/scsi/scsi_lib.c +79 -0
@@ -1247,6 +1247,17 @@ struct request *scsi_alloc_request(struct request_queue *q, blk_opf_t opf, }EXPORT_SYMBOL_GPL (scsi_alloc_request); +static struct request *scsi_alloc_request_hctx (struct request_queue *q, +blk_opf_t opf,blk_mq_req_flags_t flags,unsigned int hctx_idx) +{ +struct request *rq; + + rq =blk_mq_alloc_request_hctx (q, opf, flags, hctx_idx); +if (!IS_ERR (rq)) +scsi_initialize_rq (rq); +return rq; +} +/* * Only called when the request isn't completed by SCSI, and not freed by * SCSI
@@ -2134,6 +2145,74 @@ void scsi_mq_free_tags(struct kref *kref)complete (&shost->tagset_freed); } +/** +* scsi_get_internal_cmd() - Allocate an internal SCSI command. +* @sdev: SCSI device from which to allocate the command +* @data_direction: Data direction for the allocated command +* @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or +* BLK_MQ_REQ_NOWAIT. +* +* Allocates a SCSI command for internal LLDD use. +*/ +struct scsi_cmnd *scsi_get_internal_cmd (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags) +{ +enum req_op op = data_direction ==DMA_TO_DEVICE ?REQ_OP_DRV_OUT : +REQ_OP_DRV_IN ; +struct scsi_cmnd *scmd; +struct request *rq; + + rq =scsi_alloc_request (sdev->request_queue, op, flags); +if (IS_ERR (rq)) +return NULL ; + scmd =blk_mq_rq_to_pdu (rq); + scmd->device = sdev; + +return scmd; +} +EXPORT_SYMBOL_GPL (scsi_get_internal_cmd); + +/** +* scsi_get_internal_cmd_hctx() - Allocate an internal SCSI command from a given +* hardware queue. +* @sdev: SCSI device from which to allocate the command +* @data_direction: Data direction for the allocated command +* @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or +* BLK_MQ_REQ_NOWAIT. +* @hctx_idx: Hardware queue index. +* +* Allocates a SCSI command for internal LLDD use. +*/ +struct scsi_cmnd *scsi_get_internal_cmd_hctx (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags,unsigned int hctx_idx) +{ +enum req_op op = data_direction ==DMA_TO_DEVICE ?REQ_OP_DRV_OUT : +REQ_OP_DRV_IN ; +struct scsi_cmnd *scmd; +struct request *rq; + + rq =scsi_alloc_request_hctx (sdev->request_queue, op, flags, hctx_idx); +if (IS_ERR (rq)) +return NULL ; + scmd =blk_mq_rq_to_pdu (rq); + scmd->device = sdev; + +return scmd; +} +EXPORT_SYMBOL_GPL (scsi_get_internal_cmd_hctx); + +/** +* scsi_put_internal_cmd() - Free an internal SCSI command. +* @scmd: SCSI command to be freed +*/ +void scsi_put_internal_cmd (struct scsi_cmnd *scmd) +{ +blk_mq_free_request (blk_mq_rq_from_pdu (scmd)); +} +EXPORT_SYMBOL_GPL (scsi_put_internal_cmd); +/** * scsi_device_from_queue - return sdev associated with a request_queue * @q: The request queue to return the sdev from
include/scsi/scsi_device.h +7 -0
@@ -558,6 +558,13 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd, const struct scsi_exec_args *args);void scsi_failures_reset_retries (struct scsi_failures *failures); +struct scsi_cmnd *scsi_get_internal_cmd (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags); +struct scsi_cmnd *scsi_get_internal_cmd_hctx (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags,unsigned int hctx_idx); +void scsi_put_internal_cmd (struct scsi_cmnd *scmd);extern void sdev_disable_disk_events (struct scsi_device *sdev);extern void sdev_enable_disk_events (struct scsi_device *sdev);extern int scsi_vpd_lun_id (struct scsi_device *,char *,size_t );
Re: [PATCH v5 06/28] scsi: core: Add scsi_{get,put}_internal_cmd() helpers
Quoted 10 lines · Bart Van Assche
From: Hannes Reinecke<[email protected]>
Add helper functions to allow LLDDs to allocate and free internal commands.
Cc John Garry<[email protected]>Signed-off-by Hannes Reinecke<[email protected]>[ bvanassche: changed the 'nowait' argument into a 'flags' argument /
addedscsi_get_internal_cmd_hctx(). See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]Signed-off-by Bart Van Assche<[email protected]>
Bart Van Assche
reviewerPATCH v5 7/28 scsi_debug: Abort SCSI commands via .queue_reserved_command()
In reply to Bart Van AsscheAdd a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for processing reserved commands gets triggered while running blktests.
--- drivers/scsi/scsi_debug.c | 106 ++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 9 deletions(-)
drivers/scsi/scsi_debug.c +97 -9
@@ -451,6 +451,23 @@ struct sdeb_store_info {#define shost_to_sdebug_host (shost) \ dev_to_sdebug_host(shost->dma_dev) +struct scsi_debug_abort_cmd { +u16 tag; +u16 hwq; +}; + +enum scsi_debug_internal_cmd_type { +SCSI_DEBUG_ABORT_CMD , +}; + +struct scsi_debug_internal_cmd { +enum scsi_debug_internal_cmd_type type; + +union { +struct scsi_debug_abort_cmd abort_cmd; + }; +}; +enum sdeb_defer_type {SDEB_DEFER_NONE =0 ,SDEB_DEFER_HRT =1 ,SDEB_DEFER_WQ =2 ,SDEB_DEFER_POLL =3 };
@@ -466,6 +483,8 @@ struct sdebug_defer {struct sdebug_scsi_cmd {spinlock_t lock;struct sdebug_defer sd_dp; + +struct scsi_debug_internal_cmd internal_cmd; };static atomic_t sdebug_cmnd_count;/* number of incoming commands */
@@ -6729,20 +6748,48 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd)return false; } +static int scsi_debug_setup_abort_cmd (struct scsi_cmnd *cmd, +const struct scsi_debug_internal_cmd *internal_cmd) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmd); + + sdsc->internal_cmd = *internal_cmd; + +return 0 ; +} +/* -* Called from scsi_debug_abort() only, which is for timed-out cmd. +* Abort a pending SCSI command. Only called from scsi_debug_abort(). Although +* it would be possible to call scsi_debug_stop_cmnd() directly, an internal +* command is allocated and submitted to use the reserved command +* infrastructure. */ static bool scsi_debug_abort_cmnd (struct scsi_cmnd *cmnd) { -struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmnd); -unsigned long flags; -bool res; - -spin_lock_irqsave (&sdsc->lock, flags); - res =scsi_debug_stop_cmnd (cmnd); -spin_unlock_irqrestore (&sdsc->lock, flags); +struct request *rq =scsi_cmd_to_rq (cmnd); +u32 unique_tag =blk_mq_unique_tag (rq); +u16 hwq =blk_mq_unique_tag_to_hwq (unique_tag); +u16 tag =blk_mq_unique_tag_to_tag (unique_tag); +struct scsi_device *sdev = cmnd->device; +struct Scsi_Host *shost = sdev->host; +const struct scsi_debug_internal_cmd ic = { + .type =SCSI_DEBUG_ABORT_CMD , + .abort_cmd = { + .tag = tag, + .hwq = hwq, + }, + }; +struct scsi_cmnd *abort_cmd; +struct request *abort_rq; -return res; + abort_cmd =scsi_get_internal_cmd (shost->pseudo_sdev,DMA_TO_DEVICE , +BLK_MQ_REQ_RESERVED ); +if (WARN_ON_ONCE (!abort_cmd)) +return false; +scsi_debug_setup_abort_cmd (abort_cmd, &ic); + abort_rq =scsi_cmd_to_rq (abort_cmd); + abort_rq->timeout =secs_to_jiffies (3 ); +return blk_execute_rq (abort_rq, true) ==BLK_STS_OK ; }/*
@@ -9197,6 +9244,45 @@ static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval,return ret; } +static void scsi_debug_abort_cmd (struct Scsi_Host *shost,struct scsi_cmnd *scp) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (scp); +struct scsi_debug_abort_cmd *abort_cmd = + &sdsc->internal_cmd.abort_cmd; +struct blk_mq_tag_set *tag_set = &shost->tag_set; +unsigned int tag = abort_cmd->tag; +unsigned int hwq = abort_cmd->hwq; +struct blk_mq_tags *tags = tag_set->tags[hwq]; +struct request *abort_rq =blk_mq_tag_to_rq (tags, tag); +struct scsi_cmnd *abort_scmd =blk_mq_rq_to_pdu (abort_rq); +struct sdebug_scsi_cmd *abort_sdsc =scsi_cmd_priv (abort_scmd); +bool res; + +scoped_guard (spinlock_irqsave, &abort_sdsc->lock) + res = scsi_debug_stop_cmnd(abort_scmd); + + scp->result = (res ?DID_OK :DID_ERROR ) <<16 ; +} + +static int scsi_debug_queue_reserved_command (struct Scsi_Host *shost, +struct scsi_cmnd *scp) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (scp); + +switch (sdsc->internal_cmd.type) { +case SCSI_DEBUG_ABORT_CMD : +scsi_debug_abort_cmd (shost, scp); +break ; +default : +WARN_ON_ONCE (true); + scp->result =DID_ERROR <<16 ; +break ; + } + +scsi_done (scp); +return 0 ; +} +static int scsi_debug_queuecommand (struct Scsi_Host *shost,struct scsi_cmnd *scp) {
@@ -9416,6 +9502,7 @@ static const struct scsi_host_template sdebug_driver_template = { .sdev_destroy = scsi_debug_sdev_destroy, .ioctl = scsi_debug_ioctl, .queuecommand = scsi_debug_queuecommand, + .queue_reserved_command = scsi_debug_queue_reserved_command, .change_queue_depth = sdebug_change_qdepth, .map_queues = sdebug_map_queues, .mq_poll = sdebug_blk_mq_poll,
@@ -9425,6 +9512,7 @@ static const struct scsi_host_template sdebug_driver_template = { .eh_bus_reset_handler = scsi_debug_bus_reset, .eh_host_reset_handler = scsi_debug_host_reset, .can_queue = SDEBUG_CANQUEUE, + .nr_reserved_cmds = 1, .this_id = 7, .sg_tablesize = SG_MAX_SEGMENTS, .cmd_per_lun = DEF_CMD_PER_LUN,
Re: [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command()
Quoted 6 lines · Bart Van Assche
Add a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for processing reserved commands gets triggered while running blktests.
Signed-off-by Bart Van Assche <[email protected]>
At least Suggested-by would be good, if you don't mind
Quoted 33 lines
--- drivers/scsi/scsi_debug.c | 106 ++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 9 deletions(-)drivers/scsi/scsi_debug.c +17
-0@@ -451,6 +451,23 @@ struct sdeb_store_info {#define shost_to_sdebug_host (shost) \ dev_to_sdebug_host(shost->dma_dev) +struct scsi_debug_abort_cmd { +u16 tag; +u16 hwq; +}; + +enum scsi_debug_internal_cmd_type { +SCSI_DEBUG_ABORT_CMD , +}; + +struct scsi_debug_internal_cmd { +enum scsi_debug_internal_cmd_type type; + +union { +struct scsi_debug_abort_cmd abort_cmd; + }; +}; +enum sdeb_defer_type {SDEB_DEFER_NONE =0 ,SDEB_DEFER_HRT =1 ,SDEB_DEFER_WQ =2 ,SDEB_DEFER_POLL =3 };
drivers/scsi/scsi_debug.c struct sdebug_defer { · line 487
Quoted 5 lines
drivers/scsi/scsi_debug.c +2
-0@@ -466,6 +483,8 @@ struct sdebug_defer {struct sdebug_scsi_cmd {spinlock_t lock;struct sdebug_defer sd_dp; + +struct scsi_debug_internal_cmd internal_cmd;
you could prob make this a union with sd_dp - I mean, could they ever both be simultaneously used?
drivers/scsi/scsi_debug.c static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd) · line 6751
Quoted 8 lines
drivers/scsi/scsi_debug.c +1
-0};static atomic_t sdebug_cmnd_count;/* number of incoming commands */ @@ -6729,20 +6748,48 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd)return false; } +static int scsi_debug_setup_abort_cmd(struct scsi_cmnd *cmd,
nobody checks the return value
Quoted 33 lines
drivers/scsi/scsi_debug.c +21
-8+ const struct scsi_debug_internal_cmd *internal_cmd) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmd); + + sdsc->internal_cmd = *internal_cmd; + +return 0 ; +} +/* -* Called from scsi_debug_abort() only, which is for timed-out cmd. +* Abort a pending SCSI command. Only called from scsi_debug_abort(). Although +* it would be possible to call scsi_debug_stop_cmnd() directly, an internal +* command is allocated and submitted to use the reserved command +* infrastructure. */ static bool scsi_debug_abort_cmnd (struct scsi_cmnd *cmnd) { -struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmnd); -unsigned long flags; -bool res; - -spin_lock_irqsave (&sdsc->lock, flags); - res =scsi_debug_stop_cmnd (cmnd); -spin_unlock_irqrestore (&sdsc->lock, flags); +struct request *rq =scsi_cmd_to_rq (cmnd); +u32 unique_tag =blk_mq_unique_tag (rq); +u16 hwq =blk_mq_unique_tag_to_hwq (unique_tag); +u16 tag =blk_mq_unique_tag_to_tag (unique_tag); +struct scsi_device *sdev = cmnd->device; +struct Scsi_Host *shost = sdev->host; +const struct scsi_debug_internal_cmd ic = { + .type =SCSI_DEBUG_ABORT_CMD ,
drivers/scsi/scsi_debug.c static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd) · line 6785
Quoted 10 lines
drivers/scsi/scsi_debug.c +8
-1+ .abort_cmd = { + .tag = tag, + .hwq = hwq, + }, + }; +struct scsi_cmnd *abort_cmd; +struct request *abort_rq; -return res; + abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, DMA_TO_DEVICE,
DMA_NONE?
drivers/scsi/scsi_debug.c static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd) · line 6788
Quoted 3 lines
drivers/scsi/scsi_debug.c +3
-0+ BLK_MQ_REQ_RESERVED); +if (WARN_ON_ONCE (!abort_cmd)) +return false;
I don't really think that this deserves a WARN_ON_ONCE
Quoted 19 lines
drivers/scsi/scsi_debug.c +12
-0+scsi_debug_setup_abort_cmd (abort_cmd, &ic); + abort_rq =scsi_cmd_to_rq (abort_cmd); + abort_rq->timeout =secs_to_jiffies (3 ); +return blk_execute_rq (abort_rq, true) ==BLK_STS_OK ; }/* @@ -9197,6 +9244,45 @@ static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval,return ret; } +static void scsi_debug_abort_cmd (struct Scsi_Host *shost,struct scsi_cmnd *scp) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (scp); +struct scsi_debug_abort_cmd *abort_cmd = + &sdsc->internal_cmd.abort_cmd; +struct blk_mq_tag_set *tag_set = &shost->tag_set; +unsigned int tag = abort_cmd->tag; +unsigned int hwq = abort_cmd->hwq;
drivers/scsi/scsi_debug.c static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval, · line 9264
Quoted 10 lines
drivers/scsi/scsi_debug.c +10
-0+struct blk_mq_tags *tags = tag_set->tags[hwq]; +struct request *abort_rq =blk_mq_tag_to_rq (tags, tag); +struct scsi_cmnd *abort_scmd =blk_mq_rq_to_pdu (abort_rq); +struct sdebug_scsi_cmd *abort_sdsc =scsi_cmd_priv (abort_scmd); +bool res; + +scoped_guard (spinlock_irqsave, &abort_sdsc->lock) + res = scsi_debug_stop_cmnd(abort_scmd); + + scp->result = (res ?DID_OK :DID_ERROR ) <<16 ;
personally I think that if-else is nicer, but that's just me
And please consider using set_host_byte()
Quoted 41 lines
drivers/scsi/scsi_debug.c +23
-0+} + +static int scsi_debug_queue_reserved_command (struct Scsi_Host *shost, +struct scsi_cmnd *scp) +{ +struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (scp); + +switch (sdsc->internal_cmd.type) { +case SCSI_DEBUG_ABORT_CMD : +scsi_debug_abort_cmd (shost, scp); +break ; +default : +WARN_ON_ONCE (true); + scp->result =DID_ERROR <<16 ; +break ; + } + +scsi_done (scp); +return 0 ; +} +static int scsi_debug_queuecommand (struct Scsi_Host *shost,struct scsi_cmnd *scp) {@@ -9416,6 +9502,7 @@ static const struct scsi_host_template sdebug_driver_template = { .sdev_destroy = scsi_debug_sdev_destroy, .ioctl = scsi_debug_ioctl, .queuecommand = scsi_debug_queuecommand, + .queue_reserved_command = scsi_debug_queue_reserved_command, .change_queue_depth = sdebug_change_qdepth, .map_queues = sdebug_map_queues, .mq_poll = sdebug_blk_mq_poll,@@ -9425,6 +9512,7 @@ static const struct scsi_host_template sdebug_driver_template = { .eh_bus_reset_handler = scsi_debug_bus_reset, .eh_host_reset_handler = scsi_debug_host_reset, .can_queue = SDEBUG_CANQUEUE, + .nr_reserved_cmds = 1, .this_id = 7, .sg_tablesize = SG_MAX_SEGMENTS, .cmd_per_lun = DEF_CMD_PER_LUN,
Bart Van Assche
reviewerRe: [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command()
Quoted 9 lines · John Garry
Quoted 6 lines · Bart Van Assche
Add a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for processing reserved commands gets triggered while running blktests.
Signed-off-by Bart Van Assche <[email protected]>At least Suggested-by would be good, if you don't mind
If nobody objects I will add the following text:
----------------------------------------------------------------------
Most of the code in this patch is a modified version of code from John Garry. See also
https://lore.kernel.org/linux-scsi/[email protected]/
----------------------------------------------------------------------
Quoted 10 lines
Review struct sdebug_defer { · line 487
Quoted 8 lines
enum
sdeb_defer_type{SDEB_DEFER_NONE= 0,SDEB_DEFER_HRT= 1,SDEB_DEFER_WQ= 2,SDEB_DEFER_POLL= 3};(quoted diff) +2
-0@@ -466,6 +483,8 @@ struct sdebug_defer { struct sdebug_scsi_cmd { spinlock_t lock; struct sdebug_defer sd_dp; + + struct scsi_debug_internal_cmd internal_cmd;you could prob make this a union with
sd_dp- I mean, could they ever both be simultaneously used?
Introducing a union for sd_dp and internal_cmd only would suggest to readers of the scsi_debug code that 'lock' protects both 'sd_dp' and 'internal_cmd', which is not the case. I propose to include the following change in this patch:
drivers/scsi/scsi_debug.c +2 -3
@@ -483,8 +483,6 @@ struct sdebug_defer {struct sdebug_scsi_cmd {spinlock_t lock;struct sdebug_defer sd_dp; - -struct scsi_debug_internal_cmd internal_cmd; };static atomic_t sdebug_cmnd_count;/* number of incoming commands */
@@ -9518,7 +9516,8 @@ static const struct scsi_host_template sdebug_driver_template = { .module = THIS_MODULE, .skip_settle_delay = 1, .track_queue_depth = 1, - .cmd_size = sizeof(struct sdebug_scsi_cmd), + .cmd_size =sizeof (union {struct sdebug_scsi_cmd c; + struct scsi_debug_internal_cmd ic; }), .init_cmd_priv = sdebug_init_cmd_priv, .target_alloc = sdebug_target_alloc, .target_destroy = sdebug_target_destroy,
Quoted 3 lines
Review struct sdebug_defer { · line 488
Quoted 1 line
(quoted diff) +1
-0+static int scsi_debug_setup_abort_cmd(struct scsi_cmnd *cmd,nobody checks the return value
Agreed. I will change the return type from 'int' into 'void'.
Quoted 3 lines
Review struct sdebug_defer { · line 489
Quoted 1 line
(quoted diff) +1
-0+ abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, DMA_TO_DEVICE,
DMA_NONE?
DMA_TO_DEVICE is converted into REQ_OP_DRV_OUT by scsi_get_internal_cmd(). Isn't that more appropriate for an operation that has side effects (aborting a SCSI command) rather thanREQ_OP_DRV_IN?
Quoted 5 lines
Review struct sdebug_defer {
Quoted 3 lines
(quoted diff) +3
-0+ BLK_MQ_REQ_RESERVED); + if (WARN_ON_ONCE(!abort_cmd)) + return false;I don't really think that this deserves a
WARN_ON_ONCE
OK, I will remove the WARN_ON_ONCE().
Quoted 5 lines
Quoted 1 line
+
scp->result= (res ?DID_OK:DID_ERROR) << 16;personally I think that if-else is nicer, but that's just me
And please consider using
set_host_byte()
I will use set_host_byte().
Thanks,
Bart.
Re: [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command()
Quoted 13 lines · Bart Van Assche
Quoted 9 lines · John Garry
Quoted 6 lines · Bart Van Assche
Add a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for processing reserved commands gets triggered while running blktests.
Signed-off-by Bart Van Assche <[email protected]>At least Suggested-by would be good, if you don't mind
If nobody objects I will add the following text:
Quoted 7 lines
----------------------------------------------------------------------
Most of the code in this patch is a modified version of code from John Garry. See also
https://lore.kernel.org/linux- scsi/[email protected]/Suggested-by John Garry <[email protected]>----------------------------------------------------------------------
fine, thanks
Quoted 31 lines
Quoted 11 lines
drivers/scsi/scsi_debug.c struct sdebug_defer { · line 487
Quoted 9 lines
enum
sdeb_defer_type{SDEB_DEFER_NONE= 0,SDEB_DEFER_HRT= 1,SDEB_DEFER_WQ= 2,SDEB_DEFER_POLL= 3};drivers/scsi/scsi_debug.c +2
-0@@ -466,6 +483,8 @@ struct sdebug_defer { struct sdebug_scsi_cmd { spinlock_t lock; struct sdebug_defer sd_dp; + + struct scsi_debug_internal_cmd internal_cmd;you could prob make this a union with
sd_dp- I mean, could they ever both be simultaneously used?Introducing a union for
sd_dpandinternal_cmdonly would suggest to readers of thescsi_debugcode that 'lock' protects both 'sd_dp' and 'internal_cmd', which is not the case. I propose to include the following change in this patch:drivers/scsi/scsi_debug.c +0
-2@@ -483,8 +483,6 @@ struct sdebug_defer { struct sdebug_scsi_cmd { spinlock_t lock; struct sdebug_defer sd_dp; - - struct scsi_debug_internal_cmd internal_cmd; }; static atomic_t sdebug_cmnd_count; /* number of incoming commands */
drivers/scsi/scsi_debug.c static const struct scsi_host_template · line 9521
Quoted 7 lines
drivers/scsi/scsi_debug.c +2
-1@@ -9518,7 +9516,8 @@ static const struct scsi_host_template sdebug_driver_template = { .module = THIS_MODULE, .skip_settle_delay = 1, .track_queue_depth = 1, - .cmd_size = sizeof(struct sdebug_scsi_cmd), + .cmd_size = sizeof(union { struct sdebug_scsi_cmd c; + struct scsi_debug_internal_cmd ic; }),
ok, but you could also introduce a new structure which defines this union. That's looks a little bit better.
Quoted 10 lines
drivers/scsi/scsi_debug.c +0
-0.init_cmd_priv = sdebug_init_cmd_priv, .target_alloc = sdebug_target_alloc,.target_destroy =
sdebug_target_destroy,Quoted 3 lines
Review struct sdebug_defer { · line 488
Quoted 1 line
(quoted diff) +1
-0+static int scsi_debug_setup_abort_cmd(struct scsi_cmnd *cmd,nobody checks the return value
Agreed. I will change the return type from 'int' into 'void'.
Quoted 8 lines
Quoted 4 lines
Review struct sdebug_defer { · line 490
Quoted 2 lines
(quoted diff) +1
-0+ abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, DMA_TO_DEVICE,
DMA_NONE?
DMA_TO_DEVICEis converted intoREQ_OP_DRV_OUTbyscsi_get_internal_cmd(). Isn't that more appropriate for an operation that has side effects (aborting a SCSI command) rather thanREQ_OP_DRV_IN?
but it it make a difference if we use REQ_OP_DRV_OUT or REQ_OP_DRV_IN? If not, then I think DMA_NONE makes more sense.
Thanks,
John
Bart Van Assche
reviewerRe: [PATCH v5 07/28] scsi_debug: Abort SCSI commands via .queue_reserved_command()
Quoted 16 lines · John Garry
Review static const struct scsi_host_template · line 9521
Quoted 9 lines · Bart Van Assche
static
atomic_tsdebug_cmnd_count; /* number of incoming commands */(quoted diff) +2
-1@@ -9518,7 +9516,8 @@ static const struct scsi_host_template sdebug_driver_template = { .module = THIS_MODULE, .skip_settle_delay = 1, .track_queue_depth = 1, - .cmd_size = sizeof(struct sdebug_scsi_cmd), + .cmd_size = sizeof(union { struct sdebug_scsi_cmd c; + struct scsi_debug_internal_cmd ic; }),ok, but you could also introduce a new structure which defines this union. That's looks a little bit better.
Quoted 3 lines
(quoted diff) +0
-0>> + abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, >> DMA_TO_DEVICE,Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
DMA_NONE?
DMA_TO_DEVICEis converted intoREQ_OP_DRV_OUTbyscsi_get_internal_cmd(). Isn't that more appropriate for an operation that has side effects (aborting a SCSI command) rather thanREQ_OP_DRV_IN?but it it make a difference if we use
REQ_OP_DRV_OUTorREQ_OP_DRV_IN? If not, then I thinkDMA_NONEmakes more sense.
The above feedback has been integrated in the patch below. The following additional changes have been integrated in this patch:
- Use scsi_host_find_tag() to make the implementation more compact.
- Pass a 32-bit tag from scsi_debug_abort_cmnd() to the code that implements the abort instead of splitting this 32-bit tag into a 16-bit hwq index and a 16-bit tag.
This new version passes the blktests test that I wrote to trigger the new code.
Thanks,
Bart.
Subject: [PATCH] scsi_debug: Abort SCSI commands via an internal command
Add a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for allocating and processing reserved commands gets triggered while running blktests.
Most of the code in this patch is a modified version of code from John Garry. See also
https://lore.kernel.org/linux-scsi/[email protected]/
--- drivers/scsi/scsi_debug.c | 113 ++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 11 deletions(-)
drivers/scsi/scsi_debug.c +102 -11
@@ -6729,20 +6729,59 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd)return false; } +struct sdebug_abort_cmd { +u32 unique_tag; +}; + +enum sdebug_internal_cmd_type { +SCSI_DEBUG_ABORT_CMD , +}; + +struct sdebug_internal_cmd { +enum sdebug_internal_cmd_type type; + +union { +struct sdebug_abort_cmd abort_cmd; + }; +}; + +union sdebug_priv { +struct sdebug_scsi_cmd c; +struct sdebug_internal_cmd ic; +}; +/* -* Called from scsi_debug_abort() only, which is for timed-out cmd. +* Abort a pending SCSI command. Only called from scsi_debug_abort(). Although +* it would be possible to call scsi_debug_stop_cmnd() directly, an internal +* command is allocated and submitted to trigger the reserved command +* infrastructure. */ static bool scsi_debug_abort_cmnd (struct scsi_cmnd *cmnd) { -struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmnd); -unsigned long flags; -bool res; - -spin_lock_irqsave (&sdsc->lock, flags); - res =scsi_debug_stop_cmnd (cmnd); -spin_unlock_irqrestore (&sdsc->lock, flags); - -return res; +struct Scsi_Host *shost = cmnd->device->host; +struct request *rq =scsi_cmd_to_rq (cmnd); +u32 unique_tag =blk_mq_unique_tag (rq); +struct sdebug_internal_cmd *sdic; +struct scsi_cmnd *abort_cmd; +struct request *abort_rq; +blk_status_t res; + + abort_cmd =scsi_get_internal_cmd (shost->pseudo_sdev,DMA_NONE , +BLK_MQ_REQ_RESERVED ); +if (!abort_cmd) +return false; + sdic =scsi_cmd_priv (abort_cmd); + *sdic = (struct sdebug_internal_cmd ) { + .type =SCSI_DEBUG_ABORT_CMD , + .abort_cmd = { + .unique_tag = unique_tag, + }, + }; + abort_rq =scsi_cmd_to_rq (abort_cmd); + abort_rq->timeout =secs_to_jiffies (3 ); + res =blk_execute_rq (abort_rq, true); +scsi_put_internal_cmd (abort_cmd); +return res ==BLK_STS_OK ; }/*
@@ -9197,6 +9236,53 @@ static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval,return ret; } +static void scsi_debug_abort_cmd (struct Scsi_Host *shost,struct scsi_cmnd *scp) +{ +struct sdebug_internal_cmd *sdic =scsi_cmd_priv (scp); +struct sdebug_abort_cmd *abort_cmd = &sdic->abort_cmd; +const u32 unique_tag = abort_cmd->unique_tag; +struct scsi_cmnd *to_be_aborted_scmd = +scsi_host_find_tag (shost, unique_tag); +struct sdebug_scsi_cmd *to_be_aborted_sdsc = +scsi_cmd_priv (to_be_aborted_scmd); +bool res = false; + +if (to_be_aborted_scmd) { +scoped_guard (spinlock_irqsave, &to_be_aborted_sdsc->lock) + res = scsi_debug_stop_cmnd(to_be_aborted_scmd); +if (res) +pr_info ("%s: aborted command with tag %#x\n" , + __func__, unique_tag); +else +pr_err ("%s: failed to abort command with tag %#x\n" , + __func__, unique_tag); + }else { +pr_err ("%s: command with tag %#x not found\n" , __func__, + unique_tag); + } + +set_host_byte (scp, res ?DID_OK :DID_ERROR ); +} + +static int scsi_debug_process_reserved_command (struct Scsi_Host *shost, +struct scsi_cmnd *scp) +{ +struct sdebug_internal_cmd *sdic =scsi_cmd_priv (scp); + +switch (sdic->type) { +case SCSI_DEBUG_ABORT_CMD : +scsi_debug_abort_cmd (shost, scp); +break ; +default : +WARN_ON_ONCE (true); +set_host_byte (scp,DID_ERROR ); +break ; + } + +scsi_done (scp); +return 0 ; +} +static int scsi_debug_queuecommand (struct Scsi_Host *shost,struct scsi_cmnd *scp) {
@@ -9397,6 +9483,9 @@ static int sdebug_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd)struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmd);struct sdebug_defer *sd_dp = &sdsc->sd_dp; +if (blk_mq_is_reserved_rq (scsi_cmd_to_rq (cmd))) +return 0 ; +spin_lock_init (&sdsc->lock);hrtimer_setup (&sd_dp->hrt, sdebug_q_cmd_hrt_complete,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_PINNED );
@@ -9416,6 +9505,7 @@ static const struct scsi_host_template sdebug_driver_template = { .sdev_destroy = scsi_debug_sdev_destroy, .ioctl = scsi_debug_ioctl, .queuecommand = scsi_debug_queuecommand, + .queue_reserved_command = scsi_debug_process_reserved_command, .change_queue_depth = sdebug_change_qdepth, .map_queues = sdebug_map_queues, .mq_poll = sdebug_blk_mq_poll,
@@ -9425,6 +9515,7 @@ static const struct scsi_host_template sdebug_driver_template = { .eh_bus_reset_handler = scsi_debug_bus_reset, .eh_host_reset_handler = scsi_debug_host_reset, .can_queue = SDEBUG_CANQUEUE, + .nr_reserved_cmds = 1, .this_id = 7, .sg_tablesize = SG_MAX_SEGMENTS, .cmd_per_lun = DEF_CMD_PER_LUN,
@@ -9433,7 +9524,7 @@ static const struct scsi_host_template sdebug_driver_template = { .module = THIS_MODULE, .skip_settle_delay = 1, .track_queue_depth = 1, - .cmd_size = sizeof(struct sdebug_scsi_cmd), + .cmd_size = sizeof(union sdebug_priv), .init_cmd_priv = sdebug_init_cmd_priv, .target_alloc = sdebug_target_alloc, .target_destroy = sdebug_target_destroy,
Bart Van Assche
reviewerPATCH v5 8/28 ufs: core: Move an assignment in ufshcd_mcq_process_cqe()
In reply to Bart Van AsschePrepare for introducing a WARN_ON_ONCE() call in ufshcd_mcq_get_tag() if the tag lookup fails.
--- drivers/ufs/core/ufs-mcq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufs-mcq.c +2 -1
@@ -303,9 +303,10 @@ static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, struct ufs_hw_queue *hwq) {struct cq_entry *cqe =ufshcd_mcq_cur_cqe (hwq); -int tag =ufshcd_mcq_get_tag (hba, cqe);if (cqe->command_desc_base_addr) { +int tag =ufshcd_mcq_get_tag (hba, cqe); +ufshcd_compl_one_cqe (hba, tag, cqe);/* After processed the cqe, mark it empty (invalid) entry */ cqe->command_desc_base_addr =0 ;
RE: [PATCH v5 08/28] ufs: core: Move an assignment in ufshcd_mcq_process_cqe()
Quoted 4 lines
Prepare for introducing a
WARN_ON_ONCE()call inufshcd_mcq_get_tag()if the tag lookup fails.Signed-off-by Bart Van Assche <[email protected]>
Quoted 20 lines
--- drivers/ufs/core/ufs-mcq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/ufs/core/ufs-mcq.c index renamed from drivers/ufs/core/ufs-mcq.c +0
-0
1e50675772fe..4eb4f1af7800100644drivers/ufs/core/ufs-mcq.c +2
-1@@ -303,9 +303,10 @@ static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, struct ufs_hw_queue *hwq) {struct cq_entry *cqe =ufshcd_mcq_cur_cqe (hwq); -int tag =ufshcd_mcq_get_tag (hba, cqe);if (cqe->command_desc_base_addr) { +int tag =ufshcd_mcq_get_tag (hba, cqe); +ufshcd_compl_one_cqe (hba, tag, cqe);/* After processed the cqe, mark it empty (invalid) entry */ cqe->command_desc_base_addr =0 ;
Bart Van Assche
reviewerPATCH v5 9/28 ufs: core: Change the type of one ufshcd_add_cmd_upiu_trace() argument
In reply to Bart Van AsscheChange the 'tag' argument into an LRB pointer. This patch prepares for the removal of the hba->lrb[] array.
--- drivers/ufs/core/ufshcd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +5 -4
@@ -408,10 +408,11 @@ static void ufshcd_configure_wb(struct ufs_hba *hba)ufshcd_wb_toggle_buf_flush (hba, true); } -static void ufshcd_add_cmd_upiu_trace (struct ufs_hba *hba,unsigned int tag, +static void ufshcd_add_cmd_upiu_trace (struct ufs_hba *hba, +struct ufshcd_lrb *lrb,enum ufs_trace_str_t str_t) { -struct utp_upiu_req *rq = hba->lrb[tag].ucd_req_ptr; +struct utp_upiu_req *rq = lrb->ucd_req_ptr;struct utp_upiu_header *header;if (!trace_ufshcd_upiu_enabled ())
@@ -420,7 +421,7 @@ static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag,if (str_t ==UFS_CMD_SEND ) header = &rq->header;else - header = &hba->lrb[tag].ucd_rsp_ptr->header; + header = &lrb->ucd_rsp_ptr->header;trace_ufshcd_upiu (hba, str_t, header, &rq->sc.cdb,UFS_TSF_CDB );
@@ -494,7 +495,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,return ;/* trace UPIU also */ -ufshcd_add_cmd_upiu_trace (hba, tag, str_t); +ufshcd_add_cmd_upiu_trace (hba, lrbp, str_t);if (!trace_ufshcd_command_enabled ())return ;
Bart Van Assche
reviewerPATCH v5 10/28 ufs: core: Only call ufshcd_add_command_trace() for SCSI commands
In reply to Bart Van AsscheInstead of checking inside ufshcd_add_command_trace() whether 'cmd' points at a SCSI command, let the caller perform that check. This patch prepares for removing the lrbp->cmd pointer.
--- drivers/ufs/core/ufshcd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +3 -5
@@ -491,9 +491,6 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,struct request *rq =scsi_cmd_to_rq (cmd);int transfer_len =-1 ; -if (!cmd) -return ; -/* trace UPIU also */ ufshcd_add_cmd_upiu_trace (hba, lrbp, str_t);if (!trace_ufshcd_command_enabled ())
@@ -2368,9 +2365,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, lrbp->compl_time_stamp =ktime_set (0 ,0 ); lrbp->compl_time_stamp_local_clock =0 ; } -ufshcd_add_command_trace (hba, task_tag,UFS_CMD_SEND ); -if (lrbp->cmd) +if (lrbp->cmd) { +ufshcd_add_command_trace (hba, task_tag,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba); + }if (unlikely (ufshcd_should_inform_monitor (hba, lrbp)))ufshcd_start_monitor (hba, lrbp);
Bart Van Assche
reviewerPATCH v5 11/28 ufs: core: Change the type of one ufshcd_add_command_trace() argument
In reply to Bart Van AsscheChange the 'tag' argument into a SCSI command pointer. This patch prepares for the removal of the hba->lrb[] array.
--- drivers/ufs/core/ufshcd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/ufs/core/ufshcd.c +6 -6
@@ -478,7 +478,7 @@ static void ufshcd_add_uic_command_trace(struct ufs_hba *hba, ufshcd_readl(hba, REG_UIC_COMMAND_ARG_3)); } -static void ufshcd_add_command_trace (struct ufs_hba *hba,unsigned int tag, +static void ufshcd_add_command_trace (struct ufs_hba *hba,struct scsi_cmnd *cmd,enum ufs_trace_str_t str_t) {u64 lba =0 ;
@@ -486,9 +486,9 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,u32 doorbell =0 ;u32 intr;u32 hwq_id =0 ; -struct ufshcd_lrb *lrbp = &hba->lrb[tag]; -struct scsi_cmnd *cmd = lrbp->cmd;struct request *rq =scsi_cmd_to_rq (cmd); +unsigned int tag = rq->tag; +struct ufshcd_lrb *lrbp = &hba->lrb[tag];int transfer_len =-1 ;/* trace UPIU also */
@@ -506,7 +506,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,be32_to_cpu (lrbp->ucd_req_ptr->sc.exp_data_transfer_len); lba =scsi_get_lba (cmd);if (opcode ==WRITE_10 ) - group_id = lrbp->cmd->cmnd[6 ]; + group_id = cmd->cmnd[6 ]; }else if (opcode ==UNMAP ) {/* * The number of Bytes to be unmapped beginning with the lba.
@@ -2366,7 +2366,7 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, lrbp->compl_time_stamp_local_clock =0 ; }if (lrbp->cmd) { -ufshcd_add_command_trace (hba, task_tag,UFS_CMD_SEND ); +ufshcd_add_command_trace (hba, lrbp->cmd,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba); }if (unlikely (ufshcd_should_inform_monitor (hba, lrbp)))
@@ -5633,7 +5633,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,if (cmd) {if (unlikely (ufshcd_should_inform_monitor (hba, lrbp)))ufshcd_update_monitor (hba, lrbp); -ufshcd_add_command_trace (hba, task_tag,UFS_CMD_COMP ); +ufshcd_add_command_trace (hba, cmd,UFS_CMD_COMP ); cmd->result =ufshcd_transfer_rsp_status (hba, lrbp, cqe);ufshcd_release_scsi_cmd (hba, lrbp);/* Do not touch lrbp after scsi done */
Bart Van Assche
reviewerPATCH v5 12/28 ufs: core: Change the type of one ufshcd_send_command() argument
In reply to Bart Van AsscheChange the 'task_tag' argument into an LRB pointer. This patch prepares for the removal of the hba->lrb[] array.
--- drivers/ufs/core/ufshcd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/ufs/core/ufshcd.c +6 -7
@@ -2349,14 +2349,13 @@ static void ufshcd_update_monitor(struct ufs_hba *hba, const struct ufshcd_lrb */** * ufshcd_send_command - Send SCSI or device management commands * @hba: per adapter instance -* @task_tag: Task tag of the command +* @lrbp: Local reference block of SCSI command * @hwq: pointer to hardware queue instance */ -static inline -void ufshcd_send_command (struct ufs_hba *hba,unsigned int task_tag, -struct ufs_hw_queue *hwq) +static inline void ufshcd_send_command (struct ufs_hba *hba, +struct ufshcd_lrb *lrbp, +struct ufs_hw_queue *hwq) { -struct ufshcd_lrb *lrbp = &hba->lrb[task_tag];unsigned long flags;if (hba->monitor.enabled) {
@@ -3065,7 +3064,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)if (hba->mcq_enabled) hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (cmd)); -ufshcd_send_command (hba, tag, hwq); +ufshcd_send_command (hba, lrbp, hwq); out:if (ufs_trigger_eh (hba)) {
@@ -3310,7 +3309,7 @@ static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,int err;ufshcd_add_query_upiu_trace (hba,UFS_QUERY_SEND , lrbp->ucd_req_ptr); -ufshcd_send_command (hba, tag, hba->dev_cmd_queue); +ufshcd_send_command (hba, lrbp, hba->dev_cmd_queue); err =ufshcd_wait_for_dev_cmd (hba, lrbp, timeout); ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
Bart Van Assche
reviewerPATCH v5 13/28 ufs: core: Only call ufshcd_should_inform_monitor() for SCSI commands
In reply to Bart Van Asscheufshcd_should_inform_monitor() only returns 'true' for SCSI commands. Instead of checking inside ufshcd_should_inform_monitor() whether its second argument represents a SCSI command, only call this function for SCSI commands. This patch prepares for removing the lrbp->cmd member.
--- drivers/ufs/core/ufshcd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ufs/core/ufshcd.c +4 -3
@@ -2292,12 +2292,13 @@ static inline int ufshcd_monitor_opcode2dir(u8 opcode)return -EINVAL ; } +/* Must only be called for SCSI commands. */ static inline bool ufshcd_should_inform_monitor (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) {const struct ufs_hba_monitor *m = &hba->monitor; -return (m->enabled && lrbp && lrbp->cmd && +return (m->enabled && (!m->chunk_size || m->chunk_size == lrbp->cmd->sdb.length) &&ktime_before (hba->monitor.enabled_ts, lrbp->issue_time_stamp)); }
@@ -2367,9 +2368,9 @@ static inline void ufshcd_send_command(struct ufs_hba *hba,if (lrbp->cmd) {ufshcd_add_command_trace (hba, lrbp->cmd,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba); +if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) +ufshcd_start_monitor (hba, lrbp); } -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_start_monitor (hba, lrbp);if (hba->mcq_enabled) {int utrd_size =sizeof (struct utp_transfer_req_desc );
Bart Van Assche
reviewerPATCH v5 14/28 ufs: core: Change the monitor function argument types
In reply to Bart Van AsschePass a SCSI command pointer instead of a struct ufshcd_lrb pointer. This patch prepares for combining the SCSI command and ufshcd_lrb data structures into a single data structure.
--- drivers/ufs/core/ufshcd.c | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/ufs/core/ufshcd.c +22 -22
@@ -2294,19 +2294,20 @@ static inline int ufshcd_monitor_opcode2dir(u8 opcode)/* Must only be called for SCSI commands. */ static inline bool ufshcd_should_inform_monitor (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) {const struct ufs_hba_monitor *m = &hba->monitor; +struct request *rq =scsi_cmd_to_rq (cmd); +struct ufshcd_lrb *lrbp = &hba->lrb[rq->tag]; -return (m->enabled && - (!m->chunk_size || m->chunk_size == lrbp->cmd->sdb.length) && -ktime_before (hba->monitor.enabled_ts, lrbp->issue_time_stamp)); +return m->enabled && + (!m->chunk_size || m->chunk_size == cmd->sdb.length) && +ktime_before (hba->monitor.enabled_ts, lrbp->issue_time_stamp); } -static void ufshcd_start_monitor (struct ufs_hba *hba, -const struct ufshcd_lrb *lrbp) +static void ufshcd_start_monitor (struct ufs_hba *hba,struct scsi_cmnd *cmd) { -int dir =ufshcd_monitor_opcode2dir (*lrbp->cmd->cmnd); +int dir =ufshcd_monitor_opcode2dir (cmd->cmnd[0 ]);unsigned long flags;spin_lock_irqsave (hba->host->host_lock, flags);
@@ -2315,14 +2316,15 @@ static void ufshcd_start_monitor(struct ufs_hba *hba,spin_unlock_irqrestore (hba->host->host_lock, flags); } -static void ufshcd_update_monitor (struct ufs_hba *hba,const struct ufshcd_lrb *lrbp) +static void ufshcd_update_monitor (struct ufs_hba *hba,struct scsi_cmnd *cmd) { -int dir =ufshcd_monitor_opcode2dir (*lrbp->cmd->cmnd); +struct request *req =scsi_cmd_to_rq (cmd); +struct ufshcd_lrb *lrbp = &hba->lrb[req->tag]; +int dir =ufshcd_monitor_opcode2dir (cmd->cmnd[0 ]);unsigned long flags;spin_lock_irqsave (hba->host->host_lock, flags);if (dir >=0 && hba->monitor.nr_queued[dir] >0 ) { -const struct request *req =scsi_cmd_to_rq (lrbp->cmd);struct ufs_hba_monitor *m = &hba->monitor;ktime_t now, inc, lat;
@@ -2357,6 +2359,7 @@ static inline void ufshcd_send_command(struct ufs_hba *hba,struct ufshcd_lrb *lrbp, struct ufs_hw_queue *hwq) { + struct scsi_cmnd *cmd = lrbp->cmd;unsigned long flags;if (hba->monitor.enabled) {
@@ -2365,11 +2368,11 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, lrbp->compl_time_stamp =ktime_set (0 ,0 ); lrbp->compl_time_stamp_local_clock =0 ; } -if (lrbp->cmd) { -ufshcd_add_command_trace (hba, lrbp->cmd,UFS_CMD_SEND ); +if (cmd) { +ufshcd_add_command_trace (hba, cmd,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba); -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_start_monitor (hba, lrbp); +if (unlikely (ufshcd_should_inform_monitor (hba, cmd))) +ufshcd_start_monitor (hba, cmd); }if (hba->mcq_enabled) {
@@ -2385,8 +2388,7 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, }else {spin_lock_irqsave (&hba->outstanding_lock, flags);if (hba->vops && hba->vops->setup_xfer_req) - hba->vops->setup_xfer_req (hba, lrbp->task_tag, - !!lrbp->cmd); + hba->vops->setup_xfer_req (hba, lrbp->task_tag, !!cmd);__set_bit (lrbp->task_tag, &hba->outstanding_reqs);ufshcd_writel (hba,1 << lrbp->task_tag,REG_UTP_TRANSFER_REQ_DOOR_BELL );
@@ -5620,19 +5622,17 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba,void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag,struct cq_entry *cqe) { -struct ufshcd_lrb *lrbp; -struct scsi_cmnd *cmd; +struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; +struct scsi_cmnd *cmd = lrbp->cmd;enum utp_ocs ocs; - lrbp = &hba->lrb[task_tag];if (hba->monitor.enabled) { lrbp->compl_time_stamp =ktime_get (); lrbp->compl_time_stamp_local_clock =local_clock (); } - cmd = lrbp->cmd;if (cmd) { -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_update_monitor (hba, lrbp); +if (unlikely (ufshcd_should_inform_monitor (hba, cmd))) +ufshcd_update_monitor (hba, cmd);ufshcd_add_command_trace (hba, cmd,UFS_CMD_COMP ); cmd->result =ufshcd_transfer_rsp_status (hba, lrbp, cqe);ufshcd_release_scsi_cmd (hba, lrbp);
RE: [PATCH v5 14/28] ufs: core: Change the monitor function argument types
Quoted 5 lines
Pass a SCSI command pointer instead of a struct
ufshcd_lrbpointer. This patch prepares for combining the SCSI command andufshcd_lrbdata structures into a single data structure.Signed-off-by Bart Van Assche <[email protected]>
Quoted 119 lines
--- drivers/ufs/core/ufshcd.c | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
be8fd3b15d5f..ec1c8bdf07e6100644drivers/ufs/core/ufshcd.c +10
-7@@ -2294,19 +2294,20 @@ static inline int ufshcd_monitor_opcode2dir(u8 opcode) /* Must only be called for SCSI commands. */ static inline boolufshcd_should_inform_monitor (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) {const struct ufs_hba_monitor *m = &hba->monitor; +struct request *rq =scsi_cmd_to_rq (cmd); +struct ufshcd_lrb *lrbp = &hba->lrb[rq->tag]; -return (m->enabled && - (!m->chunk_size || m->chunk_size == lrbp->cmd->sdb.length) && -ktime_before (hba->monitor.enabled_ts, lrbp->issue_time_stamp)); +return m->enabled && + (!m->chunk_size || m->chunk_size == cmd->sdb.length) && +ktime_before (hba->monitor.enabled_ts, + lrbp->issue_time_stamp); } -static void ufshcd_start_monitor (struct ufs_hba *hba, -const struct ufshcd_lrb *lrbp) +static void ufshcd_start_monitor (struct ufs_hba *hba,struct scsi_cmnd +*cmd) { -int dir =ufshcd_monitor_opcode2dir (*lrbp->cmd->cmnd); +int dir =ufshcd_monitor_opcode2dir (cmd->cmnd[0 ]);unsigned long flags; spin_lock_irqsave(hba->host->host_lock, flags); @@ -2315,14 +2316,15@@ static void ufshcd_start_monitor(struct
ufs_hba*hba,spin_unlock_irqrestore(hba->host->host_lock, flags); }-static void
ufshcd_update_monitor(struct ufs_hba *hba, const struct ufshcd_lrb *lrbp)drivers/ufs/core/ufshcd.c +10
-6+static void ufshcd_update_monitor (struct ufs_hba *hba,struct scsi_cmnd +*cmd) { -int dir =ufshcd_monitor_opcode2dir (*lrbp->cmd->cmnd); +struct request *req =scsi_cmd_to_rq (cmd); +struct ufshcd_lrb *lrbp = &hba->lrb[req->tag]; +int dir =ufshcd_monitor_opcode2dir (cmd->cmnd[0 ]);unsigned long flags;spin_lock_irqsave (hba->host->host_lock, flags);if (dir >=0 && hba->monitor.nr_queued[dir] >0 ) { -const struct request *req =scsi_cmd_to_rq (lrbp->cmd);struct ufs_hba_monitor *m = &hba->monitor;ktime_t now, inc, lat;@@ -2357,6 +2359,7 @@ static inline void ufshcd_send_command(structufs_hba *hba, struct ufshcd_lrb *lrbp, struct ufs_hw_queue *hwq) { + struct scsi_cmnd *cmd = lrbp->cmd;unsigned long flags;if (hba->monitor.enabled) {@@ -2365,11 +2368,11 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, lrbp->compl_time_stamp =ktime_set (0 ,0 ); lrbp->compl_time_stamp_local_clock =0 ; } -if (lrbp->cmd) { -ufshcd_add_command_trace (hba, lrbp->cmd,UFS_CMD_SEND ); +if (cmd) { +ufshcd_add_command_trace (hba, cmd,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba); -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_start_monitor (hba, lrbp); +if (unlikely (ufshcd_should_inform_monitor (hba, cmd))) +ufshcd_start_monitor (hba, cmd); }if (hba->mcq_enabled) {drivers/ufs/core/ufshcd.c +3
-2@@ -2385,8 +2388,7 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, }else {spin_lock_irqsave (&hba->outstanding_lock, flags);if (hba->vops && hba->vops->setup_xfer_req) - hba->vops->setup_xfer_req (hba, lrbp->task_tag, - !!lrbp->cmd); + hba->vops->setup_xfer_req (hba, lrbp->task_tag, + !!cmd);__set_bit (lrbp->task_tag, &hba->outstanding_reqs);ufshcd_writel (hba,1 << lrbp->task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL); @@ -5620,19 +5622,17 @@ void ufshcd_release_scsi_cmd(struct ufs_hba *hba, voidufshcd_compl_one_cqe(struct
ufs_hba*hba, inttask_tag,struct cq_entry *cqe) {drivers/ufs/core/ufshcd.c +4
-6-struct ufshcd_lrb *lrbp; -struct scsi_cmnd *cmd; +struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; +struct scsi_cmnd *cmd = lrbp->cmd;enum utp_ocs ocs; - lrbp = &hba->lrb[task_tag];if (hba->monitor.enabled) { lrbp->compl_time_stamp =ktime_get (); lrbp->compl_time_stamp_local_clock =local_clock (); } - cmd = lrbp->cmd;if (cmd) { -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_update_monitor (hba, lrbp); +if (unlikely (ufshcd_should_inform_monitor (hba, cmd))) +ufshcd_update_monitor (hba, cmd);ufshcd_add_command_trace (hba, cmd,UFS_CMD_COMP ); cmd->result =ufshcd_transfer_rsp_status (hba, lrbp, cqe);ufshcd_release_scsi_cmd (hba, lrbp);
Bart Van Assche
reviewerPATCH v5 15/28 ufs: core: Rework ufshcd_mcq_compl_pending_transfer()
In reply to Bart Van AsscheReplace a tag loop with blk_mq_tagset_busy_iter(). This patch prepares for removing the hba->lrb[] array.
--- drivers/ufs/core/ufshcd.c | 80 ++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 34 deletions(-)
drivers/ufs/core/ufshcd.c +46 -34
@@ -5717,6 +5717,48 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)return completed_reqs !=0 ; } +static bool ufshcd_mcq_force_compl_one (struct request *rq,void *priv) +{ +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq); +struct scsi_device *sdev = rq->q->queuedata; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +struct ufshcd_lrb *lrbp = &hba->lrb[rq->tag]; +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); + +if (!hwq) +return true; + +ufshcd_mcq_compl_all_cqes_lock (hba, hwq); + +/* +* For those cmds of which the cqes are not present in the cq, complete +* them explicitly. +*/ + scoped_guard(spinlock_irqsave, &hwq->cq_lock) { +if (!test_bit (SCMD_STATE_COMPLETE , &cmd->state)) { +set_host_byte (cmd,DID_REQUEUE ); +ufshcd_release_scsi_cmd (hba, lrbp); +scsi_done (cmd); + } + } + +return true; +} + +static bool ufshcd_mcq_compl_one (struct request *rq,void *priv) +{ +struct scsi_device *sdev = rq->q->queuedata; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); + +if (hwq) +ufshcd_mcq_poll_cqe_lock (hba, hwq); + +return true; +} +/** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_restore()
@@ -5731,40 +5773,10 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)static void ufshcd_mcq_compl_pending_transfer (struct ufs_hba *hba,bool force_compl) { -struct ufs_hw_queue *hwq; -struct ufshcd_lrb *lrbp; -struct scsi_cmnd *cmd; -unsigned long flags; -int tag; - -for (tag =0 ; tag < hba->nutrs; tag++) { - lrbp = &hba->lrb[tag]; - cmd = lrbp->cmd; -if (!ufshcd_cmd_inflight (cmd) || -test_bit (SCMD_STATE_COMPLETE , &cmd->state)) -continue ; - - hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (cmd)); -if (!hwq) -continue ; - -if (force_compl) { -ufshcd_mcq_compl_all_cqes_lock (hba, hwq); -/* -* For those cmds of which the cqes are not present -* in the cq, complete them explicitly. -*/ -spin_lock_irqsave (&hwq->cq_lock, flags); -if (cmd && !test_bit (SCMD_STATE_COMPLETE , &cmd->state)) { -set_host_byte (cmd,DID_REQUEUE ); -ufshcd_release_scsi_cmd (hba, lrbp); -scsi_done (cmd); - } -spin_unlock_irqrestore (&hwq->cq_lock, flags); - }else { -ufshcd_mcq_poll_cqe_lock (hba, hwq); - } - } +blk_mq_tagset_busy_iter (&hba->host->tag_set, + force_compl ? ufshcd_mcq_force_compl_one : + ufshcd_mcq_compl_one, +NULL ); }/**
RE: [PATCH v5 15/28] ufs: core: Rework ufshcd_mcq_compl_pending_transfer()
Quoted 5 lines
Replace a tag loop with
blk_mq_tagset_busy_iter(). This patch prepares for removing the hba->lrb[] array.Signed-off-by Bart Van Assche <[email protected]>
Quoted 102 lines
--- drivers/ufs/core/ufshcd.c | 80 ++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 34 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
ec1c8bdf07e6..eea9e707ab4b100644drivers/ufs/core/ufshcd.c +41
-0@@ -5717,6 +5717,48 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)return completed_reqs !=0 ; } +static bool ufshcd_mcq_force_compl_one (struct request *rq,void *priv) +{ +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq); +struct scsi_device *sdev = rq->q->queuedata; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +struct ufshcd_lrb *lrbp = &hba->lrb[rq->tag]; +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); + +if (!hwq) +return true; + +ufshcd_mcq_compl_all_cqes_lock (hba, hwq); + +/* +* For those cmds of which the cqes are not present in the cq, complete +* them explicitly. +*/ + scoped_guard(spinlock_irqsave, &hwq->cq_lock) { +if (!test_bit (SCMD_STATE_COMPLETE , &cmd->state)) { +set_host_byte (cmd,DID_REQUEUE ); +ufshcd_release_scsi_cmd (hba, lrbp); +scsi_done (cmd); + } + } + +return true; +} + +static bool ufshcd_mcq_compl_one (struct request *rq,void *priv) { +struct scsi_device *sdev = rq->q->queuedata; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); + +if (hwq) +ufshcd_mcq_poll_cqe_lock (hba, hwq); + +return true; +} +/** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_restore() @@ -5731,40 +5773,10 @@ static int ufshcd_poll(struct Scsi_Host *shost,unsigned int
queue_num) static void ufshcd_mcq_compl_pending_transfer(structufs_hba*hba,bool force_compl) {drivers/ufs/core/ufshcd.c +4
-34-struct ufs_hw_queue *hwq; -struct ufshcd_lrb *lrbp; -struct scsi_cmnd *cmd; -unsigned long flags; -int tag; - -for (tag =0 ; tag < hba->nutrs; tag++) { - lrbp = &hba->lrb[tag]; - cmd = lrbp->cmd; -if (!ufshcd_cmd_inflight (cmd) || -test_bit (SCMD_STATE_COMPLETE , &cmd->state)) -continue ; - - hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (cmd)); -if (!hwq) -continue ; - -if (force_compl) { -ufshcd_mcq_compl_all_cqes_lock (hba, hwq); -/* -* For those cmds of which the cqes are not present -* in the cq, complete them explicitly. -*/ -spin_lock_irqsave (&hwq->cq_lock, flags); -if (cmd && !test_bit (SCMD_STATE_COMPLETE , &cmd->state)) { -set_host_byte (cmd,DID_REQUEUE ); -ufshcd_release_scsi_cmd (hba, lrbp); -scsi_done (cmd); - } -spin_unlock_irqrestore (&hwq->cq_lock, flags); - }else { -ufshcd_mcq_poll_cqe_lock (hba, hwq); - } - } +blk_mq_tagset_busy_iter (&hba->host->tag_set, + force_compl ? ufshcd_mcq_force_compl_one : + ufshcd_mcq_compl_one, +NULL ); }/**
Bart Van Assche
reviewerPATCH v5 16/28 ufs: core: Rework ufshcd_eh_device_reset_handler()
In reply to Bart Van AsscheMerge the MCQ mode and legacy mode loops into a single loop. This patch prepares for optimizing the hot path by removing the direct hba->lrb[] accesses from ufshcd_eh_device_reset_handler().
--- drivers/ufs/core/ufshcd.c | 84 ++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 46 deletions(-)
drivers/ufs/core/ufshcd.c +38 -46
@@ -7538,6 +7538,36 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *rreturn err ? : result; } +static bool ufshcd_clear_lu_cmds (struct request *req,void *priv) +{ +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req); +struct scsi_device *sdev = cmd->device; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +const u64 lun = *(u64 *)priv; +const u32 tag = req->tag; + +if (sdev->lun != lun) +return true; + +if (ufshcd_clear_cmd (hba, tag) <0 ) { +dev_err (hba->dev,"%s: failed to clear request %d\n" , __func__, + tag); +return true; + } + +if (hba->mcq_enabled) { +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, req); + +if (hwq) +ufshcd_mcq_poll_cqe_lock (hba, hwq); +return true; + } + +ufshcd_compl_one_cqe (hba, tag,NULL ); +return true; +} +/** * ufshcd_eh_device_reset_handler() - Reset a single logical unit. * @cmd: SCSI command pointer
@@ -7546,12 +7576,8 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r*/ static int ufshcd_eh_device_reset_handler (struct scsi_cmnd *cmd) { -unsigned long flags, pending_reqs =0 , not_cleared =0 ;struct Scsi_Host *host;struct ufs_hba *hba; -struct ufs_hw_queue *hwq; -struct ufshcd_lrb *lrbp; -u32 pos, not_cleared_mask =0 ;int err;u8 resp =0xF , lun;
@@ -7560,50 +7586,16 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lun =ufshcd_scsi_to_upiu_lun (cmd->device->lun); err =ufshcd_issue_tm_cmd (hba, lun,0 ,UFS_LOGICAL_RESET , &resp); -if (err || resp !=UPIU_TASK_MANAGEMENT_FUNC_COMPL ) { -if (!err) - err = resp; - goto out; - } - -if (hba->mcq_enabled) { -for (pos =0 ; pos < hba->nutrs; pos++) { - lrbp = &hba->lrb[pos]; -if (ufshcd_cmd_inflight (lrbp->cmd) && - lrbp->lun == lun) { -ufshcd_clear_cmd (hba, pos); - hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (lrbp->cmd)); -ufshcd_mcq_poll_cqe_lock (hba, hwq); - } - } - err =0 ; - goto out; - } - -/* clear the commands that were pending for corresponding LUN */ -spin_lock_irqsave (&hba->outstanding_lock, flags); -for_each_set_bit (pos, &hba->outstanding_reqs, hba->nutrs) -if (hba->lrb[pos].lun == lun) -__set_bit (pos, &pending_reqs); - hba->outstanding_reqs &= ~pending_reqs; -spin_unlock_irqrestore (&hba->outstanding_lock, flags); - -for_each_set_bit (pos, &pending_reqs, hba->nutrs) { -if (ufshcd_clear_cmd (hba, pos) <0 ) { -spin_lock_irqsave (&hba->outstanding_lock, flags); - not_cleared =1U << pos & -ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); - hba->outstanding_reqs |= not_cleared; - not_cleared_mask |= not_cleared; -spin_unlock_irqrestore (&hba->outstanding_lock, flags); - -dev_err (hba->dev,"%s: failed to clear request %d\n" , - __func__, pos); - } +if (err) { + }else if (resp !=UPIU_TASK_MANAGEMENT_FUNC_COMPL ) { + err = resp; + }else { +/* clear the commands that were pending for corresponding LUN */ +blk_mq_tagset_busy_iter (&hba->host->tag_set, + ufshcd_clear_lu_cmds, + &cmd->device->lun); } -__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask); -out: hba->req_abort_count =0 ;ufshcd_update_evt_hist (hba,UFS_EVT_DEV_RESET , (u32 )err);if (!err) {
RE: [PATCH v5 16/28] ufs: core: Rework ufshcd_eh_device_reset_handler()
Quoted 5 lines
Merge the MCQ mode and legacy mode loops into a single loop. This patch prepares for optimizing the hot path by removing the direct hba->lrb[] accesses from
ufshcd_eh_device_reset_handler().Signed-off-by Bart Van Assche <[email protected]>
Quoted 120 lines
--- drivers/ufs/core/ufshcd.c | 84 ++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 46 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
eea9e707ab4b..67607f2d10a2100644drivers/ufs/core/ufshcd.c +0
-0@@ -7538,6 +7538,36 @@ int ufshcd_advanced_rpmb_req_handler(struct
ufs_hba*hba, structutp_upiu_req*rreturn err ? : result;}
drivers/ufs/core/ufshcd.c +30
-0+static bool ufshcd_clear_lu_cmds (struct request *req,void *priv) { +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req); +struct scsi_device *sdev = cmd->device; +struct Scsi_Host *shost = sdev->host; +struct ufs_hba *hba =shost_priv (shost); +const u64 lun = *(u64 *)priv; +const u32 tag = req->tag; + +if (sdev->lun != lun) +return true; + +if (ufshcd_clear_cmd (hba, tag) <0 ) { +dev_err (hba->dev,"%s: failed to clear request %d\n" , __func__, + tag); +return true; + } + +if (hba->mcq_enabled) { +struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, + req); + +if (hwq) +ufshcd_mcq_poll_cqe_lock (hba, hwq); +return true; + } + +ufshcd_compl_one_cqe (hba, tag,NULL ); +return true; +} +/** * ufshcd_eh_device_reset_handler() - Reset a single logical unit. * @cmd: SCSI command pointer @@ -7546,12 +7576,8 @@ int ufshcd_advanced_rpmb_req_handler(struct
ufs_hba*hba, structutp_upiu_req*r
*/
static intufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd){drivers/ufs/core/ufshcd.c +8
-46-unsigned long flags, pending_reqs =0 , not_cleared =0 ;struct Scsi_Host *host;struct ufs_hba *hba; -struct ufs_hw_queue *hwq; -struct ufshcd_lrb *lrbp; -u32 pos, not_cleared_mask =0 ;int err;u8 resp =0xF , lun;@@ -7560,50 +7586,16 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) lun =ufshcd_scsi_to_upiu_lun (cmd->device->lun); err =ufshcd_issue_tm_cmd (hba, lun,0 ,UFS_LOGICAL_RESET , &resp); -if (err || resp !=UPIU_TASK_MANAGEMENT_FUNC_COMPL ) { -if (!err) - err = resp; - goto out; - } - -if (hba->mcq_enabled) { -for (pos =0 ; pos < hba->nutrs; pos++) { - lrbp = &hba->lrb[pos]; -if (ufshcd_cmd_inflight (lrbp->cmd) && - lrbp->lun == lun) { -ufshcd_clear_cmd (hba, pos); - hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (lrbp- >cmd)); -ufshcd_mcq_poll_cqe_lock (hba, hwq); - } - } - err =0 ; - goto out; - } - -/* clear the commands that were pending for corresponding LUN */ -spin_lock_irqsave (&hba->outstanding_lock, flags); -for_each_set_bit (pos, &hba->outstanding_reqs, hba->nutrs) -if (hba->lrb[pos].lun == lun) -__set_bit (pos, &pending_reqs); - hba->outstanding_reqs &= ~pending_reqs; -spin_unlock_irqrestore (&hba->outstanding_lock, flags); - -for_each_set_bit (pos, &pending_reqs, hba->nutrs) { -if (ufshcd_clear_cmd (hba, pos) <0 ) { -spin_lock_irqsave (&hba->outstanding_lock, flags); - not_cleared =1U << pos & -ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); - hba->outstanding_reqs |= not_cleared; - not_cleared_mask |= not_cleared; -spin_unlock_irqrestore (&hba->outstanding_lock, flags); - -dev_err (hba->dev,"%s: failed to clear request %d\n" , - __func__, pos); - } +if (err) { + }else if (resp !=UPIU_TASK_MANAGEMENT_FUNC_COMPL ) { + err = resp; + }else { +/* clear the commands that were pending for corresponding LUN */ +blk_mq_tagset_busy_iter (&hba->host->tag_set, + ufshcd_clear_lu_cmds, + &cmd->device->lun); } -__ufshcd_transfer_req_compl (hba, pending_reqs & ~not_cleared_mask); -out: hba->req_abort_count =0 ;ufshcd_update_evt_hist(hba, UFS_EVT_DEV_RESET, (u32)err); if (!err) {
Bart Van Assche
reviewerPATCH v5 17/28 ufs: core: Rework the SCSI host queue depth calculation code
In reply to Bart Van AsschePrepare for allocating the SCSI host earlier by making the SCSI host queue depth independent of the queue depth supported by the UFS device. This patch may increase the queue depth of the UFS SCSI host.
--- drivers/ufs/core/ufs-mcq.c | 20 +++++--------------- drivers/ufs/core/ufshcd-priv.h | 2 +- drivers/ufs/core/ufshcd.c | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 18 deletions(-)
drivers/ufs/core/ufs-mcq.c +5 -15
@@ -130,17 +130,15 @@ unsigned int ufshcd_mcq_queue_cfg_addr(struct ufs_hba *hba)EXPORT_SYMBOL_GPL (ufshcd_mcq_queue_cfg_addr);/** -* ufshcd_mcq_decide_queue_depth - decide the queue depth +* ufshcd_get_hba_mac - Maximum number of commands supported by the host +* controller. * @hba: per adapter instance * -* Return: queue-depth on success, non-zero on error +* Return: queue depth on success; negative upon error. * -* MAC - Max. Active Command of the Host Controller (HC) -* HC wouldn't send more than this commands to the device. -* Calculates and adjusts the queue depth based on the depth -* supported by the HC and ufs device. +* MAC = Maximum number of Active Commands supported by the Host Controller. */ -int ufshcd_mcq_decide_queue_depth (struct ufs_hba *hba) +int ufshcd_get_hba_mac (struct ufs_hba *hba) {int mac;
@@ -160,14 +158,6 @@ int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba)if (mac <0 ) goto err; -WARN_ON_ONCE (!hba->dev_info.bqueuedepth); -/* -* max. value of bqueuedepth = 256, mac is host dependent. -* It is mandatory for UFS device to define bQueueDepth if -* shared queuing architecture is enabled. -*/ -return min_t (int, mac, hba->dev_info.bqueuedepth); - err:dev_err (hba->dev,"Failed to get mac, err=%d\n" , mac);return mac;
drivers/ufs/core/ufshcd-priv.h +1 -1
@@ -65,7 +65,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, struct cq_entry *cqe);int ufshcd_mcq_init (struct ufs_hba *hba);void ufshcd_mcq_disable (struct ufs_hba *hba); -int ufshcd_mcq_decide_queue_depth (struct ufs_hba *hba); +int ufshcd_get_hba_mac (struct ufs_hba *hba);int ufshcd_mcq_memory_alloc (struct ufs_hba *hba);struct ufs_hw_queue *ufshcd_mcq_req_to_hwq (struct ufs_hba *hba,struct request *req);
drivers/ufs/core/ufshcd.c +15 -2
@@ -8438,10 +8438,11 @@ static void ufs_init_rtc(struct ufs_hba *hba, u8 *desc_buf)static int ufs_get_device_desc (struct ufs_hba *hba) { +struct ufs_dev_info *dev_info = &hba->dev_info; +struct Scsi_Host *shost = hba->host;int err;u8 model_index;u8 *desc_buf; -struct ufs_dev_info *dev_info = &hba->dev_info; desc_buf =kzalloc (QUERY_DESC_MAX_SIZE ,GFP_KERNEL );if (!desc_buf) {
@@ -8469,6 +8470,18 @@ static int ufs_get_device_desc(struct ufs_hba *hba) desc_buf[DEVICE_DESC_PARAM_SPEC_VER +1 ]; dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH ]; +/* +* According to the UFS standard, the UFS device queue depth +* (bQueueDepth) must be in the range 1..255 if the shared queueing +* architecture is supported. bQueueDepth is zero if the shared queueing +* architecture is not supported. +*/ +if (dev_info->bqueuedepth) + shost->cmd_per_lun =min (hba->nutrs, dev_info->bqueuedepth) - +UFSHCD_NUM_RESERVED ; +else + shost->cmd_per_lun = shost->can_queue; + dev_info->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP ]; dev_info->hid_sup = get_unaligned_be32(desc_buf +
@@ -8875,7 +8888,7 @@ static int ufshcd_alloc_mcq(struct ufs_hba *hba)int ret;int old_nutrs = hba->nutrs; - ret =ufshcd_mcq_decide_queue_depth (hba); + ret =ufshcd_get_hba_mac (hba);if (ret <0 )return ret;
Bart Van Assche
reviewerPATCH v5 18/28 ufs: core: Allocate the SCSI host earlier
In reply to Bart Van AsscheCall ufshcd_add_scsi_host() before any UPIU commands are sent to the UFS device. This patch prepares for letting ufshcd_add_scsi_host() allocate memory for both SCSI and UPIU commands.
--- drivers/ufs/core/ufshcd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +12 -5
@@ -10581,6 +10581,9 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) {int err; +WARN_ON_ONCE (!hba->host->can_queue); +WARN_ON_ONCE (!hba->host->cmd_per_lun); +if (is_mcq_supported (hba)) {ufshcd_mcq_enable (hba); err =ufshcd_alloc_mcq (hba);
@@ -10731,7 +10734,11 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)ufshcd_host_memory_configure (hba); host->can_queue = hba->nutrs -UFSHCD_NUM_RESERVED ; - host->cmd_per_lun = hba->nutrs -UFSHCD_NUM_RESERVED ; +/* +* Set the queue depth for WLUNs. ufs_get_device_desc() will increase +* host->cmd_per_lun to a larger value. +*/ + host->cmd_per_lun =1 ; host->max_id =UFSHCD_MAX_ID ; host->max_lun =UFS_MAX_LUNS ; host->max_channel =UFSHCD_MAX_CHANNEL ;
@@ -10822,6 +10829,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)FIELD_PREP (UFSHCI_AHIBERN8_SCALE_MASK ,3 ); } + err =ufshcd_add_scsi_host (hba); +if (err) + goto out_disable; +/* Hold auto suspend until async scan completes */ pm_runtime_get_sync (dev);
@@ -10872,10 +10883,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)if (err) goto out_disable; - err =ufshcd_add_scsi_host (hba); -if (err) - goto out_disable; -async_schedule (ufshcd_async_scan, hba);ufs_sysfs_add_nodes (hba->dev);
Bart Van Assche
reviewerPATCH v5 19/28 ufs: core: Call ufshcd_init_lrb() later
In reply to Bart Van AsscheCall ufshcd_init_lrb() from inside ufshcd_setup_dev_cmd() instead of ufshcd_host_memory_configure(). This patch prepares for calling ufshcd_host_memory_configure() before the information is available that is required to call ufshcd_setup_dev_cmd().
--- drivers/ufs/core/ufshcd.c | 53 ++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
drivers/ufs/core/ufshcd.c +27 -26
@@ -2903,8 +2903,32 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); } -static void __ufshcd_setup_cmd (struct ufshcd_lrb *lrbp,struct scsi_cmnd *cmd,u8 lun,int tag) +static void ufshcd_init_lrb (struct ufs_hba *hba,struct ufshcd_lrb *lrb,int i) +{ +struct utp_transfer_cmd_desc *cmd_descp = + (void *)hba->ucdl_base_addr + i *ufshcd_get_ucd_size (hba); +struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; +dma_addr_t cmd_desc_element_addr = + hba->ucdl_dma_addr + i *ufshcd_get_ucd_size (hba); +u16 response_offset =le16_to_cpu (utrdlp[i].response_upiu_offset); +u16 prdt_offset =le16_to_cpu (utrdlp[i].prd_table_offset); + + lrb->utr_descriptor_ptr = utrdlp + i; + lrb->utrd_dma_addr = + hba->utrdl_dma_addr + i *sizeof (struct utp_transfer_req_desc ); + lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; + lrb->ucd_req_dma_addr = cmd_desc_element_addr; + lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; + lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; + lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; + lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; +} + +static void __ufshcd_setup_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp, +struct scsi_cmnd *cmd,u8 lun,int tag) { +ufshcd_init_lrb (hba, lrbp, tag); +memset (lrbp->ucd_req_ptr,0 ,sizeof (*lrbp->ucd_req_ptr)); lrbp->cmd = cmd;
@@ -2916,7 +2940,7 @@ static void __ufshcd_setup_cmd(struct ufshcd_lrb *lrbp, struct scsi_cmnd *cmd, ustatic void ufshcd_setup_scsi_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp,struct scsi_cmnd *cmd,u8 lun,int tag) { -__ufshcd_setup_cmd (lrbp, cmd, lun, tag); +__ufshcd_setup_cmd (hba, lrbp, cmd, lun, tag); lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed (hba); lrbp->req_abort_skip = false;
@@ -2971,27 +2995,6 @@ static void ufshcd_map_queues(struct Scsi_Host *shost) } } -static void ufshcd_init_lrb (struct ufs_hba *hba,struct ufshcd_lrb *lrb,int i) -{ -struct utp_transfer_cmd_desc *cmd_descp = (void *)hba->ucdl_base_addr + - i *ufshcd_get_ucd_size (hba); -struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; -dma_addr_t cmd_desc_element_addr = hba->ucdl_dma_addr + - i *ufshcd_get_ucd_size (hba); -u16 response_offset =le16_to_cpu (utrdlp[i].response_upiu_offset); -u16 prdt_offset =le16_to_cpu (utrdlp[i].prd_table_offset); - - lrb->utr_descriptor_ptr = utrdlp + i; - lrb->utrd_dma_addr = hba->utrdl_dma_addr + - i *sizeof (struct utp_transfer_req_desc ); - lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; - lrb->ucd_req_dma_addr = cmd_desc_element_addr; - lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; - lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; - lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; - lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; -} -/** * ufshcd_queuecommand - main entry point for SCSI requests * @host: SCSI host pointer
@@ -3084,7 +3087,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)static void ufshcd_setup_dev_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp,enum dev_cmd_type cmd_type,u8 lun,int tag) { -__ufshcd_setup_cmd (lrbp,NULL , lun, tag); +__ufshcd_setup_cmd (hba, lrbp,NULL , lun, tag); lrbp->intr_cmd = true;/* No interrupt aggregation */ hba->dev_cmd.type = cmd_type; }
@@ -4042,8 +4045,6 @@ static void ufshcd_host_memory_configure(struct ufs_hba *hba) utrdlp[i].response_upiu_length =cpu_to_le16 (ALIGNED_UPIU_SIZE >>2 ); } - -ufshcd_init_lrb (hba, &hba->lrb[i], i); } }
RE: [PATCH v5 19/28] ufs: core: Call ufshcd_init_lrb() later
Quoted 7 lines
Call
ufshcd_init_lrb()from insideufshcd_setup_dev_cmd()instead ofufshcd_host_memory_configure(). This patch prepares for callingufshcd_host_memory_configure()before the information is available that is required to callufshcd_setup_dev_cmd().Signed-off-by Bart Van Assche <[email protected]>
Quoted 99 lines
--- drivers/ufs/core/ufshcd.c | 53 ++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
7ea18204b5fb..bb14af688e98100644drivers/ufs/core/ufshcd.c +25
-4@@ -2903,8 +2903,32 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); } -static void __ufshcd_setup_cmd (struct ufshcd_lrb *lrbp,struct scsi_cmnd *cmd, u8 lun, int tag) +static void ufshcd_init_lrb (struct ufs_hba *hba,struct ufshcd_lrb +*lrb,int i) { +struct utp_transfer_cmd_desc *cmd_descp = + (void *)hba->ucdl_base_addr + i *ufshcd_get_ucd_size (hba); +struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; +dma_addr_t cmd_desc_element_addr = + hba->ucdl_dma_addr + i *ufshcd_get_ucd_size (hba); +u16 response_offset =le16_to_cpu (utrdlp[i].response_upiu_offset); +u16 prdt_offset =le16_to_cpu (utrdlp[i].prd_table_offset); + + lrb->utr_descriptor_ptr = utrdlp + i; + lrb->utrd_dma_addr = + hba->utrdl_dma_addr + i *sizeof (struct utp_transfer_req_desc ); + lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; + lrb->ucd_req_dma_addr = cmd_desc_element_addr; + lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; + lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; + lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; + lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; } + +static void __ufshcd_setup_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp, +struct scsi_cmnd *cmd,u8 lun,int tag) { +ufshcd_init_lrb (hba, lrbp, tag); +memset (lrbp->ucd_req_ptr,0 ,sizeof (*lrbp->ucd_req_ptr)); lrbp->cmd = cmd;@@ -2916,7 +2940,7 @@ static void __ufshcd_setup_cmd(struct ufshcd_lrb *lrbp, struct scsi_cmnd *cmd, u static void ufshcd_setup_scsi_cmd(structufs_hba *hba,struct ufshcd_lrb *lrbp,struct scsi_cmnd *cmd,u8 lun,int tag) { -__ufshcd_setup_cmd (lrbp, cmd, lun, tag); +__ufshcd_setup_cmd (hba, lrbp, cmd, lun, tag); lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed (hba); lrbp->req_abort_skip = false;@@ -2971,27 +2995,6 @@ static void ufshcd_map_queues(struct Scsi_Host *shost) } } -static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) -{ - struct utp_transfer_cmd_desc *cmd_descp = (void *)hba-Quoted 1 line
ucdl_base_addr+drivers/ufs/core/ufshcd.c +1
-21-i *ufshcd_get_ucd_size (hba ); -struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; -dma_addr_t cmd_desc_element_addr = hba->ucdl_dma_addr + - i *ufshcd_get_ucd_size (hba); -u16 response_offset =le16_to_cpu (utrdlp[i].response_upiu_offset); -u16 prdt_offset =le16_to_cpu (utrdlp[i].prd_table_offset); - - lrb->utr_descriptor_ptr = utrdlp + i; - lrb->utrd_dma_addr = hba->utrdl_dma_addr + - i *sizeof (struct utp_transfer_req_desc ); - lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; - lrb->ucd_req_dma_addr = cmd_desc_element_addr; - lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; - lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; - lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; - lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; -} -/** * ufshcd_queuecommand - main entry point for SCSI requests * @host: SCSI host pointer @@ -3084,7 +3087,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) static void ufshcd_setup_dev_cmd(structufs_hba *hba,struct ufshcd_lrb *lrbp,enum dev_cmd_type cmd_type,u8 lun,int tag) { -__ufshcd_setup_cmd (lrbp,NULL , lun, tag); +__ufshcd_setup_cmd (hba, lrbp,NULL , lun, tag); lrbp->intr_cmd = true;/* No interrupt aggregation */ hba->dev_cmd.type = cmd_type; }@@ -4042,8 +4045,6 @@ static void ufshcd_host_memory_configure(struct ufs_hba *hba) utrdlp[i].response_upiu_length =cpu_to_le16 (ALIGNED_UPIU_SIZE >>2 ); } - -ufshcd_init_lrb (hba, &hba->lrb[i], i); } }
Bart Van Assche
reviewerPATCH v5 20/28 ufs: core: Use hba->reserved_slot
In reply to Bart Van AsscheUse hba->reserved_slot instead of open-coding it. This patch prepares for changing the value of hba->reserved_slot.
--- drivers/ufs/core/ufs-mcq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufs-mcq.c +1 -1
@@ -536,7 +536,7 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)if (hba->quirks &UFSHCD_QUIRK_MCQ_BROKEN_RTC )return -ETIMEDOUT ; -if (task_tag != hba->nutrs -UFSHCD_NUM_RESERVED ) { +if (task_tag != hba->reserved_slot) {if (!cmd)return -EINVAL ; hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (cmd));
Bart Van Assche
reviewerPATCH v5 21/28 ufs: core: Make the reserved slot a reserved request
In reply to Bart Van AsscheInstead of letting the SCSI core allocate hba->nutrs - 1 commands, let the SCSI core allocate hba->nutrs commands, set the number of reserved tags to 1 and use the reserved tag for device management commands. This patch changes the 'reserved slot' from hba->nutrs - 1 into 0 because the block layer reserves the smallest tags for reserved commands.
--- drivers/ufs/core/ufshcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +2 -2
@@ -2475,7 +2475,7 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba) hba->nutrs = (hba->capabilities &MASK_TRANSFER_REQUESTS_SLOTS_SDB ) +1 ; hba->nutmrs = ((hba->capabilities &MASK_TASK_MANAGEMENT_REQUEST_SLOTS ) >>16 ) +1 ; - hba->reserved_slot = hba->nutrs -1 ; + hba->reserved_slot =0 ; hba->nortt =FIELD_GET (MASK_NUMBER_OUTSTANDING_RTT , hba->capabilities) +1 ;
@@ -8915,7 +8915,6 @@ static int ufshcd_alloc_mcq(struct ufs_hba *hba) goto err; hba->host->can_queue = hba->nutrs -UFSHCD_NUM_RESERVED ; - hba->reserved_slot = hba->nutrs -UFSHCD_NUM_RESERVED ;return 0 ; err:
@@ -10740,6 +10739,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)* host->cmd_per_lun to a larger value. */ host->cmd_per_lun =1 ; + host->nr_reserved_cmds =UFSHCD_NUM_RESERVED ; host->max_id =UFSHCD_MAX_ID ; host->max_lun =UFS_MAX_LUNS ; host->max_channel =UFSHCD_MAX_CHANNEL ;
Bart Van Assche
reviewerPATCH v5 22/28 ufs: core: Do not clear driver-private command data
In reply to Bart Van AsscheTell the SCSI core to skip the memset() call that clears driver-private data because __ufshcd_setup_cmd() performs all necessary initialization.
--- drivers/ufs/core/ufshcd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/ufs/core/ufshcd.c +10 -0
@@ -2995,6 +2995,15 @@ static void ufshcd_map_queues(struct Scsi_Host *shost) } } +/* +* The only purpose of this function is to make the SCSI core skip the memset() +* call for the private command data. +*/ +static int ufshcd_init_cmd_priv (struct Scsi_Host *host,struct scsi_cmnd *cmd) +{ +return 0 ; +} +/** * ufshcd_queuecommand - main entry point for SCSI requests * @host: SCSI host pointer
@@ -9157,6 +9166,7 @@ static const struct scsi_host_template ufshcd_driver_template = { .name = UFSHCD, .proc_name = UFSHCD, .map_queues = ufshcd_map_queues, + .init_cmd_priv = ufshcd_init_cmd_priv, .queuecommand = ufshcd_queuecommand, .mq_poll = ufshcd_poll, .sdev_init = ufshcd_sdev_init,
Bart Van Assche
reviewerPATCH v5 23/28 ufs: core: Optimize the hot path
In reply to Bart Van AsscheSet .cmd_size in the SCSI host template such that the SCSI core makes struct scsi_cmnd and struct ufshcd_lrb adjacent. Convert the cmd->lrbp and lrbp->cmd memory loads into pointer offset calculations. Remove the data structure members that became superfluous, namely ufshcd_lrb.cmd and ufs_hba.lrb.
--- drivers/ufs/core/ufs-mcq.c | 9 +- drivers/ufs/core/ufshcd-crypto.h | 18 ++- drivers/ufs/core/ufshcd-priv.h | 41 +++++- drivers/ufs/core/ufshcd.c | 232 ++++++++++++++++--------------- include/ufs/ufshcd.h | 5 - 5 files changed, 177 insertions(+), 128 deletions(-)
drivers/ufs/core/ufs-mcq.c +5 -4
@@ -526,8 +526,8 @@ static int ufshcd_mcq_sq_start(struct ufs_hba *hba, struct ufs_hw_queue *hwq)*/ int ufshcd_mcq_sq_cleanup (struct ufs_hba *hba,int task_tag) { -struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; -struct scsi_cmnd *cmd = lrbp->cmd; +struct scsi_cmnd *cmd =ufshcd_tag_to_cmd (hba, task_tag); +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct ufs_hw_queue *hwq;void __iomem *reg, *opr_sqd_base;u32 nexus, id, val;
@@ -612,7 +612,8 @@ static void ufshcd_mcq_nullify_sqe(struct utp_transfer_req_desc *utrd)static bool ufshcd_mcq_sqe_search (struct ufs_hba *hba,struct ufs_hw_queue *hwq,int task_tag) { -struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; +struct scsi_cmnd *cmd =ufshcd_tag_to_cmd (hba, task_tag); +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct utp_transfer_req_desc *utrd;__le64 cmd_desc_base_addr;bool ret = false;
@@ -663,7 +664,7 @@ int ufshcd_mcq_abort(struct scsi_cmnd *cmd)struct Scsi_Host *host = cmd->device->host;struct ufs_hba *hba =shost_priv (host);int tag =scsi_cmd_to_rq (cmd)->tag; -struct ufshcd_lrb *lrbp = &hba->lrb[tag]; +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct ufs_hw_queue *hwq;int err;
drivers/ufs/core/ufshcd-crypto.h +11 -7
@@ -38,10 +38,10 @@ ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, }static inline int ufshcd_crypto_fill_prdt (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) { -struct scsi_cmnd *cmd = lrbp->cmd;const struct bio_crypt_ctx *crypt_ctx =scsi_cmd_to_rq (cmd)->crypt_ctx; +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);if (crypt_ctx && hba->vops && hba->vops->fill_crypto_prdt) return hba->vops->fill_crypto_prdt(hba, crypt_ctx,
@@ -51,17 +51,19 @@ static inline int ufshcd_crypto_fill_prdt(struct ufs_hba *hba, }static inline void ufshcd_crypto_clear_prdt (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) { +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); +if (!(hba->quirks &UFSHCD_QUIRK_KEYS_IN_PRDT ))return ; -if (!(scsi_cmd_to_rq (lrbp->cmd)->crypt_ctx)) +if (!(scsi_cmd_to_rq (cmd)->crypt_ctx))return ;/* Zeroize the PRDT because it can contain cryptographic keys. */ memzero_explicit (lrbp->ucd_prdt_ptr, -ufshcd_sg_entry_size (hba) *scsi_sg_count (lrbp->cmd)); +ufshcd_sg_entry_size (hba) *scsi_sg_count (cmd)); }bool ufshcd_crypto_enable (struct ufs_hba *hba);
@@ -82,13 +84,15 @@ ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, struct request_desc_header *h) { }static inline int ufshcd_crypto_fill_prdt (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) {return 0 ; }static inline void ufshcd_crypto_clear_prdt (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) { } +struct scsi_cmnd *cmd) +{ +}static inline bool ufshcd_crypto_enable (struct ufs_hba *hba) {
drivers/ufs/core/ufshcd-priv.h +39 -2
53 lines not on this page · raw message
drivers/ufs/core/ufshcd.c +122 -110
631 lines not on this page · raw message
include/ufs/ufshcd.h +0 -5
@@ -161,7 +161,6 @@ struct ufs_pm_lvl_states {* @ucd_prdt_dma_addr: PRDT dma address for debug * @ucd_rsp_dma_addr: UPIU response dma address for debug * @ucd_req_dma_addr: UPIU request dma address for debug -* @cmd: pointer to SCSI command * @scsi_status: SCSI status of the command * @command_type: SCSI, UFS, Query. * @task_tag: Task tag of the command
@@ -186,7 +185,6 @@ struct ufshcd_lrb {dma_addr_t ucd_rsp_dma_addr;dma_addr_t ucd_prdt_dma_addr; -struct scsi_cmnd *cmd;int scsi_status;int command_type;
@@ -833,7 +831,6 @@ enum ufshcd_mcq_opr {* @spm_lvl: desired UFS power management level during system PM. * @pm_op_in_progress: whether or not a PM operation is in progress. * @ahit: value of Auto-Hibernate Idle Timer register. -* @lrb: local reference block * @outstanding_tasks: Bits representing outstanding task requests * @outstanding_lock: Protects @outstanding_reqs. * @outstanding_reqs: Bits representing outstanding transfer requests
@@ -975,8 +972,6 @@ struct ufs_hba {/* Auto-Hibernate Idle Timer register value */ u32 ahit; -struct ufshcd_lrb *lrb; -unsigned long outstanding_tasks;spinlock_t outstanding_lock;unsigned long outstanding_reqs;
Bart Van Assche
reviewerPATCH v5 24/28 ufs: core: Pass a SCSI pointer instead of an LRB pointer
In reply to Bart Van AsschePass a pointer to a SCSI command between functions instead of an LRB pointer. This change prepares for removing the ufshcd_lrb task_tag member.
--- drivers/ufs/core/ufshcd.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/ufs/core/ufshcd.c +11 -10
@@ -2821,12 +2821,13 @@ static void ufshcd_prepare_utp_scsi_cmd_upiu(struct scsi_cmnd *cmd,/** * ufshcd_prepare_utp_query_req_upiu() - fill the utp_transfer_req_desc for query request * @hba: UFS hba -* @lrbp: local reference block pointer +* @cmd: SCSI command pointer * @upiu_flags: flags */ static void ufshcd_prepare_utp_query_req_upiu (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp,u8 upiu_flags) +struct scsi_cmnd *cmd,u8 upiu_flags) { +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr;struct ufs_query *query = &hba->dev_cmd.query;u16 len =be16_to_cpu (query->request.upiu_req.length);
@@ -2855,8 +2856,9 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba,memcpy (ucd_req_ptr +1 , query->descriptor, len); } -static inline void ufshcd_prepare_utp_nop_upiu (struct ufshcd_lrb *lrbp) +static inline void ufshcd_prepare_utp_nop_upiu (struct scsi_cmnd *cmd) { +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr;memset (ucd_req_ptr,0 ,sizeof (struct utp_upiu_req ));
@@ -2871,22 +2873,23 @@ static inline void ufshcd_prepare_utp_nop_upiu(struct ufshcd_lrb *lrbp)* ufshcd_compose_devman_upiu - UFS Protocol Information Unit(UPIU) * for Device Management Purposes * @hba: per adapter instance -* @lrbp: pointer to local reference block +* @cmd: SCSI command pointer * * Return: 0 upon success; < 0 upon failure. */ static int ufshcd_compose_devman_upiu (struct ufs_hba *hba, -struct ufshcd_lrb *lrbp) +struct scsi_cmnd *cmd) { +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);u8 upiu_flags;int ret =0 ;ufshcd_prepare_req_desc_hdr (hba, lrbp, &upiu_flags,DMA_NONE ,0 );if (hba->dev_cmd.type ==DEV_CMD_TYPE_QUERY ) -ufshcd_prepare_utp_query_req_upiu (hba, lrbp, upiu_flags); +ufshcd_prepare_utp_query_req_upiu (hba, cmd, upiu_flags);else if (hba->dev_cmd.type ==DEV_CMD_TYPE_NOP ) -ufshcd_prepare_utp_nop_upiu (lrbp); +ufshcd_prepare_utp_nop_upiu (cmd);else ret = -EINVAL ;
@@ -3124,11 +3127,9 @@ static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd,static int ufshcd_compose_dev_cmd (struct ufs_hba *hba,struct scsi_cmnd *cmd,enum dev_cmd_type cmd_type,int tag) { -struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); -ufshcd_setup_dev_cmd (hba, cmd, cmd_type,0 , tag); -return ufshcd_compose_devman_upiu (hba, lrbp); +return ufshcd_compose_devman_upiu (hba, cmd); }/*
Bart Van Assche
reviewerPATCH v5 25/28 ufs: core: Remove the ufshcd_lrb task_tag member
In reply to Bart Van AsscheRemove the ufshcd_lrb task_tag member and use scsi_cmd_to_rq(cmd)->tag instead. Use rq->tag instead of lrbp->task_tag. This patch reduces the size of struct ufshcd_lrb.
--- drivers/ufs/core/ufshcd.c | 62 +++++++++++++++++++-------------------- include/ufs/ufshcd.h | 1 - 2 files changed, 30 insertions(+), 33 deletions(-)
drivers/ufs/core/ufshcd.c +30 -32
@@ -604,7 +604,7 @@ static void ufshcd_print_tr(struct ufs_hba *hba, struct scsi_cmnd *cmd, bool pr_prdt) {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); -const int tag = lrbp->task_tag; +const int tag =scsi_cmd_to_rq (cmd)->tag;int prdt_length;if (hba->monitor.enabled) {
@@ -2368,6 +2368,7 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, struct ufs_hw_queue *hwq) {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); +const int tag =scsi_cmd_to_rq (cmd)->tag;unsigned long flags;if (hba->monitor.enabled) {
@@ -2396,11 +2397,10 @@ static inline void ufshcd_send_command(struct ufs_hba *hba, }else {spin_lock_irqsave (&hba->outstanding_lock, flags);if (hba->vops && hba->vops->setup_xfer_req) - hba->vops->setup_xfer_req (hba, lrbp->task_tag, + hba->vops->setup_xfer_req (hba, tag,ufshcd_is_scsi_cmd (cmd)); -__set_bit (lrbp->task_tag, &hba->outstanding_reqs); -ufshcd_writel (hba,1 << lrbp->task_tag, -REG_UTP_TRANSFER_REQ_DOOR_BELL ); +__set_bit (tag, &hba->outstanding_reqs); +ufshcd_writel (hba,1 << tag,REG_UTP_TRANSFER_REQ_DOOR_BELL );spin_unlock_irqrestore (&hba->outstanding_lock, flags); } }
@@ -2797,6 +2797,7 @@ static void ufshcd_prepare_utp_scsi_cmd_upiu(struct scsi_cmnd *cmd, u8 upiu_flags) {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); +const int tag =scsi_cmd_to_rq (cmd)->tag;struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr;unsigned short cdb_len;
@@ -2804,11 +2805,11 @@ static void ufshcd_prepare_utp_scsi_cmd_upiu(struct scsi_cmnd *cmd, .transaction_code = UPIU_TRANSACTION_COMMAND, .flags = upiu_flags, .lun = lrbp->lun, - .task_tag = lrbp->task_tag, + .task_tag = tag, .command_set_type = UPIU_COMMAND_SET_TYPE_SCSI, }; -WARN_ON_ONCE (ucd_req_ptr->header.task_tag != lrbp->task_tag); +WARN_ON_ONCE (ucd_req_ptr->header.task_tag != tag); ucd_req_ptr->sc.exp_data_transfer_len =cpu_to_be32 (cmd->sdb.length);
@@ -2829,6 +2830,7 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; +const int tag =scsi_cmd_to_rq (cmd)->tag;struct ufs_query *query = &hba->dev_cmd.query;u16 len =be16_to_cpu (query->request.upiu_req.length);
@@ -2837,7 +2839,7 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, .transaction_code = UPIU_TRANSACTION_QUERY_REQ, .flags = upiu_flags, .lun = lrbp->lun, - .task_tag = lrbp->task_tag, + .task_tag = tag, .query_function = query->request.query_func,/* Data segment length only need for WRITE_DESC */ .data_segment_length =
@@ -2860,12 +2862,13 @@ static inline void ufshcd_prepare_utp_nop_upiu(struct scsi_cmnd *cmd) {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; +const int tag =scsi_cmd_to_rq (cmd)->tag;memset (ucd_req_ptr,0 ,sizeof (struct utp_upiu_req )); ucd_req_ptr->header = (struct utp_upiu_header ){ .transaction_code =UPIU_TRANSACTION_NOP_OUT , - .task_tag = lrbp->task_tag, + .task_tag = tag, }; }
@@ -2950,7 +2953,6 @@ static void __ufshcd_setup_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd,memset (lrbp->ucd_req_ptr,0 ,sizeof (*lrbp->ucd_req_ptr)); - lrbp->task_tag = tag; lrbp->lun = lun;ufshcd_prepare_lrbp_crypto (cmd ?scsi_cmd_to_rq (cmd) :NULL , lrbp); }
@@ -3246,6 +3248,8 @@ ufshcd_dev_cmd_completion(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)static int ufshcd_wait_for_dev_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp,int max_timeout) { +struct scsi_cmnd *cmd = (struct scsi_cmnd *)lrbp -1 ; +const int tag =scsi_cmd_to_rq (cmd)->tag;unsigned long time_left =msecs_to_jiffies (max_timeout);unsigned long flags;bool pending;
@@ -3262,18 +3266,18 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, }else { err = -ETIMEDOUT ;dev_dbg (hba->dev,"%s: dev_cmd request timedout, tag %d\n" , - __func__, lrbp->task_tag); + __func__, tag);/* MCQ mode */ if (hba->mcq_enabled) {/* successfully cleared the command, retry if needed */ -if (ufshcd_clear_cmd (hba, lrbp->task_tag) ==0 ) +if (ufshcd_clear_cmd (hba, tag) ==0 ) err = -EAGAIN ;return err; }/* SDB mode */ -if (ufshcd_clear_cmd (hba, lrbp->task_tag) ==0 ) { +if (ufshcd_clear_cmd (hba, tag) ==0 ) {/* successfully cleared the command, retry if needed */ err = -EAGAIN ;/*
@@ -3282,11 +3286,9 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,* variable. */ spin_lock_irqsave (&hba->outstanding_lock, flags); - pending =test_bit (lrbp->task_tag, - &hba->outstanding_reqs); + pending =test_bit (tag, &hba->outstanding_reqs);if (pending) -__clear_bit (lrbp->task_tag, - &hba->outstanding_reqs); +__clear_bit (tag, &hba->outstanding_reqs);spin_unlock_irqrestore (&hba->outstanding_lock, flags);if (!pending) {
@@ -3299,11 +3301,10 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, } }else {dev_err (hba->dev,"%s: failed to clear tag %d\n" , - __func__, lrbp->task_tag); + __func__, tag);spin_lock_irqsave (&hba->outstanding_lock, flags); - pending =test_bit (lrbp->task_tag, - &hba->outstanding_reqs); + pending =test_bit (tag, &hba->outstanding_reqs);spin_unlock_irqrestore (&hba->outstanding_lock, flags);if (!pending) {
@@ -5459,6 +5460,7 @@ static inline int ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct cq_entry *cqe) {struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); +const int tag =scsi_cmd_to_rq (cmd)->tag;int result =0 ;int scsi_status;enum utp_ocs ocs;
@@ -5530,10 +5532,8 @@ static inline int ufshcd_transfer_rsp_status(struct ufs_hba *hba,case OCS_ABORTED :case OCS_INVALID_COMMAND_STATUS : result |=DID_REQUEUE <<16 ; -dev_warn (hba->dev, -"OCS %s from controller for tag %d\n" , - (ocs ==OCS_ABORTED ?"aborted" :"invalid" ), - lrbp->task_tag); +dev_warn (hba->dev,"OCS %s from controller for tag %d\n" , + ocs ==OCS_ABORTED ?"aborted" :"invalid" , tag);break ;case OCS_INVALID_CMD_TABLE_ATTR :case OCS_INVALID_PRDT_ATTR :
@@ -5546,9 +5546,8 @@ static inline int ufshcd_transfer_rsp_status(struct ufs_hba *hba,case OCS_GENERAL_CRYPTO_ERROR :default : result |=DID_ERROR <<16 ; -dev_err (hba->dev, -"OCS error from controller = %x for tag %d\n" , - ocs, lrbp->task_tag); +dev_err (hba->dev,"OCS error from controller = %x for tag %d\n" , + ocs, tag);ufshcd_print_evt_hist (hba);ufshcd_print_host_state (hba);break ;
@@ -7663,8 +7662,8 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)u8 resp =0xF ;for (poll_cnt =100 ; poll_cnt; poll_cnt--) { - err =ufshcd_issue_tm_cmd (hba, lrbp->lun, lrbp->task_tag, -UFS_QUERY_TASK , &resp); + err =ufshcd_issue_tm_cmd (hba, lrbp->lun, tag,UFS_QUERY_TASK , + &resp);if (!err && resp ==UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED ) {/* cmd pending in the device */ dev_err(hba->dev, "%s: cmd pending in the device. tag = %d\n",
@@ -7697,8 +7696,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)if (!poll_cnt)return -EBUSY ; - err =ufshcd_issue_tm_cmd (hba, lrbp->lun, lrbp->task_tag, -UFS_ABORT_TASK , &resp); + err =ufshcd_issue_tm_cmd (hba, lrbp->lun, tag,UFS_ABORT_TASK , &resp);if (err || resp !=UPIU_TASK_MANAGEMENT_FUNC_COMPL ) {if (!err) { err = resp;/* service response error */
@@ -7808,7 +7806,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) goto release; } - err =ufshcd_try_to_abort_task (hba, lrbp->task_tag); + err =ufshcd_try_to_abort_task (hba, tag);if (err) {dev_err (hba->dev,"%s: failed with err %d\n" , __func__, err);ufshcd_set_req_abort_skip (hba, hba->outstanding_reqs);
include/ufs/ufshcd.h +0 -1
@@ -188,7 +188,6 @@ struct ufshcd_lrb {int scsi_status;int command_type; -int task_tag;u8 lun;/* UPIU LUN id field is only 8-bit wide */ bool intr_cmd;bool req_abort_skip;
Bart Van Assche
reviewerPATCH v5 26/28 ufs: core: Make blk_mq_tagset_busy_iter() skip reserved requests
In reply to Bart Van AsscheA later patch will convert hba->reserved_slot into a reserved tag. Make blk_mq_tagset_busy_iter() skip reserved requests such that device management commands are skipped.
--- drivers/ufs/core/ufshcd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +8 -4
@@ -649,7 +649,8 @@ static bool ufshcd_print_tr_iter(struct request *req, void *priv)struct Scsi_Host *shost = sdev->host;struct ufs_hba *hba =shost_priv (shost); -ufshcd_print_tr (hba,blk_mq_rq_to_pdu (req), *(bool *)priv); +if (!blk_mq_is_reserved_rq (req)) +ufshcd_print_tr (hba,blk_mq_rq_to_pdu (req), *(bool *)priv);return true; }
@@ -5744,7 +5745,7 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)struct ufs_hba *hba =shost_priv (shost);struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); -if (!hwq) +if (blk_mq_is_reserved_rq (rq) || !hwq)return true;ufshcd_mcq_compl_all_cqes_lock (hba, hwq);
@@ -5771,7 +5772,7 @@ static bool ufshcd_mcq_compl_one(struct request *rq, void *priv)struct ufs_hba *hba =shost_priv (shost);struct ufs_hw_queue *hwq =ufshcd_mcq_req_to_hwq (hba, rq); -if (hwq) +if (!blk_mq_is_reserved_rq (rq) && hwq)ufshcd_mcq_poll_cqe_lock (hba, hwq);return true;
@@ -6633,6 +6634,9 @@ static bool ufshcd_abort_one(struct request *rq, void *priv)struct Scsi_Host *shost = sdev->host;struct ufs_hba *hba =shost_priv (shost); +if (blk_mq_is_reserved_rq (rq)) +return true; + *ret =ufshcd_try_to_abort_task (hba, tag); dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, ufshcd_is_scsi_cmd(cmd) ? cmd->cmnd[0] : -1,
@@ -7568,7 +7572,7 @@ static bool ufshcd_clear_lu_cmds(struct request *req, void *priv)const u64 lun = *(u64 *)priv;const u32 tag = req->tag; -if (sdev->lun != lun) +if (blk_mq_is_reserved_rq (req) || sdev->lun != lun)return true;if (ufshcd_clear_cmd (hba, tag) <0 ) {
Bart Van Assche
reviewerPATCH v5 27/28 ufs: core: Move code out of ufshcd_wait_for_dev_cmd()
In reply to Bart Van AsscheThe ufshcd_dev_cmd_completion() call is useful for some but not for all ufshcd_wait_for_dev_cmd() callers. Hence, remove the ufshcd_dev_cmd_completion() call from ufshcd_wait_for_dev_cmd() and move it past the ufshcd_issue_dev_cmd() calls where appropriate. This makes it easier to detect timeout errors for UPIU frames submitted through the BSG interface.
--- drivers/ufs/core/ufshcd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/ufs/core/ufshcd.c +12 -9
@@ -3262,8 +3262,6 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,if (likely (time_left)) { err =ufshcd_get_tr_ocs (lrbp,NULL ); -if (!err) - err =ufshcd_dev_cmd_completion (hba, lrbp); }else { err = -ETIMEDOUT ; dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n",
@@ -3372,6 +3370,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, {const u32 tag = hba->reserved_slot;struct scsi_cmnd *cmd =ufshcd_tag_to_cmd (hba, tag); +struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd);int err;/* Protects use of hba->reserved_slot. */
@@ -3381,7 +3380,11 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,if (unlikely (err))return err; -return ufshcd_issue_dev_cmd (hba, cmd, tag, timeout); + err =ufshcd_issue_dev_cmd (hba, cmd, tag, timeout); +if (err) +return err; + +return ufshcd_dev_cmd_completion (hba, lrbp); }/**
@@ -7384,12 +7387,9 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,memset (lrbp->ucd_rsp_ptr,0 ,sizeof (struct utp_upiu_rsp )); -/* -* ignore the returning value here - ufshcd_check_query_response is -* bound to fail since dev_cmd.query and dev_cmd.type were left empty. -* read the response directly ignoring all errors. -*/ -ufshcd_issue_dev_cmd (hba, cmd, tag, dev_cmd_timeout); + err =ufshcd_issue_dev_cmd (hba, cmd, tag, dev_cmd_timeout); +if (err) +return err;/* just copy the upiu response as it is */ memcpy (rsp_upiu, lrbp->ucd_rsp_ptr,sizeof (*rsp_upiu));
@@ -7534,7 +7534,10 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *rmemset (lrbp->ucd_rsp_ptr,0 ,sizeof (struct utp_upiu_rsp )); err =ufshcd_issue_dev_cmd (hba, cmd, tag,ADVANCED_RPMB_REQ_TIMEOUT ); +if (err) +return err; + err =ufshcd_dev_cmd_completion (hba, lrbp);if (!err) {/* Just copy the upiu response as it is */ memcpy (rsp_upiu, lrbp->ucd_rsp_ptr,sizeof (*rsp_upiu));
RE: [PATCH v5 27/28] ufs: core: Move code out of ufshcd_wait_for_dev_cmd()
Quoted 8 lines
The
ufshcd_dev_cmd_completion()call is useful for some but not for allufshcd_wait_for_dev_cmd()callers. Hence, remove theufshcd_dev_cmd_completion()call fromufshcd_wait_for_dev_cmd()and move it past theufshcd_issue_dev_cmd()calls where appropriate. This makes it easier to detect timeout errors for UPIU frames submitted through the BSG interface.Signed-off-by Bart Van Assche <[email protected]>
Quoted 68 lines
--- drivers/ufs/core/ufshcd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
a3c4f8cb2f37..b6ee8bfbb718100644drivers/ufs/core/ufshcd.c +0
-2@@ -3262,8 +3262,6 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,if (likely (time_left)) { err =ufshcd_get_tr_ocs (lrbp,NULL ); -if (!err) - err =ufshcd_dev_cmd_completion (hba, lrbp); }else { err = -ETIMEDOUT ;dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n", @@ - 3372,6 +3370,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, { const u32 tag = hba->reserved_slot; struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, tag); + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); int err; /* Protects use of hba->reserved_slot. */ @@ -3381,7 +3380,11 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, if (unlikely(err)) return err;drivers/ufs/core/ufshcd.c +8
-7-return ufshcd_issue_dev_cmd (hba, cmd, tag, timeout); + err =ufshcd_issue_dev_cmd (hba, cmd, tag, timeout); +if (err) +return err; + +return ufshcd_dev_cmd_completion (hba, lrbp); }/** @@ -7384,12 +7387,9 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,memset (lrbp->ucd_rsp_ptr,0 ,sizeof (struct utp_upiu_rsp )); -/* -* ignore the returning value here - ufshcd_check_query_response is -* bound to fail since dev_cmd.query and dev_cmd.type were left empty. -* read the response directly ignoring all errors. -*/ -ufshcd_issue_dev_cmd (hba, cmd, tag, dev_cmd_timeout); + err =ufshcd_issue_dev_cmd (hba, cmd, tag, dev_cmd_timeout); +if (err) +return err;/* just copy the upiu response as it is */ memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); @@ -7534,7+7534,10 @@ int ufshcd_advanced_rpmb_req_handler(struct
ufs_hba*hba, structutp_upiu_req*r
memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));err = ufshcd_issue_dev_cmd(hba, cmd, tag,
ADVANCED_RPMB_REQ_TIMEOUT);drivers/ufs/core/ufshcd.c +3
-0+if (err) +return err; + err =ufshcd_dev_cmd_completion (hba, lrbp);if (!err) {/* Just copy the upiu response as it is */ memcpy (rsp_upiu, lrbp->ucd_rsp_ptr,sizeof (*rsp_upiu));
Bart Van Assche
reviewerPATCH v5 28/28 ufs: core: Switch to scsi_get_internal_cmd()
In reply to Bart Van AsscheInstead of storing the tag of the reserved command in hba->reserved_slot, use scsi_get_internal_cmd() and scsi_put_internal_cmd() to allocate the tag for the reserved command dynamically. Add ufshcd_queue_reserved_command() for submitting reserved commands. Add support in ufshcd_abort() for device management commands. Use blk_execute_rq() for submitting reserved commands. Remove the code and data structures that became superfluous. This includes ufshcd_wait_for_dev_cmd(), hba->reserved_slot and ufs_dev_cmd.complete.
--- drivers/ufs/core/ufs-mcq.c | 19 ++- drivers/ufs/core/ufshcd-priv.h | 25 +--- drivers/ufs/core/ufshcd.c | 224 ++++++++++++++++----------------- include/ufs/ufshcd.h | 6 - 4 files changed, 119 insertions(+), 155 deletions(-)
drivers/ufs/core/ufs-mcq.c +7 -12
@@ -471,9 +471,6 @@ int ufshcd_mcq_init(struct ufs_hba *hba)mutex_init (&hwq->sq_mutex); } -/* The very first HW queue serves device commands */ - hba->dev_cmd_queue = &hba->uhq[0 ]; - host->host_tagset =1 ;return 0 ; }
@@ -528,6 +525,7 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag) {struct scsi_cmnd *cmd =ufshcd_tag_to_cmd (hba, task_tag);struct ufshcd_lrb *lrbp =scsi_cmd_priv (cmd); +struct request *rq =scsi_cmd_to_rq (cmd);struct ufs_hw_queue *hwq;void __iomem *reg, *opr_sqd_base;u32 nexus, id, val;
@@ -536,15 +534,12 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)if (hba->quirks &UFSHCD_QUIRK_MCQ_BROKEN_RTC )return -ETIMEDOUT ; -if (task_tag != hba->reserved_slot) { -if (!cmd) -return -EINVAL ; - hwq =ufshcd_mcq_req_to_hwq (hba,scsi_cmd_to_rq (cmd)); -if (!hwq) -return 0 ; - }else { - hwq = hba->dev_cmd_queue; - } +if (!cmd) +return -EINVAL ; + + hwq =ufshcd_mcq_req_to_hwq (hba, rq); +if (!hwq) +return 0 ; id = hwq->id;
drivers/ufs/core/ufshcd-priv.h +1 -24
@@ -367,30 +367,7 @@ static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8static inline struct scsi_cmnd *ufshcd_tag_to_cmd (struct ufs_hba *hba,u32 tag) {struct blk_mq_tags *tags = hba->host->tag_set.shared_tags; -struct request *rq; - -/* -* Handle reserved tags differently because the UFS driver does not -* call blk_mq_alloc_request() for allocating reserved requests. -* Allocating reserved tags with blk_mq_alloc_request() would require -* the following: -* - Allocate an additional request queue from &hba->host->tag_set for -* allocating reserved requests from. -* - For that request queue, allocate a SCSI device. -* - Calling blk_mq_alloc_request(hba->dev_mgmt_queue, REQ_OP_DRV_OUT, -* BLK_MQ_REQ_RESERVED) for allocating a reserved request and -* blk_mq_free_request() for freeing reserved requests. -* - Set the .device pointer for these reserved requests. -* - Submit reserved requests with blk_execute_rq(). -* - Modify ufshcd_queuecommand() such that it handles reserved requests -* in another way than SCSI requests. -* - Modify ufshcd_compl_one_cqe() such that it calls scsi_done() for -* device management commands. -* - Modify all callback functions called by blk_mq_tagset_busy_iter() -* calls in the UFS driver and skip device management commands. -*/ - rq = tag <UFSHCD_NUM_RESERVED ? tags->static_rqs[tag] : -blk_mq_tag_to_rq (tags, tag); +struct request *rq =blk_mq_tag_to_rq (tags, tag);if (WARN_ON_ONCE (!rq))return NULL ;
drivers/ufs/core/ufshcd.c +111 -113
369 lines not on this page · raw message
include/ufs/ufshcd.h +0 -6
@@ -236,13 +236,11 @@ struct ufs_query {* struct ufs_dev_cmd - all assosiated fields with device management commands * @type: device management command type - Query, NOP OUT * @lock: lock to allow one command at a time -* @complete: internal commands completion * @query: Device management query information */ struct ufs_dev_cmd {enum dev_cmd_type type;struct mutex lock; -struct completion complete;struct ufs_query query; };
@@ -838,7 +836,6 @@ enum ufshcd_mcq_opr {* @nutrs: Transfer Request Queue depth supported by controller * @nortt - Max outstanding RTTs supported by controller * @nutmrs: Task Management Queue depth supported by controller -* @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock. * @ufs_version: UFS Version to which controller complies * @vops: pointer to variant specific operations * @vps: pointer to variant specific parameters
@@ -929,7 +926,6 @@ enum ufshcd_mcq_opr {* @res: array of resource info of MCQ registers * @mcq_base: Multi circular queue registers base address * @uhq: array of supported hardware queues -* @dev_cmd_queue: Queue for issuing device management commands * @mcq_opr: MCQ operation and runtime registers * @ufs_rtc_update_work: A work for UFS RTC periodic update * @pm_qos_req: PM QoS request handle
@@ -980,7 +976,6 @@ struct ufs_hba {int nortt;u32 mcq_capabilities;int nutmrs; -u32 reserved_slot;u32 ufs_version;const struct ufs_hba_variant_ops *vops;struct ufs_hba_variant_params *vps;
@@ -1098,7 +1093,6 @@ struct ufs_hba {bool mcq_esi_enabled;void __iomem *mcq_base;struct ufs_hw_queue *uhq; -struct ufs_hw_queue *dev_cmd_queue;struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX ];struct delayed_work ufs_rtc_update_work;
Did you notice this when you tested?
[ 0.927347] dev_size_mb=8, opts=0x0, submit_queues=1, statistics=0 [ 0.930065] ------------[ cut here ]------------ [ 0.931137] WARNING: CPU: 1 PID: 1 at drivers/scsi/scsi_scan.c:228 scsi_realloc_sdev_budget_map+0x163/0x180 [ 0.933292] Modules linked in: [ 0.933948] CPU: 1 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.17.0-rc1-00143-g67ede8ca8ab5-dirty #1769 PREEMPT(voluntary) [ 0.936317] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 [ 0.938683] RIP: 0010:scsi_realloc_sdev_budget_map+0x163/0x180 [ 0.939955] Code: 45 39 ee 44 89 ee 48 8b 7c 24 28 41 0f 46 f6 e8 23 df be ff 48 8b 7c 24 08 e8 f9 99 85 ff 48 8b 3c 24 e8 90 ed 8a ff eb ae 90 <0f> 0b 90 48 83 c4 30 b8 ea ff ff ff 5b 5d 41 5c 41 5d 41 5e 41 5f [ 0.943854] RSP: 0000:ffffb29bc00139c8 EFLAGS: 00010246 [ 0.944950] RAX: 0000000000000080 RBX: ffff89bac0a53800 RCX: 0000000000000005 [ 0.946515] RDX: 0000000000000003 RSI: 0000000000000004 RDI: ffff89bac0a53800 [ 0.948019] RBP: ffff89bac0a4e000 R08: 0000000000000000 R09: 0000000000000001 [ 0.949521] R10: 0000000000000000 R11: 0000000000000008 R12: 00000000000000c0 [ 0.951038] R13: 00000000000000c0 R14: ffff89bac3d09828 R15: 0000000000000005 [ 0.952537] FS: 0000000000000000(0000) GS:ffff89bb47fe3000(0000) knlGS:0000000000000000 [ 0.954258] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.955464] CR2: 0000000000000000 CR3: 0000000120e30001 CR4: 0000000000370ef0 [ 0.957001] Call Trace: [ 0.957547] <TASK> [ 0.958087] ? attribute_container_add_device+0x4b/0x130 [ 0.959295] scsi_alloc_sdev+0x27f/0x360 [ 0.960191] scsi_probe_and_add_lun+0x1e4/0x2f0 [ 0.961203] __scsi_scan_target+0x104/0x210 [ 0.962157] scsi_scan_channel+0x54/0x90 [ 0.962942] scsi_scan_host_selected+0xcf/0x100 [ 0.964420] scsi_scan_host+0x19f/0x1c0 [ 0.965289] sdebug_driver_probe+0x1c0/0x420 [ 0.966317] really_probe+0xba/0x2b0 [ 0.967171] ? __pfx___device_attach_driver+0x10/0x10 [ 0.968308] __driver_probe_device+0x6e/0x110 [ 0.969286] driver_probe_device+0x1a/0xe0 [ 0.970232] __device_attach_driver+0x7e/0x110 [ 0.971276] bus_for_each_drv+0x8f/0xe0 [ 0.972183] __device_attach+0xa9/0x1a0 [ 0.973080] bus_probe_device+0x88/0xa0 [ 0.973973] device_add+0x61c/0x810 [ 0.974805] sdebug_add_host_helper+0x1ca/0x260 [ 0.975843] scsi_debug_init+0x341/0x7d0 [ 0.976770] ? __pfx_scsi_debug_init+0x10/0x10 [ 0.977801] do_one_initcall+0x55/0x220 [ 0.978706] kernel_init_freeable+0x199/0x2e0 [ 0.979744] ? __pfx_kernel_init+0x10/0x10 [ 0.980688] kernel_init+0x15/0x1c0 [ 0.981765] ret_from_fork+0x80/0xd0 [ 0.982710] ? __pfx_kernel_init+0x10/0x10 [ 0.983689] ret_from_fork_asm+0x1a/0x30 [ 0.984742] </TASK> [ 0.985223] ---[ end trace 0000000000000000 ]--- [ 0.986231] scsi_alloc_sdev: Allocation failure during SCSI
scanning, some SCSI devices might not be configured
Bart Van Assche
reviewerQuoted 1 line · John Garry
Did you notice this when you tested?
Yes, but I only noticed this a few minutes after I posted this patch series. I queued up the two changes below for when I repost this patch series. The first change suppresses the kernel warning from your email. The second change ensures that ufshcd_get_hba_mac() only prints an error message if it returns a negative value.
Thanks,
Bart.
drivers/scsi/scsi_scan.c +0 -3
@@ -225,9 +225,6 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,int ret;struct sbitmap sb_backup; -if (WARN_ON_ONCE (!sdev->budget_map.map)) -return -EINVAL ; - depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev));/*
drivers/ufs/core/ufs-mcq.c +1 -4
@@ -156,10 +160,7 @@ int ufshcd_get_hba_mac(struct ufs_hba *hba) mac = hba->vops->get_hba_mac (hba); }if (mac <0 ) - goto err; - -err: -dev_err (hba->dev,"Failed to get mac, err=%d\n" , mac); +dev_err (hba->dev,"Failed to get mac, err=%d\n" , mac);return mac; }