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