All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] ufs driver fixes and updates
@ 2014-07-01  9:22 Dolev Raviv
  2014-07-01  9:22 ` [PATCH 1/3] scsi: ufs: read door bell register after clearing interrupt aggregation Dolev Raviv
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dolev Raviv @ 2014-07-01  9:22 UTC (permalink / raw)
  To: James.Bottomley
  Cc: linux-scsi, linux-scsi-owner, sthumma, linux-arm-msm, santoshsy,
	Dolev Raviv

Misc fixes and updates for the UFS driver.

Dolev Raviv (1):
  scsi: ufs: read door bell register after clearing interrupt
    aggregation

Sujit Reddy Thumma (2):
  scsi: ufs: Fix sending unsupported SCSI command
  scsi: ufs: retry if the link-startup fails

 drivers/scsi/ufs/ufshcd.c | 95 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 61 insertions(+), 34 deletions(-)

-- 
1.8.5.2

-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] scsi: ufs: read door bell register after clearing interrupt aggregation
  2014-07-01  9:22 [PATCH 0/3] ufs driver fixes and updates Dolev Raviv
@ 2014-07-01  9:22 ` Dolev Raviv
  2014-07-01  9:22 ` [PATCH 2/3] scsi: ufs: Fix sending unsupported SCSI command Dolev Raviv
  2014-07-01  9:22 ` [PATCH 3/3] scsi: ufs: retry if the link-startup fails Dolev Raviv
  2 siblings, 0 replies; 7+ messages in thread
From: Dolev Raviv @ 2014-07-01  9:22 UTC (permalink / raw)
  To: James.Bottomley
  Cc: linux-scsi, linux-scsi-owner, sthumma, linux-arm-msm, santoshsy,
	Dolev Raviv

In interrupt context, after reading and comparing the UTRLDBR to
hba->outstanding_request and before resetting the interrupt aggregation,
there might be completion of another transfer request (TR). Such TRs might
get stuck, pending, until the next interrupt is generated (if any).
Changing the sequence of resetting the interrupt aggregation first and
then reading UTRLDBR status, will assure that completed TRs won't get
stuck pending.

Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 67 ++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 33 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b103e95..b533ff8 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2231,47 +2231,42 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
 	u32 tr_doorbell;
 	int result;
 	int index;
-	bool int_aggr_reset = false;
+
+	/* Resetting interrupt aggregation counters first and reading the
+	 * DOOR_BELL afterward allows us to handle all the completed requests.
+	 * In order to prevent other interrupts starvation the DB is read once
+	 * after reset. The down side of this solution is the possibility of
+	 * false interrupt if device completes another request after resetting
+	 * aggregation and before reading the DB.
+	 */
+	ufshcd_reset_intr_aggr(hba);
 
 	tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
 	completed_reqs = tr_doorbell ^ hba->outstanding_reqs;
 
-	for (index = 0; index < hba->nutrs; index++) {
-		if (test_bit(index, &completed_reqs)) {
-			lrbp = &hba->lrb[index];
-			cmd = lrbp->cmd;
-			/*
-			 * Don't skip resetting interrupt aggregation counters
-			 * if a regular command is present.
-			 */
-			int_aggr_reset |= !lrbp->intr_cmd;
-
-			if (cmd) {
-				result = ufshcd_transfer_rsp_status(hba, lrbp);
-				scsi_dma_unmap(cmd);
-				cmd->result = result;
-				/* Mark completed command as NULL in LRB */
-				lrbp->cmd = NULL;
-				clear_bit_unlock(index, &hba->lrb_in_use);
-				/* Do not touch lrbp after scsi done */
-				cmd->scsi_done(cmd);
-			} else if (lrbp->command_type ==
-					UTP_CMD_TYPE_DEV_MANAGE) {
-				if (hba->dev_cmd.complete)
-					complete(hba->dev_cmd.complete);
-			}
-		} /* end of if */
-	} /* end of for */
+	for_each_set_bit(index, &completed_reqs, hba->nutrs) {
+		lrbp = &hba->lrb[index];
+		cmd = lrbp->cmd;
+		if (cmd) {
+			result = ufshcd_transfer_rsp_status(hba, lrbp);
+			scsi_dma_unmap(cmd);
+			cmd->result = result;
+			/* Mark completed command as NULL in LRB */
+			lrbp->cmd = NULL;
+			clear_bit_unlock(index, &hba->lrb_in_use);
+			/* Do not touch lrbp after scsi done */
+			cmd->scsi_done(cmd);
+		} else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE) {
+			if (hba->dev_cmd.complete)
+				complete(hba->dev_cmd.complete);
+		}
+	}
 
 	/* clear corresponding bits of completed commands */
 	hba->outstanding_reqs ^= completed_reqs;
 
 	/* we might have free'd some tags above */
 	wake_up(&hba->dev_cmd.tag_wq);
-
-	/* Reset interrupt aggregation counters */
-	if (int_aggr_reset)
-		ufshcd_reset_intr_aggr(hba);
 }
 
 /**
@@ -2876,6 +2871,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 	int poll_cnt;
 	u8 resp = 0xF;
 	struct ufshcd_lrb *lrbp;
+	u32 reg;
 
 	host = cmd->device->host;
 	hba = shost_priv(host);
@@ -2885,6 +2881,13 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 	if (!(test_bit(tag, &hba->outstanding_reqs)))
 		goto out;
 
+	reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
+	if (!(reg & (1 << tag))) {
+		dev_err(hba->dev,
+		"%s: cmd was completed, but without a notifying intr, tag = %d",
+		__func__, tag);
+	}
+
 	lrbp = &hba->lrb[tag];
 	for (poll_cnt = 100; poll_cnt; poll_cnt--) {
 		err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag,
@@ -2893,8 +2896,6 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 			/* cmd pending in the device */
 			break;
 		} else if (!err && resp == UPIU_TASK_MANAGEMENT_FUNC_COMPL) {
-			u32 reg;
-
 			/*
 			 * cmd not pending in the device, check if it is
 			 * in transition.
-- 
1.8.5.2

-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] scsi: ufs: Fix sending unsupported SCSI command
  2014-07-01  9:22 [PATCH 0/3] ufs driver fixes and updates Dolev Raviv
  2014-07-01  9:22 ` [PATCH 1/3] scsi: ufs: read door bell register after clearing interrupt aggregation Dolev Raviv
@ 2014-07-01  9:22 ` Dolev Raviv
  2014-07-01  9:22 ` [PATCH 3/3] scsi: ufs: retry if the link-startup fails Dolev Raviv
  2 siblings, 0 replies; 7+ messages in thread
From: Dolev Raviv @ 2014-07-01  9:22 UTC (permalink / raw)
  To: James.Bottomley
  Cc: linux-scsi, linux-scsi-owner, sthumma, linux-arm-msm, santoshsy,
	Dolev Raviv

From: Sujit Reddy Thumma <sthumma@codeaurora.org>

UFS 1.1 specification does not support MAINTENANCE IN(0xA3) SCSI
command and hence it doesn't support REPORT SUPPORTED OPERATION CODES
as well.

Change-Id: Ic09c5b46b2511b1c28db478023c32b898ac69e6d
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b533ff8..f189e8a 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1992,6 +1992,9 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
 	/* allow SCSI layer to restart the device in case of errors */
 	sdev->allow_restart = 1;
 
+	/* REPORT SUPPORTED OPERATION CODES is not supported */
+	sdev->no_report_opcodes = 1;
+
 	lun_qdepth = ufshcd_read_sdev_qdepth(hba, sdev);
 	if (lun_qdepth <= 0)
 		/* eventually, we can figure out the real queue depth */
-- 
1.8.5.2

-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] scsi: ufs: retry if the link-startup fails
  2014-07-01  9:22 [PATCH 0/3] ufs driver fixes and updates Dolev Raviv
  2014-07-01  9:22 ` [PATCH 1/3] scsi: ufs: read door bell register after clearing interrupt aggregation Dolev Raviv
  2014-07-01  9:22 ` [PATCH 2/3] scsi: ufs: Fix sending unsupported SCSI command Dolev Raviv
@ 2014-07-01  9:22 ` Dolev Raviv
  2014-07-07 10:37   ` Christoph Hellwig
  2 siblings, 1 reply; 7+ messages in thread
From: Dolev Raviv @ 2014-07-01  9:22 UTC (permalink / raw)
  To: James.Bottomley
  Cc: linux-scsi, linux-scsi-owner, sthumma, linux-arm-msm, santoshsy,
	Dolev Raviv

From: Sujit Reddy Thumma <sthumma@codeaurora.org>

In some cases, due to hardware timing issues the Uni-Pro link-startup
might fail. The UFS HCI recovery procedure contradicts the Uni-Pro
sequence. The UFS HCI specifies to resend DME_LINKSTARTUP command
after IS.ULLS (link-lost interrupt) is received. The Uni-Pro specifies
that if link-startup fails the link is in "down" state. The link-lost is
indicated to the DME user only when the link is up. Hence, the UFS HCI
recovery procedure of waiting for IS.ULLS and retrying link-startup may
not work properly.

In order to resolve the ambiguity, reset the host controller to make
sure the link is in down state and retry the link-startup.

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index f189e8a..3776f5d 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -58,6 +58,9 @@
 /* Task management command timeout */
 #define TM_CMD_TIMEOUT	100 /* msecs */
 
+/* maximum number of link-startup retries */
+#define DME_LINKSTARTUP_RETRIES 3
+
 /* Expose the flag value from utp_upiu_query.value */
 #define MASK_QUERY_UPIU_FLAG_LOC 0xFF
 
@@ -1923,12 +1926,32 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)
 static int ufshcd_link_startup(struct ufs_hba *hba)
 {
 	int ret;
+	int retries = DME_LINKSTARTUP_RETRIES;
 
 	/* enable UIC related interrupts */
 	ufshcd_enable_intr(hba, UIC_COMMAND_COMPL);
 
-	ret = ufshcd_dme_link_startup(hba);
+	do {
+		ret = ufshcd_dme_link_startup(hba);
+
+		/* check if device is detected by inter-connect layer */
+		if (!ret && !ufshcd_is_device_present(hba)) {
+			dev_err(hba->dev, "%s: Device not present\n", __func__);
+			ret = -ENXIO;
+			goto out;
+		}
+
+		/*
+		 * DME link lost indication is only received when link is up,
+		 * but we can't be sure if the link is up until link startup
+		 * succeeds. So reset the local Uni-Pro and try again.
+		 */
+		if (ret && ufshcd_hba_enable(hba))
+			goto out;
+	} while (ret && retries--);
+
 	if (ret)
+		/* failed to get the link up... retire */
 		goto out;
 
 	ret = ufshcd_make_hba_operational(hba);
-- 
1.8.5.2

-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] scsi: ufs: retry if the link-startup fails
  2014-07-01  9:22 ` [PATCH 3/3] scsi: ufs: retry if the link-startup fails Dolev Raviv
@ 2014-07-07 10:37   ` Christoph Hellwig
  2014-07-08 10:18     ` Dolev Raviv
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2014-07-07 10:37 UTC (permalink / raw)
  To: Dolev Raviv
  Cc: James.Bottomley, linux-scsi, linux-scsi-owner, sthumma,
	linux-arm-msm, santoshsy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=unknown-8bit, Size: 694 bytes --]

This produces a compiler warning for me that looks serious:

../drivers/scsi/ufs/ufshcd.c: In function ‘ufshcd_link_startup’:
../drivers/scsi/ufs/ufshcd.c:1938:3: warning: passing argument 1 of
‘ufshcd_is_device_present’ makes integer from pointer without a
cast [enabled by default]
../drivers/scsi/ufs/ufshcd.c:185:19: note: expected ‘u32’ but
argument is of type ‘struct ufs_hba *’

Did you plan to change the arguments to ufshcd_is_device_present in
a later patch?
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 3/3] scsi: ufs: retry if the link-startup fails
  2014-07-07 10:37   ` Christoph Hellwig
@ 2014-07-08 10:18     ` Dolev Raviv
  2014-07-08 10:35       ` 'Christoph Hellwig'
  0 siblings, 1 reply; 7+ messages in thread
From: Dolev Raviv @ 2014-07-08 10:18 UTC (permalink / raw)
  To: 'Christoph Hellwig'
  Cc: James.Bottomley, linux-scsi, linux-scsi-owner, sthumma,
	linux-arm-msm, santoshsy

> Did you plan to change the arguments to ufshcd_is_device_present in a later patch?
I guess I overlooked it, thanks for bringing it to my attention.
I will resend the series without this patch.

Thanks,
Dolev
-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation


-----Original Message-----
From: Christoph Hellwig [mailto:hch@infradead.org] 
Sent: Monday, July 07, 2014 1:37 PM
To: Dolev Raviv
Cc: James.Bottomley@HansenPartnership.com; linux-scsi@vger.kernel.org; linux-scsi-owner@vger.kernel.org; sthumma@codeaurora.org; linux-arm-msm@vger.kernel.org; santoshsy@gmail.com
Subject: Re: [PATCH 3/3] scsi: ufs: retry if the link-startup fails

This produces a compiler warning for me that looks serious:

../drivers/scsi/ufs/ufshcd.c: In function ‘ufshcd_link_startup’:
../drivers/scsi/ufs/ufshcd.c:1938:3: warning: passing argument 1 of ‘ufshcd_is_device_present’ makes integer from pointer without a cast [enabled by default]
../drivers/scsi/ufs/ufshcd.c:185:19: note: expected ‘u32’ but argument is of type ‘struct ufs_hba *’

Did you plan to change the arguments to ufshcd_is_device_present in a later patch?

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] scsi: ufs: retry if the link-startup fails
  2014-07-08 10:18     ` Dolev Raviv
@ 2014-07-08 10:35       ` 'Christoph Hellwig'
  0 siblings, 0 replies; 7+ messages in thread
From: 'Christoph Hellwig' @ 2014-07-08 10:35 UTC (permalink / raw)
  To: Dolev Raviv
  Cc: James.Bottomley, linux-scsi, linux-scsi-owner, sthumma,
	linux-arm-msm, santoshsy

On Tue, Jul 08, 2014 at 01:18:27PM +0300, Dolev Raviv wrote:
> > Did you plan to change the arguments to ufshcd_is_device_present in a later patch?
> I guess I overlooked it, thanks for bringing it to my attention.
> I will resend the series without this patch.

If the series works just fine without this patch I'm happy to drop it
locally, no need to resend.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-08 10:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-01  9:22 [PATCH 0/3] ufs driver fixes and updates Dolev Raviv
2014-07-01  9:22 ` [PATCH 1/3] scsi: ufs: read door bell register after clearing interrupt aggregation Dolev Raviv
2014-07-01  9:22 ` [PATCH 2/3] scsi: ufs: Fix sending unsupported SCSI command Dolev Raviv
2014-07-01  9:22 ` [PATCH 3/3] scsi: ufs: retry if the link-startup fails Dolev Raviv
2014-07-07 10:37   ` Christoph Hellwig
2014-07-08 10:18     ` Dolev Raviv
2014-07-08 10:35       ` 'Christoph Hellwig'

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.