Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5662875pxb; Mon, 28 Mar 2022 15:41:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymDaqk/1eLdegC3cdrptjJoKX+RN5e6mwX+5z5Nfua+iBcTYQUNXI4CerOHR4Kft2mCUEm X-Received: by 2002:a05:6830:34a1:b0:5c4:3dca:b666 with SMTP id c33-20020a05683034a100b005c43dcab666mr11085058otu.328.1648507268462; Mon, 28 Mar 2022 15:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648507268; cv=none; d=google.com; s=arc-20160816; b=vUyulTK6ER5gO6iTGUNS7v0Opw9ZSlWhf/NpXlRvVIVLzD9gvCthVYRH5fFJ6rCBT0 Wj+YRfYRh8kk3ZIh8Yw9Oqq0hc48m6QHt5KpowP/KNzzQhvlESwUYehm4etT/aWgWipf RlkTIjCelLtAhUg93GutrN9CXCAnuHecJjkYDe78WjuY75+9xy3E8WxKIkTPLLXPPk4u XWdd1Gd/7vF9MdX59rH67nqDEE08kZ8zbTNIaxHY0D1USup2sJYNumWCOeKo8SkwR8Tl grfQWjiXFI6SEND7mhTekIiyu4lOIhBl+3JeVYPuB9nrO8iNJ2fn0n3hGpEO5QMRSd2V cMYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=7oZ/0y7i1hXtXcbHxBfvEHO2mgD8rHsn5d2q3MYVH78=; b=UxrYxxSGmPM+RPht6W62slzSczB3BKUWVlmCs4fR8dGSMeIAyK483Ynjue7I6b/Vgd ZX+7pxvjJqVWrcY5w3XaElmVaoXeOqZ6oSEhJEkFkdl8e1wi6P8oy7eO/9yLydQ9GABp haV2H/BcFSTzBIevQkXeX+hZYvrXeD4Onh87CXozVUqytfzT2ZCByaN62wPKLp4DUd3D ByfIb+jJRMKQbI4xjwAWkr8keClcgG/qLmrDCdsz4efpg5n6EiZtrz9DNVSTbVYOndI2 /GVSsUB0BZSdjqZGt8H7y/f7Pa0SnUiQzbYKAyKUOnLTCtM4Twew7g2IVQb2g+QQAEgy 00xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=dMEvYxCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bh40-20020a056808182800b002ef0c347661si14064861oib.225.2022.03.28.15.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:41:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=dMEvYxCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE59A2156DD; Mon, 28 Mar 2022 14:49:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238680AbiC1Psc (ORCPT + 99 others); Mon, 28 Mar 2022 11:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238766AbiC1Pp6 (ORCPT ); Mon, 28 Mar 2022 11:45:58 -0400 Received: from mail.baikalelectronics.ru (mail.baikalelectronics.com [87.245.175.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E308C4A930; Mon, 28 Mar 2022 08:44:14 -0700 (PDT) Received: from mail.baikalelectronics.ru (unknown [192.168.51.25]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 41DDC1E28D8; Thu, 24 Mar 2022 03:16:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.ru 41DDC1E28D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1648081000; bh=7oZ/0y7i1hXtXcbHxBfvEHO2mgD8rHsn5d2q3MYVH78=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=dMEvYxCrhNI5UvO1b22Ddg7vubS6kEv2x/l87AjhFwQ1Z4W127qM8mlJFL1cT+08b /Ln28MxrvvYC172yFKKrv9J8SbPUzJAhKRYWRo/QUiCNvPpPa4imOUixQuMXCnyv/b bBDj8O5IQWh/9que/MbzDNtw4WYjKUQAYXwZkhNw= Received: from localhost (192.168.168.10) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 24 Mar 2022 03:16:40 +0300 From: Serge Semin To: Damien Le Moal , Hans de Goede , Jens Axboe CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Rob Herring , , , Subject: [PATCH 12/21] ata: libahci: Discard redundant force_port_map parameter Date: Thu, 24 Mar 2022 03:16:19 +0300 Message-ID: <20220324001628.13028-13-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220324001628.13028-1-Sergey.Semin@baikalelectronics.ru> References: <20220324001628.13028-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 there are four port-map-related fields declared in the ahci_host_priv structure and used to setup the HBA ports mapping. First the ports-mapping is read from the PI register and immediately stored in the saved_port_map field. If forced_port_map is initialized with non-zero value then its value will have greater priority over the value read from PI, thus it will override the saved_port_map field. That value will be then masked by a non-zero mask_port_map field and after some sanity checks it will be stored in the ahci_host_priv.port_map field as a final port mapping. As you can see the logic is a bit too complicated for such a simple task. We can freely get rid from at least one of the fields with no change to the implemented semantic. The force_port_map field can be replaced with taking non-zero saved_port_map value into account. So if saved_port_map is pre-initialized by the glue-driver/platform-specific code then it will have greater priority over the value read from PI register and will be used as actual HBA ports mapping later on. Thus the ports map forcing task will be just transferred from the force_port_map to saved_port_map field. This modification will perfectly fit into the feature of having OF-based initialization of the HW-init HBA CSR fields we are about to introduce in the next commit. Signed-off-by: Serge Semin --- drivers/ata/ahci.c | 2 +- drivers/ata/ahci.h | 1 - drivers/ata/libahci.c | 10 ++++++---- drivers/ata/libahci_platform.c | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index ab5811ef5a53..8ce0d166cc8d 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -654,7 +654,7 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev, { if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) { dev_info(&pdev->dev, "JMB361 has only one port\n"); - hpriv->force_port_map = 1; + hpriv->saved_port_map = 1; } /* diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 04690b4168a3..519d148ecaea 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -329,7 +329,6 @@ struct ahci_port_priv { struct ahci_host_priv { /* Input fields */ unsigned int flags; /* AHCI_HFLAG_* */ - u32 force_port_map; /* force port map */ u32 mask_port_map; /* mask out particular bits */ void __iomem * mmio; /* bus-independent mem map */ diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 0ed484e04fd6..011175e82174 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -453,7 +453,6 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv) * reset. Values without are used for driver operation. */ hpriv->saved_cap = cap = readl(mmio + HOST_CAP); - hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL); /* CAP2 register is only defined for AHCI 1.2 and later */ vers = readl(mmio + HOST_VERSION); @@ -517,10 +516,13 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv) cap &= ~HOST_CAP_SXS; } - if (hpriv->force_port_map && port_map != hpriv->force_port_map) { + /* Override the HBA ports mapping if the platform needs it */ + port_map = readl(mmio + HOST_PORTS_IMPL); + if (hpriv->saved_port_map && port_map != hpriv->saved_port_map) { dev_info(dev, "forcing port_map 0x%x -> 0x%x\n", - port_map, hpriv->force_port_map); - port_map = hpriv->force_port_map; + port_map, hpriv->saved_port_map); + port_map = hpriv->saved_port_map; + } else { hpriv->saved_port_map = port_map; } diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index febad33aa43c..5cbc2c42164d 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -539,7 +539,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, } of_property_read_u32(dev->of_node, - "ports-implemented", &hpriv->force_port_map); + "ports-implemented", &hpriv->saved_port_map); if (child_nodes) { for_each_child_of_node(dev->of_node, child) { -- 2.35.1