mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: <damien.lemoal@opensource.wdc.com>, <jejb@linux.ibm.com>,
	<martin.petersen@oracle.com>, <hare@suse.de>, <hch@lst.de>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-scsi@vger.kernel.org>, <brking@us.ibm.com>,
	John Garry <john.garry@huawei.com>
Subject: [PATCH RFC 4/6] ata: libata-scsi: Add ata_scsi_setup_sdev()
Date: Tue, 20 Sep 2022 18:27:08 +0800	[thread overview]
Message-ID: <1663669630-21333-5-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com>

Add a function to setup the sdev associated with an ata_device.

Currently in libata to create the sdev we call __scsi_add_device() to
create the sdev and execute the scan. However if we want to move to a
2-step process where we allocate the sdev early in the port probe, then
we need a separate function just to allocate the sdev.

We add a ata_port_operations callback .setup_scsi_device for when the
driver needs a custom setup. This is essentially for libsas, which does
not use the same options for sdev parent and id.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/ata/libata-scsi.c | 25 +++++++++++++++++++++++++
 drivers/ata/libata.h      |  1 +
 include/linux/libata.h    |  2 ++
 3 files changed, 28 insertions(+)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 29e2f55c6faa..88f39ab10a92 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4257,6 +4257,31 @@ static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap)
 }
 #endif
 
+int ata_scsi_setup_sdev(struct ata_device *dev)
+{
+	u64 lun = 0;
+	int channel = 0;
+	uint id = 0;
+	struct ata_link *link = dev->link;
+	struct ata_port *ap = link->ap;
+	struct Scsi_Host *shost = ap->scsi_host;
+	struct device *parent = &shost->shost_gendev;
+	struct scsi_device *sdev;
+
+	if (ap->ops->setup_scsi_device)
+		return ap->ops->setup_scsi_device(dev);
+
+	if (ata_is_host_link(link))
+		id = dev->devno;
+	else
+		channel = link->pmp;
+	sdev = scsi_get_dev(parent, channel, id, lun);
+	if (!sdev)
+		return -ENODEV;
+	dev->sdev = sdev;
+	return 0;
+}
+
 void ata_scsi_scan_host(struct ata_port *ap, int sync)
 {
 	int tries = 5;
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 98bc8649c63f..ca6c3e0f81ea 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -113,6 +113,7 @@ extern struct ata_device *ata_scsi_find_dev(struct ata_port *ap,
 					    const struct scsi_device *scsidev);
 extern int ata_scsi_add_hosts(struct ata_host *host,
 			      struct scsi_host_template *sht);
+extern int ata_scsi_setup_sdev(struct ata_device *dev);
 extern void ata_scsi_scan_host(struct ata_port *ap, int sync);
 extern int ata_scsi_offline_dev(struct ata_device *dev);
 extern void ata_scsi_set_sense(struct ata_device *dev,
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 698032e5ef2d..67aa1d7d909b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -968,6 +968,8 @@ struct ata_port_operations {
 	void (*phy_reset)(struct ata_port *ap);
 	void (*eng_timeout)(struct ata_port *ap);
 
+	int (*setup_scsi_device)(struct ata_device *dev);
+
 	/*
 	 * ->inherits must be the last field and all the preceding
 	 * fields must be pointers.
-- 
2.35.3


  parent reply	other threads:[~2022-09-20 10:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 10:27 [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe John Garry
2022-09-20 10:27 ` [PATCH 1/6] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device() John Garry
2022-09-20 22:03   ` Damien Le Moal
2022-09-20 10:27 ` [PATCH RFC 2/6] scsi: scsi_transport_sas: Allocate end device target id in the rphy alloc John Garry
2022-09-20 22:02   ` Damien Le Moal
2022-09-21  9:21     ` John Garry
2022-09-20 10:27 ` [PATCH RFC 3/6] scsi: core: Add scsi_get_dev() John Garry
2022-09-20 21:58   ` Damien Le Moal
2022-09-21  9:17     ` John Garry
2022-09-20 10:27 ` John Garry [this message]
2022-09-20 10:27 ` [PATCH RFC 5/6] scsi: libsas: Add sas_ata_setup_device() John Garry
2022-09-20 10:27 ` [PATCH RFC 6/6] ata: libata-scsi: Allocate sdev early in port probe John Garry
2022-09-21  4:04 ` [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata " Damien Le Moal
2022-09-21  8:24   ` John Garry
2022-09-21  8:31     ` Damien Le Moal

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=1663669630-21333-5-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=brking@us.ibm.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.ibm.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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

all inboxes | Powered by JetHome®