@@ -4269,8 +4269,8 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
42694269 get , UIC_GET_ATTR_ID (attr_sel ),
42704270 UFS_UIC_COMMAND_RETRIES - retries );
42714271
4272- if (mib_val && ! ret )
4273- * mib_val = uic_cmd .argument3 ;
4272+ if (mib_val )
4273+ * mib_val = ret == 0 ? uic_cmd .argument3 : 0 ;
42744274
42754275 if (peer && (hba -> quirks & UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE )
42764276 && pwr_mode_change )
@@ -4986,7 +4986,7 @@ EXPORT_SYMBOL_GPL(ufshcd_hba_enable);
49864986
49874987static int ufshcd_disable_tx_lcc (struct ufs_hba * hba , bool peer )
49884988{
4989- int tx_lanes = 0 , i , err = 0 ;
4989+ int tx_lanes , i , err = 0 ;
49904990
49914991 if (!peer )
49924992 ufshcd_dme_get (hba , UIC_ARG_MIB (PA_CONNECTEDTXDATALANES ),
@@ -5053,7 +5053,8 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
50535053 * If UFS device isn't active then we will have to issue link startup
50545054 * 2 times to make sure the device state move to active.
50555055 */
5056- if (!ufshcd_is_ufs_dev_active (hba ))
5056+ if (!(hba -> quirks & UFSHCD_QUIRK_PERFORM_LINK_STARTUP_ONCE ) &&
5057+ !ufshcd_is_ufs_dev_active (hba ))
50575058 link_startup_again = true;
50585059
50595060link_startup :
@@ -5118,12 +5119,8 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
51185119 ufshcd_readl (hba , REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER );
51195120 ret = ufshcd_make_hba_operational (hba );
51205121out :
5121- if (ret ) {
5122+ if (ret )
51225123 dev_err (hba -> dev , "link startup failed %d\n" , ret );
5123- ufshcd_print_host_state (hba );
5124- ufshcd_print_pwr_info (hba );
5125- ufshcd_print_evt_hist (hba );
5126- }
51275124 return ret ;
51285125}
51295126
@@ -6679,6 +6676,20 @@ static void ufshcd_err_handler(struct work_struct *work)
66796676 hba -> saved_uic_err , hba -> force_reset ,
66806677 ufshcd_is_link_broken (hba ) ? "; link is broken" : "" );
66816678
6679+ /*
6680+ * Use ufshcd_rpm_get_noresume() here to safely perform link recovery
6681+ * even if an error occurs during runtime suspend or runtime resume.
6682+ * This avoids potential deadlocks that could happen if we tried to
6683+ * resume the device while a PM operation is already in progress.
6684+ */
6685+ ufshcd_rpm_get_noresume (hba );
6686+ if (hba -> pm_op_in_progress ) {
6687+ ufshcd_link_recovery (hba );
6688+ ufshcd_rpm_put (hba );
6689+ return ;
6690+ }
6691+ ufshcd_rpm_put (hba );
6692+
66826693 down (& hba -> host_sem );
66836694 spin_lock_irqsave (hba -> host -> host_lock , flags );
66846695 if (ufshcd_err_handling_should_stop (hba )) {
@@ -6690,14 +6701,6 @@ static void ufshcd_err_handler(struct work_struct *work)
66906701 }
66916702 spin_unlock_irqrestore (hba -> host -> host_lock , flags );
66926703
6693- ufshcd_rpm_get_noresume (hba );
6694- if (hba -> pm_op_in_progress ) {
6695- ufshcd_link_recovery (hba );
6696- ufshcd_rpm_put (hba );
6697- return ;
6698- }
6699- ufshcd_rpm_put (hba );
6700-
67016704 ufshcd_err_handling_prepare (hba );
67026705
67036706 spin_lock_irqsave (hba -> host -> host_lock , flags );
@@ -8538,8 +8541,6 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
85388541 DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP ) &
85398542 UFS_DEV_HID_SUPPORT ;
85408543
8541- sysfs_update_group (& hba -> dev -> kobj , & ufs_sysfs_hid_group );
8542-
85438544 model_index = desc_buf [DEVICE_DESC_PARAM_PRDCT_NAME ];
85448545
85458546 err = ufshcd_read_string_desc (hba , model_index ,
@@ -10700,7 +10701,7 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba)
1070010701 * @mmio_base: base register address
1070110702 * @irq: Interrupt line of device
1070210703 *
10703- * Return: 0 on success, non-zero value on failure.
10704+ * Return: 0 on success; < 0 on failure.
1070410705 */
1070510706int ufshcd_init (struct ufs_hba * hba , void __iomem * mmio_base , unsigned int irq )
1070610707{
@@ -10939,8 +10940,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1093910940 if (err )
1094010941 goto out_disable ;
1094110942
10942- async_schedule (ufshcd_async_scan , hba );
1094310943 ufs_sysfs_add_nodes (hba -> dev );
10944+ async_schedule (ufshcd_async_scan , hba );
1094410945
1094510946 device_enable_async_suspend (dev );
1094610947 ufshcd_pm_qos_init (hba );
@@ -10950,7 +10951,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1095010951 hba -> is_irq_enabled = false;
1095110952 ufshcd_hba_exit (hba );
1095210953out_error :
10953- return err ;
10954+ return err > 0 ? - EIO : err ;
1095410955}
1095510956EXPORT_SYMBOL_GPL (ufshcd_init );
1095610957
0 commit comments