blob: 1714e6cb66abfcc5e3bdd95bbd8a7f7848326413 [file] [log] [blame]
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001/*
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. Billsff44e542021-04-05 08:11:52 -070017#include <errno.h>
Jason M. Bills7ef5a552020-04-06 14:58:44 -070018#include <inttypes.h>
Jason M. Billsff44e542021-04-05 08:11:52 -070019#include <limits.h>
Jason M. Bills7ef5a552020-04-06 14:58:44 -070020#include <peci.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
Sumanth Bhat1ae54d22023-03-01 23:03:03 +053024#include <time.h>
Jason M. Bills7ef5a552020-04-06 14:58:44 -070025#include <unistd.h>
26#ifndef ABS
27#define ABS(_v_) (((_v_) > 0) ? (_v_) : -(_v_))
28#endif
29
Jason M. Billsff44e542021-04-05 08:11:52 -070030#define CC_COUNT 256 // CC is a byte so only has 256 possible values
31
Jason M. Bills7ef5a552020-04-06 14:58:44 -070032extern EPECIStatus peci_GetDIB(uint8_t target, uint64_t* dib);
33
Sumanth Bhat1ae54d22023-03-01 23:03:03 +053034double 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. Bills7ef5a552020-04-06 14:58:44 -070049void Usage(char* progname)
50{
51 printf("Usage:\n");
Sumanth Bhat1ae54d22023-03-01 23:03:03 +053052 printf("%s [-h] [-v] [-t] [-a <addr>] [-i <domain id>] [-s <size>] [-l "
53 "<count>] "
Jason M. Bills7b112802022-03-01 13:28:56 -080054 "<command> [parameters]\n",
Jason M. Billsff44e542021-04-05 08:11:52 -070055 progname);
Jason M. Bills7ef5a552020-04-06 14:58:44 -070056 printf("Options:\n");
Jason M. Billsff44e542021-04-05 08:11:52 -070057 printf("\t%-12s%s\n", "-h", "Display this help information");
58 printf("\t%-12s%s\n", "-v",
Jason M. Bills7ef5a552020-04-06 14:58:44 -070059 "Display additional information about the command");
Sumanth Bhat1ae54d22023-03-01 23:03:03 +053060 printf("\t%-12s%s\n", "-t", "Measure request-to-response time");
Jason M. Billsff44e542021-04-05 08:11:52 -070061 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. Bills7ef5a552020-04-06 14:58:44 -070066 "Address of the target. Accepted values are 48-55 (0x30-0x37). "
67 "Default is 48 (0x30)");
Jason M. Bills7b112802022-03-01 13:28:56 -080068 printf("\t%-12s%s\n", "-i <domain id>",
69 "Domain ID of the target. Accepted values are 0-127. Default is 0");
Jason M. Billsff44e542021-04-05 08:11:52 -070070 printf("\t%-12s%s\n", "-s <size>",
Jason M. Bills7ef5a552020-04-06 14:58:44 -070071 "Size of data to read or write in bytes. Accepted values are 1, 2, "
72 "4, 8, and 16. Default is 4");
Anna Platash03d7dae2021-02-05 13:52:05 +010073 printf("\t%-12s%s\n", "-d",
74 "Set PECI device name, for example \"-d /dev/peci-0\"");
Jason M. Bills7ef5a552020-04-06 14:58:44 -070075 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. Billsff44e542021-04-05 08:11:52 -0700105static 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. Bills7ef5a552020-04-06 14:58:44 -0700117int main(int argc, char* argv[])
118{
119 int c;
120 int i = 0;
121 char* cmd = NULL;
Patrick Williamsb65de2d2023-05-26 15:14:02 -0500122 EPECIStatus ret = PECI_CC_SUCCESS;
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700123 uint8_t address = 0x30; // use default address of 48d
Jason M. Bills7b112802022-03-01 13:28:56 -0800124 uint8_t domainId = 0; // use default domain ID of 0
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700125 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 Bhat1ae54d22023-03-01 23:03:03 +0530147 bool measureTime = false;
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700148 bool verbose = false;
Jason M. Billsff44e542021-04-05 08:11:52 -0700149 bool looped = false;
150 uint32_t loops = 1;
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530151 uint32_t loopCount = 1;
Nirav Shahfd5dfd52022-03-09 12:29:41 -0800152 uint32_t ccCounts[CC_COUNT] = {0};
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530153 struct timespec begin;
154 double timeSpent = 0.0;
155 double totalTimeSpent = 0.0;
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700156
157 //
158 // Parse arguments.
159 //
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530160 while (-1 != (c = getopt(argc, argv, "hvtl:a:i:s:d:")))
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700161 {
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 Bhat1ae54d22023-03-01 23:03:03 +0530173 case 't':
174 measureTime = true;
175 break;
176
Jason M. Billsff44e542021-04-05 08:11:52 -0700177 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 Bhat1ae54d22023-03-01 23:03:03 +0530189 loopCount =
190 loops; // Preserve a copy for average time measurement
Jason M. Billsff44e542021-04-05 08:11:52 -0700191 break;
192
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700193 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. Bills7b112802022-03-01 13:28:56 -0800204 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. Bills7ef5a552020-04-06 14:58:44 -0700214 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 Platash03d7dae2021-02-05 13:52:05 +0100225 case 'd':
226 peci_SetDevName(optarg);
227 break;
228
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700229 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 Bhat1ae54d22023-03-01 23:03:03 +0530258
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. Bills7ef5a552020-04-06 14:58:44 -0700269 if (strcmp(cmd, "ping") == 0)
270 {
271 if (verbose)
272 {
273 printf("Pinging ... ");
274 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700275 while (loops--)
276 {
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530277 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Billsff44e542021-04-05 08:11:52 -0700278 ret = peci_Ping(address);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530279 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. Billsff44e542021-04-05 08:11:52 -0700287 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. Bills7ef5a552020-04-06 14:58:44 -0700299 }
300 else if (strcmp(cmd, "getdib") == 0)
301 {
302 if (verbose)
303 {
304 printf("GetDIB\n");
305 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700306 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700307 {
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530308 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Billsff44e542021-04-05 08:11:52 -0700309 ret = peci_GetDIB(address, &dib);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530310 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. Billsff44e542021-04-05 08:11:52 -0700318 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. Bills7ef5a552020-04-06 14:58:44 -0700329 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700330 }
331
332 else if (strcmp(cmd, "gettemp") == 0)
333 {
334 if (verbose)
335 {
336 printf("GetTemp\n");
337 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700338 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700339 {
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530340 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Billsff44e542021-04-05 08:11:52 -0700341 ret = peci_GetTemp(address, &temperature);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530342 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. Billsff44e542021-04-05 08:11:52 -0700350 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. Bills7ef5a552020-04-06 14:58:44 -0700366 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700367 }
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. Billsff44e542021-04-05 08:11:52 -0700388 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700389 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700390 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530391 clock_gettime(CLOCK_REALTIME, &begin);
Patrick Williams7169faa2023-05-10 07:51:24 -0500392 ret = peci_RdPkgConfig_dom(address, domainId, u8PkgIndex,
393 u16PkgParam, u8Size,
394 (uint8_t*)&u32PkgValue, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530395 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. Billsff44e542021-04-05 08:11:52 -0700403 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. Bills7ef5a552020-04-06 14:58:44 -0700418 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700419 if (looped)
420 {
421 printLoopSummary(ccCounts);
422 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700423 }
424 else if (strcmp(cmd, "wrpkgconfig") == 0)
425 {
426 index = argc;
427 switch (argc - optind)
428 {
429 case 3:
Jason M. Bills62cbc712020-05-07 14:07:49 -0700430 u32PkgValue = (uint32_t)strtoul(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700431 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. Billsff44e542021-04-05 08:11:52 -0700444 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700445 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700446 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530447 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800448 ret = peci_WrPkgConfig_dom(address, domainId, u8PkgIndex,
449 u16PkgParam, u32PkgValue, u8Size, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530450 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. Billsff44e542021-04-05 08:11:52 -0700458 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. Bills7ef5a552020-04-06 14:58:44 -0700468 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700469 if (looped)
470 {
471 printLoopSummary(ccCounts);
472 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700473 }
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. Billsff44e542021-04-05 08:11:52 -0700493 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700494 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700495 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530496 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800497 ret = peci_RdIAMSR_dom(address, domainId, u8MsrThread, u16MsrAddr,
498 &u64MsrVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530499 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. Billsff44e542021-04-05 08:11:52 -0700507 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. Bills7ef5a552020-04-06 14:58:44 -0700522 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700523 if (looped)
524 {
525 printLoopSummary(ccCounts);
526 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700527 }
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. Billsff44e542021-04-05 08:11:52 -0700555 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700556 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700557 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530558 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800559 ret = peci_RdPCIConfig_dom(address, domainId, u8PciBus, u8PciDev,
560 u8PciFunc, u16PciReg,
561 (uint8_t*)&u32PciReadVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530562 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. Billsff44e542021-04-05 08:11:52 -0700570 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. Bills7ef5a552020-04-06 14:58:44 -0700585 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700586 if (looped)
587 {
588 printLoopSummary(ccCounts);
589 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700590 }
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. Billsff44e542021-04-05 08:11:52 -0700618 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700619 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700620 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530621 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800622 ret = peci_RdPCIConfigLocal_dom(
623 address, domainId, u8PciBus, u8PciDev, u8PciFunc, u16PciReg,
624 u8Size, (uint8_t*)&u32PciReadVal, &cc);
Jason M. Billsff44e542021-04-05 08:11:52 -0700625 ccCounts[cc]++;
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530626 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. Billsff44e542021-04-05 08:11:52 -0700633
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. Bills7ef5a552020-04-06 14:58:44 -0700647 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700648 if (looped)
649 {
650 printLoopSummary(ccCounts);
651 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700652 }
653 else if (strcmp(cmd, "wrpciconfiglocal") == 0)
654 {
655 index = argc;
Jason M. Bills62cbc712020-05-07 14:07:49 -0700656 u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700657 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. Billsff44e542021-04-05 08:11:52 -0700682 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700683 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700684 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530685 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800686 ret = peci_WrPCIConfigLocal_dom(address, domainId, u8PciBus,
687 u8PciDev, u8PciFunc, u16PciReg,
688 u8Size, u32PciWriteVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530689 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. Billsff44e542021-04-05 08:11:52 -0700697 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. Bills7ef5a552020-04-06 14:58:44 -0700707 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700708 if (looped)
709 {
710 printLoopSummary(ccCounts);
711 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700712 }
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. Billsff44e542021-04-05 08:11:52 -0700737 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700738 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700739 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530740 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800741 ret = peci_RdEndPointConfigPciLocal_dom(
742 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
743 u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530744 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. Billsff44e542021-04-05 08:11:52 -0700752 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. Bills7ef5a552020-04-06 14:58:44 -0700767 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700768 if (looped)
769 {
770 printLoopSummary(ccCounts);
771 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700772 }
773 else if (strcmp(cmd, "wrendpointconfigpcilocal") == 0)
774 {
775 index = argc;
776 switch (argc - optind)
777 {
778 case 6:
Jason M. Bills62cbc712020-05-07 14:07:49 -0700779 u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700780 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. Billsff44e542021-04-05 08:11:52 -0700799 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700800 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700801 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530802 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800803 ret = peci_WrEndPointPCIConfigLocal_dom(
804 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
805 u16PciReg, u8Size, u32PciWriteVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530806 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. Billsff44e542021-04-05 08:11:52 -0700814 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. Bills7ef5a552020-04-06 14:58:44 -0700824 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700825 if (looped)
826 {
827 printLoopSummary(ccCounts);
828 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700829 }
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. Billsff44e542021-04-05 08:11:52 -0700852 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700853 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700854 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530855 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800856 ret = peci_RdEndPointConfigPci_dom(
857 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
858 u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530859 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. Billsff44e542021-04-05 08:11:52 -0700867 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. Bills7ef5a552020-04-06 14:58:44 -0700882 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700883 if (looped)
884 {
885 printLoopSummary(ccCounts);
886 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700887 }
888 else if (strcmp(cmd, "wrendpointconfigpci") == 0)
889 {
890 index = argc;
891 switch (argc - optind)
892 {
893 case 6:
Jason M. Bills62cbc712020-05-07 14:07:49 -0700894 u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700895 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. Billsff44e542021-04-05 08:11:52 -0700913 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700914 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700915 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530916 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800917 ret = peci_WrEndPointPCIConfig_dom(
918 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
919 u16PciReg, u8Size, u32PciWriteVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530920 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. Billsff44e542021-04-05 08:11:52 -0700928 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. Bills7ef5a552020-04-06 14:58:44 -0700938 }
Jason M. Billsff44e542021-04-05 08:11:52 -0700939 if (looped)
940 {
941 printLoopSummary(ccCounts);
942 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700943 }
944 else if (strcmp(cmd, "rdendpointconfigmmio") == 0)
945 {
946 index = argc;
947 switch (argc - optind)
948 {
949 case 7:
Jason M. Bills62cbc712020-05-07 14:07:49 -0700950 u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700951 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. Billsff44e542021-04-05 08:11:52 -0700970 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -0700971 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -0700972 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530973 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -0800974 ret = peci_RdEndPointConfigMmio_dom(
975 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar,
Jason M. Billsff44e542021-04-05 08:11:52 -0700976 u8AddrType, u64Offset, u8Size, (uint8_t*)&u32PciReadVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +0530977 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. Billsff44e542021-04-05 08:11:52 -0700985 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. Bills7ef5a552020-04-06 14:58:44 -07001000 }
Jason M. Billsff44e542021-04-05 08:11:52 -07001001 if (looped)
1002 {
1003 printLoopSummary(ccCounts);
1004 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001005 }
1006 else if (strcmp(cmd, "wrendpointconfigmmio") == 0)
1007 {
1008 index = argc;
1009 switch (argc - optind)
1010 {
1011 case 8:
Jason M. Bills62cbc712020-05-07 14:07:49 -07001012 u64MmioWriteVal = (uint64_t)strtoull(argv[--index], NULL, 0);
1013 u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0);
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001014 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. Billsff44e542021-04-05 08:11:52 -07001034 while (loops--)
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001035 {
Jason M. Bills5f1d7f72023-05-12 13:58:35 -07001036 cc = 0; // reset the cc for each loop
Sumanth Bhat1ae54d22023-03-01 23:03:03 +05301037 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Bills7b112802022-03-01 13:28:56 -08001038 ret = peci_WrEndPointConfigMmio_dom(
1039 address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar,
Jason M. Billsff44e542021-04-05 08:11:52 -07001040 u8AddrType, u64Offset, u8Size, u64MmioWriteVal, &cc);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +05301041 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. Billsff44e542021-04-05 08:11:52 -07001049 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. Bills7ef5a552020-04-06 14:58:44 -07001059 }
Jason M. Billsff44e542021-04-05 08:11:52 -07001060 if (looped)
1061 {
1062 printLoopSummary(ccCounts);
1063 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001064 }
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. Billsc965e722020-07-06 15:49:14 -07001080 // remaining parameters should fit within write length
1081 if ((argc - optind) > writeLength)
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001082 {
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. Billsc965e722020-07-06 15:49:14 -07001093 for (i = 0; i < (argc - optind); i++)
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001094 {
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. Billsff44e542021-04-05 08:11:52 -07001116 while (loops--)
Jason M. Bills0e21dde2020-07-06 14:51:53 -07001117 {
Sumanth Bhat1ae54d22023-03-01 23:03:03 +05301118 clock_gettime(CLOCK_REALTIME, &begin);
Jason M. Billsff44e542021-04-05 08:11:52 -07001119 ret = peci_raw(rawAddr, readLength, rawCmd, writeLength, rawResp,
1120 readLength);
Sumanth Bhat1ae54d22023-03-01 23:03:03 +05301121 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. Billsff44e542021-04-05 08:11:52 -07001129 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 Williamsb65de2d2023-05-26 15:14:02 -05001142 if (PECI_CC_SUCCESS != ret)
Jason M. Billsff44e542021-04-05 08:11:52 -07001143 {
1144 printf("ERROR %d: command failed\n", ret);
1145 }
1146 printf(" ");
Jason M. Bills0e21dde2020-07-06 14:51:53 -07001147 for (i = 0; i < readLength; i++)
1148 {
1149 printf("0x%02x ", rawResp[i]);
1150 }
1151 printf("\n");
1152 }
Jason M. Billsff44e542021-04-05 08:11:52 -07001153
1154 if (looped)
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001155 {
Jason M. Billsff44e542021-04-05 08:11:52 -07001156 printLoopSummary(ccCounts);
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001157 }
Jason M. Bills7ef5a552020-04-06 14:58:44 -07001158
1159 free(rawCmd);
1160 free(rawResp);
1161 }
1162 else
1163 {
1164 printf("ERROR: Unrecognized command\n");
1165 goto ErrorExit;
1166 }
1167
Sumanth Bhat1ae54d22023-03-01 23:03:03 +05301168 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. Bills7ef5a552020-04-06 14:58:44 -07001178 return 0;
1179
1180ErrorExit:
1181 Usage(argv[0]);
1182 return 1;
1183}