linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	John Garry <john.garry@huawei.com>,
	axboe@kernel.dk, jejb@linux.ibm.com, martin.petersen@oracle.com,
	jinpu.wang@cloud.ionos.com, bvanassche@acm.org, hch@lst.de,
	ming.lei@redhat.com, niklas.cassel@wdc.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org,
	linuxarm@huawei.com
Subject: Re: [PATCH RFC v3 16/22] ata: libata-scsi: Allocate sdev early in port probe
Date: Thu, 27 Oct 2022 10:11:09 +0200	[thread overview]
Message-ID: <d4535f4f-d9cf-30de-ce8c-9d8ee9c0decb@suse.de> (raw)
In-Reply-To: <6c0a4a75-786a-c946-57f2-c511bd765bcc@opensource.wdc.com>

On 10/27/22 03:34, Damien Le Moal wrote:
> On 10/25/22 19:18, John Garry wrote:
>> 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.
>>
>> Export scsi_target_reap() so that it can be used to put the extra
>> reference we get when allocating the sdev.
>>
>> Signed-off-by: John Garry <john.garry@huawei.com>
>> ---
>>   drivers/ata/libata-eh.c   |  1 +
>>   drivers/ata/libata-scsi.c | 23 +++++++++--------------
>>   drivers/scsi/scsi_scan.c  |  1 +
>>   3 files changed, 11 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
>> index 08e11bc312c2..1ed5b1b64792 100644
>> --- a/drivers/ata/libata-eh.c
>> +++ b/drivers/ata/libata-eh.c
>> @@ -3446,6 +3446,7 @@ static int ata_eh_schedule_probe(struct ata_device *dev)
>>   
>>   	ata_eh_detach_dev(dev);
>>   	ata_dev_init(dev);
>> +	ata_scsi_setup_sdev(dev);
>>   	ehc->did_probe_mask |= (1 << dev->devno);
>>   	ehc->i.action |= ATA_EH_RESET;
>>   	ehc->saved_xfer_mode[dev->devno] = 0;
>> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
>> index efdba852e363..476e0ef4bd29 100644
>> --- a/drivers/ata/libata-scsi.c
>> +++ b/drivers/ata/libata-scsi.c
>> @@ -1109,7 +1109,12 @@ 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;
>>   }
>>   
>> @@ -4289,26 +4294,16 @@ 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);
> 
> Is there something equivalent to what this function does inside
> scsi_scan_target() ? I had a quick look but did not see anything...
> 
Typically, the SCSI layer has two ways of scanning.
One it the old-style serial scanning (originating in the old SCSI 
parallel model):
The scanning code will blindly scan _all_ devices up to max_luns, and 
attach every device for which the scanning code returns 'OK'.
The other one is to issue REPORT_LUNS and scan all LUNs returned there.

Mapped to libata we would need to figure out a stable SCSI enumeration, 
given that we have PMP and slave devices to content with.
To my knowledge we have ATA ports, each can have either a 'master' and 
'slave' device, _or_ it be a PMP port when it can support up to 16 
devices, right?
Point being, master/slave and PMP are exclusive, right?
So we can make the master as LUN 0, and the slave as LUN 1.
And for PMP we can use each PMP address as LUN <pmp> + 1, and keeping 
the actual device as LUN 0.

I think we can figure out whether it's a master/slave device setup 
upfront, so we should be able to set max_luns to '2' for these devices.
For PMP-capable (or devices which _might_ be PMP capable), we could 
emulate the REPORT LUNS command, mapping on the PMP mechanism to figure 
out which devices are connected.

Would that work?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman


  reply	other threads:[~2022-10-27  8:11 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 10:17 [PATCH RFC v3 00/22] blk-mq/libata/scsi: SCSI driver tagging improvements Part I John Garry
2022-10-25 10:11 ` John Garry
2022-10-25 10:17 ` [PATCH RFC v3 01/22] blk-mq: Don't get budget for reserved requests John Garry
2022-10-27  1:16   ` Damien Le Moal
2022-10-27  9:09     ` John Garry
2022-10-25 10:17 ` [PATCH RFC v3 02/22] scsi: core: Add scsi_get_dev() John Garry
2022-10-25 10:17 ` [PATCH RFC v3 03/22] scsi: core: Implement reserved command handling John Garry
2022-10-27  1:18   ` Damien Le Moal
2022-10-27  7:51     ` Hannes Reinecke
2022-10-27  8:16       ` John Garry
2022-10-27  9:11     ` John Garry
2022-10-25 10:17 ` [PATCH RFC v3 04/22] scsi: core: Add support to send reserved commands John Garry
2022-10-27  1:21   ` Damien Le Moal
2022-10-27  9:13     ` John Garry
2022-10-27  9:18       ` Damien Le Moal
2022-10-25 10:17 ` [PATCH RFC v3 05/22] scsi: core: Add support for reserved command timeout handling John Garry
2022-10-25 10:18 ` [PATCH RFC v3 06/22] scsi: libsas: Improve sas_ex_discover_expander() error handling John Garry
2022-10-25 10:18 ` [PATCH RFC v3 07/22] scsi: libsas: Notify LLDD expander found before calling sas_rphy_add() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 08/22] scsi: scsi_transport_sas: Alloc sdev for expander John Garry
2022-10-25 10:18 ` [PATCH RFC v3 09/22] scsi: libsas: Add sas_alloc_slow_task_rq() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 10/22] scsi: libsas: Add sas_queuecommand_internal() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 11/22] scsi: libsas: Add sas_internal_timeout() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 12/22] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 13/22] scsi: scsi_transport_sas: Allocate end device target id in the rphy alloc John Garry
2022-10-25 10:18 ` [PATCH RFC v3 14/22] ata: libata-scsi: Add ata_scsi_setup_sdev() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 15/22] scsi: libsas: Add sas_ata_setup_device() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 16/22] ata: libata-scsi: Allocate sdev early in port probe John Garry
2022-10-27  1:34   ` Damien Le Moal
2022-10-27  8:11     ` Hannes Reinecke [this message]
2022-10-27  9:16       ` Damien Le Moal
2022-10-27  9:51         ` Hannes Reinecke
2022-11-07 10:09           ` John Garry
2022-11-07 10:20             ` Hannes Reinecke
2022-10-25 10:18 ` [PATCH RFC v3 17/22] scsi: libsas drivers: Reserve tags John Garry
2022-10-25 10:18 ` [PATCH RFC v3 18/22] scsi: libsas: Queue SMP commands as requests John Garry
2022-10-27  1:36   ` Damien Le Moal
2022-10-27 10:45     ` John Garry
2022-10-25 10:18 ` [PATCH RFC v3 19/22] scsi: libsas: Queue TMF " John Garry
2022-10-25 10:18 ` [PATCH RFC v3 20/22] scsi: core: Add scsi_alloc_request_hwq() John Garry
2022-10-25 10:18 ` [PATCH RFC v3 21/22] scsi: libsas: Queue internal abort commands as requests John Garry
2022-10-29  1:15   ` chenxiang (M)
2022-11-02 10:04     ` John Garry
2022-11-03  3:09       ` chenxiang (M)
2022-10-25 10:18 ` [PATCH RFC v3 22/22] scsi: libsas: Delete sas_task_slow.timer John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d4535f4f-d9cf-30de-ce8c-9d8ee9c0decb@suse.de \
    --to=hare@suse.de \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hch@lst.de \
    --cc=jejb@linux.ibm.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=martin.petersen@oracle.com \
    --cc=ming.lei@redhat.com \
    --cc=niklas.cassel@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).