Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4278988imm; Fri, 18 May 2018 02:21:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGu5+7G4vHIHrsuGdrztBg5rcZNw5rgN8kCEVD/AFuYd34gcnh9c8nvcf3hvxV6Opz717q X-Received: by 2002:a62:f20d:: with SMTP id m13-v6mr8703143pfh.170.1526635304145; Fri, 18 May 2018 02:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526635304; cv=none; d=google.com; s=arc-20160816; b=IdurLJDseLO/CLhMluILKcyya1zup01STjb5Q9OFjvHs0ArCLi4UA0y7kVt4ZaM9pp LiOKrmZoalNq//Fv81OF0sjy3QKnlZzB/rjk0JXIBjjbcqos/j05fInIY2046bWmwlBY PQfg66wfvHfxf6B11td46Q9GsxhphaJOyDSlKoVXRWF/WcNCoE9aoEI7LwMxsnWe32UY XFn4cYDpGwgC34EVEsqJrLbopZB7/WajPBKweJNSNE2J0tv/cUthNf/0borvbCNA0/Vu aW1eXEQbY0qeKdvSfaH9Qvs9u71vjes/Fou48Guyv6KNJ4httYDsSJEh1Mgv0lvNzl8G eYmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=DrFowBlJ3H0ZD3I+FDRqSY25js1LcI9yBjI4uIs91t0=; b=OTmJvGdq7PcwMuhYiPpsZYvQlzuDSfUWJd3tMqRP4M1NF4jOVH/IPRUCa1a5iPVbpY 5fYMYdGlYAkzN9AL4BOqBjJTX+HMeyP9WOAQ/Qd943NxwoGXKodsiUSnOqPPK/qgIbsq 7ufknqRv/jP6jHU6DKqL7F1xOJXXlY0Bt+oD8BE8t/zoTmexa65OEy1CmLlygi/0ITyn WtKLDZ2zDt8XNydSoPytK4yqKK/HsQo0WbNSCdjAYYxCpY8yroGB9HXB1bfISDE9tyG3 wzrcRsd4aVFp5W9z5hq+FGZ9VVPTkf9GepE8gIXZUgQFbpkhVQoVe02b5hvyHiYmclZg Fcsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Rl5RpbXV; dkim=pass header.i=@codeaurora.org header.s=default header.b=RrGDKEX3; 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 q11-v6si5612208pgc.669.2018.05.18.02.21.29; Fri, 18 May 2018 02:21:44 -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=@codeaurora.org header.s=default header.b=Rl5RpbXV; dkim=pass header.i=@codeaurora.org header.s=default header.b=RrGDKEX3; 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 S1753137AbeERJUL (ORCPT + 99 others); Fri, 18 May 2018 05:20:11 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58094 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752947AbeERJTt (ORCPT ); Fri, 18 May 2018 05:19:49 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 78BB2609D1; Fri, 18 May 2018 09:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526635187; bh=HqA3KBGx6zVn8ON+10qnTjoEqltEd9b7Ry5QPGNYUUY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Rl5RpbXVlseNXnFr3RdlvrTBx/XjNk1WwM3rh8Ywusoy3tX9pfuZ9kUxlSsyavB3/ KGrkejsoMkH02fd/Du21OWaJhGmVvna6QzrY9MaGLlWBj0YSMmKA3fSiizbZLPEMNU +O+82WK04FfCHJqkJFhhAT71JYRH1zlXiyyODkJc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 690456055C; Fri, 18 May 2018 09:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526635186; bh=HqA3KBGx6zVn8ON+10qnTjoEqltEd9b7Ry5QPGNYUUY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RrGDKEX3W7SixieRHvgCvN9OkBJf5I+HoYujF+EjhVL0C/WdUm57TyyZv5gzFMiJ2 DpFQGknbJpdRbKkgQJNEYsNcUzGoKhm8LpywyYRcdJxk1NW8N19WviZjLNLE3dd/VC +Fn7vsIYmFSudRn3wKWr7i+l8E3zm1TV1F/m7/Z8= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 18 May 2018 14:49:46 +0530 From: poza@codeaurora.org To: Ray Jui Cc: Bjorn Helgaas , Lorenzo Pieralisi , Bjorn Helgaas , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, Ray Jui , linux-pci-owner@vger.kernel.org Subject: Re: [PATCH INTERNAL 2/3] PCI: iproc: Fix up corrupted PAXC root complex config registers In-Reply-To: <1526577692-21104-3-git-send-email-ray.jui@broadcom.com> References: <1526577692-21104-1-git-send-email-ray.jui@broadcom.com> <1526577692-21104-3-git-send-email-ray.jui@broadcom.com> Message-ID: X-Sender: poza@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-17 22:51, Ray Jui wrote: > 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 based on readings from the PCIe capability structure > > Signed-off-by: Ray Jui > Reviewed-by: Anup Patel > Reviewed-by: Scott Branden > --- > drivers/pci/quirks.c | 95 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 95 insertions(+) > > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c > index 47dfea0..0cdbd0a 100644 > --- a/drivers/pci/quirks.c > +++ b/drivers/pci/quirks.c > @@ -2198,6 +2198,101 @@ > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16f0, > quirk_paxc_bridge); > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd750, > quirk_paxc_bridge); > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd802, > quirk_paxc_bridge); > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd804, > quirk_paxc_bridge); > + > +/* > + * The PCI capabilities list for certain revisions of Broadcom PAXC > root > + * complexes is incorrectly terminated due to corrupted configuration > space > + * registers in the range of 0x50 - 0x5f > + * > + * As a result, the capability list becomes broken and prevent > standard PCI > + * stack from being able to traverse to the PCIe capability structure > + */ > +static void quirk_paxc_pcie_capability(struct pci_dev *pdev) > +{ > + int pos, i = 0; > + u8 next_cap; > + u16 reg16, *cap; > + struct pci_cap_saved_state *state; > + > + /* bail out if PCIe capability can be found */ > + if (pdev->pcie_cap || pci_find_capability(pdev, PCI_CAP_ID_EXP)) > + return; > + > + /* locate the power management capability */ > + pos = pci_find_capability(pdev, PCI_CAP_ID_PM); > + if (!pos) > + return; > + > + /* bail out if the next capability pointer is not 0x50/0x58 */ > + pci_read_config_byte(pdev, pos + 1, &next_cap); > + if (next_cap != 0x50 && next_cap != 0x58) > + return; > + > + /* bail out if we do not terminate at 0x50/0x58 */ > + pos = next_cap; > + pci_read_config_byte(pdev, pos + 1, &next_cap); > + if (next_cap != 0x00) > + return; > + > + /* > + * On these buggy HW, PCIe capability structure is expected to be at > + * 0xac and should terminate the list > + * > + * Borrow the similar logic from theIntel DH895xCC VFs fixup to save :%s /theIntel /Intel > + * the PCIe capability list > + */ > + pos = 0xac; > + pci_read_config_word(pdev, pos, ®16); > + if (reg16 == (0x0000 | PCI_CAP_ID_EXP)) { > + u32 status; > + > +#ifndef PCI_EXP_SAVE_REGS > +#define PCI_EXP_SAVE_REGS 7 > +#endif > + int size = PCI_EXP_SAVE_REGS * sizeof(u16); > + > + pdev->pcie_cap = pos; > + pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, ®16); > + pdev->pcie_flags_reg = reg16; > + pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, ®16); > + pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; > + > + pdev->cfg_size = PCI_CFG_SPACE_EXP_SIZE; > + if (pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status) != > + PCIBIOS_SUCCESSFUL || (status == 0xffffffff)) > + pdev->cfg_size = PCI_CFG_SPACE_SIZE; > + > + if (pci_find_saved_cap(pdev, PCI_CAP_ID_EXP)) > + return; > + > + state = kzalloc(sizeof(*state) + size, GFP_KERNEL); > + if (!state) > + return; > + > + state->cap.cap_nr = PCI_CAP_ID_EXP; > + state->cap.cap_extended = 0; > + state->cap.size = size; > + cap = (u16 *)&state->cap.data[0]; > + pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_RTCTL, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_DEVCTL2, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_LNKCTL2, &cap[i++]); > + pcie_capability_read_word(pdev, PCI_EXP_SLTCTL2, &cap[i++]); > + hlist_add_head(&state->next, &pdev->saved_cap_space); > + } > +} > +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, > PCI_DEVICE_ID_NX2_57810, > + quirk_paxc_pcie_capability); > +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16cd, > + quirk_paxc_pcie_capability); > +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x16f0, > + quirk_paxc_pcie_capability); > +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd802, > + quirk_paxc_pcie_capability); > +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0xd804, > + quirk_paxc_pcie_capability); > #endif > > /* Originally in EDAC sources for i82875P: