Commit afd53a3d authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen

scsi: core: Initialize scsi midlayer limits before allocating the queue

Turn __scsi_init_queue() into scsi_init_limits() which initializes
queue_limits structure that can be passed to blk_mq_alloc_queue().
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240409143748.980206-5-hch@lst.deReviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 9042fb6d
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <scsi/scsi_driver.h> #include <scsi/scsi_driver.h>
#include <scsi/scsi_eh.h> #include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h> #include <scsi/scsi_host.h>
#include <scsi/scsi_transport.h> /* __scsi_init_queue() */ #include <scsi/scsi_transport.h> /* scsi_init_limits() */
#include <scsi/scsi_dh.h> #include <scsi/scsi_dh.h>
#include <trace/events/scsi.h> #include <trace/events/scsi.h>
...@@ -1965,31 +1965,26 @@ static void scsi_map_queues(struct blk_mq_tag_set *set) ...@@ -1965,31 +1965,26 @@ static void scsi_map_queues(struct blk_mq_tag_set *set)
blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
} }
void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim)
{ {
struct device *dev = shost->dma_dev; struct device *dev = shost->dma_dev;
/* memset(lim, 0, sizeof(*lim));
* this limit is imposed by hardware restrictions lim->max_segments =
*/ min_t(unsigned short, shost->sg_tablesize, SG_MAX_SEGMENTS);
blk_queue_max_segments(q, min_t(unsigned short, shost->sg_tablesize,
SG_MAX_SEGMENTS));
if (scsi_host_prot_dma(shost)) { if (scsi_host_prot_dma(shost)) {
shost->sg_prot_tablesize = shost->sg_prot_tablesize =
min_not_zero(shost->sg_prot_tablesize, min_not_zero(shost->sg_prot_tablesize,
(unsigned short)SCSI_MAX_PROT_SG_SEGMENTS); (unsigned short)SCSI_MAX_PROT_SG_SEGMENTS);
BUG_ON(shost->sg_prot_tablesize < shost->sg_tablesize); BUG_ON(shost->sg_prot_tablesize < shost->sg_tablesize);
blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); lim->max_integrity_segments = shost->sg_prot_tablesize;
} }
blk_queue_max_hw_sectors(q, shost->max_sectors); lim->max_hw_sectors = shost->max_sectors;
blk_queue_segment_boundary(q, shost->dma_boundary); lim->seg_boundary_mask = shost->dma_boundary;
dma_set_seg_boundary(dev, shost->dma_boundary); lim->max_segment_size = shost->max_segment_size;
lim->virt_boundary_mask = shost->virt_boundary_mask;
blk_queue_max_segment_size(q, shost->max_segment_size);
blk_queue_virt_boundary(q, shost->virt_boundary_mask);
dma_set_max_seg_size(dev, queue_max_segment_size(q));
/* /*
* Set a reasonable default alignment: The larger of 32-byte (dword), * Set a reasonable default alignment: The larger of 32-byte (dword),
...@@ -1998,9 +1993,12 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) ...@@ -1998,9 +1993,12 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
* *
* Devices that require a bigger alignment can increase it later. * Devices that require a bigger alignment can increase it later.
*/ */
blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1); lim->dma_alignment = max(4, dma_get_cache_alignment()) - 1;
dma_set_seg_boundary(dev, shost->dma_boundary);
dma_set_max_seg_size(dev, shost->max_segment_size);
} }
EXPORT_SYMBOL_GPL(__scsi_init_queue); EXPORT_SYMBOL_GPL(scsi_init_limits);
static const struct blk_mq_ops scsi_mq_ops_no_commit = { static const struct blk_mq_ops scsi_mq_ops_no_commit = {
.get_budget = scsi_mq_get_budget, .get_budget = scsi_mq_get_budget,
......
...@@ -283,6 +283,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, ...@@ -283,6 +283,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
struct request_queue *q; struct request_queue *q;
int display_failure_msg = 1, ret; int display_failure_msg = 1, ret;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
struct queue_limits lim;
sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size, sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size,
GFP_KERNEL); GFP_KERNEL);
...@@ -332,7 +333,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, ...@@ -332,7 +333,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
sdev->sg_reserved_size = INT_MAX; sdev->sg_reserved_size = INT_MAX;
q = blk_mq_alloc_queue(&sdev->host->tag_set, NULL, NULL); scsi_init_limits(shost, &lim);
q = blk_mq_alloc_queue(&sdev->host->tag_set, &lim, NULL);
if (IS_ERR(q)) { if (IS_ERR(q)) {
/* release fn is set up in scsi_sysfs_device_initialise, so /* release fn is set up in scsi_sysfs_device_initialise, so
* have to free and put manually here */ * have to free and put manually here */
...@@ -343,7 +345,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, ...@@ -343,7 +345,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
kref_get(&sdev->host->tagset_refcnt); kref_get(&sdev->host->tagset_refcnt);
sdev->request_queue = q; sdev->request_queue = q;
q->queuedata = sdev; q->queuedata = sdev;
__scsi_init_queue(sdev->host, q);
depth = sdev->host->cmd_per_lun ?: 1; depth = sdev->host->cmd_per_lun ?: 1;
......
...@@ -4276,6 +4276,7 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host) ...@@ -4276,6 +4276,7 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
{ {
struct device *dev = &shost->shost_gendev; struct device *dev = &shost->shost_gendev;
struct fc_internal *i = to_fc_internal(shost->transportt); struct fc_internal *i = to_fc_internal(shost->transportt);
struct queue_limits lim;
struct request_queue *q; struct request_queue *q;
char bsg_name[20]; char bsg_name[20];
...@@ -4286,8 +4287,8 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host) ...@@ -4286,8 +4287,8 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
snprintf(bsg_name, sizeof(bsg_name), snprintf(bsg_name, sizeof(bsg_name),
"fc_host%d", shost->host_no); "fc_host%d", shost->host_no);
scsi_init_limits(shost, &lim);
q = bsg_setup_queue(dev, bsg_name, NULL, fc_bsg_dispatch, q = bsg_setup_queue(dev, bsg_name, &lim, fc_bsg_dispatch,
fc_bsg_job_timeout, i->f->dd_bsg_size); fc_bsg_job_timeout, i->f->dd_bsg_size);
if (IS_ERR(q)) { if (IS_ERR(q)) {
dev_err(dev, dev_err(dev,
...@@ -4295,7 +4296,6 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host) ...@@ -4295,7 +4296,6 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
shost->host_no); shost->host_no);
return PTR_ERR(q); return PTR_ERR(q);
} }
__scsi_init_queue(shost, q);
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT); blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
fc_host->rqst_q = q; fc_host->rqst_q = q;
return 0; return 0;
...@@ -4311,6 +4311,7 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport) ...@@ -4311,6 +4311,7 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
{ {
struct device *dev = &rport->dev; struct device *dev = &rport->dev;
struct fc_internal *i = to_fc_internal(shost->transportt); struct fc_internal *i = to_fc_internal(shost->transportt);
struct queue_limits lim;
struct request_queue *q; struct request_queue *q;
rport->rqst_q = NULL; rport->rqst_q = NULL;
...@@ -4318,13 +4319,13 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport) ...@@ -4318,13 +4319,13 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
if (!i->f->bsg_request) if (!i->f->bsg_request)
return -ENOTSUPP; return -ENOTSUPP;
q = bsg_setup_queue(dev, dev_name(dev), NULL, fc_bsg_dispatch_prep, scsi_init_limits(shost, &lim);
q = bsg_setup_queue(dev, dev_name(dev), &lim, fc_bsg_dispatch_prep,
fc_bsg_job_timeout, i->f->dd_bsg_size); fc_bsg_job_timeout, i->f->dd_bsg_size);
if (IS_ERR(q)) { if (IS_ERR(q)) {
dev_err(dev, "failed to setup bsg queue\n"); dev_err(dev, "failed to setup bsg queue\n");
return PTR_ERR(q); return PTR_ERR(q);
} }
__scsi_init_queue(shost, q);
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT); blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
rport->rqst_q = q; rport->rqst_q = q;
return 0; return 0;
......
...@@ -1535,6 +1535,7 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) ...@@ -1535,6 +1535,7 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
{ {
struct device *dev = &shost->shost_gendev; struct device *dev = &shost->shost_gendev;
struct iscsi_internal *i = to_iscsi_internal(shost->transportt); struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
struct queue_limits lim;
struct request_queue *q; struct request_queue *q;
char bsg_name[20]; char bsg_name[20];
...@@ -1542,14 +1543,14 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) ...@@ -1542,14 +1543,14 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
return -ENOTSUPP; return -ENOTSUPP;
snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no); snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
q = bsg_setup_queue(dev, bsg_name, NULL, iscsi_bsg_host_dispatch, NULL, scsi_init_limits(shost, &lim);
q = bsg_setup_queue(dev, bsg_name, &lim, iscsi_bsg_host_dispatch, NULL,
0); 0);
if (IS_ERR(q)) { if (IS_ERR(q)) {
shost_printk(KERN_ERR, shost, "bsg interface failed to " shost_printk(KERN_ERR, shost, "bsg interface failed to "
"initialize - no request queue\n"); "initialize - no request queue\n");
return PTR_ERR(q); return PTR_ERR(q);
} }
__scsi_init_queue(shost, q);
ihost->bsg_q = q; ihost->bsg_q = q;
return 0; return 0;
......
...@@ -83,6 +83,6 @@ scsi_transport_device_data(struct scsi_device *sdev) ...@@ -83,6 +83,6 @@ scsi_transport_device_data(struct scsi_device *sdev)
+ shost->transportt->device_private_offset; + shost->transportt->device_private_offset;
} }
void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q); void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim);
#endif /* SCSI_TRANSPORT_H */ #endif /* SCSI_TRANSPORT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment