Skip to content

Commit 22188f4

Browse files
author
Sebastian Andrzej Siewior
committed
usb/uas: use scsi_host_find_tag() to find command from a tag
In "usb/uas: use unique tags for all LUNs" we make sure to create unique tags across all LUNs. This patch uses scsi_host_find_tag() to obtain the correct command which is associated with the tag. The following changes are required: - don't use sdev->current_cmnd anymore Since we can have devices which don't support command queueing we must ensure that we can tell the two commands apart. Even if a device supports comand queuing we send the INQUIRY command "untagged" for LUN1 while we can send a tagged command to LUN0 at the same time. devinfo->cmnd is used for stashing the one "untagged" command. - tag number is altered. If stream support is used then the tag number must match the stream number. Therefore we can't use tag 0 and must start at tag 1. In case we have untagged commands (at least the first command) we must be able to distinguish between command tag 0 (which becomes 1) and untagged command (which becomes curently also 1). The following tag numbers are used: 0: never 1: for untagged commands (devinfo->cmnd) 2+: tagged commands. Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
1 parent dae5154 commit 22188f4

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

drivers/usb/storage/uas.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct uas_dev_info {
9898
unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe;
9999
unsigned use_streams:1;
100100
unsigned uas_sense_old:1;
101+
struct scsi_cmnd *cmnd;
101102
};
102103

103104
enum {
@@ -178,8 +179,6 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
178179
}
179180

180181
cmnd->result = sense_iu->status;
181-
if (sdev->current_cmnd)
182-
sdev->current_cmnd = NULL;
183182
cmnd->scsi_done(cmnd);
184183
usb_free_urb(urb);
185184
}
@@ -205,8 +204,6 @@ static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
205204
}
206205

207206
cmnd->result = sense_iu->status;
208-
if (sdev->current_cmnd)
209-
sdev->current_cmnd = NULL;
210207
cmnd->scsi_done(cmnd);
211208
usb_free_urb(urb);
212209
}
@@ -230,8 +227,8 @@ static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
230227
static void uas_stat_cmplt(struct urb *urb)
231228
{
232229
struct iu *iu = urb->transfer_buffer;
233-
struct scsi_device *sdev = urb->context;
234-
struct uas_dev_info *devinfo = sdev->hostdata;
230+
struct Scsi_Host *shost = urb->context;
231+
struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
235232
struct scsi_cmnd *cmnd;
236233
u16 tag;
237234

@@ -242,17 +239,20 @@ static void uas_stat_cmplt(struct urb *urb)
242239
}
243240

244241
tag = be16_to_cpup(&iu->tag) - 1;
245-
if (sdev->current_cmnd)
246-
cmnd = sdev->current_cmnd;
242+
if (tag == 0)
243+
cmnd = devinfo->cmnd;
247244
else
248-
cmnd = scsi_find_tag(sdev, tag);
245+
cmnd = scsi_host_find_tag(shost, tag - 1);
249246
if (!cmnd) {
250247
usb_free_urb(urb);
251248
return;
252249
}
253250

254251
switch (iu->iu_id) {
255252
case IU_ID_STATUS:
253+
if (devinfo->cmnd == cmnd)
254+
devinfo->cmnd = NULL;
255+
256256
if (urb->actual_length < 16)
257257
devinfo->uas_sense_old = 1;
258258
if (devinfo->uas_sense_old)
@@ -314,7 +314,7 @@ static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp,
314314
goto free;
315315

316316
usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu),
317-
uas_stat_cmplt, cmnd->device);
317+
uas_stat_cmplt, cmnd->device->host);
318318
urb->stream_id = stream_id;
319319
urb->transfer_flags |= URB_FREE_BUFFER;
320320
out:
@@ -346,7 +346,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
346346

347347
iu->iu_id = IU_ID_COMMAND;
348348
if (blk_rq_tagged(cmnd->request))
349-
iu->tag = cpu_to_be16(cmnd->request->tag + 1);
349+
iu->tag = cpu_to_be16(cmnd->request->tag + 2);
350350
else
351351
iu->tag = cpu_to_be16(1);
352352
iu->prio_attr = UAS_SIMPLE_TAG;
@@ -458,13 +458,13 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
458458

459459
BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer));
460460

461-
if (!cmdinfo->status_urb && sdev->current_cmnd)
461+
if (devinfo->cmnd)
462462
return SCSI_MLQUEUE_DEVICE_BUSY;
463463

464464
if (blk_rq_tagged(cmnd->request)) {
465-
cmdinfo->stream = cmnd->request->tag + 1;
465+
cmdinfo->stream = cmnd->request->tag + 2;
466466
} else {
467-
sdev->current_cmnd = cmnd;
467+
devinfo->cmnd = cmnd;
468468
cmdinfo->stream = 1;
469469
}
470470

@@ -565,7 +565,7 @@ static int uas_slave_configure(struct scsi_device *sdev)
565565
{
566566
struct uas_dev_info *devinfo = sdev->hostdata;
567567
scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
568-
scsi_activate_tcq(sdev, devinfo->qdepth - 1);
568+
scsi_activate_tcq(sdev, devinfo->qdepth - 2);
569569
return 0;
570570
}
571571

@@ -633,6 +633,7 @@ static void uas_configure_endpoints(struct uas_dev_info *devinfo)
633633
unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints;
634634

635635
devinfo->uas_sense_old = 0;
636+
devinfo->cmnd = NULL;
636637

637638
for (i = 0; i < n_endpoints; i++) {
638639
unsigned char *extra = endpoint[i].extra;
@@ -728,7 +729,7 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
728729
devinfo->udev = udev;
729730
uas_configure_endpoints(devinfo);
730731

731-
result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 1);
732+
result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 2);
732733
if (result)
733734
goto free;
734735

0 commit comments

Comments
 (0)