[PATCH RFC 6/6] ata: libata-scsi: Allocate sdev early in port probe
From: John Garry
Date: Tue Sep 20 2022 - 06:36:49 EST
Currently the per-ata device sdev is allocated as part of the scsi target
scan, which is after the ata port probe.
However it is useful to have the sdev available in the port probe. As an
example of an advantage, if the request queue is available in the probe
(which it would be if the sdev is available), then it is possible to use
a SCSI cmnd for ATA internal commands. The benefit of this is then we can
put the ATA qc structure in the SCSI cmnd private data. It will also be
useful if we want to send ATA internal commands as requests.
Signed-off-by: John Garry <john.garry@xxxxxxxxxx>
---
drivers/ata/libata-eh.c | 4 ++++
drivers/ata/libata-scsi.c | 20 ++++++--------------
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 7c128c89b454..35375873a464 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -2971,6 +2971,10 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
*/
dev->class = ehc->classes[dev->devno];
+ rc = ata_scsi_setup_sdev(dev);
+ if (rc)
+ goto err;
+
if (dev->class == ATA_DEV_PMP)
rc = sata_pmp_attach(dev);
else
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 88f39ab10a92..0e26860a82e2 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1111,7 +1111,9 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev)
if (dev->flags & ATA_DFLAG_TRUSTED)
sdev->security_supported = 1;
- dev->sdev = sdev;
+ /* Put extra reference which we get when allocating the starget initially */
+ scsi_target_reap(scsi_target(sdev));
+
return 0;
}
@@ -4279,6 +4281,7 @@ int ata_scsi_setup_sdev(struct ata_device *dev)
if (!sdev)
return -ENODEV;
dev->sdev = sdev;
+ ata_scsi_assign_ofnode(dev, ap);
return 0;
}
@@ -4292,26 +4295,15 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
repeat:
ata_for_each_link(link, ap, EDGE) {
ata_for_each_dev(dev, link, ENABLED) {
- struct scsi_device *sdev;
+ struct Scsi_Host *shost = ap->scsi_host;
int channel = 0, id = 0;
- if (dev->sdev)
- continue;
-
if (ata_is_host_link(link))
id = dev->devno;
else
channel = link->pmp;
- sdev = __scsi_add_device(ap->scsi_host, channel, id, 0,
- NULL);
- if (!IS_ERR(sdev)) {
- dev->sdev = sdev;
- ata_scsi_assign_ofnode(dev, ap);
- scsi_device_put(sdev);
- } else {
- dev->sdev = NULL;
- }
+ scsi_scan_target(&shost->shost_gendev, channel, id, 0, SCSI_SCAN_INITIAL);
}
}
--
2.35.3