Linux-PCI Archive on lore.kernel.org
 help / color / Atom feed
From: "return.0" <return.0@me.com>
To: Martin Mares <mj@ucw.cz>
Cc: linux-pci@vger.kernel.org
Subject: pciutils: decoding extended capabilities with variable size based on lane count
Date: Sat, 13 Jul 2019 05:39:49 -0500
Message-ID: <917430A7-9813-4F54-A135-BB965950EE27@me.com> (raw)

I was working on providing a patch for decoding some of the 4.0 extended capabilities, but hit a snag.  The Lane Margining and the 16GT/S Physical Layer Extended Capabilities only have valid data for the number of lanes (up to 32) currently configured. It would be nice to know the width during decode without having to re-read and decode, but instead grab it from the device structure.  

Would you support making a change to the device structure like the following:

diff --git a/lspci.h b/lspci.h
index fefee52..69912fc 100644
--- a/lspci.h
+++ b/lspci.h
@@ -42,6 +42,10 @@ struct device {
  unsigned int config_cached, config_bufsize;
  byte *config;                                /* Cached configuration space data */
  byte *present;                       /* Maps which configuration bytes are present */
+  int cap_speed;
+  int cap_width;
+  int sta_speed;
+  int sta_width;
};

extern struct device *first_dev;


Then within cap_express_link, the value would be stored to the device structure rather than a local variable.

diff --git a/ls-caps.c b/ls-caps.c
index 88964ce..bf600e8 100644
--- a/ls-caps.c
+++ b/ls-caps.c
@@ -781,16 +781,16 @@ static const char *aspm_enabled(int code)

static void cap_express_link(struct device *d, int where, int type)
{
-  u32 t, aspm, cap_speed, cap_width, sta_speed, sta_width;
+  u32 t, aspm;
  u16 w;

  t = get_conf_long(d, where + PCI_EXP_LNKCAP);
  aspm = (t & PCI_EXP_LNKCAP_ASPM) >> 10;
-  cap_speed = t & PCI_EXP_LNKCAP_SPEED;
-  cap_width = (t & PCI_EXP_LNKCAP_WIDTH) >> 4;
+  d->cap_speed = t & PCI_EXP_LNKCAP_SPEED;
+  d->cap_width = (t & PCI_EXP_LNKCAP_WIDTH) >> 4;
  printf("\t\tLnkCap:\tPort #%d, Speed %s, Width x%d, ASPM %s",
	t >> 24,
-	link_speed(cap_speed), cap_width,
+	link_speed(d->cap_speed), d->cap_width,
	aspm_support(aspm));
  if (aspm)
    {
@@ -824,13 +824,13 @@ static void cap_express_link(struct device *d, int where, int type)
	FLAG(w, PCI_EXP_LNKCTL_AUTBWIE));

  w = get_conf_word(d, where + PCI_EXP_LNKSTA);
-  sta_speed = w & PCI_EXP_LNKSTA_SPEED;
-  sta_width = (w & PCI_EXP_LNKSTA_WIDTH) >> 4;
+  d->sta_speed = w & PCI_EXP_LNKSTA_SPEED;
+  d->sta_width = (w & PCI_EXP_LNKSTA_WIDTH) >> 4;
  printf("\t\tLnkSta:\tSpeed %s (%s), Width x%d (%s)\n",
-	link_speed(sta_speed),
-	link_compare(sta_speed, cap_speed),
-	sta_width,
-	link_compare(sta_width, cap_width));
+	link_speed(d->sta_speed),
+	link_compare(d->sta_speed, d->cap_speed),
+	d->sta_width,
+	link_compare(d->sta_width, d->cap_width));
  printf("\t\t\tTrErr%c Train%c SlotClk%c DLActive%c BWMgmt%c ABWMgmt%c\n",
	FLAG(w, PCI_EXP_LNKSTA_TR_ERR),
	FLAG(w, PCI_EXP_LNKSTA_TRAIN),


Is this the best way to handle this or would you prefer a different way?

Thank you,
John

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-13 10:39 return.0 [this message]
2019-07-13 12:58 ` Martin Mareš

Reply instructions:

You may reply publically 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=917430A7-9813-4F54-A135-BB965950EE27@me.com \
    --to=return.0@me.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=mj@ucw.cz \
    /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

Linux-PCI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pci/0 linux-pci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pci linux-pci/ https://lore.kernel.org/linux-pci \
		linux-pci@vger.kernel.org linux-pci@archiver.kernel.org
	public-inbox-index linux-pci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox