Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3712391rwb; Tue, 20 Sep 2022 03:44:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7o0IWodOVYfXPO3wL/3LGvtVzbaj4QyqV/4iRYESbVsaB5XHp/S8Wdvv50dDjMjkfVsUtU X-Received: by 2002:a17:906:5d04:b0:77f:ca9f:33d1 with SMTP id g4-20020a1709065d0400b0077fca9f33d1mr16813412ejt.526.1663670682695; Tue, 20 Sep 2022 03:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663670682; cv=none; d=google.com; s=arc-20160816; b=A0j1Q11cioA/TpZeUvC1G57BVV5CjhKoBt74syBalFrPS8yWPRcLNadLy/bU+4nBWs dkqVFvBUcaUS8vt96MftC0bzWbGx+h05HkUEl7ExFrGdaFlLCpch2L2LlIqKEdCSOwM3 xI2J9S+akpHNYAWqQjOVIYvtnK87iP0/e4lCxQmekgL+z7XFHT3/TQVGQ/vV4ZeLJ3Ko CfQW3E+aWFy4rhwE08e74SYQOWFJ97wEBe4aQ4L010rvqyXb3LCDdCL0tjFcUNAt59NK 304A6l0ut/8lhLUCg7oGCCf/gTI7LysTjcb9kontL4tj7wrM8KySvEddkVhZhtbCGL5V GGQA== 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=1WTfq4IyMKhC34Cig3oibGytiNqpbFjjf+uQGbk1Bfk=; b=QZ2UtVDwQk6oarZVI/hIXKP9/5JC9V3riyrqYVlhliwf6fe4YhDH7yvKdw+mq+xDwF fUGG3PRvUZC+N0TjpDQPiRE/liPkX9XdP3jPelqKbwdn0eoXiC2zuFleKt5l/EoQpXAJ Z9wAedME/hF2LIIlIjheUULIaXXENFZeQ2uQnU/+mxWzQOypsdd8Q3vPduK1x9tkZ4qE eNqOfNseuHDmhrFDW5TmSQ7gYMSRibR1udsxQgbVwwQLWjnKzY25bZyvC1ZjsHvfQiWL E/8aqXRh9zZk/UHPu85z3cMpb3ZY4CEkbnRaKLDnnASNFAZPdVp4+tiKIrCRHCG/V1Qq Bz0w== 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 g12-20020a1709065d0c00b0077eca9fa444si937225ejt.187.2022.09.20.03.44.17; Tue, 20 Sep 2022 03:44:42 -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 S230398AbiITKgN (ORCPT + 99 others); Tue, 20 Sep 2022 06:36:13 -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 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 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. -- 2.35.3