From patchwork Tue Sep 20 10:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWydM2Bk9z1yp7 for ; Tue, 20 Sep 2022 20:36:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbiITKgT (ORCPT ); Tue, 20 Sep 2022 06:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbiITKfy (ORCPT ); Tue, 20 Sep 2022 06:35:54 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029F472FCE; Tue, 20 Sep 2022 03:34:03 -0700 (PDT) Received: from fraeml738-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYG364Nz686kk; Tue, 20 Sep 2022 18:32:50 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml738-chm.china.huawei.com (10.206.15.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:33:52 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:33:49 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH 1/6] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device() Date: Tue, 20 Sep 2022 18:27:05 +0800 Message-ID: <1663669630-21333-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org 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 Reviewed-by: Damien Le Moal --- 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); From patchwork Tue Sep 20 10:27:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWyd55rNYz1yp7 for ; Tue, 20 Sep 2022 20:36:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231313AbiITKgG (ORCPT ); Tue, 20 Sep 2022 06:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbiITKfr (ORCPT ); Tue, 20 Sep 2022 06:35:47 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C3F274CF6; Tue, 20 Sep 2022 03:34:04 -0700 (PDT) Received: from fraeml736-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYK2Gz9z67xNS; Tue, 20 Sep 2022 18:32:53 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml736-chm.china.huawei.com (10.206.15.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:33:55 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:33:52 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 2/6] scsi: scsi_transport_sas: Allocate end device target id in the rphy alloc Date: Tue, 20 Sep 2022 18:27:06 +0800 Message-ID: <1663669630-21333-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Currently the per-end device target id is allocated when adding the rphy, which is when we execute the scan of the target. However it will be useful to have the target id allocated earlier when allocating the rphy for the end device. For libata we want to move to a scheme of allocating the sdev early in the probe process and then later executing the scan (for that target). As such, users of would libata would require that the target id allocated earlier here (before the scan). Signed-off-by: John Garry --- drivers/scsi/scsi_transport_sas.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c index 2f88c61216ee..56d325665bc7 100644 --- a/drivers/scsi/scsi_transport_sas.c +++ b/drivers/scsi/scsi_transport_sas.c @@ -1433,6 +1433,7 @@ static void sas_rphy_initialize(struct sas_rphy *rphy) struct sas_rphy *sas_end_device_alloc(struct sas_port *parent) { struct Scsi_Host *shost = dev_to_shost(&parent->dev); + struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); struct sas_end_device *rdev; rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); @@ -1455,6 +1456,10 @@ struct sas_rphy *sas_end_device_alloc(struct sas_port *parent) sas_rphy_initialize(&rdev->rphy); transport_setup_device(&rdev->rphy.dev); + mutex_lock(&sas_host->lock); + rdev->rphy.scsi_target_id = sas_host->next_target_id++; + mutex_unlock(&sas_host->lock); + return &rdev->rphy; } EXPORT_SYMBOL(sas_end_device_alloc); @@ -1500,6 +1505,16 @@ struct sas_rphy *sas_expander_alloc(struct sas_port *parent, } EXPORT_SYMBOL(sas_expander_alloc); +static bool sas_rphy_end_device_valid_tproto(struct sas_rphy *rphy) +{ + struct sas_identify *identify = &rphy->identify; + + if (identify->target_port_protocols & + (SAS_PROTOCOL_SSP | SAS_PROTOCOL_STP | SAS_PROTOCOL_SATA)) + return true; + return false; +} + /** * sas_rphy_add - add a SAS remote PHY to the device hierarchy * @rphy: The remote PHY to be added @@ -1529,16 +1544,10 @@ int sas_rphy_add(struct sas_rphy *rphy) mutex_lock(&sas_host->lock); list_add_tail(&rphy->list, &sas_host->rphy_list); - if (identify->device_type == SAS_END_DEVICE && - (identify->target_port_protocols & - (SAS_PROTOCOL_SSP | SAS_PROTOCOL_STP | SAS_PROTOCOL_SATA))) - rphy->scsi_target_id = sas_host->next_target_id++; - else if (identify->device_type == SAS_END_DEVICE) - rphy->scsi_target_id = -1; mutex_unlock(&sas_host->lock); if (identify->device_type == SAS_END_DEVICE && - rphy->scsi_target_id != -1) { + sas_rphy_end_device_valid_tproto(rphy)) { int lun; if (identify->target_port_protocols & SAS_PROTOCOL_SSP) @@ -1667,7 +1676,7 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel, mutex_lock(&sas_host->lock); list_for_each_entry(rphy, &sas_host->rphy_list, list) { if (rphy->identify.device_type != SAS_END_DEVICE || - rphy->scsi_target_id == -1) + !sas_rphy_end_device_valid_tproto(rphy)) continue; if ((channel == SCAN_WILD_CARD || channel == 0) && From patchwork Tue Sep 20 10:27:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWydg4J6Qz1yp7 for ; Tue, 20 Sep 2022 20:36:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbiITKgg (ORCPT ); Tue, 20 Sep 2022 06:36:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbiITKf5 (ORCPT ); Tue, 20 Sep 2022 06:35:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DAEA74CF5; Tue, 20 Sep 2022 03:34:03 -0700 (PDT) Received: from fraeml737-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYN2gMQz6H73Y; Tue, 20 Sep 2022 18:32:56 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml737-chm.china.huawei.com (10.206.15.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:33:58 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:33:55 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 3/6] scsi: core: Add scsi_get_dev() Date: Tue, 20 Sep 2022 18:27:07 +0800 Message-ID: <1663669630-21333-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Add a function which allows use to alloc a sdev with configurable device parent, and channel:id:lun. This is useful for separating adding a scsi device into separate alloc and scan steps. Signed-off-by: John Garry --- drivers/scsi/scsi_scan.c | 25 +++++++++++++++++++++++++ include/scsi/scsi_host.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 3759b1a77504..fd15ddac01b6 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1988,3 +1988,28 @@ void scsi_forget_host(struct Scsi_Host *shost) spin_unlock_irqrestore(shost->host_lock, flags); } +struct scsi_device *scsi_get_dev(struct device *parent, int channel, uint id, u64 lun) +{ + struct Scsi_Host *shost = dev_to_shost(parent); + struct scsi_device *sdev = NULL; + struct scsi_target *starget; + + mutex_lock(&shost->scan_mutex); + if (!scsi_host_scan_allowed(shost)) + goto out; + + starget = scsi_alloc_target(parent, 0, id); + if (!starget) + goto out; + + sdev = scsi_alloc_sdev(starget, 0, NULL); + if (sdev) + sdev->borken = 0; + else + scsi_target_reap(starget); + put_device(&starget->dev); + out: + mutex_unlock(&shost->scan_mutex); + return sdev; +} +EXPORT_SYMBOL(scsi_get_dev); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index aa7b7496c93a..5142c7df7647 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -794,7 +794,10 @@ void scsi_host_busy_iter(struct Scsi_Host *, struct class_container; +extern struct scsi_device *scsi_get_dev(struct device *parent, int channel, uint id, u64 lun); + /* + * DIF defines the exchange of protection information between * initiator and SBC block device. * From patchwork Tue Sep 20 10:27:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679970 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWyd846MRz1yp7 for ; Tue, 20 Sep 2022 20:36:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231351AbiITKgJ (ORCPT ); Tue, 20 Sep 2022 06:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbiITKfw (ORCPT ); Tue, 20 Sep 2022 06:35:52 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C67267330B; Tue, 20 Sep 2022 03:34:03 -0700 (PDT) Received: from fraeml735-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyTD3QMTz67v9b; Tue, 20 Sep 2022 18:29:20 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml735-chm.china.huawei.com (10.206.15.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:34:01 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:33:58 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 4/6] ata: libata-scsi: Add ata_scsi_setup_sdev() Date: Tue, 20 Sep 2022 18:27:08 +0800 Message-ID: <1663669630-21333-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org 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 --- 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. From patchwork Tue Sep 20 10:27:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWydk60Qvz1yp7 for ; Tue, 20 Sep 2022 20:36:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231372AbiITKgk (ORCPT ); Tue, 20 Sep 2022 06:36:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbiITKf5 (ORCPT ); Tue, 20 Sep 2022 06:35:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3AC372EFF; Tue, 20 Sep 2022 03:34:06 -0700 (PDT) Received: from fraeml734-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYT6Rblz686wr; Tue, 20 Sep 2022 18:33:01 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml734-chm.china.huawei.com (10.206.15.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:34:04 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:34:01 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 5/6] scsi: libsas: Add sas_ata_setup_device() Date: Tue, 20 Sep 2022 18:27:09 +0800 Message-ID: <1663669630-21333-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Add a function which does a custom sdev alloc - essentially replicates what we do in sas_rphy_add() in terms of sdev parent and id. Signed-off-by: John Garry --- drivers/scsi/libsas/sas_ata.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index d35c9296f738..6d3535a4bfbb 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -523,6 +523,25 @@ static int sas_ata_prereset(struct ata_link *link, unsigned long deadline) return res; } +static int sas_ata_setup_device(struct ata_device *dev) +{ + u64 lun = 0; + int channel = 0; + struct ata_link *link = dev->link; + struct ata_port *ap = link->ap; + struct scsi_device *sdev; + struct domain_device *ddev = ap->private_data; + struct sas_rphy *rphy = ddev->rphy; + struct device *parent = &rphy->dev; + uint id = rphy->scsi_target_id; + + sdev = scsi_get_dev(parent, channel, id, lun); + if (!sdev) + return -ENODEV; + dev->sdev = sdev; + return 0; +} + static struct ata_port_operations sas_sata_ops = { .prereset = sas_ata_prereset, .hardreset = sas_ata_hard_reset, @@ -537,6 +556,7 @@ static struct ata_port_operations sas_sata_ops = { .set_dmamode = sas_ata_set_dmamode, .sched_eh = sas_ata_sched_eh, .end_eh = sas_ata_end_eh, + .setup_scsi_device = sas_ata_setup_device, }; static struct ata_port_info sata_port_info = { From patchwork Tue Sep 20 10:27:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 1679975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MWydh3bXSz1yp7 for ; Tue, 20 Sep 2022 20:36:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231370AbiITKgi (ORCPT ); Tue, 20 Sep 2022 06:36:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiITKf5 (ORCPT ); Tue, 20 Sep 2022 06:35:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 293CB719AD; Tue, 20 Sep 2022 03:34:09 -0700 (PDT) Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYY1Khnz6873f; Tue, 20 Sep 2022 18:33:05 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:34:07 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:34:04 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 6/6] ata: libata-scsi: Allocate sdev early in port probe Date: Tue, 20 Sep 2022 18:27:10 +0800 Message-ID: <1663669630-21333-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org 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 --- 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); } }