From patchwork Tue Aug 27 16:13:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 2850247 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 57CC09F271 for ; Tue, 27 Aug 2013 16:14:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E025204E0 for ; Tue, 27 Aug 2013 16:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B7B1204DF for ; Tue, 27 Aug 2013 16:14:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753410Ab3H0QOE (ORCPT ); Tue, 27 Aug 2013 12:14:04 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:40650 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753190Ab3H0QOC (ORCPT ); Tue, 27 Aug 2013 12:14:02 -0400 Received: by mail-pa0-f51.google.com with SMTP id lf1so5040768pab.10 for ; Tue, 27 Aug 2013 09:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=5u8JEyMnkAzl1IRoMMST7KiaweeYeQNcvfmxDobjuIM=; b=AGEtOD6P6+A8D1x1sZQ+LIW3ADWCaT0SwYIbhfnA6mry9zTjzD4Prs64H4enkQ17jn dD85MoP23sqktaqNIZF1bJvEMO8Ku9dsqdYRMQh1jzis22pxadXcQEgE7pHWUWEEPQyx qvktLvC6bdPPgN4hvqm6MEePPHalq+YvJdr4Mw7BOCC54qtzAIUedstS6YwFxp2lLa81 QbAd4eQ1doQaOCLAFF9+HpoY1hj6pFVYb0YKsxO7HoBbZ35Jg9UhAYYl40b7An34yrdx xzlYsmAZZTJCQN3Yq3pWD10f2akpGlOIuKh/DA52mKRYJFSmY8TiZC+isQj9qMM0nDrH XnYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=5u8JEyMnkAzl1IRoMMST7KiaweeYeQNcvfmxDobjuIM=; b=Kd4NMg6JTNn/Uy6NLHTh09peotKo81Wno6gqwRFQ59Ir4ACNqHOEE2rZqm63tiby1U kTj8SA+niIIGkHYDXmGR/ylQiQAz7n3kwt69cWsyzChrKu3nWRZq1iPZnIquNRPQPLGE pAJyTwzWKjdExT204Msi65vLGLbxwsO35ihpnPk1+ihBGpJycLeVnO9nn+9sJF7scK3m xZbv3T7q10spflFRHSBzeaNHth5FNys8b9r+JrUEbeoo5n/sGHt5aKHGztABXyD3sBHG gAG41M7I+PEyF305T+VHfOfBWW03CKp0Lwh9hIdPNMIjYVvyYaGexl14Z1DPTOHnvL0K QhtQ== X-Gm-Message-State: ALoCoQlFPUvFW/z5LuVnFuRXRVtQG4WUmjE1ZUxM3mcUEPQpv2wzuh2vY/62xWkBdg4v0odztDou/S9Pt+L47G7ejIXHRcKc+EbBpnSKyi6gTpAqxOK8Mu7AmSRCe83tB1naoGPL+uws0OQHxn1WBr84ErJFeADxWylXV62pcvNZ/PwklyjxOsZW4GbIEs2KQzPzBH9jGlvhONrJCkOcTRI2W1+qMD8sHQ== X-Received: by 10.66.231.42 with SMTP id td10mr10063721pac.144.1377620041534; Tue, 27 Aug 2013 09:14:01 -0700 (PDT) Received: from google.com ([172.19.241.6]) by mx.google.com with ESMTPSA id br3sm25512078pbd.31.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Aug 2013 09:14:00 -0700 (PDT) Date: Tue, 27 Aug 2013 10:13:57 -0600 From: Bjorn Helgaas To: Yuval Mintz Cc: "jacob.e.keller@intel.com" , "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" , Jiang Liu Subject: Re: pcie_get_minimum_link returns 0 width Message-ID: <20130827161357.GA21180@google.com> References: <20130825100157.GA16500@lb-tlvb-yuvalmin.il.broadcom.com> <979A8436335E3744ADCD3A9F2A2B68A52AD136BE@SJEXCHMB10.corp.ad.broadcom.com> <979A8436335E3744ADCD3A9F2A2B68A52AD13D0C@SJEXCHMB10.corp.ad.broadcom.com> <979A8436335E3744ADCD3A9F2A2B68A52AD13FB9@SJEXCHMB10.corp.ad.broadcom.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Aug 27, 2013 at 07:57:20AM -0600, Bjorn Helgaas wrote: > [+cc Jiang] > > On Tue, Aug 27, 2013 at 1:40 AM, Yuval Mintz wrote: > >> On Mon, Aug 26, 2013 at 5:36 PM, Yuval Mintz > >> wrote: > >> >> > Hi, > >> >> > > >> >> > I tried adding support for the newly added 'pcie_get_minimum_link' into > >> >> the > >> >> > bnx2x driver, but found out the some of my devices started showing > >> width > >> >> x0. > >> >> > > >> >> > By adding debug prints, I've found out there were devices up the chain > >> that > >> >> > Showed 0 when their PCI_EXP_LNKSTA was read by said function. > >> >> > However, when I tried looking via lspci the output claimed the width was > >> >> x4. > >> Looking at its implementation, one obvious difference is that > >> pcie_get_minimum_link() traverses up the hierarchy and keeps track of > >> the minimum values it finds. lspci, on the other hand, just reads > >> PCI_EXP_LNKSTA from a single device and decodes it. > >> > >> You said lspci reports x4 for every device from the Root Port all the > >> way down to your NIC, so I would think the minimum from > >> pcie_get_minimum_link() would be x4. But apparently it's not. Maybe > >> there's a bug in it. Can you post the complete "lspci -vv" output > >> along with your debug patch and output? > >> > >> Bjorn > > > > Here's the patch: > > --- > > drivers/pci/pci.c | 8 +++++++- > > 1 files changed, 7 insertions(+), 1 deletions(-) > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index c71e78c..72cb87b 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -3601,13 +3601,19 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, > > enum pcie_link_width next_width; > > > > ret = pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); > > - if (ret) > > + if (ret) { > > + printk(KERN_ERR "Failed to Read LNKSTA\n"); > > return ret; > > + } > > > > next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS]; > > next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >> > > PCI_EXP_LNKSTA_NLW_SHIFT; > > > > + printk(KERN_ERR "LnkSta %04x [%04x:%02x.%02x]\n", > > + lnksta, dev->bus->number, PCI_SLOT(dev->devfn), > > + PCI_FUNC(dev->devfn)); > > I think pcie_cap_has_lnkctl() is incorrect: it currently thinks only > Root Ports, Endpoints, and Legacy Endpoints have link registers. But > I think switch ports (Upstream Ports and Downstream Ports) also have > link registers (PCIe spec r3.0, sec 7.8). Jiang? Yuval, can you try the patch below? PCI: Allow access to link-related registers for switch and bridge ports From: Bjorn Helgaas Every PCIe device has a link, except Root Complex Integrated Endpoints and Root Complex Event Collectors. Previously we didn't give access to PCIe capability link-related registers for Upstream Ports, Downstream Ports, and bridges, so attempts to read PCI_EXP_LNKCTL returned zero. See PCIe spec r3.0, sec 7.8 and 1.3.2.3. Reported-by: Yuval Mintz Signed-off-by: Bjorn Helgaas --- drivers/pci/access.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/access.c b/drivers/pci/access.c index 1cc2366..46dd5ad 100644 --- a/drivers/pci/access.c +++ b/drivers/pci/access.c @@ -485,9 +485,8 @@ static inline bool pcie_cap_has_lnkctl(const struct pci_dev *dev) int type = pci_pcie_type(dev); return pcie_cap_version(dev) > 1 || - type == PCI_EXP_TYPE_ROOT_PORT || - type == PCI_EXP_TYPE_ENDPOINT || - type == PCI_EXP_TYPE_LEG_END; + !(type == PCI_EXP_TYPE_RC_END || + type == PCI_EXP_TYPE_RC_EC); } static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev)