[PATCH 3/4] [USB] UASP: Reorganize stream id assignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the host controller reports more streams than
it actually supports and the device goes into flow
control due to an unsupported stream id, we can
now send a TMF with a stream id that the host
controller can handle.

Signed-off-by: Luben Tuikov <ltuikov@xxxxxxxxx>
---
 drivers/usb/storage/uasp.c |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/storage/uasp.c b/drivers/usb/storage/uasp.c
index e5a26e9..40ee5a4 100644
--- a/drivers/usb/storage/uasp.c
+++ b/drivers/usb/storage/uasp.c
@@ -43,6 +43,10 @@ MODULE_PARM_DESC(MaxNumStreams, "\n"
 	"\tattached device and this value. Valid values are -1, default,\n"
 	"\tand 1 to 0xFFEF.");
 
+#define TMF_TAG          1
+#define CMD_UNTAGGED_TAG 2
+#define CMD_TAG_OFFS     3
+
 /* Information unit types
  */
 #define IU_CMD   1
@@ -189,7 +193,7 @@ static void uasp_sense(struct urb *urb, struct scsi_cmnd *cmd, u16 tag)
 		memcpy(cmd->sense_buffer, iu + IU_SENSE_LEN, slen);
 	}
 
-	if (tag == 1)
+	if (tag == CMD_UNTAGGED_TAG)
 		sdev->current_cmnd = NULL;
 	cmd->scsi_done(cmd);
 	usb_free_urb(urb);
@@ -267,10 +271,10 @@ static void uasp_stat_done(struct urb *urb)
 		return;
 	}
 
-	if (tag == 1)
+	if (tag == CMD_UNTAGGED_TAG)
 		cmd = sdev->current_cmnd;
-	else if (tag > 1)
-		cmd = scsi_find_tag(sdev, tag-2);
+	else if (tag >= CMD_TAG_OFFS)
+		cmd = scsi_find_tag(sdev, tag - CMD_TAG_OFFS);
 
 	if (cmd == NULL)
 		goto Out_no_cmd;
@@ -583,10 +587,10 @@ static int uasp_queuecommand(struct scsi_cmnd *cmd,
 	 * regardless of how many tags it supports.
 	 */
 	if (blk_rq_tagged(cmd->request)) {
-		cmdinfo->tag = cmd->request->tag + 2;
+		cmdinfo->tag = cmd->request->tag + CMD_TAG_OFFS;
 	} else if (sdev->current_cmnd == NULL) {
 		sdev->current_cmnd = cmd;
-		cmdinfo->tag = 1;
+		cmdinfo->tag = CMD_UNTAGGED_TAG;
 	} else {
 		cmd->result = DID_ABORT << 16;
 		goto Out_err;
@@ -643,7 +647,7 @@ static int uasp_alloc_tmf_urb(struct urb **urb, struct uasp_tport_info *tpinfo,
 	 * it for their own use, as well as being able to free it back
 	 * later. See the comment in uasp_set_max_cmds().
 	 */
-	tag = tpinfo->max_cmds + 2;
+	tag = TMF_TAG;
 
 	tiu[0] = IU_TMF;
 	tiu[2] = tag >> 8;
@@ -765,9 +769,9 @@ static int uasp_er_tmf(struct scsi_cmnd *cmd, u8 tmf)
 	int res;
 
 	if (sdev->current_cmnd == cmd)
-		tag = 1;
+		tag = CMD_UNTAGGED_TAG;
 	else
-		tag = cmd->request->tag + 2;
+		tag = cmd->request->tag + CMD_TAG_OFFS;
 
 	res = uasp_do_tmf(cmd, tmf, tag);
 
@@ -888,12 +892,13 @@ static int uasp_set_max_cmds(struct uasp_tport_info *tpinfo)
 {
 	int mc;
 
-	/* The range of tags generated by the block layer would be
-	 * [0, max_cmds-1], which is [0, num_streams-3]. Now reserve
-	 * stream 1 for untagged commands submitted to us and the last
-	 * usable stream id for a TMF to get the following stream id
-	 * assignment:
-	 * [1:untagged, [2, num_streams-1]:tagged, num_streams:TMF].
+	/* Define the following cmd tag assignment:
+	 * [1:TMF, 2:untagged, [3, num_streams]:tagged].
+	 * Thus there are num_streams-3+1 = num_streams-2 tags
+	 * for tagged commands. Report this number to the SCSI Core
+	 * as the number of maximum commands we can queue, thus
+	 * giving us a tag range [0, num_streams-3], which we
+	 * offset by 3 (CMD_TAG_OFFS).
 	 */
 	mc = tpinfo->num_streams - 2;
 	if (mc <= 0) {
-- 
1.7.0.1

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


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux