diff mbox series

[v3,1/2] usb-storage: fix sdev->host->dma_dev

Message ID 20200903075639.31138-1-tom.ty89@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v3,1/2] usb-storage: fix sdev->host->dma_dev | expand

Commit Message

Tom Yan Sept. 3, 2020, 7:56 a.m. UTC
Use scsi_add_host_with_dma() instead of scsi_add_host() in usb.c and uas.c.

When the scsi request queue is initialized/allocated, hw_max_sectors is clamped
to the dma max mapping size. Therefore, the correct device that should be used
for the clamping needs to be set.

The same clamping is still needed in the USB drivers as hw_max_sectors could be
changed there. The original clamping would be invalidated in such cases.

Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
 drivers/usb/storage/scsiglue.c |  2 +-
 drivers/usb/storage/uas.c      | 17 +++++++++++------
 drivers/usb/storage/usb.c      |  5 +++--
 3 files changed, 15 insertions(+), 9 deletions(-)

Comments

Greg KH Sept. 3, 2020, 8:20 a.m. UTC | #1
On Thu, Sep 03, 2020 at 03:56:38PM +0800, Tom Yan wrote:
> Use scsi_add_host_with_dma() instead of scsi_add_host() in usb.c and uas.c.
> 
> When the scsi request queue is initialized/allocated, hw_max_sectors is clamped
> to the dma max mapping size. Therefore, the correct device that should be used
> for the clamping needs to be set.
> 
> The same clamping is still needed in the USB drivers as hw_max_sectors could be
> changed there. The original clamping would be invalidated in such cases.
> 
> Signed-off-by: Tom Yan <tom.ty89@gmail.com>
> ---
>  drivers/usb/storage/scsiglue.c |  2 +-
>  drivers/usb/storage/uas.c      | 17 +++++++++++------
>  drivers/usb/storage/usb.c      |  5 +++--
>  3 files changed, 15 insertions(+), 9 deletions(-)

What changed from the previous version?  Always include that below the
--- line as is documented to do so.

Please fix up and resend.

thanks,

greg k-h
Tom Yan Sept. 3, 2020, 8:28 a.m. UTC | #2
Hmm, actually the older versions were pretty much an entirely
different approach/patch (not involving fixing the dma_dev at all).
Should I just resend without the "v3"?

On Thu, 3 Sep 2020 at 16:19, Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Sep 03, 2020 at 03:56:38PM +0800, Tom Yan wrote:
> > Use scsi_add_host_with_dma() instead of scsi_add_host() in usb.c and uas.c.
> >
> > When the scsi request queue is initialized/allocated, hw_max_sectors is clamped
> > to the dma max mapping size. Therefore, the correct device that should be used
> > for the clamping needs to be set.
> >
> > The same clamping is still needed in the USB drivers as hw_max_sectors could be
> > changed there. The original clamping would be invalidated in such cases.
> >
> > Signed-off-by: Tom Yan <tom.ty89@gmail.com>
> > ---
> >  drivers/usb/storage/scsiglue.c |  2 +-
> >  drivers/usb/storage/uas.c      | 17 +++++++++++------
> >  drivers/usb/storage/usb.c      |  5 +++--
> >  3 files changed, 15 insertions(+), 9 deletions(-)
>
> What changed from the previous version?  Always include that below the
> --- line as is documented to do so.
>
> Please fix up and resend.
>
> thanks,
>
> greg k-h
Greg KH Sept. 3, 2020, 8:34 a.m. UTC | #3
On Thu, Sep 03, 2020 at 04:28:53PM +0800, Tom Yan wrote:
> Hmm, actually the older versions were pretty much an entirely
> different approach/patch (not involving fixing the dma_dev at all).
> Should I just resend without the "v3"?

As you already sent a v3 patch series, the next one would be v4, right?
:)

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index e5a971b83e3f..560efd1479ba 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -92,7 +92,7 @@  static int slave_alloc (struct scsi_device *sdev)
 static int slave_configure(struct scsi_device *sdev)
 {
 	struct us_data *us = host_to_us(sdev->host);
-	struct device *dev = us->pusb_dev->bus->sysdev;
+	struct device *dev = sdev->host->dma_dev;
 
 	/*
 	 * Many devices have trouble transferring more than 32KB at a time,
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 08f9296431e9..f4beeb8a8adb 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -827,17 +827,22 @@  static int uas_slave_alloc(struct scsi_device *sdev)
 	 */
 	blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
 
-	if (devinfo->flags & US_FL_MAX_SECTORS_64)
-		blk_queue_max_hw_sectors(sdev->request_queue, 64);
-	else if (devinfo->flags & US_FL_MAX_SECTORS_240)
-		blk_queue_max_hw_sectors(sdev->request_queue, 240);
-
 	return 0;
 }
 
 static int uas_slave_configure(struct scsi_device *sdev)
 {
 	struct uas_dev_info *devinfo = sdev->hostdata;
+	struct device *dev = sdev->host->dma_dev;
+
+	if (devinfo->flags & US_FL_MAX_SECTORS_64)
+		blk_queue_max_hw_sectors(sdev->request_queue, 64);
+	else if (devinfo->flags & US_FL_MAX_SECTORS_240)
+		blk_queue_max_hw_sectors(sdev->request_queue, 240);
+
+	blk_queue_max_hw_sectors(sdev->request_queue,
+		min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
+		      dma_max_mapping_size(dev) >> SECTOR_SHIFT));
 
 	if (devinfo->flags & US_FL_NO_REPORT_OPCODES)
 		sdev->no_report_opcodes = 1;
@@ -1023,7 +1028,7 @@  static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	shost->can_queue = devinfo->qdepth - 2;
 
 	usb_set_intfdata(intf, shost);
-	result = scsi_add_host(shost, &intf->dev);
+	result = scsi_add_host_with_dma(shost, &intf->dev, udev->bus->sysdev);
 	if (result)
 		goto free_streams;
 
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 94a64729dc27..c2ef367cf257 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -1049,8 +1049,9 @@  int usb_stor_probe2(struct us_data *us)
 		goto BadDevice;
 	usb_autopm_get_interface_no_resume(us->pusb_intf);
 	snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
-					dev_name(&us->pusb_intf->dev));
-	result = scsi_add_host(us_to_host(us), dev);
+					dev_name(dev));
+	result = scsi_add_host_with_dma(us_to_host(us), dev,
+					us->pusb_dev->bus->sysdev);
 	if (result) {
 		dev_warn(dev,
 				"Unable to add the scsi host\n");