Skip to content

Commit c4fd17e

Browse files
committed
Quickassist.c whitespace cleanup. Enhanced the Cavium macros for CAVIUM_MAX_PENDING and CAVIUM_MAX_POLL over-ridable.
1 parent c25086b commit c4fd17e

2 files changed

Lines changed: 76 additions & 72 deletions

File tree

wolfcrypt/src/port/intel/quickassist.c

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ int IntelQaHardwareStart(const char* process_name, int limitDevAccess)
479479

480480
int IntelQaInit(void* threadId)
481481
{
482-
int ret;
482+
int ret;
483483
int devId;
484484
#if !defined(WC_NO_ASYNC_THREADING) && defined(WC_ASYNC_THREAD_BIND)
485485
pthread_t* thread = (pthread_t*)threadId;
@@ -520,7 +520,7 @@ int IntelQaInit(void* threadId)
520520
}
521521
#endif /* !WC_NO_ASYNC_THREADING && !WC_NO_ASYNC_THREAD_BIND */
522522

523-
return devId;
523+
return devId;
524524
}
525525

526526
int IntelQaNumInstances(void)
@@ -534,7 +534,7 @@ int IntelQaOpen(WC_ASYNC_DEV* dev, int devId)
534534
return BAD_FUNC_ARG;
535535
}
536536

537-
(void)devId;
537+
(void)devId;
538538

539539
/* clear device info */
540540
XMEMSET(&dev->qat, 0, sizeof(IntelQaDev));
@@ -544,15 +544,15 @@ int IntelQaOpen(WC_ASYNC_DEV* dev, int devId)
544544
return ASYNC_INIT_E;
545545
}
546546

547-
dev->qat.devId = devId;
547+
dev->qat.devId = devId;
548548
dev->qat.handle = g_cyInstances[devId];
549549

550550
#ifdef QAT_USE_POLLING_THREAD
551551
/* start polling thread */
552552
IntelQaStartPollingThread(dev);
553553
#endif
554554

555-
return 0;
555+
return 0;
556556
}
557557

558558
#if defined(QAT_ENABLE_CRYPTO) || defined(QAT_ENABLE_HASH)
@@ -651,13 +651,13 @@ void IntelQaClose(WC_ASYNC_DEV* dev)
651651
IntelQaStopPollingThread(dev);
652652
#endif
653653

654-
dev->qat.handle = NULL;
654+
dev->qat.handle = NULL;
655655
}
656656
}
657657

658658
void IntelQaDeInit(int devId)
659659
{
660-
(void)devId;
660+
(void)devId;
661661

662662
if (pthread_mutex_lock(&g_Hwlock) == 0) {
663663
IntelQaHardwareStop();
@@ -723,10 +723,10 @@ int IntelQaDevCopy(WC_ASYNC_DEV* src, WC_ASYNC_DEV* dst)
723723

724724
int IntelQaPoll(WC_ASYNC_DEV* dev)
725725
{
726-
int ret = 0;
726+
int ret = 0;
727727

728728
#ifndef QAT_USE_POLLING_THREAD
729-
CpaStatus status;
729+
CpaStatus status;
730730
WOLF_EVENT* event = &dev->event;
731731

732732
#ifdef QAT_USE_POLLING_CHECK
@@ -745,11 +745,11 @@ int IntelQaPoll(WC_ASYNC_DEV* dev)
745745
}
746746
#endif
747747

748-
status = icp_sal_CyPollInstance(dev->qat.handle, QAT_POLL_RESP_QUOTA);
749-
if (status != CPA_STATUS_SUCCESS && status != CPA_STATUS_RETRY) {
750-
printf("IntelQa: Poll failure %d\n", status);
751-
ret = -1;
752-
}
748+
status = icp_sal_CyPollInstance(dev->qat.handle, QAT_POLL_RESP_QUOTA);
749+
if (status != CPA_STATUS_SUCCESS && status != CPA_STATUS_RETRY) {
750+
printf("IntelQa: Poll failure %d\n", status);
751+
ret = -1;
752+
}
753753

754754
#ifndef WC_NO_ASYNC_THREADING
755755
if (event->threadId == 0 || event->threadId == wc_AsyncThreadId())
@@ -784,7 +784,7 @@ int IntelQaPoll(WC_ASYNC_DEV* dev)
784784
(void)dev;
785785
#endif
786786

787-
return ret;
787+
return ret;
788788
}
789789

790790
static int IntelQaPollBlockRet(WC_ASYNC_DEV* dev, int ret_wait)
@@ -1448,12 +1448,12 @@ static void IntelQaRsaPrivateCallback(void *pCallbackTag,
14481448
int ret = ASYNC_OP_E;
14491449

14501450
#ifdef QAT_DEBUG
1451-
printf("IntelQaRsaPrivateCallback: dev %p, status %d, len %d\n",
1451+
printf("IntelQaRsaPrivateCallback: dev %p, status %d, len %d\n",
14521452
dev, status, pOut->dataLenInBytes);
14531453
#endif
14541454

1455-
if (status == CPA_STATUS_SUCCESS) {
1456-
/* validate returned output */
1455+
if (status == CPA_STATUS_SUCCESS) {
1456+
/* validate returned output */
14571457

14581458
if (dev->qat.outLenPtr) {
14591459
if (pOut->dataLenInBytes > *dev->qat.outLenPtr) {
@@ -1462,14 +1462,14 @@ static void IntelQaRsaPrivateCallback(void *pCallbackTag,
14621462
*dev->qat.outLenPtr = pOut->dataLenInBytes;
14631463
}
14641464

1465-
/* return data */
1465+
/* return data */
14661466
if (dev->qat.out && dev->qat.out != pOut->pData) {
1467-
XMEMCPY(dev->qat.out, pOut->pData, pOut->dataLenInBytes);
1467+
XMEMCPY(dev->qat.out, pOut->pData, pOut->dataLenInBytes);
14681468
}
14691469

14701470
/* mark event result */
14711471
ret = 0; /* success */
1472-
}
1472+
}
14731473
(void)opData;
14741474

14751475
/* set return code to mark complete */
@@ -1481,8 +1481,8 @@ int IntelQaRsaPrivate(WC_ASYNC_DEV* dev,
14811481
WC_BIGINT* d, WC_BIGINT* n,
14821482
byte* out, word32* outLen)
14831483
{
1484-
int ret = 0, retryCount = 0;
1485-
CpaStatus status = CPA_STATUS_SUCCESS;
1484+
int ret = 0, retryCount = 0;
1485+
CpaStatus status = CPA_STATUS_SUCCESS;
14861486
CpaCyRsaPrivateKey* privateKey = NULL;
14871487
CpaCyRsaDecryptOpData* opData = NULL;
14881488
CpaFlatBuffer* outBuf = NULL;
@@ -1497,15 +1497,15 @@ int IntelQaRsaPrivate(WC_ASYNC_DEV* dev,
14971497
printf("IntelQaRsaPrivate: dev %p, in %p (%d), out %p\n", dev, in, inLen, out);
14981498
#endif
14991499

1500-
/* setup operation */
1501-
opData = &dev->qat.op.rsa_priv.opData;
1500+
/* setup operation */
1501+
opData = &dev->qat.op.rsa_priv.opData;
15021502
outBuf = &dev->qat.op.rsa_priv.outBuf;
15031503
privateKey = &dev->qat.op.rsa_priv.privateKey;
15041504

1505-
/* init variables */
1505+
/* init variables */
15061506
XMEMSET(opData, 0, sizeof(CpaCyRsaDecryptOpData));
15071507
XMEMSET(outBuf, 0, sizeof(CpaFlatBuffer));
1508-
XMEMSET(privateKey, 0, sizeof(CpaCyRsaPrivateKey));
1508+
XMEMSET(privateKey, 0, sizeof(CpaCyRsaPrivateKey));
15091509

15101510
/* assign buffers */
15111511
ret = IntelQaBigIntToFlatBuffer(d, &privateKey->privateKeyRep1.privateExponentD);
@@ -1524,21 +1524,21 @@ int IntelQaRsaPrivate(WC_ASYNC_DEV* dev,
15241524
*outLen = inLen;
15251525
}
15261526

1527-
opData->inputData.dataLenInBytes = inLen;
1528-
opData->inputData.pData = XREALLOC((byte*)in, inLen, dev->heap,
1527+
opData->inputData.dataLenInBytes = inLen;
1528+
opData->inputData.pData = XREALLOC((byte*)in, inLen, dev->heap,
15291529
DYNAMIC_TYPE_ASYNC_NUMA);
15301530

1531-
outBuf->dataLenInBytes = *outLen;
1532-
outBuf->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
1531+
outBuf->dataLenInBytes = *outLen;
1532+
outBuf->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
15331533

1534-
/* check allocations */
1535-
if (opData->inputData.pData == NULL || outBuf->pData == NULL) {
1536-
ret = MEMORY_E; goto exit;
1537-
}
1534+
/* check allocations */
1535+
if (opData->inputData.pData == NULL || outBuf->pData == NULL) {
1536+
ret = MEMORY_E; goto exit;
1537+
}
15381538

1539-
/* setup private key */
1540-
privateKey->version = CPA_CY_RSA_VERSION_TWO_PRIME;
1541-
privateKey->privateKeyRepType = CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1;
1539+
/* setup private key */
1540+
privateKey->version = CPA_CY_RSA_VERSION_TWO_PRIME;
1541+
privateKey->privateKeyRepType = CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1;
15421542

15431543
/* assign private key to private op data */
15441544
opData->pRecipientPrivateKey = privateKey;
@@ -1550,7 +1550,7 @@ int IntelQaRsaPrivate(WC_ASYNC_DEV* dev,
15501550

15511551
/* perform RSA decrypt */
15521552
do {
1553-
status = cpaCyRsaDecrypt(dev->qat.handle,
1553+
status = cpaCyRsaDecrypt(dev->qat.handle,
15541554
callback,
15551555
dev,
15561556
opData,
@@ -1571,7 +1571,7 @@ int IntelQaRsaPrivate(WC_ASYNC_DEV* dev,
15711571
/* handle cleanup */
15721572
IntelQaRsaPrivateFree(dev);
15731573

1574-
return ret;
1574+
return ret;
15751575
}
15761576

15771577
int IntelQaRsaCrtPrivate(WC_ASYNC_DEV* dev,
@@ -1741,8 +1741,8 @@ int IntelQaRsaPublic(WC_ASYNC_DEV* dev,
17411741
WC_BIGINT* e, WC_BIGINT* n,
17421742
byte* out, word32* outLen)
17431743
{
1744-
int ret = 0, retryCount = 0;
1745-
CpaStatus status = CPA_STATUS_SUCCESS;
1744+
int ret = 0, retryCount = 0;
1745+
CpaStatus status = CPA_STATUS_SUCCESS;
17461746
CpaCyRsaPublicKey* publicKey = NULL;
17471747
CpaCyRsaEncryptOpData* opData = NULL;
17481748
CpaFlatBuffer* outBuf = NULL;
@@ -1757,15 +1757,15 @@ int IntelQaRsaPublic(WC_ASYNC_DEV* dev,
17571757
printf("IntelQaRsaPublic: dev %p, in %p (%d), out %p\n", dev, in, inLen, out);
17581758
#endif
17591759

1760-
/* setup operation */
1761-
opData = &dev->qat.op.rsa_pub.opData;
1760+
/* setup operation */
1761+
opData = &dev->qat.op.rsa_pub.opData;
17621762
outBuf = &dev->qat.op.rsa_pub.outBuf;
17631763
publicKey = &dev->qat.op.rsa_pub.publicKey;
17641764

1765-
/* init variables */
1765+
/* init variables */
17661766
XMEMSET(opData, 0, sizeof(CpaCyRsaEncryptOpData));
17671767
XMEMSET(outBuf, 0, sizeof(CpaFlatBuffer));
1768-
XMEMSET(publicKey, 0, sizeof(CpaCyRsaPublicKey));
1768+
XMEMSET(publicKey, 0, sizeof(CpaCyRsaPublicKey));
17691769

17701770
/* assign buffers */
17711771
ret = IntelQaBigIntToFlatBuffer(e, &publicKey->publicExponentE);
@@ -1781,17 +1781,17 @@ int IntelQaRsaPublic(WC_ASYNC_DEV* dev,
17811781
/* make sure output len is set to modulus size */
17821782
*outLen = n->len;
17831783

1784-
opData->inputData.dataLenInBytes = inLen;
1785-
opData->inputData.pData = XREALLOC((byte*)in, inLen, dev->heap,
1784+
opData->inputData.dataLenInBytes = inLen;
1785+
opData->inputData.pData = XREALLOC((byte*)in, inLen, dev->heap,
17861786
DYNAMIC_TYPE_ASYNC_NUMA);
17871787

1788-
outBuf->dataLenInBytes = *outLen;
1789-
outBuf->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA64);
1788+
outBuf->dataLenInBytes = *outLen;
1789+
outBuf->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA64);
17901790

1791-
/* check allocations */
1792-
if (opData->inputData.pData == NULL || outBuf->pData == NULL) {
1793-
ret = MEMORY_E; goto exit;
1794-
}
1791+
/* check allocations */
1792+
if (opData->inputData.pData == NULL || outBuf->pData == NULL) {
1793+
ret = MEMORY_E; goto exit;
1794+
}
17951795

17961796
/* assign public key to public op data */
17971797
opData->pPublicKey = publicKey;
@@ -1803,7 +1803,7 @@ int IntelQaRsaPublic(WC_ASYNC_DEV* dev,
18031803

18041804
/* perform RSA encrypt */
18051805
do {
1806-
status = cpaCyRsaEncrypt(dev->qat.handle,
1806+
status = cpaCyRsaEncrypt(dev->qat.handle,
18071807
callback,
18081808
dev,
18091809
opData,
@@ -1824,7 +1824,7 @@ int IntelQaRsaPublic(WC_ASYNC_DEV* dev,
18241824
/* handle cleanup */
18251825
IntelQaRsaPublicFree(dev);
18261826

1827-
return ret;
1827+
return ret;
18281828
}
18291829

18301830
static void IntelQaRsaModExpFree(WC_ASYNC_DEV* dev)
@@ -1891,7 +1891,7 @@ int IntelQaRsaExptMod(WC_ASYNC_DEV* dev,
18911891
byte* out, word32* outLen)
18921892
{
18931893
int ret = 0, retryCount = 0;
1894-
CpaStatus status = CPA_STATUS_SUCCESS;
1894+
CpaStatus status = CPA_STATUS_SUCCESS;
18951895
CpaCyLnModExpOpData* opData = NULL;
18961896
CpaFlatBuffer* target = NULL;
18971897
CpaCyGenFlatBufCbFunc callback = IntelQaRsaModExpCallback;
@@ -1909,7 +1909,7 @@ int IntelQaRsaExptMod(WC_ASYNC_DEV* dev,
19091909
opData = &dev->qat.op.rsa_modexp.opData;
19101910
target = &dev->qat.op.rsa_modexp.target;
19111911

1912-
/* init variables */
1912+
/* init variables */
19131913
XMEMSET(opData, 0, sizeof(CpaCyLnModExpOpData));
19141914
XMEMSET(target, 0, sizeof(CpaFlatBuffer));
19151915

@@ -1920,23 +1920,23 @@ int IntelQaRsaExptMod(WC_ASYNC_DEV* dev,
19201920
ret = BAD_FUNC_ARG; goto exit;
19211921
}
19221922

1923-
opData->base.dataLenInBytes = inLen;
1924-
opData->base.pData = XREALLOC((byte*)in, inLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
1923+
opData->base.dataLenInBytes = inLen;
1924+
opData->base.pData = XREALLOC((byte*)in, inLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
19251925

1926-
target->dataLenInBytes = *outLen;
1927-
target->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
1926+
target->dataLenInBytes = *outLen;
1927+
target->pData = XREALLOC(out, *outLen, dev->heap, DYNAMIC_TYPE_ASYNC_NUMA);
19281928

1929-
/* check allocations */
1930-
if (opData->base.pData == NULL || target->pData == NULL) {
1931-
ret = MEMORY_E; goto exit;
1932-
}
1929+
/* check allocations */
1930+
if (opData->base.pData == NULL || target->pData == NULL) {
1931+
ret = MEMORY_E; goto exit;
1932+
}
19331933

19341934
/* store info needed for output */
19351935
dev->qat.out = out;
19361936
dev->qat.outLenPtr = outLen;
19371937
IntelQaOpInit(dev, IntelQaRsaModExpFree);
19381938

1939-
/* make modexp call async */
1939+
/* make modexp call async */
19401940
do {
19411941
status = cpaCyLnModExp(dev->qat.handle,
19421942
callback,
@@ -4594,7 +4594,7 @@ int main(int argc, char** argv)
45944594
wolfSSL_Debugging_ON();
45954595
#endif
45964596

4597-
IntelQaInit(NULL);
4597+
IntelQaInit(NULL);
45984598

45994599
/* DRBG Test */
46004600
IntelQaOpen(&dev, 0);
@@ -4710,9 +4710,9 @@ int main(int argc, char** argv)
47104710
(void)tmp;
47114711
(void)tmpLen;
47124712

4713-
IntelQaDeInit(0);
4713+
IntelQaDeInit(0);
47144714

4715-
return 0;
4715+
return 0;
47164716
}
47174717

47184718
#endif

wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ typedef struct CspMultiRequestStatusBuffer CspMultiRequestStatusBuffer;
6868

6969

7070
#ifdef WOLFSSL_ASYNC_CRYPT
71-
#define CAVIUM_MAX_PENDING 10 /* 90 */
72-
#define CAVIUM_MAX_POLL MAX_TO_POLL
71+
#ifndef CAVIUM_MAX_PENDING
72+
#define CAVIUM_MAX_PENDING 10 /* 90 */
73+
#endif
74+
#ifndef CAVIUM_MAX_POLL
75+
#define CAVIUM_MAX_POLL MAX_TO_POLL
76+
#endif
7377
#endif
7478

7579

0 commit comments

Comments
 (0)