Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4685900imm; Mon, 11 Jun 2018 17:23:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKa65+V+70mIwVinAf8GgP2dPgIHaN2KKxu5fCRlPSKeJlgg7Q7CNf7FKAqPVWrfdPa9bzp X-Received: by 2002:a17:902:b60c:: with SMTP id b12-v6mr1453738pls.44.1528763012368; Mon, 11 Jun 2018 17:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528763012; cv=none; d=google.com; s=arc-20160816; b=ucsAon1jsWSbw04SPzbAkHi5x+14q+heJmBvQfUtbjA0KUm6VqGz+T3mu5tF2TXc0s 91xj8eNtx1OybHpdui5ajhmleMO5XRnUiHLmHWtsYWJ0+L8vhK3+cala7dq1I6JhszKo zFmYL1TnfrUoHga0cLobRhjLW9ySifYfxtPyxfMl2+v2lk2P9kHFvZjrdM1hyNiq/aV5 I/7d/M1UIdY6u3YLP3rXFYcSTCQAWIyqLFNTvhEoF0mTaA4vk423MDxmyMItzENe9WTp GBnPuomH4bmcntinKvDRmRK+C01BLl31eui6JxekYEYSAJHy4djxuF0Bl6OXGn+i+ZSq 3Y3g== 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:arc-authentication-results; bh=iP6AbfiWeNEKpQjP3offaSqR26PzJ/i8yHSP9WMZMPY=; b=zuawSrPPnNWRYUfR2P2JEvvjVM4Wf9YWlmbnGIhv2QRqBH88AQO+vrY+qFV72qTT53 CB8xW9LxTiK+E2dDGTPt4dNLlPSQ7Iv89YyttaZwgi2/uUxrtx6e3FKBv8Z5L41/h+BH UPo5BURf+rcekp9jjsg7h81atqBrP+0gWE62IdPLto/0RJeqjD1Z4ZSrBh8e7EImUFnS W0Ies6R769IKRLPW84No22ap7w18T/tXmuH2bdZAPqMhRfZ/2cNU1zk6Vre67xWAM/Nz cWRRVitj2W8bUohpk/OL8sbK227MExn+MGAe7YEPxSrfqILxvD2vGHgYZVVIjUzrfRD3 LUpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Af8tAT77; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19-v6si40171562pls.139.2018.06.11.17.23.18; Mon, 11 Jun 2018 17:23:32 -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=@broadcom.com header.s=google header.b=Af8tAT77; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934662AbeFLAV3 (ORCPT + 99 others); Mon, 11 Jun 2018 20:21:29 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:34017 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934625AbeFLAV0 (ORCPT ); Mon, 11 Jun 2018 20:21:26 -0400 Received: by mail-qt0-f195.google.com with SMTP id d3-v6so22162448qto.1 for ; Mon, 11 Jun 2018 17:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iP6AbfiWeNEKpQjP3offaSqR26PzJ/i8yHSP9WMZMPY=; b=Af8tAT77k9+ZYn4FIt5ob2R3agxznvrY/krYRFRNWIAFsgPETenJOR7OtC/jlIGCFA AuUKRDwfDgjX0uABZTMIy2qSSG7VcCrnigNAW6K+4Izbzo3WJUXEx/H8G+/xG+c0ExPe CYAxr95tx0iiTl7kDJlhMBI4w8ecHdo67l6e4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iP6AbfiWeNEKpQjP3offaSqR26PzJ/i8yHSP9WMZMPY=; b=qR/AxX8Z8SS8WT6Os78G7RBu1yGonNZcF0qpsicD7CAJtFUySgrw2OUSKYIK9mZ80N d/tcnXza3TXBDMIRrPVxZA1UR8Pkcwaph7q2DSFMBSUF0otUTPRXJ86R7zjb2FdX2i7h pGCV3YLaKoJcHHzSuvzbCbjY5Kc136qj0D5O8s8vj+7+Uv8fY+abOw5fNyu/K2bRDQzu N7RoiYqYjYkQRx6+XVCgSiElCddqE6vU5I/5uQTGsmbBys+hvjk/cJ6vp0Fpiq58ZvkY XumEloj3ezJIEAiEy62Z9R512+0QsGHKrxTOEJSXnG8p3YHVfhStdL2EyacjLFIh/OV7 B8Rg== X-Gm-Message-State: APt69E0a41x+iMWAwme2QBq99lAlIwwXyIIo6Cmp2l6k/ZNB3IE7F6JJ 6PWFZYVrpR9fUzdLaG9nTMJg29QRs/8= X-Received: by 2002:a0c:b203:: with SMTP id x3-v6mr1395586qvd.86.1528762885296; Mon, 11 Jun 2018 17:21:25 -0700 (PDT) Received: from lbrmn-lnxub44-1.ric.broadcom.com ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id v26-v6sm31470299qtc.12.2018.06.11.17.21.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jun 2018 17:21:24 -0700 (PDT) From: Ray Jui To: Lorenzo Pieralisi , Bjorn Helgaas Cc: Bjorn Helgaas , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, Ray Jui , Ray Jui Subject: [PATCH v2 2/5] PCI: iproc: Fix up corrupted PAXC root complex config registers Date: Mon, 11 Jun 2018 17:21:04 -0700 Message-Id: <1528762867-16823-3-git-send-email-ray.jui@broadcom.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1528762867-16823-1-git-send-email-ray.jui@broadcom.com> References: <1528762867-16823-1-git-send-email-ray.jui@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On certain versions of Broadcom PAXC based root complexes, certain regions of the configuration space are corrupted. As a result, it prevents the Linux PCIe stack from traversing the linked list of the capability registers completely and therefore the root complex is not advertised as "PCIe capable". This prevents the correct PCIe RID from being parsed in the kernel PCIe stack. A correct RID is required for mapping to a stream ID from the SMMU or the device ID from the GICv3 ITS This patch fixes up the issue by manually populating the related PCIe capabilities Signed-off-by: Ray Jui --- drivers/pci/host/pcie-iproc.c | 65 +++++++++++++++++++++++++++++++++++++++---- drivers/pci/host/pcie-iproc.h | 3 ++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c index 3c76c5f..680f6b1 100644 --- a/drivers/pci/host/pcie-iproc.c +++ b/drivers/pci/host/pcie-iproc.c @@ -85,6 +85,8 @@ #define IMAP_VALID_SHIFT 0 #define IMAP_VALID BIT(IMAP_VALID_SHIFT) +#define IPROC_PCI_PM_CAP 0x48 +#define IPROC_PCI_PM_CAP_MASK 0xffff #define IPROC_PCI_EXP_CAP 0xac #define IPROC_PCIE_REG_INVALID 0xffff @@ -375,6 +377,17 @@ static const u16 iproc_pcie_reg_paxc_v2[] = { [IPROC_PCIE_CFG_DATA] = 0x1fc, }; +/* + * List of device IDs of controllers that have corrupted capability list that + * require SW fixup + */ +static const u16 iproc_pcie_corrupt_cap_did[] = { + 0x16cd, + 0x16f0, + 0xd802, + 0xd804 +}; + static inline struct iproc_pcie *iproc_data(struct pci_bus *bus) { struct iproc_pcie *pcie = bus->sysdata; @@ -495,6 +508,49 @@ static unsigned int iproc_pcie_cfg_retry(void __iomem *cfg_data_p) return data; } +static void iproc_pcie_fix_cap(struct iproc_pcie *pcie, int where, u32 *val) +{ + u32 i, dev_id; + + switch (where & ~0x3) { + case PCI_VENDOR_ID: + dev_id = *val >> 16; + + /* + * Activate fixup for those controllers that have corrupted + * capability list registers + */ + for (i = 0; i < ARRAY_SIZE(iproc_pcie_corrupt_cap_did); i++) + if (dev_id == iproc_pcie_corrupt_cap_did[i]) + pcie->fix_paxc_cap = true; + break; + + case IPROC_PCI_PM_CAP: + if (pcie->fix_paxc_cap) { + /* advertise PM, force next capability to PCIe */ + *val &= ~IPROC_PCI_PM_CAP_MASK; + *val |= IPROC_PCI_EXP_CAP << 8 | PCI_CAP_ID_PM; + } + break; + + case IPROC_PCI_EXP_CAP: + if (pcie->fix_paxc_cap) { + /* advertise root port, version 2, terminate here */ + *val = (PCI_EXP_TYPE_ROOT_PORT << 4 | 2) << 16 | + PCI_CAP_ID_EXP; + } + break; + + case IPROC_PCI_EXP_CAP + PCI_EXP_RTCTL: + /* Don't advertise CRS SV support */ + *val &= ~(PCI_EXP_RTCAP_CRSVIS << 16); + break; + + default: + break; + } +} + static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val) { @@ -509,13 +565,10 @@ static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn, /* root complex access */ if (busno == 0) { ret = pci_generic_config_read32(bus, devfn, where, size, val); - if (ret != PCIBIOS_SUCCESSFUL) - return ret; + if (ret == PCIBIOS_SUCCESSFUL) + iproc_pcie_fix_cap(pcie, where, val); - /* Don't advertise CRS SV support */ - if ((where & ~0x3) == IPROC_PCI_EXP_CAP + PCI_EXP_RTCTL) - *val &= ~(PCI_EXP_RTCAP_CRSVIS << 16); - return PCIBIOS_SUCCESSFUL; + return ret; } cfg_data_p = iproc_pcie_map_ep_cfg_reg(pcie, busno, slot, fn, where); diff --git a/drivers/pci/host/pcie-iproc.h b/drivers/pci/host/pcie-iproc.h index 814b600..9d5cfee 100644 --- a/drivers/pci/host/pcie-iproc.h +++ b/drivers/pci/host/pcie-iproc.h @@ -60,6 +60,8 @@ struct iproc_msi; * @ep_is_internal: indicates an internal emulated endpoint device is connected * @has_apb_err_disable: indicates the controller can be configured to prevent * unsupported request from being forwarded as an APB bus error + * @fix_paxc_cap: indicates the controller has corrupted capability list in its + * config space registers and requires SW based fixup * * @need_ob_cfg: indicates SW needs to configure the outbound mapping window * @ob: outbound mapping related parameters @@ -85,6 +87,7 @@ struct iproc_pcie { int (*map_irq)(const struct pci_dev *, u8, u8); bool ep_is_internal; bool has_apb_err_disable; + bool fix_paxc_cap; bool need_ob_cfg; struct iproc_pcie_ob ob; -- 2.1.4