Skip to content

Commit 17a9739

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: ufs: core: Introduce ufshcd_add_scsi_host()
Move the code for adding a SCSI host and also the code for managing TMF tags from ufshcd_init() into a new function called ufshcd_add_scsi_host(). This patch prepares for combining the two scsi_add_host() calls into a single call. No functionality has been changed. Reviewed-by: Avri Altman <avri.altman@wdc.com> Reviewed-by: Bean Huo <beanhuo@micron.com> Reviewed-by: Bao D. Nguyen <quic_nguyenb@quicinc.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20241016201249.2256266-2-bvanassche@acm.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 2a330f1 commit 17a9739

1 file changed

Lines changed: 59 additions & 37 deletions

File tree

drivers/ufs/core/ufshcd.c

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10333,6 +10333,62 @@ static const struct blk_mq_ops ufshcd_tmf_ops = {
1033310333
.queue_rq = ufshcd_queue_tmf,
1033410334
};
1033510335

10336+
static int ufshcd_add_scsi_host(struct ufs_hba *hba)
10337+
{
10338+
int err;
10339+
10340+
if (!is_mcq_supported(hba)) {
10341+
if (!hba->lsdb_sup) {
10342+
dev_err(hba->dev,
10343+
"%s: failed to initialize (legacy doorbell mode not supported)\n",
10344+
__func__);
10345+
return -EINVAL;
10346+
}
10347+
err = scsi_add_host(hba->host, hba->dev);
10348+
if (err) {
10349+
dev_err(hba->dev, "scsi_add_host failed\n");
10350+
return err;
10351+
}
10352+
hba->scsi_host_added = true;
10353+
}
10354+
10355+
hba->tmf_tag_set = (struct blk_mq_tag_set) {
10356+
.nr_hw_queues = 1,
10357+
.queue_depth = hba->nutmrs,
10358+
.ops = &ufshcd_tmf_ops,
10359+
.flags = BLK_MQ_F_NO_SCHED,
10360+
};
10361+
err = blk_mq_alloc_tag_set(&hba->tmf_tag_set);
10362+
if (err < 0)
10363+
goto remove_scsi_host;
10364+
hba->tmf_queue = blk_mq_alloc_queue(&hba->tmf_tag_set, NULL, NULL);
10365+
if (IS_ERR(hba->tmf_queue)) {
10366+
err = PTR_ERR(hba->tmf_queue);
10367+
goto free_tmf_tag_set;
10368+
}
10369+
hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs,
10370+
sizeof(*hba->tmf_rqs), GFP_KERNEL);
10371+
if (!hba->tmf_rqs) {
10372+
err = -ENOMEM;
10373+
goto free_tmf_queue;
10374+
}
10375+
10376+
return 0;
10377+
10378+
free_tmf_queue:
10379+
blk_mq_destroy_queue(hba->tmf_queue);
10380+
blk_put_queue(hba->tmf_queue);
10381+
10382+
free_tmf_tag_set:
10383+
blk_mq_free_tag_set(&hba->tmf_tag_set);
10384+
10385+
remove_scsi_host:
10386+
if (hba->scsi_host_added)
10387+
scsi_remove_host(hba->host);
10388+
10389+
return err;
10390+
}
10391+
1033610392
/**
1033710393
* ufshcd_init - Driver initialization routine
1033810394
* @hba: per-adapter instance
@@ -10464,41 +10520,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1046410520
hba->is_irq_enabled = true;
1046510521
}
1046610522

10467-
if (!is_mcq_supported(hba)) {
10468-
if (!hba->lsdb_sup) {
10469-
dev_err(hba->dev, "%s: failed to initialize (legacy doorbell mode not supported)\n",
10470-
__func__);
10471-
err = -EINVAL;
10472-
goto out_disable;
10473-
}
10474-
err = scsi_add_host(host, hba->dev);
10475-
if (err) {
10476-
dev_err(hba->dev, "scsi_add_host failed\n");
10477-
goto out_disable;
10478-
}
10479-
hba->scsi_host_added = true;
10480-
}
10481-
10482-
hba->tmf_tag_set = (struct blk_mq_tag_set) {
10483-
.nr_hw_queues = 1,
10484-
.queue_depth = hba->nutmrs,
10485-
.ops = &ufshcd_tmf_ops,
10486-
.flags = BLK_MQ_F_NO_SCHED,
10487-
};
10488-
err = blk_mq_alloc_tag_set(&hba->tmf_tag_set);
10489-
if (err < 0)
10490-
goto out_remove_scsi_host;
10491-
hba->tmf_queue = blk_mq_alloc_queue(&hba->tmf_tag_set, NULL, NULL);
10492-
if (IS_ERR(hba->tmf_queue)) {
10493-
err = PTR_ERR(hba->tmf_queue);
10494-
goto free_tmf_tag_set;
10495-
}
10496-
hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs,
10497-
sizeof(*hba->tmf_rqs), GFP_KERNEL);
10498-
if (!hba->tmf_rqs) {
10499-
err = -ENOMEM;
10500-
goto free_tmf_queue;
10501-
}
10523+
err = ufshcd_add_scsi_host(hba);
10524+
if (err)
10525+
goto out_disable;
1050210526

1050310527
/* Reset the attached device */
1050410528
ufshcd_device_reset(hba);
@@ -10556,9 +10580,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1055610580
free_tmf_queue:
1055710581
blk_mq_destroy_queue(hba->tmf_queue);
1055810582
blk_put_queue(hba->tmf_queue);
10559-
free_tmf_tag_set:
1056010583
blk_mq_free_tag_set(&hba->tmf_tag_set);
10561-
out_remove_scsi_host:
1056210584
if (hba->scsi_host_added)
1056310585
scsi_remove_host(hba->host);
1056410586
out_disable:

0 commit comments

Comments
 (0)