2022-09-20 10:45:47

by John Garry

[permalink] [raw]
Subject: [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe

Currently for libata the SCSI device (sdev) associated with an ata_device
is allocated when the port probe has completed.

It's useful to have the SCSI device and its associated request queue
available earlier for the port probe. Specifically if we have the
request queue available, then we can:
- Easily put ATA qc in SCSI cmnd priv data
- Send ATA internal commands on SCSI device request queue for [0]. The
current solution there is to use the shost sdev request queue, which
isn't great.

This series changes the ata port probe to alloc the sdev in the
ata_device revalidation, and then just do a SCSI starget scan afterwards.

Why an RFC?
1. IPR driver needs to be fixed up - it does not use ATA EH port probe
Mail [1] needs following up
2. SATA PMP support needs verification, but I don't have a setup
3. This series needs to be merged into or go after [0]

Patch 1/6 could be merged now.

[0] https://lore.kernel.org/linux-ide/[email protected]/
[1] https://lore.kernel.org/linux-ide/[email protected]/

Any comments welcome - please have a look.

Based on v6.0-rc4 and tested for QEMU AHCI and libsas.

John Garry (6):
scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device()
scsi: scsi_transport_sas: Allocate end device target id in the rphy
alloc
scsi: core: Add scsi_get_dev()
ata: libata-scsi: Add ata_scsi_setup_sdev()
scsi: libsas: Add sas_ata_setup_device()
ata: libata-scsi: Allocate sdev early in port probe

drivers/ata/libata-eh.c | 4 +++
drivers/ata/libata-scsi.c | 45 +++++++++++++++++++++----------
drivers/ata/libata.h | 1 +
drivers/scsi/libsas/sas_ata.c | 20 ++++++++++++++
drivers/scsi/scsi_scan.c | 28 ++++++++++++++++++-
drivers/scsi/scsi_transport_sas.c | 25 +++++++++++------
include/linux/libata.h | 2 ++
include/scsi/scsi_host.h | 3 +++
8 files changed, 105 insertions(+), 23 deletions(-)

--
2.35.3


2022-09-20 10:58:44

by John Garry

[permalink] [raw]
Subject: [PATCH 1/6] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device()

Instead of using hardcoded '1' as the __scsi_add_device() ->
scsi_probe_and_add_lun() rescan arg, use proper macro SCSI_SCAN_RESCAN.

Signed-off-by: John Garry <[email protected]>
---
drivers/scsi/scsi_scan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index ac6059702d13..3759b1a77504 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1588,7 +1588,8 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
scsi_complete_async_scans();

if (scsi_host_scan_allowed(shost) && scsi_autopm_get_host(shost) == 0) {
- scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
+ scsi_probe_and_add_lun(starget, lun, NULL, &sdev,
+ SCSI_SCAN_RESCAN, hostdata);
scsi_autopm_put_host(shost);
}
mutex_unlock(&shost->scan_mutex);
--
2.35.3

2022-09-20 11:01:04

by John Garry

[permalink] [raw]
Subject: [PATCH RFC 6/6] ata: libata-scsi: Allocate sdev early in port probe

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 <[email protected]>
---
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

2022-09-20 22:30:49

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH 1/6] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device()

On 9/20/22 19:27, John Garry wrote:
> Instead of using hardcoded '1' as the __scsi_add_device() ->
> scsi_probe_and_add_lun() rescan arg, use proper macro SCSI_SCAN_RESCAN.
>
> Signed-off-by: John Garry <[email protected]>
> ---
> drivers/scsi/scsi_scan.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
> index ac6059702d13..3759b1a77504 100644
> --- a/drivers/scsi/scsi_scan.c
> +++ b/drivers/scsi/scsi_scan.c
> @@ -1588,7 +1588,8 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
> scsi_complete_async_scans();
>
> if (scsi_host_scan_allowed(shost) && scsi_autopm_get_host(shost) == 0) {
> - scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
> + scsi_probe_and_add_lun(starget, lun, NULL, &sdev,
> + SCSI_SCAN_RESCAN, hostdata);
> scsi_autopm_put_host(shost);
> }
> mutex_unlock(&shost->scan_mutex);

Looks good.

Reviewed-by: Damien Le Moal <[email protected]>

--
Damien Le Moal
Western Digital Research

2022-09-21 04:38:51

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe

On 9/20/22 19:27, John Garry wrote:
> Currently for libata the SCSI device (sdev) associated with an ata_device
> is allocated when the port probe has completed.
>
> It's useful to have the SCSI device and its associated request queue
> available earlier for the port probe. Specifically if we have the
> request queue available, then we can:
> - Easily put ATA qc in SCSI cmnd priv data
> - Send ATA internal commands on SCSI device request queue for [0]. The
> current solution there is to use the shost sdev request queue, which
> isn't great.
>
> This series changes the ata port probe to alloc the sdev in the
> ata_device revalidation, and then just do a SCSI starget scan afterwards.
>
> Why an RFC?
> 1. IPR driver needs to be fixed up - it does not use ATA EH port probe
> Mail [1] needs following up

Yes. If IPR could be converted to ata error_handler, a lot of code can
be simplified in libata too.

> 2. SATA PMP support needs verification, but I don't have a setup

Port multiplier behind a sas HBA will be challenging to setup :)
I can try, but I will need to open up one of my servers and hook a small
PMP box to one of the pm8001 plugs. I may have the cables for that...
Let me check.

> 3. This series needs to be merged into or go after [0]
>
> Patch 1/6 could be merged now.
>
> [0] https://lore.kernel.org/linux-ide/[email protected]/
> [1] https://lore.kernel.org/linux-ide/[email protected]/
>
> Any comments welcome - please have a look.
>
> Based on v6.0-rc4 and tested for QEMU AHCI and libsas.
>
> John Garry (6):
> scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device()
> scsi: scsi_transport_sas: Allocate end device target id in the rphy
> alloc
> scsi: core: Add scsi_get_dev()
> ata: libata-scsi: Add ata_scsi_setup_sdev()
> scsi: libsas: Add sas_ata_setup_device()
> ata: libata-scsi: Allocate sdev early in port probe
>
> drivers/ata/libata-eh.c | 4 +++
> drivers/ata/libata-scsi.c | 45 +++++++++++++++++++++----------
> drivers/ata/libata.h | 1 +
> drivers/scsi/libsas/sas_ata.c | 20 ++++++++++++++
> drivers/scsi/scsi_scan.c | 28 ++++++++++++++++++-
> drivers/scsi/scsi_transport_sas.c | 25 +++++++++++------
> include/linux/libata.h | 2 ++
> include/scsi/scsi_host.h | 3 +++
> 8 files changed, 105 insertions(+), 23 deletions(-)
>

--
Damien Le Moal
Western Digital Research

2022-09-21 08:43:51

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe

On 9/21/22 17:24, John Garry wrote:
> On 21/09/2022 05:04, Damien Le Moal wrote:
>> On 9/20/22 19:27, John Garry wrote:
>>> Currently for libata the SCSI device (sdev) associated with an
>>> ata_device
>>> is allocated when the port probe has completed.
>>>
>>> It's useful to have the SCSI device and its associated request queue
>>> available earlier for the port probe. Specifically if we have the
>>> request queue available, then we can:
>>> - Easily put ATA qc in SCSI cmnd priv data
>>> - Send ATA internal commands on SCSI device request queue for [0]. The
>>>    current solution there is to use the shost sdev request queue, which
>>>    isn't great.
>>> This series changes the ata port probe to alloc the sdev in the
>>> ata_device revalidation, and then just do a SCSI starget scan
>>> afterwards.
>>>
>>> Why an RFC?
>>> 1. IPR  driver needs to be fixed up - it does not use ATA EH port probe
>>>     Mail [1] needs following up
>>
>> Yes. If IPR could be converted to ata error_handler, a lot of code can
>> be simplified in libata too.
>
> Hmmm... yeah, it would be good to see progress there.
>
>>
>>> 2. SATA PMP support needs verification, but I don't have a setup
>>
>> Port multiplier behind a sas HBA will be challenging to setup :)
>> I can try, but I will need to open up one of my servers and hook a
>> small PMP box to one of the pm8001 plugs. I may have the cables for
>> that... Let me check.
>
> I was more thinking of just AHCI with a port multiplier.

OK. I got confused :)
Easy then, my test box is all hooked up already.
Will give this a spin.

>
> As for SAS controllers, I don't think it's something to be concerned
> about. For a start, I know for sure that hisi_sas HW does not support
> port multipliers, and I don't think that pm8001 does either. In
> addition, libsas does not even support it - I did see a series in the
> scsi list from years ago (to support it), but it did not progress.
>
> Thanks,
> John

--
Damien Le Moal
Western Digital Research

2022-09-21 08:49:12

by John Garry

[permalink] [raw]
Subject: Re: [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe

On 21/09/2022 05:04, Damien Le Moal wrote:
> On 9/20/22 19:27, John Garry wrote:
>> Currently for libata the SCSI device (sdev) associated with an ata_device
>> is allocated when the port probe has completed.
>>
>> It's useful to have the SCSI device and its associated request queue
>> available earlier for the port probe. Specifically if we have the
>> request queue available, then we can:
>> - Easily put ATA qc in SCSI cmnd priv data
>> - Send ATA internal commands on SCSI device request queue for [0]. The
>>    current solution there is to use the shost sdev request queue, which
>>    isn't great.
>> This series changes the ata port probe to alloc the sdev in the
>> ata_device revalidation, and then just do a SCSI starget scan afterwards.
>>
>> Why an RFC?
>> 1. IPR  driver needs to be fixed up - it does not use ATA EH port probe
>>     Mail [1] needs following up
>
> Yes. If IPR could be converted to ata error_handler, a lot of code can
> be simplified in libata too.

Hmmm... yeah, it would be good to see progress there.

>
>> 2. SATA PMP support needs verification, but I don't have a setup
>
> Port multiplier behind a sas HBA will be challenging to setup :)
> I can try, but I will need to open up one of my servers and hook a small
> PMP box to one of the pm8001 plugs. I may have the cables for that...
> Let me check.

I was more thinking of just AHCI with a port multiplier.

As for SAS controllers, I don't think it's something to be concerned
about. For a start, I know for sure that hisi_sas HW does not support
port multipliers, and I don't think that pm8001 does either. In
addition, libsas does not even support it - I did see a series in the
scsi list from years ago (to support it), but it did not progress.

Thanks,
John