Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #include <ctype.h> |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 17 | #include <errno.h> |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 18 | #include <inttypes.h> |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 19 | #include <limits.h> |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 20 | #include <peci.h> |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 24 | #include <time.h> |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 25 | #include <unistd.h> |
| 26 | #ifndef ABS |
| 27 | #define ABS(_v_) (((_v_) > 0) ? (_v_) : -(_v_)) |
| 28 | #endif |
| 29 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 30 | #define CC_COUNT 256 // CC is a byte so only has 256 possible values |
| 31 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 32 | extern EPECIStatus peci_GetDIB(uint8_t target, uint64_t* dib); |
| 33 | |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 34 | double getTimeDifference(const struct timespec begin) |
| 35 | { |
| 36 | double timeDiff = 0.0; |
| 37 | struct timespec end; |
| 38 | long seconds = 0; |
| 39 | long nanoseconds = 0; |
| 40 | |
| 41 | clock_gettime(CLOCK_REALTIME, &end); |
| 42 | seconds = end.tv_sec - begin.tv_sec; |
| 43 | nanoseconds = end.tv_nsec - begin.tv_nsec; |
| 44 | timeDiff = (double)seconds + (double)nanoseconds * 1e-9; |
| 45 | |
| 46 | return timeDiff; |
| 47 | } |
| 48 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 49 | void Usage(char* progname) |
| 50 | { |
| 51 | printf("Usage:\n"); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 52 | printf("%s [-h] [-v] [-t] [-a <addr>] [-i <domain id>] [-s <size>] [-l " |
| 53 | "<count>] " |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 54 | "<command> [parameters]\n", |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 55 | progname); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 56 | printf("Options:\n"); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 57 | printf("\t%-12s%s\n", "-h", "Display this help information"); |
| 58 | printf("\t%-12s%s\n", "-v", |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 59 | "Display additional information about the command"); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 60 | printf("\t%-12s%s\n", "-t", "Measure request-to-response time"); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 61 | printf("\t%-12s%s %lu\n", "-l <count>", |
| 62 | "Loop the command the given number of times. <count> is in the " |
| 63 | "range 1 to", |
| 64 | ULONG_MAX); |
| 65 | printf("\t%-12s%s\n", "-a <addr>", |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 66 | "Address of the target. Accepted values are 48-55 (0x30-0x37). " |
| 67 | "Default is 48 (0x30)"); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 68 | printf("\t%-12s%s\n", "-i <domain id>", |
| 69 | "Domain ID of the target. Accepted values are 0-127. Default is 0"); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 70 | printf("\t%-12s%s\n", "-s <size>", |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 71 | "Size of data to read or write in bytes. Accepted values are 1, 2, " |
| 72 | "4, 8, and 16. Default is 4"); |
Anna Platash | 03d7dae | 2021-02-05 13:52:05 +0100 | [diff] [blame] | 73 | printf("\t%-12s%s\n", "-d", |
| 74 | "Set PECI device name, for example \"-d /dev/peci-0\""); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 75 | printf("Commands:\n"); |
| 76 | printf("\t%-28s%s\n", "Ping", "Ping the target"); |
| 77 | printf("\t%-28s%s\n", "GetTemp", "Get the temperature"); |
| 78 | printf("\t%-28s%s\n", "GetDIB", "Get the DIB"); |
| 79 | printf("\t%-28s%s\n", "RdPkgConfig", |
| 80 | "Read Package Config <Index Parameter>"); |
| 81 | printf("\t%-28s%s\n", "WrPkgConfig", |
| 82 | "Write Package Config <Index Parameter Data>"); |
| 83 | printf("\t%-28s%s\n", "RdIAMSR", "MSR Read <Thread Address>"); |
| 84 | printf("\t%-28s%s\n", "RdPCIConfig", "PCI Read <Bus Dev Func [Reg]>"); |
| 85 | printf("\t%-28s%s\n", "RdPCIConfigLocal", |
| 86 | "Local PCI Read <Bus Dev Func [Reg]>"); |
| 87 | printf("\t%-28s%s\n", "WrPCIConfigLocal", |
| 88 | "Local PCI Write <Bus Dev Func Reg Data>"); |
| 89 | printf("\t%-28s%s\n", "RdEndpointConfigPCILocal", |
| 90 | "Endpoint Local PCI Config Read <Seg Bus Dev Func Reg>"); |
| 91 | printf("\t%-28s%s\n", "WrEndpointConfigPCILocal", |
| 92 | "Endpoint Local PCI Config Write <Seg Bus Dev Func Reg Data>"); |
| 93 | printf("\t%-28s%s\n", "RdEndpointConfigPCI", |
| 94 | "Endpoint PCI Config Read <Seg Bus Dev Func Reg>"); |
| 95 | printf("\t%-28s%s\n", "WrEndpointConfigPCI", |
| 96 | "Endpoint PCI Config Write <Seg Bus Dev Func Reg Data>"); |
| 97 | printf("\t%-28s%s\n", "RdEndpointConfigMMIO", |
| 98 | "Endpoint MMIO Read <AType Bar Seg Bus Dev Func Reg>"); |
| 99 | printf("\t%-28s%s\n", "WrEndpointConfigMMIO", |
| 100 | "Endpoint MMIO Write <AType Bar Seg Bus Dev Func Reg Data>"); |
| 101 | printf("\t%-28s%s\n", "raw", "Raw PECI command in bytes"); |
| 102 | printf("\n"); |
| 103 | } |
| 104 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 105 | static void printLoopSummary(uint32_t* ccCounts) |
| 106 | { |
| 107 | printf("Completion code counts:\n"); |
| 108 | for (uint32_t i = 0; i < CC_COUNT; i++) |
| 109 | { |
| 110 | if (ccCounts[i]) |
| 111 | { |
| 112 | printf(" 0x%02x: %d\n", i, ccCounts[i]); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 117 | int main(int argc, char* argv[]) |
| 118 | { |
| 119 | int c; |
| 120 | int i = 0; |
| 121 | char* cmd = NULL; |
Patrick Williams | b65de2d | 2023-05-26 15:14:02 -0500 | [diff] [blame^] | 122 | EPECIStatus ret = PECI_CC_SUCCESS; |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 123 | uint8_t address = 0x30; // use default address of 48d |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 124 | uint8_t domainId = 0; // use default domain ID of 0 |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 125 | uint8_t u8Size = 4; // default to a DWORD |
| 126 | uint32_t u32PciReadVal = 0; |
| 127 | uint8_t u8Seg = 0; |
| 128 | uint8_t u8Bar = 0; |
| 129 | uint8_t u8AddrType = 0; |
| 130 | uint8_t u8PciBus = 0; |
| 131 | uint8_t u8PciDev = 0; |
| 132 | uint8_t u8PciFunc = 0; |
| 133 | uint16_t u16PciReg = 0; |
| 134 | uint64_t u64Offset = 0; |
| 135 | uint32_t u32PciWriteVal = 0; |
| 136 | uint64_t u64MmioWriteVal = 0; |
| 137 | uint8_t u8PkgIndex = 0; |
| 138 | uint16_t u16PkgParam = 0; |
| 139 | uint32_t u32PkgValue = 0; |
| 140 | uint8_t u8MsrThread = 0; |
| 141 | uint16_t u16MsrAddr = 0; |
| 142 | uint64_t u64MsrVal = 0; |
| 143 | short temperature; |
| 144 | uint64_t dib; |
| 145 | int index = 0; |
| 146 | uint8_t cc = 0; |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 147 | bool measureTime = false; |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 148 | bool verbose = false; |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 149 | bool looped = false; |
| 150 | uint32_t loops = 1; |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 151 | uint32_t loopCount = 1; |
Nirav Shah | fd5dfd5 | 2022-03-09 12:29:41 -0800 | [diff] [blame] | 152 | uint32_t ccCounts[CC_COUNT] = {0}; |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 153 | struct timespec begin; |
| 154 | double timeSpent = 0.0; |
| 155 | double totalTimeSpent = 0.0; |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 156 | |
| 157 | // |
| 158 | // Parse arguments. |
| 159 | // |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 160 | while (-1 != (c = getopt(argc, argv, "hvtl:a:i:s:d:"))) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 161 | { |
| 162 | switch (c) |
| 163 | { |
| 164 | case 'h': |
| 165 | Usage(argv[0]); |
| 166 | return 0; |
| 167 | break; |
| 168 | |
| 169 | case 'v': |
| 170 | verbose = true; |
| 171 | break; |
| 172 | |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 173 | case 't': |
| 174 | measureTime = true; |
| 175 | break; |
| 176 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 177 | case 'l': |
| 178 | looped = true; |
| 179 | errno = 0; |
| 180 | if (optarg != NULL) |
| 181 | loops = (uint32_t)strtoul(optarg, NULL, 0); |
| 182 | if (!loops || errno) |
| 183 | { |
| 184 | printf("ERROR: Invalid loop count\n"); |
| 185 | if (errno) |
| 186 | perror(""); |
| 187 | goto ErrorExit; |
| 188 | } |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 189 | loopCount = |
| 190 | loops; // Preserve a copy for average time measurement |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 191 | break; |
| 192 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 193 | case 'a': |
| 194 | if (optarg != NULL) |
| 195 | address = (uint8_t)strtoul(optarg, NULL, 0); |
| 196 | if (address < MIN_CLIENT_ADDR || address > MAX_CLIENT_ADDR) |
| 197 | { |
| 198 | printf("ERROR: Invalid address \"0x%x\"\n", address); |
| 199 | goto ErrorExit; |
| 200 | } |
| 201 | |
| 202 | break; |
| 203 | |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 204 | case 'i': |
| 205 | if (optarg != NULL) |
| 206 | domainId = (uint8_t)strtoul(optarg, NULL, 0); |
| 207 | if (domainId >= 128) // Domain ID is only 7 bits |
| 208 | { |
| 209 | printf("ERROR: Invalid domain ID \"%d\"\n", domainId); |
| 210 | goto ErrorExit; |
| 211 | } |
| 212 | break; |
| 213 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 214 | case 's': |
| 215 | if (optarg != NULL) |
| 216 | u8Size = (uint8_t)strtoul(optarg, NULL, 0); |
| 217 | if (u8Size != 1 && u8Size != 2 && u8Size != 4 && u8Size != 8 && |
| 218 | u8Size != 16) |
| 219 | { |
| 220 | printf("ERROR: Invalid size \"%d\"\n", u8Size); |
| 221 | goto ErrorExit; |
| 222 | } |
| 223 | break; |
| 224 | |
Anna Platash | 03d7dae | 2021-02-05 13:52:05 +0100 | [diff] [blame] | 225 | case 'd': |
| 226 | peci_SetDevName(optarg); |
| 227 | break; |
| 228 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 229 | default: |
| 230 | printf("ERROR: Unrecognized option \"-%c\"\n", optopt); |
| 231 | goto ErrorExit; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // Get the command from the first parameter |
| 237 | cmd = argv[optind++]; |
| 238 | if (cmd == NULL) |
| 239 | { |
| 240 | Usage(argv[0]); |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | // Allow any case |
| 245 | while (cmd[i]) |
| 246 | { |
| 247 | cmd[i] = (char)tolower((int)cmd[i]); |
| 248 | i++; |
| 249 | } |
| 250 | |
| 251 | // |
| 252 | // Execute the command |
| 253 | // |
| 254 | if (verbose) |
| 255 | { |
| 256 | printf("PECI target[0x%x]: ", address); |
| 257 | } |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 258 | |
| 259 | if (measureTime) |
| 260 | { |
| 261 | if (verbose && (loopCount > 1)) |
| 262 | { |
| 263 | printf("Warning: Request-response time measurement with verbose " |
| 264 | "mode can affect the time between consecutive commands in " |
| 265 | "looped mode!\n"); |
| 266 | } |
| 267 | } |
| 268 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 269 | if (strcmp(cmd, "ping") == 0) |
| 270 | { |
| 271 | if (verbose) |
| 272 | { |
| 273 | printf("Pinging ... "); |
| 274 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 275 | while (loops--) |
| 276 | { |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 277 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 278 | ret = peci_Ping(address); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 279 | timeSpent = getTimeDifference(begin); |
| 280 | if (verbose && measureTime) |
| 281 | { |
| 282 | printf("\nTime taken in iteration %d = %lf s\n", |
| 283 | (loopCount - loops), timeSpent); |
| 284 | } |
| 285 | totalTimeSpent += timeSpent; |
| 286 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 287 | if (verbose || loops == 0) |
| 288 | { |
| 289 | if (0 != ret) |
| 290 | { |
| 291 | printf("Failed\n"); |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | printf("Succeeded\n"); |
| 296 | } |
| 297 | } |
| 298 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 299 | } |
| 300 | else if (strcmp(cmd, "getdib") == 0) |
| 301 | { |
| 302 | if (verbose) |
| 303 | { |
| 304 | printf("GetDIB\n"); |
| 305 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 306 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 307 | { |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 308 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 309 | ret = peci_GetDIB(address, &dib); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 310 | timeSpent = getTimeDifference(begin); |
| 311 | if (verbose && measureTime) |
| 312 | { |
| 313 | printf("\nTime taken in iteration %d = %lf s\n", |
| 314 | (loopCount - loops), timeSpent); |
| 315 | } |
| 316 | totalTimeSpent += timeSpent; |
| 317 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 318 | if (verbose || loops == 0) |
| 319 | { |
| 320 | if (0 != ret) |
| 321 | { |
| 322 | printf("ERROR %d: Retrieving DIB failed\n", ret); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | printf(" 0x%" PRIx64 "\n", dib); |
| 327 | } |
| 328 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 329 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | else if (strcmp(cmd, "gettemp") == 0) |
| 333 | { |
| 334 | if (verbose) |
| 335 | { |
| 336 | printf("GetTemp\n"); |
| 337 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 338 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 339 | { |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 340 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 341 | ret = peci_GetTemp(address, &temperature); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 342 | timeSpent = getTimeDifference(begin); |
| 343 | if (verbose && measureTime) |
| 344 | { |
| 345 | printf("\nTime taken in iteration %d = %lf s\n", |
| 346 | (loopCount - loops), timeSpent); |
| 347 | } |
| 348 | totalTimeSpent += timeSpent; |
| 349 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 350 | if (verbose || loops == 0) |
| 351 | { |
| 352 | if (0 != ret) |
| 353 | { |
| 354 | printf("ERROR %d: Retrieving temperature failed\n", ret); |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | printf(" %04xh (%c%d.%02dC)\n", |
| 359 | (int)(unsigned int)(unsigned short)temperature, |
| 360 | (0 > temperature) ? '-' : '+', |
| 361 | (int)((unsigned int)ABS(temperature) / 64), |
| 362 | (int)(((unsigned int)ABS(temperature) % 64) * 100) / |
| 363 | 64); |
| 364 | } |
| 365 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 366 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | else if (strcmp(cmd, "rdpkgconfig") == 0) |
| 370 | { |
| 371 | index = argc; |
| 372 | switch (argc - optind) |
| 373 | { |
| 374 | case 2: |
| 375 | u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 376 | u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 377 | break; |
| 378 | default: |
| 379 | printf("ERROR: Unsupported arguments for Pkg Read\n"); |
| 380 | goto ErrorExit; |
| 381 | break; |
| 382 | } |
| 383 | if (verbose) |
| 384 | { |
| 385 | printf("Pkg Read of Index %02x Param %04x\n", u8PkgIndex, |
| 386 | u16PkgParam); |
| 387 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 388 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 389 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 390 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 391 | clock_gettime(CLOCK_REALTIME, &begin); |
Patrick Williams | 7169faa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 392 | ret = peci_RdPkgConfig_dom(address, domainId, u8PkgIndex, |
| 393 | u16PkgParam, u8Size, |
| 394 | (uint8_t*)&u32PkgValue, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 395 | timeSpent = getTimeDifference(begin); |
| 396 | if (verbose && measureTime) |
| 397 | { |
| 398 | printf("\nTime taken in iteration %d = %lf s\n", |
| 399 | (loopCount - loops), timeSpent); |
| 400 | } |
| 401 | totalTimeSpent += timeSpent; |
| 402 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 403 | ccCounts[cc]++; |
| 404 | |
| 405 | if (verbose || loops == 0) |
| 406 | { |
| 407 | if (0 != ret) |
| 408 | { |
| 409 | printf("ERROR %d: command failed\n", ret); |
| 410 | printf(" cc:0x%02x\n", cc); |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 415 | u32PkgValue); |
| 416 | } |
| 417 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 418 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 419 | if (looped) |
| 420 | { |
| 421 | printLoopSummary(ccCounts); |
| 422 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 423 | } |
| 424 | else if (strcmp(cmd, "wrpkgconfig") == 0) |
| 425 | { |
| 426 | index = argc; |
| 427 | switch (argc - optind) |
| 428 | { |
| 429 | case 3: |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 430 | u32PkgValue = (uint32_t)strtoul(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 431 | u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 432 | u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 433 | break; |
| 434 | default: |
| 435 | printf("ERROR: Unsupported arguments for Pkg Write\n"); |
| 436 | goto ErrorExit; |
| 437 | break; |
| 438 | } |
| 439 | if (verbose) |
| 440 | { |
| 441 | printf("Pkg Write of Index %02x Param %04x: 0x%0*x\n", u8PkgIndex, |
| 442 | u16PkgParam, u8Size * 2, u32PkgValue); |
| 443 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 444 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 445 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 446 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 447 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 448 | ret = peci_WrPkgConfig_dom(address, domainId, u8PkgIndex, |
| 449 | u16PkgParam, u32PkgValue, u8Size, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 450 | timeSpent = getTimeDifference(begin); |
| 451 | if (verbose && measureTime) |
| 452 | { |
| 453 | printf("\nTime taken in iteration %d = %lf s\n", |
| 454 | (loopCount - loops), timeSpent); |
| 455 | } |
| 456 | totalTimeSpent += timeSpent; |
| 457 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 458 | ccCounts[cc]++; |
| 459 | |
| 460 | if (verbose || loops == 0) |
| 461 | { |
| 462 | if (0 != ret) |
| 463 | { |
| 464 | printf("ERROR %d: command failed\n", ret); |
| 465 | } |
| 466 | printf(" cc:0x%02x\n", cc); |
| 467 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 468 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 469 | if (looped) |
| 470 | { |
| 471 | printLoopSummary(ccCounts); |
| 472 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 473 | } |
| 474 | else if (strcmp(cmd, "rdiamsr") == 0) |
| 475 | { |
| 476 | index = argc; |
| 477 | switch (argc - optind) |
| 478 | { |
| 479 | case 2: |
| 480 | u16MsrAddr = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 481 | u8MsrThread = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 482 | break; |
| 483 | default: |
| 484 | printf("ERROR: Unsupported arguments for MSR Read\n"); |
| 485 | goto ErrorExit; |
| 486 | break; |
| 487 | } |
| 488 | if (verbose) |
| 489 | { |
| 490 | printf("MSR Read of Thread %02x MSR %04x\n", u8MsrThread, |
| 491 | u16MsrAddr); |
| 492 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 493 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 494 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 495 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 496 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 497 | ret = peci_RdIAMSR_dom(address, domainId, u8MsrThread, u16MsrAddr, |
| 498 | &u64MsrVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 499 | timeSpent = getTimeDifference(begin); |
| 500 | if (verbose && measureTime) |
| 501 | { |
| 502 | printf("\nTime taken in iteration %d = %lf s\n", |
| 503 | (loopCount - loops), timeSpent); |
| 504 | } |
| 505 | totalTimeSpent += timeSpent; |
| 506 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 507 | ccCounts[cc]++; |
| 508 | |
| 509 | if (verbose || loops == 0) |
| 510 | { |
| 511 | if (0 != ret) |
| 512 | { |
| 513 | printf("ERROR %d: command failed\n", ret); |
| 514 | printf(" cc:0x%02x\n", cc); |
| 515 | } |
| 516 | else |
| 517 | { |
| 518 | printf(" cc:0x%02x 0x%0*llx\n", cc, u8Size * 2, |
| 519 | (unsigned long long)u64MsrVal); |
| 520 | } |
| 521 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 522 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 523 | if (looped) |
| 524 | { |
| 525 | printLoopSummary(ccCounts); |
| 526 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 527 | } |
| 528 | else if (strcmp(cmd, "rdpciconfig") == 0) |
| 529 | { |
| 530 | index = argc; |
| 531 | switch (argc - optind) |
| 532 | { |
| 533 | case 4: |
| 534 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 535 | /* FALLTHROUGH */ |
| 536 | case 3: |
| 537 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 538 | /* FALLTHROUGH */ |
| 539 | case 2: |
| 540 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 541 | /* FALLTHROUGH */ |
| 542 | case 1: |
| 543 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 544 | break; |
| 545 | default: |
| 546 | printf("ERROR: Unsupported arguments for PCI Read\n"); |
| 547 | goto ErrorExit; |
| 548 | break; |
| 549 | } |
| 550 | if (verbose) |
| 551 | { |
| 552 | printf("PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus, u8PciDev, |
| 553 | u8PciFunc, u16PciReg); |
| 554 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 555 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 556 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 557 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 558 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 559 | ret = peci_RdPCIConfig_dom(address, domainId, u8PciBus, u8PciDev, |
| 560 | u8PciFunc, u16PciReg, |
| 561 | (uint8_t*)&u32PciReadVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 562 | timeSpent = getTimeDifference(begin); |
| 563 | if (verbose && measureTime) |
| 564 | { |
| 565 | printf("\nTime taken in iteration %d = %lf s\n", |
| 566 | (loopCount - loops), timeSpent); |
| 567 | } |
| 568 | totalTimeSpent += timeSpent; |
| 569 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 570 | ccCounts[cc]++; |
| 571 | |
| 572 | if (verbose || loops == 0) |
| 573 | { |
| 574 | if (0 != ret) |
| 575 | { |
| 576 | printf("ERROR %d: command failed\n", ret); |
| 577 | printf(" cc:0x%02x\n", cc); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 582 | u32PciReadVal); |
| 583 | } |
| 584 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 585 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 586 | if (looped) |
| 587 | { |
| 588 | printLoopSummary(ccCounts); |
| 589 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 590 | } |
| 591 | else if (strcmp(cmd, "rdpciconfiglocal") == 0) |
| 592 | { |
| 593 | index = argc; |
| 594 | switch (argc - optind) |
| 595 | { |
| 596 | case 4: |
| 597 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 598 | /* FALLTHROUGH */ |
| 599 | case 3: |
| 600 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 601 | /* FALLTHROUGH */ |
| 602 | case 2: |
| 603 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 604 | /* FALLTHROUGH */ |
| 605 | case 1: |
| 606 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 607 | break; |
| 608 | default: |
| 609 | printf("ERROR: Unsupported arguments for Local PCI Read\n"); |
| 610 | goto ErrorExit; |
| 611 | break; |
| 612 | } |
| 613 | if (verbose) |
| 614 | { |
| 615 | printf("Local PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus, |
| 616 | u8PciDev, u8PciFunc, u16PciReg); |
| 617 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 618 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 619 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 620 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 621 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 622 | ret = peci_RdPCIConfigLocal_dom( |
| 623 | address, domainId, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, |
| 624 | u8Size, (uint8_t*)&u32PciReadVal, &cc); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 625 | ccCounts[cc]++; |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 626 | timeSpent = getTimeDifference(begin); |
| 627 | if (verbose && measureTime) |
| 628 | { |
| 629 | printf("\nTime taken in iteration %d = %lf s\n", |
| 630 | (loopCount - loops), timeSpent); |
| 631 | } |
| 632 | totalTimeSpent += timeSpent; |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 633 | |
| 634 | if (verbose || loops == 0) |
| 635 | { |
| 636 | if (0 != ret) |
| 637 | { |
| 638 | printf("ERROR %d: command failed\n", ret); |
| 639 | printf(" cc:0x%02x\n", cc); |
| 640 | } |
| 641 | else |
| 642 | { |
| 643 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 644 | u32PciReadVal); |
| 645 | } |
| 646 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 647 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 648 | if (looped) |
| 649 | { |
| 650 | printLoopSummary(ccCounts); |
| 651 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 652 | } |
| 653 | else if (strcmp(cmd, "wrpciconfiglocal") == 0) |
| 654 | { |
| 655 | index = argc; |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 656 | u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 657 | switch (argc - optind) |
| 658 | { |
| 659 | case 5: |
| 660 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 661 | /* FALLTHROUGH */ |
| 662 | case 4: |
| 663 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 664 | /* FALLTHROUGH */ |
| 665 | case 3: |
| 666 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 667 | /* FALLTHROUGH */ |
| 668 | case 2: |
| 669 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 670 | break; |
| 671 | default: |
| 672 | printf("ERROR: Unsupported arguments for Local PCI Write\n"); |
| 673 | goto ErrorExit; |
| 674 | break; |
| 675 | } |
| 676 | if (verbose) |
| 677 | { |
| 678 | printf("Local PCI Write of %02x:%02x:%02x Reg %02x: 0x%0*x\n", |
| 679 | u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2, |
| 680 | u32PciWriteVal); |
| 681 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 682 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 683 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 684 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 685 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 686 | ret = peci_WrPCIConfigLocal_dom(address, domainId, u8PciBus, |
| 687 | u8PciDev, u8PciFunc, u16PciReg, |
| 688 | u8Size, u32PciWriteVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 689 | timeSpent = getTimeDifference(begin); |
| 690 | if (verbose && measureTime) |
| 691 | { |
| 692 | printf("\nTime taken in iteration %d = %lf s\n", |
| 693 | (loopCount - loops), timeSpent); |
| 694 | } |
| 695 | totalTimeSpent += timeSpent; |
| 696 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 697 | ccCounts[cc]++; |
| 698 | |
| 699 | if (verbose || loops == 0) |
| 700 | { |
| 701 | if (0 != ret) |
| 702 | { |
| 703 | printf("ERROR %d: command failed\n", ret); |
| 704 | } |
| 705 | printf(" cc:0x%02x\n", cc); |
| 706 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 707 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 708 | if (looped) |
| 709 | { |
| 710 | printLoopSummary(ccCounts); |
| 711 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 712 | } |
| 713 | else if (strcmp(cmd, "rdendpointconfigpcilocal") == 0) |
| 714 | { |
| 715 | index = argc; |
| 716 | switch (argc - optind) |
| 717 | { |
| 718 | case 5: |
| 719 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 720 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 721 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 722 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 723 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 724 | break; |
| 725 | |
| 726 | default: |
| 727 | printf("ERROR: Unsupported arguments for Endpoint Local PCI " |
| 728 | "Read\n"); |
| 729 | goto ErrorExit; |
| 730 | } |
| 731 | if (verbose) |
| 732 | { |
| 733 | printf( |
| 734 | "Endpoint Local PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n", |
| 735 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg); |
| 736 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 737 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 738 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 739 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 740 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 741 | ret = peci_RdEndPointConfigPciLocal_dom( |
| 742 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, |
| 743 | u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 744 | timeSpent = getTimeDifference(begin); |
| 745 | if (verbose && measureTime) |
| 746 | { |
| 747 | printf("\nTime taken in iteration %d = %lf s\n", |
| 748 | (loopCount - loops), timeSpent); |
| 749 | } |
| 750 | totalTimeSpent += timeSpent; |
| 751 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 752 | ccCounts[cc]++; |
| 753 | |
| 754 | if (verbose || loops == 0) |
| 755 | { |
| 756 | if (0 != ret) |
| 757 | { |
| 758 | printf("ERROR %d: command failed\n", ret); |
| 759 | printf(" cc:0x%02x\n", cc); |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 764 | u32PciReadVal); |
| 765 | } |
| 766 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 767 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 768 | if (looped) |
| 769 | { |
| 770 | printLoopSummary(ccCounts); |
| 771 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 772 | } |
| 773 | else if (strcmp(cmd, "wrendpointconfigpcilocal") == 0) |
| 774 | { |
| 775 | index = argc; |
| 776 | switch (argc - optind) |
| 777 | { |
| 778 | case 6: |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 779 | u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 780 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 781 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 782 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 783 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 784 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 785 | break; |
| 786 | |
| 787 | default: |
| 788 | printf("ERROR: Unsupported arguments for Endpoint Local PCI " |
| 789 | "Write\n"); |
| 790 | goto ErrorExit; |
| 791 | } |
| 792 | if (verbose) |
| 793 | { |
| 794 | printf("Endpoint Local PCI Write of Seg:%02x %02x:%02x:%02x Reg " |
| 795 | "%02x: 0x%0*x\n", |
| 796 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2, |
| 797 | u32PciWriteVal); |
| 798 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 799 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 800 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 801 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 802 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 803 | ret = peci_WrEndPointPCIConfigLocal_dom( |
| 804 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, |
| 805 | u16PciReg, u8Size, u32PciWriteVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 806 | timeSpent = getTimeDifference(begin); |
| 807 | if (verbose && measureTime) |
| 808 | { |
| 809 | printf("\nTime taken in iteration %d = %lf s\n", |
| 810 | (loopCount - loops), timeSpent); |
| 811 | } |
| 812 | totalTimeSpent += timeSpent; |
| 813 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 814 | ccCounts[cc]++; |
| 815 | |
| 816 | if (verbose || loops == 0) |
| 817 | { |
| 818 | if (0 != ret) |
| 819 | { |
| 820 | printf("ERROR %d: command failed\n", ret); |
| 821 | } |
| 822 | printf(" cc:0x%02x\n", cc); |
| 823 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 824 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 825 | if (looped) |
| 826 | { |
| 827 | printLoopSummary(ccCounts); |
| 828 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 829 | } |
| 830 | else if (strcmp(cmd, "rdendpointconfigpci") == 0) |
| 831 | { |
| 832 | index = argc; |
| 833 | switch (argc - optind) |
| 834 | { |
| 835 | case 5: |
| 836 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 837 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 838 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 839 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 840 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 841 | break; |
| 842 | |
| 843 | default: |
| 844 | printf("ERROR: Unsupported arguments for Endpoint PCI Read\n"); |
| 845 | goto ErrorExit; |
| 846 | } |
| 847 | if (verbose) |
| 848 | { |
| 849 | printf("Endpoint PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n", |
| 850 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg); |
| 851 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 852 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 853 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 854 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 855 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 856 | ret = peci_RdEndPointConfigPci_dom( |
| 857 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, |
| 858 | u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 859 | timeSpent = getTimeDifference(begin); |
| 860 | if (verbose && measureTime) |
| 861 | { |
| 862 | printf("\nTime taken in iteration %d = %lf s\n", |
| 863 | (loopCount - loops), timeSpent); |
| 864 | } |
| 865 | totalTimeSpent += timeSpent; |
| 866 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 867 | ccCounts[cc]++; |
| 868 | |
| 869 | if (verbose || loops == 0) |
| 870 | { |
| 871 | if (0 != ret) |
| 872 | { |
| 873 | printf("ERROR %d: command failed\n", ret); |
| 874 | printf(" cc:0x%02x\n", cc); |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 879 | u32PciReadVal); |
| 880 | } |
| 881 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 882 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 883 | if (looped) |
| 884 | { |
| 885 | printLoopSummary(ccCounts); |
| 886 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 887 | } |
| 888 | else if (strcmp(cmd, "wrendpointconfigpci") == 0) |
| 889 | { |
| 890 | index = argc; |
| 891 | switch (argc - optind) |
| 892 | { |
| 893 | case 6: |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 894 | u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 895 | u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0); |
| 896 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 897 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 898 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 899 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 900 | break; |
| 901 | |
| 902 | default: |
| 903 | printf("ERROR: Unsupported arguments for Endpoint PCI Write\n"); |
| 904 | goto ErrorExit; |
| 905 | } |
| 906 | if (verbose) |
| 907 | { |
| 908 | printf("Endpoint PCI Write of Seg:%02x %02x:%02x:%02x Reg %02x: " |
| 909 | "0x%0*x\n", |
| 910 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2, |
| 911 | u32PciWriteVal); |
| 912 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 913 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 914 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 915 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 916 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 917 | ret = peci_WrEndPointPCIConfig_dom( |
| 918 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, |
| 919 | u16PciReg, u8Size, u32PciWriteVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 920 | timeSpent = getTimeDifference(begin); |
| 921 | if (verbose && measureTime) |
| 922 | { |
| 923 | printf("\nTime taken in iteration %d = %lf s\n", |
| 924 | (loopCount - loops), timeSpent); |
| 925 | } |
| 926 | totalTimeSpent += timeSpent; |
| 927 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 928 | ccCounts[cc]++; |
| 929 | |
| 930 | if (verbose || loops == 0) |
| 931 | { |
| 932 | if (0 != ret) |
| 933 | { |
| 934 | printf("ERROR %d: command failed\n", ret); |
| 935 | } |
| 936 | printf(" cc:0x%02x\n", cc); |
| 937 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 938 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 939 | if (looped) |
| 940 | { |
| 941 | printLoopSummary(ccCounts); |
| 942 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 943 | } |
| 944 | else if (strcmp(cmd, "rdendpointconfigmmio") == 0) |
| 945 | { |
| 946 | index = argc; |
| 947 | switch (argc - optind) |
| 948 | { |
| 949 | case 7: |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 950 | u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 951 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 952 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 953 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 954 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 955 | u8Bar = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 956 | u8AddrType = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 957 | break; |
| 958 | |
| 959 | default: |
| 960 | printf("ERROR: Unsupported arguments for Endpoint MMIO Read\n"); |
| 961 | goto ErrorExit; |
| 962 | } |
| 963 | if (verbose) |
| 964 | { |
| 965 | printf("Endpoint MMIO Read of Seg:%02x %02x:%02x:%02x AType:%02x " |
| 966 | "Bar:%02x Offset:0x%" PRIx64 "\n", |
| 967 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar, |
| 968 | u64Offset); |
| 969 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 970 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 971 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 972 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 973 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 974 | ret = peci_RdEndPointConfigMmio_dom( |
| 975 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar, |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 976 | u8AddrType, u64Offset, u8Size, (uint8_t*)&u32PciReadVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 977 | timeSpent = getTimeDifference(begin); |
| 978 | if (verbose && measureTime) |
| 979 | { |
| 980 | printf("\nTime taken in iteration %d = %lf s\n", |
| 981 | (loopCount - loops), timeSpent); |
| 982 | } |
| 983 | totalTimeSpent += timeSpent; |
| 984 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 985 | ccCounts[cc]++; |
| 986 | |
| 987 | if (verbose || loops == 0) |
| 988 | { |
| 989 | if (0 != ret) |
| 990 | { |
| 991 | printf("ERROR %d: command failed\n", ret); |
| 992 | printf(" cc:0x%02x\n", cc); |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, |
| 997 | u32PciReadVal); |
| 998 | } |
| 999 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1000 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1001 | if (looped) |
| 1002 | { |
| 1003 | printLoopSummary(ccCounts); |
| 1004 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1005 | } |
| 1006 | else if (strcmp(cmd, "wrendpointconfigmmio") == 0) |
| 1007 | { |
| 1008 | index = argc; |
| 1009 | switch (argc - optind) |
| 1010 | { |
| 1011 | case 8: |
Jason M. Bills | 62cbc71 | 2020-05-07 14:07:49 -0700 | [diff] [blame] | 1012 | u64MmioWriteVal = (uint64_t)strtoull(argv[--index], NULL, 0); |
| 1013 | u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1014 | u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1015 | u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1016 | u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1017 | u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1018 | u8Bar = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1019 | u8AddrType = (uint8_t)strtoul(argv[--index], NULL, 0); |
| 1020 | break; |
| 1021 | |
| 1022 | default: |
| 1023 | printf( |
| 1024 | "ERROR: Unsupported arguments for Endpoint MMIO Write\n"); |
| 1025 | goto ErrorExit; |
| 1026 | } |
| 1027 | if (verbose) |
| 1028 | { |
| 1029 | printf("Endpoint MMIO Write of Seg:%02x %02x:%02x:%02x AType:%02x " |
| 1030 | "Bar:%02x Offset:0x%" PRIx64 ": 0x%0*" PRIx64 "\n", |
| 1031 | u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar, |
| 1032 | u64Offset, u8Size * 2, u64MmioWriteVal); |
| 1033 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1034 | while (loops--) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1035 | { |
Jason M. Bills | 5f1d7f7 | 2023-05-12 13:58:35 -0700 | [diff] [blame] | 1036 | cc = 0; // reset the cc for each loop |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 1037 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | 7b11280 | 2022-03-01 13:28:56 -0800 | [diff] [blame] | 1038 | ret = peci_WrEndPointConfigMmio_dom( |
| 1039 | address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar, |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1040 | u8AddrType, u64Offset, u8Size, u64MmioWriteVal, &cc); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 1041 | timeSpent = getTimeDifference(begin); |
| 1042 | if (verbose && measureTime) |
| 1043 | { |
| 1044 | printf("\nTime taken in iteration %d = %lf s\n", |
| 1045 | (loopCount - loops), timeSpent); |
| 1046 | } |
| 1047 | totalTimeSpent += timeSpent; |
| 1048 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1049 | ccCounts[cc]++; |
| 1050 | |
| 1051 | if (verbose || loops == 0) |
| 1052 | { |
| 1053 | if (0 != ret) |
| 1054 | { |
| 1055 | printf("ERROR %d: command failed\n", ret); |
| 1056 | } |
| 1057 | printf(" cc:0x%02x\n", cc); |
| 1058 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1059 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1060 | if (looped) |
| 1061 | { |
| 1062 | printLoopSummary(ccCounts); |
| 1063 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1064 | } |
| 1065 | else if (strcmp(cmd, "raw") == 0) |
| 1066 | { |
| 1067 | if ((argc - optind) < 3) |
| 1068 | { |
| 1069 | printf("ERROR: Unsupported arguments for raw command\n"); |
| 1070 | goto ErrorExit; |
| 1071 | } |
| 1072 | |
| 1073 | // Address is provided in the first byte of the PECI command |
| 1074 | uint8_t rawAddr = (uint8_t)strtoul(argv[optind++], NULL, 0); |
| 1075 | // Write length is provided in the second byte of the PECI command |
| 1076 | uint8_t writeLength = (uint8_t)strtoul(argv[optind++], NULL, 0); |
| 1077 | // Read length is provided in the third byte of the PECI command |
| 1078 | uint8_t readLength = (uint8_t)strtoul(argv[optind++], NULL, 0); |
| 1079 | |
Jason M. Bills | c965e72 | 2020-07-06 15:49:14 -0700 | [diff] [blame] | 1080 | // remaining parameters should fit within write length |
| 1081 | if ((argc - optind) > writeLength) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1082 | { |
| 1083 | printf("ERROR: Incorrect write length for raw command\n"); |
| 1084 | goto ErrorExit; |
| 1085 | } |
| 1086 | uint8_t* rawCmd = (uint8_t*)calloc(writeLength, sizeof(uint8_t)); |
| 1087 | if (rawCmd == NULL) |
| 1088 | { |
| 1089 | // calloc failed, abort the sequence |
| 1090 | printf("Raw command memory allocation failed\n"); |
| 1091 | return 1; |
| 1092 | } |
Jason M. Bills | c965e72 | 2020-07-06 15:49:14 -0700 | [diff] [blame] | 1093 | for (i = 0; i < (argc - optind); i++) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1094 | { |
| 1095 | rawCmd[i] = (uint8_t)strtoul(argv[i + optind], NULL, 0); |
| 1096 | } |
| 1097 | if (verbose) |
| 1098 | { |
| 1099 | printf("Raw command: %02x %02x %02x ", rawAddr, writeLength, |
| 1100 | readLength); |
| 1101 | for (i = 0; i < writeLength; i++) |
| 1102 | { |
| 1103 | printf("0x%02x ", rawCmd[i]); |
| 1104 | } |
| 1105 | printf("\n"); |
| 1106 | } |
| 1107 | |
| 1108 | uint8_t* rawResp = (uint8_t*)calloc(readLength, sizeof(uint8_t)); |
| 1109 | if (rawResp == NULL) |
| 1110 | { |
| 1111 | // calloc failed, abort the sequence |
| 1112 | printf("Raw command memory allocation failed\n"); |
| 1113 | free(rawCmd); |
| 1114 | return 1; |
| 1115 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1116 | while (loops--) |
Jason M. Bills | 0e21dde | 2020-07-06 14:51:53 -0700 | [diff] [blame] | 1117 | { |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 1118 | clock_gettime(CLOCK_REALTIME, &begin); |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1119 | ret = peci_raw(rawAddr, readLength, rawCmd, writeLength, rawResp, |
| 1120 | readLength); |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 1121 | timeSpent = getTimeDifference(begin); |
| 1122 | if (verbose && measureTime) |
| 1123 | { |
| 1124 | printf("\nTime taken in iteration %d = %lf s\n", |
| 1125 | (loopCount - loops), timeSpent); |
| 1126 | } |
| 1127 | totalTimeSpent += timeSpent; |
| 1128 | |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1129 | if (verbose) |
| 1130 | { |
| 1131 | printf(" "); |
| 1132 | for (i = 0; i < readLength; i++) |
| 1133 | { |
| 1134 | printf("0x%02x ", rawResp[i]); |
| 1135 | } |
| 1136 | printf("\n"); |
| 1137 | } |
| 1138 | ccCounts[rawResp[0]]++; |
| 1139 | } |
| 1140 | if (!verbose) |
| 1141 | { |
Patrick Williams | b65de2d | 2023-05-26 15:14:02 -0500 | [diff] [blame^] | 1142 | if (PECI_CC_SUCCESS != ret) |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1143 | { |
| 1144 | printf("ERROR %d: command failed\n", ret); |
| 1145 | } |
| 1146 | printf(" "); |
Jason M. Bills | 0e21dde | 2020-07-06 14:51:53 -0700 | [diff] [blame] | 1147 | for (i = 0; i < readLength; i++) |
| 1148 | { |
| 1149 | printf("0x%02x ", rawResp[i]); |
| 1150 | } |
| 1151 | printf("\n"); |
| 1152 | } |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1153 | |
| 1154 | if (looped) |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1155 | { |
Jason M. Bills | ff44e54 | 2021-04-05 08:11:52 -0700 | [diff] [blame] | 1156 | printLoopSummary(ccCounts); |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1157 | } |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1158 | |
| 1159 | free(rawCmd); |
| 1160 | free(rawResp); |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | printf("ERROR: Unrecognized command\n"); |
| 1165 | goto ErrorExit; |
| 1166 | } |
| 1167 | |
Sumanth Bhat | 1ae54d2 | 2023-03-01 23:03:03 +0530 | [diff] [blame] | 1168 | if (measureTime) |
| 1169 | { |
| 1170 | printf("Total time taken = %lf seconds\n", totalTimeSpent); |
| 1171 | if (loopCount > 1) |
| 1172 | { |
| 1173 | printf("Average time taken per command = %lf seconds\n", |
| 1174 | totalTimeSpent / loopCount); |
| 1175 | } |
| 1176 | } |
| 1177 | |
Jason M. Bills | 7ef5a55 | 2020-04-06 14:58:44 -0700 | [diff] [blame] | 1178 | return 0; |
| 1179 | |
| 1180 | ErrorExit: |
| 1181 | Usage(argv[0]); |
| 1182 | return 1; |
| 1183 | } |