1 /*- 2 * Copyright (c) 2012 Advanced Computing Technologies LLC 3 * Written by: John H. Baldwin <jhb@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef lint 29 static const char rcsid[] = 30 "$FreeBSD$"; 31 #endif /* not lint */ 32 33 #include <sys/param.h> 34 #include <sys/pciio.h> 35 36 #include <err.h> 37 #include <stdio.h> 38 39 #include <dev/pci/pcireg.h> 40 41 #include "pciconf.h" 42 43 struct bit_table { 44 uint32_t mask; 45 const char *desc; 46 }; 47 48 /* Error indicators in the PCI status register (PCIR_STATUS). */ 49 static struct bit_table pci_status[] = { 50 { PCIM_STATUS_MDPERR, "Master Data Parity Error" }, 51 { PCIM_STATUS_STABORT, "Sent Target-Abort" }, 52 { PCIM_STATUS_RTABORT, "Received Target-Abort" }, 53 { PCIM_STATUS_RMABORT, "Received Master-Abort" }, 54 { PCIM_STATUS_SERR, "Signalled System Error" }, 55 { PCIM_STATUS_PERR, "Detected Parity Error" }, 56 { 0, NULL }, 57 }; 58 59 /* Valid error indicator bits in PCIR_STATUS. */ 60 #define PCI_ERRORS (PCIM_STATUS_MDPERR | PCIM_STATUS_STABORT | \ 61 PCIM_STATUS_RTABORT | PCIM_STATUS_RMABORT | \ 62 PCIM_STATUS_SERR | PCIM_STATUS_PERR) 63 64 /* Error indicators in the PCI-Express device status register. */ 65 static struct bit_table pcie_device_status[] = { 66 { PCIM_EXP_STA_CORRECTABLE_ERROR, "Correctable Error Detected" }, 67 { PCIM_EXP_STA_NON_FATAL_ERROR, "Non-Fatal Error Detected" }, 68 { PCIM_EXP_STA_FATAL_ERROR, "Fatal Error Detected" }, 69 { PCIM_EXP_STA_UNSUPPORTED_REQ, "Unsupported Request Detected" }, 70 { 0, NULL }, 71 }; 72 73 /* Valid error indicator bits in the PCI-Express device status register. */ 74 #define PCIE_ERRORS (PCIM_EXP_STA_CORRECTABLE_ERROR | \ 75 PCIM_EXP_STA_NON_FATAL_ERROR | \ 76 PCIM_EXP_STA_FATAL_ERROR | \ 77 PCIM_EXP_STA_UNSUPPORTED_REQ) 78 79 /* AER Uncorrected errors. */ 80 static struct bit_table aer_uc[] = { 81 { PCIM_AER_UC_TRAINING_ERROR, "Link Training Error" }, 82 { PCIM_AER_UC_DL_PROTOCOL_ERROR, "Data Link Protocol Error" }, 83 { PCIM_AER_UC_SURPRISE_LINK_DOWN, "Surprise Link Down Error" }, 84 { PCIM_AER_UC_POISONED_TLP, "Poisoned TLP" }, 85 { PCIM_AER_UC_FC_PROTOCOL_ERROR, "Flow Control Protocol Error" }, 86 { PCIM_AER_UC_COMPLETION_TIMEOUT, "Completion Timeout" }, 87 { PCIM_AER_UC_COMPLETER_ABORT, "Completer Abort" }, 88 { PCIM_AER_UC_UNEXPECTED_COMPLETION, "Unexpected Completion" }, 89 { PCIM_AER_UC_RECEIVER_OVERFLOW, "Receiver Overflow Error" }, 90 { PCIM_AER_UC_MALFORMED_TLP, "Malformed TLP" }, 91 { PCIM_AER_UC_ECRC_ERROR, "ECRC Error" }, 92 { PCIM_AER_UC_UNSUPPORTED_REQUEST, "Unsupported Request" }, 93 { PCIM_AER_UC_ACS_VIOLATION, "ACS Violation" }, 94 { 0, NULL }, 95 }; 96 97 /* AER Corrected errors. */ 98 static struct bit_table aer_cor[] = { 99 { PCIM_AER_COR_RECEIVER_ERROR, "Receiver Error" }, 100 { PCIM_AER_COR_BAD_TLP, "Bad TLP" }, 101 { PCIM_AER_COR_BAD_DLLP, "Bad DLLP" }, 102 { PCIM_AER_COR_REPLAY_ROLLOVER, "REPLAY_NUM Rollover" }, 103 { PCIM_AER_COR_REPLAY_TIMEOUT, "Replay Timer Timeout" }, 104 { PCIM_AER_COR_ADVISORY_NF_ERROR, "Advisory Non-Fatal Error" }, 105 { 0, NULL }, 106 }; 107 108 static void 109 print_bits(const char *header, struct bit_table *table, uint32_t mask) 110 { 111 int first; 112 113 first = 1; 114 for (; table->desc != NULL; table++) 115 if (mask & table->mask) { 116 if (first) { 117 printf("%14s = ", header); 118 first = 0; 119 } else 120 printf(" "); 121 printf("%s\n", table->desc); 122 mask &= ~table->mask; 123 } 124 if (mask != 0) { 125 if (first) 126 printf("%14s = ", header); 127 else 128 printf(" "); 129 printf("Unknown: 0x%08x\n", mask); 130 } 131 } 132 133 void 134 list_errors(int fd, struct pci_conf *p) 135 { 136 uint32_t mask, severity; 137 uint16_t sta, aer; 138 uint8_t pcie; 139 140 /* First check for standard PCI errors. */ 141 sta = read_config(fd, &p->pc_sel, PCIR_STATUS, 2); 142 print_bits("PCI errors", pci_status, sta & PCI_ERRORS); 143 144 /* See if this is a PCI-express device. */ 145 pcie = pci_find_cap(fd, p, PCIY_EXPRESS); 146 if (pcie == 0) 147 return; 148 149 /* Check for PCI-e errors. */ 150 sta = read_config(fd, &p->pc_sel, pcie + PCIR_EXPRESS_DEVICE_STA, 2); 151 print_bits("PCI-e errors", pcie_device_status, sta & PCIE_ERRORS); 152 153 /* See if this device supports AER. */ 154 aer = pcie_find_cap(fd, p, PCIZ_AER); 155 if (aer == 0) 156 return; 157 158 /* Check for uncorrected errors. */ 159 mask = read_config(fd, &p->pc_sel, aer + PCIR_AER_UC_STATUS, 4); 160 severity = read_config(fd, &p->pc_sel, aer + PCIR_AER_UC_SEVERITY, 4); 161 print_bits("Fatal", aer_uc, mask & severity); 162 print_bits("Non-fatal", aer_uc, mask & ~severity); 163 164 /* Check for corrected errors. */ 165 mask = read_config(fd, &p->pc_sel, aer + PCIR_AER_COR_STATUS, 4); 166 print_bits("Corrected", aer_cor, mask); 167 } 168