Skip to content

Commit b7eefcf

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: core: Add a device_configure method to the host template
This is a version of ->slave_configure that also takes a queue_limits structure that the caller applies, and thus allows drivers to reconfigure the queue using the atomic queue limits API. In the long run it should also replace ->slave_configure entirely as there is no need to have two different methods here, and the slave name in addition to being politically charged also has no basis in the SCSI standards or the kernel code. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20240409143748.980206-11-hch@lst.de Reviewed-by: Bart Van Assche <bvanassche@acm.org> 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 693a1e8 commit b7eefcf

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

drivers/scsi/scsi_scan.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
227227

228228
/*
229229
* realloc if new shift is calculated, which is caused by setting
230-
* up one new default queue depth after calling ->slave_configure
230+
* up one new default queue depth after calling ->device_configure
231231
*/
232232
if (!need_alloc && new_shift != sdev->budget_map.shift)
233233
need_alloc = need_free = true;
@@ -874,6 +874,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
874874
static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
875875
blist_flags_t *bflags, int async)
876876
{
877+
const struct scsi_host_template *hostt = sdev->host->hostt;
877878
struct queue_limits lim;
878879
int ret;
879880

@@ -1073,33 +1074,37 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
10731074
lim.max_hw_sectors = 512;
10741075
else if (*bflags & BLIST_MAX_1024)
10751076
lim.max_hw_sectors = 1024;
1077+
1078+
if (hostt->device_configure)
1079+
ret = hostt->device_configure(sdev, &lim);
1080+
else if (hostt->slave_configure)
1081+
ret = hostt->slave_configure(sdev);
1082+
if (ret) {
1083+
queue_limits_cancel_update(sdev->request_queue);
1084+
/*
1085+
* If the LLDD reports device not present, don't clutter the
1086+
* console with failure messages.
1087+
*/
1088+
if (ret != -ENXIO)
1089+
sdev_printk(KERN_ERR, sdev,
1090+
"failed to configure device\n");
1091+
return SCSI_SCAN_NO_RESPONSE;
1092+
}
1093+
10761094
ret = queue_limits_commit_update(sdev->request_queue, &lim);
10771095
if (ret) {
10781096
sdev_printk(KERN_ERR, sdev, "failed to apply queue limits.\n");
10791097
return SCSI_SCAN_NO_RESPONSE;
10801098
}
10811099

1082-
if (sdev->host->hostt->slave_configure) {
1083-
ret = sdev->host->hostt->slave_configure(sdev);
1084-
if (ret) {
1085-
/*
1086-
* if LLDD reports slave not present, don't clutter
1087-
* console with alloc failure messages
1088-
*/
1089-
if (ret != -ENXIO) {
1090-
sdev_printk(KERN_ERR, sdev,
1091-
"failed to configure device\n");
1092-
}
1093-
return SCSI_SCAN_NO_RESPONSE;
1094-
}
1095-
1096-
/*
1097-
* The queue_depth is often changed in ->slave_configure.
1098-
* Set up budget map again since memory consumption of
1099-
* the map depends on actual queue depth.
1100-
*/
1100+
/*
1101+
* The queue_depth is often changed in ->device_configure.
1102+
*
1103+
* Set up budget map again since memory consumption of the map depends
1104+
* on actual queue depth.
1105+
*/
1106+
if (hostt->device_configure || hostt->slave_configure)
11011107
scsi_realloc_sdev_budget_map(sdev, sdev->queue_depth);
1102-
}
11031108

11041109
if (sdev->scsi_level >= SCSI_3)
11051110
scsi_attach_vpd(sdev);

include/scsi/scsi_host.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ struct scsi_host_template {
211211
* up after yourself before returning non-0
212212
*
213213
* Status: OPTIONAL
214+
*
215+
* Note: slave_configure is the legacy version, use device_configure for
216+
* all new code. A driver must never define both.
214217
*/
218+
int (* device_configure)(struct scsi_device *, struct queue_limits *lim);
215219
int (* slave_configure)(struct scsi_device *);
216220

217221
/*

0 commit comments

Comments
 (0)