Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp118673rdb; Wed, 18 Oct 2023 21:38:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ+wB0lRWVcfL5UwnPy+YHmbM/Ai9DqF9bKvl79TbEgX+uByjfLJg7Ic6KDtGxHj76Kgaw X-Received: by 2002:aa7:88cc:0:b0:690:3793:17e5 with SMTP id k12-20020aa788cc000000b00690379317e5mr1081735pff.4.1697690310575; Wed, 18 Oct 2023 21:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697690310; cv=none; d=google.com; s=arc-20160816; b=D8FJayy9O5DKXIcLDQhfrhIAG/cxxX7UizuAtUp5lk1NJxwR0P3usoWFQ75tfmFK3i 09IYy7iFKGHbmr+BojZygiZbSA2e/nq+kdDsq3MCN3/DHq8/1TACvLZIX60dqYSlLKNv 0nlNUhnXQOC9T4bOytf06aqQagbcK4Ftbz/tO0dgRU9ZH29QwX6iIeEUQxMI4kDkyIn4 fUAJWvywQ2YYhHQPqhXZFB8HMnAgIkT1k6mkIPLHh4/EY+5JkFvO+AQ45H+bYMLi0UAA XcibAJ/xflwVi9YnCklt3XzpXZ8/MAFmlLV5YwUhHGLu2KMUCLNrQIygSJfN6kV4jdKc X+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=2ee5WpctjPUgoDFDBIHdnJ/ADkHfyWTnAoSZDMH6IJk=; fh=voVX45xS6sUXY5sGcN0gTJ/erA6asoS6yJWc1UQeD5M=; b=Hq9oQqZ3EQ+Yo6ZX2hhNADRy/O/7n5IMN60KyMZR8j26aE0yFIiWD4fTNZ/nKyPcya QHHJ61UvSgV9wAMUbesY9SJTeAOGaugb8X5DZc7jm4jYFZ6qsj+eaY3JrAXrDZAAqPOy TgsP7orEXYOb4Omq8MOkhx5tCkj6YzqLCZoGqbsbwK+i+t0kNZnLfFVVpojMq4CNFvyo 0EEjNli/lbLvxLXYyVUo5obi1mhAnaEHTH1H9Z3tGilRggugCmhu0aJwTipJm3nAKTQv NmHEkOXpWEU+SQFlVkmP1eycMpDKLB/2tNbXkC1/vfVqQqE2FMC101IERdD9hErHBvXY QGGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=gJJtgYvz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i69-20020a636d48000000b005a9f776c57dsi3512739pgc.644.2023.10.18.21.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 21:38:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=gJJtgYvz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1FFD28133D1D; Wed, 18 Oct 2023 21:38:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbjJSEiU (ORCPT + 99 others); Thu, 19 Oct 2023 00:38:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjJSEiR (ORCPT ); Thu, 19 Oct 2023 00:38:17 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA86B11F; Wed, 18 Oct 2023 21:38:14 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 39J4bsb7034905; Wed, 18 Oct 2023 23:37:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1697690274; bh=2ee5WpctjPUgoDFDBIHdnJ/ADkHfyWTnAoSZDMH6IJk=; h=Date:CC:Subject:To:References:From:In-Reply-To; b=gJJtgYvz4blRqhUT7S6ylzuJTNZs8gOG31vhzBY1BE0MAdcPubIc61sVSZM/j7Op4 fJnPJ3xLgdngp9p1o01xKV8LuLOz/WDCWNgBFfv+P037LNDvOt/TOUuuyx9+kJ7BCv bNUFhLdF0H4aA4JbziE8kNSQMh4O7EeDTxsa59hY= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 39J4bsXP066872 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Oct 2023 23:37:54 -0500 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Wed, 18 Oct 2023 23:37:53 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Wed, 18 Oct 2023 23:37:53 -0500 Received: from [172.24.227.9] (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 39J4bn51111409; Wed, 18 Oct 2023 23:37:50 -0500 Message-ID: Date: Thu, 19 Oct 2023 10:07:49 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird CC: , , , , , , , , , Subject: Re: [PATCH v2] PCI: keystone: Fix ks_pcie_v3_65_add_bus() for AM654x SoC To: Serge Semin References: <20231018075038.2740534-1-s-vadapalli@ti.com> <6b74d547-bdaf-41e3-8046-ce295a0ecf03@ti.com> Content-Language: en-US From: Siddharth Vadapalli In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 21:38:28 -0700 (PDT) On 18/10/23 17:45, Serge Semin wrote: > On Wed, Oct 18, 2023 at 05:26:53PM +0530, Siddharth Vadapalli wrote: >> >> ... >> >> Even before commit 6ab15b5e7057, with support for AM654x (using version 4.90a >> DWC PCIe IP-core) already present, ks_pcie_ops was being used for AM654x. This >> indicates that prior to commit 6ab15b5e7057, the ks_pcie_ops was applicable to >> AM654x and there's no problem. However, when commit 6ab15b5e7057 converted the >> .scan_bus() method in ks_pcie_host_ops (which wasn't used for AM654x) to >> .add_bus(), it added the method within the shared ks_pcie_ops structure which >> implicitly, *mistakenly*, assumes that a function named "ks_pcie_v3_65_add_bus" >> is also applicable to other controller versions (4.90a in this case). Paying >> attention to the name of the function, it becomes clear that it was added for >> controller version "3.65", hence the name "...v3_65...". The assumption that the >> function/method is applicable to other controller versions as well, was >> incorrect which led to the current issue that can be observed. The commit >> 6ab15b5e7057 ended up adding a new method for a controller version which *never* >> used the method. This therefore is a bug. >> > >> The simplest fix I see is that of exiting ks_pcie_v3_65_add_bus() if: >> ks_pcie->is_am6 is set, since such checks have been scattered throughout the >> same driver prior to the addition of commit 6ab15b5e7057 as well. >> >> I am open to other implementations of fixing this issue as well. Kindly let me >> know in case of any suggestions. > > A simplest fix isn't always the best one. As you said yourself the > ks_pcie_v3_65_add_bus() implies having it called for v3.65. Calling it > for the newer controllers was a mistake causing the bug. Thus having > the ks_pcie_ops utilized for both old and new controllers was also a At the point in time when support for the new controller was added, ks_pcie_ops was defined as: static struct pci_ops ks_pcie_ops = { .map_bus = dw_pcie_own_conf_map_bus, .read = pci_generic_config_read, .write = pci_generic_config_write, }; which did not have anything version specific. It is only after commit 6ab15b5e7057 that a version specific .add_bus method was added to ks_pcie_ops, making ks_pcie_ops version-specific since then. > mistake. Therefor my suggestion to fix the problem by defining the two > pci_ops structure instances would be more correct at least from the > code readability point of view. It would make the > ks_pcie_v3_65_add_bus() function body and name coherent. Sure. Thank you for the suggestion. I will leave ks_pcie_ops as-is for the older 3.65 controller while adding the ks_pcie_am6_ops without the .add_bus method for the newer 4.90 controller. I assume this should be acceptable since the pci-keystone.c driver only has two controller versions, namely 3.65a and 4.90a, with the new 4.90a controller only applicable to AM654x SoC which is already being distinguished in the driver using the is_am6 flag. In the v3 patch, I will add the following: static struct pci_ops ks_pcie_am6_ops = { .map_bus = dw_pcie_own_conf_map_bus, .read = pci_generic_config_read, .write = pci_generic_config_write, }; and also update ks_pcie_host_init() to the following: if(ks_pcie->is_am6) pp->bridge->ops = &ks_pcie_am6_ops; else pp->bridge->ops = &ks_pcie_ops; > > Meanwhile your fix look more like a workaround. The > ks_pcie_v3_65_add_bus() function will be still called for the AM6x > v4.90 controllers, which based on its semantic would be and will be > wrong in any case. So instead of noop-ing the function it would be > better to just drop it being called for the new controllers. Yes, I will drop it for the new 4.90a controller rather than making it a no-op. > > -Serge(y) > >> >>> >>> -Serge(y) >>> >>>> return 0; >>>> >>>> /* Configure and set up BAR0 */ >>>> -- >>>> 2.34.1 >>>> >> >> -- >> Regards, >> Siddharth. -- Regards, Siddharth.