Commit 22188f4a933c6e86ac67f52028895c795896492e
1 parent
dae51546b6
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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 <bigeasy@linutronix.de>
Showing 1 changed file with 17 additions and 16 deletions Side-by-side Diff
drivers/usb/storage/uas.c
... | ... | @@ -98,6 +98,7 @@ |
98 | 98 | unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; |
99 | 99 | unsigned use_streams:1; |
100 | 100 | unsigned uas_sense_old:1; |
101 | + struct scsi_cmnd *cmnd; | |
101 | 102 | }; |
102 | 103 | |
103 | 104 | enum { |
... | ... | @@ -178,8 +179,6 @@ |
178 | 179 | } |
179 | 180 | |
180 | 181 | cmnd->result = sense_iu->status; |
181 | - if (sdev->current_cmnd) | |
182 | - sdev->current_cmnd = NULL; | |
183 | 182 | cmnd->scsi_done(cmnd); |
184 | 183 | usb_free_urb(urb); |
185 | 184 | } |
... | ... | @@ -205,8 +204,6 @@ |
205 | 204 | } |
206 | 205 | |
207 | 206 | cmnd->result = sense_iu->status; |
208 | - if (sdev->current_cmnd) | |
209 | - sdev->current_cmnd = NULL; | |
210 | 207 | cmnd->scsi_done(cmnd); |
211 | 208 | usb_free_urb(urb); |
212 | 209 | } |
... | ... | @@ -230,8 +227,8 @@ |
230 | 227 | static void uas_stat_cmplt(struct urb *urb) |
231 | 228 | { |
232 | 229 | 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]; | |
235 | 232 | struct scsi_cmnd *cmnd; |
236 | 233 | u16 tag; |
237 | 234 | |
238 | 235 | |
... | ... | @@ -242,10 +239,10 @@ |
242 | 239 | } |
243 | 240 | |
244 | 241 | 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; | |
247 | 244 | else |
248 | - cmnd = scsi_find_tag(sdev, tag); | |
245 | + cmnd = scsi_host_find_tag(shost, tag - 1); | |
249 | 246 | if (!cmnd) { |
250 | 247 | usb_free_urb(urb); |
251 | 248 | return; |
... | ... | @@ -253,6 +250,9 @@ |
253 | 250 | |
254 | 251 | switch (iu->iu_id) { |
255 | 252 | case IU_ID_STATUS: |
253 | + if (devinfo->cmnd == cmnd) | |
254 | + devinfo->cmnd = NULL; | |
255 | + | |
256 | 256 | if (urb->actual_length < 16) |
257 | 257 | devinfo->uas_sense_old = 1; |
258 | 258 | if (devinfo->uas_sense_old) |
... | ... | @@ -314,7 +314,7 @@ |
314 | 314 | goto free; |
315 | 315 | |
316 | 316 | 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); | |
318 | 318 | urb->stream_id = stream_id; |
319 | 319 | urb->transfer_flags |= URB_FREE_BUFFER; |
320 | 320 | out: |
... | ... | @@ -346,7 +346,7 @@ |
346 | 346 | |
347 | 347 | iu->iu_id = IU_ID_COMMAND; |
348 | 348 | 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); | |
350 | 350 | else |
351 | 351 | iu->tag = cpu_to_be16(1); |
352 | 352 | iu->prio_attr = UAS_SIMPLE_TAG; |
353 | 353 | |
354 | 354 | |
... | ... | @@ -458,13 +458,13 @@ |
458 | 458 | |
459 | 459 | BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); |
460 | 460 | |
461 | - if (!cmdinfo->status_urb && sdev->current_cmnd) | |
461 | + if (devinfo->cmnd) | |
462 | 462 | return SCSI_MLQUEUE_DEVICE_BUSY; |
463 | 463 | |
464 | 464 | if (blk_rq_tagged(cmnd->request)) { |
465 | - cmdinfo->stream = cmnd->request->tag + 1; | |
465 | + cmdinfo->stream = cmnd->request->tag + 2; | |
466 | 466 | } else { |
467 | - sdev->current_cmnd = cmnd; | |
467 | + devinfo->cmnd = cmnd; | |
468 | 468 | cmdinfo->stream = 1; |
469 | 469 | } |
470 | 470 | |
... | ... | @@ -565,7 +565,7 @@ |
565 | 565 | { |
566 | 566 | struct uas_dev_info *devinfo = sdev->hostdata; |
567 | 567 | scsi_set_tag_type(sdev, MSG_ORDERED_TAG); |
568 | - scsi_activate_tcq(sdev, devinfo->qdepth - 1); | |
568 | + scsi_activate_tcq(sdev, devinfo->qdepth - 2); | |
569 | 569 | return 0; |
570 | 570 | } |
571 | 571 | |
... | ... | @@ -633,6 +633,7 @@ |
633 | 633 | unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints; |
634 | 634 | |
635 | 635 | devinfo->uas_sense_old = 0; |
636 | + devinfo->cmnd = NULL; | |
636 | 637 | |
637 | 638 | for (i = 0; i < n_endpoints; i++) { |
638 | 639 | unsigned char *extra = endpoint[i].extra; |
... | ... | @@ -728,7 +729,7 @@ |
728 | 729 | devinfo->udev = udev; |
729 | 730 | uas_configure_endpoints(devinfo); |
730 | 731 | |
731 | - result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 1); | |
732 | + result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 2); | |
732 | 733 | if (result) |
733 | 734 | goto free; |
734 | 735 |