linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Martin Mares <mj@ucw.cz>, Logan Gunthorpe <logang@deltatee.com>
Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-doc@vger.kernel.org, "Stephen Bates" <sbates@raithlin.com>,
	"Christoph Hellwig" <hch@lst.de>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	"Marc Zyngier" <marc.zyngier@arm.com>,
	"Kai-Heng Feng" <kai.heng.feng@canonical.com>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Jérôme Glisse" <jglisse@redhat.com>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: lspci: Display path to device
Date: Tue, 17 Jul 2018 13:39:00 -0700	[thread overview]
Message-ID: <20180717203900.GA1771@bombadil.infradead.org> (raw)
In-Reply-To: <20180717170204.30470-1-logang@deltatee.com>

On Tue, Jul 17, 2018 at 11:02:00AM -0600, Logan Gunthorpe wrote:
> The second patch expands the new helper to optionally take a path of
> PCI devfns. This is to address Alex's renumbering concern when using
> simple bus-devfns. The implementation is essentially how he described it and
> similar to the Intel VT-d spec (Section 8.3.1).

I don't like telling the user to grovel around lspci -t by hand.  It's
not many lines of code to add a new -P option to lspci to show the path
to each device instead of bus:dev.fn

Here's three examples, first without, then with -P.

(my laptop):
6d:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961
00:1d.0/00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961

(tests/PCI-X-bridges-and-domains):
0002:42:00.0 Ethernet controller: Trident Microsystems 4DWave DX (rev 26)
0002:00:02.4/01.0/00.0 Ethernet controller: Trident Microsystems 4DWave DX (rev 26)

(my Nehalem system):
04:00.0 Serial Attached SCSI controller: LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] (rev 02)
00:03.0/00.0/00.0/00.0 Serial Attached SCSI controller: LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] (rev 02)

The Nehalem system makes an interesting testcase because it exposes some
registers in fake PCIe devices that aren't behind the root ports.  eg:

ff:06.3 Host bridge: Intel Corporation Xeon 5500/Core i7 Integrated Memory Controller Channel 2 Thermal Control Registers (rev 04)

Martin, what do you think to this patch?  Also, I'm happy to send you
the lspci -xxxx from the Nehalem system to add to tests/

diff --git a/lspci.c b/lspci.c
index 3bf1925..ae0fdd2 100644
--- a/lspci.c
+++ b/lspci.c
@@ -19,6 +19,7 @@ int verbose;				/* Show detailed information */
 static int opt_hex;			/* Show contents of config space as hexadecimal numbers */
 struct pci_filter filter;		/* Device filter */
 static int opt_tree;			/* Show bus tree */
+static int opt_path;			/* Show bridge path */
 static int opt_machine;			/* Generate machine-readable output */
 static int opt_map_mode;		/* Bus mapping mode enabled */
 static int opt_domains;			/* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */
@@ -29,7 +30,7 @@ char *opt_pcimap;			/* Override path to Linux modules.pcimap */
 
 const char program_name[] = "lspci";
 
-static char options[] = "nvbxs:d:ti:mgp:qkMDQ" GENERIC_OPTIONS ;
+static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ;
 
 static char help_msg[] =
 "Usage: lspci [<switches>]\n"
@@ -247,6 +248,34 @@ sort_them(void)
 
 /*** Normal output ***/
 
+static void
+show_slot_path(struct pci_dev *p)
+{
+  struct pci_dev *d = NULL;
+
+  if (opt_path && p->bus)
+    {
+      for (d = p->access->devices; d; d = d->next) {
+	if (d->hdrtype == -1)
+	  d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f;
+	if (d->hdrtype != PCI_HEADER_TYPE_BRIDGE &&
+	    d->hdrtype != PCI_HEADER_TYPE_CARDBUS)
+	  continue;
+	if (pci_read_byte(d, PCI_SECONDARY_BUS) > p->bus)
+	  continue;
+	if (pci_read_byte(d, PCI_SUBORDINATE_BUS) < p->bus)
+	  continue;
+	show_slot_path(d);
+	break;
+      }
+    }
+
+  if (d)
+    printf("/%02x.%d", p->dev, p->func);
+  else
+    printf("%02x:%02x.%d", p->bus, p->dev, p->func);
+}
+
 static void
 show_slot_name(struct device *d)
 {
@@ -254,7 +283,7 @@ show_slot_name(struct device *d)
 
   if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2))
     printf("%04x:", p->domain);
-  printf("%02x:%02x.%d", p->bus, p->dev, p->func);
+  show_slot_path(p);
 }
 
 void
@@ -989,6 +1018,9 @@ main(int argc, char **argv)
       case 'x':
 	opt_hex++;
 	break;
+      case 'P':
+	opt_path++;
+	break;
       case 't':
 	opt_tree++;
 	break;
diff --git a/lspci.man b/lspci.man
index 35b3620..565dd5b 100644
--- a/lspci.man
+++ b/lspci.man
@@ -95,6 +95,9 @@ PCI bus instead of as seen by the kernel.
 .B -D
 Always show PCI domain numbers. By default, lspci suppresses them on machines which
 have only domain 0.
+.TP
+.B -P
+Name PCI devices by path through each bridge, instead of by bus number.
 
 .SS Options to control resolving ID's to names
 .TP

  parent reply	other threads:[~2018-07-17 21:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 17:02 [PATCH v7 0/4] Add parameter for disabling ACS redirection for P2P Logan Gunthorpe
2018-07-17 17:02 ` [PATCH v7 1/4] PCI: Make specifying PCI devices in kernel parameters reusable Logan Gunthorpe
2018-07-17 17:02 ` [PATCH v7 2/4] PCI: Allow specifying devices using a base bus and path of devfns Logan Gunthorpe
2018-07-17 17:02 ` [PATCH v7 3/4] PCI: Introduce disable_acs_redir quirk Logan Gunthorpe
2018-07-17 17:48   ` Alex Williamson
2018-07-17 17:02 ` [PATCH v7 4/4] PCI: Introduce the disable_acs_redir parameter Logan Gunthorpe
2018-07-17 17:48   ` Alex Williamson
2018-07-17 17:49     ` Logan Gunthorpe
2018-07-17 17:57       ` Stephen  Bates
2018-07-17 20:39 ` Matthew Wilcox [this message]
2018-07-17 20:51   ` lspci: Display path to device Logan Gunthorpe
2018-07-17 21:00   ` Bjorn Helgaas
2018-07-17 21:46     ` Matthew Wilcox
2018-08-09 23:48   ` Matthew Wilcox
2018-08-10  9:35   ` Martin Mares
2018-08-10 10:30     ` Martin Mares
2018-08-10 14:56       ` Matthew Wilcox
2018-08-12  9:28         ` Martin Mares
2018-08-12 10:31           ` Matthew Wilcox
2018-08-12 10:51             ` Martin Mares
2018-08-13 15:55             ` Logan Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180717203900.GA1771@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=alex.williamson@redhat.com \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=frederic@kernel.org \
    --cc=hch@lst.de \
    --cc=jglisse@redhat.com \
    --cc=kai.heng.feng@canonical.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=marc.zyngier@arm.com \
    --cc=mingo@kernel.org \
    --cc=mj@ucw.cz \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=sbates@raithlin.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).