summaryrefslogtreecommitdiff
path: root/drivers/scsi/ufs
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/ufs')
-rw-r--r--drivers/scsi/ufs/ufs.h6
-rw-r--r--drivers/scsi/ufs/ufshcd.c80
-rw-r--r--drivers/scsi/ufs/ufshpb.c22
3 files changed, 90 insertions, 18 deletions
diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
index 0bfdca3e648e..4a00c24a3209 100644
--- a/drivers/scsi/ufs/ufs.h
+++ b/drivers/scsi/ufs/ufs.h
@@ -43,6 +43,12 @@
/* WriteBooster buffer is available only for the logical unit from 0 to 7 */
#define UFS_UPIU_MAX_WB_LUN_ID 8
+/*
+ * WriteBooster buffer lifetime has a limit setted by vendor.
+ * If it is over the limit, WriteBooster feature will be disabled.
+ */
+#define UFS_WB_EXCEED_LIFETIME 0x0B
+
/* Well known logical unit id in LUN field of UPIU */
enum {
UFS_UPIU_REPORT_LUNS_WLUN = 0x81,
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 9349557b8a01..3f9caafa91bf 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -83,8 +83,6 @@
/* Polling time to wait for fDeviceInit */
#define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
-#define wlun_dev_to_hba(dv) shost_priv(to_scsi_device(dv)->host)
-
#define ufshcd_toggle_vreg(_dev, _vreg, _on) \
({ \
int _ret; \
@@ -367,7 +365,7 @@ static void ufshcd_add_uic_command_trace(struct ufs_hba *hba,
static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,
enum ufs_trace_str_t str_t)
{
- u64 lba;
+ u64 lba = 0;
u8 opcode = 0, group_id = 0;
u32 intr, doorbell;
struct ufshcd_lrb *lrbp = &hba->lrb[tag];
@@ -384,7 +382,6 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,
return;
opcode = cmd->cmnd[0];
- lba = scsi_get_lba(cmd);
if (opcode == READ_10 || opcode == WRITE_10) {
/*
@@ -392,6 +389,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,
*/
transfer_len =
be32_to_cpu(lrbp->ucd_req_ptr->sc.exp_data_transfer_len);
+ lba = scsi_get_lba(cmd);
if (opcode == WRITE_10)
group_id = lrbp->cmd->cmnd[6];
} else if (opcode == UNMAP) {
@@ -399,6 +397,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,
* The number of Bytes to be unmapped beginning with the lba.
*/
transfer_len = blk_rq_bytes(rq);
+ lba = scsi_get_lba(cmd);
}
intr = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
@@ -585,7 +584,12 @@ static void ufshcd_print_pwr_info(struct ufs_hba *hba)
"INVALID MODE",
};
- dev_err(hba->dev, "%s:[RX, TX]: gear=[%d, %d], lane[%d, %d], pwr[%s, %s], rate = %d\n",
+ /*
+ * Using dev_dbg to avoid messages during runtime PM to avoid
+ * never-ending cycles of messages written back to storage by user space
+ * causing runtime resume, causing more messages and so on.
+ */
+ dev_dbg(hba->dev, "%s:[RX, TX]: gear=[%d, %d], lane[%d, %d], pwr[%s, %s], rate = %d\n",
__func__,
hba->pwr_info.gear_rx, hba->pwr_info.gear_tx,
hba->pwr_info.lane_rx, hba->pwr_info.lane_tx,
@@ -5024,6 +5028,12 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)
pm_runtime_get_noresume(&sdev->sdev_gendev);
else if (ufshcd_is_rpm_autosuspend_allowed(hba))
sdev->rpm_autosuspend = 1;
+ /*
+ * Do not print messages during runtime PM to avoid never-ending cycles
+ * of messages written back to storage by user space causing runtime
+ * resume, causing more messages and so on.
+ */
+ sdev->silence_suspend = 1;
ufshcd_crypto_register(hba, q);
@@ -5778,6 +5788,47 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
return false;
}
+static void ufshcd_wb_force_disable(struct ufs_hba *hba)
+{
+ if (!(hba->quirks & UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL))
+ ufshcd_wb_toggle_flush(hba, false);
+
+ ufshcd_wb_toggle_flush_during_h8(hba, false);
+ ufshcd_wb_toggle(hba, false);
+ hba->caps &= ~UFSHCD_CAP_WB_EN;
+
+ dev_info(hba->dev, "%s: WB force disabled\n", __func__);
+}
+
+static bool ufshcd_is_wb_buf_lifetime_available(struct ufs_hba *hba)
+{
+ u32 lifetime;
+ int ret;
+ u8 index;
+
+ index = ufshcd_wb_get_query_index(hba);
+ ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST,
+ index, 0, &lifetime);
+ if (ret) {
+ dev_err(hba->dev,
+ "%s: bWriteBoosterBufferLifeTimeEst read failed %d\n",
+ __func__, ret);
+ return false;
+ }
+
+ if (lifetime == UFS_WB_EXCEED_LIFETIME) {
+ dev_err(hba->dev, "%s: WB buf lifetime is exhausted 0x%02X\n",
+ __func__, lifetime);
+ return false;
+ }
+
+ dev_dbg(hba->dev, "%s: WB buf lifetime is 0x%02X\n",
+ __func__, lifetime);
+
+ return true;
+}
+
static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
{
int ret;
@@ -5786,6 +5837,12 @@ static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
if (!ufshcd_is_wb_allowed(hba))
return false;
+
+ if (!ufshcd_is_wb_buf_lifetime_available(hba)) {
+ ufshcd_wb_force_disable(hba);
+ return false;
+ }
+
/*
* The ufs device needs the vcc to be ON to flush.
* With user-space reduction enabled, it's enough to enable flush
@@ -7339,7 +7396,13 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba,
if (!hba->vreg_info.vcc || !hba->vreg_info.vccq ||
!hba->vreg_info.vccq2) {
- dev_err(hba->dev,
+ /*
+ * Using dev_dbg to avoid messages during runtime PM to avoid
+ * never-ending cycles of messages written back to storage by
+ * user space causing runtime resume, causing more messages and
+ * so on.
+ */
+ dev_dbg(hba->dev,
"%s: Regulator capability was not set, actvIccLevel=%d",
__func__, icc_level);
goto out;
@@ -7486,6 +7549,7 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf)
if (!ufshcd_is_wb_allowed(hba))
return;
+
/*
* Probe WB only for UFS-2.2 and UFS-3.1 (and later) devices or
* UFS devices with quirk UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES
@@ -7537,6 +7601,10 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf)
if (!d_lu_wb_buf_alloc)
goto wb_disabled;
}
+
+ if (!ufshcd_is_wb_buf_lifetime_available(hba))
+ goto wb_disabled;
+
return;
wb_disabled:
diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c
index 8970068314ef..b2bec19022cd 100644
--- a/drivers/scsi/ufs/ufshpb.c
+++ b/drivers/scsi/ufs/ufshpb.c
@@ -666,15 +666,14 @@ static void ufshpb_execute_umap_req(struct ufshpb_lu *hpb,
struct ufshpb_req *umap_req,
struct ufshpb_region *rgn)
{
- struct request *req;
- struct scsi_request *rq;
+ struct request *req = umap_req->req;
+ struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
- req = umap_req->req;
req->timeout = 0;
- req->end_io_data = (void *)umap_req;
- rq = scsi_req(req);
- ufshpb_set_unmap_cmd(rq->cmd, rgn);
- rq->cmd_len = HPB_WRITE_BUFFER_CMD_LENGTH;
+ req->end_io_data = umap_req;
+
+ ufshpb_set_unmap_cmd(scmd->cmnd, rgn);
+ scmd->cmd_len = HPB_WRITE_BUFFER_CMD_LENGTH;
blk_execute_rq_nowait(req, true, ufshpb_umap_req_compl_fn);
@@ -686,7 +685,7 @@ static int ufshpb_execute_map_req(struct ufshpb_lu *hpb,
{
struct request_queue *q;
struct request *req;
- struct scsi_request *rq;
+ struct scsi_cmnd *scmd;
int mem_size = hpb->srgn_mem_size;
int ret = 0;
int i;
@@ -709,14 +708,13 @@ static int ufshpb_execute_map_req(struct ufshpb_lu *hpb,
req->end_io_data = map_req;
- rq = scsi_req(req);
-
if (unlikely(last))
mem_size = hpb->last_srgn_entries * HPB_ENTRY_SIZE;
- ufshpb_set_read_buf_cmd(rq->cmd, map_req->rb.rgn_idx,
+ scmd = blk_mq_rq_to_pdu(req);
+ ufshpb_set_read_buf_cmd(scmd->cmnd, map_req->rb.rgn_idx,
map_req->rb.srgn_idx, mem_size);
- rq->cmd_len = HPB_READ_BUFFER_CMD_LENGTH;
+ scmd->cmd_len = HPB_READ_BUFFER_CMD_LENGTH;
blk_execute_rq_nowait(req, true, ufshpb_map_req_compl_fn);