forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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
....@@ -634,13 +649,6 @@
634649 * and 2048 for USB3 devices.
635650 */
636651 .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,
644652
645653 /* emulated HBA */
646654 .emulated = 1,