Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp172225imd; Wed, 31 Oct 2018 16:46:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5f4omlHzKzdS0tYGS/5Qlkel5LtoCVBGajJ5XfADWVG5wvtuletzM98EvqCT29iTn7NbQ6z X-Received: by 2002:a62:1693:: with SMTP id 141-v6mr5532017pfw.183.1541029586645; Wed, 31 Oct 2018 16:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029586; cv=none; d=google.com; s=arc-20160816; b=oayK6Ekyk34v7U8frHLymrJTqg69ZQ/qHbEqDahNwLuV6MHuE8ZGoGKbSS6Y9Tjbh5 m0VosTtGj4u69M4U473td57UsEjllPuaZuK7WoSRrWgfvxhaqr9EATbA48JaVKjpRCuh syyWleJsaM57tGumdgRqXQxfKGlbHUjQR7Wdicn7IcMh4uPHTawtlrknC2eblPWhyZKb 8kdXG3/rwbT7//5SIPW6M0lPeW2Ot8um7InSaJ3HK2jJoN5yObTpuMX//Ewb52t3Le/z tdOThCFZNsEEbcwso/EnDnixt7vSA62PxUatVKMDNfc8xxq0cX/FIJfq1zebYSGUBGqw 1jlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=2i0xHmdc7QFPHhIq4ewijnreHdf2IZzTJCZxVRBQU+E=; b=x8nvxGcwPOKb86PhMyo+Uqp+24sKpIREfxJhoKRdAp+z2WgBLsf2vnUjNckzWokcfI YZyJSpc71uqplUMU9XMf6pMmsdHchuD7W63QdOh7eT9dBdu6dNlgE1xYe/lkpyU4xC7I rHFDIV4PO1ayYTKrRZ35cvMn60KsmMKXPbUXPX6oFGUvceSRY172tJgI15B0ch5EwxRY nIrcafvllGUgJ72BXCpd3gh9+hMSbnEWSRaeKea37oydwPUizCK/SfqjMgkihKL6a7tI 4nn3zXJGxbwZH0eFGr4JD+1HNhi9lcAUjCBE97cAapPUxek8CD2n1P5st9/ATRRVSX14 VKuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=miqS8k2n; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12-v6si27377403pgo.136.2018.10.31.16.46.12; Wed, 31 Oct 2018 16:46:26 -0700 (PDT) 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=miqS8k2n; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728903AbeKAIH0 (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbeKAIH0 (ORCPT ); Thu, 1 Nov 2018 04:07:26 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0205620830; Wed, 31 Oct 2018 23:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027235; bh=GZvI6+ZUhrjC2GF5Z5vETFphxwnIvDDokVS7VhFE/Jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=miqS8k2nXFR4hkH3KOAphzR+Vsb4vGnHvuNiBp+rZfu8/pzzkNDTRrg+wlsd0ZO04 Lp2av6/3Lr7WPd63QJJdFqDRvsrik1/vZXzYxX+rJnfJJK9kXVdc0hY2x9HpxXsrUQ NhzpiLWyWzS5SpFQvipEehqJ5FD5cr1m6mjYtMBM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Honghui Zhang , Lorenzo Pieralisi , Sasha Levin Subject: [PATCH AUTOSEL 4.19 103/146] PCI: mediatek: Fix mtk_pcie_find_port() endpoint/port matching logic Date: Wed, 31 Oct 2018 19:04:58 -0400 Message-Id: <20181031230541.28822-103-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/pci/controller/pcie-mediatek.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 861dda69f366..c5ff6ca65eab 100644 --- 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_find_port(struct pci_bus *bus, { 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)) -- 2.17.1