Blame ls-ecaps.c

Packit 9fb349
/*
Packit 9fb349
 *	The PCI Utilities -- Show Extended Capabilities
Packit 9fb349
 *
Packit Service 745c2f
 *	Copyright (c) 1997--2020 Martin Mares <mj@ucw.cz>
Packit 9fb349
 *
Packit 9fb349
 *	Can be freely distributed and used under the terms of the GNU GPL.
Packit 9fb349
 */
Packit 9fb349
Packit 9fb349
#include <stdio.h>
Packit 9fb349
#include <string.h>
Packit 9fb349
Packit 9fb349
#include "lspci.h"
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_tph(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 tph_cap;
Packit 9fb349
  printf("Transaction Processing Hints\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_TPH_CAPABILITIES, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  tph_cap = get_conf_long(d, where + PCI_TPH_CAPABILITIES);
Packit 9fb349
Packit 9fb349
  if (tph_cap & PCI_TPH_INTVEC_SUP)
Packit 9fb349
    printf("\t\tInterrupt vector mode supported\n");
Packit 9fb349
  if (tph_cap & PCI_TPH_DEV_SUP)
Packit 9fb349
    printf("\t\tDevice specific mode supported\n");
Packit 9fb349
  if (tph_cap & PCI_TPH_EXT_REQ_SUP)
Packit 9fb349
    printf("\t\tExtended requester support\n");
Packit 9fb349
Packit 9fb349
  switch (tph_cap & PCI_TPH_ST_LOC_MASK) {
Packit 9fb349
  case PCI_TPH_ST_NONE:
Packit 9fb349
    printf("\t\tNo steering table available\n");
Packit 9fb349
    break;
Packit 9fb349
  case PCI_TPH_ST_CAP:
Packit 9fb349
    printf("\t\tSteering table in TPH capability structure\n");
Packit 9fb349
    break;
Packit 9fb349
  case PCI_TPH_ST_MSIX:
Packit 9fb349
    printf("\t\tSteering table in MSI-X table\n");
Packit 9fb349
    break;
Packit 9fb349
  default:
Packit 9fb349
    printf("\t\tReserved steering table location\n");
Packit 9fb349
    break;
Packit 9fb349
  }
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static u32
Packit 9fb349
cap_ltr_scale(u8 scale)
Packit 9fb349
{
Packit 9fb349
  return 1 << (scale * 5);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_ltr(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 scale;
Packit 9fb349
  u16 snoop, nosnoop;
Packit 9fb349
  printf("Latency Tolerance Reporting\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_LTR_MAX_SNOOP, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  snoop = get_conf_word(d, where + PCI_LTR_MAX_SNOOP);
Packit 9fb349
  scale = cap_ltr_scale((snoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK);
Packit 9fb349
  printf("\t\tMax snoop latency: %lldns\n",
Packit 9fb349
	 ((unsigned long long)snoop & PCI_LTR_VALUE_MASK) * scale);
Packit 9fb349
Packit 9fb349
  nosnoop = get_conf_word(d, where + PCI_LTR_MAX_NOSNOOP);
Packit 9fb349
  scale = cap_ltr_scale((nosnoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK);
Packit 9fb349
  printf("\t\tMax no snoop latency: %lldns\n",
Packit 9fb349
	 ((unsigned long long)nosnoop & PCI_LTR_VALUE_MASK) * scale);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_sec(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 ctrl3, lane_err_stat;
Packit 9fb349
  u8 lane;
Packit 9fb349
  printf("Secondary PCI Express\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_SEC_LNKCTL3, 12))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  ctrl3 = get_conf_word(d, where + PCI_SEC_LNKCTL3);
Packit Service 745c2f
  printf("\t\tLnkCtl3: LnkEquIntrruptEn%c PerformEqu%c\n",
Packit 9fb349
	FLAG(ctrl3, PCI_SEC_LNKCTL3_LNK_EQU_REQ_INTR_EN),
Packit 9fb349
	FLAG(ctrl3, PCI_SEC_LNKCTL3_PERFORM_LINK_EQU));
Packit 9fb349
Packit 9fb349
  lane_err_stat = get_conf_word(d, where + PCI_SEC_LANE_ERR);
Packit 9fb349
  printf("\t\tLaneErrStat: ");
Packit 9fb349
  if (lane_err_stat)
Packit 9fb349
    {
Packit 9fb349
      printf("LaneErr at lane:");
Packit 9fb349
      for (lane = 0; lane_err_stat; lane_err_stat >>= 1, lane += 1)
Packit 9fb349
        if (BITS(lane_err_stat, 0, 1))
Packit 9fb349
          printf(" %u", lane);
Packit 9fb349
    }
Packit 9fb349
  else
Packit 9fb349
    printf("0");
Packit 9fb349
  printf("\n");
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_dsn(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 t1, t2;
Packit 9fb349
  if (!config_fetch(d, where + 4, 8))
Packit 9fb349
    return;
Packit 9fb349
  t1 = get_conf_long(d, where + 4);
Packit 9fb349
  t2 = get_conf_long(d, where + 8);
Packit 9fb349
  printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
Packit 9fb349
	t2 >> 24, (t2 >> 16) & 0xff, (t2 >> 8) & 0xff, t2 & 0xff,
Packit 9fb349
	t1 >> 24, (t1 >> 16) & 0xff, (t1 >> 8) & 0xff, t1 & 0xff);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_aer(struct device *d, int where, int type)
Packit 9fb349
{
Packit 9fb349
  u32 l, l0, l1, l2, l3;
Packit 9fb349
  u16 w;
Packit 9fb349
Packit 9fb349
  printf("Advanced Error Reporting\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_ERR_UNCOR_STATUS, 40))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_UNCOR_STATUS);
Packit 9fb349
  printf("\t\tUESta:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
Packit 9fb349
	"MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_UNCOR_MASK);
Packit 9fb349
  printf("\t\tUEMsk:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
Packit 9fb349
	"MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_UNCOR_SEVER);
Packit 9fb349
  printf("\t\tUESvrt:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
Packit 9fb349
	"MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
Packit 9fb349
	FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_COR_STATUS);
Packit 9fb349
  printf("\t\tCESta:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c AdvNonFatalErr%c\n",
Packit 9fb349
	FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
Packit 9fb349
	FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_COR_MASK);
Packit 9fb349
  printf("\t\tCEMsk:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c AdvNonFatalErr%c\n",
Packit 9fb349
	FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
Packit 9fb349
	FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
Packit 9fb349
  l = get_conf_long(d, where + PCI_ERR_CAP);
Packit 9fb349
  printf("\t\tAERCap:\tFirst Error Pointer: %02x, ECRCGenCap%c ECRCGenEn%c ECRCChkCap%c ECRCChkEn%c\n"
Packit 9fb349
	"\t\t\tMultHdrRecCap%c MultHdrRecEn%c TLPPfxPres%c HdrLogCap%c\n",
Packit 9fb349
	PCI_ERR_CAP_FEP(l), FLAG(l, PCI_ERR_CAP_ECRC_GENC), FLAG(l, PCI_ERR_CAP_ECRC_GENE),
Packit 9fb349
	FLAG(l, PCI_ERR_CAP_ECRC_CHKC), FLAG(l, PCI_ERR_CAP_ECRC_CHKE),
Packit 9fb349
	FLAG(l, PCI_ERR_CAP_MULT_HDRC), FLAG(l, PCI_ERR_CAP_MULT_HDRE),
Packit 9fb349
	FLAG(l, PCI_ERR_CAP_TLP_PFX), FLAG(l, PCI_ERR_CAP_HDR_LOG));
Packit 9fb349
Packit 9fb349
  l0 = get_conf_long(d, where + PCI_ERR_HEADER_LOG);
Packit 9fb349
  l1 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 4);
Packit 9fb349
  l2 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 8);
Packit 9fb349
  l3 = get_conf_long(d, where + PCI_ERR_HEADER_LOG + 12);
Packit 9fb349
  printf("\t\tHeaderLog: %08x %08x %08x %08x\n", l0, l1, l2, l3);
Packit 9fb349
Packit 9fb349
  if (type == PCI_EXP_TYPE_ROOT_PORT || type == PCI_EXP_TYPE_ROOT_EC)
Packit 9fb349
    {
Packit 9fb349
      if (!config_fetch(d, where + PCI_ERR_ROOT_COMMAND, 12))
Packit 9fb349
        return;
Packit 9fb349
Packit 9fb349
      l = get_conf_long(d, where + PCI_ERR_ROOT_COMMAND);
Packit 9fb349
      printf("\t\tRootCmd: CERptEn%c NFERptEn%c FERptEn%c\n",
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_CMD_COR_EN),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_CMD_NONFATAL_EN),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_CMD_FATAL_EN));
Packit 9fb349
Packit 9fb349
      l = get_conf_long(d, where + PCI_ERR_ROOT_STATUS);
Packit 9fb349
      printf("\t\tRootSta: CERcvd%c MultCERcvd%c UERcvd%c MultUERcvd%c\n"
Packit 9fb349
	    "\t\t\t FirstFatal%c NonFatalMsg%c FatalMsg%c IntMsg %d\n",
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_COR_RCV),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_MULTI_COR_RCV),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_UNCOR_RCV),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_MULTI_UNCOR_RCV),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_FIRST_FATAL),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_NONFATAL_RCV),
Packit 9fb349
	    FLAG(l, PCI_ERR_ROOT_FATAL_RCV),
Packit 9fb349
	    PCI_ERR_MSG_NUM(l));
Packit 9fb349
Packit 9fb349
      w = get_conf_word(d, where + PCI_ERR_ROOT_COR_SRC);
Packit 9fb349
      printf("\t\tErrorSrc: ERR_COR: %04x ", w);
Packit 9fb349
Packit 9fb349
      w = get_conf_word(d, where + PCI_ERR_ROOT_SRC);
Packit 9fb349
      printf("ERR_FATAL/NONFATAL: %04x\n", w);
Packit 9fb349
    }
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void cap_dpc(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 l;
Packit 9fb349
Packit 9fb349
  printf("Downstream Port Containment\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_DPC_CAP, 8))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  l = get_conf_word(d, where + PCI_DPC_CAP);
Packit 9fb349
  printf("\t\tDpcCap:\tINT Msg #%d, RPExt%c PoisonedTLP%c SwTrigger%c RP PIO Log %d, DL_ActiveErr%c\n",
Packit 9fb349
    PCI_DPC_CAP_INT_MSG(l), FLAG(l, PCI_DPC_CAP_RP_EXT), FLAG(l, PCI_DPC_CAP_TLP_BLOCK),
Packit 9fb349
    FLAG(l, PCI_DPC_CAP_SW_TRIGGER), PCI_DPC_CAP_RP_LOG(l), FLAG(l, PCI_DPC_CAP_DL_ACT_ERR));
Packit 9fb349
Packit 9fb349
  l = get_conf_word(d, where + PCI_DPC_CTL);
Packit 9fb349
  printf("\t\tDpcCtl:\tTrigger:%x Cmpl%c INT%c ErrCor%c PoisonedTLP%c SwTrigger%c DL_ActiveErr%c\n",
Packit 9fb349
    PCI_DPC_CTL_TRIGGER(l), FLAG(l, PCI_DPC_CTL_CMPL), FLAG(l, PCI_DPC_CTL_INT),
Packit 9fb349
    FLAG(l, PCI_DPC_CTL_ERR_COR), FLAG(l, PCI_DPC_CTL_TLP), FLAG(l, PCI_DPC_CTL_SW_TRIGGER),
Packit 9fb349
    FLAG(l, PCI_DPC_CTL_DL_ACTIVE));
Packit 9fb349
Packit 9fb349
  l = get_conf_word(d, where + PCI_DPC_STATUS);
Packit 9fb349
  printf("\t\tDpcSta:\tTrigger%c Reason:%02x INT%c RPBusy%c TriggerExt:%02x RP PIO ErrPtr:%02x\n",
Packit 9fb349
    FLAG(l, PCI_DPC_STS_TRIGGER), PCI_DPC_STS_REASON(l), FLAG(l, PCI_DPC_STS_INT),
Packit 9fb349
    FLAG(l, PCI_DPC_STS_RP_BUSY), PCI_DPC_STS_TRIGGER_EXT(l), PCI_DPC_STS_PIO_FEP(l));
Packit 9fb349
Packit 9fb349
  l = get_conf_word(d, where + PCI_DPC_SOURCE);
Packit 9fb349
  printf("\t\tSource:\t%04x\n", l);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_acs(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
Packit 9fb349
  printf("Access Control Services\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_ACS_CAP, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_ACS_CAP);
Packit 9fb349
  printf("\t\tACSCap:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
Packit 9fb349
	"DirectTrans%c\n",
Packit 9fb349
	FLAG(w, PCI_ACS_CAP_VALID), FLAG(w, PCI_ACS_CAP_BLOCK), FLAG(w, PCI_ACS_CAP_REQ_RED),
Packit 9fb349
	FLAG(w, PCI_ACS_CAP_CMPLT_RED), FLAG(w, PCI_ACS_CAP_FORWARD), FLAG(w, PCI_ACS_CAP_EGRESS),
Packit 9fb349
	FLAG(w, PCI_ACS_CAP_TRANS));
Packit 9fb349
  w = get_conf_word(d, where + PCI_ACS_CTRL);
Packit 9fb349
  printf("\t\tACSCtl:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
Packit 9fb349
	"DirectTrans%c\n",
Packit 9fb349
	FLAG(w, PCI_ACS_CTRL_VALID), FLAG(w, PCI_ACS_CTRL_BLOCK), FLAG(w, PCI_ACS_CTRL_REQ_RED),
Packit 9fb349
	FLAG(w, PCI_ACS_CTRL_CMPLT_RED), FLAG(w, PCI_ACS_CTRL_FORWARD), FLAG(w, PCI_ACS_CTRL_EGRESS),
Packit 9fb349
	FLAG(w, PCI_ACS_CTRL_TRANS));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_ari(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
Packit 9fb349
  printf("Alternative Routing-ID Interpretation (ARI)\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_ARI_CAP, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_ARI_CAP);
Packit 9fb349
  printf("\t\tARICap:\tMFVC%c ACS%c, Next Function: %d\n",
Packit 9fb349
	FLAG(w, PCI_ARI_CAP_MFVC), FLAG(w, PCI_ARI_CAP_ACS),
Packit 9fb349
	PCI_ARI_CAP_NFN(w));
Packit 9fb349
  w = get_conf_word(d, where + PCI_ARI_CTRL);
Packit 9fb349
  printf("\t\tARICtl:\tMFVC%c ACS%c, Function Group: %d\n",
Packit 9fb349
	FLAG(w, PCI_ARI_CTRL_MFVC), FLAG(w, PCI_ARI_CTRL_ACS),
Packit 9fb349
	PCI_ARI_CTRL_FG(w));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_ats(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
Packit 9fb349
  printf("Address Translation Service (ATS)\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_ATS_CAP, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_ATS_CAP);
Packit 9fb349
  printf("\t\tATSCap:\tInvalidate Queue Depth: %02x\n", PCI_ATS_CAP_IQD(w));
Packit 9fb349
  w = get_conf_word(d, where + PCI_ATS_CTRL);
Packit 9fb349
  printf("\t\tATSCtl:\tEnable%c, Smallest Translation Unit: %02x\n",
Packit 9fb349
	FLAG(w, PCI_ATS_CTRL_ENABLE), PCI_ATS_CTRL_STU(w));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_pri(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
  u32 l;
Packit 9fb349
Packit 9fb349
  printf("Page Request Interface (PRI)\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_PRI_CTRL, 0xc))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_PRI_CTRL);
Packit 9fb349
  printf("\t\tPRICtl: Enable%c Reset%c\n",
Packit 9fb349
	FLAG(w, PCI_PRI_CTRL_ENABLE), FLAG(w, PCI_PRI_CTRL_RESET));
Packit 9fb349
  w = get_conf_word(d, where + PCI_PRI_STATUS);
Packit 9fb349
  printf("\t\tPRISta: RF%c UPRGI%c Stopped%c\n",
Packit 9fb349
	FLAG(w, PCI_PRI_STATUS_RF), FLAG(w, PCI_PRI_STATUS_UPRGI),
Packit 9fb349
	FLAG(w, PCI_PRI_STATUS_STOPPED));
Packit 9fb349
  l = get_conf_long(d, where + PCI_PRI_MAX_REQ);
Packit 9fb349
  printf("\t\tPage Request Capacity: %08x, ", l);
Packit 9fb349
  l = get_conf_long(d, where + PCI_PRI_ALLOC_REQ);
Packit 9fb349
  printf("Page Request Allocation: %08x\n", l);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_pasid(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
Packit 9fb349
  printf("Process Address Space ID (PASID)\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_PASID_CAP, 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_PASID_CAP);
Packit 9fb349
  printf("\t\tPASIDCap: Exec%c Priv%c, Max PASID Width: %02x\n",
Packit 9fb349
	FLAG(w, PCI_PASID_CAP_EXEC), FLAG(w, PCI_PASID_CAP_PRIV),
Packit 9fb349
	PCI_PASID_CAP_WIDTH(w));
Packit 9fb349
  w = get_conf_word(d, where + PCI_PASID_CTRL);
Packit 9fb349
  printf("\t\tPASIDCtl: Enable%c Exec%c Priv%c\n",
Packit 9fb349
	FLAG(w, PCI_PASID_CTRL_ENABLE), FLAG(w, PCI_PASID_CTRL_EXEC),
Packit 9fb349
	FLAG(w, PCI_PASID_CTRL_PRIV));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_sriov(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u16 b;
Packit 9fb349
  u16 w;
Packit 9fb349
  u32 l;
Packit 9fb349
  int i;
Packit 9fb349
Packit 9fb349
  printf("Single Root I/O Virtualization (SR-IOV)\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_IOV_CAP, 0x3c))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  l = get_conf_long(d, where + PCI_IOV_CAP);
Packit 9fb349
  printf("\t\tIOVCap:\tMigration%c, Interrupt Message Number: %03x\n",
Packit 9fb349
	FLAG(l, PCI_IOV_CAP_VFM), PCI_IOV_CAP_IMN(l));
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_CTRL);
Packit 9fb349
  printf("\t\tIOVCtl:\tEnable%c Migration%c Interrupt%c MSE%c ARIHierarchy%c\n",
Packit 9fb349
	FLAG(w, PCI_IOV_CTRL_VFE), FLAG(w, PCI_IOV_CTRL_VFME),
Packit 9fb349
	FLAG(w, PCI_IOV_CTRL_VFMIE), FLAG(w, PCI_IOV_CTRL_MSE),
Packit 9fb349
	FLAG(w, PCI_IOV_CTRL_ARI));
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_STATUS);
Packit 9fb349
  printf("\t\tIOVSta:\tMigration%c\n", FLAG(w, PCI_IOV_STATUS_MS));
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_INITIALVF);
Packit 9fb349
  printf("\t\tInitial VFs: %d, ", w);
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_TOTALVF);
Packit 9fb349
  printf("Total VFs: %d, ", w);
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_NUMVF);
Packit 9fb349
  printf("Number of VFs: %d, ", w);
Packit 9fb349
  b = get_conf_byte(d, where + PCI_IOV_FDL);
Packit 9fb349
  printf("Function Dependency Link: %02x\n", b);
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_OFFSET);
Packit 9fb349
  printf("\t\tVF offset: %d, ", w);
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_STRIDE);
Packit 9fb349
  printf("stride: %d, ", w);
Packit 9fb349
  w = get_conf_word(d, where + PCI_IOV_DID);
Packit 9fb349
  printf("Device ID: %04x\n", w);
Packit 9fb349
  l = get_conf_long(d, where + PCI_IOV_SUPPS);
Packit 9fb349
  printf("\t\tSupported Page Size: %08x, ", l);
Packit 9fb349
  l = get_conf_long(d, where + PCI_IOV_SYSPS);
Packit 9fb349
  printf("System Page Size: %08x\n", l);
Packit 9fb349
Packit 9fb349
  for (i=0; i < PCI_IOV_NUM_BAR; i++)
Packit 9fb349
    {
Packit 9fb349
      u32 addr;
Packit 9fb349
      int type;
Packit 9fb349
      u32 h;
Packit 9fb349
      l = get_conf_long(d, where + PCI_IOV_BAR_BASE + 4*i);
Packit 9fb349
      if (l == 0xffffffff)
Packit 9fb349
	l = 0;
Packit 9fb349
      if (!l)
Packit 9fb349
	continue;
Packit 9fb349
      printf("\t\tRegion %d: Memory at ", i);
Packit 9fb349
      addr = l & PCI_ADDR_MEM_MASK;
Packit 9fb349
      type = l & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
Packit 9fb349
      if (type == PCI_BASE_ADDRESS_MEM_TYPE_64)
Packit 9fb349
	{
Packit 9fb349
	  i++;
Packit 9fb349
	  h = get_conf_long(d, where + PCI_IOV_BAR_BASE + (i*4));
Packit 9fb349
	  printf("%08x", h);
Packit 9fb349
	}
Packit 9fb349
      printf("%08x (%s-bit, %sprefetchable)\n",
Packit 9fb349
	addr,
Packit 9fb349
	(type == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32" : "64",
Packit 9fb349
	(l & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  l = get_conf_long(d, where + PCI_IOV_MSAO);
Packit 9fb349
  printf("\t\tVF Migration: offset: %08x, BIR: %x\n", PCI_IOV_MSA_OFFSET(l),
Packit 9fb349
	PCI_IOV_MSA_BIR(l));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_multicast(struct device *d, int where, int type)
Packit 9fb349
{
Packit 9fb349
  u16 w;
Packit 9fb349
  u32 l;
Packit 9fb349
  u64 bar, rcv, block;
Packit 9fb349
Packit 9fb349
  printf("Multicast\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_MCAST_CAP, 0x30))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  w = get_conf_word(d, where + PCI_MCAST_CAP);
Packit 9fb349
  printf("\t\tMcastCap: MaxGroups %d", PCI_MCAST_CAP_MAX_GROUP(w) + 1);
Packit 9fb349
  if (type == PCI_EXP_TYPE_ENDPOINT || type == PCI_EXP_TYPE_ROOT_INT_EP)
Packit 9fb349
    printf(", WindowSz %d (%d bytes)",
Packit 9fb349
      PCI_MCAST_CAP_WIN_SIZE(w), 1 << PCI_MCAST_CAP_WIN_SIZE(w));
Packit 9fb349
  if (type == PCI_EXP_TYPE_ROOT_PORT ||
Packit 9fb349
      type == PCI_EXP_TYPE_UPSTREAM || type == PCI_EXP_TYPE_DOWNSTREAM)
Packit 9fb349
    printf(", ECRCRegen%c\n", FLAG(w, PCI_MCAST_CAP_ECRC));
Packit 9fb349
  w = get_conf_word(d, where + PCI_MCAST_CTRL);
Packit 9fb349
  printf("\t\tMcastCtl: NumGroups %d, Enable%c\n",
Packit 9fb349
    PCI_MCAST_CTRL_NUM_GROUP(w) + 1, FLAG(w, PCI_MCAST_CTRL_ENABLE));
Packit 9fb349
  bar = get_conf_long(d, where + PCI_MCAST_BAR);
Packit 9fb349
  l = get_conf_long(d, where + PCI_MCAST_BAR + 4);
Packit 9fb349
  bar |= (u64) l << 32;
Packit 9fb349
  printf("\t\tMcastBAR: IndexPos %d, BaseAddr %016" PCI_U64_FMT_X "\n",
Packit 9fb349
    PCI_MCAST_BAR_INDEX_POS(bar), bar & PCI_MCAST_BAR_MASK);
Packit 9fb349
  rcv = get_conf_long(d, where + PCI_MCAST_RCV);
Packit 9fb349
  l = get_conf_long(d, where + PCI_MCAST_RCV + 4);
Packit 9fb349
  rcv |= (u64) l << 32;
Packit 9fb349
  printf("\t\tMcastReceiveVec:      %016" PCI_U64_FMT_X "\n", rcv);
Packit 9fb349
  block = get_conf_long(d, where + PCI_MCAST_BLOCK);
Packit 9fb349
  l = get_conf_long(d, where + PCI_MCAST_BLOCK + 4);
Packit 9fb349
  block |= (u64) l << 32;
Packit 9fb349
  printf("\t\tMcastBlockAllVec:     %016" PCI_U64_FMT_X "\n", block);
Packit 9fb349
  block = get_conf_long(d, where + PCI_MCAST_BLOCK_UNTRANS);
Packit 9fb349
  l = get_conf_long(d, where + PCI_MCAST_BLOCK_UNTRANS + 4);
Packit 9fb349
  block |= (u64) l << 32;
Packit 9fb349
  printf("\t\tMcastBlockUntransVec: %016" PCI_U64_FMT_X "\n", block);
Packit 9fb349
Packit 9fb349
  if (type == PCI_EXP_TYPE_ENDPOINT || type == PCI_EXP_TYPE_ROOT_INT_EP)
Packit 9fb349
    return;
Packit 9fb349
  bar = get_conf_long(d, where + PCI_MCAST_OVL_BAR);
Packit 9fb349
  l = get_conf_long(d, where + PCI_MCAST_OVL_BAR + 4);
Packit 9fb349
  bar |= (u64) l << 32;
Packit 9fb349
  printf("\t\tMcastOverlayBAR: OverlaySize %d ", PCI_MCAST_OVL_SIZE(bar));
Packit 9fb349
  if (PCI_MCAST_OVL_SIZE(bar) >= 6)
Packit 9fb349
    printf("(%d bytes)", 1 << PCI_MCAST_OVL_SIZE(bar));
Packit 9fb349
  else
Packit 9fb349
    printf("(disabled)");
Packit 9fb349
  printf(", BaseAddr %016" PCI_U64_FMT_X "\n", bar & PCI_MCAST_OVL_MASK);
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_vc(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 cr1, cr2;
Packit 9fb349
  u16 ctrl, status;
Packit 9fb349
  int evc_cnt;
Packit 9fb349
  int arb_table_pos;
Packit 9fb349
  int i, j;
Packit 9fb349
  static const char ref_clocks[][6] = { "100ns" };
Packit 9fb349
  static const char arb_selects[8][7] = { "Fixed", "WRR32", "WRR64", "WRR128", "??4", "??5", "??6", "??7" };
Packit 9fb349
  static const char vc_arb_selects[8][8] = { "Fixed", "WRR32", "WRR64", "WRR128", "TWRR128", "WRR256", "??6", "??7" };
Packit 9fb349
  char buf[8];
Packit 9fb349
Packit 9fb349
  printf("Virtual Channel\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + 4, 0x1c - 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  cr1 = get_conf_long(d, where + PCI_VC_PORT_REG1);
Packit 9fb349
  cr2 = get_conf_long(d, where + PCI_VC_PORT_REG2);
Packit 9fb349
  ctrl = get_conf_word(d, where + PCI_VC_PORT_CTRL);
Packit 9fb349
  status = get_conf_word(d, where + PCI_VC_PORT_STATUS);
Packit 9fb349
Packit 9fb349
  evc_cnt = BITS(cr1, 0, 3);
Packit 9fb349
  printf("\t\tCaps:\tLPEVC=%d RefClk=%s PATEntryBits=%d\n",
Packit 9fb349
    BITS(cr1, 4, 3),
Packit 9fb349
    TABLE(ref_clocks, BITS(cr1, 8, 2), buf),
Packit 9fb349
    1 << BITS(cr1, 10, 2));
Packit 9fb349
Packit 9fb349
  printf("\t\tArb:");
Packit 9fb349
  for (i=0; i<8; i++)
Packit 9fb349
    if (arb_selects[i][0] != '?' || cr2 & (1 << i))
Packit 9fb349
      printf("%c%s%c", (i ? ' ' : '\t'), arb_selects[i], FLAG(cr2, 1 << i));
Packit 9fb349
  arb_table_pos = BITS(cr2, 24, 8);
Packit 9fb349
Packit 9fb349
  printf("\n\t\tCtrl:\tArbSelect=%s\n", TABLE(arb_selects, BITS(ctrl, 1, 3), buf));
Packit 9fb349
  printf("\t\tStatus:\tInProgress%c\n", FLAG(status, 1));
Packit 9fb349
Packit 9fb349
  if (arb_table_pos)
Packit 9fb349
    {
Packit 9fb349
      arb_table_pos = where + 16*arb_table_pos;
Packit 9fb349
      printf("\t\tPort Arbitration Table [%x] \n", arb_table_pos);
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  for (i=0; i<=evc_cnt; i++)
Packit 9fb349
    {
Packit 9fb349
      int pos = where + PCI_VC_RES_CAP + 12*i;
Packit 9fb349
      u32 rcap, rctrl;
Packit 9fb349
      u16 rstatus;
Packit 9fb349
      int pat_pos;
Packit 9fb349
Packit 9fb349
      printf("\t\tVC%d:\t", i);
Packit 9fb349
      if (!config_fetch(d, pos, 12))
Packit 9fb349
	{
Packit 9fb349
	  printf("<unreadable>\n");
Packit 9fb349
	  continue;
Packit 9fb349
	}
Packit 9fb349
      rcap = get_conf_long(d, pos);
Packit 9fb349
      rctrl = get_conf_long(d, pos+4);
Packit 9fb349
      rstatus = get_conf_word(d, pos+10);
Packit 9fb349
Packit 9fb349
      pat_pos = BITS(rcap, 24, 8);
Packit 9fb349
      printf("Caps:\tPATOffset=%02x MaxTimeSlots=%d RejSnoopTrans%c\n",
Packit 9fb349
	pat_pos,
Packit 9fb349
	BITS(rcap, 16, 6) + 1,
Packit 9fb349
	FLAG(rcap, 1 << 15));
Packit 9fb349
Packit 9fb349
      printf("\t\t\tArb:");
Packit 9fb349
      for (j=0; j<8; j++)
Packit 9fb349
	if (vc_arb_selects[j][0] != '?' || rcap & (1 << j))
Packit 9fb349
	  printf("%c%s%c", (j ? ' ' : '\t'), vc_arb_selects[j], FLAG(rcap, 1 << j));
Packit 9fb349
Packit 9fb349
      printf("\n\t\t\tCtrl:\tEnable%c ID=%d ArbSelect=%s TC/VC=%02x\n",
Packit 9fb349
	FLAG(rctrl, 1 << 31),
Packit 9fb349
	BITS(rctrl, 24, 3),
Packit 9fb349
	TABLE(vc_arb_selects, BITS(rctrl, 17, 3), buf),
Packit 9fb349
	BITS(rctrl, 0, 8));
Packit 9fb349
Packit 9fb349
      printf("\t\t\tStatus:\tNegoPending%c InProgress%c\n",
Packit 9fb349
	FLAG(rstatus, 2),
Packit 9fb349
	FLAG(rstatus, 1));
Packit 9fb349
Packit 9fb349
      if (pat_pos)
Packit 9fb349
	printf("\t\t\tPort Arbitration Table \n");
Packit 9fb349
    }
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_rclink(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 esd;
Packit 9fb349
  int num_links;
Packit 9fb349
  int i;
Packit 9fb349
  static const char elt_types[][9] = { "Config", "Egress", "Internal" };
Packit 9fb349
  char buf[8];
Packit 9fb349
Packit 9fb349
  printf("Root Complex Link\n");
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + 4, PCI_RCLINK_LINK1 - 4))
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  esd = get_conf_long(d, where + PCI_RCLINK_ESD);
Packit 9fb349
  num_links = BITS(esd, 8, 8);
Packit 9fb349
  printf("\t\tDesc:\tPortNumber=%02x ComponentID=%02x EltType=%s\n",
Packit 9fb349
    BITS(esd, 24, 8),
Packit 9fb349
    BITS(esd, 16, 8),
Packit 9fb349
    TABLE(elt_types, BITS(esd, 0, 8), buf));
Packit 9fb349
Packit 9fb349
  for (i=0; i
Packit 9fb349
    {
Packit 9fb349
      int pos = where + PCI_RCLINK_LINK1 + i*PCI_RCLINK_LINK_SIZE;
Packit 9fb349
      u32 desc;
Packit 9fb349
      u32 addr_lo, addr_hi;
Packit 9fb349
Packit 9fb349
      printf("\t\tLink%d:\t", i);
Packit 9fb349
      if (!config_fetch(d, pos, PCI_RCLINK_LINK_SIZE))
Packit 9fb349
	{
Packit 9fb349
	  printf("<unreadable>\n");
Packit 9fb349
	  return;
Packit 9fb349
	}
Packit 9fb349
      desc = get_conf_long(d, pos + PCI_RCLINK_LINK_DESC);
Packit 9fb349
      addr_lo = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR);
Packit 9fb349
      addr_hi = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR + 4);
Packit 9fb349
Packit 9fb349
      printf("Desc:\tTargetPort=%02x TargetComponent=%02x AssocRCRB%c LinkType=%s LinkValid%c\n",
Packit 9fb349
	BITS(desc, 24, 8),
Packit 9fb349
	BITS(desc, 16, 8),
Packit 9fb349
	FLAG(desc, 4),
Packit 9fb349
	((desc & 2) ? "Config" : "MemMapped"),
Packit 9fb349
	FLAG(desc, 1));
Packit 9fb349
Packit 9fb349
      if (desc & 2)
Packit 9fb349
	{
Packit 9fb349
	  int n = addr_lo & 7;
Packit 9fb349
	  if (!n)
Packit 9fb349
	    n = 8;
Packit 9fb349
	  printf("\t\t\tAddr:\t%02x:%02x.%d  CfgSpace=%08x%08x\n",
Packit 9fb349
	    BITS(addr_lo, 20, n),
Packit 9fb349
	    BITS(addr_lo, 15, 5),
Packit 9fb349
	    BITS(addr_lo, 12, 3),
Packit 9fb349
	    addr_hi, addr_lo);
Packit 9fb349
	}
Packit 9fb349
      else
Packit 9fb349
	printf("\t\t\tAddr:\t%08x%08x\n", addr_hi, addr_lo);
Packit 9fb349
    }
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit Service 745c2f
cap_dvsec_cxl(struct device *d, int where)
Packit Service 745c2f
{
Packit Service 745c2f
  u16 l;
Packit Service 745c2f
Packit Service 745c2f
  printf(": CXL\n");
Packit Service 745c2f
  if (verbose < 2)
Packit Service 745c2f
    return;
Packit Service 745c2f
Packit Service 745c2f
  if (!config_fetch(d, where + PCI_CXL_CAP, 12))
Packit Service 745c2f
    return;
Packit Service 745c2f
Packit Service 745c2f
  l = get_conf_word(d, where + PCI_CXL_CAP);
Packit Service 745c2f
  printf("\t\tCXLCap:\tCache%c IO%c Mem%c Mem HW Init%c HDMCount %d Viral%c\n",
Packit Service 745c2f
    FLAG(l, PCI_CXL_CAP_CACHE), FLAG(l, PCI_CXL_CAP_IO), FLAG(l, PCI_CXL_CAP_MEM),
Packit Service 745c2f
    FLAG(l, PCI_CXL_CAP_MEM_HWINIT), PCI_CXL_CAP_HDM_CNT(l), FLAG(l, PCI_CXL_CAP_VIRAL));
Packit Service 745c2f
Packit Service 745c2f
  l = get_conf_word(d, where + PCI_CXL_CTRL);
Packit Service 745c2f
  printf("\t\tCXLCtl:\tCache%c IO%c Mem%c Cache SF Cov %d Cache SF Gran %d Cache Clean%c Viral%c\n",
Packit Service 745c2f
    FLAG(l, PCI_CXL_CTRL_CACHE), FLAG(l, PCI_CXL_CTRL_IO), FLAG(l, PCI_CXL_CTRL_MEM),
Packit Service 745c2f
    PCI_CXL_CTRL_CACHE_SF_COV(l), PCI_CXL_CTRL_CACHE_SF_GRAN(l), FLAG(l, PCI_CXL_CTRL_CACHE_CLN),
Packit Service 745c2f
    FLAG(l, PCI_CXL_CTRL_VIRAL));
Packit Service 745c2f
Packit Service 745c2f
  l = get_conf_word(d, where + PCI_CXL_STATUS);
Packit Service 745c2f
  printf("\t\tCXLSta:\tViral%c\n", FLAG(l, PCI_CXL_STATUS_VIRAL));
Packit Service 745c2f
}
Packit Service 745c2f
Packit Service 745c2f
static void
Packit Service 745c2f
cap_dvsec(struct device *d, int where)
Packit Service 745c2f
{
Packit Service 745c2f
  printf("Designated Vendor-Specific: ");
Packit Service 745c2f
  if (!config_fetch(d, where + PCI_DVSEC_HEADER1, 8))
Packit Service 745c2f
    {
Packit Service 745c2f
      printf("<unreadable>\n");
Packit Service 745c2f
      return;
Packit Service 745c2f
    }
Packit Service 745c2f
Packit Service 745c2f
  u32 hdr = get_conf_long(d, where + PCI_DVSEC_HEADER1);
Packit Service 745c2f
  u16 vendor = BITS(hdr, 0, 16);
Packit Service 745c2f
  byte rev = BITS(hdr, 16, 4);
Packit Service 745c2f
  u16 len = BITS(hdr, 20, 12);
Packit Service 745c2f
Packit Service 745c2f
  u16 id = get_conf_long(d, where + PCI_DVSEC_HEADER2);
Packit Service 745c2f
Packit Service 745c2f
  printf("Vendor=%04x ID=%04x Rev=%d Len=%d", vendor, id, rev, len);
Packit Service 745c2f
  if (vendor == PCI_DVSEC_VENDOR_ID_CXL && id == PCI_DVSEC_ID_CXL && len >= 16)
Packit Service 745c2f
    cap_dvsec_cxl(d, where);
Packit Service 745c2f
  else
Packit Service 745c2f
    printf(" \n");
Packit Service 745c2f
}
Packit Service 745c2f
Packit Service 745c2f
static void
Packit 9fb349
cap_evendor(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 hdr;
Packit 9fb349
Packit 9fb349
  printf("Vendor Specific Information: ");
Packit 9fb349
  if (!config_fetch(d, where + PCI_EVNDR_HEADER, 4))
Packit 9fb349
    {
Packit 9fb349
      printf("<unreadable>\n");
Packit 9fb349
      return;
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  hdr = get_conf_long(d, where + PCI_EVNDR_HEADER);
Packit 9fb349
  printf("ID=%04x Rev=%d Len=%03x \n",
Packit 9fb349
    BITS(hdr, 0, 16),
Packit 9fb349
    BITS(hdr, 16, 4),
Packit 9fb349
    BITS(hdr, 20, 12));
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static int l1pm_calc_pwron(int scale, int value)
Packit 9fb349
{
Packit 9fb349
  switch (scale)
Packit 9fb349
    {
Packit 9fb349
      case 0:
Packit 9fb349
	return 2 * value;
Packit 9fb349
      case 1:
Packit 9fb349
	return 10 * value;
Packit 9fb349
      case 2:
Packit 9fb349
	return 100 * value;
Packit 9fb349
    }
Packit 9fb349
  return -1;
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_l1pm(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 l1_cap, val, scale;
Packit 9fb349
  int time;
Packit 9fb349
Packit 9fb349
  printf("L1 PM Substates\n");
Packit 9fb349
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + PCI_L1PM_SUBSTAT_CAP, 12))
Packit 9fb349
    {
Packit 9fb349
      printf("\t\t<unreadable>\n");
Packit 9fb349
      return;
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  l1_cap = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CAP);
Packit 9fb349
  printf("\t\tL1SubCap: ");
Packit 9fb349
  printf("PCI-PM_L1.2%c PCI-PM_L1.1%c ASPM_L1.2%c ASPM_L1.1%c L1_PM_Substates%c\n",
Packit 9fb349
    FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_PM_L12),
Packit 9fb349
    FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_PM_L11),
Packit 9fb349
    FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_ASPM_L12),
Packit 9fb349
    FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_ASPM_L11),
Packit 9fb349
    FLAG(l1_cap, PCI_L1PM_SUBSTAT_CAP_L1PM_SUPP));
Packit 9fb349
Packit 9fb349
  if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
Packit 9fb349
    {
Packit 9fb349
      printf("\t\t\t  PortCommonModeRestoreTime=%dus ", BITS(l1_cap, 8, 8));
Packit 9fb349
      time = l1pm_calc_pwron(BITS(l1_cap, 16, 2), BITS(l1_cap, 19, 5));
Packit 9fb349
      if (time != -1)
Packit 9fb349
	printf("PortTPowerOnTime=%dus\n", time);
Packit 9fb349
      else
Packit 9fb349
	printf("PortTPowerOnTime=<error>\n");
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  val = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CTL1);
Packit 9fb349
  printf("\t\tL1SubCtl1: PCI-PM_L1.2%c PCI-PM_L1.1%c ASPM_L1.2%c ASPM_L1.1%c\n",
Packit 9fb349
    FLAG(val, PCI_L1PM_SUBSTAT_CTL1_PM_L12),
Packit 9fb349
    FLAG(val, PCI_L1PM_SUBSTAT_CTL1_PM_L11),
Packit 9fb349
    FLAG(val, PCI_L1PM_SUBSTAT_CTL1_ASPM_L12),
Packit 9fb349
    FLAG(val, PCI_L1PM_SUBSTAT_CTL1_ASPM_L11));
Packit 9fb349
Packit 9fb349
  if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
Packit 9fb349
    {
Packit 9fb349
      printf("\t\t\t   T_CommonMode=%dus", BITS(val, 8, 8));
Packit 9fb349
Packit 9fb349
      if (l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
Packit 9fb349
	{
Packit 9fb349
	  scale = BITS(val, 29, 3);
Packit 9fb349
	  if (scale > 5)
Packit 9fb349
	    printf(" LTR1.2_Threshold=<error>");
Packit 9fb349
	  else
Packit 9fb349
	    printf(" LTR1.2_Threshold=%lldns", BITS(val, 16, 10) * (unsigned long long) cap_ltr_scale(scale));
Packit 9fb349
	}
Packit 9fb349
      printf("\n");
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  val = get_conf_long(d, where + PCI_L1PM_SUBSTAT_CTL2);
Packit 9fb349
  printf("\t\tL1SubCtl2:");
Packit 9fb349
  if (l1_cap & PCI_L1PM_SUBSTAT_CAP_PM_L12 || l1_cap & PCI_L1PM_SUBSTAT_CAP_ASPM_L12)
Packit 9fb349
    {
Packit 9fb349
      time = l1pm_calc_pwron(BITS(val, 0, 2), BITS(val, 3, 5));
Packit 9fb349
      if (time != -1)
Packit 9fb349
	printf(" T_PwrOn=%dus", time);
Packit 9fb349
      else
Packit 9fb349
	printf(" T_PwrOn=<error>");
Packit 9fb349
    }
Packit 9fb349
  printf("\n");
Packit 9fb349
}
Packit 9fb349
Packit 9fb349
static void
Packit 9fb349
cap_ptm(struct device *d, int where)
Packit 9fb349
{
Packit 9fb349
  u32 buff;
Packit 9fb349
  u16 clock;
Packit 9fb349
Packit 9fb349
  printf("Precision Time Measurement\n");
Packit 9fb349
Packit 9fb349
  if (verbose < 2)
Packit 9fb349
    return;
Packit 9fb349
Packit 9fb349
  if (!config_fetch(d, where + 4, 8))
Packit 9fb349
    {
Packit 9fb349
      printf("\t\t<unreadable>\n");
Packit 9fb349
      return;
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  buff = get_conf_long(d, where + 4);
Packit 9fb349
  printf("\t\tPTMCap: ");
Packit 9fb349
  printf("Requester:%c Responder:%c Root:%c\n",
Packit 9fb349
    FLAG(buff, 0x1),
Packit 9fb349
    FLAG(buff, 0x2),
Packit 9fb349
    FLAG(buff, 0x4));
Packit 9fb349
Packit 9fb349
  clock = BITS(buff, 8, 8);
Packit 9fb349
  printf("\t\tPTMClockGranularity: ");
Packit 9fb349
  switch (clock)
Packit 9fb349
    {
Packit 9fb349
      case 0x00:
Packit 9fb349
        printf("Unimplemented\n");
Packit 9fb349
        break;
Packit 9fb349
      case 0xff:
Packit 9fb349
        printf("Greater than 254ns\n");
Packit 9fb349
        break;
Packit 9fb349
      default:
Packit 9fb349
        printf("%huns\n", clock);
Packit 9fb349
    }
Packit 9fb349
Packit 9fb349
  buff = get_conf_long(d, where + 8);
Packit 9fb349
  printf("\t\tPTMControl: ");
Packit 9fb349
  printf("Enabled:%c RootSelected:%c\n",
Packit 9fb349
    FLAG(buff, 0x1),
Packit 9fb349
    FLAG(buff, 0x2));
Packit 9fb349
Packit 9fb349
  clock = BITS(buff, 8, 8);
Packit 9fb349
  printf("\t\tPTMEffectiveGranularity: ");
Packit 9fb349
  switch (clock)
Packit 9fb349
    {
Packit 9fb349
      case 0x00:
Packit 9fb349
        printf("Unknown\n");
Packit 9fb349
        break;
Packit 9fb349
      case 0xff:
Packit 9fb349
        printf("Greater than 254ns\n");
Packit 9fb349
        break;
Packit 9fb349
      default:
Packit 9fb349
        printf("%huns\n", clock);
Packit 9fb349
    }
Packit 9fb349
}
Packit 9fb349
Packit Service 745c2f
static void
Packit Service 745c2f
print_rebar_range_size(int ld2_size)
Packit Service 745c2f
{
Packit Service 745c2f
  // This function prints the input as a power-of-2 size value
Packit Service 745c2f
  // It is biased with 1MB = 0, ...
Packit Service 745c2f
  // Maximum resizable BAR value supported is 2^63 bytes = 43
Packit Service 745c2f
  // for the extended resizable BAR capability definition
Packit Service 745c2f
  // (otherwise it would stop at 2^28)
Packit Service 745c2f
Packit Service 745c2f
  if (ld2_size >= 0 && ld2_size < 10)
Packit Service 745c2f
    printf(" %dMB", (1 << ld2_size));
Packit Service 745c2f
  else if (ld2_size >= 10 && ld2_size < 20)
Packit Service 745c2f
    printf(" %dGB", (1 << (ld2_size-10)));
Packit Service 745c2f
  else if (ld2_size >= 20 && ld2_size < 30)
Packit Service 745c2f
    printf(" %dTB", (1 << (ld2_size-20)));
Packit Service 745c2f
  else if (ld2_size >= 30 && ld2_size < 40)
Packit Service 745c2f
    printf(" %dPB", (1 << (ld2_size-30)));
Packit Service 745c2f
  else if (ld2_size >= 40 && ld2_size < 44)
Packit Service 745c2f
    printf(" %dEB", (1 << (ld2_size-40)));
Packit Service 745c2f
  else
Packit Service 745c2f
    printf(" <unknown>");
Packit Service 745c2f
}
Packit Service 745c2f
Packit Service 745c2f
static void
Packit Service 745c2f
cap_rebar(struct device *d, int where, int virtual)
Packit Service 745c2f
{
Packit Service 745c2f
  u32 sizes_buffer, control_buffer, ext_sizes, current_size;
Packit Service 745c2f
  u16 bar_index, barcount, i;
Packit Service 745c2f
  // If the structure exists, at least one bar is defined
Packit Service 745c2f
  u16 num_bars = 1;
Packit Service 745c2f
Packit Service 745c2f
  printf("%s Resizable BAR\n", (virtual) ? "Virtual" : "Physical");
Packit Service 745c2f
Packit Service 745c2f
  if (verbose < 2)
Packit Service 745c2f
    return;
Packit Service 745c2f
Packit Service 745c2f
  // Go through all defined BAR definitions of the caps, at minimum 1
Packit Service 745c2f
  // (loop also terminates if num_bars read from caps is > 6)
Packit Service 745c2f
  for (barcount = 0; barcount < num_bars; barcount++)
Packit Service 745c2f
    {
Packit Service 745c2f
      where += 4;
Packit Service 745c2f
Packit Service 745c2f
      // Get the next BAR configuration
Packit Service 745c2f
      if (!config_fetch(d, where, 8))
Packit Service 745c2f
        {
Packit Service 745c2f
          printf("\t\t<unreadable>\n");
Packit Service 745c2f
          return;
Packit Service 745c2f
        }
Packit Service 745c2f
Packit Service 745c2f
      sizes_buffer = get_conf_long(d, where) >> 4;
Packit Service 745c2f
      where += 4;
Packit Service 745c2f
      control_buffer = get_conf_long(d, where);
Packit Service 745c2f
Packit Service 745c2f
      bar_index  = BITS(control_buffer, 0, 3);
Packit Service 745c2f
      current_size = BITS(control_buffer, 8, 6);
Packit Service 745c2f
      ext_sizes = BITS(control_buffer, 16, 16);
Packit Service 745c2f
Packit Service 745c2f
      if (barcount == 0)
Packit Service 745c2f
        {
Packit Service 745c2f
          // Only index 0 controlreg has the num_bar count definition
Packit Service 745c2f
          num_bars = BITS(control_buffer, 5, 3);
Packit Service 745c2f
	  if (num_bars < 1 || num_bars > 6)
Packit Service 745c2f
	    {
Packit Service 745c2f
	      printf("\t\t<error in resizable BAR: num_bars=%d is out of specification>\n", num_bars);
Packit Service 745c2f
	      break;
Packit Service 745c2f
	    }
Packit Service 745c2f
        }
Packit Service 745c2f
Packit Service 745c2f
      // Resizable BAR list entry have an arbitrary index and current size
Packit Service 745c2f
      printf("\t\tBAR %d: current size:", bar_index);
Packit Service 745c2f
      print_rebar_range_size(current_size);
Packit Service 745c2f
Packit Service 745c2f
      if (sizes_buffer || ext_sizes)
Packit Service 745c2f
	{
Packit Service 745c2f
	  printf(", supported:");
Packit Service 745c2f
Packit Service 745c2f
	  for (i=0; i<28; i++)
Packit Service 745c2f
	    if (sizes_buffer & (1U << i))
Packit Service 745c2f
	      print_rebar_range_size(i);
Packit Service 745c2f
Packit Service 745c2f
	  for (i=0; i<16; i++)
Packit Service 745c2f
	    if (ext_sizes & (1U << i))
Packit Service 745c2f
	      print_rebar_range_size(i + 28);
Packit Service 745c2f
	}
Packit Service 745c2f
Packit Service 745c2f
      printf("\n");
Packit Service 745c2f
    }
Packit Service 745c2f
}
Packit Service 745c2f
Packit 9fb349
void
Packit 9fb349
show_ext_caps(struct device *d, int type)
Packit 9fb349
{
Packit 9fb349
  int where = 0x100;
Packit 9fb349
  char been_there[0x1000];
Packit 9fb349
  memset(been_there, 0, 0x1000);
Packit 9fb349
  do
Packit 9fb349
    {
Packit 9fb349
      u32 header;
Packit 9fb349
      int id, version;
Packit 9fb349
Packit 9fb349
      if (!config_fetch(d, where, 4))
Packit 9fb349
	break;
Packit 9fb349
      header = get_conf_long(d, where);
Packit 9fb349
      if (!header)
Packit 9fb349
	break;
Packit 9fb349
      id = header & 0xffff;
Packit 9fb349
      version = (header >> 16) & 0xf;
Packit 9fb349
      printf("\tCapabilities: [%03x", where);
Packit 9fb349
      if (verbose > 1)
Packit 9fb349
	printf(" v%d", version);
Packit 9fb349
      printf("] ");
Packit 9fb349
      if (been_there[where]++)
Packit 9fb349
	{
Packit 9fb349
	  printf("<chain looped>\n");
Packit 9fb349
	  break;
Packit 9fb349
	}
Packit 9fb349
      switch (id)
Packit 9fb349
	{
Packit 9fb349
	  case PCI_EXT_CAP_ID_NULL:
Packit 9fb349
	    printf("Null\n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_AER:
Packit 9fb349
	    cap_aer(d, where, type);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_DPC:
Packit 9fb349
	    cap_dpc(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_VC:
Packit 9fb349
	  case PCI_EXT_CAP_ID_VC2:
Packit 9fb349
	    cap_vc(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_DSN:
Packit 9fb349
	    cap_dsn(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_PB:
Packit 9fb349
	    printf("Power Budgeting \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_RCLINK:
Packit 9fb349
	    cap_rclink(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_RCILINK:
Packit 9fb349
	    printf("Root Complex Internal Link \n");
Packit 9fb349
	    break;
Packit Service 64f0bb
	  case PCI_EXT_CAP_ID_RCECOLL:
Packit Service 64f0bb
	    printf("Root Complex Event Collector \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_MFVC:
Packit 9fb349
	    printf("Multi-Function Virtual Channel \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_RCRB:
Packit 9fb349
	    printf("Root Complex Register Block \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_VNDR:
Packit 9fb349
	    cap_evendor(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_ACS:
Packit 9fb349
	    cap_acs(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_ARI:
Packit 9fb349
	    cap_ari(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_ATS:
Packit 9fb349
	    cap_ats(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_SRIOV:
Packit 9fb349
	    cap_sriov(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_MRIOV:
Packit 9fb349
	    printf("Multi-Root I/O Virtualization \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_MCAST:
Packit 9fb349
	    cap_multicast(d, where, type);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_PRI:
Packit 9fb349
	    cap_pri(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_REBAR:
Packit Service 745c2f
	    cap_rebar(d, where, 0);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_DPA:
Packit 9fb349
	    printf("Dynamic Power Allocation \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_TPH:
Packit 9fb349
	    cap_tph(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_LTR:
Packit 9fb349
	    cap_ltr(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_SECPCI:
Packit 9fb349
	    cap_sec(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_PMUX:
Packit 9fb349
	    printf("Protocol Multiplexing \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_PASID:
Packit 9fb349
	    cap_pasid(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_LNR:
Packit 9fb349
	    printf("LN Requester \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_L1PM:
Packit 9fb349
	    cap_l1pm(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_PTM:
Packit 9fb349
	    cap_ptm(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_M_PCIE:
Packit 9fb349
	    printf("PCI Express over M_PHY \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_FRS:
Packit 9fb349
	    printf("FRS Queueing \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_RTR:
Packit 9fb349
	    printf("Readiness Time Reporting \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_DVSEC:
Packit Service 745c2f
	    cap_dvsec(d, where);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_VF_REBAR:
Packit Service 745c2f
	    cap_rebar(d, where, 1);
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_DLNK:
Packit 9fb349
	    printf("Data Link Feature \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_16GT:
Packit 9fb349
	    printf("Physical Layer 16.0 GT/s \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_LMR:
Packit 9fb349
	    printf("Lane Margining at the Receiver \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_HIER_ID:
Packit 9fb349
	    printf("Hierarchy ID \n");
Packit 9fb349
	    break;
Packit 9fb349
	  case PCI_EXT_CAP_ID_NPEM:
Packit 9fb349
	    printf("Native PCIe Enclosure Management \n");
Packit 9fb349
	    break;
Packit 9fb349
	  default:
Packit 9fb349
	    printf("Extended Capability ID %#02x\n", id);
Packit 9fb349
	    break;
Packit 9fb349
	}
Packit 9fb349
      where = (header >> 20) & ~3;
Packit 9fb349
    } while (where);
Packit 9fb349
}