/*
// Copyright (c) 2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <peci.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#ifndef ABS
#define ABS(_v_) (((_v_) > 0) ? (_v_) : -(_v_))
#endif

#define CC_COUNT 256 // CC is a byte so only has 256 possible values

extern EPECIStatus peci_GetDIB(uint8_t target, uint64_t* dib);

double getTimeDifference(const struct timespec begin)
{
    double timeDiff = 0.0;
    struct timespec end;
    time_t seconds = 0;
    time_t nanoseconds = 0;

    clock_gettime(CLOCK_REALTIME, &end);
    seconds = end.tv_sec - begin.tv_sec;
    nanoseconds = end.tv_nsec - begin.tv_nsec;
    timeDiff = (double)seconds + (double)nanoseconds * 1e-9;

    return timeDiff;
}

void Usage(char* progname)
{
    printf("Usage:\n");
    printf("%s [-h] [-v] [-t] [-a <addr>] [-i <domain id>] [-s <size>] [-l "
           "<count>] "
           "<command> [parameters]\n",
           progname);
    printf("Options:\n");
    printf("\t%-12s%s\n", "-h", "Display this help information");
    printf("\t%-12s%s\n", "-v",
           "Display additional information about the command");
    printf("\t%-12s%s\n", "-t", "Measure request-to-response time");
    printf("\t%-12s%s %lu\n", "-l <count>",
           "Loop the command the given number of times. <count> is in the "
           "range 1 to",
           ULONG_MAX);
    printf("\t%-12s%s\n", "-a <addr>",
           "Address of the target. Accepted values are 48-55 (0x30-0x37). "
           "Default is 48 (0x30)");
    printf("\t%-12s%s\n", "-i <domain id>",
           "Domain ID of the target. Accepted values are 0-127. Default is 0");
    printf("\t%-12s%s\n", "-s <size>",
           "Size of data to read or write in bytes. Accepted values are 1, 2, "
           "4, 8, and 16. Default is 4");
    printf("\t%-12s%s\n", "-d",
           "Set PECI device name, for example \"-d /dev/peci-0\"");
    printf("Commands:\n");
    printf("\t%-28s%s\n", "Ping", "Ping the target");
    printf("\t%-28s%s\n", "GetTemp", "Get the temperature");
    printf("\t%-28s%s\n", "GetDIB", "Get the DIB");
    printf("\t%-28s%s\n", "RdPkgConfig",
           "Read Package Config <Index Parameter>");
    printf("\t%-28s%s\n", "WrPkgConfig",
           "Write Package Config <Index Parameter Data>");
    printf("\t%-28s%s\n", "RdIAMSR", "MSR Read <Thread Address>");
    printf("\t%-28s%s\n", "RdPCIConfig", "PCI Read <Bus Dev Func [Reg]>");
    printf("\t%-28s%s\n", "RdPCIConfigLocal",
           "Local PCI Read <Bus Dev Func [Reg]>");
    printf("\t%-28s%s\n", "WrPCIConfigLocal",
           "Local PCI Write <Bus Dev Func Reg Data>");
    printf("\t%-28s%s\n", "RdEndpointConfigPCILocal",
           "Endpoint Local PCI Config Read <Seg Bus Dev Func Reg>");
    printf("\t%-28s%s\n", "WrEndpointConfigPCILocal",
           "Endpoint Local PCI Config Write <Seg Bus Dev Func Reg Data>");
    printf("\t%-28s%s\n", "RdEndpointConfigPCI",
           "Endpoint PCI Config Read <Seg Bus Dev Func Reg>");
    printf("\t%-28s%s\n", "WrEndpointConfigPCI",
           "Endpoint PCI Config Write <Seg Bus Dev Func Reg Data>");
    printf("\t%-28s%s\n", "RdEndpointConfigMMIO",
           "Endpoint MMIO Read <AType Bar Seg Bus Dev Func Reg>");
    printf("\t%-28s%s\n", "WrEndpointConfigMMIO",
           "Endpoint MMIO Write <AType Bar Seg Bus Dev Func Reg Data>");
    printf("\t%-28s%s\n", "raw", "Raw PECI command in bytes");
    printf("\n");
}

static void printLoopSummary(uint32_t* ccCounts)
{
    printf("Completion code counts:\n");
    for (uint32_t i = 0; i < CC_COUNT; i++)
    {
        if (ccCounts[i])
        {
            printf("   0x%02x: %d\n", i, ccCounts[i]);
        }
    }
}

int main(int argc, char* argv[])
{
    int c;
    int i = 0;
    char* cmd = NULL;
    EPECIStatus ret = PECI_CC_SUCCESS;
    uint8_t address = 0x30; // use default address of 48d
    uint8_t domainId = 0;   // use default domain ID of 0
    uint8_t u8Size = 4;     // default to a DWORD
    uint32_t u32PciReadVal = 0;
    uint64_t u64MmioReadVal = 0;
    uint8_t u8Seg = 0;
    uint8_t u8Bar = 0;
    uint8_t u8AddrType = 0;
    uint8_t u8PciBus = 0;
    uint8_t u8PciDev = 0;
    uint8_t u8PciFunc = 0;
    uint16_t u16PciReg = 0;
    uint64_t u64Offset = 0;
    uint32_t u32PciWriteVal = 0;
    uint64_t u64MmioWriteVal = 0;
    uint8_t u8PkgIndex = 0;
    uint16_t u16PkgParam = 0;
    uint32_t u32PkgValue = 0;
    uint8_t u8MsrThread = 0;
    uint16_t u16MsrAddr = 0;
    uint64_t u64MsrVal = 0;
    short temperature;
    uint64_t dib;
    int index = 0;
    uint8_t cc = 0;
    bool measureTime = false;
    bool verbose = false;
    bool looped = false;
    uint32_t loops = 1;
    uint32_t loopCount = 1;
    uint32_t ccCounts[CC_COUNT] = {0};
    struct timespec begin;
    double timeSpent = 0.0;
    double totalTimeSpent = 0.0;

    //
    // Parse arguments.
    //
    while (-1 != (c = getopt(argc, argv, "hvtl:a:i:s:d:")))
    {
        switch (c)
        {
            case 'h':
                Usage(argv[0]);
                return 0;
                break;

            case 'v':
                verbose = true;
                break;

            case 't':
                measureTime = true;
                break;

            case 'l':
                looped = true;
                errno = 0;
                if (optarg != NULL)
                    loops = (uint32_t)strtoul(optarg, NULL, 0);
                if (!loops || errno)
                {
                    printf("ERROR: Invalid loop count\n");
                    if (errno)
                        perror("");
                    goto ErrorExit;
                }
                loopCount =
                    loops; // Preserve a copy for average time measurement
                break;

            case 'a':
                if (optarg != NULL)
                    address = (uint8_t)strtoul(optarg, NULL, 0);
                if (address < MIN_CLIENT_ADDR || address > MAX_CLIENT_ADDR)
                {
                    printf("ERROR: Invalid address \"0x%x\"\n", address);
                    goto ErrorExit;
                }

                break;

            case 'i':
                if (optarg != NULL)
                    domainId = (uint8_t)strtoul(optarg, NULL, 0);
                if (domainId >= 128) // Domain ID is only 7 bits
                {
                    printf("ERROR: Invalid domain ID \"%d\"\n", domainId);
                    goto ErrorExit;
                }
                break;

            case 's':
                if (optarg != NULL)
                    u8Size = (uint8_t)strtoul(optarg, NULL, 0);
                if (u8Size != 1 && u8Size != 2 && u8Size != 4 && u8Size != 8 &&
                    u8Size != 16)
                {
                    printf("ERROR: Invalid size \"%d\"\n", u8Size);
                    goto ErrorExit;
                }
                break;

            case 'd':
                peci_SetDevName(optarg);
                break;

            default:
                printf("ERROR: Unrecognized option \"-%c\"\n", optopt);
                goto ErrorExit;
                break;
        }
    }

    // Get the command from the first parameter
    cmd = argv[optind++];
    if (cmd == NULL)
    {
        Usage(argv[0]);
        return 0;
    }

    // Allow any case
    while (cmd[i])
    {
        cmd[i] = (char)tolower((int)cmd[i]);
        i++;
    }

    //
    // Execute the command
    //
    if (verbose)
    {
        printf("PECI target[0x%x]: ", address);
    }

    if (measureTime)
    {
        if (verbose && (loopCount > 1))
        {
            printf("Warning: Request-response time measurement with verbose "
                   "mode can affect the time between consecutive commands in "
                   "looped mode!\n");
        }
    }

    if (strcmp(cmd, "ping") == 0)
    {
        if (verbose)
        {
            printf("Pinging ... ");
        }
        while (loops--)
        {
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_Ping(address);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("Failed\n");
                }
                else
                {
                    printf("Succeeded\n");
                }
            }
        }
    }
    else if (strcmp(cmd, "getdib") == 0)
    {
        if (verbose)
        {
            printf("GetDIB\n");
        }
        while (loops--)
        {
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_GetDIB(address, &dib);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: Retrieving DIB failed\n", ret);
                }
                else
                {
                    printf("   0x%" PRIx64 "\n", dib);
                }
            }
        }
    }

    else if (strcmp(cmd, "gettemp") == 0)
    {
        if (verbose)
        {
            printf("GetTemp\n");
        }
        while (loops--)
        {
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_GetTemp(address, &temperature);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: Retrieving temperature failed\n", ret);
                }
                else
                {
                    printf("   %04xh (%c%d.%02dC)\n",
                           (int)(unsigned int)(unsigned short)temperature,
                           (0 > temperature) ? '-' : '+',
                           (int)((unsigned int)ABS(temperature) / 64),
                           (int)(((unsigned int)ABS(temperature) % 64) * 100) /
                               64);
                }
            }
        }
    }

    else if (strcmp(cmd, "rdpkgconfig") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 2:
                u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for Pkg Read\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("Pkg Read of Index %02x Param %04x\n", u8PkgIndex,
                   u16PkgParam);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdPkgConfig_dom(address, domainId, u8PkgIndex,
                                       u16PkgParam, u8Size,
                                       (uint8_t*)&u32PkgValue, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*x\n", cc, u8Size * 2,
                           u32PkgValue);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "wrpkgconfig") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 3:
                u32PkgValue = (uint32_t)strtoul(argv[--index], NULL, 0);
                u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for Pkg Write\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("Pkg Write of Index %02x Param %04x: 0x%0*x\n", u8PkgIndex,
                   u16PkgParam, u8Size * 2, u32PkgValue);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_WrPkgConfig_dom(address, domainId, u8PkgIndex,
                                       u16PkgParam, u32PkgValue, u8Size, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                }
                printf("   cc:0x%02x\n", cc);
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdiamsr") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 2:
                u16MsrAddr = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8MsrThread = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for MSR Read\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("MSR Read of Thread %02x MSR %04x\n", u8MsrThread,
                   u16MsrAddr);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdIAMSR_dom(address, domainId, u8MsrThread, u16MsrAddr,
                                   &u64MsrVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*llx\n", cc, u8Size * 2,
                           (unsigned long long)u64MsrVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdpciconfig") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 4:
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 3:
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 2:
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 1:
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for PCI Read\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus, u8PciDev,
                   u8PciFunc, u16PciReg);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdPCIConfig_dom(address, domainId, u8PciBus, u8PciDev,
                                       u8PciFunc, u16PciReg,
                                       (uint8_t*)&u32PciReadVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*x\n", cc, u8Size * 2,
                           u32PciReadVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdpciconfiglocal") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 4:
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 3:
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 2:
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 1:
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for Local PCI Read\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("Local PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus,
                   u8PciDev, u8PciFunc, u16PciReg);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdPCIConfigLocal_dom(
                address, domainId, u8PciBus, u8PciDev, u8PciFunc, u16PciReg,
                u8Size, (uint8_t*)&u32PciReadVal, &cc);
            ccCounts[cc]++;
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*x\n", cc, u8Size * 2,
                           u32PciReadVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "wrpciconfiglocal") == 0)
    {
        index = argc;
        u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
        switch (argc - optind)
        {
            case 5:
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 4:
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 3:
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                /* FALLTHROUGH */
            case 2:
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;
            default:
                printf("ERROR: Unsupported arguments for Local PCI Write\n");
                goto ErrorExit;
                break;
        }
        if (verbose)
        {
            printf("Local PCI Write of %02x:%02x:%02x Reg %02x: 0x%0*x\n",
                   u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
                   u32PciWriteVal);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_WrPCIConfigLocal_dom(address, domainId, u8PciBus,
                                            u8PciDev, u8PciFunc, u16PciReg,
                                            u8Size, u32PciWriteVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                }
                printf("   cc:0x%02x\n", cc);
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdendpointconfigpcilocal") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 5:
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf("ERROR: Unsupported arguments for Endpoint Local PCI "
                       "Read\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf(
                "Endpoint Local PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n",
                u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdEndPointConfigPciLocal_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
                u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*x\n", cc, u8Size * 2,
                           u32PciReadVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "wrendpointconfigpcilocal") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 6:
                u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf("ERROR: Unsupported arguments for Endpoint Local PCI "
                       "Write\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf("Endpoint Local PCI Write of Seg:%02x %02x:%02x:%02x Reg "
                   "%02x: 0x%0*x\n",
                   u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
                   u32PciWriteVal);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_WrEndPointPCIConfigLocal_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
                u16PciReg, u8Size, u32PciWriteVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                }
                printf("   cc:0x%02x\n", cc);
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdendpointconfigpci") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 5:
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf("ERROR: Unsupported arguments for Endpoint PCI Read\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf("Endpoint PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n",
                   u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdEndPointConfigPci_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
                u16PciReg, u8Size, (uint8_t*)&u32PciReadVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*x\n", cc, u8Size * 2,
                           u32PciReadVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "wrendpointconfigpci") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 6:
                u32PciWriteVal = (uint32_t)strtoul(argv[--index], NULL, 0);
                u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf("ERROR: Unsupported arguments for Endpoint PCI Write\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf("Endpoint PCI Write of Seg:%02x %02x:%02x:%02x Reg %02x: "
                   "0x%0*x\n",
                   u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
                   u32PciWriteVal);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_WrEndPointPCIConfig_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc,
                u16PciReg, u8Size, u32PciWriteVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                }
                printf("   cc:0x%02x\n", cc);
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "rdendpointconfigmmio") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 7:
                u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Bar = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8AddrType = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf("ERROR: Unsupported arguments for Endpoint MMIO Read\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf("Endpoint MMIO Read of Seg:%02x %02x:%02x:%02x AType:%02x "
                   "Bar:%02x Offset:0x%" PRIx64 "\n",
                   u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar,
                   u64Offset);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_RdEndPointConfigMmio_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar,
                u8AddrType, u64Offset, u8Size, (uint8_t*)&u64MmioReadVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                    printf("   cc:0x%02x\n", cc);
                }
                else
                {
                    printf("   cc:0x%02x 0x%0*" PRIx64 "\n", cc, u8Size * 2,
                           u64MmioReadVal);
                }
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "wrendpointconfigmmio") == 0)
    {
        index = argc;
        switch (argc - optind)
        {
            case 8:
                u64MmioWriteVal = (uint64_t)strtoull(argv[--index], NULL, 0);
                u64Offset = (uint64_t)strtoull(argv[--index], NULL, 0);
                u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Seg = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8Bar = (uint8_t)strtoul(argv[--index], NULL, 0);
                u8AddrType = (uint8_t)strtoul(argv[--index], NULL, 0);
                break;

            default:
                printf(
                    "ERROR: Unsupported arguments for Endpoint MMIO Write\n");
                goto ErrorExit;
        }
        if (verbose)
        {
            printf("Endpoint MMIO Write of Seg:%02x %02x:%02x:%02x AType:%02x "
                   "Bar:%02x Offset:0x%" PRIx64 ": 0x%0*" PRIx64 "\n",
                   u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar,
                   u64Offset, u8Size * 2, u64MmioWriteVal);
        }
        while (loops--)
        {
            cc = 0; // reset the cc for each loop
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_WrEndPointConfigMmio_dom(
                address, domainId, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar,
                u8AddrType, u64Offset, u8Size, u64MmioWriteVal, &cc);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            ccCounts[cc]++;

            if (verbose || loops == 0)
            {
                if (0 != ret)
                {
                    printf("ERROR %d: command failed\n", ret);
                }
                printf("   cc:0x%02x\n", cc);
            }
        }
        if (looped)
        {
            printLoopSummary(ccCounts);
        }
    }
    else if (strcmp(cmd, "raw") == 0)
    {
        if ((argc - optind) < 3)
        {
            printf("ERROR: Unsupported arguments for raw command\n");
            goto ErrorExit;
        }

        // Address is provided in the first byte of the PECI command
        uint8_t rawAddr = (uint8_t)strtoul(argv[optind++], NULL, 0);
        // Write length is provided in the second byte of the PECI command
        uint8_t writeLength = (uint8_t)strtoul(argv[optind++], NULL, 0);
        // Read length is provided in the third byte of the PECI command
        uint8_t readLength = (uint8_t)strtoul(argv[optind++], NULL, 0);

        // remaining parameters should fit within write length
        if ((argc - optind) > writeLength)
        {
            printf("ERROR: Incorrect write length for raw command\n");
            goto ErrorExit;
        }
        uint8_t* rawCmd = (uint8_t*)calloc(writeLength, sizeof(uint8_t));
        if (rawCmd == NULL)
        {
            // calloc failed, abort the sequence
            printf("Raw command memory allocation failed\n");
            return 1;
        }
        for (i = 0; i < (argc - optind); i++)
        {
            rawCmd[i] = (uint8_t)strtoul(argv[i + optind], NULL, 0);
        }
        if (verbose)
        {
            printf("Raw command: %02x %02x %02x ", rawAddr, writeLength,
                   readLength);
            for (i = 0; i < writeLength; i++)
            {
                printf("0x%02x ", rawCmd[i]);
            }
            printf("\n");
        }

        uint8_t* rawResp = (uint8_t*)calloc(readLength, sizeof(uint8_t));
        if (rawResp == NULL)
        {
            // calloc failed, abort the sequence
            printf("Raw command memory allocation failed\n");
            free(rawCmd);
            return 1;
        }
        while (loops--)
        {
            clock_gettime(CLOCK_REALTIME, &begin);
            ret = peci_raw(rawAddr, readLength, rawCmd, writeLength, rawResp,
                           readLength);
            timeSpent = getTimeDifference(begin);
            if (verbose && measureTime)
            {
                printf("\nTime taken in iteration %d = %lf s\n",
                       (loopCount - loops), timeSpent);
            }
            totalTimeSpent += timeSpent;

            if (verbose)
            {
                printf("   ");
                for (i = 0; i < readLength; i++)
                {
                    printf("0x%02x ", rawResp[i]);
                }
                printf("\n");
            }
            ccCounts[rawResp[0]]++;
        }
        if (!verbose)
        {
            if (PECI_CC_SUCCESS != ret)
            {
                printf("ERROR %d: command failed\n", ret);
            }
            printf("   ");
            for (i = 0; i < readLength; i++)
            {
                printf("0x%02x ", rawResp[i]);
            }
            printf("\n");
        }

        if (looped)
        {
            printLoopSummary(ccCounts);
        }

        free(rawCmd);
        free(rawResp);
    }
    else
    {
        printf("ERROR: Unrecognized command\n");
        goto ErrorExit;
    }

    if (measureTime)
    {
        printf("Total time taken = %lf seconds\n", totalTimeSpent);
        if (loopCount > 1)
        {
            printf("Average time taken per command = %lf seconds\n",
                   totalTimeSpent / loopCount);
        }
    }

    return 0;

ErrorExit:
    Usage(argv[0]);
    return 1;
}
