Lines Matching +full:regulator +full:- +full:booster

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2011-2013 Samsung India Software Operations
5 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
17 #include <linux/blk-pm.h>
24 #include <linux/regulator/consumer.h>
31 #include "ufshcd-priv.h"
34 #include "ufs-sysfs.h"
35 #include "ufs-debugfs.h"
36 #include "ufs-fault-injection.h"
38 #include "ufshcd-crypto.h"
77 /* maximum number of link-startup retries */
115 return hba->mcq_sup && use_mcq_mode; in is_mcq_supported()
119 …mode, "Control MCQ mode for controllers starting from UFSHCI 4.0. 1 - enable MCQ, 0 - disable MCQ.…
162 return -EINVAL; in ufshcd_dump_regs()
166 return -ENOMEM; in ufshcd_dump_regs()
213 ((h)->eh_flags |= UFSHCD_EH_IN_PROGRESS)
215 ((h)->eh_flags & UFSHCD_EH_IN_PROGRESS)
217 ((h)->eh_flags &= ~UFSHCD_EH_IN_PROGRESS)
263 return (hba->clk_gating.active_reqs || hba->outstanding_reqs || hba->outstanding_tasks || in ufshcd_is_ufs_dev_busy()
264 hba->active_uic_cmd || hba->uic_async_done); in ufshcd_is_ufs_dev_busy()
323 if (!hba->is_irq_enabled) { in ufshcd_enable_irq()
324 enable_irq(hba->irq); in ufshcd_enable_irq()
325 hba->is_irq_enabled = true; in ufshcd_enable_irq()
332 if (hba->is_irq_enabled) { in ufshcd_disable_irq()
333 disable_irq(hba->irq); in ufshcd_disable_irq()
334 hba->is_irq_enabled = false; in ufshcd_disable_irq()
354 if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt)) in ufshcd_scsi_unblock_requests()
355 scsi_unblock_requests(hba->host); in ufshcd_scsi_unblock_requests()
360 if (atomic_inc_return(&hba->scsi_block_reqs_cnt) == 1) in ufshcd_scsi_block_requests()
361 scsi_block_requests(hba->host); in ufshcd_scsi_block_requests()
367 struct utp_upiu_req *rq = hba->lrb[tag].ucd_req_ptr; in ufshcd_add_cmd_upiu_trace()
374 header = &rq->header; in ufshcd_add_cmd_upiu_trace()
376 header = &hba->lrb[tag].ucd_rsp_ptr->header; in ufshcd_add_cmd_upiu_trace()
378 trace_ufshcd_upiu(dev_name(hba->dev), str_t, header, &rq->sc.cdb, in ufshcd_add_cmd_upiu_trace()
389 trace_ufshcd_upiu(dev_name(hba->dev), str_t, &rq_rsp->header, in ufshcd_add_query_upiu_trace()
390 &rq_rsp->qr, UFS_TSF_OSF); in ufshcd_add_query_upiu_trace()
396 struct utp_task_req_desc *descp = &hba->utmrdl_base_addr[tag]; in ufshcd_add_tm_upiu_trace()
402 trace_ufshcd_upiu(dev_name(hba->dev), str_t, in ufshcd_add_tm_upiu_trace()
403 &descp->upiu_req.req_header, in ufshcd_add_tm_upiu_trace()
404 &descp->upiu_req.input_param1, in ufshcd_add_tm_upiu_trace()
407 trace_ufshcd_upiu(dev_name(hba->dev), str_t, in ufshcd_add_tm_upiu_trace()
408 &descp->upiu_rsp.rsp_header, in ufshcd_add_tm_upiu_trace()
409 &descp->upiu_rsp.output_param1, in ufshcd_add_tm_upiu_trace()
423 cmd = ucmd->command; in ufshcd_add_uic_command_trace()
427 trace_ufshcd_uic_command(dev_name(hba->dev), str_t, cmd, in ufshcd_add_uic_command_trace()
440 int hwq_id = -1; in ufshcd_add_command_trace()
441 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_add_command_trace()
442 struct scsi_cmnd *cmd = lrbp->cmd; in ufshcd_add_command_trace()
444 int transfer_len = -1; in ufshcd_add_command_trace()
454 opcode = cmd->cmnd[0]; in ufshcd_add_command_trace()
461 be32_to_cpu(lrbp->ucd_req_ptr->sc.exp_data_transfer_len); in ufshcd_add_command_trace()
464 group_id = lrbp->cmd->cmnd[6]; in ufshcd_add_command_trace()
475 if (hba->mcq_enabled) { in ufshcd_add_command_trace()
478 hwq_id = hwq->id; in ufshcd_add_command_trace()
482 trace_ufshcd_command(cmd->device, str_t, tag, doorbell, hwq_id, in ufshcd_add_command_trace()
489 struct list_head *head = &hba->clk_list_head; in ufshcd_print_clk_freqs()
495 if (!IS_ERR_OR_NULL(clki->clk) && clki->min_freq && in ufshcd_print_clk_freqs()
496 clki->max_freq) in ufshcd_print_clk_freqs()
497 dev_err(hba->dev, "clk: %s, rate: %u\n", in ufshcd_print_clk_freqs()
498 clki->name, clki->curr_freq); in ufshcd_print_clk_freqs()
512 e = &hba->ufs_stats.event[id]; in ufshcd_print_evt()
515 int p = (i + e->pos) % UFS_EVENT_HIST_LENGTH; in ufshcd_print_evt()
517 if (e->tstamp[p] == 0) in ufshcd_print_evt()
519 dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p, in ufshcd_print_evt()
520 e->val[p], div_u64(e->tstamp[p], 1000)); in ufshcd_print_evt()
525 dev_err(hba->dev, "No record of %s\n", err_name); in ufshcd_print_evt()
527 dev_err(hba->dev, "%s: total cnt=%llu\n", err_name, e->cnt); in ufshcd_print_evt()
563 lrbp = &hba->lrb[tag]; in ufshcd_print_tr()
565 dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n", in ufshcd_print_tr()
566 tag, div_u64(lrbp->issue_time_stamp_local_clock, 1000)); in ufshcd_print_tr()
567 dev_err(hba->dev, "UPIU[%d] - complete time %lld us\n", in ufshcd_print_tr()
568 tag, div_u64(lrbp->compl_time_stamp_local_clock, 1000)); in ufshcd_print_tr()
569 dev_err(hba->dev, in ufshcd_print_tr()
570 "UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n", in ufshcd_print_tr()
571 tag, (u64)lrbp->utrd_dma_addr); in ufshcd_print_tr()
573 ufshcd_hex_dump("UPIU TRD: ", lrbp->utr_descriptor_ptr, in ufshcd_print_tr()
575 dev_err(hba->dev, "UPIU[%d] - Request UPIU phys@0x%llx\n", tag, in ufshcd_print_tr()
576 (u64)lrbp->ucd_req_dma_addr); in ufshcd_print_tr()
577 ufshcd_hex_dump("UPIU REQ: ", lrbp->ucd_req_ptr, in ufshcd_print_tr()
579 dev_err(hba->dev, "UPIU[%d] - Response UPIU phys@0x%llx\n", tag, in ufshcd_print_tr()
580 (u64)lrbp->ucd_rsp_dma_addr); in ufshcd_print_tr()
581 ufshcd_hex_dump("UPIU RSP: ", lrbp->ucd_rsp_ptr, in ufshcd_print_tr()
585 lrbp->utr_descriptor_ptr->prd_table_length); in ufshcd_print_tr()
586 if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) in ufshcd_print_tr()
589 dev_err(hba->dev, in ufshcd_print_tr()
590 "UPIU[%d] - PRDT - %d entries phys@0x%llx\n", in ufshcd_print_tr()
592 (u64)lrbp->ucd_prdt_dma_addr); in ufshcd_print_tr()
595 ufshcd_hex_dump("UPIU PRDT: ", lrbp->ucd_prdt_ptr, in ufshcd_print_tr()
601 struct scsi_device *sdev = req->q->queuedata; in ufshcd_print_tr_iter()
602 struct Scsi_Host *shost = sdev->host; in ufshcd_print_tr_iter()
605 ufshcd_print_tr(hba, req->tag, *(bool *)priv); in ufshcd_print_tr_iter()
611 * ufshcd_print_trs_all - print trs for all started requests.
612 * @hba: per-adapter instance.
617 blk_mq_tagset_busy_iter(&hba->host->tag_set, ufshcd_print_tr_iter, &pr_prdt); in ufshcd_print_trs_all()
624 for_each_set_bit(tag, &bitmap, hba->nutmrs) { in ufshcd_print_tmrs()
625 struct utp_task_req_desc *tmrdp = &hba->utmrdl_base_addr[tag]; in ufshcd_print_tmrs()
627 dev_err(hba->dev, "TM[%d] - Task Management Header\n", tag); in ufshcd_print_tmrs()
634 const struct scsi_device *sdev_ufs = hba->ufs_device_wlun; in ufshcd_print_host_state()
636 dev_err(hba->dev, "UFS Host state=%d\n", hba->ufshcd_state); in ufshcd_print_host_state()
637 dev_err(hba->dev, "outstanding reqs=0x%lx tasks=0x%lx\n", in ufshcd_print_host_state()
638 hba->outstanding_reqs, hba->outstanding_tasks); in ufshcd_print_host_state()
639 dev_err(hba->dev, "saved_err=0x%x, saved_uic_err=0x%x\n", in ufshcd_print_host_state()
640 hba->saved_err, hba->saved_uic_err); in ufshcd_print_host_state()
641 dev_err(hba->dev, "Device power mode=%d, UIC link state=%d\n", in ufshcd_print_host_state()
642 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_print_host_state()
643 dev_err(hba->dev, "PM in progress=%d, sys. suspended=%d\n", in ufshcd_print_host_state()
644 hba->pm_op_in_progress, hba->is_sys_suspended); in ufshcd_print_host_state()
645 dev_err(hba->dev, "Auto BKOPS=%d, Host self-block=%d\n", in ufshcd_print_host_state()
646 hba->auto_bkops_enabled, hba->host->host_self_blocked); in ufshcd_print_host_state()
647 dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state); in ufshcd_print_host_state()
648 dev_err(hba->dev, in ufshcd_print_host_state()
650 div_u64(hba->ufs_stats.last_hibern8_exit_tstamp, 1000), in ufshcd_print_host_state()
651 hba->ufs_stats.hibern8_exit_cnt); in ufshcd_print_host_state()
652 dev_err(hba->dev, "last intr at %lld us, last intr status=0x%x\n", in ufshcd_print_host_state()
653 div_u64(hba->ufs_stats.last_intr_ts, 1000), in ufshcd_print_host_state()
654 hba->ufs_stats.last_intr_status); in ufshcd_print_host_state()
655 dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n", in ufshcd_print_host_state()
656 hba->eh_flags, hba->req_abort_count); in ufshcd_print_host_state()
657 dev_err(hba->dev, "hba->ufs_version=0x%x, Host capabilities=0x%x, caps=0x%x\n", in ufshcd_print_host_state()
658 hba->ufs_version, hba->capabilities, hba->caps); in ufshcd_print_host_state()
659 dev_err(hba->dev, "quirks=0x%x, dev. quirks=0x%x\n", hba->quirks, in ufshcd_print_host_state()
660 hba->dev_quirks); in ufshcd_print_host_state()
662 dev_err(hba->dev, "UFS dev info: %.8s %.16s rev %.4s\n", in ufshcd_print_host_state()
663 sdev_ufs->vendor, sdev_ufs->model, sdev_ufs->rev); in ufshcd_print_host_state()
669 * ufshcd_print_pwr_info - print power params as saved in hba
671 * @hba: per-adapter instance
687 * never-ending cycles of messages written back to storage by user space in ufshcd_print_pwr_info()
690 dev_dbg(hba->dev, "%s:[RX, TX]: gear=[%d, %d], lane[%d, %d], pwr[%s, %s], rate = %d\n", in ufshcd_print_pwr_info()
692 hba->pwr_info.gear_rx, hba->pwr_info.gear_tx, in ufshcd_print_pwr_info()
693 hba->pwr_info.lane_rx, hba->pwr_info.lane_tx, in ufshcd_print_pwr_info()
694 names[hba->pwr_info.pwr_rx], in ufshcd_print_pwr_info()
695 names[hba->pwr_info.pwr_tx], in ufshcd_print_pwr_info()
696 hba->pwr_info.hs_rate); in ufshcd_print_pwr_info()
708 hba->dev_info.wb_enabled = false; in ufshcd_device_reset()
709 hba->dev_info.wb_buf_flush_enabled = false; in ufshcd_device_reset()
711 if (hba->dev_info.rtc_type == UFS_RTC_RELATIVE) in ufshcd_device_reset()
712 hba->dev_info.rtc_time_baseline = 0; in ufshcd_device_reset()
714 if (err != -EOPNOTSUPP) in ufshcd_device_reset()
731 * ufshcd_wait_for_register - wait for register value to change
732 * @hba: per-adapter interface
739 * Return: -ETIMEDOUT on error, zero on success.
755 err = -ETIMEDOUT; in ufshcd_wait_for_register()
764 * ufshcd_get_intr_mask - Get the interrupt bit mask
771 if (hba->ufs_version <= ufshci_version(2, 0)) in ufshcd_get_intr_mask()
778 * ufshcd_get_ufs_version - Get the UFS version supported by the HBA
787 if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION) in ufshcd_get_ufs_version()
804 * ufshcd_is_device_present - Check if any device connected to
816 * ufshcd_get_tr_ocs - Get the UTRD Overall Command Status
828 return le32_to_cpu(cqe->status) & MASK_OCS; in ufshcd_get_tr_ocs()
830 return lrbp->utr_descriptor_ptr->header.ocs & MASK_OCS; in ufshcd_get_tr_ocs()
834 * ufshcd_utrl_clear() - Clear requests from the controller request list.
840 if (hba->quirks & UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR) in ufshcd_utrl_clear()
859 * ufshcd_utmrl_clear - Clear a bit in UTMRLCLR register
865 if (hba->quirks & UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR) in ufshcd_utmrl_clear()
872 * ufshcd_get_lists_status - Check UCRDY, UTRLRDY and UTMRLRDY
883 * ufshcd_get_uic_cmd_result - Get the UIC command result
888 * Return: 0 on success; non-zero value on error.
897 * ufshcd_get_dme_attr_val - Get the value of attribute returned by UIC command
902 * Return: 0 on success; non-zero value on error.
910 * ufshcd_get_req_rsp - returns the TR response transaction type
918 return ucd_rsp_ptr->header.transaction_code; in ufshcd_get_req_rsp()
922 * ufshcd_is_exception_event - Check if the device raised an exception event
932 return ucd_rsp_ptr->header.device_information & 1; in ufshcd_is_exception_event()
936 * ufshcd_reset_intr_aggr - Reset interrupt aggregation values.
948 * ufshcd_config_intr_aggr - Configure interrupt aggregation values.
963 * ufshcd_disable_intr_aggr - Disables interrupt aggregation.
972 * ufshcd_enable_run_stop_reg - Enable run-stop registers,
973 * When run-stop registers are set to 1, it indicates the
986 * ufshcd_hba_start - Start controller initialization sequence
1000 * ufshcd_is_hba_active - Get controller state
1012 * ufshcd_pm_qos_init - initialize PM QoS request
1018 if (hba->pm_qos_enabled) in ufshcd_pm_qos_init()
1021 cpu_latency_qos_add_request(&hba->pm_qos_req, PM_QOS_DEFAULT_VALUE); in ufshcd_pm_qos_init()
1023 if (cpu_latency_qos_request_active(&hba->pm_qos_req)) in ufshcd_pm_qos_init()
1024 hba->pm_qos_enabled = true; in ufshcd_pm_qos_init()
1028 * ufshcd_pm_qos_exit - remove request from PM QoS
1033 if (!hba->pm_qos_enabled) in ufshcd_pm_qos_exit()
1036 cpu_latency_qos_remove_request(&hba->pm_qos_req); in ufshcd_pm_qos_exit()
1037 hba->pm_qos_enabled = false; in ufshcd_pm_qos_exit()
1041 * ufshcd_pm_qos_update - update PM QoS request
1047 if (!hba->pm_qos_enabled) in ufshcd_pm_qos_update()
1050 cpu_latency_qos_update_request(&hba->pm_qos_req, on ? 0 : PM_QOS_DEFAULT_VALUE); in ufshcd_pm_qos_update()
1054 * ufshcd_set_clk_freq - set UFS controller clock frequencies
1064 struct list_head *head = &hba->clk_list_head; in ufshcd_set_clk_freq()
1070 if (!IS_ERR_OR_NULL(clki->clk)) { in ufshcd_set_clk_freq()
1071 if (scale_up && clki->max_freq) { in ufshcd_set_clk_freq()
1072 if (clki->curr_freq == clki->max_freq) in ufshcd_set_clk_freq()
1075 ret = clk_set_rate(clki->clk, clki->max_freq); in ufshcd_set_clk_freq()
1077 dev_err(hba->dev, "%s: %s clk set rate(%dHz) failed, %d\n", in ufshcd_set_clk_freq()
1078 __func__, clki->name, in ufshcd_set_clk_freq()
1079 clki->max_freq, ret); in ufshcd_set_clk_freq()
1082 trace_ufshcd_clk_scaling(dev_name(hba->dev), in ufshcd_set_clk_freq()
1083 "scaled up", clki->name, in ufshcd_set_clk_freq()
1084 clki->curr_freq, in ufshcd_set_clk_freq()
1085 clki->max_freq); in ufshcd_set_clk_freq()
1087 clki->curr_freq = clki->max_freq; in ufshcd_set_clk_freq()
1089 } else if (!scale_up && clki->min_freq) { in ufshcd_set_clk_freq()
1090 if (clki->curr_freq == clki->min_freq) in ufshcd_set_clk_freq()
1093 ret = clk_set_rate(clki->clk, clki->min_freq); in ufshcd_set_clk_freq()
1095 dev_err(hba->dev, "%s: %s clk set rate(%dHz) failed, %d\n", in ufshcd_set_clk_freq()
1096 __func__, clki->name, in ufshcd_set_clk_freq()
1097 clki->min_freq, ret); in ufshcd_set_clk_freq()
1100 trace_ufshcd_clk_scaling(dev_name(hba->dev), in ufshcd_set_clk_freq()
1101 "scaled down", clki->name, in ufshcd_set_clk_freq()
1102 clki->curr_freq, in ufshcd_set_clk_freq()
1103 clki->min_freq); in ufshcd_set_clk_freq()
1104 clki->curr_freq = clki->min_freq; in ufshcd_set_clk_freq()
1107 dev_dbg(hba->dev, "%s: clk: %s, rate: %lu\n", __func__, in ufshcd_set_clk_freq()
1108 clki->name, clk_get_rate(clki->clk)); in ufshcd_set_clk_freq()
1120 struct list_head *head = &hba->clk_list_head; in ufshcd_opp_config_clks()
1127 if (!IS_ERR_OR_NULL(clki->clk)) { in ufshcd_opp_config_clks()
1134 ret = clk_set_rate(clki->clk, freq); in ufshcd_opp_config_clks()
1137 __func__, clki->name, freq, ret); in ufshcd_opp_config_clks()
1143 clki->name, hba->clk_scaling.target_freq, freq); in ufshcd_opp_config_clks()
1156 opp = dev_pm_opp_find_freq_floor_indexed(hba->dev, in ufshcd_opp_set_rate()
1161 ret = dev_pm_opp_set_opp(hba->dev, opp); in ufshcd_opp_set_rate()
1168 * ufshcd_scale_clks - scale up or scale down UFS controller clocks
1185 if (hba->use_pm_opp) in ufshcd_scale_clks()
1194 if (hba->use_pm_opp) in ufshcd_scale_clks()
1196 hba->devfreq->previous_freq); in ufshcd_scale_clks()
1205 trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), in ufshcd_scale_clks()
1212 * ufshcd_is_devfreq_scaling_required - check if scaling is required or not
1223 struct list_head *head = &hba->clk_list_head; in ufshcd_is_devfreq_scaling_required()
1228 if (hba->use_pm_opp) in ufshcd_is_devfreq_scaling_required()
1229 return freq != hba->clk_scaling.target_freq; in ufshcd_is_devfreq_scaling_required()
1232 if (!IS_ERR_OR_NULL(clki->clk)) { in ufshcd_is_devfreq_scaling_required()
1233 if (scale_up && clki->max_freq) { in ufshcd_is_devfreq_scaling_required()
1234 if (clki->curr_freq == clki->max_freq) in ufshcd_is_devfreq_scaling_required()
1237 } else if (!scale_up && clki->min_freq) { in ufshcd_is_devfreq_scaling_required()
1238 if (clki->curr_freq == clki->min_freq) in ufshcd_is_devfreq_scaling_required()
1260 lockdep_assert_held(hba->host->host_lock); in ufshcd_pending_cmds()
1261 __shost_for_each_device(sdev, hba->host) in ufshcd_pending_cmds()
1262 pending += sbitmap_weight(&sdev->budget_map); in ufshcd_pending_cmds()
1271 * Return: 0 upon success; -EBUSY upon timeout.
1284 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_wait_for_doorbell_clr()
1291 if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { in ufshcd_wait_for_doorbell_clr()
1292 ret = -EBUSY; in ufshcd_wait_for_doorbell_clr()
1305 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_wait_for_doorbell_clr()
1317 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_wait_for_doorbell_clr()
1321 dev_err(hba->dev, in ufshcd_wait_for_doorbell_clr()
1324 ret = -EBUSY; in ufshcd_wait_for_doorbell_clr()
1327 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_wait_for_doorbell_clr()
1333 * ufshcd_scale_gear - scale up/down UFS gear
1337 * Return: 0 for success; -EBUSY if scaling can't happen at this time;
1338 * non-zero for any other errors.
1346 memcpy(&new_pwr_info, &hba->clk_scaling.saved_pwr_info, in ufshcd_scale_gear()
1349 memcpy(&new_pwr_info, &hba->pwr_info, in ufshcd_scale_gear()
1352 if (hba->pwr_info.gear_tx > hba->clk_scaling.min_gear || in ufshcd_scale_gear()
1353 hba->pwr_info.gear_rx > hba->clk_scaling.min_gear) { in ufshcd_scale_gear()
1355 memcpy(&hba->clk_scaling.saved_pwr_info, in ufshcd_scale_gear()
1356 &hba->pwr_info, in ufshcd_scale_gear()
1360 new_pwr_info.gear_tx = hba->clk_scaling.min_gear; in ufshcd_scale_gear()
1361 new_pwr_info.gear_rx = hba->clk_scaling.min_gear; in ufshcd_scale_gear()
1368 dev_err(hba->dev, "%s: failed err %d, old gear: (tx %d rx %d), new gear: (tx %d rx %d)", in ufshcd_scale_gear()
1370 hba->pwr_info.gear_tx, hba->pwr_info.gear_rx, in ufshcd_scale_gear()
1380 * Return: 0 upon success; -EBUSY upon timeout.
1389 blk_mq_quiesce_tagset(&hba->host->tag_set); in ufshcd_clock_scaling_prepare()
1390 mutex_lock(&hba->wb_mutex); in ufshcd_clock_scaling_prepare()
1391 down_write(&hba->clk_scaling_lock); in ufshcd_clock_scaling_prepare()
1393 if (!hba->clk_scaling.is_allowed || in ufshcd_clock_scaling_prepare()
1395 ret = -EBUSY; in ufshcd_clock_scaling_prepare()
1396 up_write(&hba->clk_scaling_lock); in ufshcd_clock_scaling_prepare()
1397 mutex_unlock(&hba->wb_mutex); in ufshcd_clock_scaling_prepare()
1398 blk_mq_unquiesce_tagset(&hba->host->tag_set); in ufshcd_clock_scaling_prepare()
1411 up_write(&hba->clk_scaling_lock); in ufshcd_clock_scaling_unprepare()
1413 /* Enable Write Booster if we have scaled up else disable it */ in ufshcd_clock_scaling_unprepare()
1417 mutex_unlock(&hba->wb_mutex); in ufshcd_clock_scaling_unprepare()
1419 blk_mq_unquiesce_tagset(&hba->host->tag_set); in ufshcd_clock_scaling_unprepare()
1424 * ufshcd_devfreq_scale - scale up/down UFS clocks and gear
1429 * Return: 0 for success; -EBUSY if scaling can't happen at this time; non-zero
1459 ufshcd_scale_clks(hba, hba->devfreq->previous_freq, in ufshcd_devfreq_scale()
1476 spin_lock_irqsave(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_suspend_work()
1477 if (hba->clk_scaling.active_reqs || hba->clk_scaling.is_suspended) { in ufshcd_clk_scaling_suspend_work()
1478 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_suspend_work()
1481 hba->clk_scaling.is_suspended = true; in ufshcd_clk_scaling_suspend_work()
1482 hba->clk_scaling.window_start_t = 0; in ufshcd_clk_scaling_suspend_work()
1483 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_suspend_work()
1485 devfreq_suspend_device(hba->devfreq); in ufshcd_clk_scaling_suspend_work()
1494 spin_lock_irqsave(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_resume_work()
1495 if (!hba->clk_scaling.is_suspended) { in ufshcd_clk_scaling_resume_work()
1496 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_resume_work()
1499 hba->clk_scaling.is_suspended = false; in ufshcd_clk_scaling_resume_work()
1500 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_clk_scaling_resume_work()
1502 devfreq_resume_device(hba->devfreq); in ufshcd_clk_scaling_resume_work()
1512 struct list_head *clk_list = &hba->clk_list_head; in ufshcd_devfreq_target()
1517 return -EINVAL; in ufshcd_devfreq_target()
1519 if (hba->use_pm_opp) { in ufshcd_devfreq_target()
1530 clki = list_first_entry(&hba->clk_list_head, struct ufs_clk_info, in ufshcd_devfreq_target()
1532 *freq = (unsigned long) clk_round_rate(clki->clk, *freq); in ufshcd_devfreq_target()
1535 spin_lock_irqsave(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1537 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1542 if (hba->clk_scaling.is_suspended) { in ufshcd_devfreq_target()
1543 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1544 dev_warn(hba->dev, "clock scaling is suspended, skip"); in ufshcd_devfreq_target()
1548 if (!hba->clk_scaling.active_reqs) in ufshcd_devfreq_target()
1552 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1556 /* Decide based on the target or rounded-off frequency and update */ in ufshcd_devfreq_target()
1557 if (hba->use_pm_opp) in ufshcd_devfreq_target()
1558 scale_up = *freq > hba->clk_scaling.target_freq; in ufshcd_devfreq_target()
1560 scale_up = *freq == clki->max_freq; in ufshcd_devfreq_target()
1562 if (!hba->use_pm_opp && !scale_up) in ufshcd_devfreq_target()
1563 *freq = clki->min_freq; in ufshcd_devfreq_target()
1567 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1571 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); in ufshcd_devfreq_target()
1576 hba->clk_scaling.target_freq = *freq; in ufshcd_devfreq_target()
1578 trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), in ufshcd_devfreq_target()
1584 (!scale_up || hba->clk_scaling.suspend_on_no_request)) in ufshcd_devfreq_target()
1585 queue_work(hba->clk_scaling.workq, in ufshcd_devfreq_target()
1586 &hba->clk_scaling.suspend_work); in ufshcd_devfreq_target()
1595 struct ufs_clk_scaling *scaling = &hba->clk_scaling; in ufshcd_devfreq_get_dev_status()
1600 return -EINVAL; in ufshcd_devfreq_get_dev_status()
1604 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_devfreq_get_dev_status()
1606 if (!scaling->window_start_t) in ufshcd_devfreq_get_dev_status()
1614 if (hba->use_pm_opp) { in ufshcd_devfreq_get_dev_status()
1615 stat->current_frequency = hba->clk_scaling.target_freq; in ufshcd_devfreq_get_dev_status()
1617 struct list_head *clk_list = &hba->clk_list_head; in ufshcd_devfreq_get_dev_status()
1621 stat->current_frequency = clki->curr_freq; in ufshcd_devfreq_get_dev_status()
1624 if (scaling->is_busy_started) in ufshcd_devfreq_get_dev_status()
1625 scaling->tot_busy_t += ktime_us_delta(curr_t, in ufshcd_devfreq_get_dev_status()
1626 scaling->busy_start_t); in ufshcd_devfreq_get_dev_status()
1627 stat->total_time = ktime_us_delta(curr_t, scaling->window_start_t); in ufshcd_devfreq_get_dev_status()
1628 stat->busy_time = scaling->tot_busy_t; in ufshcd_devfreq_get_dev_status()
1630 scaling->window_start_t = curr_t; in ufshcd_devfreq_get_dev_status()
1631 scaling->tot_busy_t = 0; in ufshcd_devfreq_get_dev_status()
1633 if (scaling->active_reqs) { in ufshcd_devfreq_get_dev_status()
1634 scaling->busy_start_t = curr_t; in ufshcd_devfreq_get_dev_status()
1635 scaling->is_busy_started = true; in ufshcd_devfreq_get_dev_status()
1637 scaling->busy_start_t = 0; in ufshcd_devfreq_get_dev_status()
1638 scaling->is_busy_started = false; in ufshcd_devfreq_get_dev_status()
1640 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_devfreq_get_dev_status()
1646 struct list_head *clk_list = &hba->clk_list_head; in ufshcd_devfreq_init()
1655 if (!hba->use_pm_opp) { in ufshcd_devfreq_init()
1657 dev_pm_opp_add(hba->dev, clki->min_freq, 0); in ufshcd_devfreq_init()
1658 dev_pm_opp_add(hba->dev, clki->max_freq, 0); in ufshcd_devfreq_init()
1661 ufshcd_vops_config_scaling_param(hba, &hba->vps->devfreq_profile, in ufshcd_devfreq_init()
1662 &hba->vps->ondemand_data); in ufshcd_devfreq_init()
1663 devfreq = devfreq_add_device(hba->dev, in ufshcd_devfreq_init()
1664 &hba->vps->devfreq_profile, in ufshcd_devfreq_init()
1666 &hba->vps->ondemand_data); in ufshcd_devfreq_init()
1669 dev_err(hba->dev, "Unable to register with devfreq %d\n", ret); in ufshcd_devfreq_init()
1671 if (!hba->use_pm_opp) { in ufshcd_devfreq_init()
1672 dev_pm_opp_remove(hba->dev, clki->min_freq); in ufshcd_devfreq_init()
1673 dev_pm_opp_remove(hba->dev, clki->max_freq); in ufshcd_devfreq_init()
1678 hba->devfreq = devfreq; in ufshcd_devfreq_init()
1685 struct list_head *clk_list = &hba->clk_list_head; in ufshcd_devfreq_remove()
1687 if (!hba->devfreq) in ufshcd_devfreq_remove()
1690 devfreq_remove_device(hba->devfreq); in ufshcd_devfreq_remove()
1691 hba->devfreq = NULL; in ufshcd_devfreq_remove()
1693 if (!hba->use_pm_opp) { in ufshcd_devfreq_remove()
1697 dev_pm_opp_remove(hba->dev, clki->min_freq); in ufshcd_devfreq_remove()
1698 dev_pm_opp_remove(hba->dev, clki->max_freq); in ufshcd_devfreq_remove()
1707 cancel_work_sync(&hba->clk_scaling.suspend_work); in ufshcd_suspend_clkscaling()
1708 cancel_work_sync(&hba->clk_scaling.resume_work); in ufshcd_suspend_clkscaling()
1710 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_suspend_clkscaling()
1711 if (!hba->clk_scaling.is_suspended) { in ufshcd_suspend_clkscaling()
1713 hba->clk_scaling.is_suspended = true; in ufshcd_suspend_clkscaling()
1714 hba->clk_scaling.window_start_t = 0; in ufshcd_suspend_clkscaling()
1716 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_suspend_clkscaling()
1719 devfreq_suspend_device(hba->devfreq); in ufshcd_suspend_clkscaling()
1727 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_resume_clkscaling()
1728 if (hba->clk_scaling.is_suspended) { in ufshcd_resume_clkscaling()
1730 hba->clk_scaling.is_suspended = false; in ufshcd_resume_clkscaling()
1732 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_resume_clkscaling()
1735 devfreq_resume_device(hba->devfreq); in ufshcd_resume_clkscaling()
1743 return sysfs_emit(buf, "%d\n", hba->clk_scaling.is_enabled); in ufshcd_clkscale_enable_show()
1754 return -EINVAL; in ufshcd_clkscale_enable_store()
1756 down(&hba->host_sem); in ufshcd_clkscale_enable_store()
1758 err = -EBUSY; in ufshcd_clkscale_enable_store()
1763 if (value == hba->clk_scaling.is_enabled) in ufshcd_clkscale_enable_store()
1769 hba->clk_scaling.is_enabled = value; in ufshcd_clkscale_enable_store()
1777 dev_err(hba->dev, "%s: failed to scale clocks up %d\n", in ufshcd_clkscale_enable_store()
1784 up(&hba->host_sem); in ufshcd_clkscale_enable_store()
1790 hba->clk_scaling.enable_attr.show = ufshcd_clkscale_enable_show; in ufshcd_init_clk_scaling_sysfs()
1791 hba->clk_scaling.enable_attr.store = ufshcd_clkscale_enable_store; in ufshcd_init_clk_scaling_sysfs()
1792 sysfs_attr_init(&hba->clk_scaling.enable_attr.attr); in ufshcd_init_clk_scaling_sysfs()
1793 hba->clk_scaling.enable_attr.attr.name = "clkscale_enable"; in ufshcd_init_clk_scaling_sysfs()
1794 hba->clk_scaling.enable_attr.attr.mode = 0644; in ufshcd_init_clk_scaling_sysfs()
1795 if (device_create_file(hba->dev, &hba->clk_scaling.enable_attr)) in ufshcd_init_clk_scaling_sysfs()
1796 dev_err(hba->dev, "Failed to create sysfs for clkscale_enable\n"); in ufshcd_init_clk_scaling_sysfs()
1801 if (hba->clk_scaling.enable_attr.attr.name) in ufshcd_remove_clk_scaling_sysfs()
1802 device_remove_file(hba->dev, &hba->clk_scaling.enable_attr); in ufshcd_remove_clk_scaling_sysfs()
1810 if (!hba->clk_scaling.min_gear) in ufshcd_init_clk_scaling()
1811 hba->clk_scaling.min_gear = UFS_HS_G1; in ufshcd_init_clk_scaling()
1813 INIT_WORK(&hba->clk_scaling.suspend_work, in ufshcd_init_clk_scaling()
1815 INIT_WORK(&hba->clk_scaling.resume_work, in ufshcd_init_clk_scaling()
1818 hba->clk_scaling.workq = alloc_ordered_workqueue( in ufshcd_init_clk_scaling()
1819 "ufs_clkscaling_%d", WQ_MEM_RECLAIM, hba->host->host_no); in ufshcd_init_clk_scaling()
1821 hba->clk_scaling.is_initialized = true; in ufshcd_init_clk_scaling()
1826 if (!hba->clk_scaling.is_initialized) in ufshcd_exit_clk_scaling()
1830 destroy_workqueue(hba->clk_scaling.workq); in ufshcd_exit_clk_scaling()
1832 hba->clk_scaling.is_initialized = false; in ufshcd_exit_clk_scaling()
1842 cancel_delayed_work_sync(&hba->clk_gating.gate_work); in ufshcd_ungate_work()
1844 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_ungate_work()
1845 if (hba->clk_gating.state == CLKS_ON) { in ufshcd_ungate_work()
1846 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_ungate_work()
1850 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_ungate_work()
1859 hba->clk_gating.is_suspended = true; in ufshcd_ungate_work()
1863 dev_err(hba->dev, "%s: hibern8 exit failed %d\n", in ufshcd_ungate_work()
1868 hba->clk_gating.is_suspended = false; in ufshcd_ungate_work()
1873 * ufshcd_hold - Enable clocks that were gated earlier due to ufshcd_release.
1883 !hba->clk_gating.is_initialized) in ufshcd_hold()
1885 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_hold()
1886 hba->clk_gating.active_reqs++; in ufshcd_hold()
1889 switch (hba->clk_gating.state) { in ufshcd_hold()
1901 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_hold()
1902 flush_result = flush_work(&hba->clk_gating.ungate_work); in ufshcd_hold()
1903 if (hba->clk_gating.is_suspended && !flush_result) in ufshcd_hold()
1905 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_hold()
1910 if (cancel_delayed_work(&hba->clk_gating.gate_work)) { in ufshcd_hold()
1911 hba->clk_gating.state = CLKS_ON; in ufshcd_hold()
1912 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_hold()
1913 hba->clk_gating.state); in ufshcd_hold()
1923 hba->clk_gating.state = REQ_CLKS_ON; in ufshcd_hold()
1924 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_hold()
1925 hba->clk_gating.state); in ufshcd_hold()
1926 queue_work(hba->clk_gating.clk_gating_workq, in ufshcd_hold()
1927 &hba->clk_gating.ungate_work); in ufshcd_hold()
1934 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_hold()
1935 flush_work(&hba->clk_gating.ungate_work); in ufshcd_hold()
1937 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_hold()
1940 dev_err(hba->dev, "%s: clk gating is in invalid state %d\n", in ufshcd_hold()
1941 __func__, hba->clk_gating.state); in ufshcd_hold()
1944 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_hold()
1955 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_gate_work()
1962 if (hba->clk_gating.is_suspended || in ufshcd_gate_work()
1963 (hba->clk_gating.state != REQ_CLKS_OFF)) { in ufshcd_gate_work()
1964 hba->clk_gating.state = CLKS_ON; in ufshcd_gate_work()
1965 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_gate_work()
1966 hba->clk_gating.state); in ufshcd_gate_work()
1970 if (ufshcd_is_ufs_dev_busy(hba) || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) in ufshcd_gate_work()
1973 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_gate_work()
1979 hba->clk_gating.state = CLKS_ON; in ufshcd_gate_work()
1980 dev_err(hba->dev, "%s: hibern8 enter failed %d\n", in ufshcd_gate_work()
1982 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_gate_work()
1983 hba->clk_gating.state); in ufshcd_gate_work()
2004 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_gate_work()
2005 if (hba->clk_gating.state == REQ_CLKS_OFF) { in ufshcd_gate_work()
2006 hba->clk_gating.state = CLKS_OFF; in ufshcd_gate_work()
2007 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_gate_work()
2008 hba->clk_gating.state); in ufshcd_gate_work()
2011 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_gate_work()
2022 hba->clk_gating.active_reqs--; in __ufshcd_release()
2024 if (hba->clk_gating.active_reqs || hba->clk_gating.is_suspended || in __ufshcd_release()
2025 hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL || in __ufshcd_release()
2026 hba->outstanding_tasks || !hba->clk_gating.is_initialized || in __ufshcd_release()
2027 hba->active_uic_cmd || hba->uic_async_done || in __ufshcd_release()
2028 hba->clk_gating.state == CLKS_OFF) in __ufshcd_release()
2031 hba->clk_gating.state = REQ_CLKS_OFF; in __ufshcd_release()
2032 trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state); in __ufshcd_release()
2033 queue_delayed_work(hba->clk_gating.clk_gating_workq, in __ufshcd_release()
2034 &hba->clk_gating.gate_work, in __ufshcd_release()
2035 msecs_to_jiffies(hba->clk_gating.delay_ms)); in __ufshcd_release()
2042 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_release()
2044 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_release()
2053 return sysfs_emit(buf, "%lu\n", hba->clk_gating.delay_ms); in ufshcd_clkgate_delay_show()
2061 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clkgate_delay_set()
2062 hba->clk_gating.delay_ms = value; in ufshcd_clkgate_delay_set()
2063 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clkgate_delay_set()
2073 return -EINVAL; in ufshcd_clkgate_delay_store()
2084 return sysfs_emit(buf, "%d\n", hba->clk_gating.is_enabled); in ufshcd_clkgate_enable_show()
2095 return -EINVAL; in ufshcd_clkgate_enable_store()
2099 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clkgate_enable_store()
2100 if (value == hba->clk_gating.is_enabled) in ufshcd_clkgate_enable_store()
2106 hba->clk_gating.active_reqs++; in ufshcd_clkgate_enable_store()
2108 hba->clk_gating.is_enabled = value; in ufshcd_clkgate_enable_store()
2110 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clkgate_enable_store()
2116 hba->clk_gating.delay_attr.show = ufshcd_clkgate_delay_show; in ufshcd_init_clk_gating_sysfs()
2117 hba->clk_gating.delay_attr.store = ufshcd_clkgate_delay_store; in ufshcd_init_clk_gating_sysfs()
2118 sysfs_attr_init(&hba->clk_gating.delay_attr.attr); in ufshcd_init_clk_gating_sysfs()
2119 hba->clk_gating.delay_attr.attr.name = "clkgate_delay_ms"; in ufshcd_init_clk_gating_sysfs()
2120 hba->clk_gating.delay_attr.attr.mode = 0644; in ufshcd_init_clk_gating_sysfs()
2121 if (device_create_file(hba->dev, &hba->clk_gating.delay_attr)) in ufshcd_init_clk_gating_sysfs()
2122 dev_err(hba->dev, "Failed to create sysfs for clkgate_delay\n"); in ufshcd_init_clk_gating_sysfs()
2124 hba->clk_gating.enable_attr.show = ufshcd_clkgate_enable_show; in ufshcd_init_clk_gating_sysfs()
2125 hba->clk_gating.enable_attr.store = ufshcd_clkgate_enable_store; in ufshcd_init_clk_gating_sysfs()
2126 sysfs_attr_init(&hba->clk_gating.enable_attr.attr); in ufshcd_init_clk_gating_sysfs()
2127 hba->clk_gating.enable_attr.attr.name = "clkgate_enable"; in ufshcd_init_clk_gating_sysfs()
2128 hba->clk_gating.enable_attr.attr.mode = 0644; in ufshcd_init_clk_gating_sysfs()
2129 if (device_create_file(hba->dev, &hba->clk_gating.enable_attr)) in ufshcd_init_clk_gating_sysfs()
2130 dev_err(hba->dev, "Failed to create sysfs for clkgate_enable\n"); in ufshcd_init_clk_gating_sysfs()
2135 if (hba->clk_gating.delay_attr.attr.name) in ufshcd_remove_clk_gating_sysfs()
2136 device_remove_file(hba->dev, &hba->clk_gating.delay_attr); in ufshcd_remove_clk_gating_sysfs()
2137 if (hba->clk_gating.enable_attr.attr.name) in ufshcd_remove_clk_gating_sysfs()
2138 device_remove_file(hba->dev, &hba->clk_gating.enable_attr); in ufshcd_remove_clk_gating_sysfs()
2146 hba->clk_gating.state = CLKS_ON; in ufshcd_init_clk_gating()
2148 hba->clk_gating.delay_ms = 150; in ufshcd_init_clk_gating()
2149 INIT_DELAYED_WORK(&hba->clk_gating.gate_work, ufshcd_gate_work); in ufshcd_init_clk_gating()
2150 INIT_WORK(&hba->clk_gating.ungate_work, ufshcd_ungate_work); in ufshcd_init_clk_gating()
2152 hba->clk_gating.clk_gating_workq = alloc_ordered_workqueue( in ufshcd_init_clk_gating()
2154 hba->host->host_no); in ufshcd_init_clk_gating()
2158 hba->clk_gating.is_enabled = true; in ufshcd_init_clk_gating()
2159 hba->clk_gating.is_initialized = true; in ufshcd_init_clk_gating()
2164 if (!hba->clk_gating.is_initialized) in ufshcd_exit_clk_gating()
2171 hba->clk_gating.is_initialized = false; in ufshcd_exit_clk_gating()
2174 destroy_workqueue(hba->clk_gating.clk_gating_workq); in ufshcd_exit_clk_gating()
2186 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clk_scaling_start_busy()
2187 if (!hba->clk_scaling.active_reqs++) in ufshcd_clk_scaling_start_busy()
2190 if (!hba->clk_scaling.is_enabled || hba->pm_op_in_progress) { in ufshcd_clk_scaling_start_busy()
2191 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clk_scaling_start_busy()
2196 queue_work(hba->clk_scaling.workq, in ufshcd_clk_scaling_start_busy()
2197 &hba->clk_scaling.resume_work); in ufshcd_clk_scaling_start_busy()
2199 if (!hba->clk_scaling.window_start_t) { in ufshcd_clk_scaling_start_busy()
2200 hba->clk_scaling.window_start_t = curr_t; in ufshcd_clk_scaling_start_busy()
2201 hba->clk_scaling.tot_busy_t = 0; in ufshcd_clk_scaling_start_busy()
2202 hba->clk_scaling.is_busy_started = false; in ufshcd_clk_scaling_start_busy()
2205 if (!hba->clk_scaling.is_busy_started) { in ufshcd_clk_scaling_start_busy()
2206 hba->clk_scaling.busy_start_t = curr_t; in ufshcd_clk_scaling_start_busy()
2207 hba->clk_scaling.is_busy_started = true; in ufshcd_clk_scaling_start_busy()
2209 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clk_scaling_start_busy()
2214 struct ufs_clk_scaling *scaling = &hba->clk_scaling; in ufshcd_clk_scaling_update_busy()
2220 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clk_scaling_update_busy()
2221 hba->clk_scaling.active_reqs--; in ufshcd_clk_scaling_update_busy()
2222 if (!scaling->active_reqs && scaling->is_busy_started) { in ufshcd_clk_scaling_update_busy()
2223 scaling->tot_busy_t += ktime_to_us(ktime_sub(ktime_get(), in ufshcd_clk_scaling_update_busy()
2224 scaling->busy_start_t)); in ufshcd_clk_scaling_update_busy()
2225 scaling->busy_start_t = 0; in ufshcd_clk_scaling_update_busy()
2226 scaling->is_busy_started = false; in ufshcd_clk_scaling_update_busy()
2228 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clk_scaling_update_busy()
2238 return -EINVAL; in ufshcd_monitor_opcode2dir()
2244 const struct ufs_hba_monitor *m = &hba->monitor; in ufshcd_should_inform_monitor()
2246 return (m->enabled && lrbp && lrbp->cmd && in ufshcd_should_inform_monitor()
2247 (!m->chunk_size || m->chunk_size == lrbp->cmd->sdb.length) && in ufshcd_should_inform_monitor()
2248 ktime_before(hba->monitor.enabled_ts, lrbp->issue_time_stamp)); in ufshcd_should_inform_monitor()
2254 int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd); in ufshcd_start_monitor()
2257 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_start_monitor()
2258 if (dir >= 0 && hba->monitor.nr_queued[dir]++ == 0) in ufshcd_start_monitor()
2259 hba->monitor.busy_start_ts[dir] = ktime_get(); in ufshcd_start_monitor()
2260 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_start_monitor()
2265 int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd); in ufshcd_update_monitor()
2268 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_update_monitor()
2269 if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) { in ufshcd_update_monitor()
2270 const struct request *req = scsi_cmd_to_rq(lrbp->cmd); in ufshcd_update_monitor()
2271 struct ufs_hba_monitor *m = &hba->monitor; in ufshcd_update_monitor()
2274 now = lrbp->compl_time_stamp; in ufshcd_update_monitor()
2275 inc = ktime_sub(now, m->busy_start_ts[dir]); in ufshcd_update_monitor()
2276 m->total_busy[dir] = ktime_add(m->total_busy[dir], inc); in ufshcd_update_monitor()
2277 m->nr_sec_rw[dir] += blk_rq_sectors(req); in ufshcd_update_monitor()
2280 m->nr_req[dir]++; in ufshcd_update_monitor()
2281 lat = ktime_sub(now, lrbp->issue_time_stamp); in ufshcd_update_monitor()
2282 m->lat_sum[dir] += lat; in ufshcd_update_monitor()
2283 if (m->lat_max[dir] < lat || !m->lat_max[dir]) in ufshcd_update_monitor()
2284 m->lat_max[dir] = lat; in ufshcd_update_monitor()
2285 if (m->lat_min[dir] > lat || !m->lat_min[dir]) in ufshcd_update_monitor()
2286 m->lat_min[dir] = lat; in ufshcd_update_monitor()
2288 m->nr_queued[dir]--; in ufshcd_update_monitor()
2290 m->busy_start_ts[dir] = now; in ufshcd_update_monitor()
2292 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_update_monitor()
2296 * ufshcd_send_command - Send SCSI or device management commands
2305 struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; in ufshcd_send_command()
2308 lrbp->issue_time_stamp = ktime_get(); in ufshcd_send_command()
2309 lrbp->issue_time_stamp_local_clock = local_clock(); in ufshcd_send_command()
2310 lrbp->compl_time_stamp = ktime_set(0, 0); in ufshcd_send_command()
2311 lrbp->compl_time_stamp_local_clock = 0; in ufshcd_send_command()
2313 if (lrbp->cmd) in ufshcd_send_command()
2318 if (hba->mcq_enabled) { in ufshcd_send_command()
2320 struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr; in ufshcd_send_command()
2323 spin_lock(&hwq->sq_lock); in ufshcd_send_command()
2324 dest = hwq->sqe_base_addr + hwq->sq_tail_slot; in ufshcd_send_command()
2327 spin_unlock(&hwq->sq_lock); in ufshcd_send_command()
2329 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_send_command()
2330 if (hba->vops && hba->vops->setup_xfer_req) in ufshcd_send_command()
2331 hba->vops->setup_xfer_req(hba, lrbp->task_tag, in ufshcd_send_command()
2332 !!lrbp->cmd); in ufshcd_send_command()
2333 __set_bit(lrbp->task_tag, &hba->outstanding_reqs); in ufshcd_send_command()
2334 ufshcd_writel(hba, 1 << lrbp->task_tag, in ufshcd_send_command()
2336 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_send_command()
2341 * ufshcd_copy_sense_data - Copy sense data in case of check condition
2346 u8 *const sense_buffer = lrbp->cmd->sense_buffer; in ufshcd_copy_sense_data()
2350 resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header.data_segment_length); in ufshcd_copy_sense_data()
2354 len = be16_to_cpu(lrbp->ucd_rsp_ptr->sr.sense_data_len); in ufshcd_copy_sense_data()
2357 memcpy(sense_buffer, lrbp->ucd_rsp_ptr->sr.sense_data, in ufshcd_copy_sense_data()
2363 * ufshcd_copy_query_response() - Copy the Query Response and the data
2373 struct ufs_query_res *query_res = &hba->dev_cmd.query.response; in ufshcd_copy_query_response()
2375 memcpy(&query_res->upiu_res, &lrbp->ucd_rsp_ptr->qr, QUERY_OSF_SIZE); in ufshcd_copy_query_response()
2378 if (hba->dev_cmd.query.descriptor && in ufshcd_copy_query_response()
2379 lrbp->ucd_rsp_ptr->qr.opcode == UPIU_QUERY_OPCODE_READ_DESC) { in ufshcd_copy_query_response()
2380 u8 *descp = (u8 *)lrbp->ucd_rsp_ptr + in ufshcd_copy_query_response()
2386 resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header in ufshcd_copy_query_response()
2389 hba->dev_cmd.query.request.upiu_req.length); in ufshcd_copy_query_response()
2391 memcpy(hba->dev_cmd.query.descriptor, descp, resp_len); in ufshcd_copy_query_response()
2393 dev_warn(hba->dev, in ufshcd_copy_query_response()
2396 return -EINVAL; in ufshcd_copy_query_response()
2404 * ufshcd_hba_capabilities - Read controller capabilities
2413 hba->capabilities = ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES); in ufshcd_hba_capabilities()
2414 if (hba->quirks & UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS) in ufshcd_hba_capabilities()
2415 hba->capabilities &= ~MASK_64_ADDRESSING_SUPPORT; in ufshcd_hba_capabilities()
2418 hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS_SDB) + 1; in ufshcd_hba_capabilities()
2419 hba->nutmrs = in ufshcd_hba_capabilities()
2420 ((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1; in ufshcd_hba_capabilities()
2421 hba->reserved_slot = hba->nutrs - 1; in ufshcd_hba_capabilities()
2423 hba->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1; in ufshcd_hba_capabilities()
2428 dev_err(hba->dev, "crypto setup failed\n"); in ufshcd_hba_capabilities()
2437 hba->mcq_sup = FIELD_GET(MASK_MCQ_SUPPORT, hba->capabilities); in ufshcd_hba_capabilities()
2442 if (!(hba->quirks & UFSHCD_QUIRK_BROKEN_LSDBS_CAP)) in ufshcd_hba_capabilities()
2443 hba->lsdb_sup = !FIELD_GET(MASK_LSDB_SUPPORT, hba->capabilities); in ufshcd_hba_capabilities()
2445 hba->lsdb_sup = true; in ufshcd_hba_capabilities()
2447 if (!hba->mcq_sup) in ufshcd_hba_capabilities()
2450 hba->mcq_capabilities = ufshcd_readl(hba, REG_MCQCAP); in ufshcd_hba_capabilities()
2451 hba->ext_iid_sup = FIELD_GET(MASK_EXT_IID_SUPPORT, in ufshcd_hba_capabilities()
2452 hba->mcq_capabilities); in ufshcd_hba_capabilities()
2458 * ufshcd_ready_for_uic_cmd - Check if controller is ready
2474 * ufshcd_get_upmcrs - Get the power mode change request status
2487 * ufshcd_dispatch_uic_cmd - Dispatch an UIC command to the Unipro layer
2494 lockdep_assert_held(&hba->uic_cmd_mutex); in ufshcd_dispatch_uic_cmd()
2496 WARN_ON(hba->active_uic_cmd); in ufshcd_dispatch_uic_cmd()
2498 hba->active_uic_cmd = uic_cmd; in ufshcd_dispatch_uic_cmd()
2501 ufshcd_writel(hba, uic_cmd->argument1, REG_UIC_COMMAND_ARG_1); in ufshcd_dispatch_uic_cmd()
2502 ufshcd_writel(hba, uic_cmd->argument2, REG_UIC_COMMAND_ARG_2); in ufshcd_dispatch_uic_cmd()
2503 ufshcd_writel(hba, uic_cmd->argument3, REG_UIC_COMMAND_ARG_3); in ufshcd_dispatch_uic_cmd()
2508 ufshcd_writel(hba, uic_cmd->command & COMMAND_OPCODE_MASK, in ufshcd_dispatch_uic_cmd()
2513 * ufshcd_wait_for_uic_cmd - Wait for completion of an UIC command
2525 lockdep_assert_held(&hba->uic_cmd_mutex); in ufshcd_wait_for_uic_cmd()
2527 if (wait_for_completion_timeout(&uic_cmd->done, in ufshcd_wait_for_uic_cmd()
2529 ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; in ufshcd_wait_for_uic_cmd()
2531 ret = -ETIMEDOUT; in ufshcd_wait_for_uic_cmd()
2532 dev_err(hba->dev, in ufshcd_wait_for_uic_cmd()
2534 uic_cmd->command, uic_cmd->argument3); in ufshcd_wait_for_uic_cmd()
2536 if (!uic_cmd->cmd_active) { in ufshcd_wait_for_uic_cmd()
2537 dev_err(hba->dev, "%s: UIC cmd has been completed, return the result\n", in ufshcd_wait_for_uic_cmd()
2539 ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; in ufshcd_wait_for_uic_cmd()
2543 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_wait_for_uic_cmd()
2544 hba->active_uic_cmd = NULL; in ufshcd_wait_for_uic_cmd()
2545 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_wait_for_uic_cmd()
2551 * __ufshcd_send_uic_cmd - Send UIC commands and retrieve the result
2562 lockdep_assert_held(&hba->uic_cmd_mutex); in __ufshcd_send_uic_cmd()
2565 dev_err(hba->dev, in __ufshcd_send_uic_cmd()
2567 return -EIO; in __ufshcd_send_uic_cmd()
2571 init_completion(&uic_cmd->done); in __ufshcd_send_uic_cmd()
2573 uic_cmd->cmd_active = 1; in __ufshcd_send_uic_cmd()
2580 * ufshcd_send_uic_cmd - Send UIC commands and retrieve the result
2590 if (hba->quirks & UFSHCD_QUIRK_BROKEN_UIC_CMD) in ufshcd_send_uic_cmd()
2594 mutex_lock(&hba->uic_cmd_mutex); in ufshcd_send_uic_cmd()
2601 mutex_unlock(&hba->uic_cmd_mutex); in ufshcd_send_uic_cmd()
2608 * ufshcd_sgl_to_prdt - SG list to PRTD (Physical Region Description Table, 4DW format)
2609 * @hba: per-adapter instance
2623 if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) in ufshcd_sgl_to_prdt()
2624 lrbp->utr_descriptor_ptr->prd_table_length = in ufshcd_sgl_to_prdt()
2627 lrbp->utr_descriptor_ptr->prd_table_length = cpu_to_le16(sg_entries); in ufshcd_sgl_to_prdt()
2629 prd = lrbp->ucd_prdt_ptr; in ufshcd_sgl_to_prdt()
2643 prd->size = cpu_to_le32(len - 1); in ufshcd_sgl_to_prdt()
2644 prd->addr = cpu_to_le64(sg->dma_address); in ufshcd_sgl_to_prdt()
2645 prd->reserved = 0; in ufshcd_sgl_to_prdt()
2649 lrbp->utr_descriptor_ptr->prd_table_length = 0; in ufshcd_sgl_to_prdt()
2654 * ufshcd_map_sg - Map scatter-gather list to prdt
2658 * Return: 0 in case of success, non-zero value in case of failure.
2662 struct scsi_cmnd *cmd = lrbp->cmd; in ufshcd_map_sg()
2674 * ufshcd_enable_intr - enable interrupts
2687 * ufshcd_disable_intr - disable interrupts
2700 * ufshcd_prepare_req_desc_hdr - Fill UTP Transfer request descriptor header according to request
2713 struct utp_transfer_req_desc *req_desc = lrbp->utr_descriptor_ptr; in ufshcd_prepare_req_desc_hdr()
2714 struct request_desc_header *h = &req_desc->header; in ufshcd_prepare_req_desc_hdr()
2717 lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; in ufshcd_prepare_req_desc_hdr()
2732 h->command_type = lrbp->command_type; in ufshcd_prepare_req_desc_hdr()
2733 h->data_direction = data_direction; in ufshcd_prepare_req_desc_hdr()
2734 h->ehs_length = ehs_length; in ufshcd_prepare_req_desc_hdr()
2736 if (lrbp->intr_cmd) in ufshcd_prepare_req_desc_hdr()
2737 h->interrupt = 1; in ufshcd_prepare_req_desc_hdr()
2747 h->ocs = OCS_INVALID_COMMAND_STATUS; in ufshcd_prepare_req_desc_hdr()
2749 req_desc->prd_table_length = 0; in ufshcd_prepare_req_desc_hdr()
2753 * ufshcd_prepare_utp_scsi_cmd_upiu() - fills the utp_transfer_req_desc,
2761 struct scsi_cmnd *cmd = lrbp->cmd; in ufshcd_prepare_utp_scsi_cmd_upiu()
2762 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; in ufshcd_prepare_utp_scsi_cmd_upiu()
2765 ucd_req_ptr->header = (struct utp_upiu_header){ in ufshcd_prepare_utp_scsi_cmd_upiu()
2768 .lun = lrbp->lun, in ufshcd_prepare_utp_scsi_cmd_upiu()
2769 .task_tag = lrbp->task_tag, in ufshcd_prepare_utp_scsi_cmd_upiu()
2773 WARN_ON_ONCE(ucd_req_ptr->header.task_tag != lrbp->task_tag); in ufshcd_prepare_utp_scsi_cmd_upiu()
2775 ucd_req_ptr->sc.exp_data_transfer_len = cpu_to_be32(cmd->sdb.length); in ufshcd_prepare_utp_scsi_cmd_upiu()
2777 cdb_len = min_t(unsigned short, cmd->cmd_len, UFS_CDB_SIZE); in ufshcd_prepare_utp_scsi_cmd_upiu()
2778 memset(ucd_req_ptr->sc.cdb, 0, UFS_CDB_SIZE); in ufshcd_prepare_utp_scsi_cmd_upiu()
2779 memcpy(ucd_req_ptr->sc.cdb, cmd->cmnd, cdb_len); in ufshcd_prepare_utp_scsi_cmd_upiu()
2781 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); in ufshcd_prepare_utp_scsi_cmd_upiu()
2785 * ufshcd_prepare_utp_query_req_upiu() - fill the utp_transfer_req_desc for query request
2793 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; in ufshcd_prepare_utp_query_req_upiu()
2794 struct ufs_query *query = &hba->dev_cmd.query; in ufshcd_prepare_utp_query_req_upiu()
2795 u16 len = be16_to_cpu(query->request.upiu_req.length); in ufshcd_prepare_utp_query_req_upiu()
2798 ucd_req_ptr->header = (struct utp_upiu_header){ in ufshcd_prepare_utp_query_req_upiu()
2801 .lun = lrbp->lun, in ufshcd_prepare_utp_query_req_upiu()
2802 .task_tag = lrbp->task_tag, in ufshcd_prepare_utp_query_req_upiu()
2803 .query_function = query->request.query_func, in ufshcd_prepare_utp_query_req_upiu()
2806 query->request.upiu_req.opcode == in ufshcd_prepare_utp_query_req_upiu()
2813 memcpy(&ucd_req_ptr->qr, &query->request.upiu_req, in ufshcd_prepare_utp_query_req_upiu()
2817 if (query->request.upiu_req.opcode == UPIU_QUERY_OPCODE_WRITE_DESC) in ufshcd_prepare_utp_query_req_upiu()
2818 memcpy(ucd_req_ptr + 1, query->descriptor, len); in ufshcd_prepare_utp_query_req_upiu()
2820 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); in ufshcd_prepare_utp_query_req_upiu()
2825 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; in ufshcd_prepare_utp_nop_upiu()
2829 ucd_req_ptr->header = (struct utp_upiu_header){ in ufshcd_prepare_utp_nop_upiu()
2831 .task_tag = lrbp->task_tag, in ufshcd_prepare_utp_nop_upiu()
2834 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); in ufshcd_prepare_utp_nop_upiu()
2838 * ufshcd_compose_devman_upiu - UFS Protocol Information Unit(UPIU)
2853 if (hba->dev_cmd.type == DEV_CMD_TYPE_QUERY) in ufshcd_compose_devman_upiu()
2855 else if (hba->dev_cmd.type == DEV_CMD_TYPE_NOP) in ufshcd_compose_devman_upiu()
2858 ret = -EINVAL; in ufshcd_compose_devman_upiu()
2864 * ufshcd_comp_scsi_upiu - UFS Protocol Information Unit(UPIU)
2871 struct request *rq = scsi_cmd_to_rq(lrbp->cmd); in ufshcd_comp_scsi_upiu()
2875 ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, lrbp->cmd->sc_data_direction, 0); in ufshcd_comp_scsi_upiu()
2882 * ufshcd_upiu_wlun_to_scsi_wlun - maps UPIU W-LUN id to SCSI W-LUN ID
2883 * @upiu_wlun_id: UPIU W-LUN id
2885 * Return: SCSI W-LUN id.
2894 return sdev->lun == in is_device_wlun()
2908 hba->nr_queues[HCTX_TYPE_DEFAULT] = 1; in ufshcd_map_queues()
2909 hba->nr_queues[HCTX_TYPE_READ] = 0; in ufshcd_map_queues()
2910 hba->nr_queues[HCTX_TYPE_POLL] = 1; in ufshcd_map_queues()
2911 hba->nr_hw_queues = 1; in ufshcd_map_queues()
2914 for (i = 0; i < shost->nr_maps; i++) { in ufshcd_map_queues()
2915 struct blk_mq_queue_map *map = &shost->tag_set.map[i]; in ufshcd_map_queues()
2917 map->nr_queues = hba->nr_queues[i]; in ufshcd_map_queues()
2918 if (!map->nr_queues) in ufshcd_map_queues()
2920 map->queue_offset = queue_offset; in ufshcd_map_queues()
2922 map->queue_offset = 0; in ufshcd_map_queues()
2925 queue_offset += map->nr_queues; in ufshcd_map_queues()
2931 struct utp_transfer_cmd_desc *cmd_descp = (void *)hba->ucdl_base_addr + in ufshcd_init_lrb()
2933 struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; in ufshcd_init_lrb()
2934 dma_addr_t cmd_desc_element_addr = hba->ucdl_dma_addr + in ufshcd_init_lrb()
2939 lrb->utr_descriptor_ptr = utrdlp + i; in ufshcd_init_lrb()
2940 lrb->utrd_dma_addr = hba->utrdl_dma_addr + in ufshcd_init_lrb()
2942 lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; in ufshcd_init_lrb()
2943 lrb->ucd_req_dma_addr = cmd_desc_element_addr; in ufshcd_init_lrb()
2944 lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; in ufshcd_init_lrb()
2945 lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; in ufshcd_init_lrb()
2946 lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; in ufshcd_init_lrb()
2947 lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; in ufshcd_init_lrb()
2951 * ufshcd_queuecommand - main entry point for SCSI requests
2955 * Return: 0 for success, non-zero in case of failure.
2960 int tag = scsi_cmd_to_rq(cmd)->tag; in ufshcd_queuecommand()
2965 switch (hba->ufshcd_state) { in ufshcd_queuecommand()
2970 * SCSI error handler can call ->queuecommand() while UFS error in ufshcd_queuecommand()
2992 if (hba->pm_op_in_progress) { in ufshcd_queuecommand()
2993 hba->force_reset = true; in ufshcd_queuecommand()
3008 hba->req_abort_count = 0; in ufshcd_queuecommand()
3012 lrbp = &hba->lrb[tag]; in ufshcd_queuecommand()
3013 lrbp->cmd = cmd; in ufshcd_queuecommand()
3014 lrbp->task_tag = tag; in ufshcd_queuecommand()
3015 lrbp->lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun); in ufshcd_queuecommand()
3016 lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed(hba); in ufshcd_queuecommand()
3020 lrbp->req_abort_skip = false; in ufshcd_queuecommand()
3030 if (hba->mcq_enabled) in ufshcd_queuecommand()
3039 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_queuecommand()
3041 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_queuecommand()
3050 lrbp->cmd = NULL; in ufshcd_setup_dev_cmd()
3051 lrbp->task_tag = tag; in ufshcd_setup_dev_cmd()
3052 lrbp->lun = lun; in ufshcd_setup_dev_cmd()
3053 lrbp->intr_cmd = true; /* No interrupt aggregation */ in ufshcd_setup_dev_cmd()
3055 hba->dev_cmd.type = cmd_type; in ufshcd_setup_dev_cmd()
3089 if (hba->mcq_enabled) { in ufshcd_clear_cmd()
3096 dev_err(hba->dev, "%s: failed tag=%d. err=%d\n", in ufshcd_clear_cmd()
3106 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clear_cmd()
3108 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clear_cmd()
3111 * wait for h/w to clear corresponding bit in door-bell. in ufshcd_clear_cmd()
3119 * ufshcd_dev_cmd_completion() - handles device management command responses
3131 hba->ufs_stats.last_hibern8_exit_tstamp = ktime_set(0, 0); in ufshcd_dev_cmd_completion()
3132 resp = ufshcd_get_req_rsp(lrbp->ucd_rsp_ptr); in ufshcd_dev_cmd_completion()
3136 if (hba->dev_cmd.type != DEV_CMD_TYPE_NOP) { in ufshcd_dev_cmd_completion()
3137 err = -EINVAL; in ufshcd_dev_cmd_completion()
3138 dev_err(hba->dev, "%s: unexpected response %x\n", in ufshcd_dev_cmd_completion()
3143 u8 response = lrbp->ucd_rsp_ptr->header.response; in ufshcd_dev_cmd_completion()
3151 err = -EPERM; in ufshcd_dev_cmd_completion()
3152 dev_err(hba->dev, "%s: Reject UPIU not fully implemented\n", in ufshcd_dev_cmd_completion()
3156 if (hba->dev_cmd.type != DEV_CMD_TYPE_RPMB) { in ufshcd_dev_cmd_completion()
3157 err = -EINVAL; in ufshcd_dev_cmd_completion()
3158 dev_err(hba->dev, "%s: unexpected response %x\n", __func__, resp); in ufshcd_dev_cmd_completion()
3162 err = -EINVAL; in ufshcd_dev_cmd_completion()
3163 dev_err(hba->dev, "%s: Invalid device management cmd response: %x\n", in ufshcd_dev_cmd_completion()
3180 time_left = wait_for_completion_timeout(hba->dev_cmd.complete, in ufshcd_wait_for_dev_cmd()
3189 hba->dev_cmd.complete = NULL; in ufshcd_wait_for_dev_cmd()
3194 err = -ETIMEDOUT; in ufshcd_wait_for_dev_cmd()
3195 dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n", in ufshcd_wait_for_dev_cmd()
3196 __func__, lrbp->task_tag); in ufshcd_wait_for_dev_cmd()
3199 if (hba->mcq_enabled) { in ufshcd_wait_for_dev_cmd()
3201 if (ufshcd_clear_cmd(hba, lrbp->task_tag) == 0) in ufshcd_wait_for_dev_cmd()
3202 err = -EAGAIN; in ufshcd_wait_for_dev_cmd()
3203 hba->dev_cmd.complete = NULL; in ufshcd_wait_for_dev_cmd()
3208 if (ufshcd_clear_cmd(hba, lrbp->task_tag) == 0) { in ufshcd_wait_for_dev_cmd()
3210 err = -EAGAIN; in ufshcd_wait_for_dev_cmd()
3216 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_wait_for_dev_cmd()
3217 pending = test_bit(lrbp->task_tag, in ufshcd_wait_for_dev_cmd()
3218 &hba->outstanding_reqs); in ufshcd_wait_for_dev_cmd()
3220 hba->dev_cmd.complete = NULL; in ufshcd_wait_for_dev_cmd()
3221 __clear_bit(lrbp->task_tag, in ufshcd_wait_for_dev_cmd()
3222 &hba->outstanding_reqs); in ufshcd_wait_for_dev_cmd()
3224 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_wait_for_dev_cmd()
3235 dev_err(hba->dev, "%s: failed to clear tag %d\n", in ufshcd_wait_for_dev_cmd()
3236 __func__, lrbp->task_tag); in ufshcd_wait_for_dev_cmd()
3238 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_wait_for_dev_cmd()
3239 pending = test_bit(lrbp->task_tag, in ufshcd_wait_for_dev_cmd()
3240 &hba->outstanding_reqs); in ufshcd_wait_for_dev_cmd()
3242 hba->dev_cmd.complete = NULL; in ufshcd_wait_for_dev_cmd()
3243 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_wait_for_dev_cmd()
3262 mutex_lock(&hba->dev_cmd.lock); in ufshcd_dev_man_lock()
3263 down_read(&hba->clk_scaling_lock); in ufshcd_dev_man_lock()
3268 up_read(&hba->clk_scaling_lock); in ufshcd_dev_man_unlock()
3269 mutex_unlock(&hba->dev_cmd.lock); in ufshcd_dev_man_unlock()
3279 hba->dev_cmd.complete = &wait; in ufshcd_issue_dev_cmd()
3281 ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); in ufshcd_issue_dev_cmd()
3283 ufshcd_send_command(hba, tag, hba->dev_cmd_queue); in ufshcd_issue_dev_cmd()
3287 (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); in ufshcd_issue_dev_cmd()
3293 * ufshcd_exec_dev_cmd - API for sending device management requests
3301 * it is expected you hold the hba->dev_cmd.lock mutex.
3306 const u32 tag = hba->reserved_slot; in ufshcd_exec_dev_cmd()
3307 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_exec_dev_cmd()
3310 /* Protects use of hba->reserved_slot. */ in ufshcd_exec_dev_cmd()
3311 lockdep_assert_held(&hba->dev_cmd.lock); in ufshcd_exec_dev_cmd()
3321 * ufshcd_init_query() - init the query response and request parameters
3322 * @hba: per-adapter instance
3334 *request = &hba->dev_cmd.query.request; in ufshcd_init_query()
3335 *response = &hba->dev_cmd.query.response; in ufshcd_init_query()
3338 (*request)->upiu_req.opcode = opcode; in ufshcd_init_query()
3339 (*request)->upiu_req.idn = idn; in ufshcd_init_query()
3340 (*request)->upiu_req.index = index; in ufshcd_init_query()
3341 (*request)->upiu_req.selector = selector; in ufshcd_init_query()
3353 dev_dbg(hba->dev, in ufshcd_query_flag_retry()
3361 dev_err(hba->dev, in ufshcd_query_flag_retry()
3368 * ufshcd_query_flag() - API function for sending flag query requests
3369 * @hba: per-adapter instance
3375 * Return: 0 for success, non-zero in case of failure.
3396 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST; in ufshcd_query_flag()
3399 request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST; in ufshcd_query_flag()
3402 dev_err(hba->dev, "%s: Invalid argument for read request\n", in ufshcd_query_flag()
3404 err = -EINVAL; in ufshcd_query_flag()
3409 dev_err(hba->dev, in ufshcd_query_flag()
3412 err = -EINVAL; in ufshcd_query_flag()
3419 dev_err(hba->dev, in ufshcd_query_flag()
3426 *flag_res = (be32_to_cpu(response->upiu_res.value) & in ufshcd_query_flag()
3435 * ufshcd_query_attr - API function for sending attribute requests
3436 * @hba: per-adapter instance
3443 * Return: 0 for success, non-zero in case of failure.
3455 dev_err(hba->dev, "%s: attribute value required for opcode 0x%x\n", in ufshcd_query_attr()
3457 return -EINVAL; in ufshcd_query_attr()
3467 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST; in ufshcd_query_attr()
3468 request->upiu_req.value = cpu_to_be32(*attr_val); in ufshcd_query_attr()
3471 request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST; in ufshcd_query_attr()
3474 dev_err(hba->dev, "%s: Expected query attr opcode but got = 0x%.2x\n", in ufshcd_query_attr()
3476 err = -EINVAL; in ufshcd_query_attr()
3483 dev_err(hba->dev, "%s: opcode 0x%.2x for idn %d failed, index %d, err = %d\n", in ufshcd_query_attr()
3488 *attr_val = be32_to_cpu(response->upiu_res.value); in ufshcd_query_attr()
3496 * ufshcd_query_attr_retry() - API function for sending query
3498 * @hba: per-adapter instance
3506 * Return: 0 for success, non-zero in case of failure.
3515 for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { in ufshcd_query_attr_retry()
3519 dev_dbg(hba->dev, "%s: failed with error %d, retries %d\n", in ufshcd_query_attr_retry()
3526 dev_err(hba->dev, in ufshcd_query_attr_retry()
3543 dev_err(hba->dev, "%s: descriptor buffer required for opcode 0x%x\n", in __ufshcd_query_descriptor()
3545 return -EINVAL; in __ufshcd_query_descriptor()
3549 dev_err(hba->dev, "%s: descriptor buffer size (%d) is out of range\n", in __ufshcd_query_descriptor()
3551 return -EINVAL; in __ufshcd_query_descriptor()
3558 hba->dev_cmd.query.descriptor = desc_buf; in __ufshcd_query_descriptor()
3559 request->upiu_req.length = cpu_to_be16(*buf_len); in __ufshcd_query_descriptor()
3563 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST; in __ufshcd_query_descriptor()
3566 request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST; in __ufshcd_query_descriptor()
3569 dev_err(hba->dev, in __ufshcd_query_descriptor()
3572 err = -EINVAL; in __ufshcd_query_descriptor()
3579 dev_err(hba->dev, "%s: opcode 0x%.2x for idn %d failed, index %d, err = %d\n", in __ufshcd_query_descriptor()
3584 *buf_len = be16_to_cpu(response->upiu_res.length); in __ufshcd_query_descriptor()
3587 hba->dev_cmd.query.descriptor = NULL; in __ufshcd_query_descriptor()
3593 * ufshcd_query_descriptor_retry - API function for sending descriptor requests
3594 * @hba: per-adapter instance
3605 * Return: 0 for success, non-zero in case of failure.
3616 for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { in ufshcd_query_descriptor_retry()
3619 if (!err || err == -EINVAL) in ufshcd_query_descriptor_retry()
3627 * ufshcd_read_desc_param - read the specified descriptor parameter
3635 * Return: 0 in case of success, non-zero otherwise.
3651 return -EINVAL; in ufshcd_read_desc_param()
3657 return -ENOMEM; in ufshcd_read_desc_param()
3668 …dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret … in ufshcd_read_desc_param()
3677 dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", in ufshcd_read_desc_param()
3679 ret = -EINVAL; in ufshcd_read_desc_param()
3685 dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header\n", in ufshcd_read_desc_param()
3687 ret = -EINVAL; in ufshcd_read_desc_param()
3694 ret = -EINVAL; in ufshcd_read_desc_param()
3697 min_t(u32, param_size, buff_len - param_offset)); in ufshcd_read_desc_param()
3706 * struct uc_string_id - unicode string
3718 /* replace non-printable or non-ASCII characters with spaces */
3725 * ufshcd_read_string_desc - read string descriptor
3735 * * -ENOMEM: on allocation failure
3736 * * -EINVAL: on a wrong parameter
3746 return -EINVAL; in ufshcd_read_string_desc()
3750 return -ENOMEM; in ufshcd_read_string_desc()
3755 dev_err(hba->dev, "Reading String Desc failed after %d retries. err = %d\n", in ufshcd_read_string_desc()
3761 if (uc_str->len <= QUERY_DESC_HDR_SIZE) { in ufshcd_read_string_desc()
3762 dev_dbg(hba->dev, "String Desc is of zero length\n"); in ufshcd_read_string_desc()
3772 ascii_len = (uc_str->len - QUERY_DESC_HDR_SIZE) / 2 + 1; in ufshcd_read_string_desc()
3775 ret = -ENOMEM; in ufshcd_read_string_desc()
3781 * we need to convert to utf-8 so it can be displayed in ufshcd_read_string_desc()
3783 ret = utf16s_to_utf8s(uc_str->uc, in ufshcd_read_string_desc()
3784 uc_str->len - QUERY_DESC_HDR_SIZE, in ufshcd_read_string_desc()
3785 UTF16_BIG_ENDIAN, str, ascii_len - 1); in ufshcd_read_string_desc()
3787 /* replace non-printable or non-ASCII characters with spaces */ in ufshcd_read_string_desc()
3794 str = kmemdup(uc_str, uc_str->len, GFP_KERNEL); in ufshcd_read_string_desc()
3796 ret = -ENOMEM; in ufshcd_read_string_desc()
3799 ret = uc_str->len; in ufshcd_read_string_desc()
3808 * ufshcd_read_unit_desc_param - read the specified unit descriptor parameter
3815 * Return: 0 in case of success, non-zero otherwise.
3827 if (!ufs_is_valid_unit_desc_lun(&hba->dev_info, lun)) in ufshcd_read_unit_desc_param()
3828 return -EOPNOTSUPP; in ufshcd_read_unit_desc_param()
3839 if (hba->dev_info.wspecversion >= 0x300) { in ufshcd_get_ref_clk_gating_wait()
3844 dev_err(hba->dev, "Failed reading bRefClkGatingWait. err = %d, use default %uus\n", in ufshcd_get_ref_clk_gating_wait()
3849 dev_err(hba->dev, "Undefined ref clk gating wait time, use default %uus\n", in ufshcd_get_ref_clk_gating_wait()
3853 hba->dev_info.clk_gating_wait_us = gating_wait; in ufshcd_get_ref_clk_gating_wait()
3860 * ufshcd_memory_alloc - allocate memory for host memory space data structures
3870 * Return: 0 for success, non-zero in case of failure.
3877 ucdl_size = ufshcd_get_ucd_size(hba) * hba->nutrs; in ufshcd_memory_alloc()
3878 hba->ucdl_base_addr = dmam_alloc_coherent(hba->dev, in ufshcd_memory_alloc()
3880 &hba->ucdl_dma_addr, in ufshcd_memory_alloc()
3886 if (!hba->ucdl_base_addr || in ufshcd_memory_alloc()
3887 WARN_ON(hba->ucdl_dma_addr & (128 - 1))) { in ufshcd_memory_alloc()
3888 dev_err(hba->dev, in ufshcd_memory_alloc()
3897 utrdl_size = (sizeof(struct utp_transfer_req_desc) * hba->nutrs); in ufshcd_memory_alloc()
3898 hba->utrdl_base_addr = dmam_alloc_coherent(hba->dev, in ufshcd_memory_alloc()
3900 &hba->utrdl_dma_addr, in ufshcd_memory_alloc()
3902 if (!hba->utrdl_base_addr || in ufshcd_memory_alloc()
3903 WARN_ON(hba->utrdl_dma_addr & (SZ_1K - 1))) { in ufshcd_memory_alloc()
3904 dev_err(hba->dev, in ufshcd_memory_alloc()
3915 if (hba->utmrdl_base_addr) in ufshcd_memory_alloc()
3921 utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs; in ufshcd_memory_alloc()
3922 hba->utmrdl_base_addr = dmam_alloc_coherent(hba->dev, in ufshcd_memory_alloc()
3924 &hba->utmrdl_dma_addr, in ufshcd_memory_alloc()
3926 if (!hba->utmrdl_base_addr || in ufshcd_memory_alloc()
3927 WARN_ON(hba->utmrdl_dma_addr & (SZ_1K - 1))) { in ufshcd_memory_alloc()
3928 dev_err(hba->dev, in ufshcd_memory_alloc()
3935 hba->lrb = devm_kcalloc(hba->dev, in ufshcd_memory_alloc()
3936 hba->nutrs, sizeof(struct ufshcd_lrb), in ufshcd_memory_alloc()
3938 if (!hba->lrb) { in ufshcd_memory_alloc()
3939 dev_err(hba->dev, "LRB Memory allocation failed\n"); in ufshcd_memory_alloc()
3944 return -ENOMEM; in ufshcd_memory_alloc()
3948 * ufshcd_host_memory_configure - configure local reference block with
3970 utrdlp = hba->utrdl_base_addr; in ufshcd_host_memory_configure()
3978 cmd_desc_dma_addr = hba->ucdl_dma_addr; in ufshcd_host_memory_configure()
3980 for (i = 0; i < hba->nutrs; i++) { in ufshcd_host_memory_configure()
3988 if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) { in ufshcd_host_memory_configure()
4004 ufshcd_init_lrb(hba, &hba->lrb[i], i); in ufshcd_host_memory_configure()
4009 * ufshcd_dme_link_startup - Notify Unipro to perform link startup
4017 * Return: 0 on success, non-zero value on failure.
4028 dev_dbg(hba->dev, in ufshcd_dme_link_startup()
4029 "dme-link-startup: error code %d\n", ret); in ufshcd_dme_link_startup()
4033 * ufshcd_dme_reset - UIC command for DME_RESET
4039 * Return: 0 on success, non-zero value on failure.
4050 dev_err(hba->dev, in ufshcd_dme_reset()
4051 "dme-reset: error code %d\n", ret); in ufshcd_dme_reset()
4073 * ufshcd_dme_enable - UIC command for DME_ENABLE
4078 * Return: 0 on success, non-zero value on failure.
4089 dev_err(hba->dev, in ufshcd_dme_enable()
4090 "dme-enable: error code %d\n", ret); in ufshcd_dme_enable()
4100 if (!(hba->quirks & UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS)) in ufshcd_add_delay_before_dme_cmd()
4107 if (unlikely(!ktime_to_us(hba->last_dme_cmd_tstamp))) { in ufshcd_add_delay_before_dme_cmd()
4113 hba->last_dme_cmd_tstamp)); in ufshcd_add_delay_before_dme_cmd()
4117 MIN_DELAY_BEFORE_DME_CMDS_US - delta; in ufshcd_add_delay_before_dme_cmd()
4128 hba->last_dme_cmd_tstamp = ktime_get(); in ufshcd_add_delay_before_dme_cmd()
4132 * ufshcd_dme_set_attr - UIC command for DME_SET, DME_PEER_SET
4139 * Return: 0 on success, non-zero value on failure.
4151 "dme-set", in ufshcd_dme_set_attr()
4152 "dme-peer-set" in ufshcd_dme_set_attr()
4162 dev_dbg(hba->dev, "%s: attr-id 0x%x val 0x%x error code %d\n", in ufshcd_dme_set_attr()
4164 } while (ret && peer && --retries); in ufshcd_dme_set_attr()
4167 dev_err(hba->dev, "%s: attr-id 0x%x val 0x%x failed %d retries\n", in ufshcd_dme_set_attr()
4169 UFS_UIC_COMMAND_RETRIES - retries); in ufshcd_dme_set_attr()
4176 * ufshcd_dme_get_attr - UIC command for DME_GET, DME_PEER_GET
4182 * Return: 0 on success, non-zero value on failure.
4192 "dme-get", in ufshcd_dme_get_attr()
4193 "dme-peer-get" in ufshcd_dme_get_attr()
4202 if (peer && (hba->quirks & UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE)) { in ufshcd_dme_get_attr()
4203 orig_pwr_info = hba->pwr_info; in ufshcd_dme_get_attr()
4228 dev_dbg(hba->dev, "%s: attr-id 0x%x error code %d\n", in ufshcd_dme_get_attr()
4230 } while (ret && peer && --retries); in ufshcd_dme_get_attr()
4233 dev_err(hba->dev, "%s: attr-id 0x%x failed %d retries\n", in ufshcd_dme_get_attr()
4235 UFS_UIC_COMMAND_RETRIES - retries); in ufshcd_dme_get_attr()
4240 if (peer && (hba->quirks & UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE) in ufshcd_dme_get_attr()
4249 * ufshcd_uic_pwr_ctrl - executes UIC commands (which affects the link power
4262 * Return: 0 on success, non-zero value on failure.
4272 mutex_lock(&hba->uic_cmd_mutex); in ufshcd_uic_pwr_ctrl()
4275 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_uic_pwr_ctrl()
4277 ret = -ENOLINK; in ufshcd_uic_pwr_ctrl()
4280 hba->uic_async_done = &uic_async_done; in ufshcd_uic_pwr_ctrl()
4290 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_uic_pwr_ctrl()
4293 dev_err(hba->dev, in ufshcd_uic_pwr_ctrl()
4295 cmd->command, cmd->argument3, ret); in ufshcd_uic_pwr_ctrl()
4299 if (!wait_for_completion_timeout(hba->uic_async_done, in ufshcd_uic_pwr_ctrl()
4301 dev_err(hba->dev, in ufshcd_uic_pwr_ctrl()
4303 cmd->command, cmd->argument3); in ufshcd_uic_pwr_ctrl()
4305 if (!cmd->cmd_active) { in ufshcd_uic_pwr_ctrl()
4306 dev_err(hba->dev, "%s: Power Mode Change operation has been completed, go check UPMCRS\n", in ufshcd_uic_pwr_ctrl()
4311 ret = -ETIMEDOUT; in ufshcd_uic_pwr_ctrl()
4318 dev_err(hba->dev, in ufshcd_uic_pwr_ctrl()
4320 cmd->command, status); in ufshcd_uic_pwr_ctrl()
4321 ret = (status != PWR_OK) ? status : -1; in ufshcd_uic_pwr_ctrl()
4330 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_uic_pwr_ctrl()
4331 hba->active_uic_cmd = NULL; in ufshcd_uic_pwr_ctrl()
4332 hba->uic_async_done = NULL; in ufshcd_uic_pwr_ctrl()
4340 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_uic_pwr_ctrl()
4341 mutex_unlock(&hba->uic_cmd_mutex); in ufshcd_uic_pwr_ctrl()
4347 * ufshcd_uic_change_pwr_mode - Perform the UIC power mode chage
4352 * Return: 0 on success, non-zero value on failure.
4363 if (hba->quirks & UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP) { in ufshcd_uic_change_pwr_mode()
4367 dev_err(hba->dev, "%s: failed to enable PA_RXHSUNTERMCAP ret %d\n", in ufshcd_uic_change_pwr_mode()
4387 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_link_recovery()
4388 hba->ufshcd_state = UFSHCD_STATE_RESET; in ufshcd_link_recovery()
4390 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_link_recovery()
4397 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_link_recovery()
4399 hba->ufshcd_state = UFSHCD_STATE_ERROR; in ufshcd_link_recovery()
4401 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_link_recovery()
4404 dev_err(hba->dev, "%s: link recovery failed, err %d", in ufshcd_link_recovery()
4422 trace_ufshcd_profile_hibern8(dev_name(hba->dev), "enter", in ufshcd_uic_hibern8_enter()
4426 dev_err(hba->dev, "%s: hibern8 enter failed. ret = %d\n", in ufshcd_uic_hibern8_enter()
4447 trace_ufshcd_profile_hibern8(dev_name(hba->dev), "exit", in ufshcd_uic_hibern8_exit()
4451 dev_err(hba->dev, "%s: hibern8 exit failed. ret = %d\n", in ufshcd_uic_hibern8_exit()
4456 hba->ufs_stats.last_hibern8_exit_tstamp = local_clock(); in ufshcd_uic_hibern8_exit()
4457 hba->ufs_stats.hibern8_exit_cnt++; in ufshcd_uic_hibern8_exit()
4469 ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); in ufshcd_configure_auto_hibern8()
4474 const u32 cur_ahit = READ_ONCE(hba->ahit); in ufshcd_auto_hibern8_update()
4479 WRITE_ONCE(hba->ahit, ahit); in ufshcd_auto_hibern8_update()
4480 if (!pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { in ufshcd_auto_hibern8_update()
4491 * ufshcd_init_pwr_info - setting the POR (power on reset)
4493 * @hba: per-adapter instance
4497 hba->pwr_info.gear_rx = UFS_PWM_G1; in ufshcd_init_pwr_info()
4498 hba->pwr_info.gear_tx = UFS_PWM_G1; in ufshcd_init_pwr_info()
4499 hba->pwr_info.lane_rx = UFS_LANE_1; in ufshcd_init_pwr_info()
4500 hba->pwr_info.lane_tx = UFS_LANE_1; in ufshcd_init_pwr_info()
4501 hba->pwr_info.pwr_rx = SLOWAUTO_MODE; in ufshcd_init_pwr_info()
4502 hba->pwr_info.pwr_tx = SLOWAUTO_MODE; in ufshcd_init_pwr_info()
4503 hba->pwr_info.hs_rate = 0; in ufshcd_init_pwr_info()
4507 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device
4508 * @hba: per-adapter instance
4514 struct ufs_pa_layer_attr *pwr_info = &hba->max_pwr_info.info; in ufshcd_get_max_pwr_mode()
4516 if (hba->max_pwr_info.is_valid) in ufshcd_get_max_pwr_mode()
4519 if (hba->quirks & UFSHCD_QUIRK_HIBERN_FASTAUTO) { in ufshcd_get_max_pwr_mode()
4520 pwr_info->pwr_tx = FASTAUTO_MODE; in ufshcd_get_max_pwr_mode()
4521 pwr_info->pwr_rx = FASTAUTO_MODE; in ufshcd_get_max_pwr_mode()
4523 pwr_info->pwr_tx = FAST_MODE; in ufshcd_get_max_pwr_mode()
4524 pwr_info->pwr_rx = FAST_MODE; in ufshcd_get_max_pwr_mode()
4526 pwr_info->hs_rate = PA_HS_MODE_B; in ufshcd_get_max_pwr_mode()
4530 &pwr_info->lane_rx); in ufshcd_get_max_pwr_mode()
4532 &pwr_info->lane_tx); in ufshcd_get_max_pwr_mode()
4534 if (!pwr_info->lane_rx || !pwr_info->lane_tx) { in ufshcd_get_max_pwr_mode()
4535 dev_err(hba->dev, "%s: invalid connected lanes value. rx=%d, tx=%d\n", in ufshcd_get_max_pwr_mode()
4537 pwr_info->lane_rx, in ufshcd_get_max_pwr_mode()
4538 pwr_info->lane_tx); in ufshcd_get_max_pwr_mode()
4539 return -EINVAL; in ufshcd_get_max_pwr_mode()
4547 ufshcd_dme_get(hba, UIC_ARG_MIB(PA_MAXRXHSGEAR), &pwr_info->gear_rx); in ufshcd_get_max_pwr_mode()
4548 if (!pwr_info->gear_rx) { in ufshcd_get_max_pwr_mode()
4550 &pwr_info->gear_rx); in ufshcd_get_max_pwr_mode()
4551 if (!pwr_info->gear_rx) { in ufshcd_get_max_pwr_mode()
4552 dev_err(hba->dev, "%s: invalid max pwm rx gear read = %d\n", in ufshcd_get_max_pwr_mode()
4553 __func__, pwr_info->gear_rx); in ufshcd_get_max_pwr_mode()
4554 return -EINVAL; in ufshcd_get_max_pwr_mode()
4556 pwr_info->pwr_rx = SLOW_MODE; in ufshcd_get_max_pwr_mode()
4560 &pwr_info->gear_tx); in ufshcd_get_max_pwr_mode()
4561 if (!pwr_info->gear_tx) { in ufshcd_get_max_pwr_mode()
4563 &pwr_info->gear_tx); in ufshcd_get_max_pwr_mode()
4564 if (!pwr_info->gear_tx) { in ufshcd_get_max_pwr_mode()
4565 dev_err(hba->dev, "%s: invalid max pwm tx gear read = %d\n", in ufshcd_get_max_pwr_mode()
4566 __func__, pwr_info->gear_tx); in ufshcd_get_max_pwr_mode()
4567 return -EINVAL; in ufshcd_get_max_pwr_mode()
4569 pwr_info->pwr_tx = SLOW_MODE; in ufshcd_get_max_pwr_mode()
4572 hba->max_pwr_info.is_valid = true; in ufshcd_get_max_pwr_mode()
4582 if (!hba->force_pmc && in ufshcd_change_power_mode()
4583 pwr_mode->gear_rx == hba->pwr_info.gear_rx && in ufshcd_change_power_mode()
4584 pwr_mode->gear_tx == hba->pwr_info.gear_tx && in ufshcd_change_power_mode()
4585 pwr_mode->lane_rx == hba->pwr_info.lane_rx && in ufshcd_change_power_mode()
4586 pwr_mode->lane_tx == hba->pwr_info.lane_tx && in ufshcd_change_power_mode()
4587 pwr_mode->pwr_rx == hba->pwr_info.pwr_rx && in ufshcd_change_power_mode()
4588 pwr_mode->pwr_tx == hba->pwr_info.pwr_tx && in ufshcd_change_power_mode()
4589 pwr_mode->hs_rate == hba->pwr_info.hs_rate) { in ufshcd_change_power_mode()
4590 dev_dbg(hba->dev, "%s: power already configured\n", __func__); in ufshcd_change_power_mode()
4596 * - PA_RXGEAR, PA_ACTIVERXDATALANES, PA_RXTERMINATION, in ufshcd_change_power_mode()
4597 * - PA_TXGEAR, PA_ACTIVETXDATALANES, PA_TXTERMINATION, in ufshcd_change_power_mode()
4598 * - PA_HSSERIES in ufshcd_change_power_mode()
4600 ufshcd_dme_set(hba, UIC_ARG_MIB(PA_RXGEAR), pwr_mode->gear_rx); in ufshcd_change_power_mode()
4602 pwr_mode->lane_rx); in ufshcd_change_power_mode()
4603 if (pwr_mode->pwr_rx == FASTAUTO_MODE || in ufshcd_change_power_mode()
4604 pwr_mode->pwr_rx == FAST_MODE) in ufshcd_change_power_mode()
4609 ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TXGEAR), pwr_mode->gear_tx); in ufshcd_change_power_mode()
4611 pwr_mode->lane_tx); in ufshcd_change_power_mode()
4612 if (pwr_mode->pwr_tx == FASTAUTO_MODE || in ufshcd_change_power_mode()
4613 pwr_mode->pwr_tx == FAST_MODE) in ufshcd_change_power_mode()
4618 if (pwr_mode->pwr_rx == FASTAUTO_MODE || in ufshcd_change_power_mode()
4619 pwr_mode->pwr_tx == FASTAUTO_MODE || in ufshcd_change_power_mode()
4620 pwr_mode->pwr_rx == FAST_MODE || in ufshcd_change_power_mode()
4621 pwr_mode->pwr_tx == FAST_MODE) in ufshcd_change_power_mode()
4623 pwr_mode->hs_rate); in ufshcd_change_power_mode()
4625 if (!(hba->quirks & UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING)) { in ufshcd_change_power_mode()
4647 ret = ufshcd_uic_change_pwr_mode(hba, pwr_mode->pwr_rx << 4 in ufshcd_change_power_mode()
4648 | pwr_mode->pwr_tx); in ufshcd_change_power_mode()
4651 dev_err(hba->dev, in ufshcd_change_power_mode()
4657 memcpy(&hba->pwr_info, pwr_mode, in ufshcd_change_power_mode()
4665 * ufshcd_config_pwr_mode - configure a new power mode
4666 * @hba: per-adapter instance
4690 * ufshcd_complete_dev_init() - checks device readiness
4691 * @hba: per-adapter instance
4706 dev_err(hba->dev, in ufshcd_complete_dev_init()
4723 dev_err(hba->dev, in ufshcd_complete_dev_init()
4727 dev_err(hba->dev, in ufshcd_complete_dev_init()
4730 err = -EBUSY; in ufshcd_complete_dev_init()
4737 * ufshcd_make_hba_operational - Make UFS controller operational
4744 * 4. Configure run-stop-registers
4746 * Return: 0 on success, non-zero value on failure.
4758 ufshcd_config_intr_aggr(hba, hba->nutrs - 1, INT_AGGR_DEF_TO); in ufshcd_make_hba_operational()
4763 ufshcd_writel(hba, lower_32_bits(hba->utrdl_dma_addr), in ufshcd_make_hba_operational()
4765 ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr), in ufshcd_make_hba_operational()
4767 ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr), in ufshcd_make_hba_operational()
4769 ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr), in ufshcd_make_hba_operational()
4779 dev_err(hba->dev, in ufshcd_make_hba_operational()
4781 err = -EIO; in ufshcd_make_hba_operational()
4789 * ufshcd_hba_stop - Send controller to reset state
4801 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_hba_stop()
4803 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_hba_stop()
4809 dev_err(hba->dev, "%s: Controller disable failed\n", __func__); in ufshcd_hba_stop()
4814 * ufshcd_hba_execute_hce - initialize the controller
4821 * Return: 0 on success, non-zero value on failure.
4843 * During initialization the HCE bit value changes from 1->0->1. in ufshcd_hba_execute_hce()
4851 ufshcd_delay_us(hba->vps->hba_enable_delay_us, 100); in ufshcd_hba_execute_hce()
4857 retry_inner--; in ufshcd_hba_execute_hce()
4859 dev_err(hba->dev, in ufshcd_hba_execute_hce()
4862 retry_outer--; in ufshcd_hba_execute_hce()
4865 return -EIO; in ufshcd_hba_execute_hce()
4882 if (hba->quirks & UFSHCI_QUIRK_BROKEN_HCE) { in ufshcd_hba_enable()
4890 dev_err(hba->dev, "DME_RESET failed\n"); in ufshcd_hba_enable()
4896 dev_err(hba->dev, "Enabling DME failed\n"); in ufshcd_hba_enable()
4931 dev_err(hba->dev, "%s: TX LCC Disable failed, peer = %d, lane = %d, err = %d", in ufshcd_disable_tx_lcc()
4952 e = &hba->ufs_stats.event[id]; in ufshcd_update_evt_hist()
4953 e->val[e->pos] = val; in ufshcd_update_evt_hist()
4954 e->tstamp[e->pos] = local_clock(); in ufshcd_update_evt_hist()
4955 e->cnt += 1; in ufshcd_update_evt_hist()
4956 e->pos = (e->pos + 1) % UFS_EVENT_HIST_LENGTH; in ufshcd_update_evt_hist()
4963 * ufshcd_link_startup - Initialize unipro link startup
4966 * Return: 0 for success, non-zero in case of failure.
4987 /* check if device is detected by inter-connect layer */ in ufshcd_link_startup()
4992 dev_err(hba->dev, "%s: Device not present\n", __func__); in ufshcd_link_startup()
4993 ret = -ENXIO; in ufshcd_link_startup()
5000 * succeeds. So reset the local Uni-Pro and try again. in ufshcd_link_startup()
5008 } while (ret && retries--); in ufshcd_link_startup()
5024 /* Mark that link is up in PWM-G1, 1-lane, SLOW-AUTO mode */ in ufshcd_link_startup()
5028 if (hba->quirks & UFSHCD_QUIRK_BROKEN_LCC) { in ufshcd_link_startup()
5044 dev_err(hba->dev, "link startup failed %d\n", ret); in ufshcd_link_startup()
5053 * ufshcd_verify_dev_init() - Verify device initialization
5054 * @hba: per-adapter instance
5071 for (retries = NOP_OUT_RETRIES; retries > 0; retries--) { in ufshcd_verify_dev_init()
5073 hba->nop_out_timeout); in ufshcd_verify_dev_init()
5075 if (!err || err == -ETIMEDOUT) in ufshcd_verify_dev_init()
5078 dev_dbg(hba->dev, "%s: error %d retrying\n", __func__, err); in ufshcd_verify_dev_init()
5084 dev_err(hba->dev, "%s: NOP OUT failed %d\n", __func__, err); in ufshcd_verify_dev_init()
5089 * ufshcd_setup_links - associate link b/w device wlun and other luns
5101 if (hba->ufs_device_wlun) { in ufshcd_setup_links()
5102 link = device_link_add(&sdev->sdev_gendev, in ufshcd_setup_links()
5103 &hba->ufs_device_wlun->sdev_gendev, in ufshcd_setup_links()
5106 dev_err(&sdev->sdev_gendev, "Failed establishing link - %s\n", in ufshcd_setup_links()
5107 dev_name(&hba->ufs_device_wlun->sdev_gendev)); in ufshcd_setup_links()
5110 hba->luns_avail--; in ufshcd_setup_links()
5112 if (hba->luns_avail == 1) { in ufshcd_setup_links()
5121 hba->luns_avail--; in ufshcd_setup_links()
5126 * ufshcd_lu_init - Initialize the relevant parameters of the LU
5127 * @hba: per-adapter instance
5133 u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); in ufshcd_lu_init()
5134 u8 lun_qdepth = hba->nutrs; in ufshcd_lu_init()
5144 if (ret == -EOPNOTSUPP) in ufshcd_lu_init()
5153 * In per-LU queueing architecture, bLUQueueDepth will not be 0, then we will in ufshcd_lu_init()
5156 lun_qdepth = min_t(int, desc_buf[UNIT_DESC_PARAM_LU_Q_DEPTH], hba->nutrs); in ufshcd_lu_init()
5162 if (hba->dev_info.f_power_on_wp_en && lun < hba->dev_info.max_lu_supported && in ufshcd_lu_init()
5163 !hba->dev_info.is_lu_power_on_wp && in ufshcd_lu_init()
5165 hba->dev_info.is_lu_power_on_wp = true; in ufshcd_lu_init()
5170 hba->dev_info.b_advanced_rpmb_en = true; in ufshcd_lu_init()
5179 dev_dbg(hba->dev, "Set LU %x queue depth %d\n", lun, lun_qdepth); in ufshcd_lu_init()
5184 * ufshcd_slave_alloc - handle initial SCSI device configurations
5193 hba = shost_priv(sdev->host); in ufshcd_slave_alloc()
5196 sdev->use_10_for_ms = 1; in ufshcd_slave_alloc()
5199 sdev->set_dbd_for_ms = 1; in ufshcd_slave_alloc()
5202 sdev->allow_restart = 1; in ufshcd_slave_alloc()
5205 sdev->no_report_opcodes = 1; in ufshcd_slave_alloc()
5208 sdev->no_write_same = 1; in ufshcd_slave_alloc()
5218 * ufshcd_change_queue_depth - change queue depth
5228 return scsi_change_queue_depth(sdev, min(depth, sdev->host->can_queue)); in ufshcd_change_queue_depth()
5232 * ufshcd_device_configure - adjust SCSI device configurations
5241 struct ufs_hba *hba = shost_priv(sdev->host); in ufshcd_device_configure()
5242 struct request_queue *q = sdev->request_queue; in ufshcd_device_configure()
5244 lim->dma_pad_mask = PRDT_DATA_BYTE_COUNT_PAD - 1; in ufshcd_device_configure()
5247 * Block runtime-pm until all consumers are added. in ufshcd_device_configure()
5251 pm_runtime_get_noresume(&sdev->sdev_gendev); in ufshcd_device_configure()
5253 sdev->rpm_autosuspend = 1; in ufshcd_device_configure()
5255 * Do not print messages during runtime PM to avoid never-ending cycles in ufshcd_device_configure()
5259 sdev->silence_suspend = 1; in ufshcd_device_configure()
5267 * ufshcd_slave_destroy - remove SCSI device configurations
5275 hba = shost_priv(sdev->host); in ufshcd_slave_destroy()
5278 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) { in ufshcd_slave_destroy()
5279 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_slave_destroy()
5280 hba->ufs_device_wlun = NULL; in ufshcd_slave_destroy()
5281 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_slave_destroy()
5282 } else if (hba->ufs_device_wlun) { in ufshcd_slave_destroy()
5286 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_slave_destroy()
5287 if (hba->ufs_device_wlun) { in ufshcd_slave_destroy()
5288 supplier = &hba->ufs_device_wlun->sdev_gendev; in ufshcd_slave_destroy()
5291 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_slave_destroy()
5299 device_link_remove(&sdev->sdev_gendev, supplier); in ufshcd_slave_destroy()
5306 * ufshcd_scsi_cmd_status - Update SCSI command result based on SCSI status
5339 * ufshcd_transfer_rsp_status - Get overall status of the response
5356 upiu_flags = lrbp->ucd_rsp_ptr->header.flags; in ufshcd_transfer_rsp_status()
5357 resid = be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count); in ufshcd_transfer_rsp_status()
5363 scsi_set_resid(lrbp->cmd, resid); in ufshcd_transfer_rsp_status()
5368 if (hba->quirks & UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR) { in ufshcd_transfer_rsp_status()
5369 if (lrbp->ucd_rsp_ptr->header.response || in ufshcd_transfer_rsp_status()
5370 lrbp->ucd_rsp_ptr->header.status) in ufshcd_transfer_rsp_status()
5376 hba->ufs_stats.last_hibern8_exit_tstamp = ktime_set(0, 0); in ufshcd_transfer_rsp_status()
5377 switch (ufshcd_get_req_rsp(lrbp->ucd_rsp_ptr)) { in ufshcd_transfer_rsp_status()
5383 scsi_status = lrbp->ucd_rsp_ptr->header.status; in ufshcd_transfer_rsp_status()
5398 if (!hba->pm_op_in_progress && in ufshcd_transfer_rsp_status()
5400 ufshcd_is_exception_event(lrbp->ucd_rsp_ptr)) in ufshcd_transfer_rsp_status()
5402 schedule_work(&hba->eeh_work); in ufshcd_transfer_rsp_status()
5407 dev_err(hba->dev, in ufshcd_transfer_rsp_status()
5411 dev_err(hba->dev, in ufshcd_transfer_rsp_status()
5421 dev_warn(hba->dev, in ufshcd_transfer_rsp_status()
5424 lrbp->task_tag); in ufshcd_transfer_rsp_status()
5437 dev_err(hba->dev, in ufshcd_transfer_rsp_status()
5439 ocs, lrbp->task_tag); in ufshcd_transfer_rsp_status()
5446 (host_byte(result) != DID_REQUEUE) && !hba->silence_err_logs) in ufshcd_transfer_rsp_status()
5447 ufshcd_print_tr(hba, lrbp->task_tag, true); in ufshcd_transfer_rsp_status()
5461 if (hba->active_uic_cmd && in ufshcd_is_auto_hibern8_error()
5462 (hba->active_uic_cmd->command == UIC_CMD_DME_HIBER_ENTER || in ufshcd_is_auto_hibern8_error()
5463 hba->active_uic_cmd->command == UIC_CMD_DME_HIBER_EXIT)) in ufshcd_is_auto_hibern8_error()
5470 * ufshcd_uic_cmd_compl - handle completion of uic command
5475 * IRQ_HANDLED - If interrupt is valid
5476 * IRQ_NONE - If invalid interrupt
5482 spin_lock(hba->host->host_lock); in ufshcd_uic_cmd_compl()
5484 hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status); in ufshcd_uic_cmd_compl()
5486 if ((intr_status & UIC_COMMAND_COMPL) && hba->active_uic_cmd) { in ufshcd_uic_cmd_compl()
5487 hba->active_uic_cmd->argument2 |= in ufshcd_uic_cmd_compl()
5489 hba->active_uic_cmd->argument3 = in ufshcd_uic_cmd_compl()
5491 if (!hba->uic_async_done) in ufshcd_uic_cmd_compl()
5492 hba->active_uic_cmd->cmd_active = 0; in ufshcd_uic_cmd_compl()
5493 complete(&hba->active_uic_cmd->done); in ufshcd_uic_cmd_compl()
5497 if ((intr_status & UFSHCD_UIC_PWR_MASK) && hba->uic_async_done) { in ufshcd_uic_cmd_compl()
5498 hba->active_uic_cmd->cmd_active = 0; in ufshcd_uic_cmd_compl()
5499 complete(hba->uic_async_done); in ufshcd_uic_cmd_compl()
5504 ufshcd_add_uic_command_trace(hba, hba->active_uic_cmd, in ufshcd_uic_cmd_compl()
5506 spin_unlock(hba->host->host_lock); in ufshcd_uic_cmd_compl()
5514 struct scsi_cmnd *cmd = lrbp->cmd; in ufshcd_release_scsi_cmd()
5523 * ufshcd_compl_one_cqe - handle a completion queue entry
5535 lrbp = &hba->lrb[task_tag]; in ufshcd_compl_one_cqe()
5536 lrbp->compl_time_stamp = ktime_get(); in ufshcd_compl_one_cqe()
5537 cmd = lrbp->cmd; in ufshcd_compl_one_cqe()
5542 cmd->result = ufshcd_transfer_rsp_status(hba, lrbp, cqe); in ufshcd_compl_one_cqe()
5546 } else if (hba->dev_cmd.complete) { in ufshcd_compl_one_cqe()
5548 ocs = le32_to_cpu(cqe->status) & MASK_OCS; in ufshcd_compl_one_cqe()
5549 lrbp->utr_descriptor_ptr->header.ocs = ocs; in ufshcd_compl_one_cqe()
5551 complete(hba->dev_cmd.complete); in ufshcd_compl_one_cqe()
5556 * __ufshcd_transfer_req_compl - handle SCSI and query command completion
5565 for_each_set_bit(tag, &completed_reqs, hba->nutrs) in __ufshcd_transfer_req_compl()
5571 UFSHCD_POLL_FROM_INTERRUPT_CONTEXT = -1
5579 for_each_set_bit(tag, completed_reqs, hba->nutrs) { in ufshcd_clear_polled()
5580 struct scsi_cmnd *cmd = hba->lrb[tag].cmd; in ufshcd_clear_polled()
5584 if (scsi_cmd_to_rq(cmd)->cmd_flags & REQ_POLLED) in ufshcd_clear_polled()
5600 if (hba->mcq_enabled) { in ufshcd_poll()
5601 hwq = &hba->uhq[queue_num]; in ufshcd_poll()
5606 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_poll()
5608 completed_reqs = ~tr_doorbell & hba->outstanding_reqs; in ufshcd_poll()
5609 WARN_ONCE(completed_reqs & ~hba->outstanding_reqs, in ufshcd_poll()
5611 hba->outstanding_reqs); in ufshcd_poll()
5616 hba->outstanding_reqs &= ~completed_reqs; in ufshcd_poll()
5617 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_poll()
5626 * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is
5645 for (tag = 0; tag < hba->nutrs; tag++) { in ufshcd_mcq_compl_pending_transfer()
5646 lrbp = &hba->lrb[tag]; in ufshcd_mcq_compl_pending_transfer()
5647 cmd = lrbp->cmd; in ufshcd_mcq_compl_pending_transfer()
5649 test_bit(SCMD_STATE_COMPLETE, &cmd->state)) in ufshcd_mcq_compl_pending_transfer()
5660 spin_lock_irqsave(&hwq->cq_lock, flags); in ufshcd_mcq_compl_pending_transfer()
5661 if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { in ufshcd_mcq_compl_pending_transfer()
5666 spin_unlock_irqrestore(&hwq->cq_lock, flags); in ufshcd_mcq_compl_pending_transfer()
5674 * ufshcd_transfer_req_compl - handle SCSI and query command completion
5678 * IRQ_HANDLED - If interrupt is valid
5679 * IRQ_NONE - If invalid interrupt
5691 !(hba->quirks & UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR)) in ufshcd_transfer_req_compl()
5701 ufshcd_poll(hba->host, UFSHCD_POLL_FROM_INTERRUPT_CONTEXT); in ufshcd_transfer_req_compl()
5717 mutex_lock(&hba->ee_ctrl_mutex); in ufshcd_write_ee_control()
5718 err = __ufshcd_write_ee_control(hba, hba->ee_ctrl_mask); in ufshcd_write_ee_control()
5719 mutex_unlock(&hba->ee_ctrl_mutex); in ufshcd_write_ee_control()
5721 dev_err(hba->dev, "%s: failed to write ee control %d\n", in ufshcd_write_ee_control()
5732 mutex_lock(&hba->ee_ctrl_mutex); in ufshcd_update_ee_control()
5735 if (ee_ctrl_mask != hba->ee_ctrl_mask) in ufshcd_update_ee_control()
5739 hba->ee_ctrl_mask = ee_ctrl_mask; in ufshcd_update_ee_control()
5742 mutex_unlock(&hba->ee_ctrl_mutex); in ufshcd_update_ee_control()
5747 * ufshcd_disable_ee - disable exception event
5748 * @hba: per-adapter instance
5754 * Return: zero on success, non-zero error value on failure.
5762 * ufshcd_enable_ee - enable exception event
5763 * @hba: per-adapter instance
5769 * Return: zero on success, non-zero error value on failure.
5777 * ufshcd_enable_auto_bkops - Allow device managed BKOPS
5778 * @hba: per-adapter instance
5785 * Return: zero on success, non-zero on failure.
5791 if (hba->auto_bkops_enabled) in ufshcd_enable_auto_bkops()
5797 dev_err(hba->dev, "%s: failed to enable bkops %d\n", in ufshcd_enable_auto_bkops()
5802 hba->auto_bkops_enabled = true; in ufshcd_enable_auto_bkops()
5803 trace_ufshcd_auto_bkops_state(dev_name(hba->dev), "Enabled"); in ufshcd_enable_auto_bkops()
5808 dev_err(hba->dev, "%s: failed to disable exception event %d\n", in ufshcd_enable_auto_bkops()
5815 * ufshcd_disable_auto_bkops - block device in doing background operations
5816 * @hba: per-adapter instance
5820 * not-operable. Make sure to call ufshcd_enable_auto_bkops() whenever the
5824 * Return: zero on success, non-zero on failure.
5830 if (!hba->auto_bkops_enabled) in ufshcd_disable_auto_bkops()
5839 dev_err(hba->dev, "%s: failed to enable exception event %d\n", in ufshcd_disable_auto_bkops()
5847 dev_err(hba->dev, "%s: failed to disable bkops %d\n", in ufshcd_disable_auto_bkops()
5853 hba->auto_bkops_enabled = false; in ufshcd_disable_auto_bkops()
5854 trace_ufshcd_auto_bkops_state(dev_name(hba->dev), "Disabled"); in ufshcd_disable_auto_bkops()
5855 hba->is_urgent_bkops_lvl_checked = false; in ufshcd_disable_auto_bkops()
5861 * ufshcd_force_reset_auto_bkops - force reset auto bkops state
5866 * as well. This function would change the auto-bkops state based on
5872 hba->auto_bkops_enabled = false; in ufshcd_force_reset_auto_bkops()
5873 hba->ee_ctrl_mask |= MASK_EE_URGENT_BKOPS; in ufshcd_force_reset_auto_bkops()
5876 hba->auto_bkops_enabled = true; in ufshcd_force_reset_auto_bkops()
5877 hba->ee_ctrl_mask &= ~MASK_EE_URGENT_BKOPS; in ufshcd_force_reset_auto_bkops()
5880 hba->urgent_bkops_lvl = BKOPS_STATUS_PERF_IMPACT; in ufshcd_force_reset_auto_bkops()
5881 hba->is_urgent_bkops_lvl_checked = false; in ufshcd_force_reset_auto_bkops()
5891 * ufshcd_bkops_ctrl - control the auto bkops based on current bkops status
5892 * @hba: per-adapter instance
5896 * bkops_status is greater than or equal to the "hba->urgent_bkops_lvl",
5899 * Return: 0 for success, non-zero in case of failure.
5901 * NOTE: Caller of this function can check the "hba->auto_bkops_enabled" flag
5907 enum bkops_status status = hba->urgent_bkops_lvl; in ufshcd_bkops_ctrl()
5913 dev_err(hba->dev, "%s: failed to get BKOPS status %d\n", in ufshcd_bkops_ctrl()
5917 dev_err(hba->dev, "%s: invalid BKOPS status %d\n", in ufshcd_bkops_ctrl()
5919 err = -EINVAL; in ufshcd_bkops_ctrl()
5942 if (hba->is_urgent_bkops_lvl_checked) in ufshcd_bkops_exception_event_handler()
5947 dev_err(hba->dev, "%s: failed to get BKOPS status %d\n", in ufshcd_bkops_exception_event_handler()
5959 dev_err(hba->dev, "%s: device raised urgent BKOPS exception for bkops status %d\n", in ufshcd_bkops_exception_event_handler()
5962 hba->urgent_bkops_lvl = curr_status; in ufshcd_bkops_exception_event_handler()
5963 hba->is_urgent_bkops_lvl_checked = true; in ufshcd_bkops_exception_event_handler()
5970 dev_err(hba->dev, "%s: failed to handle urgent bkops %d\n", in ufshcd_bkops_exception_event_handler()
5982 dev_info(hba->dev, "exception Tcase %d\n", value - 80); in ufshcd_temp_exception_event_handler()
6007 hba->dev_info.wb_enabled == enable) in ufshcd_wb_toggle()
6012 dev_err(hba->dev, "%s: Write Booster %s failed %d\n", in ufshcd_wb_toggle()
6017 hba->dev_info.wb_enabled = enable; in ufshcd_wb_toggle()
6018 dev_dbg(hba->dev, "%s: Write Booster %s\n", in ufshcd_wb_toggle()
6032 dev_err(hba->dev, "%s: WB-Buf Flush during H8 %s failed %d\n", in ufshcd_wb_toggle_buf_flush_during_h8()
6036 dev_dbg(hba->dev, "%s: WB-Buf Flush during H8 %s\n", in ufshcd_wb_toggle_buf_flush_during_h8()
6045 hba->dev_info.wb_buf_flush_enabled == enable) in ufshcd_wb_toggle_buf_flush()
6050 dev_err(hba->dev, "%s: WB-Buf Flush %s failed %d\n", in ufshcd_wb_toggle_buf_flush()
6055 hba->dev_info.wb_buf_flush_enabled = enable; in ufshcd_wb_toggle_buf_flush()
6056 dev_dbg(hba->dev, "%s: WB-Buf Flush %s\n", in ufshcd_wb_toggle_buf_flush()
6074 dev_err(hba->dev, "%s: dCurWriteBoosterBufferSize read failed %d\n", in ufshcd_wb_presrv_usrspc_keep_vcc_on()
6080 dev_info(hba->dev, "dCurWBBuf: %d WB disabled until free-space is available\n", in ufshcd_wb_presrv_usrspc_keep_vcc_on()
6085 return avail_buf < hba->vps->wb_flush_threshold; in ufshcd_wb_presrv_usrspc_keep_vcc_on()
6095 hba->caps &= ~UFSHCD_CAP_WB_EN; in ufshcd_wb_force_disable()
6097 dev_info(hba->dev, "%s: WB force disabled\n", __func__); in ufshcd_wb_force_disable()
6111 dev_err(hba->dev, in ufshcd_is_wb_buf_lifetime_available()
6118 dev_err(hba->dev, "%s: WB buf lifetime is exhausted 0x%02X\n", in ufshcd_is_wb_buf_lifetime_available()
6123 dev_dbg(hba->dev, "%s: WB buf lifetime is 0x%02X\n", in ufshcd_is_wb_buf_lifetime_available()
6145 * With user-space reduction enabled, it's enough to enable flush in ufshcd_wb_need_flush()
6148 * With user-space preserved enabled, the current-buffer in ufshcd_wb_need_flush()
6159 dev_warn(hba->dev, "%s: dAvailableWriteBoosterBufferSize read failed %d\n", in ufshcd_wb_need_flush()
6164 if (!hba->dev_info.b_presrv_uspc_en) in ufshcd_wb_need_flush()
6186 * ufshcd_exception_event_handler - handle exceptions raised by device
6202 dev_err(hba->dev, "%s: failed to get exception status %d\n", in ufshcd_exception_event_handler()
6207 trace_ufshcd_exception_event(dev_name(hba->dev), status); in ufshcd_exception_event_handler()
6209 if (status & hba->ee_drv_mask & MASK_EE_URGENT_BKOPS) in ufshcd_exception_event_handler()
6212 if (status & hba->ee_drv_mask & MASK_EE_URGENT_TEMP) in ufshcd_exception_event_handler()
6220 /* Complete requests that have door-bell cleared */
6223 if (hba->mcq_enabled) in ufshcd_complete_requests()
6232 * ufshcd_quirk_dl_nac_errors - This function checks if error handling is
6234 * @hba: per-adapter instance
6243 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6248 if (hba->saved_err & (CONTROLLER_FATAL_ERROR | SYSTEM_BUS_FATAL_ERROR)) in ufshcd_quirk_dl_nac_errors()
6251 if ((hba->saved_err & DEVICE_FATAL_ERROR) || in ufshcd_quirk_dl_nac_errors()
6252 ((hba->saved_err & UIC_ERROR) && in ufshcd_quirk_dl_nac_errors()
6253 (hba->saved_uic_err & UFSHCD_UIC_DL_TCx_REPLAY_ERROR))) in ufshcd_quirk_dl_nac_errors()
6256 if ((hba->saved_err & UIC_ERROR) && in ufshcd_quirk_dl_nac_errors()
6257 (hba->saved_uic_err & UFSHCD_UIC_DL_NAC_RECEIVED_ERROR)) { in ufshcd_quirk_dl_nac_errors()
6262 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6264 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6270 if ((hba->saved_err & INT_FATAL_ERRORS) || in ufshcd_quirk_dl_nac_errors()
6271 ((hba->saved_err & UIC_ERROR) && in ufshcd_quirk_dl_nac_errors()
6272 (hba->saved_uic_err & ~UFSHCD_UIC_DL_NAC_RECEIVED_ERROR))) in ufshcd_quirk_dl_nac_errors()
6278 * - If we don't get any response then do error recovery. in ufshcd_quirk_dl_nac_errors()
6279 * - If we get response then clear the DL NAC error bit. in ufshcd_quirk_dl_nac_errors()
6282 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6284 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6290 if (hba->saved_uic_err == UFSHCD_UIC_DL_NAC_RECEIVED_ERROR) in ufshcd_quirk_dl_nac_errors()
6291 hba->saved_err &= ~UIC_ERROR; in ufshcd_quirk_dl_nac_errors()
6293 hba->saved_uic_err &= ~UFSHCD_UIC_DL_NAC_RECEIVED_ERROR; in ufshcd_quirk_dl_nac_errors()
6294 if (!hba->saved_uic_err) in ufshcd_quirk_dl_nac_errors()
6298 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_quirk_dl_nac_errors()
6305 return (hba->saved_uic_err & UFSHCD_UIC_DL_PA_INIT_ERROR) || in ufshcd_is_saved_err_fatal()
6306 (hba->saved_err & (INT_FATAL_ERRORS | UFSHCD_UIC_HIBERN8_MASK)); in ufshcd_is_saved_err_fatal()
6311 lockdep_assert_held(hba->host->host_lock); in ufshcd_schedule_eh_work()
6314 if (hba->ufshcd_state != UFSHCD_STATE_ERROR) { in ufshcd_schedule_eh_work()
6315 if (hba->force_reset || ufshcd_is_link_broken(hba) || in ufshcd_schedule_eh_work()
6317 hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_FATAL; in ufshcd_schedule_eh_work()
6319 hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_NON_FATAL; in ufshcd_schedule_eh_work()
6320 queue_work(hba->eh_wq, &hba->eh_work); in ufshcd_schedule_eh_work()
6326 spin_lock_irq(hba->host->host_lock); in ufshcd_force_error_recovery()
6327 hba->force_reset = true; in ufshcd_force_error_recovery()
6329 spin_unlock_irq(hba->host->host_lock); in ufshcd_force_error_recovery()
6334 mutex_lock(&hba->wb_mutex); in ufshcd_clk_scaling_allow()
6335 down_write(&hba->clk_scaling_lock); in ufshcd_clk_scaling_allow()
6336 hba->clk_scaling.is_allowed = allow; in ufshcd_clk_scaling_allow()
6337 up_write(&hba->clk_scaling_lock); in ufshcd_clk_scaling_allow()
6338 mutex_unlock(&hba->wb_mutex); in ufshcd_clk_scaling_allow()
6344 if (hba->clk_scaling.is_enabled) in ufshcd_clk_scaling_suspend()
6349 if (hba->clk_scaling.is_enabled) in ufshcd_clk_scaling_suspend()
6357 if (pm_runtime_status_suspended(&hba->ufs_device_wlun->sdev_gendev) || in ufshcd_err_handling_prepare()
6358 hba->is_sys_suspended) { in ufshcd_err_handling_prepare()
6369 ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq); in ufshcd_err_handling_prepare()
6370 ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq2); in ufshcd_err_handling_prepare()
6374 pm_op = hba->is_sys_suspended ? UFS_SYSTEM_PM : UFS_RUNTIME_PM; in ufshcd_err_handling_prepare()
6379 hba->clk_scaling.is_enabled) in ufshcd_err_handling_prepare()
6385 blk_mq_wait_quiesce_done(&hba->host->tag_set); in ufshcd_err_handling_prepare()
6386 cancel_work_sync(&hba->eeh_work); in ufshcd_err_handling_prepare()
6400 return (!hba->is_powered || hba->shutting_down || in ufshcd_err_handling_should_stop()
6401 !hba->ufs_device_wlun || in ufshcd_err_handling_should_stop()
6402 hba->ufshcd_state == UFSHCD_STATE_ERROR || in ufshcd_err_handling_should_stop()
6403 (!(hba->saved_err || hba->saved_uic_err || hba->force_reset || in ufshcd_err_handling_should_stop()
6410 struct Scsi_Host *shost = hba->host; in ufshcd_recover_pm_error()
6415 hba->is_sys_suspended = false; in ufshcd_recover_pm_error()
6420 ret = pm_runtime_set_active(&hba->ufs_device_wlun->sdev_gendev); in ufshcd_recover_pm_error()
6424 ret = pm_runtime_set_active(hba->dev); in ufshcd_recover_pm_error()
6433 q = sdev->request_queue; in ufshcd_recover_pm_error()
6434 if (q->dev && (q->rpm_status == RPM_SUSPENDED || in ufshcd_recover_pm_error()
6435 q->rpm_status == RPM_SUSPENDING)) in ufshcd_recover_pm_error()
6436 pm_request_resume(q->dev); in ufshcd_recover_pm_error()
6448 struct ufs_pa_layer_attr *pwr_info = &hba->pwr_info; in ufshcd_is_pwr_mode_restore_needed()
6453 if (pwr_info->pwr_rx != ((mode >> PWRMODE_RX_OFFSET) & PWRMODE_MASK)) in ufshcd_is_pwr_mode_restore_needed()
6456 if (pwr_info->pwr_tx != (mode & PWRMODE_MASK)) in ufshcd_is_pwr_mode_restore_needed()
6465 u32 tag = rq->tag; in ufshcd_abort_one()
6467 struct scsi_device *sdev = cmd->device; in ufshcd_abort_one()
6468 struct Scsi_Host *shost = sdev->host; in ufshcd_abort_one()
6472 dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, in ufshcd_abort_one()
6473 hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, in ufshcd_abort_one()
6480 * ufshcd_abort_all - Abort all pending commands.
6489 blk_mq_tagset_busy_iter(&hba->host->tag_set, ufshcd_abort_one, &ret); in ufshcd_abort_all()
6494 for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) { in ufshcd_abort_all()
6508 * ufshcd_err_handler - handle UFS errors that require s/w attention
6522 dev_info(hba->dev, in ufshcd_err_handler()
6524 __func__, ufshcd_state_name[hba->ufshcd_state], in ufshcd_err_handler()
6525 hba->is_powered, hba->shutting_down, hba->saved_err, in ufshcd_err_handler()
6526 hba->saved_uic_err, hba->force_reset, in ufshcd_err_handler()
6529 down(&hba->host_sem); in ufshcd_err_handler()
6530 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6532 if (hba->ufshcd_state != UFSHCD_STATE_ERROR) in ufshcd_err_handler()
6533 hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; in ufshcd_err_handler()
6534 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6535 up(&hba->host_sem); in ufshcd_err_handler()
6539 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6541 /* Complete requests that have door-bell cleared by h/w */ in ufshcd_err_handler()
6543 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6548 if (hba->ufshcd_state != UFSHCD_STATE_ERROR) in ufshcd_err_handler()
6549 hba->ufshcd_state = UFSHCD_STATE_RESET; in ufshcd_err_handler()
6557 if ((hba->dev_quirks & UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS) && in ufshcd_err_handler()
6558 !hba->force_reset) { in ufshcd_err_handler()
6561 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6564 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6569 if ((hba->saved_err & (INT_FATAL_ERRORS | UFSHCD_UIC_HIBERN8_MASK)) || in ufshcd_err_handler()
6570 (hba->saved_uic_err && in ufshcd_err_handler()
6571 (hba->saved_uic_err != UFSHCD_UIC_PA_GENERIC_ERROR))) { in ufshcd_err_handler()
6572 bool pr_prdt = !!(hba->saved_err & SYSTEM_BUS_FATAL_ERROR); in ufshcd_err_handler()
6574 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6578 ufshcd_print_tmrs(hba, hba->outstanding_tasks); in ufshcd_err_handler()
6580 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6588 if (hba->force_reset || ufshcd_is_link_broken(hba) || in ufshcd_err_handler()
6590 ((hba->saved_err & UIC_ERROR) && in ufshcd_err_handler()
6591 (hba->saved_uic_err & (UFSHCD_UIC_DL_NAC_RECEIVED_ERROR | in ufshcd_err_handler()
6601 if (hba->saved_uic_err & UFSHCD_UIC_PA_GENERIC_ERROR) { in ufshcd_err_handler()
6602 hba->saved_uic_err &= ~UFSHCD_UIC_PA_GENERIC_ERROR; in ufshcd_err_handler()
6603 if (!hba->saved_uic_err) in ufshcd_err_handler()
6604 hba->saved_err &= ~UIC_ERROR; in ufshcd_err_handler()
6605 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6608 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6609 if (!hba->saved_err && !needs_restore) in ufshcd_err_handler()
6613 hba->silence_err_logs = true; in ufshcd_err_handler()
6615 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6619 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6620 hba->silence_err_logs = false; in ufshcd_err_handler()
6629 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6634 down_write(&hba->clk_scaling_lock); in ufshcd_err_handler()
6635 hba->force_pmc = true; in ufshcd_err_handler()
6636 pmc_err = ufshcd_config_pwr_mode(hba, &(hba->pwr_info)); in ufshcd_err_handler()
6639 dev_err(hba->dev, "%s: Failed to restore power mode, err = %d\n", in ufshcd_err_handler()
6642 hba->force_pmc = false; in ufshcd_err_handler()
6644 up_write(&hba->clk_scaling_lock); in ufshcd_err_handler()
6645 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6653 hba->force_reset = false; in ufshcd_err_handler()
6654 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6657 dev_err(hba->dev, "%s: reset and restore failed with err %d\n", in ufshcd_err_handler()
6661 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_err_handler()
6666 if (hba->ufshcd_state == UFSHCD_STATE_RESET) in ufshcd_err_handler()
6667 hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; in ufshcd_err_handler()
6668 if (hba->saved_err || hba->saved_uic_err) in ufshcd_err_handler()
6669 dev_err_ratelimited(hba->dev, "%s: exit: saved_err 0x%x saved_uic_err 0x%x", in ufshcd_err_handler()
6670 __func__, hba->saved_err, hba->saved_uic_err); in ufshcd_err_handler()
6673 if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL && in ufshcd_err_handler()
6674 hba->ufshcd_state != UFSHCD_STATE_ERROR) { in ufshcd_err_handler()
6675 if (--retries) in ufshcd_err_handler()
6677 hba->ufshcd_state = UFSHCD_STATE_ERROR; in ufshcd_err_handler()
6680 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_err_handler()
6682 up(&hba->host_sem); in ufshcd_err_handler()
6684 dev_info(hba->dev, "%s finished; HBA state %s\n", __func__, in ufshcd_err_handler()
6685 ufshcd_state_name[hba->ufshcd_state]); in ufshcd_err_handler()
6689 * ufshcd_update_uic_error - check and set fatal UIC error flags.
6690 * @hba: per-adapter instance
6693 * IRQ_HANDLED - If interrupt is valid
6694 * IRQ_NONE - If invalid interrupt
6711 dev_dbg(hba->dev, "%s: UIC Lane error reported\n", in ufshcd_update_uic_error()
6718 hba->uic_error |= UFSHCD_UIC_PA_GENERIC_ERROR; in ufshcd_update_uic_error()
6719 if (hba->uic_async_done && hba->active_uic_cmd) in ufshcd_update_uic_error()
6720 cmd = hba->active_uic_cmd; in ufshcd_update_uic_error()
6725 if (cmd && (cmd->command == UIC_CMD_DME_SET)) in ufshcd_update_uic_error()
6726 hba->uic_error &= ~UFSHCD_UIC_PA_GENERIC_ERROR; in ufshcd_update_uic_error()
6738 hba->uic_error |= UFSHCD_UIC_DL_PA_INIT_ERROR; in ufshcd_update_uic_error()
6739 else if (hba->dev_quirks & in ufshcd_update_uic_error()
6742 hba->uic_error |= in ufshcd_update_uic_error()
6745 hba->uic_error |= UFSHCD_UIC_DL_TCx_REPLAY_ERROR; in ufshcd_update_uic_error()
6755 hba->uic_error |= UFSHCD_UIC_NL_ERROR; in ufshcd_update_uic_error()
6763 hba->uic_error |= UFSHCD_UIC_TL_ERROR; in ufshcd_update_uic_error()
6771 hba->uic_error |= UFSHCD_UIC_DME_ERROR; in ufshcd_update_uic_error()
6775 dev_dbg(hba->dev, "%s: UIC error flags = 0x%08x\n", in ufshcd_update_uic_error()
6776 __func__, hba->uic_error); in ufshcd_update_uic_error()
6781 * ufshcd_check_errors - Check for errors that need s/w attention
6782 * @hba: per-adapter instance
6786 * IRQ_HANDLED - If interrupt is valid
6787 * IRQ_NONE - If invalid interrupt
6794 spin_lock(hba->host->host_lock); in ufshcd_check_errors()
6795 hba->errors |= UFSHCD_ERROR_MASK & intr_status; in ufshcd_check_errors()
6797 if (hba->errors & INT_FATAL_ERRORS) { in ufshcd_check_errors()
6799 hba->errors); in ufshcd_check_errors()
6803 if (hba->errors & UIC_ERROR) { in ufshcd_check_errors()
6804 hba->uic_error = 0; in ufshcd_check_errors()
6806 if (hba->uic_error) in ufshcd_check_errors()
6810 if (hba->errors & UFSHCD_UIC_HIBERN8_MASK) { in ufshcd_check_errors()
6811 dev_err(hba->dev, in ufshcd_check_errors()
6812 "%s: Auto Hibern8 %s failed - status: 0x%08x, upmcrs: 0x%08x\n", in ufshcd_check_errors()
6813 __func__, (hba->errors & UIC_HIBERNATE_ENTER) ? in ufshcd_check_errors()
6815 hba->errors, ufshcd_get_upmcrs(hba)); in ufshcd_check_errors()
6817 hba->errors); in ufshcd_check_errors()
6827 hba->saved_err |= hba->errors; in ufshcd_check_errors()
6828 hba->saved_uic_err |= hba->uic_error; in ufshcd_check_errors()
6831 if ((hba->saved_err & in ufshcd_check_errors()
6833 (hba->saved_uic_err && in ufshcd_check_errors()
6834 (hba->saved_uic_err != UFSHCD_UIC_PA_GENERIC_ERROR))) { in ufshcd_check_errors()
6835 dev_err(hba->dev, "%s: saved_err 0x%x saved_uic_err 0x%x\n", in ufshcd_check_errors()
6836 __func__, hba->saved_err, in ufshcd_check_errors()
6837 hba->saved_uic_err); in ufshcd_check_errors()
6846 * if (!queue_eh_work) - in ufshcd_check_errors()
6847 * Other errors are either non-fatal where host recovers in ufshcd_check_errors()
6851 hba->errors = 0; in ufshcd_check_errors()
6852 hba->uic_error = 0; in ufshcd_check_errors()
6853 spin_unlock(hba->host->host_lock); in ufshcd_check_errors()
6858 * ufshcd_tmc_handler - handle task management function completion
6862 * IRQ_HANDLED - If interrupt is valid
6863 * IRQ_NONE - If invalid interrupt
6871 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_tmc_handler()
6873 issued = hba->outstanding_tasks & ~pending; in ufshcd_tmc_handler()
6874 for_each_set_bit(tag, &issued, hba->nutmrs) { in ufshcd_tmc_handler()
6875 struct request *req = hba->tmf_rqs[tag]; in ufshcd_tmc_handler()
6876 struct completion *c = req->end_io_data; in ufshcd_tmc_handler()
6881 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_tmc_handler()
6887 * ufshcd_handle_mcq_cq_events - handle MCQ completion queue events
6902 outstanding_cqs = (1U << hba->nr_hw_queues) - 1; in ufshcd_handle_mcq_cq_events()
6905 nr_queues = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL]; in ufshcd_handle_mcq_cq_events()
6907 hwq = &hba->uhq[i]; in ufshcd_handle_mcq_cq_events()
6921 * ufshcd_sl_intr - Interrupt service routine
6926 * IRQ_HANDLED - If interrupt is valid
6927 * IRQ_NONE - If invalid interrupt
6936 if (intr_status & UFSHCD_ERROR_MASK || hba->errors) in ufshcd_sl_intr()
6952 * ufshcd_intr - Main interrupt service routine
6957 * IRQ_HANDLED - If interrupt is valid
6958 * IRQ_NONE - If invalid interrupt
6965 int retries = hba->nutrs; in ufshcd_intr()
6968 hba->ufs_stats.last_intr_status = intr_status; in ufshcd_intr()
6969 hba->ufs_stats.last_intr_ts = local_clock(); in ufshcd_intr()
6972 * There could be max of hba->nutrs reqs in flight and in worst case in ufshcd_intr()
6977 while (intr_status && retries--) { in ufshcd_intr()
6989 hba->outstanding_reqs) && !ufshcd_eh_in_progress(hba)) { in ufshcd_intr()
6990 dev_err(hba->dev, "%s: Unhandled interrupt 0x%08x (0x%08x, 0x%08x)\n", in ufshcd_intr()
6993 hba->ufs_stats.last_intr_status, in ufshcd_intr()
7007 if (!test_bit(tag, &hba->outstanding_tasks)) in ufshcd_clear_tm_cmd()
7010 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_clear_tm_cmd()
7012 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_clear_tm_cmd()
7019 dev_err(hba->dev, "Clearing task management function with tag %d %s\n", in ufshcd_clear_tm_cmd()
7029 struct request_queue *q = hba->tmf_queue; in __ufshcd_issue_tm_cmd()
7030 struct Scsi_Host *host = hba->host; in __ufshcd_issue_tm_cmd()
7043 req->end_io_data = &wait; in __ufshcd_issue_tm_cmd()
7046 spin_lock_irqsave(host->host_lock, flags); in __ufshcd_issue_tm_cmd()
7048 task_tag = req->tag; in __ufshcd_issue_tm_cmd()
7049 hba->tmf_rqs[req->tag] = req; in __ufshcd_issue_tm_cmd()
7050 treq->upiu_req.req_header.task_tag = task_tag; in __ufshcd_issue_tm_cmd()
7052 memcpy(hba->utmrdl_base_addr + task_tag, treq, sizeof(*treq)); in __ufshcd_issue_tm_cmd()
7056 __set_bit(task_tag, &hba->outstanding_tasks); in __ufshcd_issue_tm_cmd()
7059 spin_unlock_irqrestore(host->host_lock, flags); in __ufshcd_issue_tm_cmd()
7068 dev_err(hba->dev, "%s: task management cmd 0x%.2x timed-out\n", in __ufshcd_issue_tm_cmd()
7071 dev_WARN(hba->dev, "%s: unable to clear tm cmd (slot %d) after timeout\n", in __ufshcd_issue_tm_cmd()
7073 err = -ETIMEDOUT; in __ufshcd_issue_tm_cmd()
7076 memcpy(treq, hba->utmrdl_base_addr + task_tag, sizeof(*treq)); in __ufshcd_issue_tm_cmd()
7081 spin_lock_irqsave(hba->host->host_lock, flags); in __ufshcd_issue_tm_cmd()
7082 hba->tmf_rqs[req->tag] = NULL; in __ufshcd_issue_tm_cmd()
7083 __clear_bit(task_tag, &hba->outstanding_tasks); in __ufshcd_issue_tm_cmd()
7084 spin_unlock_irqrestore(hba->host->host_lock, flags); in __ufshcd_issue_tm_cmd()
7093 * ufshcd_issue_tm_cmd - issues task management commands to controller
7100 * Return: non-zero value on error, zero on success.
7126 if (err == -ETIMEDOUT) in ufshcd_issue_tm_cmd()
7131 dev_err(hba->dev, "%s: failed, ocs = 0x%x\n", in ufshcd_issue_tm_cmd()
7140 * ufshcd_issue_devman_upiu_cmd - API for sending "utrd" type requests
7141 * @hba: per-adapter instance
7149 * Those type of requests uses UTP Transfer Request Descriptor - utrd.
7154 * the caller is expected to hold the hba->dev_cmd.lock mutex.
7165 const u32 tag = hba->reserved_slot; in ufshcd_issue_devman_upiu_cmd()
7166 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_issue_devman_upiu_cmd()
7170 /* Protects use of hba->reserved_slot. */ in ufshcd_issue_devman_upiu_cmd()
7171 lockdep_assert_held(&hba->dev_cmd.lock); in ufshcd_issue_devman_upiu_cmd()
7178 req_upiu->header.task_tag = tag; in ufshcd_issue_devman_upiu_cmd()
7181 memcpy(lrbp->ucd_req_ptr, req_upiu, sizeof(*lrbp->ucd_req_ptr)); in ufshcd_issue_devman_upiu_cmd()
7187 memcpy(lrbp->ucd_req_ptr + 1, desc_buff, *buff_len); in ufshcd_issue_devman_upiu_cmd()
7191 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); in ufshcd_issue_devman_upiu_cmd()
7194 * ignore the returning value here - ufshcd_check_query_response is in ufshcd_issue_devman_upiu_cmd()
7201 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); in ufshcd_issue_devman_upiu_cmd()
7203 u8 *descp = (u8 *)lrbp->ucd_rsp_ptr + sizeof(*rsp_upiu); in ufshcd_issue_devman_upiu_cmd()
7204 u16 resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header in ufshcd_issue_devman_upiu_cmd()
7211 dev_warn(hba->dev, in ufshcd_issue_devman_upiu_cmd()
7215 err = -EINVAL; in ufshcd_issue_devman_upiu_cmd()
7219 (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); in ufshcd_issue_devman_upiu_cmd()
7225 * ufshcd_exec_raw_upiu_cmd - API function for sending raw upiu commands
7226 * @hba: per-adapter instance
7228 * @rsp_upiu: upiu reply - only 8 DW as we do not support scsi commands
7252 u8 tm_f = req_upiu->header.tm_function; in ufshcd_exec_raw_upiu_cmd()
7273 if (err == -ETIMEDOUT) in ufshcd_exec_raw_upiu_cmd()
7278 dev_err(hba->dev, "%s: failed, ocs = 0x%x\n", __func__, in ufshcd_exec_raw_upiu_cmd()
7287 err = -EINVAL; in ufshcd_exec_raw_upiu_cmd()
7296 * ufshcd_advanced_rpmb_req_handler - handle advanced RPMB request
7306 * Return: zero on success, non-zero on failure.
7313 const u32 tag = hba->reserved_slot; in ufshcd_advanced_rpmb_req_handler()
7314 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_advanced_rpmb_req_handler()
7320 int ehs = (hba->capabilities & MASK_EHSLUTRD_SUPPORTED) ? 2 : 0; in ufshcd_advanced_rpmb_req_handler()
7322 /* Protects use of hba->reserved_slot. */ in ufshcd_advanced_rpmb_req_handler()
7330 req_upiu->header.task_tag = tag; in ufshcd_advanced_rpmb_req_handler()
7333 memcpy(lrbp->ucd_req_ptr, req_upiu, sizeof(*lrbp->ucd_req_ptr)); in ufshcd_advanced_rpmb_req_handler()
7335 memcpy(lrbp->ucd_req_ptr + 1, req_ehs, sizeof(*req_ehs)); in ufshcd_advanced_rpmb_req_handler()
7340 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); in ufshcd_advanced_rpmb_req_handler()
7346 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); in ufshcd_advanced_rpmb_req_handler()
7348 result = (lrbp->ucd_rsp_ptr->header.response << 8) | in ufshcd_advanced_rpmb_req_handler()
7349 lrbp->ucd_rsp_ptr->header.status; in ufshcd_advanced_rpmb_req_handler()
7351 ehs_len = lrbp->ucd_rsp_ptr->header.ehs_length; in ufshcd_advanced_rpmb_req_handler()
7362 ehs_data = (u8 *)lrbp->ucd_rsp_ptr + EHS_OFFSET_IN_RESPONSE; in ufshcd_advanced_rpmb_req_handler()
7373 * ufshcd_eh_device_reset_handler() - Reset a single logical unit.
7389 host = cmd->device->host; in ufshcd_eh_device_reset_handler()
7392 lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun); in ufshcd_eh_device_reset_handler()
7400 if (hba->mcq_enabled) { in ufshcd_eh_device_reset_handler()
7401 for (pos = 0; pos < hba->nutrs; pos++) { in ufshcd_eh_device_reset_handler()
7402 lrbp = &hba->lrb[pos]; in ufshcd_eh_device_reset_handler()
7403 if (ufshcd_cmd_inflight(lrbp->cmd) && in ufshcd_eh_device_reset_handler()
7404 lrbp->lun == lun) { in ufshcd_eh_device_reset_handler()
7406 hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd)); in ufshcd_eh_device_reset_handler()
7415 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_eh_device_reset_handler()
7416 for_each_set_bit(pos, &hba->outstanding_reqs, hba->nutrs) in ufshcd_eh_device_reset_handler()
7417 if (hba->lrb[pos].lun == lun) in ufshcd_eh_device_reset_handler()
7419 hba->outstanding_reqs &= ~pending_reqs; in ufshcd_eh_device_reset_handler()
7420 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_eh_device_reset_handler()
7422 for_each_set_bit(pos, &pending_reqs, hba->nutrs) { in ufshcd_eh_device_reset_handler()
7424 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_eh_device_reset_handler()
7427 hba->outstanding_reqs |= not_cleared; in ufshcd_eh_device_reset_handler()
7429 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_eh_device_reset_handler()
7431 dev_err(hba->dev, "%s: failed to clear request %d\n", in ufshcd_eh_device_reset_handler()
7438 hba->req_abort_count = 0; in ufshcd_eh_device_reset_handler()
7443 dev_err(hba->dev, "%s: failed with err %d\n", __func__, err); in ufshcd_eh_device_reset_handler()
7454 for_each_set_bit(tag, &bitmap, hba->nutrs) { in ufshcd_set_req_abort_skip()
7455 lrbp = &hba->lrb[tag]; in ufshcd_set_req_abort_skip()
7456 lrbp->req_abort_skip = true; in ufshcd_set_req_abort_skip()
7461 * ufshcd_try_to_abort_task - abort a specific task
7466 * command, and in host controller by clearing the door-bell register. There can
7471 * Return: zero on success, non-zero on failure.
7475 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_try_to_abort_task()
7481 for (poll_cnt = 100; poll_cnt; poll_cnt--) { in ufshcd_try_to_abort_task()
7482 err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag, in ufshcd_try_to_abort_task()
7486 dev_err(hba->dev, "%s: cmd pending in the device. tag = %d\n", in ufshcd_try_to_abort_task()
7494 dev_err(hba->dev, "%s: cmd at tag %d not pending in the device.\n", in ufshcd_try_to_abort_task()
7496 if (hba->mcq_enabled) { in ufshcd_try_to_abort_task()
7498 if (ufshcd_cmd_inflight(lrbp->cmd)) { in ufshcd_try_to_abort_task()
7504 dev_err(hba->dev, "%s: cmd at tag=%d is cleared.\n", in ufshcd_try_to_abort_task()
7517 dev_err(hba->dev, "%s: cmd at tag %d successfully cleared from DB.\n", in ufshcd_try_to_abort_task()
7521 dev_err(hba->dev, in ufshcd_try_to_abort_task()
7531 err = -EBUSY; in ufshcd_try_to_abort_task()
7535 err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag, in ufshcd_try_to_abort_task()
7540 dev_err(hba->dev, "%s: issued. tag = %d, err %d\n", in ufshcd_try_to_abort_task()
7548 dev_err(hba->dev, "%s: Failed clearing cmd at tag %d, err %d\n", in ufshcd_try_to_abort_task()
7556 * ufshcd_abort - scsi host template eh_abort_handler callback
7563 struct Scsi_Host *host = cmd->device->host; in ufshcd_abort()
7565 int tag = scsi_cmd_to_rq(cmd)->tag; in ufshcd_abort()
7566 struct ufshcd_lrb *lrbp = &hba->lrb[tag]; in ufshcd_abort()
7574 if (!hba->mcq_enabled) { in ufshcd_abort()
7576 if (!test_bit(tag, &hba->outstanding_reqs)) { in ufshcd_abort()
7578 dev_err(hba->dev, in ufshcd_abort()
7580 __func__, tag, hba->outstanding_reqs, reg); in ufshcd_abort()
7586 dev_info(hba->dev, "%s: Device abort task at tag %d\n", __func__, tag); in ufshcd_abort()
7596 if (!hba->req_abort_count) { in ufshcd_abort()
7605 hba->req_abort_count++; in ufshcd_abort()
7607 if (!hba->mcq_enabled && !(reg & (1 << tag))) { in ufshcd_abort()
7609 dev_err(hba->dev, in ufshcd_abort()
7617 * Task abort to the device W-LUN is illegal. When this command in ufshcd_abort()
7621 * the lrb taken by this cmd and re-set it in outstanding_reqs, in ufshcd_abort()
7624 if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) { in ufshcd_abort()
7625 ufshcd_update_evt_hist(hba, UFS_EVT_ABORT, lrbp->lun); in ufshcd_abort()
7627 spin_lock_irqsave(host->host_lock, flags); in ufshcd_abort()
7628 hba->force_reset = true; in ufshcd_abort()
7630 spin_unlock_irqrestore(host->host_lock, flags); in ufshcd_abort()
7634 if (hba->mcq_enabled) { in ufshcd_abort()
7641 if (lrbp->req_abort_skip) { in ufshcd_abort()
7642 dev_err(hba->dev, "%s: skipping abort\n", __func__); in ufshcd_abort()
7643 ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); in ufshcd_abort()
7649 dev_err(hba->dev, "%s: failed with err %d\n", __func__, err); in ufshcd_abort()
7650 ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); in ufshcd_abort()
7659 spin_lock_irqsave(&hba->outstanding_lock, flags); in ufshcd_abort()
7660 outstanding = __test_and_clear_bit(tag, &hba->outstanding_reqs); in ufshcd_abort()
7661 spin_unlock_irqrestore(&hba->outstanding_lock, flags); in ufshcd_abort()
7675 * ufshcd_host_reset_and_restore - reset and restore host controller
7676 * @hba: per-adapter instance
7679 * local and remote (device) Uni-Pro stack and the attributes
7682 * Return: zero on success, non-zero on failure.
7693 hba->silence_err_logs = true; in ufshcd_host_reset_and_restore()
7695 hba->silence_err_logs = false; in ufshcd_host_reset_and_restore()
7707 dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err); in ufshcd_host_reset_and_restore()
7713 * ufshcd_reset_and_restore - reset and re-initialize host/device
7714 * @hba: per-adapter instance
7716 * Reset and recover device, host and re-establish link. This
7719 * Return: zero on success, non-zero on failure.
7729 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_reset_and_restore()
7735 saved_err |= hba->saved_err; in ufshcd_reset_and_restore()
7736 saved_uic_err |= hba->saved_uic_err; in ufshcd_reset_and_restore()
7737 hba->saved_err = 0; in ufshcd_reset_and_restore()
7738 hba->saved_uic_err = 0; in ufshcd_reset_and_restore()
7739 hba->force_reset = false; in ufshcd_reset_and_restore()
7740 hba->ufshcd_state = UFSHCD_STATE_RESET; in ufshcd_reset_and_restore()
7741 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_reset_and_restore()
7748 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_reset_and_restore()
7752 if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL && in ufshcd_reset_and_restore()
7753 hba->ufshcd_state != UFSHCD_STATE_ERROR && in ufshcd_reset_and_restore()
7754 hba->ufshcd_state != UFSHCD_STATE_EH_SCHEDULED_NON_FATAL) in ufshcd_reset_and_restore()
7755 err = -EAGAIN; in ufshcd_reset_and_restore()
7756 } while (err && --retries); in ufshcd_reset_and_restore()
7759 * Inform scsi mid-layer that we did reset and allow to handle in ufshcd_reset_and_restore()
7762 scsi_report_bus_reset(hba->host, 0); in ufshcd_reset_and_restore()
7764 hba->ufshcd_state = UFSHCD_STATE_ERROR; in ufshcd_reset_and_restore()
7765 hba->saved_err |= saved_err; in ufshcd_reset_and_restore()
7766 hba->saved_uic_err |= saved_uic_err; in ufshcd_reset_and_restore()
7768 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_reset_and_restore()
7774 * ufshcd_eh_host_reset_handler - host reset handler registered to scsi layer
7785 hba = shost_priv(cmd->device->host); in ufshcd_eh_host_reset_handler()
7789 * stuck in this function waiting for flush_work(&hba->eh_work). And in ufshcd_eh_host_reset_handler()
7793 if (hba->pm_op_in_progress) { in ufshcd_eh_host_reset_handler()
7800 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_eh_host_reset_handler()
7801 hba->force_reset = true; in ufshcd_eh_host_reset_handler()
7803 dev_err(hba->dev, "%s: reset in progress - 1\n", __func__); in ufshcd_eh_host_reset_handler()
7804 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_eh_host_reset_handler()
7806 flush_work(&hba->eh_work); in ufshcd_eh_host_reset_handler()
7808 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_eh_host_reset_handler()
7809 if (hba->ufshcd_state == UFSHCD_STATE_ERROR) in ufshcd_eh_host_reset_handler()
7811 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_eh_host_reset_handler()
7817 * ufshcd_get_max_icc_level - calculate the ICC level
7818 * @sup_curr_uA: max. current supported by the regulator
7822 * Return: calculated max ICC level for specific regulator.
7832 for (i = start_scan; i >= 0; i--) { in ufshcd_get_max_icc_level()
7863 * ufshcd_find_max_sup_active_icc_level - calculate the max ICC level
7865 * @hba: per-adapter instance
7875 if (!hba->vreg_info.vcc || !hba->vreg_info.vccq || in ufshcd_find_max_sup_active_icc_level()
7876 !hba->vreg_info.vccq2) { in ufshcd_find_max_sup_active_icc_level()
7879 * never-ending cycles of messages written back to storage by in ufshcd_find_max_sup_active_icc_level()
7883 dev_dbg(hba->dev, in ufshcd_find_max_sup_active_icc_level()
7884 "%s: Regulator capability was not set, actvIccLevel=%d", in ufshcd_find_max_sup_active_icc_level()
7889 if (hba->vreg_info.vcc->max_uA) in ufshcd_find_max_sup_active_icc_level()
7891 hba->vreg_info.vcc->max_uA, in ufshcd_find_max_sup_active_icc_level()
7892 POWER_DESC_MAX_ACTV_ICC_LVLS - 1, in ufshcd_find_max_sup_active_icc_level()
7895 if (hba->vreg_info.vccq->max_uA) in ufshcd_find_max_sup_active_icc_level()
7897 hba->vreg_info.vccq->max_uA, in ufshcd_find_max_sup_active_icc_level()
7901 if (hba->vreg_info.vccq2->max_uA) in ufshcd_find_max_sup_active_icc_level()
7903 hba->vreg_info.vccq2->max_uA, in ufshcd_find_max_sup_active_icc_level()
7923 dev_err(hba->dev, in ufshcd_set_active_icc_lvl()
7930 dev_dbg(hba->dev, "%s: setting icc_level 0x%x", __func__, icc_level); in ufshcd_set_active_icc_lvl()
7936 dev_err(hba->dev, in ufshcd_set_active_icc_lvl()
7946 struct Scsi_Host *shost = sdev->host; in ufshcd_blk_pm_runtime_init()
7949 blk_pm_runtime_init(sdev->request_queue, &sdev->sdev_gendev); in ufshcd_blk_pm_runtime_init()
7950 if (sdev->rpm_autosuspend) in ufshcd_blk_pm_runtime_init()
7951 pm_runtime_set_autosuspend_delay(&sdev->sdev_gendev, in ufshcd_blk_pm_runtime_init()
7952 shost->rpm_autosuspend_delay); in ufshcd_blk_pm_runtime_init()
7957 * ufshcd_scsi_add_wlus - Adds required W-LUs
7958 * @hba: per-adapter instance
7979 * Return: zero on success (all required W-LUs are added successfully),
7980 * non-zero error value on failure (if failed to add any of the required W-LU).
7987 hba->ufs_device_wlun = __scsi_add_device(hba->host, 0, 0, in ufshcd_scsi_add_wlus()
7989 if (IS_ERR(hba->ufs_device_wlun)) { in ufshcd_scsi_add_wlus()
7990 ret = PTR_ERR(hba->ufs_device_wlun); in ufshcd_scsi_add_wlus()
7991 hba->ufs_device_wlun = NULL; in ufshcd_scsi_add_wlus()
7994 scsi_device_put(hba->ufs_device_wlun); in ufshcd_scsi_add_wlus()
7996 sdev_rpmb = __scsi_add_device(hba->host, 0, 0, in ufshcd_scsi_add_wlus()
8005 sdev_boot = __scsi_add_device(hba->host, 0, 0, in ufshcd_scsi_add_wlus()
8008 dev_err(hba->dev, "%s: BOOT WLUN not found\n", __func__); in ufshcd_scsi_add_wlus()
8016 scsi_remove_device(hba->ufs_device_wlun); in ufshcd_scsi_add_wlus()
8023 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_wb_probe()
8032 * Probe WB only for UFS-2.2 and UFS-3.1 (and later) devices or in ufshcd_wb_probe()
8036 if (!(dev_info->wspecversion >= 0x310 || in ufshcd_wb_probe()
8037 dev_info->wspecversion == 0x220 || in ufshcd_wb_probe()
8038 (hba->dev_quirks & UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES))) in ufshcd_wb_probe()
8052 dev_info->wb_buffer_type = desc_buf[DEVICE_DESC_PARAM_WB_TYPE]; in ufshcd_wb_probe()
8054 dev_info->b_presrv_uspc_en = in ufshcd_wb_probe()
8057 if (dev_info->wb_buffer_type == WB_BUF_MODE_SHARED) { in ufshcd_wb_probe()
8070 dev_info->wb_dedicated_lu = lun; in ufshcd_wb_probe()
8085 hba->caps &= ~UFSHCD_CAP_WB_EN; in ufshcd_wb_probe()
8090 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_temp_notif_probe()
8094 if (!(hba->caps & UFSHCD_CAP_TEMP_NOTIF) || dev_info->wspecversion < 0x300) in ufshcd_temp_notif_probe()
8113 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_ext_iid_probe()
8118 /* Only UFS-4.0 and above may support EXT_IID */ in ufshcd_ext_iid_probe()
8119 if (dev_info->wspecversion < 0x400) in ufshcd_ext_iid_probe()
8130 dev_err(hba->dev, "failed reading bEXTIIDEn. err = %d\n", err); in ufshcd_ext_iid_probe()
8133 dev_info->b_ext_iid_en = ext_iid_en; in ufshcd_ext_iid_probe()
8138 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_set_rtt()
8141 int host_rtt_cap = hba->vops && hba->vops->max_num_rtt ? in ufshcd_set_rtt()
8142 hba->vops->max_num_rtt : hba->nortt; in ufshcd_set_rtt()
8144 /* RTT override makes sense only for UFS-4.0 and above */ in ufshcd_set_rtt()
8145 if (dev_info->wspecversion < 0x400) in ufshcd_set_rtt()
8150 dev_err(hba->dev, "failed reading bMaxNumOfRTT\n"); in ufshcd_set_rtt()
8158 rtt = min_t(int, dev_info->rtt_cap, host_rtt_cap); in ufshcd_set_rtt()
8165 dev_err(hba->dev, "failed writing bMaxNumOfRTT\n"); in ufshcd_set_rtt()
8172 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_fixup_dev_quirks()
8177 for (f = fixups; f->quirk; f++) { in ufshcd_fixup_dev_quirks()
8178 if ((f->wmanufacturerid == dev_info->wmanufacturerid || in ufshcd_fixup_dev_quirks()
8179 f->wmanufacturerid == UFS_ANY_VENDOR) && in ufshcd_fixup_dev_quirks()
8180 ((dev_info->model && in ufshcd_fixup_dev_quirks()
8181 STR_PRFX_EQUAL(f->model, dev_info->model)) || in ufshcd_fixup_dev_quirks()
8182 !strcmp(f->model, UFS_ANY_MODEL))) in ufshcd_fixup_dev_quirks()
8183 hba->dev_quirks |= f->quirk; in ufshcd_fixup_dev_quirks()
8205 if (ts64.tv_sec < hba->dev_info.rtc_time_baseline) { in ufshcd_update_rtc()
8206 dev_warn_once(hba->dev, "%s: Current time precedes previous setting!\n", __func__); in ufshcd_update_rtc()
8211 * The Absolute RTC mode has a 136-year limit, spanning from 2010 to 2146. If a time beyond in ufshcd_update_rtc()
8214 val = ts64.tv_sec - hba->dev_info.rtc_time_baseline; in ufshcd_update_rtc()
8225 dev_err(hba->dev, "%s: Failed to update rtc %d\n", __func__, err); in ufshcd_update_rtc()
8226 else if (hba->dev_info.rtc_type == UFS_RTC_RELATIVE) in ufshcd_update_rtc()
8227 hba->dev_info.rtc_time_baseline = ts64.tv_sec; in ufshcd_update_rtc()
8237 if (!ufshcd_is_ufs_dev_busy(hba) && hba->ufshcd_state == UFSHCD_STATE_OPERATIONAL) in ufshcd_rtc_work()
8240 if (ufshcd_is_ufs_dev_active(hba) && hba->dev_info.rtc_update_period) in ufshcd_rtc_work()
8241 schedule_delayed_work(&hba->ufs_rtc_update_work, in ufshcd_rtc_work()
8242 msecs_to_jiffies(hba->dev_info.rtc_update_period)); in ufshcd_rtc_work()
8248 struct ufs_dev_info *dev_info = &hba->dev_info; in ufs_init_rtc()
8251 dev_info->rtc_type = UFS_RTC_ABSOLUTE; in ufs_init_rtc()
8258 dev_info->rtc_time_baseline = mktime64(2010, 1, 1, 0, 0, 0) - in ufs_init_rtc()
8261 dev_info->rtc_type = UFS_RTC_RELATIVE; in ufs_init_rtc()
8262 dev_info->rtc_time_baseline = 0; in ufs_init_rtc()
8270 dev_info->rtc_update_period = 0; in ufs_init_rtc()
8278 struct ufs_dev_info *dev_info = &hba->dev_info; in ufs_get_device_desc()
8282 err = -ENOMEM; in ufs_get_device_desc()
8289 dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", in ufs_get_device_desc()
8298 dev_info->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 | in ufs_get_device_desc()
8302 dev_info->wspecversion = desc_buf[DEVICE_DESC_PARAM_SPEC_VER] << 8 | in ufs_get_device_desc()
8304 dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH]; in ufs_get_device_desc()
8306 dev_info->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP]; in ufs_get_device_desc()
8311 &dev_info->model, SD_ASCII_STD); in ufs_get_device_desc()
8313 dev_err(hba->dev, "%s: Failed reading Product Name. err = %d\n", in ufs_get_device_desc()
8318 hba->luns_avail = desc_buf[DEVICE_DESC_PARAM_NUM_LU] + in ufs_get_device_desc()
8329 if (hba->ext_iid_sup) in ufs_get_device_desc()
8345 struct ufs_dev_info *dev_info = &hba->dev_info; in ufs_put_device_desc()
8347 kfree(dev_info->model); in ufs_put_device_desc()
8348 dev_info->model = NULL; in ufs_put_device_desc()
8352 * ufshcd_quirk_tune_host_pa_tactivate - Ensures that host PA_TACTIVATE is
8354 * @hba: per-adapter instance
8360 * Return: zero on success, non-zero error value on failure.
8382 dev_err(hba->dev, "%s: invalid host PA_GRANULARITY %d", in ufshcd_quirk_tune_host_pa_tactivate()
8384 return -EINVAL; in ufshcd_quirk_tune_host_pa_tactivate()
8389 dev_err(hba->dev, "%s: invalid device PA_GRANULARITY %d", in ufshcd_quirk_tune_host_pa_tactivate()
8391 return -EINVAL; in ufshcd_quirk_tune_host_pa_tactivate()
8403 pa_tactivate_us = pa_tactivate * gran_to_us_table[granularity - 1]; in ufshcd_quirk_tune_host_pa_tactivate()
8405 gran_to_us_table[peer_granularity - 1]; in ufshcd_quirk_tune_host_pa_tactivate()
8411 gran_to_us_table[peer_granularity - 1]; in ufshcd_quirk_tune_host_pa_tactivate()
8425 if (hba->dev_quirks & UFS_DEVICE_QUIRK_PA_TACTIVATE) in ufshcd_tune_unipro_params()
8429 if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE) in ufshcd_tune_unipro_params()
8435 hba->ufs_stats.hibern8_exit_cnt = 0; in ufshcd_clear_dbg_ufs_stats()
8436 hba->ufs_stats.last_hibern8_exit_tstamp = ktime_set(0, 0); in ufshcd_clear_dbg_ufs_stats()
8437 hba->req_abort_count = 0; in ufshcd_clear_dbg_ufs_stats()
8447 err = -ENOMEM; in ufshcd_device_geo_params_init()
8454 dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", in ufshcd_device_geo_params_init()
8460 hba->dev_info.max_lu_supported = 32; in ufshcd_device_geo_params_init()
8462 hba->dev_info.max_lu_supported = 8; in ufshcd_device_geo_params_init()
8500 hba->dev_ref_clk_freq = in ufshcd_parse_dev_ref_clk_freq()
8503 if (hba->dev_ref_clk_freq == REF_CLK_FREQ_INVAL) in ufshcd_parse_dev_ref_clk_freq()
8504 dev_err(hba->dev, in ufshcd_parse_dev_ref_clk_freq()
8512 u32 freq = hba->dev_ref_clk_freq; in ufshcd_set_dev_ref_clk()
8518 dev_err(hba->dev, "failed reading bRefClkFreq. err = %d\n", in ufshcd_set_dev_ref_clk()
8530 dev_err(hba->dev, "bRefClkFreq setting to %lu Hz failed\n", in ufshcd_set_dev_ref_clk()
8535 dev_dbg(hba->dev, "bRefClkFreq setting to %lu Hz succeeded\n", in ufshcd_set_dev_ref_clk()
8555 dev_err(hba->dev, "%s: Failed getting device info. err = %d\n", in ufshcd_device_params_init()
8566 hba->dev_info.f_power_on_wp_en = flag; in ufshcd_device_params_init()
8568 /* Probe maximum power mode co-supported by both UFS host and device */ in ufshcd_device_params_init()
8570 dev_err(hba->dev, in ufshcd_device_params_init()
8582 struct ufs_dev_info *dev_info = &hba->dev_info; in ufshcd_set_timestamp_attr()
8585 if (dev_info->wspecversion < 0x400) in ufshcd_set_timestamp_attr()
8594 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST; in ufshcd_set_timestamp_attr()
8596 upiu_data = (struct utp_upiu_query_v4_0 *)&request->upiu_req; in ufshcd_set_timestamp_attr()
8598 put_unaligned_be64(ktime_get_real_ns(), &upiu_data->osf3); in ufshcd_set_timestamp_attr()
8603 dev_err(hba->dev, "%s: failed to set timestamp %d\n", in ufshcd_set_timestamp_attr()
8610 * ufshcd_add_lus - probe and add UFS logical units
8611 * @hba: per-adapter instance
8626 memcpy(&hba->clk_scaling.saved_pwr_info, in ufshcd_add_lus()
8627 &hba->pwr_info, in ufshcd_add_lus()
8629 hba->clk_scaling.is_allowed = true; in ufshcd_add_lus()
8635 hba->clk_scaling.is_enabled = true; in ufshcd_add_lus()
8640 * The RTC update code accesses the hba->ufs_device_wlun->sdev_gendev in ufshcd_add_lus()
8644 schedule_delayed_work(&hba->ufs_rtc_update_work, in ufshcd_add_lus()
8648 scsi_scan_host(hba->host); in ufshcd_add_lus()
8654 /* SDB - Single Doorbell */
8660 dmam_free_coherent(hba->dev, ucdl_size, hba->ucdl_base_addr, in ufshcd_release_sdb_queue()
8661 hba->ucdl_dma_addr); in ufshcd_release_sdb_queue()
8664 dmam_free_coherent(hba->dev, utrdl_size, hba->utrdl_base_addr, in ufshcd_release_sdb_queue()
8665 hba->utrdl_dma_addr); in ufshcd_release_sdb_queue()
8667 devm_kfree(hba->dev, hba->lrb); in ufshcd_release_sdb_queue()
8673 int old_nutrs = hba->nutrs; in ufshcd_alloc_mcq()
8679 hba->nutrs = ret; in ufshcd_alloc_mcq()
8688 if (hba->nutrs != old_nutrs) { in ufshcd_alloc_mcq()
8700 hba->host->can_queue = hba->nutrs - UFSHCD_NUM_RESERVED; in ufshcd_alloc_mcq()
8701 hba->reserved_slot = hba->nutrs - UFSHCD_NUM_RESERVED; in ufshcd_alloc_mcq()
8705 hba->nutrs = old_nutrs; in ufshcd_alloc_mcq()
8715 dev_info(hba->dev, "ESI %sconfigured\n", ret ? "is not " : ""); in ufshcd_config_mcq()
8718 if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_INTR) in ufshcd_config_mcq()
8722 ufshcd_mcq_config_mac(hba, hba->nutrs); in ufshcd_config_mcq()
8724 …dev_info(hba->dev, "MCQ configured, nr_queues=%d, io_queues=%d, read_queue=%d, poll_queues=%d, que… in ufshcd_config_mcq()
8725 hba->nr_hw_queues, hba->nr_queues[HCTX_TYPE_DEFAULT], in ufshcd_config_mcq()
8726 hba->nr_queues[HCTX_TYPE_READ], hba->nr_queues[HCTX_TYPE_POLL], in ufshcd_config_mcq()
8727 hba->nutrs); in ufshcd_config_mcq()
8733 struct Scsi_Host *host = hba->host; in ufshcd_device_init()
8735 hba->ufshcd_state = UFSHCD_STATE_RESET; in ufshcd_device_init()
8741 if (hba->quirks & UFSHCD_QUIRK_SKIP_PH_CONFIGURATION) in ufshcd_device_init()
8751 if (hba->mcq_enabled && !init_dev_params) { in ufshcd_device_init()
8774 if (is_mcq_supported(hba) && !hba->scsi_host_added) { in ufshcd_device_init()
8783 dev_err(hba->dev, "MCQ mode is disabled, err=%d\n", in ufshcd_device_init()
8786 ret = scsi_add_host(host, hba->dev); in ufshcd_device_init()
8788 dev_err(hba->dev, "scsi_add_host failed\n"); in ufshcd_device_init()
8791 hba->scsi_host_added = true; in ufshcd_device_init()
8808 if (hba->max_pwr_info.is_valid) { in ufshcd_device_init()
8813 if (hba->dev_ref_clk_freq != REF_CLK_FREQ_INVAL) in ufshcd_device_init()
8815 ret = ufshcd_config_pwr_mode(hba, &hba->max_pwr_info.info); in ufshcd_device_init()
8817 dev_err(hba->dev, "%s: Failed setting power mode, err = %d\n", in ufshcd_device_init()
8827 * ufshcd_probe_hba - probe hba to detect device and initialize it
8828 * @hba: per-adapter instance
8831 * Execute link-startup and verify device initialization
8845 if (!hba->pm_op_in_progress && in ufshcd_probe_hba()
8846 (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) { in ufshcd_probe_hba()
8854 dev_err(hba->dev, "Host controller enable failed\n"); in ufshcd_probe_hba()
8876 /* Enable UFS Write Booster if supported */ in ufshcd_probe_hba()
8879 if (hba->ee_usr_mask) in ufshcd_probe_hba()
8884 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_probe_hba()
8886 hba->ufshcd_state = UFSHCD_STATE_ERROR; in ufshcd_probe_hba()
8887 else if (hba->ufshcd_state == UFSHCD_STATE_RESET) in ufshcd_probe_hba()
8888 hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; in ufshcd_probe_hba()
8889 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_probe_hba()
8891 trace_ufshcd_init(dev_name(hba->dev), ret, in ufshcd_probe_hba()
8893 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_probe_hba()
8898 * ufshcd_async_scan - asynchronous execution for probing hba
8907 down(&hba->host_sem); in ufshcd_async_scan()
8910 up(&hba->host_sem); in ufshcd_async_scan()
8918 pm_runtime_put_sync(hba->dev); in ufshcd_async_scan()
8921 dev_err(hba->dev, "%s failed: %d\n", __func__, ret); in ufshcd_async_scan()
8926 struct ufs_hba *hba = shost_priv(scmd->device->host); in ufshcd_eh_timed_out()
8928 if (!hba->system_suspending) { in ufshcd_eh_timed_out()
8940 dev_info(hba->dev, "%s() finished; outstanding_tasks = %#lx.\n", in ufshcd_eh_timed_out()
8941 __func__, hba->outstanding_tasks); in ufshcd_eh_timed_out()
8943 return hba->outstanding_reqs ? SCSI_EH_RESET_TIMER : SCSI_EH_DONE; in ufshcd_eh_timed_out()
8977 .this_id = -1,
8998 * zero max_uA may cause unexpected behavior when regulator is in ufshcd_config_vreg_load()
9001 if (!vreg->max_uA) in ufshcd_config_vreg_load()
9004 ret = regulator_set_load(vreg->reg, ua); in ufshcd_config_vreg_load()
9007 __func__, vreg->name, ua, ret); in ufshcd_config_vreg_load()
9016 return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA); in ufshcd_config_vreg_lpm()
9025 return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA); in ufshcd_config_vreg_hpm()
9031 if (regulator_count_voltages(vreg->reg) <= 0) in ufshcd_config_vreg()
9034 return ufshcd_config_vreg_load(dev, vreg, on ? vreg->max_uA : 0); in ufshcd_config_vreg()
9041 if (!vreg || vreg->enabled) in ufshcd_enable_vreg()
9046 ret = regulator_enable(vreg->reg); in ufshcd_enable_vreg()
9049 vreg->enabled = true; in ufshcd_enable_vreg()
9052 __func__, vreg->name, ret); in ufshcd_enable_vreg()
9061 if (!vreg || !vreg->enabled || vreg->always_on) in ufshcd_disable_vreg()
9064 ret = regulator_disable(vreg->reg); in ufshcd_disable_vreg()
9069 vreg->enabled = false; in ufshcd_disable_vreg()
9072 __func__, vreg->name, ret); in ufshcd_disable_vreg()
9081 struct device *dev = hba->dev; in ufshcd_setup_vreg()
9082 struct ufs_vreg_info *info = &hba->vreg_info; in ufshcd_setup_vreg()
9084 ret = ufshcd_toggle_vreg(dev, info->vcc, on); in ufshcd_setup_vreg()
9088 ret = ufshcd_toggle_vreg(dev, info->vccq, on); in ufshcd_setup_vreg()
9092 ret = ufshcd_toggle_vreg(dev, info->vccq2, on); in ufshcd_setup_vreg()
9096 ufshcd_toggle_vreg(dev, info->vccq2, false); in ufshcd_setup_vreg()
9097 ufshcd_toggle_vreg(dev, info->vccq, false); in ufshcd_setup_vreg()
9098 ufshcd_toggle_vreg(dev, info->vcc, false); in ufshcd_setup_vreg()
9105 struct ufs_vreg_info *info = &hba->vreg_info; in ufshcd_setup_hba_vreg()
9107 return ufshcd_toggle_vreg(hba->dev, info->vdd_hba, on); in ufshcd_setup_hba_vreg()
9117 vreg->reg = devm_regulator_get(dev, vreg->name); in ufshcd_get_vreg()
9118 if (IS_ERR(vreg->reg)) { in ufshcd_get_vreg()
9119 ret = PTR_ERR(vreg->reg); in ufshcd_get_vreg()
9121 __func__, vreg->name, ret); in ufshcd_get_vreg()
9131 struct device *dev = hba->dev; in ufshcd_init_vreg()
9132 struct ufs_vreg_info *info = &hba->vreg_info; in ufshcd_init_vreg()
9134 ret = ufshcd_get_vreg(dev, info->vcc); in ufshcd_init_vreg()
9138 ret = ufshcd_get_vreg(dev, info->vccq); in ufshcd_init_vreg()
9140 ret = ufshcd_get_vreg(dev, info->vccq2); in ufshcd_init_vreg()
9147 struct ufs_vreg_info *info = &hba->vreg_info; in ufshcd_init_hba_vreg()
9149 return ufshcd_get_vreg(hba->dev, info->vdd_hba); in ufshcd_init_hba_vreg()
9156 struct list_head *head = &hba->clk_list_head; in ufshcd_setup_clocks()
9169 if (!IS_ERR_OR_NULL(clki->clk)) { in ufshcd_setup_clocks()
9175 clki->keep_link_active) in ufshcd_setup_clocks()
9178 clk_state_changed = on ^ clki->enabled; in ufshcd_setup_clocks()
9179 if (on && !clki->enabled) { in ufshcd_setup_clocks()
9180 ret = clk_prepare_enable(clki->clk); in ufshcd_setup_clocks()
9182 dev_err(hba->dev, "%s: %s prepare enable failed, %d\n", in ufshcd_setup_clocks()
9183 __func__, clki->name, ret); in ufshcd_setup_clocks()
9186 } else if (!on && clki->enabled) { in ufshcd_setup_clocks()
9187 clk_disable_unprepare(clki->clk); in ufshcd_setup_clocks()
9189 clki->enabled = on; in ufshcd_setup_clocks()
9190 dev_dbg(hba->dev, "%s: clk: %s %sabled\n", __func__, in ufshcd_setup_clocks()
9191 clki->name, on ? "en" : "dis"); in ufshcd_setup_clocks()
9204 if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled) in ufshcd_setup_clocks()
9205 clk_disable_unprepare(clki->clk); in ufshcd_setup_clocks()
9208 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_setup_clocks()
9209 hba->clk_gating.state = CLKS_ON; in ufshcd_setup_clocks()
9210 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_setup_clocks()
9211 hba->clk_gating.state); in ufshcd_setup_clocks()
9212 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_setup_clocks()
9216 trace_ufshcd_profile_clk_gating(dev_name(hba->dev), in ufshcd_setup_clocks()
9225 int ret = device_property_read_u32(hba->dev, "ref-clk-freq", &freq); in ufshcd_parse_ref_clk_property()
9228 dev_dbg(hba->dev, "Cannot query 'ref-clk-freq' property = %d", ret); in ufshcd_parse_ref_clk_property()
9239 struct device *dev = hba->dev; in ufshcd_init_clocks()
9240 struct list_head *head = &hba->clk_list_head; in ufshcd_init_clocks()
9246 if (!clki->name) in ufshcd_init_clocks()
9249 clki->clk = devm_clk_get(dev, clki->name); in ufshcd_init_clocks()
9250 if (IS_ERR(clki->clk)) { in ufshcd_init_clocks()
9251 ret = PTR_ERR(clki->clk); in ufshcd_init_clocks()
9253 __func__, clki->name, ret); in ufshcd_init_clocks()
9262 if (!strcmp(clki->name, "ref_clk")) in ufshcd_init_clocks()
9263 ufshcd_parse_dev_ref_clk_freq(hba, clki->clk); in ufshcd_init_clocks()
9265 if (clki->max_freq) { in ufshcd_init_clocks()
9266 ret = clk_set_rate(clki->clk, clki->max_freq); in ufshcd_init_clocks()
9268 dev_err(hba->dev, "%s: %s clk set rate(%dHz) failed, %d\n", in ufshcd_init_clocks()
9269 __func__, clki->name, in ufshcd_init_clocks()
9270 clki->max_freq, ret); in ufshcd_init_clocks()
9273 clki->curr_freq = clki->max_freq; in ufshcd_init_clocks()
9276 clki->name, clk_get_rate(clki->clk)); in ufshcd_init_clocks()
9280 if (hba->use_pm_opp) { in ufshcd_init_clocks()
9283 dev_err(hba->dev, "%s: failed to set OPP: %d", __func__, in ufshcd_init_clocks()
9297 if (!hba->vops) in ufshcd_variant_hba_init()
9302 dev_err_probe(hba->dev, err, in ufshcd_variant_hba_init()
9311 if (!hba->vops) in ufshcd_variant_hba_exit()
9340 if (hba->dev_ref_clk_freq == REF_CLK_FREQ_INVAL) in ufshcd_hba_init()
9341 hba->dev_ref_clk_freq = ufshcd_parse_ref_clk_property(hba); in ufshcd_hba_init()
9362 hba->is_powered = true; in ufshcd_hba_init()
9377 if (hba->is_powered) { in ufshcd_hba_exit()
9381 if (hba->eh_wq) in ufshcd_hba_exit()
9382 destroy_workqueue(hba->eh_wq); in ufshcd_hba_exit()
9388 hba->is_powered = false; in ufshcd_hba_exit()
9420 * ufshcd_set_dev_pwr_mode - sends START STOP UNIT command to set device
9436 spin_lock_irqsave(hba->host->host_lock, flags); in ufshcd_set_dev_pwr_mode()
9437 sdp = hba->ufs_device_wlun; in ufshcd_set_dev_pwr_mode()
9441 ret = -ENODEV; in ufshcd_set_dev_pwr_mode()
9442 spin_unlock_irqrestore(hba->host->host_lock, flags); in ufshcd_set_dev_pwr_mode()
9448 * If scsi commands fail, the scsi mid-layer schedules scsi error- in ufshcd_set_dev_pwr_mode()
9453 hba->host->eh_noresume = 1; in ufshcd_set_dev_pwr_mode()
9468 ret = -EIO; in ufshcd_set_dev_pwr_mode()
9471 hba->curr_dev_pwr_mode = pwr_mode; in ufshcd_set_dev_pwr_mode()
9475 hba->host->eh_noresume = 0; in ufshcd_set_dev_pwr_mode()
9485 if (req_link_state == hba->uic_link_state) in ufshcd_link_state_transition()
9493 dev_err(hba->dev, "%s: hibern8 enter failed %d\n", in ufshcd_link_state_transition()
9504 (!check_for_bkops || !hba->auto_bkops_enabled)) { in ufshcd_link_state_transition()
9517 dev_err(hba->dev, "%s: hibern8 enter failed %d\n", in ufshcd_link_state_transition()
9548 hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM) in ufshcd_vreg_set_lpm()
9563 * If Write Booster is enabled and the device needs to flush the WB in ufshcd_vreg_set_lpm()
9567 !hba->dev_info.is_lu_power_on_wp) { in ufshcd_vreg_set_lpm()
9571 ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false); in ufshcd_vreg_set_lpm()
9574 ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq); in ufshcd_vreg_set_lpm()
9575 ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq2); in ufshcd_vreg_set_lpm()
9580 * Some UFS devices require delay after VCC power rail is turned-off. in ufshcd_vreg_set_lpm()
9582 if (vcc_off && hba->vreg_info.vcc && in ufshcd_vreg_set_lpm()
9583 hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM) in ufshcd_vreg_set_lpm()
9593 !hba->dev_info.is_lu_power_on_wp) { in ufshcd_vreg_set_hpm()
9597 ret = ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq); in ufshcd_vreg_set_hpm()
9600 ret = ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq2); in ufshcd_vreg_set_hpm()
9604 ret = ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, true); in ufshcd_vreg_set_hpm()
9609 ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq); in ufshcd_vreg_set_hpm()
9611 ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false); in ufshcd_vreg_set_hpm()
9637 hba->pm_op_in_progress = true; in __ufshcd_wl_suspend()
9640 hba->rpm_lvl : hba->spm_lvl; in __ufshcd_wl_suspend()
9653 hba->clk_gating.is_suspended = true; in __ufshcd_wl_suspend()
9663 if ((req_dev_pwr_mode == hba->curr_dev_pwr_mode) && in __ufshcd_wl_suspend()
9664 (req_link_state == hba->uic_link_state)) in __ufshcd_wl_suspend()
9672 ret = -EBUSY; in __ufshcd_wl_suspend()
9691 ret = -EBUSY; in __ufshcd_wl_suspend()
9703 hba->dev_info.b_rpm_dev_flush_capable = in __ufshcd_wl_suspend()
9704 hba->auto_bkops_enabled || in __ufshcd_wl_suspend()
9711 flush_work(&hba->eeh_work); in __ufshcd_wl_suspend()
9717 if (req_dev_pwr_mode != hba->curr_dev_pwr_mode) { in __ufshcd_wl_suspend()
9722 if (!hba->dev_info.b_rpm_dev_flush_capable) { in __ufshcd_wl_suspend()
9731 ret = -EBUSY; in __ufshcd_wl_suspend()
9751 ret = -EBUSY; in __ufshcd_wl_suspend()
9766 cancel_delayed_work_sync(&hba->ufs_rtc_update_work); in __ufshcd_wl_suspend()
9795 hba->dev_info.b_rpm_dev_flush_capable = false; in __ufshcd_wl_suspend()
9797 if (hba->dev_info.b_rpm_dev_flush_capable) { in __ufshcd_wl_suspend()
9798 schedule_delayed_work(&hba->rpm_dev_flush_recheck_work, in __ufshcd_wl_suspend()
9804 hba->clk_gating.is_suspended = false; in __ufshcd_wl_suspend()
9807 hba->pm_op_in_progress = false; in __ufshcd_wl_suspend()
9815 enum uic_link_state old_link_state = hba->uic_link_state; in __ufshcd_wl_resume()
9817 hba->pm_op_in_progress = true; in __ufshcd_wl_resume()
9836 dev_err(hba->dev, "%s: hibern8 exit failed %d\n", in __ufshcd_wl_resume()
9861 schedule_delayed_work(&hba->ufs_rtc_update_work, in __ufshcd_wl_resume()
9870 * keep auto-bkops enabled or else disable it. in __ufshcd_wl_resume()
9874 if (hba->ee_usr_mask) in __ufshcd_wl_resume()
9880 if (hba->dev_info.b_rpm_dev_flush_capable) { in __ufshcd_wl_resume()
9881 hba->dev_info.b_rpm_dev_flush_capable = false; in __ufshcd_wl_resume()
9882 cancel_delayed_work(&hba->rpm_dev_flush_recheck_work); in __ufshcd_wl_resume()
9897 hba->clk_gating.is_suspended = false; in __ufshcd_wl_resume()
9899 hba->pm_op_in_progress = false; in __ufshcd_wl_resume()
9910 hba = shost_priv(sdev->host); in ufshcd_wl_runtime_suspend()
9914 dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__, ret); in ufshcd_wl_runtime_suspend()
9918 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_wl_runtime_suspend()
9930 hba = shost_priv(sdev->host); in ufshcd_wl_runtime_resume()
9934 dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__, ret); in ufshcd_wl_runtime_resume()
9938 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_wl_runtime_resume()
9952 hba = shost_priv(sdev->host); in ufshcd_wl_suspend()
9953 down(&hba->host_sem); in ufshcd_wl_suspend()
9954 hba->system_suspending = true; in ufshcd_wl_suspend()
9961 dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__, ret); in ufshcd_wl_suspend()
9962 up(&hba->host_sem); in ufshcd_wl_suspend()
9967 hba->is_sys_suspended = true; in ufshcd_wl_suspend()
9970 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_wl_suspend()
9982 hba = shost_priv(sdev->host); in ufshcd_wl_resume()
9989 dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__, ret); in ufshcd_wl_resume()
9993 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_wl_resume()
9995 hba->is_sys_suspended = false; in ufshcd_wl_resume()
9996 hba->system_suspending = false; in ufshcd_wl_resume()
9997 up(&hba->host_sem); in ufshcd_wl_resume()
10003 * ufshcd_suspend - helper function for suspend operations
10007 * and set vreg and hba-vreg in lpm mode.
10015 if (!hba->is_powered) in ufshcd_suspend()
10028 hba->clk_gating.state = CLKS_OFF; in ufshcd_suspend()
10029 trace_ufshcd_clk_gating(dev_name(hba->dev), in ufshcd_suspend()
10030 hba->clk_gating.state); in ufshcd_suspend()
10042 * ufshcd_resume - helper function for resume operations
10048 * Return: 0 for success and non-zero for failure.
10054 if (!hba->is_powered) in ufshcd_resume()
10083 * ufshcd_system_suspend - system suspend callback
10089 * Return: 0 for success and non-zero for failure.
10097 if (pm_runtime_suspended(hba->dev)) in ufshcd_system_suspend()
10102 trace_ufshcd_system_suspend(dev_name(hba->dev), ret, in ufshcd_system_suspend()
10104 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_system_suspend()
10110 * ufshcd_system_resume - system resume callback
10116 * Return: 0 for success and non-zero for failure.
10124 if (pm_runtime_suspended(hba->dev)) in ufshcd_system_resume()
10130 trace_ufshcd_system_resume(dev_name(hba->dev), ret, in ufshcd_system_resume()
10132 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_system_resume()
10141 * ufshcd_runtime_suspend - runtime suspend callback
10146 * Return: 0 for success and non-zero for failure.
10156 trace_ufshcd_runtime_suspend(dev_name(hba->dev), ret, in ufshcd_runtime_suspend()
10158 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_runtime_suspend()
10164 * ufshcd_runtime_resume - runtime resume routine
10183 trace_ufshcd_runtime_resume(dev_name(hba->dev), ret, in ufshcd_runtime_resume()
10185 hba->curr_dev_pwr_mode, hba->uic_link_state); in ufshcd_runtime_resume()
10194 struct ufs_hba *hba = shost_priv(sdev->host); in ufshcd_wl_shutdown()
10196 down(&hba->host_sem); in ufshcd_wl_shutdown()
10197 hba->shutting_down = true; in ufshcd_wl_shutdown()
10198 up(&hba->host_sem); in ufshcd_wl_shutdown()
10203 shost_for_each_device(sdev, hba->host) { in ufshcd_wl_shutdown()
10204 if (sdev == hba->ufs_device_wlun) in ufshcd_wl_shutdown()
10206 mutex_lock(&sdev->state_mutex); in ufshcd_wl_shutdown()
10208 mutex_unlock(&sdev->state_mutex); in ufshcd_wl_shutdown()
10219 hba->is_powered = false; in ufshcd_wl_shutdown()
10223 * ufshcd_remove - de-allocate SCSI host and host memory space
10229 if (hba->ufs_device_wlun) in ufshcd_remove()
10233 ufs_sysfs_remove_nodes(hba->dev); in ufshcd_remove()
10234 blk_mq_destroy_queue(hba->tmf_queue); in ufshcd_remove()
10235 blk_put_queue(hba->tmf_queue); in ufshcd_remove()
10236 blk_mq_free_tag_set(&hba->tmf_tag_set); in ufshcd_remove()
10237 if (hba->scsi_host_added) in ufshcd_remove()
10238 scsi_remove_host(hba->host); in ufshcd_remove()
10240 ufshcd_disable_intr(hba, hba->intr_mask); in ufshcd_remove()
10266 ufshcd_writel(hba, lower_32_bits(hba->utrdl_dma_addr), in ufshcd_system_restore()
10268 ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr), in ufshcd_system_restore()
10270 ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr), in ufshcd_system_restore()
10272 ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr), in ufshcd_system_restore()
10294 * ufshcd_dealloc_host - deallocate Host Bus Adapter (HBA)
10299 scsi_host_put(hba->host); in ufshcd_dealloc_host()
10304 * ufshcd_set_dma_mask - Set dma mask based on the controller
10308 * Return: 0 for success, non-zero for failure.
10312 if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) { in ufshcd_set_dma_mask()
10313 if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64))) in ufshcd_set_dma_mask()
10316 return dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(32)); in ufshcd_set_dma_mask()
10320 * ufshcd_alloc_host - allocate Host Bus Adapter (HBA)
10324 * Return: 0 on success, non-zero value on failure.
10335 err = -ENODEV; in ufshcd_alloc_host()
10343 err = -ENOMEM; in ufshcd_alloc_host()
10346 host->nr_maps = HCTX_TYPE_POLL + 1; in ufshcd_alloc_host()
10348 hba->host = host; in ufshcd_alloc_host()
10349 hba->dev = dev; in ufshcd_alloc_host()
10350 hba->dev_ref_clk_freq = REF_CLK_FREQ_INVAL; in ufshcd_alloc_host()
10351 hba->nop_out_timeout = NOP_OUT_TIMEOUT; in ufshcd_alloc_host()
10353 INIT_LIST_HEAD(&hba->clk_list_head); in ufshcd_alloc_host()
10354 spin_lock_init(&hba->outstanding_lock); in ufshcd_alloc_host()
10376 * ufshcd_init - Driver initialization routine
10377 * @hba: per-adapter instance
10381 * Return: 0 on success, non-zero value on failure.
10386 struct Scsi_Host *host = hba->host; in ufshcd_init()
10387 struct device *dev = hba->dev; in ufshcd_init()
10397 dev_err(hba->dev, in ufshcd_init()
10399 err = -ENODEV; in ufshcd_init()
10403 hba->mmio_base = mmio_base; in ufshcd_init()
10404 hba->irq = irq; in ufshcd_init()
10405 hba->vps = &ufs_hba_vps; in ufshcd_init()
10417 hba->ufs_version = ufshcd_get_ufs_version(hba); in ufshcd_init()
10420 hba->intr_mask = ufshcd_get_intr_mask(hba); in ufshcd_init()
10424 dev_err(hba->dev, "set dma mask failed\n"); in ufshcd_init()
10431 dev_err(hba->dev, "Memory allocation failed\n"); in ufshcd_init()
10438 host->can_queue = hba->nutrs - UFSHCD_NUM_RESERVED; in ufshcd_init()
10439 host->cmd_per_lun = hba->nutrs - UFSHCD_NUM_RESERVED; in ufshcd_init()
10440 host->max_id = UFSHCD_MAX_ID; in ufshcd_init()
10441 host->max_lun = UFS_MAX_LUNS; in ufshcd_init()
10442 host->max_channel = UFSHCD_MAX_CHANNEL; in ufshcd_init()
10443 host->unique_id = host->host_no; in ufshcd_init()
10444 host->max_cmd_len = UFS_CDB_SIZE; in ufshcd_init()
10445 host->queuecommand_may_block = !!(hba->caps & UFSHCD_CAP_CLK_GATING); in ufshcd_init()
10448 if (host->rpm_autosuspend_delay == 0) in ufshcd_init()
10449 host->rpm_autosuspend_delay = RPM_AUTOSUSPEND_DELAY_MS; in ufshcd_init()
10451 hba->max_pwr_info.is_valid = false; in ufshcd_init()
10454 hba->eh_wq = alloc_ordered_workqueue("ufs_eh_wq_%d", WQ_MEM_RECLAIM, in ufshcd_init()
10455 hba->host->host_no); in ufshcd_init()
10456 if (!hba->eh_wq) { in ufshcd_init()
10457 dev_err(hba->dev, "%s: failed to create eh workqueue\n", in ufshcd_init()
10459 err = -ENOMEM; in ufshcd_init()
10462 INIT_WORK(&hba->eh_work, ufshcd_err_handler); in ufshcd_init()
10463 INIT_WORK(&hba->eeh_work, ufshcd_exception_event_handler); in ufshcd_init()
10465 sema_init(&hba->host_sem, 1); in ufshcd_init()
10468 mutex_init(&hba->uic_cmd_mutex); in ufshcd_init()
10471 mutex_init(&hba->dev_cmd.lock); in ufshcd_init()
10474 mutex_init(&hba->ee_ctrl_mutex); in ufshcd_init()
10476 mutex_init(&hba->wb_mutex); in ufshcd_init()
10477 init_rwsem(&hba->clk_scaling_lock); in ufshcd_init()
10500 dev_err(hba->dev, "request irq failed\n"); in ufshcd_init()
10503 hba->is_irq_enabled = true; in ufshcd_init()
10507 if (!hba->lsdb_sup) { in ufshcd_init()
10508 dev_err(hba->dev, "%s: failed to initialize (legacy doorbell mode not supported)\n", in ufshcd_init()
10510 err = -EINVAL; in ufshcd_init()
10513 err = scsi_add_host(host, hba->dev); in ufshcd_init()
10515 dev_err(hba->dev, "scsi_add_host failed\n"); in ufshcd_init()
10518 hba->scsi_host_added = true; in ufshcd_init()
10521 hba->tmf_tag_set = (struct blk_mq_tag_set) { in ufshcd_init()
10523 .queue_depth = hba->nutmrs, in ufshcd_init()
10527 err = blk_mq_alloc_tag_set(&hba->tmf_tag_set); in ufshcd_init()
10530 hba->tmf_queue = blk_mq_alloc_queue(&hba->tmf_tag_set, NULL, NULL); in ufshcd_init()
10531 if (IS_ERR(hba->tmf_queue)) { in ufshcd_init()
10532 err = PTR_ERR(hba->tmf_queue); in ufshcd_init()
10535 hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs, in ufshcd_init()
10536 sizeof(*hba->tmf_rqs), GFP_KERNEL); in ufshcd_init()
10537 if (!hba->tmf_rqs) { in ufshcd_init()
10538 err = -ENOMEM; in ufshcd_init()
10550 dev_err(hba->dev, "Host controller enable failed\n"); in ufshcd_init()
10561 hba->rpm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state( in ufshcd_init()
10564 hba->spm_lvl = ufs_get_desired_pm_lvl_for_dev_link_state( in ufshcd_init()
10568 INIT_DELAYED_WORK(&hba->rpm_dev_flush_recheck_work, ufshcd_rpm_dev_flush_recheck_work); in ufshcd_init()
10569 INIT_DELAYED_WORK(&hba->ufs_rtc_update_work, ufshcd_rtc_work); in ufshcd_init()
10571 /* Set the default auto-hiberate idle timer value to 150 ms */ in ufshcd_init()
10572 if (ufshcd_is_auto_hibern8_supported(hba) && !hba->ahit) { in ufshcd_init()
10573 hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 150) | in ufshcd_init()
10579 atomic_set(&hba->scsi_block_reqs_cnt, 0); in ufshcd_init()
10581 * We are assuming that device wasn't put in sleep/power-down in ufshcd_init()
10589 ufs_sysfs_add_nodes(hba->dev); in ufshcd_init()
10596 blk_mq_destroy_queue(hba->tmf_queue); in ufshcd_init()
10597 blk_put_queue(hba->tmf_queue); in ufshcd_init()
10599 blk_mq_free_tag_set(&hba->tmf_tag_set); in ufshcd_init()
10601 if (hba->scsi_host_added) in ufshcd_init()
10602 scsi_remove_host(hba->host); in ufshcd_init()
10604 hba->is_irq_enabled = false; in ufshcd_init()
10615 if (hba->complete_put) { in ufshcd_resume_complete()
10617 hba->complete_put = false; in ufshcd_resume_complete()
10624 struct device *dev = &hba->ufs_device_wlun->sdev_gendev; in ufshcd_rpm_ok_for_spm()
10630 spin_lock_irqsave(&dev->power.lock, flags); in ufshcd_rpm_ok_for_spm()
10631 dev_pwr_mode = ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl); in ufshcd_rpm_ok_for_spm()
10632 link_state = ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl); in ufshcd_rpm_ok_for_spm()
10634 hba->curr_dev_pwr_mode == dev_pwr_mode && in ufshcd_rpm_ok_for_spm()
10635 hba->uic_link_state == link_state && in ufshcd_rpm_ok_for_spm()
10636 !hba->dev_info.b_rpm_dev_flush_capable; in ufshcd_rpm_ok_for_spm()
10637 spin_unlock_irqrestore(&dev->power.lock, flags); in ufshcd_rpm_ok_for_spm()
10648 * SCSI assumes that runtime-pm and system-pm for scsi drivers in __ufshcd_suspend_prepare()
10649 * are same. And it doesn't wake up the device for system-suspend in __ufshcd_suspend_prepare()
10653 if (hba->ufs_device_wlun) { in __ufshcd_suspend_prepare()
10663 if (ret < 0 && ret != -EACCES) { in __ufshcd_suspend_prepare()
10668 hba->complete_put = true; in __ufshcd_suspend_prepare()
10684 struct ufs_hba *hba = shost_priv(sdev->host); in ufshcd_wl_poweroff()
10696 return -ENODEV; in ufshcd_wl_probe()
10698 blk_pm_runtime_init(sdev->request_queue, dev); in ufshcd_wl_probe()
10726 * gcc compilers before version 10 cannot do constant-folding for in ufshcd_check_header_layout()
10727 * sub-byte bitfields. Hence skip the layout checks for gcc 9 and in ufshcd_check_header_layout()
10771 * ufs_dev_wlun_template - describes ufs device wlun
10772 * ufs-device wlun - used to send pm commands
10773 * All luns are consumers of ufs-device wlun.
10777 * With ufs design, SSU should be sent to ufs-device wlun.