git: dde4103a465b - stable/13 - pciconf(8): Decode ACS extended capability.

From: Navdeep Parhar <np_at_FreeBSD.org>
Date: Thu, 02 Feb 2023 07:39:44 UTC
The branch stable/13 has been updated by np:

URL: https://cgit.FreeBSD.org/src/commit/?id=dde4103a465bd8021eafabc159942c60a9473625

commit dde4103a465bd8021eafabc159942c60a9473625
Author:     Navdeep Parhar <np@FreeBSD.org>
AuthorDate: 2022-11-04 19:30:09 +0000
Commit:     Navdeep Parhar <np@FreeBSD.org>
CommitDate: 2023-02-02 07:21:59 +0000

    pciconf(8): Decode ACS extended capability.
    
    Sponsored by:   Chelsio Communications
    Reviewed by:    kib@
    Differential Revision:  https://reviews.freebsd.org/D37271
    
    (cherry picked from commit 118cfb829f355a4545f079f12bab5ea8e41fe214)
---
 usr.sbin/pciconf/cap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/usr.sbin/pciconf/cap.c b/usr.sbin/pciconf/cap.c
index eae53acbd250..3d28fe9bc331 100644
--- a/usr.sbin/pciconf/cap.c
+++ b/usr.sbin/pciconf/cap.c
@@ -1016,6 +1016,64 @@ ecap_sriov(int fd, struct pci_conf *p, uint16_t ptr, uint8_t ver)
 		print_bar(fd, p, "iov bar  ", ptr + PCIR_SRIOV_BAR(i));
 }
 
+static const char *
+check_avail_and_state(u_int cap, u_int capbit, u_int ctl, u_int ctlbit)
+{
+
+	if (cap & capbit)
+		return (ctl & ctlbit ? "enabled" : "disabled");
+	else
+		return "unavailable";
+}
+
+static void
+ecap_acs(int fd, struct pci_conf *p, uint16_t ptr, uint8_t ver)
+{
+	uint16_t acs_cap, acs_ctl;
+	static const char *const acc[] = { "access enabled", "blocking enabled",
+		"redirect enabled", "reserved" };
+
+	printf("ACS %d ", ver);
+	if (ver != 1) {
+		printf("\n");
+		return;
+	}
+
+#define	CHECK_AVAIL_STATE(bit) \
+	check_avail_and_state(acs_cap, bit, acs_ctl, bit##_ENABLE)
+
+	acs_cap = read_config(fd, &p->pc_sel, ptr + PCIR_ACS_CAP, 2);
+	acs_ctl = read_config(fd, &p->pc_sel, ptr + PCIR_ACS_CTL, 2);
+	printf("Source Validation %s, Translation Blocking %s\n",
+	    CHECK_AVAIL_STATE(PCIM_ACS_SOURCE_VALIDATION),
+	    CHECK_AVAIL_STATE(PCIM_ACS_TRANSLATION_BLOCKING));
+
+	printf("                     ");
+	printf("P2P Req Redirect %s, P2P Cmpl Redirect %s\n",
+	    CHECK_AVAIL_STATE(PCIM_ACS_P2P_REQ_REDIRECT),
+	    CHECK_AVAIL_STATE(PCIM_ACS_P2P_CMP_REDIRECT));
+	printf("                     ");
+	printf("P2P Upstream Forwarding %s, P2P Egress Control %s\n",
+	    CHECK_AVAIL_STATE(PCIM_ACS_P2P_UPSTREAM_FORWARDING),
+	    CHECK_AVAIL_STATE(PCIM_ACS_P2P_EGRESS_CTL));
+	printf("                     ");
+	printf("P2P Direct Translated %s, Enhanced Capability %s\n",
+	    CHECK_AVAIL_STATE(PCIM_ACS_P2P_DIRECT_TRANSLATED),
+	    acs_ctl & PCIM_ACS_ENHANCED_CAP ? "available" : "unavailable");
+#undef	CHECK_AVAIL_STATE
+
+	if (acs_cap & PCIM_ACS_ENHANCED_CAP) {
+		printf("                     ");
+		printf("I/O Req Blocking %s, Unclaimed Req Redirect Control %s\n",
+		    check_enabled(acs_ctl & PCIM_ACS_IO_REQ_BLOCKING_ENABLE),
+		    check_enabled(acs_ctl & PCIM_ACS_UNCLAIMED_REQ_REDIRECT_CTL));
+		printf("                     ");
+		printf("DSP BAR %s, USP BAR %s\n",
+		    acc[(acs_cap & PCIM_ACS_DSP_MEM_TGT_ACC_CTL) >> 8],
+		    acc[(acs_cap & PCIM_ACS_USP_MEM_TGT_ACC_CTL) >> 10]);
+	}
+}
+
 static struct {
 	uint16_t id;
 	const char *name;
@@ -1099,6 +1157,9 @@ list_ecaps(int fd, struct pci_conf *p)
 		case PCIZ_SRIOV:
 			ecap_sriov(fd, p, ptr, PCI_EXTCAP_VER(ecap));
 			break;
+		case PCIZ_ACS:
+			ecap_acs(fd, p, ptr, PCI_EXTCAP_VER(ecap));
+			break;
 		default:
 			name = "unknown";
 			for (i = 0; ecap_names[i].name != NULL; i++)