Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3727806rwb; Tue, 20 Sep 2022 04:01:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4BV5ET4vbmUpMguNRq67SB/GYhcHySRAbzTt19mDRJeWCD/8o56HuBuw8s6clRyupgWYJ0 X-Received: by 2002:a17:90b:1b52:b0:202:c1e3:7e9f with SMTP id nv18-20020a17090b1b5200b00202c1e37e9fmr3269289pjb.68.1663671663980; Tue, 20 Sep 2022 04:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663671663; cv=none; d=google.com; s=arc-20160816; b=kT5Wsd2bpvGzEfOp5XqeXj5rIunqyoCNKdoiuUR1FQ+v4OWPu3QVHfc2RjrF8Gckkj l2iTVNDRc0qjbG7k2WSZcIpQEScWIP9pRooAqc3B9aSFO3WLPIBlUXCP3kdpD0vljoEr ucikuaIV6mraFe0m1VB05hw5+zWFaL3jgQkBOLA+lBg/Z0X1JUfkipCaZDGPrSQOA15z dXlEyYc/jtLyppgyR81vyslDI9HdXupSibDu/QKFvM3mk7kGroVI3Klz1pER+TM0Mqk4 kJnDFWd8ZRgk4VNN+NnIbLGCPgmqJGMr7zVUkiBkkyoWRSKufc0VdXzsPkAfYWlqzFE/ rV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=PwGb6hkPmrYgJwUnVqaI97fWHqGzb3nCGMZDgM4H7S4=; b=bGbXTTsPMGKQXVCe+ojb84zQZizLAL6N6yluANG5EGAss6HLs3DCnPFTzES1OAS7is jKTxYWy/S3BjAUVViRLNuYyB0TplsZbeuUqQ0ex1mYVTs5AyVo6gfC2yd/0jGwFZOb/b OTgmsCif5SOGHw20kopm8JnHz628m9/BptVfuLQmk/QEyg3e3rjQMiG5zQ/HKDDd+uvv Vbz9995qpT9CGL07PxP0IiIbcYI7Wis74DG/KIc23xN1s3du1ceqCfz+8Nib1rQU/eVX J5v1PgjE+/9s22mjyyHvM/s/uNVROpC5/7ASyRVhni7g+exsNGuz1tsIJWUeRXlKRGZD IYUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a62d44a000000b00537280a2fc4si1308700pfl.231.2022.09.20.04.00.51; Tue, 20 Sep 2022 04:01:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbiITKgp (ORCPT + 99 others); Tue, 20 Sep 2022 06:36:45 -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 Content-Type: text/plain 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-kernel@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); } } -- 2.35.3