Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3482969imu; Sun, 11 Nov 2018 16:07:23 -0800 (PST) X-Google-Smtp-Source: AJdET5f/pxwimqlzH5ME7EZL/tS4ipTalkxswusQQ5Ze5nZc4JdXoP2A1D9MobMW6K2JLr+yaKD/ X-Received: by 2002:a17:902:9a47:: with SMTP id x7-v6mr17911006plv.316.1541981243784; Sun, 11 Nov 2018 16:07:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981243; cv=none; d=google.com; s=arc-20160816; b=dMlcefBYlyIILf2YV3bzVfd9mDljYEtgUsOKCzBW6S56ZDN9rHswhsqUXw7HAzVM/3 LTLazumGm+optkkMrF4Tf49qzfyz8aRXmRCoX/P+27lXFKMVlAX56HUqvyQvuo9Qp4Mh fpJXgOpurDJpseQi5ntSMYyHysra1CejVxECt2SlFUC6AFpQG1fIGH850LaBT6MirFVj JufV+CSFGwZItWiJK/gX3hd6T2YU8SweYcfOqM9cvDybW4qQb9WFoFDXRuZRvb/XBvyS SRn2YMX42Fba6/yF58EdItElGoszNmCAXOzydqoRtmz/LFB1LoQXBTvrZOlVHJH+ogvV JRug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+buBKSgZ2MTaMnnVaE49bqlDL9HtB+GNDJg/e9l+ebw=; b=lYM9ki5EXA3XTGUFkb1YJJOdyeQkiGTmPe8xJruRDmQjIf/TL+WIJ7AToxy0DXqZa4 COzRWIr5HpvD9oOp8S+v0Yqczv96/qxhK9e0bKd4ua9s1YDtuNeApQOrcn3zuJXV8j8z J7NlMboVrU75ju/6bkCDGGMb5rYD07IPYnJiefn87hoeiwJVoxt8L+IEHzTxOKWhwxI8 rnIY4DW3KAQ8na0mFjx6qkNsqWzqwlFlkhN/oC5XNCQfrbggd0b2ke9IP8g6hbKQ+ODk LvmXQYYZIzEJRA8NqsDU7U8YivItcKWCGJFWvcbn/I09cmNk/sXxJ0F83unyyd+7Nfo5 crBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gy3GuuAS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z136si13651887pgz.28.2018.11.11.16.07.08; Sun, 11 Nov 2018 16:07:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gy3GuuAS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731812AbeKLIRi (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:33814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731776AbeKLIRh (ORCPT ); Mon, 12 Nov 2018 03:17:37 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1AE9B21508; Sun, 11 Nov 2018 22:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975262; bh=KZ4k9XOt6P4z3l7C+9MnBI9aFjB+MHlfhxHjQ6XKVP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gy3GuuAS9NeWDQm75gsjWz5b/w94afKStVhE3FcSK0y+ko7YnZ1yLmMmjWpM+CQ2t yGjvVXcVX0O4isE/Hnt/2kD76XdwltCBXcEH4oelNmyuH2IOFNYWCfdZjP/LFRyQCg zEsreza7bbxB0ZMWHSr+NA5z4n0DXzOrpryTYn34= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Honghui Zhang , Lorenzo Pieralisi , Ryder Lee , Sasha Levin Subject: [PATCH 4.19 148/361] PCI: mediatek: Fix mtk_pcie_find_port() endpoint/port matching logic Date: Sun, 11 Nov 2018 14:18:15 -0800 Message-Id: <20181111221641.145728287@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Honghui Zhang [ Upstream commit 074d6f32689ce05a084b6fa3db38445745bf11cc ] The Mediatek's host controller has two slots, each with its own control registers. The host driver needs to identify what slot is connected to what port in order to access the device's configuration space. Current code retrieving slot connected to a given endpoint device. Assuming each slot is connected to one endpoint device as below: host bridge bus 0 --> __________|_______ | | | | slot 0 slot 1 bus 1 -->| bus 2 --> | | | EP 0 EP 1 During PCI enumeration, system software will scan all the PCI devices on every bus starting from devfn 0. Using PCI_SLOT(devfn) for matching an endpoint to its slot is erroneous in that the devfn does not contain the hierarchical bus numbering in it. In order to match an endpoint with its slot (and related port), the PCI tree must be walked up to the root bus (where the root ports are situated) and then the PCI_SLOT(devfn) matching logic can be correctly applied for matching. This patch fixes the mtk_pcie_find_port() slot matching logic by adding appropriate PCI tree walking code to retrieve the slot/port a given endpoint is connected to. Signed-off-by: Honghui Zhang [lorenzo.pieralisi@arm.com: rewrote the commit log] Signed-off-by: Lorenzo Pieralisi Acked-by: Ryder Lee Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pcie-mediatek.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -337,6 +337,17 @@ static struct mtk_pcie_port *mtk_pcie_fi { struct mtk_pcie *pcie = bus->sysdata; struct mtk_pcie_port *port; + struct pci_dev *dev = NULL; + + /* + * Walk the bus hierarchy to get the devfn value + * of the port in the root bus. + */ + while (bus && bus->number) { + dev = bus->self; + bus = dev->bus; + devfn = dev->devfn; + } list_for_each_entry(port, &pcie->ports, list) if (port->slot == PCI_SLOT(devfn))