Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3435902imu; Sun, 11 Nov 2018 15:03:44 -0800 (PST) X-Google-Smtp-Source: AJdET5frPbr5EU3YpPRJs9BmBue0z0DEQDlpcFO22bew7/17RbFkLmSf4Pu2mrZzW9JIyePDfndh X-Received: by 2002:a17:902:bf03:: with SMTP id bi3-v6mr1092375plb.288.1541977424008; Sun, 11 Nov 2018 15:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977423; cv=none; d=google.com; s=arc-20160816; b=mkQ19aazjf5CpLJqF+h7GDI+ksnDQWq5yCAgbM8wFt1SRMjFTnWtsHBooEzfh1xloP EiKNwbyGvn7zUAoTYOqVvNKVlhcHp3uuTFHH9wY4qTiM7VW1ldENv1F9Gz/vGWfDDwQo 0oG0XTHjSckBiSPgzth0lhB3P+b1RQMo6Ix/KiPhB4MTi4xiRJ1bheswt5RTif5tT2ly ybHj1HsnqPu/V6ps0ABkTNLDRQHRfXoo3JkiQ3s2JS+e8cbdlp11H9Y5vsl2B5YTGNCA Hzx/L+OCeQU0xqB3Zlfl238iWQ9hEG9/98DXVE9DCYpUkqh12MPr4SOiSIX+3/GUlHzx r0qw== 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=9sIA1tJlU/HhMNnVB9O0eiBrqOBu3f8372F1iVTc8Q0=; b=dkqfPRLuelITsVT2TZdFAbHZdRZvIlzfk8SRbdTPujlEZfMXS5RAFYcv+mgASGGSaA xfSDy0B+EUfJq8MPH+1z9qc1xJ3f674GrZ9LkIDqaaEPSsr/iFzppsG4ObAqSc5b2eiD SBUApl2cGbOHIzznwAOlfYu+As8+GQE6HEQ/v8Eb+ttV59mN6Zz0DsASC9tzwi1IHuaO gUlyWWbt/raj8HjpgM9TG12EPvO/NkiKSOeIpnNUFnjxI/ckf4OPmxXxHMdB5dNzMecO tTt8OMwomNHkw6q370+xadjWQ9GLh0NJ3iUSxFghsCQKc9ygUrHdz8Mvt6VIR+7JCYgZ BcYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QPGrqFrt; 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 a4-v6si17198441pln.67.2018.11.11.15.03.29; Sun, 11 Nov 2018 15:03:43 -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=QPGrqFrt; 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 S2390660AbeKLIxQ (ORCPT + 99 others); Mon, 12 Nov 2018 03:53:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:52394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390575AbeKLIWZ (ORCPT ); Mon, 12 Nov 2018 03:22:25 -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 C6BD6223CA; Sun, 11 Nov 2018 22:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975548; bh=VsVEdV1nPKYy8HdGF9eaop3TvIPTLHO7wQG9rcTVMrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QPGrqFrtBTI7qZe1yrIRzKNMFnXpBW6tfs7w0oZnbR+oTo629RwT/OHsOxmHzzWHG A2z23mrgcJh+Czq9WCuhwlxQ9CihKHK2S7Rk2mVkbZKFG6f2mmAcTaCwxmPX7F7yeG sE4NdZIuMFnapDa8Bv9PbpYJ/DkXmIRLVDGHqcsY= 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.14 085/222] PCI: mediatek: Fix mtk_pcie_find_port() endpoint/port matching logic Date: Sun, 11 Nov 2018 14:23:02 -0800 Message-Id: <20181111221655.611452995@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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/host/pcie-mediatek.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/pci/host/pcie-mediatek.c +++ b/drivers/pci/host/pcie-mediatek.c @@ -333,6 +333,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))