.. | .. |
---|
28 | 28 | * status of a command. |
---|
29 | 29 | */ |
---|
30 | 30 | |
---|
| 31 | +#include <linux/blkdev.h> |
---|
| 32 | +#include <linux/dma-mapping.h> |
---|
31 | 33 | #include <linux/module.h> |
---|
32 | 34 | #include <linux/mutex.h> |
---|
33 | 35 | |
---|
.. | .. |
---|
38 | 40 | #include <scsi/scsi_eh.h> |
---|
39 | 41 | |
---|
40 | 42 | #include "usb.h" |
---|
| 43 | +#include <linux/usb/hcd.h> |
---|
41 | 44 | #include "scsiglue.h" |
---|
42 | 45 | #include "debug.h" |
---|
43 | 46 | #include "transport.h" |
---|
.. | .. |
---|
89 | 92 | static int slave_configure(struct scsi_device *sdev) |
---|
90 | 93 | { |
---|
91 | 94 | struct us_data *us = host_to_us(sdev->host); |
---|
| 95 | + struct device *dev = us->pusb_dev->bus->sysdev; |
---|
92 | 96 | |
---|
93 | 97 | /* |
---|
94 | 98 | * Many devices have trouble transferring more than 32KB at a time, |
---|
.. | .. |
---|
123 | 127 | } |
---|
124 | 128 | |
---|
125 | 129 | /* |
---|
| 130 | + * The max_hw_sectors should be up to maximum size of a mapping for |
---|
| 131 | + * the device. Otherwise, a DMA API might fail on swiotlb environment. |
---|
| 132 | + */ |
---|
| 133 | + blk_queue_max_hw_sectors(sdev->request_queue, |
---|
| 134 | + min_t(size_t, queue_max_hw_sectors(sdev->request_queue), |
---|
| 135 | + dma_max_mapping_size(dev) >> SECTOR_SHIFT)); |
---|
| 136 | + |
---|
| 137 | + /* |
---|
126 | 138 | * Some USB host controllers can't do DMA; they have to use PIO. |
---|
127 | | - * They indicate this by setting their dma_mask to NULL. For |
---|
128 | | - * such controllers we need to make sure the block layer sets |
---|
| 139 | + * For such controllers we need to make sure the block layer sets |
---|
129 | 140 | * up bounce buffers in addressable memory. |
---|
130 | 141 | */ |
---|
131 | | - if (!us->pusb_dev->bus->controller->dma_mask) |
---|
| 142 | + if (!hcd_uses_dma(bus_to_hcd(us->pusb_dev->bus)) || |
---|
| 143 | + (bus_to_hcd(us->pusb_dev->bus)->localmem_pool != NULL)) |
---|
132 | 144 | blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH); |
---|
133 | 145 | |
---|
134 | 146 | /* |
---|
.. | .. |
---|
189 | 201 | */ |
---|
190 | 202 | sdev->skip_ms_page_8 = 1; |
---|
191 | 203 | |
---|
192 | | - /* Some devices don't handle VPD pages correctly */ |
---|
193 | | - sdev->skip_vpd_pages = 1; |
---|
| 204 | + /* |
---|
| 205 | + * Some devices don't handle VPD pages correctly, so skip vpd |
---|
| 206 | + * pages if not forced by SCSI layer. |
---|
| 207 | + */ |
---|
| 208 | + sdev->skip_vpd_pages = !sdev->try_vpd_pages; |
---|
194 | 209 | |
---|
195 | 210 | /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */ |
---|
196 | 211 | sdev->no_report_opcodes = 1; |
---|
.. | .. |
---|
287 | 302 | } else { |
---|
288 | 303 | |
---|
289 | 304 | /* |
---|
290 | | - * Non-disk-type devices don't need to blacklist any pages |
---|
| 305 | + * Non-disk-type devices don't need to ignore any pages |
---|
291 | 306 | * or to force 192-byte transfer lengths for MODE SENSE. |
---|
292 | 307 | * But they do need to use MODE SENSE(10). |
---|
293 | 308 | */ |
---|
.. | .. |
---|
359 | 374 | |
---|
360 | 375 | /* check for state-transition errors */ |
---|
361 | 376 | if (us->srb != NULL) { |
---|
362 | | - printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n", |
---|
363 | | - __func__, us->srb); |
---|
| 377 | + dev_err(&us->pusb_intf->dev, |
---|
| 378 | + "Error in %s: us->srb = %p\n", __func__, us->srb); |
---|
364 | 379 | return SCSI_MLQUEUE_HOST_BUSY; |
---|
365 | 380 | } |
---|
366 | 381 | |
---|
.. | .. |
---|
396 | 411 | ***********************************************************************/ |
---|
397 | 412 | |
---|
398 | 413 | /* Command timeout and abort */ |
---|
399 | | -static int command_abort(struct scsi_cmnd *srb) |
---|
| 414 | +static int command_abort_matching(struct us_data *us, struct scsi_cmnd *srb_match) |
---|
400 | 415 | { |
---|
401 | | - struct us_data *us = host_to_us(srb->device->host); |
---|
402 | | - |
---|
403 | | - usb_stor_dbg(us, "%s called\n", __func__); |
---|
404 | | - |
---|
405 | 416 | /* |
---|
406 | 417 | * us->srb together with the TIMED_OUT, RESETTING, and ABORTING |
---|
407 | 418 | * bits are protected by the host lock. |
---|
408 | 419 | */ |
---|
409 | 420 | scsi_lock(us_to_host(us)); |
---|
410 | 421 | |
---|
411 | | - /* Is this command still active? */ |
---|
412 | | - if (us->srb != srb) { |
---|
| 422 | + /* is there any active pending command to abort ? */ |
---|
| 423 | + if (!us->srb) { |
---|
413 | 424 | scsi_unlock(us_to_host(us)); |
---|
414 | 425 | usb_stor_dbg(us, "-- nothing to abort\n"); |
---|
| 426 | + return SUCCESS; |
---|
| 427 | + } |
---|
| 428 | + |
---|
| 429 | + /* Does the command match the passed srb if any ? */ |
---|
| 430 | + if (srb_match && us->srb != srb_match) { |
---|
| 431 | + scsi_unlock(us_to_host(us)); |
---|
| 432 | + usb_stor_dbg(us, "-- pending command mismatch\n"); |
---|
415 | 433 | return FAILED; |
---|
416 | 434 | } |
---|
417 | 435 | |
---|
.. | .. |
---|
434 | 452 | return SUCCESS; |
---|
435 | 453 | } |
---|
436 | 454 | |
---|
| 455 | +static int command_abort(struct scsi_cmnd *srb) |
---|
| 456 | +{ |
---|
| 457 | + struct us_data *us = host_to_us(srb->device->host); |
---|
| 458 | + |
---|
| 459 | + usb_stor_dbg(us, "%s called\n", __func__); |
---|
| 460 | + return command_abort_matching(us, srb); |
---|
| 461 | +} |
---|
| 462 | + |
---|
437 | 463 | /* |
---|
438 | 464 | * This invokes the transport reset mechanism to reset the state of the |
---|
439 | 465 | * device |
---|
.. | .. |
---|
444 | 470 | int result; |
---|
445 | 471 | |
---|
446 | 472 | usb_stor_dbg(us, "%s called\n", __func__); |
---|
| 473 | + |
---|
| 474 | + /* abort any pending command before reset */ |
---|
| 475 | + command_abort_matching(us, NULL); |
---|
447 | 476 | |
---|
448 | 477 | /* lock the device pointers and do the reset */ |
---|
449 | 478 | mutex_lock(&(us->dev_mutex)); |
---|
.. | .. |
---|
634 | 663 | * and 2048 for USB3 devices. |
---|
635 | 664 | */ |
---|
636 | 665 | .max_sectors = 240, |
---|
637 | | - |
---|
638 | | - /* |
---|
639 | | - * merge commands... this seems to help performance, but |
---|
640 | | - * periodically someone should test to see which setting is more |
---|
641 | | - * optimal. |
---|
642 | | - */ |
---|
643 | | - .use_clustering = 1, |
---|
644 | 666 | |
---|
645 | 667 | /* emulated HBA */ |
---|
646 | 668 | .emulated = 1, |
---|