Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1528700pxk; Fri, 2 Oct 2020 11:50:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOG8ethcJodDrHOtsoIt+J4xEMuWkKGsiTY3XVfYTJ1cuoBw+alX85zsD6migG1LV00916 X-Received: by 2002:a17:906:370a:: with SMTP id d10mr3832391ejc.393.1601664604931; Fri, 02 Oct 2020 11:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601664604; cv=none; d=google.com; s=arc-20160816; b=xURAAmSWXtlr8R9EtrcV97hdyWF9jhpP1YBFdBVvYfif3cgrj4qNSSDMXtJOLjT8Pb rhpNoPrfKfFDNalESS3PTz2V3iDYo6bYQ+f7CrfJPBG0xchEQy3OkoRBlOrVt70YUT4c dkiX1Ncxqj0GbwCTkcXW61NJ3lDaCq68y6wbhFe7DTTMfmx6vheKSKAKruixhzebCBcv gIO3kr8QHbR9R0at6BDP8eOV9vEXnTh5NZrN0FIoJo2CyW7F+FTo293KxuEw1JYUbFxE lKmyownbvTUmJVJAS0HM00Txr5Q9W6t/ndLQQA2gABhy+THqeVaaNW7GH2Ob9/9pe8GP I/7g== 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-signature; bh=t0uKDJq27vNzBDRDYM5SRRTTNMGSpWZb8xaUcJWhNTE=; b=T+LAqTJkPHCfWO1iL53j9n2RgqxF7dQ0mxKSgqMvSBXtyHR3yS1r2qEJCDzaErJmXq 5vZxQhoqcE7Nd5NKWwq9R9kVSsL5SXIKYoDtRRv/i04OW1LDmiavZNhu0BNM+0azqumN 1yvIBafn71DCnN42nbsHgK5aI4KIyQe2kM4HcnajdL0ccfzFm8gbV/n1kJ6zXc2SYD9y JtZu/SSaI7zQPKsE/kFFwHt49BbKpdXSStCGIeUMHCrVD9bmsFLjPZY9eFE2GDR9BC/4 tYiXC6gd1cODIfMwIC2OGUYvB/B5PCIOvNUpVHWEangnTZI36sHWOB5m6HBLbtE/0hfr 5Rfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oregontracks.org header.s=fm1 header.b=cnTiJBVT; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gpX9yEma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e15si160976edr.306.2020.10.02.11.49.42; Fri, 02 Oct 2020 11:50:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oregontracks.org header.s=fm1 header.b=cnTiJBVT; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gpX9yEma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388443AbgJBSsV (ORCPT + 99 others); Fri, 2 Oct 2020 14:48:21 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:51303 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388415AbgJBSsO (ORCPT ); Fri, 2 Oct 2020 14:48:14 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 58BBC5C0158; Fri, 2 Oct 2020 14:48:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 02 Oct 2020 14:48:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= oregontracks.org; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm1; bh=t0uKDJq27vNzBDRDYM5SRRTTNMGSpWZb8xaUcJWhNTE=; b=cnTiJ BVT1d4QW9PJljrBNDph95tvHP3LKwR/DiOMqa2LxcHi1FzUPZPr53+u+7In4cwD9 Bgx4/zZUi4P07JM5HlhZCR6eaCPn1AODGhSlpptW+sEFl89I9hchxlNPFK69zZr3 JZcqIbj3meHYGy0Pkf98O4TFwSJHT2XYNkPuKwvo7LsDy47QMnUUrwWuZF9ttk8G va/i7eWv+SoGYLP4m13rWkXqEyheueKgouu/HlEdxIf2AA9yVlwiD43oTTn1Q4aq ovd4DPzP/eebWuwKVTEbdwNZ40iA7iOxi8yNvbtDsLb+JAPQB5WGMQ5QQ10LUeSy yEcZ6IoPIhsTrZLmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=t0uKDJq27vNzBDRDYM5SRRTTNMGSpWZb8xaUcJWhNTE=; b=gpX9yEma Yf5dL33U0PeouLffE60/vhSGG2fowJWug8sD4TkE5zprE/hDH/6BtbY1JlOSX9Y2 ASbtlGixXRKw7mkTe2kKKRU5l0soOuQXaCnj48S6Wy338BO32ORRosHS5Dia0dNY B4ER6uFCY2KyTEl8B0t0crzue+A9NzMyHBBXXNX33bpbll87OxAbtapnEa6vLqBf diu3s4jq4H5z5U31/ubwbLixCSHVa7ZwdUEIqb170UyJy/GwikZq16e+rTeqsArp KPtB0lP/mQuLIzvQUWCPKpa3fV7kE0UpH5al4Sad4ZJ/ZugXdxysnubjzefp1rKb ylwtJvhSwn6t6A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrfeeigdduvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepufgvrghnucggucfmvghllhgvhicuoehsvggrnhhvkhdruggv vhesohhrvghgohhnthhrrggtkhhsrdhorhhgqeenucggtffrrghtthgvrhhnpeehkeffte eiudeiffelkeelvefftdelhfeitdeigeffleeufedvgfegvdefvedtteenucfkphepvdeg rddvtddrudegkedrgeelnecuvehluhhsthgvrhfuihiivgepkeenucfrrghrrghmpehmrg hilhhfrhhomhepshgvrghnvhhkrdguvghvsehorhgvghhonhhtrhgrtghkshdrohhrgh X-ME-Proxy: Received: from arch-ashland-svkelley.hsd1.or.comcast.net (c-24-20-148-49.hsd1.or.comcast.net [24.20.148.49]) by mail.messagingengine.com (Postfix) with ESMTPA id CA89F3064688; Fri, 2 Oct 2020 14:48:10 -0400 (EDT) From: Sean V Kelley To: bhelgaas@google.com, Jonathan.Cameron@huawei.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@intel.com, qiuxu.zhuo@intel.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Sean V Kelley Subject: [PATCH v8 10/14] PCI/RCEC: Add pcie_link_rcec() to associate RCiEPs Date: Fri, 2 Oct 2020 11:47:31 -0700 Message-Id: <20201002184735.1229220-11-seanvk.dev@oregontracks.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002184735.1229220-1-seanvk.dev@oregontracks.org> References: <20201002184735.1229220-1-seanvk.dev@oregontracks.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean V Kelley A Root Complex Event Collector provides support for terminating error and PME messages from associated RCiEPs. Make use of the RCEC Endpoint Association Extended Capability to identify associated RCiEPs. Link the associated RCiEPs as the RCECs are enumerated. Co-developed-by: Qiuxu Zhuo Signed-off-by: Qiuxu Zhuo Signed-off-by: Sean V Kelley Reviewed-by: Jonathan Cameron --- drivers/pci/pci.h | 2 + drivers/pci/pcie/portdrv_pci.c | 3 ++ drivers/pci/pcie/rcec.c | 91 ++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 4 files changed, 97 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 98ec87ef780d..ea5716d48b68 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -473,9 +473,11 @@ static inline void pci_dpc_init(struct pci_dev *pdev) {} #ifdef CONFIG_PCIEPORTBUS int pci_rcec_init(struct pci_dev *dev); void pci_rcec_exit(struct pci_dev *dev); +void pcie_link_rcec(struct pci_dev *rcec); #else static inline int pci_rcec_init(struct pci_dev *dev) { return 0; } static inline void pci_rcec_exit(struct pci_dev *dev) {} +static inline void pcie_link_rcec(struct pci_dev *rcec) {} #endif #ifdef CONFIG_PCI_ATS diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 4d880679b9b1..dbeb0155c2c3 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c @@ -110,6 +110,9 @@ static int pcie_portdrv_probe(struct pci_dev *dev, (pci_pcie_type(dev) != PCI_EXP_TYPE_RC_EC))) return -ENODEV; + if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_EC) + pcie_link_rcec(dev); + status = pcie_port_device_register(dev); if (status) return status; diff --git a/drivers/pci/pcie/rcec.c b/drivers/pci/pcie/rcec.c index da02b0af442d..9ba74d8064e9 100644 --- a/drivers/pci/pcie/rcec.c +++ b/drivers/pci/pcie/rcec.c @@ -15,6 +15,97 @@ #include "../pci.h" +struct walk_rcec_data { + struct pci_dev *rcec; + int (*user_callback)(struct pci_dev *dev, void *data); + void *user_data; +}; + +static bool rcec_assoc_rciep(struct pci_dev *rcec, struct pci_dev *rciep) +{ + unsigned long bitmap = rcec->rcec_ea->bitmap; + unsigned int devn; + + /* An RCiEP found on a different bus in range */ + if (rcec->bus->number != rciep->bus->number) + return true; + + /* Same bus, so check bitmap */ + for_each_set_bit(devn, &bitmap, 32) + if (devn == rciep->devfn) + return true; + + return false; +} + +static int link_rcec_helper(struct pci_dev *dev, void *data) +{ + struct walk_rcec_data *rcec_data = data; + struct pci_dev *rcec = rcec_data->rcec; + + if ((pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END) && rcec_assoc_rciep(rcec, dev)) { + dev->rcec = rcec; + pci_dbg(dev, "PME & error events reported via %s\n", pci_name(rcec)); + } + + return 0; +} + +static void walk_rcec(int (*cb)(struct pci_dev *dev, void *data), void *userdata) +{ + struct walk_rcec_data *rcec_data = userdata; + struct pci_dev *rcec = rcec_data->rcec; + u8 nextbusn, lastbusn; + struct pci_bus *bus; + unsigned int bnr; + + if (!rcec->rcec_ea) + return; + + /* Walk own bus for bitmap based association */ + pci_walk_bus(rcec->bus, cb, rcec_data); + + nextbusn = rcec->rcec_ea->nextbusn; + lastbusn = rcec->rcec_ea->lastbusn; + + /* All RCiEP devices are on the same bus as the RCEC */ + if (nextbusn == 0xff && lastbusn == 0x00) + return; + + for (bnr = nextbusn; bnr <= lastbusn; bnr++) { + /* No association indicated (PCIe 5.0-1, 7.9.10.3) */ + if (bnr == rcec->bus->number) + continue; + + bus = pci_find_bus(pci_domain_nr(rcec->bus), bnr); + if (!bus) + continue; + + /* Find RCiEP devices on the given bus ranges */ + pci_walk_bus(bus, cb, rcec_data); + } +} + +/** + * pcie_link_rcec - Link RCiEP devices associating with RCEC. + * @rcec RCEC whose RCiEP devices should be linked. + * + * Link the given RCEC to each RCiEP device found. + */ +void pcie_link_rcec(struct pci_dev *rcec) +{ + struct walk_rcec_data rcec_data; + + if (!rcec->rcec_ea) + return; + + rcec_data.rcec = rcec; + rcec_data.user_callback = NULL; + rcec_data.user_data = NULL; + + walk_rcec(link_rcec_helper, &rcec_data); +} + int pci_rcec_init(struct pci_dev *dev) { struct rcec_ea *rcec_ea; diff --git a/include/linux/pci.h b/include/linux/pci.h index 2290439e8bc0..e546b16b13c1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -330,6 +330,7 @@ struct pci_dev { #endif #ifdef CONFIG_PCIEPORTBUS struct rcec_ea *rcec_ea; /* RCEC cached endpoint association */ + struct pci_dev *rcec; /* Associated RCEC device */ #endif u8 pcie_cap; /* PCIe capability offset */ u8 msi_cap; /* MSI capability offset */ -- 2.28.0