Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3711133rwb; Tue, 20 Sep 2022 03:43:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5QpfSLub8Qe5ODsGC5D0VlpNVjGul6t3TDHAtowUy2MzNpJSu0OuZk6HTiPJrcK4h21Ewu X-Received: by 2002:a17:907:1df1:b0:77a:a670:d807 with SMTP id og49-20020a1709071df100b0077aa670d807mr16373300ejc.163.1663670600974; Tue, 20 Sep 2022 03:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663670600; cv=none; d=google.com; s=arc-20160816; b=kWtpHOTOCc4qmieVZDNPC7ucDuXCYnVXkTRSEmJTu7/N6juCnqDulPAtLJO8qqCODu 6xHoYxiAtc+V7e5nnayEmXtfKXgbPSxFcfpsBUcUI6DLmN+rUR5WMXGkxjxqsOK7lc1Z 2aT+8trnStity9qd8M3k3yFpG9tjIHdvglkZKh3e02QRsbVXDZU8aUVqbB2zLbwG6ING GdH80xNl7QMst4euo7Q8IZILPafpfxNTf34tkbfPb4MuClewOp4x0RW4WbO3nn5VMXLQ Z283sIp0rH/zTUyGX4Y1O4lhARvN1Q4HtpzvAn1I11R5Gp0gjPxs5mcIhg4VK/MvHsVI J72w== 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=Q6x/3hHuQQfzh1aajUSHV4+7Zt6yT5ePie8IQe/+zN0=; b=kJOcNPKblcMO85GOaAvCJBafJksajJ2E8crpJiQ2Gd6fgk50rgI0VROHjpE5tQ/FgD XAiYi2LgEFJ3dBWN69wp468aZKjcuSveT+QTpT36sZ+1wLmv3C1pX/3Zd4UjQUssIIpR 0+lnr8MEee7U63RCR/05WVTOhFKZA0F+272m5654Rt2U/CFwC1rBrqnxdCu+iKed5E8b k8XkVc3z7BfjwtwP1w9fiu+JHXRZhyKOEql8fpuJoArqQhPFPrAK7n3iNMjZAzHYXLsZ Xkd5EsVJ8PpUJJCiazmpVdZk//EQTfY1Ava+wtV+jGdRuoTPZt/UggTmAnTa3COIYOw/ 3ycg== 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 b8-20020a056402350800b004515d9b26d3si1446000edd.406.2022.09.20.03.42.55; Tue, 20 Sep 2022 03:43:20 -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 S230217AbiITKgI (ORCPT + 99 others); Tue, 20 Sep 2022 06:36:08 -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 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-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) && -- 2.35.3