Simplify the UFS driver initialization code
Subsystems (2)
Bart Van Assche
reviewerv3 cover Simplify the UFS driver initialization code
Hi Martin,
This patch series addresses the following issues in the UFS driver initialization code:
* The legacy and MCQ scsi_add_host() calls occur in different functions. This patch series reduces the number of scsi_add_host() calls from two to one.
* Two functions have a boolean 'init_dev_params' argument. This patch series removes that argument from both functions by splitting functions and by pushing some function calls from caller into callee.
Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v2:
- Improved several patch descriptions.
- Moved one source code comment.
Changes compared to v1:
- Fixed a compiler warning reported by the kernel build robot.
- Improved patch descriptions.
Bart Van Assche (9):
ufs: core: Introduce ufshcd_add_scsi_host()
ufs: core: Introduce ufshcd_activate_link()
ufs: core: Introduce ufshcd_post_device_init()
ufs: core: Call ufshcd_add_scsi_host() later
ufs: core: Move the ufshcd_device_init() call
ufs: core: Move the ufshcd_device_init(hba, true) call
ufs: core: Expand the ufshcd_device_init(hba, true) call
ufs: core: Move the MCQ scsi_add_host() call
ufs: core: Remove the second argument of ufshcd_device_init()
drivers/ufs/core/ufshcd.c | 268 ++++++++++++++++++++++---------------- 1 file changed, 153 insertions(+), 115 deletions(-)
Bart Van Assche
reviewerPATCH v3 1/9 ufs: core: Introduce ufshcd_add_scsi_host()
Move the code for adding a SCSI host and also the code for managing TMF tags from ufshcd_init() into a new function called ufshcd_add_scsi_host(). This patch prepares for combining the two scsi_add_host() calls into a single call. No functionality has been changed.
--- drivers/ufs/core/ufshcd.c | 84 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 31 deletions(-)
drivers/ufs/core/ufshcd.c +53 -31
@@ -10375,6 +10375,56 @@ static const struct blk_mq_ops ufshcd_tmf_ops = { .queue_rq = ufshcd_queue_tmf, }; +static int ufshcd_add_scsi_host (struct ufs_hba *hba) +{ +int err; + +if (!is_mcq_supported (hba)) { + err =scsi_add_host (hba->host, hba->dev); +if (err) { +dev_err (hba->dev,"scsi_add_host failed\n" ); +return err; + } + hba->scsi_host_added = true; + } + + hba->tmf_tag_set = (struct blk_mq_tag_set ) { + .nr_hw_queues =1 , + .queue_depth = hba->nutmrs, + .ops = &ufshcd_tmf_ops, + .flags =BLK_MQ_F_NO_SCHED , + }; + err =blk_mq_alloc_tag_set (&hba->tmf_tag_set); +if (err <0 ) + goto remove_scsi_host; + hba->tmf_queue =blk_mq_alloc_queue (&hba->tmf_tag_set,NULL ,NULL ); +if (IS_ERR (hba->tmf_queue)) { + err =PTR_ERR (hba->tmf_queue); + goto free_tmf_tag_set; + } + hba->tmf_rqs =devm_kcalloc (hba->dev, hba->nutmrs, +sizeof (*hba->tmf_rqs),GFP_KERNEL ); +if (!hba->tmf_rqs) { + err = -ENOMEM ; + goto free_tmf_queue; + } + +return 0 ; + +free_tmf_queue: +blk_mq_destroy_queue (hba->tmf_queue); +blk_put_queue (hba->tmf_queue); + +free_tmf_tag_set: +blk_mq_free_tag_set (&hba->tmf_tag_set); + +remove_scsi_host: +if (hba->scsi_host_added) +scsi_remove_host (hba->host); + +return err; +} +/** * ufshcd_init - Driver initialization routine * @hba: per-adapter instance
@@ -10506,35 +10556,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->is_irq_enabled = true; } -if (!is_mcq_supported (hba)) { - err =scsi_add_host (host, hba->dev); -if (err) { -dev_err (hba->dev,"scsi_add_host failed\n" ); - goto out_disable; - } - hba->scsi_host_added = true; - } - - hba->tmf_tag_set = (struct blk_mq_tag_set ) { - .nr_hw_queues =1 , - .queue_depth = hba->nutmrs, - .ops = &ufshcd_tmf_ops, - .flags =BLK_MQ_F_NO_SCHED , - }; - err =blk_mq_alloc_tag_set (&hba->tmf_tag_set); -if (err <0 ) - goto out_remove_scsi_host; - hba->tmf_queue =blk_mq_alloc_queue (&hba->tmf_tag_set,NULL ,NULL ); -if (IS_ERR (hba->tmf_queue)) { - err =PTR_ERR (hba->tmf_queue); - goto free_tmf_tag_set; - } - hba->tmf_rqs =devm_kcalloc (hba->dev, hba->nutmrs, -sizeof (*hba->tmf_rqs),GFP_KERNEL ); -if (!hba->tmf_rqs) { - err = -ENOMEM ; - goto free_tmf_queue; - } + err =ufshcd_add_scsi_host (hba); +if (err) + goto out_disable;/* Reset the attached device */ ufshcd_device_reset (hba);
@@ -10592,9 +10616,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) free_tmf_queue:blk_mq_destroy_queue (hba->tmf_queue);blk_put_queue (hba->tmf_queue); -free_tmf_tag_set:blk_mq_free_tag_set (&hba->tmf_tag_set); -out_remove_scsi_host:if (hba->scsi_host_added)scsi_remove_host (hba->host); out_disable:
Re: [PATCH v3 1/9] ufs: core: Introduce ufshcd_add_scsi_host()
Quoted 8 lines · Bart Van Assche
Move the code for adding a SCSI host and also the code for managing TMF tags from
ufshcd_init()into a new function calledufshcd_add_scsi_host(). This patch prepares for combining the twoscsi_add_host()calls into a single call. No functionality has been changed.Reviewed-by Avri Altman <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Bean Huo <[email protected]>
Bart Van Assche
reviewerPATCH v3 2/9 ufs: core: Introduce ufshcd_activate_link()
In reply to Bart Van AsschePrepare for introducing a second caller by moving the code for activating the link between UFS controller and device into a new function. No functionality has been changed.
--- drivers/ufs/core/ufshcd.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +13 -2
@@ -8727,10 +8727,9 @@ static void ufshcd_config_mcq(struct ufs_hba *hba) hba->nutrs); } -static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params) +static int ufshcd_activate_link (struct ufs_hba *hba) {int ret; -struct Scsi_Host *host = hba->host; hba->ufshcd_state =UFSHCD_STATE_RESET ;
@@ -8747,6 +8746,18 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)/* UniPro link is active now */ ufshcd_set_link_active (hba); +return 0 ; +} + +static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params) +{ +struct Scsi_Host *host = hba->host; +int ret; + + ret =ufshcd_activate_link (hba); +if (ret) +return ret; +/* Reconfigure MCQ upon reset */ if (hba->mcq_enabled && !init_dev_params) {ufshcd_config_mcq (hba);
Re: [PATCH v3 2/9] ufs: core: Introduce ufshcd_activate_link()
Bart Van Assche
reviewerPATCH v3 3/9 ufs: core: Introduce ufshcd_post_device_init()
In reply to Bart Van AsschePrepare for introducing a second caller by moving more code from ufshcd_device_init() into a new function.
--- drivers/ufs/core/ufshcd.c | 63 ++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 27 deletions(-)
drivers/ufs/core/ufshcd.c +36 -27
@@ -8749,6 +8749,41 @@ static int ufshcd_activate_link(struct ufs_hba *hba)return 0 ; } +static int ufshcd_post_device_init (struct ufs_hba *hba) +{ +int ret; + +ufshcd_tune_unipro_params (hba); + +/* UFS device is also active now */ +ufshcd_set_ufs_dev_active (hba); +ufshcd_force_reset_auto_bkops (hba); + +ufshcd_set_timestamp_attr (hba); +schedule_delayed_work (&hba->ufs_rtc_update_work, +msecs_to_jiffies (UFS_RTC_UPDATE_INTERVAL_MS )); + +if (!hba->max_pwr_info.is_valid) +return 0 ; + +/* +* Set the right value to bRefClkFreq before attempting to +* switch to HS gears. +*/ +if (hba->dev_ref_clk_freq !=REF_CLK_FREQ_INVAL ) +ufshcd_set_dev_ref_clk (hba); +/* Gear up to HS gear. */ + ret =ufshcd_config_pwr_mode (hba, &hba->max_pwr_info.info); +if (ret) { +dev_err (hba->dev, +"%s: Failed setting power mode, err = %d\n" , + __func__, ret); +return ret; + } + +return 0 ; +} +static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params) {struct Scsi_Host *host = hba->host;
@@ -8807,33 +8842,7 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) } } -ufshcd_tune_unipro_params (hba); - -/* UFS device is also active now */ -ufshcd_set_ufs_dev_active (hba); -ufshcd_force_reset_auto_bkops (hba); - -ufshcd_set_timestamp_attr (hba); -schedule_delayed_work (&hba->ufs_rtc_update_work, -msecs_to_jiffies (UFS_RTC_UPDATE_INTERVAL_MS )); - -/* Gear up to HS gear if supported */ -if (hba->max_pwr_info.is_valid) { -/* -* Set the right value to bRefClkFreq before attempting to -* switch to HS gears. -*/ -if (hba->dev_ref_clk_freq !=REF_CLK_FREQ_INVAL ) -ufshcd_set_dev_ref_clk (hba); - ret =ufshcd_config_pwr_mode (hba, &hba->max_pwr_info.info); -if (ret) { -dev_err (hba->dev,"%s: Failed setting power mode, err = %d\n" , - __func__, ret); -return ret; - } - } - -return 0 ; +return ufshcd_post_device_init (hba); }/**
Bart Van Assche
reviewerPATCH v3 4/9 ufs: core: Call ufshcd_add_scsi_host() later
In reply to Bart Van AsscheCall ufshcd_add_scsi_host() after host controller initialization has completed. This is possible because no code between the old and new ufshcd_add_scsi_host() call site depends on the scsi_add_host() call.
--- drivers/ufs/core/ufshcd.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/ufs/core/ufshcd.c +5 -11
@@ -10576,10 +10576,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->is_irq_enabled = true; } - err =ufshcd_add_scsi_host (hba); -if (err) - goto out_disable; -/* Reset the attached device */ ufshcd_device_reset (hba);
@@ -10591,7 +10587,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)dev_err (hba->dev,"Host controller enable failed\n" );ufshcd_print_evt_hist (hba);ufshcd_print_host_state (hba); - goto free_tmf_queue; + goto out_disable; }/*
@@ -10626,6 +10622,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)*/ ufshcd_set_ufs_dev_active (hba); + err =ufshcd_add_scsi_host (hba); +if (err) + goto out_disable; +async_schedule (ufshcd_async_scan, hba);ufs_sysfs_add_nodes (hba->dev);
@@ -10633,12 +10633,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)ufshcd_pm_qos_init (hba);return 0 ; -free_tmf_queue: -blk_mq_destroy_queue (hba->tmf_queue); -blk_put_queue (hba->tmf_queue); -blk_mq_free_tag_set (&hba->tmf_tag_set); -if (hba->scsi_host_added) -scsi_remove_host (hba->host); out_disable: hba->is_irq_enabled = false;ufshcd_hba_exit (hba);
Re: [PATCH v3 4/9] ufs: core: Call ufshcd_add_scsi_host() later
Quoted 6 lines · Bart Van Assche
Call
ufshcd_add_scsi_host()after host controller initialization has completed. This is possible because no code between the old and newufshcd_add_scsi_host()call site depends on thescsi_add_host()call.Reviewed-by Manivannan Sadhasivam <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
I don't understand why the first 3 patches can't be combined into this one for easier review.
Bart Van Assche
reviewerRe: [PATCH v3 4/9] ufs: core: Call ufshcd_add_scsi_host() later
Quoted 2 lines · Bean Huo
I don't understand why the first 3 patches can't be combined into this one for easier review.
Combining patches is easy but I'd like to keep the first four patches separate. I'm following this guidance from Documentation/process/submitting-patches.rst: "Solve only one problem per patch." I don't think that it is possible to follow this rule if I combine any of the first four patches?
Thanks,
Bart.
Bart Van Assche
reviewerPATCH v3 5/9 ufs: core: Move the ufshcd_device_init() call
In reply to Bart Van AsscheMove the ufshcd_device_init() call to the ufshcd_probe_hba() callers and remove the 'init_dev_params' argument of ufshcd_probe_hba(). This change refactors the code without modifying the behavior of the UFSHCI driver. This change prepares for moving one ufshcd_device_init() call into ufshcd_init().
--- drivers/ufs/core/ufshcd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/ufs/core/ufshcd.c +13 -12
@@ -298,7 +298,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);static int ufshcd_eh_host_reset_handler (struct scsi_cmnd *cmd);static int ufshcd_clear_tm_cmd (struct ufs_hba *hba,int tag);static void ufshcd_hba_exit (struct ufs_hba *hba); -static int ufshcd_probe_hba (struct ufs_hba *hba,bool init_dev_params); +static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params); +static int ufshcd_probe_hba (struct ufs_hba *hba);static int ufshcd_setup_clocks (struct ufs_hba *hba,bool on);static inline void ufshcd_add_delay_before_dme_cmd (struct ufs_hba *hba);static int ufshcd_host_reset_and_restore (struct ufs_hba *hba);
@@ -7711,8 +7712,11 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba) err =ufshcd_hba_enable (hba);/* Establish the link again and restore the device */ -if (!err) - err =ufshcd_probe_hba (hba, false); +if (!err) { + err =ufshcd_device_init (hba,/*init_dev_params=*/ false); +if (!err) + err =ufshcd_probe_hba (hba); + }if (err)dev_err (hba->dev,"%s: Host init failed %d\n" , __func__, err);
@@ -8848,21 +8852,16 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)/** * ufshcd_probe_hba - probe hba to detect device and initialize it * @hba: per-adapter instance -* @init_dev_params: whether or not to call ufshcd_device_params_init(). * * Execute link-startup and verify device initialization * * Return: 0 upon success; < 0 upon failure. */ -static int ufshcd_probe_hba (struct ufs_hba *hba,bool init_dev_params) +static int ufshcd_probe_hba (struct ufs_hba *hba) {ktime_t start =ktime_get ();unsigned long flags; -int ret; - - ret =ufshcd_device_init (hba, init_dev_params); -if (ret) - goto out; +int ret =0 ;if (!hba->pm_op_in_progress && (hba->quirks &UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH )) {
@@ -8880,7 +8879,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) }/* Reinit the device */ - ret =ufshcd_device_init (hba, init_dev_params); + ret =ufshcd_device_init (hba,/*init_dev_params=*/ false);if (ret) goto out; }
@@ -8928,7 +8927,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)down (&hba->host_sem);/* Initialize hba, detect and initialize UFS device */ - ret =ufshcd_probe_hba (hba, true); + ret =ufshcd_device_init (hba,/*init_dev_params=*/ true); +if (ret ==0 ) + ret =ufshcd_probe_hba (hba);up (&hba->host_sem);if (ret) goto out;
Bart Van Assche
reviewerPATCH v3 6/9 ufs: core: Move the ufshcd_device_init(hba, true) call
In reply to Bart Van AsscheMove the ufshcd_device_init(hba, true) call from ufshcd_async_scan() into ufshcd_init(). This patch prepares for moving both scsi_add_host() calls into ufshcd_add_scsi_host(). Calling ufshcd_device_init() from ufshcd_init() without holding hba->host_sem is safe. This is safe because hba->host_sem serializes core code and sysfs callbacks. The ufshcd_device_init() call is moved before the scsi_add_host() call and hence happens before any SCSI sysfs attributes are created.
--- drivers/ufs/core/ufshcd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +5 -4
@@ -8926,10 +8926,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)int ret;down (&hba->host_sem); -/* Initialize hba, detect and initialize UFS device */ - ret =ufshcd_device_init (hba,/*init_dev_params=*/ true); -if (ret ==0 ) - ret =ufshcd_probe_hba (hba); + ret =ufshcd_probe_hba (hba);up (&hba->host_sem);if (ret) goto out;
@@ -10623,6 +10620,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)*/ ufshcd_set_ufs_dev_active (hba); + err =ufshcd_device_init (hba,/*init_dev_params=*/ true); +if (err) + goto out_disable; + err =ufshcd_add_scsi_host (hba);if (err) goto out_disable;
Bart Van Assche
reviewerPATCH v3 7/9 ufs: core: Expand the ufshcd_device_init(hba, true) call
In reply to Bart Van AsscheExpand the ufshcd_device_init(hba, true) call and remove all code that depends on init_dev_params == false. This change prepares for combining the two scsi_add_host() calls.
--- drivers/ufs/core/ufshcd.c | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +42 -1
@@ -10620,7 +10620,48 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)*/ ufshcd_set_ufs_dev_active (hba); - err =ufshcd_device_init (hba,/*init_dev_params=*/ true); + err =ufshcd_activate_link (hba); +if (err) + goto out_disable; + +/* Verify device initialization by sending NOP OUT UPIU. */ + err =ufshcd_verify_dev_init (hba); +if (err) + goto out_disable; + +/* Initiate UFS initialization and waiting for completion. */ + err =ufshcd_complete_dev_init (hba); +if (err) + goto out_disable; + +/* +* Initialize UFS device parameters used by driver, these +* parameters are associated with UFS descriptors. +*/ + err =ufshcd_device_params_init (hba); +if (err) + goto out_disable; +if (is_mcq_supported (hba)) { +ufshcd_mcq_enable (hba); + err =ufshcd_alloc_mcq (hba); +if (!err) { +ufshcd_config_mcq (hba); + }else { +/* Continue with SDB mode */ +ufshcd_mcq_disable (hba); + use_mcq_mode = false; +dev_err (hba->dev,"MCQ mode is disabled, err=%d\n" , + err); + } + err =scsi_add_host (host, hba->dev); +if (err) { +dev_err (hba->dev,"scsi_add_host failed\n" ); + goto out_disable; + } + hba->scsi_host_added = true; + } + + err =ufshcd_post_device_init (hba);if (err) goto out_disable;
Bart Van Assche
reviewerPATCH v3 8/9 ufs: core: Move the MCQ scsi_add_host() call
In reply to Bart Van AsscheWhether or not MCQ is used, call scsi_add_host from ufshcd_add_scsi_host(). For MCQ this patch swaps the order of the scsi_add_host() and ufshcd_post_device_init() calls. This patch also prepares for moving both scsi_add_host() calls into ufshcd_add_scsi_host().
--- drivers/ufs/core/ufshcd.c | 43 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 25 deletions(-)
drivers/ufs/core/ufshcd.c +18 -25
@@ -10397,15 +10397,27 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) {int err; -if (!is_mcq_supported (hba)) { - err =scsi_add_host (hba->host, hba->dev); -if (err) { -dev_err (hba->dev,"scsi_add_host failed\n" ); -return err; +if (is_mcq_supported (hba)) { +ufshcd_mcq_enable (hba); + err =ufshcd_alloc_mcq (hba); +if (!err) { +ufshcd_config_mcq (hba); + }else { +/* Continue with SDB mode */ +ufshcd_mcq_disable (hba); + use_mcq_mode = false; +dev_err (hba->dev,"MCQ mode is disabled, err=%d\n" , + err); } - hba->scsi_host_added = true; } + err =scsi_add_host (hba->host, hba->dev); +if (err) { +dev_err (hba->dev,"scsi_add_host failed\n" ); +return err; + } + hba->scsi_host_added = true; + hba->tmf_tag_set = (struct blk_mq_tag_set ) { .nr_hw_queues =1 , .queue_depth = hba->nutmrs,
@@ -10641,25 +10653,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) err =ufshcd_device_params_init (hba);if (err) goto out_disable; -if (is_mcq_supported (hba)) { -ufshcd_mcq_enable (hba); - err =ufshcd_alloc_mcq (hba); -if (!err) { -ufshcd_config_mcq (hba); - }else { -/* Continue with SDB mode */ -ufshcd_mcq_disable (hba); - use_mcq_mode = false; -dev_err (hba->dev,"MCQ mode is disabled, err=%d\n" , - err); - } - err =scsi_add_host (host, hba->dev); -if (err) { -dev_err (hba->dev,"scsi_add_host failed\n" ); - goto out_disable; - } - hba->scsi_host_added = true; - } err =ufshcd_post_device_init (hba);if (err)
Bart Van Assche
reviewerPATCH v3 9/9 ufs: core: Remove the second argument of ufshcd_device_init()
In reply to Bart Van AsscheBoth ufshcd_device_init() callers pass 'false' as second argument. Hence, remove that second argument.
--- drivers/ufs/core/ufshcd.c | 44 +++++---------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-)
drivers/ufs/core/ufshcd.c +5 -39
@@ -298,7 +298,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);static int ufshcd_eh_host_reset_handler (struct scsi_cmnd *cmd);static int ufshcd_clear_tm_cmd (struct ufs_hba *hba,int tag);static void ufshcd_hba_exit (struct ufs_hba *hba); -static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params); +static int ufshcd_device_init (struct ufs_hba *hba);static int ufshcd_probe_hba (struct ufs_hba *hba);static int ufshcd_setup_clocks (struct ufs_hba *hba,bool on);static inline void ufshcd_add_delay_before_dme_cmd (struct ufs_hba *hba);
@@ -7713,7 +7713,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)/* Establish the link again and restore the device */ if (!err) { - err =ufshcd_device_init (hba,/*init_dev_params=*/ false); + err =ufshcd_device_init (hba);if (!err) err =ufshcd_probe_hba (hba); }
@@ -8788,9 +8788,8 @@ static int ufshcd_post_device_init(struct ufs_hba *hba)return 0 ; } -static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params) +static int ufshcd_device_init (struct ufs_hba *hba) { -struct Scsi_Host *host = hba->host;int ret; ret =ufshcd_activate_link (hba);
@@ -8798,7 +8797,7 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)return ret;/* Reconfigure MCQ upon reset */ -if (hba->mcq_enabled && !init_dev_params) { +if (hba->mcq_enabled) {ufshcd_config_mcq (hba);ufshcd_mcq_enable (hba); }
@@ -8813,39 +8812,6 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)if (ret)return ret; -/* -* Initialize UFS device parameters used by driver, these -* parameters are associated with UFS descriptors. -*/ -if (init_dev_params) { - ret =ufshcd_device_params_init (hba); -if (ret) -return ret; -if (is_mcq_supported (hba) && !hba->scsi_host_added) { -ufshcd_mcq_enable (hba); - ret =ufshcd_alloc_mcq (hba); -if (!ret) { -ufshcd_config_mcq (hba); - }else { -/* Continue with SDB mode */ -ufshcd_mcq_disable (hba); - use_mcq_mode = false; -dev_err (hba->dev,"MCQ mode is disabled, err=%d\n" , - ret); - } - ret =scsi_add_host (host, hba->dev); -if (ret) { -dev_err (hba->dev,"scsi_add_host failed\n" ); -return ret; - } - hba->scsi_host_added = true; - }else if (is_mcq_supported (hba)) { -/* UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH is set */ -ufshcd_config_mcq (hba); -ufshcd_mcq_enable (hba); - } - } -return ufshcd_post_device_init (hba); }
@@ -8879,7 +8845,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) }/* Reinit the device */ - ret =ufshcd_device_init (hba,/*init_dev_params=*/ false); + ret =ufshcd_device_init (hba);if (ret) goto out; }
Re: [PATCH v3 9/9] ufs: core: Remove the second argument of ufshcd_device_init()
It's inconvenient to review them one by one, so until the last one. I understand the main purpose is to remove init_dev_params. Why not merge all the preparation patches into the last one?
Quoted 117 lines · Bart Van Assche
Both
ufshcd_device_init()callers pass 'false' as second argument. Hence,
remove that second argument.Signed-off-by Bart Van Assche <[email protected]>---
drivers/ufs/core/ufshcd.c | 44 +++++-------------------------------- --1 file changed, 5 insertions(+), 39 deletions(-)drivers/ufs/core/ufshcd.c +1
-1@@ -298,7 +298,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba); static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd); static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag); static void ufshcd_hba_exit(struct ufs_hba *hba); -static int ufshcd_device_init (struct ufs_hba *hba,bool init_dev_params); +static int ufshcd_device_init (struct ufs_hba *hba); static int ufshcd_probe_hba(struct ufs_hba *hba);static int
ufshcd_setup_clocks(struct ufs_hba *hba, bool on); static inline voidufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);drivers/ufs/core/ufshcd.c +0
-0@@ -7713,7 +7713,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
/* Establish the link again and restore the device */ if (!err) {drivers/ufs/core/ufshcd.c +0
-1- err = ufshcd_device_init(hba,/*init_dev_params=*/false);
drivers/ufs/core/ufshcd.c +1
-0+ err =ufshcd_device_init (hba);if (!err)
err =ufshcd_probe_hba(hba); }drivers/ufs/core/ufshcd.c +0
-0@@ -8788,9 +8788,8 @@ static int ufshcd_post_device_init(struct ufs_hba *hba) return 0; }
-static intufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
+static intufshcd_device_init(struct ufs_hba *hba){drivers/ufs/core/ufshcd.c +0
-1-struct Scsi_Host *host = hba->host;int ret;
ret =ufshcd_activate_link(hba);drivers/ufs/core/ufshcd.c +0
-0@@ -8798,7 +8797,7 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) return ret;
/* Reconfigure MCQ upon reset */drivers/ufs/core/ufshcd.c +1
-1-if (hba->mcq_enabled && !init_dev_params) { +if (hba->mcq_enabled) {
ufshcd_config_mcq(hba);
ufshcd_mcq_enable(hba);
}drivers/ufs/core/ufshcd.c +0
-0@@ -8813,39 +8812,6 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params) if (ret) return ret;drivers/ufs/core/ufshcd.c +0
-9-/* -* Initialize UFS device parameters used by driver, these -* parameters are associated with UFS descriptors. -*/ -if (init_dev_params) { - ret =ufshcd_device_params_init (hba); -if (ret) -return ret; -if (is_mcq_supported (hba) && !hba->scsi_host_added){
drivers/ufs/core/ufshcd.c +0
-9-ufshcd_mcq_enable (hba); - ret =ufshcd_alloc_mcq (hba); -if (!ret) { -ufshcd_config_mcq (hba); - }else { -/* Continue with SDB mode */ -ufshcd_mcq_disable (hba); - use_mcq_mode = false; - dev_err(hba->dev, "MCQ mode isdisabled, err=%d\n",
drivers/ufs/core/ufshcd.c +0
-5- ret); - } - ret =scsi_add_host (host, hba->dev); -if (ret) { - dev_err(hba->dev, "scsi_add_hostfailed\n");
drivers/ufs/core/ufshcd.c +0
-5-return ret; - } - hba->scsi_host_added = true; - }else if (is_mcq_supported (hba)) { -/* UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH is set */
drivers/ufs/core/ufshcd.c +0
-5-ufshcd_config_mcq (hba); -ufshcd_mcq_enable (hba); - } - } -return
ufshcd_post_device_init(hba);
}drivers/ufs/core/ufshcd.c +0
-0@@ -8879,7 +8845,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) }
/* Reinit the device */drivers/ufs/core/ufshcd.c +0
-1- ret = ufshcd_device_init(hba,/*init_dev_params=*/false);
drivers/ufs/core/ufshcd.c +1
-0+ ret =ufshcd_device_init (hba);if (ret)
goto out;
}
Bart Van Assche
reviewerRe: [PATCH v3 9/9] ufs: core: Remove the second argument of ufshcd_device_init()
Quoted 3 lines · Bean Huo
It's inconvenient to review them one by one, so until the last one. I understand the main purpose is to remove
init_dev_params. Why not merge all the preparation patches into the last one?
The main purpose of this patch series is to combine the twoscsi_add_host() calls into a single call (see also the cover letter).
Something unfortunate about the current MCQ implementation is that
adding MCQ support introduced a new scsi_add_host() call far away from
the original scsi_add_host() call. Hence, there is a risk that the two code paths for adding a SCSI host in the UFS driver would start to diverge. This patch series eliminates that risk by combining the two scsi_add_host() calls into a single call.
Removing the 'init_dev_params' argument is only a secondary goal of this patch series.
I'm afraid if I would combine all nine patches into a single patch that it would be very hard to review that single patch. Additionally, the patch description would become very long. The kernel documentation says the following about long patch descriptions: "If your description starts to get long, that's a sign that you probably need to split up your patch. See :ref:split_changes."
Thanks,
Bart.