forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/usb/storage/scsiglue.c
....@@ -28,6 +28,8 @@
2828 * status of a command.
2929 */
3030
31
+#include <linux/blkdev.h>
32
+#include <linux/dma-mapping.h>
3133 #include <linux/module.h>
3234 #include <linux/mutex.h>
3335
....@@ -38,6 +40,7 @@
3840 #include <scsi/scsi_eh.h>
3941
4042 #include "usb.h"
43
+#include <linux/usb/hcd.h>
4144 #include "scsiglue.h"
4245 #include "debug.h"
4346 #include "transport.h"
....@@ -89,6 +92,7 @@
8992 static int slave_configure(struct scsi_device *sdev)
9093 {
9194 struct us_data *us = host_to_us(sdev->host);
95
+ struct device *dev = us->pusb_dev->bus->sysdev;
9296
9397 /*
9498 * Many devices have trouble transferring more than 32KB at a time,
....@@ -123,12 +127,20 @@
123127 }
124128
125129 /*
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
+ /*
126138 * 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
129140 * up bounce buffers in addressable memory.
130141 */
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))
132144 blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH);
133145
134146 /*
....@@ -189,8 +201,11 @@
189201 */
190202 sdev->skip_ms_page_8 = 1;
191203
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;
194209
195210 /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */
196211 sdev->no_report_opcodes = 1;
....@@ -287,7 +302,7 @@
287302 } else {
288303
289304 /*
290
- * Non-disk-type devices don't need to blacklist any pages
305
+ * Non-disk-type devices don't need to ignore any pages
291306 * or to force 192-byte transfer lengths for MODE SENSE.
292307 * But they do need to use MODE SENSE(10).
293308 */
....@@ -359,8 +374,8 @@
359374
360375 /* check for state-transition errors */
361376 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);
364379 return SCSI_MLQUEUE_HOST_BUSY;
365380 }
366381
....@@ -396,22 +411,25 @@
396411 ***********************************************************************/
397412
398413 /* 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)
400415 {
401
- struct us_data *us = host_to_us(srb->device->host);
402
-
403
- usb_stor_dbg(us, "%s called\n", __func__);
404
-
405416 /*
406417 * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
407418 * bits are protected by the host lock.
408419 */
409420 scsi_lock(us_to_host(us));
410421
411
- /* Is this command still active? */
412
- if (us->srb != srb) {
422
+ /* is there any active pending command to abort ? */
423
+ if (!us->srb) {
413424 scsi_unlock(us_to_host(us));
414425 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");
415433 return FAILED;
416434 }
417435
....@@ -434,6 +452,14 @@
434452 return SUCCESS;
435453 }
436454
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
+
437463 /*
438464 * This invokes the transport reset mechanism to reset the state of the
439465 * device
....@@ -444,6 +470,9 @@
444470 int result;
445471
446472 usb_stor_dbg(us, "%s called\n", __func__);
473
+
474
+ /* abort any pending command before reset */
475
+ command_abort_matching(us, NULL);
447476
448477 /* lock the device pointers and do the reset */
449478 mutex_lock(&(us->dev_mutex));
....@@ -634,13 +663,6 @@
634663 * and 2048 for USB3 devices.
635664 */
636665 .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,
644666
645667 /* emulated HBA */
646668 .emulated = 1,