Skip to content

Commit 70a7949

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: usb-storage: Switch to using ->device_configure
Switch to the ->device_configure method instead of ->slave_configure and update the block limits on the passed in queue_limits instead of using the per-limit accessors. Also use the proper atomic queue limit update helpers and freeze the queue when updating max_hw_sectors from sysfs. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20240409143748.980206-18-hch@lst.de Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9ca2dc2 commit 70a7949

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

drivers/usb/storage/scsiglue.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int slave_alloc (struct scsi_device *sdev)
8282
return 0;
8383
}
8484

85-
static int slave_configure(struct scsi_device *sdev)
85+
static int device_configure(struct scsi_device *sdev, struct queue_limits *lim)
8686
{
8787
struct us_data *us = host_to_us(sdev->host);
8888
struct device *dev = us->pusb_dev->bus->sysdev;
@@ -97,31 +97,28 @@ static int slave_configure(struct scsi_device *sdev)
9797

9898
if (us->fflags & US_FL_MAX_SECTORS_MIN)
9999
max_sectors = PAGE_SIZE >> 9;
100-
if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
101-
blk_queue_max_hw_sectors(sdev->request_queue,
102-
max_sectors);
100+
lim->max_hw_sectors = min(lim->max_hw_sectors, max_sectors);
103101
} else if (sdev->type == TYPE_TAPE) {
104102
/*
105103
* Tapes need much higher max_sector limits, so just
106104
* raise it to the maximum possible (4 GB / 512) and
107105
* let the queue segment size sort out the real limit.
108106
*/
109-
blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
107+
lim->max_hw_sectors = 0x7FFFFF;
110108
} else if (us->pusb_dev->speed >= USB_SPEED_SUPER) {
111109
/*
112110
* USB3 devices will be limited to 2048 sectors. This gives us
113111
* better throughput on most devices.
114112
*/
115-
blk_queue_max_hw_sectors(sdev->request_queue, 2048);
113+
lim->max_hw_sectors = 2048;
116114
}
117115

118116
/*
119117
* The max_hw_sectors should be up to maximum size of a mapping for
120118
* the device. Otherwise, a DMA API might fail on swiotlb environment.
121119
*/
122-
blk_queue_max_hw_sectors(sdev->request_queue,
123-
min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
124-
dma_max_mapping_size(dev) >> SECTOR_SHIFT));
120+
lim->max_hw_sectors = min_t(size_t,
121+
lim->max_hw_sectors, dma_max_mapping_size(dev) >> SECTOR_SHIFT);
125122

126123
/*
127124
* We can't put these settings in slave_alloc() because that gets
@@ -582,13 +579,22 @@ static ssize_t max_sectors_store(struct device *dev, struct device_attribute *at
582579
size_t count)
583580
{
584581
struct scsi_device *sdev = to_scsi_device(dev);
582+
struct queue_limits lim;
585583
unsigned short ms;
584+
int ret;
586585

587-
if (sscanf(buf, "%hu", &ms) > 0) {
588-
blk_queue_max_hw_sectors(sdev->request_queue, ms);
589-
return count;
590-
}
591-
return -EINVAL;
586+
if (sscanf(buf, "%hu", &ms) <= 0)
587+
return -EINVAL;
588+
589+
blk_mq_freeze_queue(sdev->request_queue);
590+
lim = queue_limits_start_update(sdev->request_queue);
591+
lim.max_hw_sectors = ms;
592+
ret = queue_limits_commit_update(sdev->request_queue, &lim);
593+
blk_mq_unfreeze_queue(sdev->request_queue);
594+
595+
if (ret)
596+
return ret;
597+
return count;
592598
}
593599
static DEVICE_ATTR_RW(max_sectors);
594600

@@ -626,7 +632,7 @@ static const struct scsi_host_template usb_stor_host_template = {
626632
.this_id = -1,
627633

628634
.slave_alloc = slave_alloc,
629-
.slave_configure = slave_configure,
635+
.device_configure = device_configure,
630636
.target_alloc = target_alloc,
631637

632638
/* lots of sg segments can be handled */

0 commit comments

Comments
 (0)