From patchwork Tue Oct 25 10:18: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: 10673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp908278wru; Tue, 25 Oct 2022 02:53:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7U2VDgxMni+bkSR6I/2h0fiVleIto+2Zjgl1D08W6cu28ROsN1udYjPDcYHyqApqFGzkAO X-Received: by 2002:a63:551b:0:b0:44b:7dcf:92ee with SMTP id j27-20020a63551b000000b0044b7dcf92eemr32779220pgb.610.1666691618581; Tue, 25 Oct 2022 02:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666691618; cv=none; d=google.com; s=arc-20160816; b=F2Ua3Mu4alOaqrXkKlYAB69WgtYEh98gvfJtpvjVbw6zoAlvj+SHl0BAtgVwut8kop F1Yroxz8e3lt20Yt0Mqruct8t8jxOoV5bU1/ZIhBiIuiizXulqbzZuLLscg3P3viQoe3 aUjzz/rZsTvJ+tyOxfZFJm5ZRC3zY+r5ZcUB1AXtIGEf1ea8232kIYxnQ5RqLVkohSS0 lBIUVHdbJjSVUEjULIa6uDzn6kvEi6LJY1mjrkH+PI2stwkAx9gByWNbGJVw5IuLIpoE +avnUk2F/iQ8VucjVy3nfuc1hwOk7UuYYJuetOhzegp1PUj5o03loxZdQ3XY6N1LR2FV UgYQ== 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=CNrz55GuvaoJ9CBTsNOZ7M5z/EprRxB9os9jyOM2bVI=; b=kBQauBgq2rQ43AzMUA/syXWYjoMjhNSKJN34ntT6I1FvP86v8hZNF9Hkc6dCqGnhVZ 4HYtiKc0/nREfJIpQaQg2Msx6NR5rFsrLqtZbQnnDyJh3aslOz1fmy5r0ax1ZK6RzkWN 1lSev/tilid/BwOk0sZntZIUX7FncEFU4PnWeQO2kZtiB4bYmrTrp+W0XRtn3xGHiB/+ rrRjN42xrMoGkQ3khbPEOovmgfIKsRTjpH7mXsj9KfYqMPtW+gs29NYHAXCTbLhPmfBT EMHIPT/QCUD3XhmkCOd7XAuu9BK8GpHUiPmZBxkSeKNj5W6CK8OgywaE37cOHcBZlels 3fng== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a635951000000b0044601bb2f90si2365379pgm.530.2022.10.25.02.53.24; Tue, 25 Oct 2022 02:53:38 -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 S231645AbiJYJwK (ORCPT + 99 others); Tue, 25 Oct 2022 05:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbiJYJul (ORCPT ); Tue, 25 Oct 2022 05:50:41 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B4E615F900; Tue, 25 Oct 2022 02:48:55 -0700 (PDT) Received: from frapeml100005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MxRtr3sltz67vyB; Tue, 25 Oct 2022 17:47:32 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by frapeml100005.china.huawei.com (7.182.85.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 11:48:53 +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, 25 Oct 2022 10:48:49 +0100 From: John Garry To: , , , , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v3 14/22] ata: libata-scsi: Add ata_scsi_setup_sdev() Date: Tue, 25 Oct 2022 18:18:08 +0800 Message-ID: <1666693096-180008-15-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1666693096-180008-1-git-send-email-john.garry@huawei.com> References: <1666693096-180008-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747652830659992540?= X-GMAIL-MSGID: =?utf-8?q?1747652830659992540?= 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 | 26 ++++++++++++++++++++++++++ drivers/ata/libata.h | 1 + include/linux/libata.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e2ebb0b065e2..efdba852e363 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -4253,6 +4253,32 @@ 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; + ata_scsi_assign_ofnode(dev, ap); + 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 2c5c8273af01..0c2df1e60768 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -112,6 +112,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 fe990176e6ee..827d5838cd23 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.