Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/pci/ReadAER.c
- This file was added.
| /*- | |||||
| * Copyright (c) 2016 Isilon LLC, EMC | |||||
| * All rights reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in the | |||||
| * documentation and/or other materials provided with the distribution. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
| * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
| * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
| * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| */ | |||||
| #include <stdio.h> | |||||
| #include <sys/types.h> | |||||
| #include <sys/sysctl.h> | |||||
| #include <stdlib.h> | |||||
| #include <string.h> | |||||
| #include <errno.h> | |||||
| struct AER_error_data { | |||||
| int error_number; | |||||
| const char *dev_name; | |||||
| int unit; | |||||
| int pcie_cap_status; | |||||
| int unc_err_status; | |||||
| int unc_err_seve; | |||||
| int c_err_status; | |||||
| int AER_ECRC; | |||||
| int root_err_status; | |||||
| int err_src_ID; | |||||
| int c_err_src_ID; | |||||
| }; | |||||
| void printThings(struct AER_error_data error_data); | |||||
| int main(int argc, char *argv[]) | |||||
| { | |||||
| int error; | |||||
| int indexnum; | |||||
| int name[4]; | |||||
| int count; | |||||
| struct AER_error_data error_data; | |||||
| size_t size; | |||||
| size = sizeof(int); | |||||
| error = sysctlbyname("hw.pci.pcib_error_count", &count, &size, NULL, 0); | |||||
| if (error != 0) { | |||||
| printf("Error: %d\n", error); | |||||
| printf("Errno Translate: %s\n", strerror(errno)); | |||||
| return 0; | |||||
| } | |||||
| printf("Total %d error(s).\n", count); | |||||
| printf("Old records may be overwritten, depends on driver's record length limit.\n"); | |||||
| if (argc != 2) { | |||||
| printf("arg error: expect one argument: index of error to fetch, or -1 to fetch last record\n"); | |||||
| return 0; | |||||
| } | |||||
| indexnum = atoi(argv[1]); | |||||
| if ((indexnum < -1) || (indexnum > count - 1) || (count == 0)) { | |||||
| printf("Invalid argument\n"); | |||||
| return 0; | |||||
| } | |||||
| if (indexnum == -1) | |||||
| indexnum = count -1; | |||||
| size = 4; | |||||
| sysctlnametomib("hw.pci.pcib_error_records", name, &size); | |||||
| name[3] = indexnum; | |||||
| bzero(&error_data, sizeof(error_data)); | |||||
| size = sizeof(error_data); | |||||
| error = sysctl(name, 4, &error_data, &size, NULL, 0); | |||||
| if (error != 0) { | |||||
| printf("Error: %d\n", error); | |||||
| printf("Errno Translate: %s\n", strerror(errno)); | |||||
| } else | |||||
| printThings(error_data); | |||||
| return 0; | |||||
| } | |||||
| void printDecHex(int value) | |||||
| { | |||||
| printf(" %d, HEX: %X\n", value, value); | |||||
| } | |||||
| void printThings(struct AER_error_data error_data) | |||||
| { | |||||
| printf("-------------------------------------\n"); | |||||
| printf("Error NO.%d\n", error_data.error_number); | |||||
| printf("Error Source: pcib%d\n", error_data.unit); | |||||
| printf("-------\n"); | |||||
| printf("Get: pcie_cap_status:"); | |||||
| printDecHex(error_data.pcie_cap_status); | |||||
| printf("Get: unc_err_status:"); | |||||
| printDecHex(error_data.unc_err_status); | |||||
| printf("Get: unc_err_seve:"); | |||||
| printDecHex(error_data.unc_err_seve); | |||||
| printf("Get: c_err_status:"); | |||||
| printDecHex(error_data.c_err_status); | |||||
| printf("Get: AER_ECRC:"); | |||||
| printDecHex(error_data.AER_ECRC); | |||||
| printf("Get: root_err_status:"); | |||||
| printDecHex(error_data.root_err_status); | |||||
| printf("Get: err_src_ID:"); | |||||
| printDecHex(error_data.err_src_ID); | |||||
| printf("Get: c_err_src_ID:"); | |||||
| printDecHex(error_data.c_err_src_ID); | |||||
| printf("------------------------------------\n"); | |||||
| } | |||||