]> mj.ucw.cz Git - pciutils.git/blob - ls-ecaps.c
dac87ffe0055ef0244830ebed6717c8252fd49fa
[pciutils.git] / ls-ecaps.c
1 /*
2  *      The PCI Utilities -- Show Extended Capabilities
3  *
4  *      Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL.
7  */
8
9 #include <stdio.h>
10 #include <string.h>
11
12 #include "lspci.h"
13
14 static void
15 cap_dsn(struct device *d, int where)
16 {
17   u32 t1, t2;
18   if (!config_fetch(d, where + 4, 8))
19     return;
20   t1 = get_conf_long(d, where + 4);
21   t2 = get_conf_long(d, where + 8);
22   printf("Device Serial Number %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
23         t2 >> 24, (t2 >> 16) & 0xff, (t2 >> 8) & 0xff, t2 & 0xff,
24         t1 >> 24, (t1 >> 16) & 0xff, (t1 >> 8) & 0xff, t1 & 0xff);
25 }
26
27 static void
28 cap_aer(struct device *d, int where)
29 {
30   u32 l;
31
32   printf("Advanced Error Reporting\n");
33   if (verbose < 2)
34     return;
35
36   if (!config_fetch(d, where + PCI_ERR_UNCOR_STATUS, 24))
37     return;
38
39   l = get_conf_long(d, where + PCI_ERR_UNCOR_STATUS);
40   printf("\t\tUESta:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
41         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
42         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
43         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
44         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
45         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
46   l = get_conf_long(d, where + PCI_ERR_UNCOR_MASK);
47   printf("\t\tUEMsk:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
48         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
49         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
50         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
51         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
52         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
53   l = get_conf_long(d, where + PCI_ERR_UNCOR_SEVER);
54   printf("\t\tUESvrt:\tDLP%c SDES%c TLP%c FCP%c CmpltTO%c CmpltAbrt%c UnxCmplt%c RxOF%c "
55         "MalfTLP%c ECRC%c UnsupReq%c ACSViol%c\n",
56         FLAG(l, PCI_ERR_UNC_DLP), FLAG(l, PCI_ERR_UNC_SDES), FLAG(l, PCI_ERR_UNC_POISON_TLP),
57         FLAG(l, PCI_ERR_UNC_FCP), FLAG(l, PCI_ERR_UNC_COMP_TIME), FLAG(l, PCI_ERR_UNC_COMP_ABORT),
58         FLAG(l, PCI_ERR_UNC_UNX_COMP), FLAG(l, PCI_ERR_UNC_RX_OVER), FLAG(l, PCI_ERR_UNC_MALF_TLP),
59         FLAG(l, PCI_ERR_UNC_ECRC), FLAG(l, PCI_ERR_UNC_UNSUP), FLAG(l, PCI_ERR_UNC_ACS_VIOL));
60   l = get_conf_long(d, where + PCI_ERR_COR_STATUS);
61   printf("\t\tCESta:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c NonFatalErr%c\n",
62         FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
63         FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
64   l = get_conf_long(d, where + PCI_ERR_COR_MASK);
65   printf("\t\tCEMsk:\tRxErr%c BadTLP%c BadDLLP%c Rollover%c Timeout%c NonFatalErr%c\n",
66         FLAG(l, PCI_ERR_COR_RCVR), FLAG(l, PCI_ERR_COR_BAD_TLP), FLAG(l, PCI_ERR_COR_BAD_DLLP),
67         FLAG(l, PCI_ERR_COR_REP_ROLL), FLAG(l, PCI_ERR_COR_REP_TIMER), FLAG(l, PCI_ERR_COR_REP_ANFE));
68   l = get_conf_long(d, where + PCI_ERR_CAP);
69   printf("\t\tAERCap:\tFirst Error Pointer: %02x, GenCap%c CGenEn%c ChkCap%c ChkEn%c\n",
70         PCI_ERR_CAP_FEP(l), FLAG(l, PCI_ERR_CAP_ECRC_GENC), FLAG(l, PCI_ERR_CAP_ECRC_GENE),
71         FLAG(l, PCI_ERR_CAP_ECRC_CHKC), FLAG(l, PCI_ERR_CAP_ECRC_CHKE));
72
73 }
74
75 static void
76 cap_acs(struct device *d, int where)
77 {
78   u16 w;
79
80   printf("Access Control Services\n");
81   if (verbose < 2)
82     return;
83
84   if (!config_fetch(d, where + PCI_ACS_CAP, 4))
85     return;
86
87   w = get_conf_word(d, where + PCI_ACS_CAP);
88   printf("\t\tACSCap:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
89         "DirectTrans%c\n",
90         FLAG(w, PCI_ACS_CAP_VALID), FLAG(w, PCI_ACS_CAP_BLOCK), FLAG(w, PCI_ACS_CAP_REQ_RED),
91         FLAG(w, PCI_ACS_CAP_CMPLT_RED), FLAG(w, PCI_ACS_CAP_FORWARD), FLAG(w, PCI_ACS_CAP_EGRESS),
92         FLAG(w, PCI_ACS_CAP_TRANS));
93   w = get_conf_word(d, where + PCI_ACS_CTRL);
94   printf("\t\tACSCtl:\tSrcValid%c TransBlk%c ReqRedir%c CmpltRedir%c UpstreamFwd%c EgressCtrl%c "
95         "DirectTrans%c\n",
96         FLAG(w, PCI_ACS_CTRL_VALID), FLAG(w, PCI_ACS_CTRL_BLOCK), FLAG(w, PCI_ACS_CTRL_REQ_RED),
97         FLAG(w, PCI_ACS_CTRL_CMPLT_RED), FLAG(w, PCI_ACS_CTRL_FORWARD), FLAG(w, PCI_ACS_CTRL_EGRESS),
98         FLAG(w, PCI_ACS_CTRL_TRANS));
99 }
100
101 static void
102 cap_ari(struct device *d, int where)
103 {
104   u16 w;
105
106   printf("Alternative Routing-ID Interpretation (ARI)\n");
107   if (verbose < 2)
108     return;
109
110   if (!config_fetch(d, where + PCI_ARI_CAP, 4))
111     return;
112
113   w = get_conf_word(d, where + PCI_ARI_CAP);
114   printf("\t\tARICap:\tMFVC%c ACS%c, Next Function: %d\n",
115         FLAG(w, PCI_ARI_CAP_MFVC), FLAG(w, PCI_ARI_CAP_ACS),
116         PCI_ARI_CAP_NFN(w));
117   w = get_conf_word(d, where + PCI_ARI_CTRL);
118   printf("\t\tARICtl:\tMFVC%c ACS%c, Function Group: %d\n",
119         FLAG(w, PCI_ARI_CTRL_MFVC), FLAG(w, PCI_ARI_CTRL_ACS),
120         PCI_ARI_CTRL_FG(w));
121 }
122
123 static void
124 cap_ats(struct device *d, int where)
125 {
126   u16 w;
127
128   printf("Address Translation Service (ATS)\n");
129   if (verbose < 2)
130     return;
131
132   if (!config_fetch(d, where + PCI_ATS_CAP, 4))
133     return;
134
135   w = get_conf_word(d, where + PCI_ATS_CAP);
136   printf("\t\tATSCap:\tInvalidate Queue Depth: %02x\n", PCI_ATS_CAP_IQD(w));
137   w = get_conf_word(d, where + PCI_ATS_CTRL);
138   printf("\t\tATSCtl:\tEnable%c, Smallest Translation Unit: %02x\n",
139         FLAG(w, PCI_ATS_CTRL_ENABLE), PCI_ATS_CTRL_STU(w));
140 }
141
142 static void
143 cap_sriov(struct device *d, int where)
144 {
145   u16 b;
146   u16 w;
147   u32 l;
148   int i;
149
150   printf("Single Root I/O Virtualization (SR-IOV)\n");
151   if (verbose < 2)
152     return;
153
154   if (!config_fetch(d, where + PCI_IOV_CAP, 0x3c))
155     return;
156
157   l = get_conf_long(d, where + PCI_IOV_CAP);
158   printf("\t\tIOVCap:\tMigration%c, Interrupt Message Number: %03x\n",
159         FLAG(l, PCI_IOV_CAP_VFM), PCI_IOV_CAP_IMN(l));
160   w = get_conf_word(d, where + PCI_IOV_CTRL);
161   printf("\t\tIOVCtl:\tEnable%c Migration%c Interrupt%c MSE%c ARIHierarchy%c\n",
162         FLAG(w, PCI_IOV_CTRL_VFE), FLAG(w, PCI_IOV_CTRL_VFME),
163         FLAG(w, PCI_IOV_CTRL_VFMIE), FLAG(w, PCI_IOV_CTRL_MSE),
164         FLAG(w, PCI_IOV_CTRL_ARI));
165   w = get_conf_word(d, where + PCI_IOV_STATUS);
166   printf("\t\tIOVSta:\tMigration%c\n", FLAG(w, PCI_IOV_STATUS_MS));
167   w = get_conf_word(d, where + PCI_IOV_INITIALVF);
168   printf("\t\tInitial VFs: %d, ", w);
169   w = get_conf_word(d, where + PCI_IOV_TOTALVF);
170   printf("Total VFs: %d, ", w);
171   w = get_conf_word(d, where + PCI_IOV_NUMVF);
172   printf("Number of VFs: %d, ", w);
173   b = get_conf_byte(d, where + PCI_IOV_FDL);
174   printf("Function Dependency Link: %02x\n", b);
175   w = get_conf_word(d, where + PCI_IOV_OFFSET);
176   printf("\t\tVF offset: %d, ", w);
177   w = get_conf_word(d, where + PCI_IOV_STRIDE);
178   printf("stride: %d, ", w);
179   w = get_conf_word(d, where + PCI_IOV_DID);
180   printf("Device ID: %04x\n", w);
181   l = get_conf_long(d, where + PCI_IOV_SUPPS);
182   printf("\t\tSupported Page Size: %08x, ", l);
183   l = get_conf_long(d, where + PCI_IOV_SYSPS);
184   printf("System Page Size: %08x\n", l);
185
186   for (i=0; i < PCI_IOV_NUM_BAR; i++)
187     {
188       u32 addr;
189       int type;
190       u32 h;
191       l = get_conf_long(d, where + PCI_IOV_BAR_BASE + 4*i);
192       if (l == 0xffffffff)
193         l = 0;
194       if (!l)
195         continue;
196       printf("\t\tRegion %d: Memory at ", i);
197       addr = l & PCI_ADDR_MEM_MASK;
198       type = l & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
199       if (type == PCI_BASE_ADDRESS_MEM_TYPE_64)
200         {
201           i++;
202           h = get_conf_long(d, where + PCI_IOV_BAR_BASE + (i*4));
203           printf("%08x", h);
204         }
205       printf("%08x (%s-bit, %sprefetchable)\n",
206         addr,
207         (type == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32" : "64",
208         (l & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
209     }
210
211   l = get_conf_long(d, where + PCI_IOV_MSAO);
212   printf("\t\tVF Migration: offset: %08x, BIR: %x\n", PCI_IOV_MSA_OFFSET(l),
213         PCI_IOV_MSA_BIR(l));
214 }
215
216 static void
217 cap_vc(struct device *d, int where)
218 {
219   u32 cr1, cr2;
220   u16 ctrl, status;
221   int evc_cnt;
222   int arb_table_pos;
223   int i, j;
224   static const char ref_clocks[][6] = { "100ns" };
225   static const char arb_selects[][7] = { "Fixed", "WRR32", "WRR64", "WRR128" };
226   static const char vc_arb_selects[][8] = { "Fixed", "WRR32", "WRR64", "WRR128", "TWRR128", "WRR256" };
227   char buf[8];
228
229   printf("Virtual Channel\n");
230   if (verbose < 2)
231     return;
232
233   if (!config_fetch(d, where + 4, 0x1c - 4))
234     return;
235
236   cr1 = get_conf_long(d, where + PCI_VC_PORT_REG1);
237   cr2 = get_conf_long(d, where + PCI_VC_PORT_REG2);
238   ctrl = get_conf_word(d, where + PCI_VC_PORT_CTRL);
239   status = get_conf_word(d, where + PCI_VC_PORT_STATUS);
240
241   evc_cnt = BITS(cr1, 0, 3);
242   printf("\t\tCaps:\tLPEVC=%d RefClk=%s PATEntrySize=%d\n",
243     BITS(cr1, 4, 3),
244     TABLE(ref_clocks, BITS(cr1, 8, 2), buf),
245     BITS(cr1, 10, 2));
246
247   printf("\t\tArb:\t");
248   for (i=0; i<8; i++)
249     if (arb_selects[i][0] != '?' || cr2 & (1 << i))
250       printf("%s%c ", arb_selects[i], FLAG(cr2, 1 << i));
251   arb_table_pos = BITS(cr2, 24, 8);
252   printf("TableOffset=%x\n", arb_table_pos);
253
254   printf("\t\tCtrl:\tArbSelect=%s\n", TABLE(arb_selects, BITS(ctrl, 1, 3), buf));
255   printf("\t\tStatus:\tInProgress%c\n", FLAG(status, 1));
256
257   if (arb_table_pos)
258     printf("\t\tPort Arbitration Table <?>\n");
259
260   for (i=0; i<=evc_cnt; i++)
261     {
262       int pos = where + PCI_VC_RES_CAP + 12*i;
263       u32 rcap, rctrl;
264       u16 rstatus;
265       int pat_pos;
266
267       printf("\t\tVC%d:\t", i);
268       if (!config_fetch(d, pos, 12))
269         {
270           printf("<unreadable>\n");
271           continue;
272         }
273       rcap = get_conf_long(d, pos);
274       rctrl = get_conf_long(d, pos+4);
275       rstatus = get_conf_word(d, pos+8);
276
277       pat_pos = BITS(rcap, 24, 8);
278       printf("Caps:\tPATOffset=%02x MaxTimeSlots=%d RejSnoopTrans%c\n",
279         pat_pos,
280         BITS(rcap, 16, 6) + 1,
281         FLAG(rcap, 1 << 15));
282
283       printf("\t\t\tArb:");
284       for (j=0; j<8; j++)
285         if (vc_arb_selects[j][0] != '?' || rcap & (1 << j))
286           printf("%c%s%c", (j ? ' ' : '\t'), vc_arb_selects[j], FLAG(rcap, 1 << j));
287
288       printf("\n\t\t\tCtrl:\tEnable%c ID=%d ArbSelect=%s TC/VC=%02x\n",
289         FLAG(rctrl, 1 << 31),
290         BITS(rctrl, 24, 3),
291         TABLE(vc_arb_selects, BITS(rctrl, 17, 3), buf),
292         BITS(rctrl, 0, 8));
293
294       printf("\t\t\tStatus:\tNegoPending%c InProgress%c\n",
295         FLAG(rstatus, 2),
296         FLAG(rstatus, 1));
297
298       if (pat_pos)
299         printf("\t\t\tPort Arbitration Table <?>\n");
300     }
301 }
302
303 static void
304 cap_rclink(struct device *d, int where)
305 {
306   u32 esd;
307   int num_links;
308   int i;
309   static const char elt_types[][9] = { "Config", "Egress", "Internal" };
310   char buf[8];
311
312   printf("Root Complex Link\n");
313   if (verbose < 2)
314     return;
315
316   if (!config_fetch(d, where + 4, PCI_RCLINK_LINK1 - 4))
317     return;
318
319   esd = get_conf_long(d, where + PCI_RCLINK_ESD);
320   num_links = BITS(esd, 8, 8);
321   printf("\t\tDesc:\tPortNumber=%02x ComponentID=%02x EltType=%s\n",
322     BITS(esd, 24, 8),
323     BITS(esd, 16, 8),
324     TABLE(elt_types, BITS(esd, 0, 8), buf));
325
326   for (i=0; i<num_links; i++)
327     {
328       int pos = where + PCI_RCLINK_LINK1 + i*PCI_RCLINK_LINK_SIZE;
329       u32 desc;
330       u32 addr_lo, addr_hi;
331
332       printf("\t\tLink%d:\t", i);
333       if (!config_fetch(d, pos, PCI_RCLINK_LINK_SIZE))
334         {
335           printf("<unreadable>\n");
336           return;
337         }
338       desc = get_conf_long(d, pos + PCI_RCLINK_LINK_DESC);
339       addr_lo = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR);
340       addr_hi = get_conf_long(d, pos + PCI_RCLINK_LINK_ADDR + 4);
341
342       printf("Desc:\tTargetPort=%02x TargetComponent=%02x AssocRCRB%c LinkType=%s LinkValid%c\n",
343         BITS(desc, 24, 8),
344         BITS(desc, 16, 8),
345         FLAG(desc, 4),
346         ((desc & 2) ? "Config" : "MemMapped"),
347         FLAG(desc, 1));
348
349       if (desc & 2)
350         {
351           int n = addr_lo & 7;
352           if (!n)
353             n = 8;
354           printf("\t\t\tAddr:\t%02x:%02x.%d  CfgSpace=%08x%08x\n",
355             BITS(addr_lo, 20, n),
356             BITS(addr_lo, 15, 5),
357             BITS(addr_lo, 12, 3),
358             addr_hi, addr_lo);
359         }
360       else
361         printf("\t\t\tAddr:\t%08x%08x\n", addr_hi, addr_lo);
362     }
363 }
364
365 static void
366 cap_evendor(struct device *d, int where)
367 {
368   u32 hdr;
369
370   printf("Vendor Specific Information: ");
371   if (!config_fetch(d, where + PCI_EVNDR_HEADER, 4))
372     {
373       printf("<unreadable>\n");
374       return;
375     }
376
377   hdr = get_conf_long(d, where + PCI_EVNDR_HEADER);
378   printf("ID=%04x Rev=%d Len=%03x <?>\n",
379     BITS(hdr, 0, 16),
380     BITS(hdr, 16, 4),
381     BITS(hdr, 20, 12));
382 }
383
384 void
385 show_ext_caps(struct device *d)
386 {
387   int where = 0x100;
388   char been_there[0x1000];
389   memset(been_there, 0, 0x1000);
390   do
391     {
392       u32 header;
393       int id, version;
394
395       if (!config_fetch(d, where, 4))
396         break;
397       header = get_conf_long(d, where);
398       if (!header)
399         break;
400       id = header & 0xffff;
401       version = (header >> 16) & 0xf;
402       printf("\tCapabilities: [%03x", where);
403       if (verbose > 1)
404         printf(" v%d", version);
405       printf("] ");
406       if (been_there[where]++)
407         {
408           printf("<chain looped>\n");
409           break;
410         }
411       switch (id)
412         {
413           case PCI_EXT_CAP_ID_AER:
414             cap_aer(d, where);
415             break;
416           case PCI_EXT_CAP_ID_VC:
417           case PCI_EXT_CAP_ID_VC2:
418             cap_vc(d, where);
419             break;
420           case PCI_EXT_CAP_ID_DSN:
421             cap_dsn(d, where);
422             break;
423           case PCI_EXT_CAP_ID_PB:
424             printf("Power Budgeting <?>\n");
425             break;
426           case PCI_EXT_CAP_ID_RCLINK:
427             cap_rclink(d, where);
428             break;
429           case PCI_EXT_CAP_ID_RCILINK:
430             printf("Root Complex Internal Link <?>\n");
431             break;
432           case PCI_EXT_CAP_ID_RCECOLL:
433             printf("Root Complex Event Collector <?>\n");
434             break;
435           case PCI_EXT_CAP_ID_MFVC:
436             printf("Multi-Function Virtual Channel <?>\n");
437             break;
438           case PCI_EXT_CAP_ID_RBCB:
439             printf("Root Bridge Control Block <?>\n");
440             break;
441           case PCI_EXT_CAP_ID_VNDR:
442             cap_evendor(d, where);
443             break;
444           case PCI_EXT_CAP_ID_ACS:
445             cap_acs(d, where);
446             break;
447           case PCI_EXT_CAP_ID_ARI:
448             cap_ari(d, where);
449             break;
450           case PCI_EXT_CAP_ID_ATS:
451             cap_ats(d, where);
452             break;
453           case PCI_EXT_CAP_ID_SRIOV:
454             cap_sriov(d, where);
455             break;
456           default:
457             printf("#%02x\n", id);
458             break;
459         }
460       where = (header >> 20) & ~3;
461     } while (where);
462 }