]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/sa-lld.git/blob - test/SaUnitTest/src/testconn2.c
moved the throughput computation to be done via cycle capture instead of osal call...
[keystone-rtos/sa-lld.git] / test / SaUnitTest / src / testconn2.c
1 /*
2  *
3  * Copyright (C) 2010-2020 Texas Instruments Incorporated - http://www.ti.com/
4  *
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions
8  *  are met:
9  *
10  *    Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  *    Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the
16  *    distribution.
17  *
18  *    Neither the name of Texas Instruments Incorporated nor the names of
19  *    its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34 */
36 #include "unittest.h"
37 #include "testconn.h"
38 #include "salldsim/salldcfg.h"
39 #include "ti/osal/osal.h"
40 #if defined (NSS_LITE2)
41 #include "ti/csl/arch/csl_arch.h"
42 #include <inttypes.h>
43 #endif
45 /*
46  * Declare protocol and connection related handles
47  */
48 sauHdrHandle_t  testHdrHandles[SA_TEST_MAX_HDR_HANDLES];
49 sauConnHandle_t testConnHandles[SA_TEST_MAX_CONNS] __attribute__ ((aligned (16)));
50 int             numHdrHandles, numConnHandles;
52 static uint8_t  testCmdLbBuf[sa_MAX_CMDLB_SIZE];
53 static uint8_t  testCmdLbBuf2[sa_MAX_CMDLB_SIZE];
54 static uint8_t  sap_pkt_test_buf[TF_DESC_BUFSIZE];
56 /* Protocol Base Addresses */
57 uint8_t testMacSrcAddr[6]  = {0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04};
58 uint8_t testMacDestAddr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
59 uint8_t testIpSrcAddr[16]  = {0x9e, 0xda, 0x6d, 0x14, 0, 0, 0, 0,
60                             0, 0, 0, 0, 0, 0, 0, 0};
61 uint8_t testIpDestAddr[16] = {0x14, 0x15, 0x16, 0x17, 0, 0, 0, 0,
62                             0, 0, 0, 0, 0, 0, 0, 0};
63 uint8_t testIpinSrcAddr[16] = {0x9e, 0xda, 0x6d, 0x20, 0, 0, 0, 0,
64                              0, 0, 0, 0, 0, 0, 0, 0};
65 uint8_t testIpinDestAddr[16] = {0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0,
66                               0, 0, 0, 0, 0, 0, 0, 0};
67                               
68 static uint8_t testEncIV[16] = {0x00, 0x00, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 
69                               0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};    
70                              
71 static uint8_t testAuthIV[16] = {0x00, 0x00, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
72                                0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
73                                
74 static uint8_t testAad[12] = {0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0, 0, 0, 0};  
76 #define SAU_TXPKT_TO_HOST   1                                                               
78 /* Internal local functions for throughput measurement */
79 #if defined (BUILD_MCU)
80 static void sau_cycle_cnt_init(void)
81 {
82     uint32_t val;
83     CSL_armR5PmuCfg(0, 0, 1);
84     /* Clear the overflow */
85     val = CSL_armR5PmuReadCntrOverflowStatus();
86     val &= 0x80000007;
87     CSL_armR5PmuClearCntrOverflowStatus(val);
88     CSL_armR5PmuCfgCntr(CSL_ARM_R5_PMU_CYCLE_COUNTER_NUM, CSL_ARM_R5_PMU_EVENT_TYPE_CYCLE_CNT);
89     CSL_armR5PmuEnableAllCntrs(0);
90     CSL_armR5PmuResetCycleCnt();
91     /* Set PMCR C-bit */
92     CSL_armR5PmuResetCntrs();
93     CSL_armR5PmuEnableAllCntrs(1);
94 }
95 static uint64_t sau_read_cycle_cnt(void)
96 {
97     uint32_t val;
98     uint64_t cnt;
99     val = CSL_armR5PmuReadCntr(CSL_ARM_R5_PMU_CYCLE_COUNTER_NUM);
100     cnt = (uint64_t) val;
101     return (cnt);
103 #elif defined (BUILD_MPU)
104 static void sau_cycle_cnt_init(void)
106     CSL_initGTC();
108 static uint64_t sau_read_cycle_cnt(void)
110     uint64_t cnt;
111     cnt = CSL_getGTCcount();
112     return (cnt);
114 #else
115 static void sau_cycle_cnt_init(void)
117   /* stub function */
119 static uint64_t sau_read_cycle_cnt(void)
121   /* stub function */
124 #endif
127 /*******************************************************************************
128  *  Function: Create a Data Mode channel  
129  *******************************************************************************
130  *  DESCRIPTION:  Create a Data Mode Channel
131  *
132  ******************************************************************************/
133 sauHdrHandle_t* sauCreateDm (sauHdrHandle_t *pHdl, uint16_t hdrSize, sauDataModeConfig_t* pCfg)
135     sauHdrHandle_t *pHdrHandle = TEST_ALLOC_HDR_HANDLE();
136     salldSimCommConfig_t        commCfg;
137     salldSimDataModeConfig_t    dmCfg;
138     salldOpenConfig_t           openCfg;
139     uint16_t retCode;
140     sauDataMode_t  *pDmHdr = &pHdrHandle->u.data;
141     int i;
142     
143     if (pHdrHandle == NULL)
144     {
145         salld_sim_print("sauCreateDm: Hdr Handle is not available!\n");
146         return (NULL);
147     }    
148     
149     /* Prepare and create the SALLD channel */
150     memset(&commCfg, 0, sizeof(commCfg));
151     memset(&dmCfg, 0, sizeof(dmCfg));
152     memset(&openCfg, 0, sizeof(openCfg));
153     commCfg.protocolType  = sa_PT_NULL;
154     commCfg.cipherMode    = pCfg->cipherMode;
155     commCfg.authMode      = pCfg->authMode;
156     commCfg.replayWinSize = 0;
157     
158     commCfg.destInfo[0].swInfo0 = 0x55500000;
159     commCfg.destInfo[0].swInfo1 = 0x5550;
160     commCfg.destInfo[0].flowID =  tFramework.tfFlowNum;
161     commCfg.destInfo[0].queueID = tFramework.rxComplRingNum; /* Route to Host, using default flow */
162     commCfg.destInfo[1].swInfo0 = 0;
163     commCfg.destInfo[1].flowID = 0;
164     commCfg.destInfo[1].queueID = 0;     /* Note Used */
166     dmCfg.encKeySize = pCfg->encKeySize;
167     dmCfg.macKeySize = pCfg->macKeySize;
168     dmCfg.macSize    = pCfg->macSize;
169     dmCfg.aadSize    = pCfg->aadSize;
170     dmCfg.enc        = pCfg->enc;
171     dmCfg.enc1st     = pCfg->enc1st;
172     dmCfg.ivSize     = pCfg->ivSize;
173     dmCfg.saltSize   = pCfg->saltSize;
174     dmCfg.ctrlBitMap = (uint16_t) 0U;
176     if(pCfg->ctrlBitMap & SAU_DM_CFG_PROMOTE)
177     {
178         dmCfg.ctrlBitMap |= sa_DM_CONFIG_PROMOTE_CHANNEL;
179     }
180     if(pCfg->ctrlBitMap & SAU_DM_CFG_DEMOTE)
181     {
182         dmCfg.ctrlBitMap |= sa_DM_CONFIG_DEMOTE_CHANNEL;
183     }
184     if(pCfg->ctrlBitMap & SAU_DM_CFG_NONSECURE_CRYPTO)
185     {
186         dmCfg.ctrlBitMap |= sa_DM_CONFIG_USE_SECURE_CTX_FOR_NON_SECURE_CHANNEL;
187     }
188 #if defined(NSS_LITE2)
189     /* Wild card match for the incoming packets's for PrivId
190      * User privillage for the channel
191      */
192      dmCfg.secure            = 0;
193      dmCfg.priv              = 0;
194      dmCfg.privId            = 0xC3;
195 #endif
197     openCfg.ctrlBitMap    = sa_CONTROLINFO_CTRL_TX_ON;
198     pDmHdr->pChan = salldcfg_chan_init(&commCfg, (void *)&dmCfg);
200     if (pDmHdr->pChan == NULL)
201     {
202         /* Free the protocol header handle */
203         numHdrHandles--;
204         salld_sim_print("sauCreateDm: salldcfg_chan_init() failed!\n");
205         return (NULL);
206     }
207     
208     if ((retCode = salldSim_init_chn(pDmHdr->pChan)) != salld_SIM_ERR_NONE)
209     {
210         numHdrHandles--;
211         salld_sim_print("sauCreateDm: salldSim_init_chn() failed with retCode = 0x%0x!\n", retCode);
212         return (NULL);
213     }
214     
215     if ((retCode = salldSim_open_chn(pDmHdr->pChan, &openCfg)) != salld_SIM_ERR_NONE)
216     {
217         numHdrHandles--;
218         salld_sim_print("sauCreateDm: salldSim_open_chn() failed with retCode = 0x%0x!\n", retCode);
219         return (NULL);
220     }
222     /* Fill the header information */
223     pDmHdr->seqNum = 0;
224     pDmHdr->aadSize = pCfg->aadSize; 
225     memcpy(pDmHdr->aad, testAad, pDmHdr->aadSize);
226     
227     pDmHdr->fCmdLbAvail = FALSE;
228     
229     pHdrHandle->hdrLen = hdrSize;
230     
231     switch (pCfg->cipherMode)
232     {
233         case sa_CipherMode_AES_CTR:
234         case sa_CipherMode_AES_F8:
235         case sa_CipherMode_AES_CBC:
236         case sa_CipherMode_CCM:
237         case sa_CipherMode_GCM:
238         case sa_CipherMode_SNOW3G_F8:
239             pDmHdr->encIvSize = 16;
240             break;
241         
242         case sa_CipherMode_DES_CBC:
243         case sa_CipherMode_3DES_CBC:
244         case sa_CipherMode_KASUMI_F8:
245             pDmHdr->encIvSize = 8;
246             break;
247             
248         default:
249             pDmHdr->encIvSize = 0;
250             break;
251     }
252     
253     memcpy(pDmHdr->encIV, testEncIV, pDmHdr->encIvSize);
254     
255     switch (pCfg->authMode)
256     {
257         case sa_AuthMode_GMAC:
258         case sa_AuthMode_GMAC_AH:
259             pDmHdr->authIvSize = 8;
260             break;
261         
262         case sa_AuthMode_KASUMI_F9:
263             pDmHdr->authIvSize = 8;
264             break;
265             
266         default:
267             pDmHdr->authIvSize = 0;
268             break;
269     }
270     
271     memcpy(pDmHdr->authIV, testAuthIV, pDmHdr->authIvSize);
272     
273     
274     pHdrHandle->upHdl = pHdl;   
275     pHdrHandle->hdrType = SAU_PROTO_DATAMODE;
277     /* Check if the hdrSize exceeded the max size */
278     if (hdrSize > SAU_MAX_HDR_SIZE)
279     {
280       /* Reset the hdrSize */
281       hdrSize = 12;
282     }
284     /* Fill the default header info */
285     for(i = 0; i < hdrSize; i++)
286         pHdrHandle->hdr[i] = (uint8_t)i;
287     
288     return(pHdrHandle);
291 /*******************************************************************************
292  *  Function: Create connection  
293  *******************************************************************************
294  *  DESCRIPTION:  Link the related hdr Handles to create a connection 
295  *
296  ******************************************************************************/
297 sauConnHandle_t* sauCreateConnection(tFramework_t *tf, saTest_t *pat, sauHdrHandle_t *pTail)
299     sauConnHandle_t* pConnHdl = TEST_ALLOC_CONN_HANDLE(); 
300     sauHdrHandle_t* pHdrHdl = pTail;
301     int index, ipIndex;
302     
303     if (pConnHdl == NULL)
304     {
305         salld_sim_print("sauCreateConnection: Connection Handle is not available!\n");
306         return (NULL);
307     }  
308     
309     memset(pConnHdl, 0, sizeof(sauConnHandle_t));
310     memset(pConnHdl->ipOffset, SA_CONN_OFFSET_NONE, 3);
311     pConnHdl->ID = (uint16_t)(numConnHandles - 1);
312     pConnHdl->ipsecOffset = SA_CONN_OFFSET_NONE;
313     pConnHdl->rtpOffset = SA_CONN_OFFSET_NONE;
314     pConnHdl->udpOffset = SA_CONN_OFFSET_NONE;
315     pConnHdl->ipsecIndex = SA_CONN_INDEX_NONE;
316     pConnHdl->srtpIndex = SA_CONN_INDEX_NONE;
317     pConnHdl->srtcpIndex = SA_CONN_INDEX_NONE;
318     
319     /* record the handles in the connection chain */
320     do 
321     {
322         pConnHdl->pHdrHdl[pConnHdl->numHandles++] = pHdrHdl; 
323         
324         if (pConnHdl->numHandles > SA_MAX_HDR_HANDLES_PER_CONN)
325         {
326             salld_sim_print("sauCreateConnection: Too many entries (%d) in the chain\n", 
327                               pConnHdl->numHandles);
328             numConnHandles--;
329             return(NULL);                  
330         }
331     } while ((pHdrHdl = pHdrHdl->upHdl));
332     
333 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
334     /*
335      * Perform the following processes in reverse order
336      * - Extract Header information
337      * - Extract protocol offset information
338      * - Register the receive protocol information to PA if not done before
339      */
340     sauCmdReply.replyId = TF_CMD_SWINFO0_ADD_ID + 0;  /* TF_CMD_SWINFO0_ADD_ID identifies command, 16 LS bits identify the local handle number */
341     sauCmdReply.queue = tf->QGen[Q_CMD_REPLY];
342 #endif
344     ipIndex = 0; 
345     for (index = pConnHdl->numHandles - 1; index >= 0; index--)
346     {
347         pHdrHdl = pConnHdl->pHdrHdl[index];
348         
349         switch (pHdrHdl->hdrType)
350         {
351         #if !defined(NSS_LITE) && !defined(NSS_LITE2)
352             case SAU_PROTO_MAC:
353                 sauRegisterMac(tf, pat, pHdrHdl);
354             break;
355             
356             case SAU_PROTO_IP:
357                 pHdrHdl->u.ip.index = ipIndex;
358                 pConnHdl->ipOffset[ipIndex++] = pConnHdl->hdrLen;
359                 if (pHdrHdl->u.ip.ipsecHandle)
360                 {
361                     /* Note: only one IPSEC channel is supported per connection */
362                     pConnHdl->ipsecIndex = index;  
363                     pConnHdl->ipsecOffset = pConnHdl->hdrLen + pHdrHdl->hdrLen; 
364                     pHdrHdl->u.ip.ipsecHandle->pChan->pConnHdl = (void *)pConnHdl; 
365                     
366                 }    
367                 sauRegisterIp(tf, pat, pHdrHdl, index);   
368             break;
369         
370             case SAU_PROTO_UDP:
371                 pConnHdl->udpOffset =  pConnHdl->hdrLen;
372                 if (pHdrHdl->u.udp.srtpHandle)
373                 {
374                     pConnHdl->rtpOffset = pConnHdl->udpOffset + 8;
375                     /* Note: only one SRTP channel is supported per connection */
376                     pConnHdl->srtpIndex = index; 
377                     pHdrHdl->u.udp.srtpHandle->pChan->pConnHdl = (void *)pConnHdl;   
378                     
379                 }
380                 else if (pHdrHdl->u.udp.srtcpHandle)
381                 {
382                     pConnHdl->rtpOffset = pConnHdl->udpOffset + 8;
383                     /* Note: only one SRTCP channel is supported per connection */
384                     pConnHdl->srtcpIndex = index; 
385                     pHdrHdl->u.udp.srtcpHandle->pChan->pConnHdl = (void *)pConnHdl;   
386                 
387                 }    
388                 sauRegisterUdp(tf, pat, pHdrHdl);
389             break;
390             
391             case SAU_PROTO_AC:
392         #endif    
393             case SAU_PROTO_DATAMODE:
394             break;
395             
396             default:
397                 /* Should never enter here */
398                 salld_sim_print("sauCreateConnection: Invalid Hdr type (%d) in the chain\n", 
399                                  pHdrHdl->hdrType);
400                 numConnHandles--;
401                 return(NULL);                  
402         }
403         
404         /* copy the header and update hdr length */
405         memcpy(&pConnHdl->hdr[pConnHdl->hdrLen], pHdrHdl->hdr, pHdrHdl->hdrLen);
406         pConnHdl->hdrLen += pHdrHdl->hdrLen;
407     }
408     pConnHdl->numIp = (uint8_t)ipIndex; 
409     
410     return(pConnHdl);
411
413 /*******************************************************************************
414  *  Function: Generate payload  
415  *******************************************************************************
416  *  DESCRIPTION:  Fill the data buffer with the specified payload data  
417  *
418  *  Note: It is up to the caller to allocate buffer
419  ******************************************************************************/
420 void sauGenPayload(sauPayloadType_e type, uint8_t initValue, uint16_t len, uint8_t* buf)
422     uint8_t data = initValue;
423     int i;
424     
425     switch (type)
426     {
427         case SAU_PAYLOAD_CONST:
428             memset(buf, data, len);
429             break;
430             
431         case SAU_PAYLOAD_INC8: 
432             for(i = 0; i < len; i++) buf[i] = data++;       
433             break;
434             
435         case SAU_PAYLOAD_DEC8: 
436             for(i = 0; i < len; i++) buf[i] = data--;       
437             break;
438             
439          case SAU_PAYLOAD_RANDOM:
440             for(i = 0; i < len; i++) buf[i] = rand() & 0xFF;       
441             break;
442             
443          default:
444             printf("sauGenPayload: invalid paylaod type (%d)\n", type);
445             break;   
446     }
449 uint64_t dmProcCycle[1000];
450 uint32_t dmProcCycleMeasCnt = 0;
452 uint64_t dmProcCycle2[1000];
453 uint32_t dmProcCycleMeasCnt2 = 0;
455 /*******************************************************************************
456  *  Function: Prepare and format Data Mode packet 
457  *******************************************************************************
458  *  DESCRIPTION:  This function format data mode packet 
459  *
460  ******************************************************************************/
461 static void sauFormatDmPkt(sauConnHandle_t *pConnHdl, sauHdrHandle_t* pDmHdl, 
462                           Sa_PktInfo_t* pPktInfo, Sa_PktDesc_t* pPktDesc, uint16_t payloadLen)
464     Sa_PayloadInfo_t *pPayloadInfo = &pPktInfo->payloadInfo;
465     Sa_CmdLabelInfo_t*  pCmdLbInfo = &pPktInfo->cmdlb;
466     sauDataMode_t*  pDmHdr = &pDmHdl->u.data;
467     
468     /* Command Label Info */
469     pCmdLbInfo->cmdLbBuf = testCmdLbBuf;
470     
471     /* fill the payload Info */
472     pPktInfo->validBitMap = sa_PKT_INFO_VALID_PAYLOAD_INFO |
473                             sa_PKT_INFO_VALID_CMDLB_INFO;
474     pPayloadInfo->encOffset = pConnHdl->hdrLen;
475     pPayloadInfo->authOffset = 0;
476     pPayloadInfo->encSize  = payloadLen;
477     pPayloadInfo->authSize = pPktDesc->size;
478     pPayloadInfo->encIV    = pDmHdr->encIV;
479     pPayloadInfo->authIV   = pDmHdr->authIV;
480     pPayloadInfo->aad      = pDmHdr->aad;
481     
482     /* Update the IV and AAD with sequence Number */
483     pktWrite32bits_m((uint8_t *)pDmHdr->encIV, 0, pDmHdr->seqNum);
484     pktWrite32bits_m((uint8_t *)pDmHdr->authIV, 0, pDmHdr->seqNum);
485     // if (pPayloadInfo->aad)
486     if (pDmHdr->aadSize)
487     {
488         /* We only support AAD length of 8 and 12 */
489         pktWrite32bits_m((uint8_t *)pDmHdr->aad, pDmHdr->aadSize - 4, pDmHdr->seqNum);
490     }
491     
492     pDmHdr->seqNum++;
493     
494     pPktDesc->payloadOffset = 0;
495     pPktDesc->payloadLen = pPktDesc->size;
496     
497     if (!pDmHdr->fCmdLbAvail)
498     {
499         /* first packet */
500         pCmdLbInfo->cmdLbUpdateInfo = &pDmHdr->cmdLbUpdate;
501         Sa_chanSendData(pDmHdr->pChan->salldInst, pPktInfo, FALSE);
502         
503         /* Copy and update command lable */
504         pDmHdr->cmdLbSize = pCmdLbInfo->cmdLbSize;
505         memcpy((void *)pDmHdr->cmdLbBuf, testCmdLbBuf, pDmHdr->cmdLbSize);
506         
507         {
508             Sa_CmdLbUpdateInfo_t* updateInfo = &pDmHdr->cmdLbUpdate;
509             uint32_t *cmdLb = pDmHdr->cmdLbBuf;
510             sa_mDmResetCmdLb(updateInfo, cmdLb);
511         }  
512         
513         pDmHdr->fCmdLbAvail = TRUE;      
514             
515     }
516     else
517     {
518         pCmdLbInfo->cmdLbUpdateInfo = NULL;
520         if(dmProcCycleMeasCnt < 1000)
521         {
522             dmProcCycle[dmProcCycleMeasCnt] = TimerP_getTimeInUsecs();
523         }
524         Sa_chanSendData(pDmHdr->pChan->salldInst, pPktInfo, FALSE);
525         if (dmProcCycleMeasCnt < 1000)
526         {
527             dmProcCycle[dmProcCycleMeasCnt] = TimerP_getTimeInUsecs() - dmProcCycle[dmProcCycleMeasCnt];
528             dmProcCycleMeasCnt++;
529         }
531         /* Command update measurement */
532         if(dmProcCycleMeasCnt2 < 1000)
533         {
534             dmProcCycle2[dmProcCycleMeasCnt2] = TimerP_getTimeInUsecs();
535         }
537         {
538             Sa_CmdLbUpdateInfo_t* updateInfo = &pDmHdr->cmdLbUpdate;
539             uint32_t *cmdLb  = (uint32_t *)testCmdLbBuf2;
540             uint32_t *cmdLb2 = cmdLb;
541             
542             memcpy(cmdLb, pDmHdr->cmdLbBuf, pDmHdr->cmdLbSize);
544             if (updateInfo->subMode == sa_DM_CCM_GEN)
545             {
546               sa_mDmUpdateCmdLb_ccm_gen(pConnHdl->hdrLen, payloadLen, pDmHdr->encIV, pDmHdr->aadSize,  pDmHdr->aad, updateInfo, cmdLb2);
547             }
548             else 
549             {
550               sa_mDmUpdateCmdLb(pConnHdl->hdrLen, payloadLen, pDmHdr->encIV, 0, pPktDesc->size, pDmHdr->authIV,
551                                 pDmHdr->aadSize,  pDmHdr->aad,  (uint8_t *) pPktDesc->segments[0], updateInfo, cmdLb2);
552             }
553             
554             if (dmProcCycleMeasCnt2 < 1000)
555             {
556                 dmProcCycle2[dmProcCycleMeasCnt2] = TimerP_getTimeInUsecs() - dmProcCycle2[dmProcCycleMeasCnt2];
557                 dmProcCycleMeasCnt2++;
558             }
560             if (memcmp(testCmdLbBuf, cmdLb, pDmHdr->cmdLbSize))
561             {
562                 salld_sim_print("sauFormatDmPkt: command label mismatches!\n");
563                 salld_sim_halt ();
565             }
567         }
571     }
574 /*******************************************************************************
575  *  Function: Generate DM packet per connection
576  *******************************************************************************
577  *  DESCRIPTION:  This function prepares the Data Mode packet ready to be send to PA/SA
578  *      subsystem through the CPPI queue. It performs the following actions
579  *      - Allocate the buffer descriptor based on payalod and header size
580  *      - Initialize the SA pktInfo structure
581  *      - Prepare and call salldSendData()
582  *      - Fill the swInfo words
583  *      - Prepare and fill the PS Info words with a set of the SA commands
584  *        per connection
585  *
586  ******************************************************************************/
587 static CSL_UdmapCppi5HMPD* sauGenDmPkt(tFramework_t *tf, int connIndex, uint16_t payloadLen, uint8_t* payload)
589     sauConnHandle_t *pConnHdl = &testConnHandles[connIndex];
590     sauHdrHandle_t* pHdrHdl;
591     CSL_UdmapCppi5HMPD *hd;
592     Sa_PktInfo_t  pktInfo;
593     Sa_PktDesc_t* pPktDesc = &pktInfo.pktDesc;
594     Sa_CmdLabelInfo_t*  pCmdLbInfo = &pktInfo.cmdlb;
595     uint16_t      pktLen;
596     int           index;
597     uintptr_t     cmdLblAddr;
598     uint32_t      pktId, flowId;
599     uint32_t      pTsInfo = 0, pSwInfo0, pSwInfo1, pSwInfo2;
601     #if SA_GEN_TEST_VECTOR_TX
602     static Bool   first[10] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
603     #endif
604     
605     if (connIndex >= SA_TEST_MAX_CONNS)
606     {
607         salld_sim_print("sauGenToAirPkt: connIndex(%d) exceeds its range\n", connIndex);
608         return NULL;
609     }
610     
611     pktLen = payloadLen + pConnHdl->hdrLen;
613     hd = testCommonGetBuffer(tf, (Int)(pktLen + SA_PKT_MARGIN));
614     if (hd == NULL)  {
615         salld_sim_print("sauGenTxPkt: no link buffer available\n");
616         return NULL;
617     }
619     /* Initialize the packet descriptor */
620     salld_sim_init_pktdesc(pPktDesc, 1);
621     pPktDesc->size = pktLen;
622     pPktDesc->segments[0] =  (void *) (uintptr_t)(hd->bufPtr); 
623     pPktDesc->segUsedSizes[0] = pPktDesc->size;
624     pPktDesc->segAllocSizes[0] = hd->orgBufLen;
625     
626     /* Construct the original packet and update the first 32-bit payload with connection ID */
627     memcpy((uint8_t *)pPktDesc->segments[0], pConnHdl->hdr,  pConnHdl->hdrLen);
628     memcpy(((uint8_t *)pPktDesc->segments[0]) + pConnHdl->hdrLen, payload,  payloadLen);
629     pktWrite32bits_m((uint8_t *)pPktDesc->segments[0], pConnHdl->hdrLen, (uint32_t)connIndex);
630     
631     /* We only support one-layer at this moment */
632     if ( pConnHdl->numHandles != 1)
633     {
634         salld_sim_print("sauGenToAirPkt: to many handles %d \n", pConnHdl->numHandles);
635         return NULL;
636     }
637     
638     /* Perform protocol-specific operation in reverse order */
639     for (index = 0; index < pConnHdl->numHandles; index++)
640     {
641         pHdrHdl = pConnHdl->pHdrHdl[index];
642         
643         switch (pHdrHdl->hdrType)
644         {
645             case SAU_PROTO_DATAMODE:
647                 sauFormatDmPkt(pConnHdl, pHdrHdl, &pktInfo, pPktDesc, payloadLen);
649                 /* Update EPIB information */
650                 CSL_udmapCppi5SetEpiDataPresent((void*) hd, EPI_PRESENT);
651                 CSL_udmapCppi5RdEpiData((void *) hd, &pTsInfo, &pSwInfo0, &pSwInfo1, &pSwInfo2);
652                 /* UPdate swInfo */
653                 pSwInfo0 = pktInfo.swInfo.swInfo[0];
654                 pSwInfo1 = pktInfo.swInfo.swInfo[1];
655                 pSwInfo2 = pktInfo.swInfo.swInfo[2];
656                 CSL_udmapCppi5WrEpiData((void *) hd, pTsInfo, pSwInfo0, pSwInfo1, pSwInfo2);
657                 /* overwrite the flow id */
658                 CSL_udmapCppi5GetIds((void*) hd, &pktId, &flowId);
659                 /* Clear PS flags and any error */
660                 hd->pktInfo1 = 0;
661 #if defined (ACP_COHERENCY)
662                 hd->nextDescPtr = CSL_pktdmaMakeAselAddr((uint64_t) 0ULL, \
663                                 CSL_LCDMA_RINGACC_ASEL_ENDPOINT_ACP_WR_ALLOC);
664 #else
665                 /* Clear any next descriptor pointer */
666                 hd->nextDescPtr = 0;
667 #endif
668                 flowId = tFramework.tfFlowNum;
669                 CSL_udmapCppi5SetIds((void*) hd, SA2UL_TEST_CPPI5_DESCRIPTOR_TYPE_HOST, pktId, flowId);
670             break;
671         
672             default:
673                 /* Should never enter here */
674                 salld_sim_print("sauGenToAirPkt: Hdr entry (%d) with invalid Hdr type (%d) in the chain \n", 
675                                  index, pHdrHdl->hdrType);
676                 return(NULL);                  
677         }
678     }
679     
680     /* Prepare to send pkt to PA/SA */
681     CSL_udmapCppi5SetBufferAddr((CSL_UdmapCppi5HMPD*) hd, (uint64_t)Osal_VirtToPhys(pPktDesc->segments[0]));
683 #if defined (ACP_COHERENCY)
684     /* update the buffer for asel bits*/
685     hd->bufPtr      = CSL_pktdmaMakeAselAddr ((uint64_t) hd->bufPtr, \
686                              CSL_LCDMA_RINGACC_ASEL_ENDPOINT_ACP_WR_ALLOC);
687 #endif
690 #if defined(SOC_AM64X)
691     /* For AM64X (LCDMA) bufferLen is set to max value during allocation */
692 #else
693     CSL_udmapCppi5SetBufferLen ((CSL_UdmapCppi5HMPD*) hd, pPktDesc->size);
694 #endif
695     CSL_udmapCppi5SetPktLen((void *) hd, SA2UL_TEST_CPPI5_DESCRIPTOR_TYPE_HOST, pPktDesc->size);
697     /* Attach the command label in PS data */
698     CSL_udmapCppi5SetPsDataLoc((void *) hd, CSL_UDMAP_CPPI5_PD_DESCINFO_PSINFO_VAL_IN_DESC);
699     cmdLblAddr = CSL_udmapCppi5GetPsDataAddr((void*) hd, 0, EPI_PRESENT);
700     /* First word of PS INFO */
701     memcpy ((void *) cmdLblAddr, pCmdLbInfo->cmdLbBuf, pCmdLbInfo->cmdLbSize);
702     CSL_udmapCppi5SetPsDataLen((void *) hd, pCmdLbInfo->cmdLbSize);
704     #if SA_GEN_TEST_VECTOR_TX
705     if(first[connIndex])
706     {
707         utilOutputScFromSwInfo(&tFramework, pktInfo.swInfo.swInfo);
708         first[connIndex] = FALSE;
709     }
710     
711     utilOutputPkt(&tFramework, pktInfo.swInfo.swInfo, pCmdLbInfo->cmdLbSize, (uint32_t *)pCmdLbInfo->cmdLbBuf,
712                    pPktDesc->size, (uint8_t*) pPktDesc->segments[0], TRUE);
713     #endif
714     
715     
716     return (hd);
719 /*******************************************************************************
720  *  Function: Prepare and send From-Air packet per connection
721  *******************************************************************************
722  *  DESCRIPTION:  This function process the rx packet from the network through
723  *      PA/SA subsystem via the CPPI queue. It performs the following actions
724  *      - Allocate the buffer descriptor based on payalod and header size
725  *      - Initialize the SA pktInfo structure
726  *      - Perform all the protocol-specific operations specified in the connection
727  *        UDP: Update UDP length and calculate UDP checksum
728  *        SRTP: Update sequence number, prepare and call salldSendData()
729  *        IP: Update IP length, calculate IP checksum
730  *        IPSEC: Prepare and call salldSendData()    
731  *      - Fill the swInfo words
732  *      - Prepare and fill the PS Info words with a set of the PA/SA commands 
733  *        per connection 
734  * 
735  * Note: We do not support non-security connection at this moment
736  *
737  ******************************************************************************/
738 void sauRelayDmPkt(int connIndex, CSL_UdmapCppi5HMPD* hd)
739 {  
740     sauConnHandle_t *pConnHdl = &testConnHandles[connIndex];
741     sauConnHandle_t *pPrevConnHdl = &testConnHandles[connIndex - 1];
742     sauHdrHandle_t *pHdrHdl, *pPrevHdrHdl;
743     Sa_PktInfo_t  pktInfo;
744     Sa_PayloadInfo_t *pPayloadInfo = &pktInfo.payloadInfo;
745     Sa_PktDesc_t* pPktDesc = &pktInfo.pktDesc;
746     Sa_CmdLabelInfo_t*  pCmdLbInfo = &pktInfo.cmdlb;
747     uintptr_t      cmdLblAddr;
748     #if SA_GEN_TEST_VECTOR_RX
749     static Bool   first[10] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
750     #endif
751     uint32_t      pktId, flowId;
752     uint32_t      pTsInfo, pSwInfo0, pSwInfo1, pSwInfo2;
753     /* Initialize the packet descriptor */
754     salld_sim_init_pktdesc(pPktDesc, 1);
755 #if defined (SOC_AM64X)
756     pPktDesc->size= CSL_udmapCppi5GetPktLen((void*) hd);
757 #else
758     pPktDesc->size = hd->bufInfo1 & 0x1FFFFF;
759 #endif
760     pPktDesc->segments[0] = (void *) (uintptr_t) (hd->bufPtr); 
761     pPktDesc->segUsedSizes[0] = pPktDesc->size;
762     pPktDesc->segAllocSizes[0] = hd->orgBufLen;
764     /* Call Post-Processing function to remove potential padding */
765     pPrevHdrHdl = pPrevConnHdl->pHdrHdl[0];
766     /*
767      * Note: need to record the payload info at the output of Sa_chanSendData in general use case
768      */
769     pktInfo.validBitMap = sa_PKT_INFO_VALID_PAYLOAD_INFO;
770     pPayloadInfo->encOffset = pPrevConnHdl->hdrLen;
771     pPayloadInfo->authOffset = 0;
772     pPayloadInfo->encSize  = pPktDesc->size - pPayloadInfo->encOffset;
773     pPayloadInfo->authSize = pPktDesc->size;
774     
775     Sa_chanReceiveData(pPrevHdrHdl->u.data.pChan->salldInst, &pktInfo);
776     
777     /* Clear PS Info section */
778     CSL_udmapCppi5SetPsDataLen((void *)hd,  0);
779     
780     /* We only support one-layer at this moment */
781     if ( pConnHdl->numHandles != 1)
782     {
783         salld_sim_print("sauRelayDmPkt: too many handles %d \n", pConnHdl->numHandles);
784         return;
785     }
786     
787     pHdrHdl = pConnHdl->pHdrHdl[0];
788     
789     sauFormatDmPkt(pConnHdl, pHdrHdl, &pktInfo, pPktDesc, pPktDesc->size - pConnHdl->hdrLen);
791     /* Update EPIB information */
792     CSL_udmapCppi5SetEpiDataPresent((void*) hd, EPI_PRESENT);
793     CSL_udmapCppi5RdEpiData((void *) hd, &pTsInfo, &pSwInfo0, &pSwInfo1, &pSwInfo2);
794     /* UPdate swInfo */
795     pSwInfo0 = pktInfo.swInfo.swInfo[0];
796     pSwInfo1 = pktInfo.swInfo.swInfo[1];
797     pSwInfo2 = pktInfo.swInfo.swInfo[2];
798     CSL_udmapCppi5WrEpiData((void *) hd, pTsInfo, pSwInfo0, pSwInfo1, pSwInfo2);
799     
800     /* Prepare to send pkt to PA/SA */
801     CSL_udmapCppi5SetBufferAddr((CSL_UdmapCppi5HMPD*) hd, (uint64_t) Osal_VirtToPhys(pPktDesc->segments[0]));
802     CSL_udmapCppi5SetBufferLen ((CSL_UdmapCppi5HMPD*) hd, pPktDesc->size);
803     CSL_udmapCppi5SetPktLen((void *) hd, SA2UL_TEST_CPPI5_DESCRIPTOR_TYPE_HOST, pPktDesc->size);
805     /* overwrite the flow id */
806     CSL_udmapCppi5GetIds((void*) hd, &pktId, &flowId);
807     /* Clear PS flags and any error */
808     hd->pktInfo1 = 0;
809     /* Clear any next descriptor pointer */
810     hd->nextDescPtr = 0;
811     flowId = tFramework.tfFlowNum;
812     CSL_udmapCppi5SetIds((void*) hd, SA2UL_TEST_CPPI5_DESCRIPTOR_TYPE_HOST, pktId, flowId);
814     /* Attach the command label in PS data */
815     CSL_udmapCppi5SetPsDataLoc((void *) hd, CSL_UDMAP_CPPI5_PD_DESCINFO_PSINFO_VAL_IN_DESC);
816     cmdLblAddr = CSL_udmapCppi5GetPsDataAddr((void*) hd, 0, EPI_PRESENT);
817     memcpy ((void *) cmdLblAddr, pCmdLbInfo->cmdLbBuf, pCmdLbInfo->cmdLbSize);
818     CSL_udmapCppi5SetPsDataLen((void *) hd, pCmdLbInfo->cmdLbSize);
821     #if SA_GEN_TEST_VECTOR_RX
822     if(first[connIndex])
823     {
824         utilOutputScFromSwInfo(&tFramework, pktInfo.swInfo.swInfo);
825         first[connIndex] = FALSE;
826     }
827     
828     utilOutputPkt(&tFramework, pktInfo.swInfo.swInfo, pCmdLbInfo->cmdLbSize, (uint32_t *)pCmdLbInfo->cmdLbBuf,
829                    pPktDesc->size, (uint8_t*) pPktDesc->segments[0], TRUE);
830     #endif
831     
832     
835 /*******************************************************************************
836  *  Function: Verify the decrypted payload data in Data Mode
837  *******************************************************************************
838  *  DESCRIPTION:  This function verifies the decrypted payload data in Data Mode
839  *
840  ******************************************************************************/
841 void sauVerifyDmPkt(int connIndex, CSL_UdmapCppi5HMPD* hd)
842 {  
843     
844     int dataLen, i;
845     uint32_t rcvConnId;
846     uint8_t  *pData;
847     sauConnHandle_t *pConnHdl = &testConnHandles[connIndex];
848     
849     /* Verify payload */
850     #if !SA_GEN_TEST_VECTOR_TX
851     testDispPkts(hd);
852     #endif
853     
854     salld_sim_disp_control(TRUE);    
855     
856     /* Verify the decoded packet */
857 #if defined (BUILD_MCU1_0) || defined (_TMS320C6X)
858     rcvConnId = pktRead32bits_m((uint8_t *)(uint32_t)hd->bufPtr, pConnHdl->hdrLen);
859 #else
860     rcvConnId = pktRead32bits_m((uint8_t *)hd->bufPtr, pConnHdl->hdrLen);
861 #endif
862     if (rcvConnId != connIndex)
863     {
864         salld_sim_print("Receive Pkt of connection %d from PA/SA with incorrect connId = %d\n", connIndex, rcvConnId); 
865     }
866     
867 #if defined (BUILD_MCU1_0) || defined (_TMS320C6X)
868     pData = (uint8_t *)(uint32_t)hd->bufPtr + pConnHdl->hdrLen + 4;
869 #else
870     pData = (uint8_t *)hd->bufPtr + pConnHdl->hdrLen + 4;
871 #endif
872     /* For CBC mode, the last partial block will be incorrect */
873     /* dataLen = CSL_cppi5GetBufLen(CSL_CPPI5_DESCRIPTOR_TYPE_HOST, (uintptr_t *)&hd) - pConnHdl->hdrLen - 4 - 1 - 15; */
874 #if defined (SOC_AM64X)
875     dataLen    = CSL_udmapCppi5GetPktLen((void *) hd);
876 #else
877     dataLen    = CSL_udmapCppi5GetBufferLen((CSL_UdmapCppi5HMPD*) hd);
878 #endif
879     dataLen   -= (pConnHdl->hdrLen + 4 + 1 + 15);
880     
881     for ( i = 0; i < dataLen; i++)
882     {
883         if ((uint8_t)(pData[i + 1] - pData[i]) != 1)
884         {
885             salld_sim_print("Receive Pkt of connection %d from PA/SA with incorrect data at location %d, data = 0x%02x\n", 
886                             connIndex, pConnHdl->hdrLen + 4 + i, pData[i]);
887             break;
888         } 
889     }
890     
891     salld_sim_disp_control(FALSE);    
892     
893     /* free buffer */
894     testCommonRecycleLBDesc (&tFramework, hd); /* No Error Check here */
897 volatile uint32_t bookKeepTxCount = 0;
898 void sauBookKeepTx(void)
900   FW_CPPI_DESC_T *pCppiDesc;
902   bookKeepTxCount++;
904   /* return queue processing begin */
905   do
906   {
907       /* Need to free up the FW_PKT_DESC_T back to the application */
909       /* Go through the TX Return queue which is where the descriptor is re-cycled after it is transmitted on the wire
910           get the buffer which is this case is a FW_PKT_DESC_T and return it to the application/stack */
911       RingPop(tFramework.gTxComplRingHandle, &pCppiDesc);
913       if (pCppiDesc)  {
914         
915           /* clear source and dst tags */
916           CSL_udmapCppi5SetSrcTag(&pCppiDesc->hostDesc, 0);
917           CSL_udmapCppi5SetDstTag(&pCppiDesc->hostDesc, 0);
918 #if defined (ACP_COHERENCY)
919           pCppiDesc->hostDesc.nextDescPtr = CSL_pktdmaClrAselInAddr(pCppiDesc->hostDesc.nextDescPtr);
920           /* update the buffer for asel bits*/
921           pCppiDesc->hostDesc.bufPtr  = CSL_pktdmaClrAselInAddr ((uint64_t) pCppiDesc->hostDesc.bufPtr);
922 #endif
924          pCppiDesc->nextPtr = (uint64_t) (uintptr_t) tFramework.txReadyDescs;
925          tFramework.txReadyDescs = pCppiDesc;
926       }
927   } while (pCppiDesc != NULL);
928   /* return queue processing end */
931 volatile uint32_t bookKeepRxCount = 0;
932 void sauBookKeepRx(void)
934   FW_CPPI_DESC_T     *pCppiDesc;
935   CSL_UdmapCppi5HMPD *hd;
937   bookKeepRxCount++;
939   /* return queue processing begin */
940   do
941   {
942       /* Need to free up the FW_PKT_DESC_T back to the application */
943       pCppiDesc = (FW_CPPI_DESC_T *) NULL;
944       hd        = (CSL_UdmapCppi5HMPD *) NULL;
946       /* Go through the TX Return queue which is where the descriptor is re-cycled after it is transmitted on the wire
947           get the buffer which is this case is a FW_PKT_DESC_T and return it to the application/stack */
948       RingPop(tFramework.gTxComplRingHandle, &pCppiDesc);
950       /* push to receive fdq */
951       if (pCppiDesc != (FW_CPPI_DESC_T *) NULL)
952       {
953           hd  = &pCppiDesc->hostDesc;
954 #if defined (ACP_COHERENCY)
955          /* Clear ASEL tagging */
956           hd->nextDescPtr = CSL_pktdmaClrAselInAddr(hd->nextDescPtr);
957           hd->bufPtr      = CSL_pktdmaClrAselInAddr(hd->bufPtr);
958 #endif
960 #if defined (SOC_AM64X)
961      /* There is no default return policy field for AM64x */
962 #else
963           /* update back to original return queue for Rx */
964           CSL_udmapCppi5SetReturnPolicy( hd,
965                                          CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST,
966                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPOLICY_VAL_ENTIRE_PKT,
967                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_EARLYRET_VAL_NO,
968                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPUSHPOLICY_VAL_TO_TAIL,
969                                          tFramework.rxFreeRingNum);
970 #endif
971           /* clear source and dst tags */
972           CSL_udmapCppi5SetSrcTag(hd, 0);
973           CSL_udmapCppi5SetDstTag(hd, 0);
975           hd  = (CSL_UdmapCppi5HMPD * )Osal_PhysToVirt (hd);
976           
977       }
978     /* Push descriptor to Rx free descriptor queue */
979     if (hd != NULL) {
980       CSL_udmapCppi5SetBufferLen((CSL_UdmapCppi5HMPD *) hd, TF_DESC_BUFSIZE);
981       RingPush (tFramework.gRxFreeRingHandle, TF_DESC_BUFSIZE, (physptr_t)hd);
982     }
984   } while (hd != NULL);
987     /* return queue processing begin */
988   do
989   {
990       /* Need to free up the FW_PKT_DESC_T back to the application */
991       pCppiDesc = (FW_CPPI_DESC_T *) NULL;
992       hd        = (CSL_UdmapCppi5HMPD *) NULL;
994       /* Go through the RX Return queue which is where the descriptor is re-cycled after it is transmitted on the wire
995           get the buffer which is this case is a FW_PKT_DESC_T and return it to the application/stack */
996       RingPop(tFramework.gRxRingHandle, &pCppiDesc);
998       /* push to receive fdq */
999       if (pCppiDesc != (FW_CPPI_DESC_T *) NULL)
1000       {
1001           hd  = &pCppiDesc->hostDesc;
1002 #if defined (ACP_COHERENCY)
1003           /* Clear ASEL tagging */
1004           hd->nextDescPtr = CSL_pktdmaClrAselInAddr(hd->nextDescPtr);
1005           hd->bufPtr      = CSL_pktdmaClrAselInAddr(hd->bufPtr);
1006 #endif
1008 #if defined (SOC_AM64X)
1009 #else
1010           /* update back to original return queue for Rx */
1011           CSL_udmapCppi5SetReturnPolicy( hd,
1012                                          CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST,
1013                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPOLICY_VAL_ENTIRE_PKT,
1014                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_EARLYRET_VAL_NO,
1015                                          CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPUSHPOLICY_VAL_TO_TAIL,
1016                                          tFramework.rxFreeRingNum);
1017 #endif
1018           /* clear source and dst tags */
1019           CSL_udmapCppi5SetSrcTag(hd, 0);
1020           CSL_udmapCppi5SetDstTag(hd, 0);
1022           hd  = (CSL_UdmapCppi5HMPD * )Osal_PhysToVirt (hd);
1023       }
1024     /* Push descriptor to Rx free descriptor queue */
1025     if (hd != NULL) {
1026       CSL_udmapCppi5SetBufferLen((CSL_UdmapCppi5HMPD *) hd, TF_DESC_BUFSIZE);
1027       RingPush (tFramework.gRxFreeRingHandle, TF_DESC_BUFSIZE, (physptr_t)hd);
1028     }
1030   } while (hd != NULL);
1031   /* return queue processing end */
1034 void sauCheckDesc(CSL_UdmapCppi5HMPD *hd, uint32_t connIndex, uint32_t pktNum, uint32_t lineNum)
1036   uint32_t pktlen, bufflen;
1038   pktlen  = CSL_udmapCppi5GetPktLen((void*) hd);
1039   bufflen = CSL_udmapCppi5GetBufferLen(hd);
1041   if (pktlen != bufflen)
1042   {
1043       SALog("from Line num: %d Conn %d(Pkt %d) (pktLen %d) (buffLen %d): pktlen does not match bufflen!\n", \
1044              lineNum, connIndex, pktNum, pktlen, bufflen); 
1045       System_flush();
1046   }
1050 /*******************************************************************************
1051  *  Function: Connection Verification
1052  *******************************************************************************
1053  *  DESCRIPTION:  This function performs multi-connection multi-packet verification
1054  *      as specified below:
1055  *
1056  *   - For each pkt loop
1057  *     - Generate payload with specific data pattern and variable length
1058  *     - For each pair of connections
1059  *       - Format the raw packet with the connection header and payload
1060  *       - Perform the following protocol-specific operations 
1061  *         - Invoke salld_sendData() API for Data Mode channel
1062  *       - Prepare and send packet to SA for Encryption (and Authentication)
1063  *       - Receive encrypted packet from SA sub-system
1064  *       - Perform the following protocol-specific operations
1065  *          - Invoke salld_sendData() API for the corresponding Data Mode channel
1066  *       - Forward the packet to SA for Decryption (and Authentication) 
1067  *       - Preceive the decrypted packet from the SA sub-system
1068  *       - Perform payload verification              
1069  *   - End of the test loop
1070  *
1071  ******************************************************************************/
1072 void sauConnDmPktTest(tFramework_t *tf, saTest_t *pat, uint16_t numPkts,
1073                       uint16_t initLen, uint16_t step, sauPayloadType_e payloadType)
1076     CSL_UdmapCppi5HMPD *hd;
1077     Int       pktNum, connIndex;
1078     uint16_t  payloadLen;
1079     uint32_t  infoLen, pktLen, infoLen1;
1080     uint32_t  authTag[8];
1081     uint32_t  psFlags;
1082     uintptr_t psDataAddr;
1083     Int       i;
1086     /* Packet Tests */
1087     for (pktNum = 0; pktNum < numPkts; pktNum++)
1088     {
1089         payloadLen = initLen + pktNum * step;
1090         sauGenPayload(payloadType, 0,  payloadLen, sap_pkt_test_buf);
1091         
1092         /* 
1093          * We should perform encryption/authentication verification for
1094          * a pair of connection
1095          *
1096          */
1097         for (connIndex = 0; connIndex < numConnHandles; connIndex += 2)
1098         {
1099             hd = sauGenDmPkt(tf, connIndex, payloadLen, sap_pkt_test_buf);
1100             if (hd == NULL)
1101             {
1102                 saTestRecoverAndExit (tf, pat, SA_TEST_FAILED);  /* no return */
1103             }
1105             gRxPktCntInRing = 0;
1106             pktLen = CSL_udmapCppi5GetPktLen((void *) hd);
1107             RingPush(tFramework.gTxRingHandle, pktLen, (physptr_t) hd);
1109               /* The packet should loop back into queue TF_RING_RXQ */    
1110             for (i = 0; i < 2000; i++)  {
1111                 utilCycleDelay (1000);
1112                 if (gRxPktCntInRing != 0)
1113                     break;
1114             }
1116             if (i >= 2000)  {
1117                 SALog ("%s (%s:%d): Did not find SA reply in rx ring %d \n", pat->name, __FILE__, __LINE__, tFramework.rxComplRingNum);
1118                 System_flush();
1119                 salld_sim_halt();
1120                 saTestRecoverAndExit (tf, pat, SA_TEST_FAILED);  /* no return */
1121             }
1123             /* Book Keep the Tx */
1124             sauBookKeepTx();
1126             /* This descriptor has a buffer owned by the framework, so the common code can be used for recycle */
1127             if (gRxPktCntInRing != 0) 
1128             {
1129                 FW_CPPI_DESC_T *pAppDesc;
1130                 pAppDesc = (FW_CPPI_DESC_T *) NULL;
1131                 hd = (CSL_UdmapCppi5HMPD *)(NULL);
1132                 RingPop(tFramework.gRxRingHandle, &pAppDesc);
1133                 if (pAppDesc != (FW_CPPI_DESC_T *) NULL)
1134                 {
1135                     hd = &pAppDesc->hostDesc;
1136                 }
1137                 else
1138                 {
1139                    SALog(" The null descriptor in the ring, unexpected behavior \n");
1140                    System_flush();
1141                    salld_sim_halt();
1142                 }
1144                 /* Check if the descriptor has some errors, if yes - halt the test for inspection */
1145                 psFlags = CSL_udmapCppi5GetPsFlags(hd);
1147                 if (psFlags)
1148                 {
1149                    SALog(" The SA2UL returned error code = %d \n", psFlags);
1150                    System_flush();
1151                    salld_sim_halt();
1152                 }
1153                 
1154                 /* Extract PS Info if exists */
1155                 psDataAddr = CSL_udmapCppi5GetPsDataAddr((void*) hd, 0, 1);
1156                 infoLen    = CSL_udmapCppi5GetPsDataLen((void *) hd);
1158                 /* Copy Auth tag if any */
1159                 if (infoLen != 0) {
1160                   memcpy(authTag, (void *) psDataAddr, infoLen);
1161                 }
1163 #if defined (DMA_TYPE_LCDMA)
1164 #else
1165                 sauCheckDesc(hd, connIndex, pktNum, __LINE__);
1166 #endif
1167                 salld_sim_print("Conn %d: Receive Data Mode Pkt %d from SA\n", connIndex, pktNum); 
1168                 #if !SA_GEN_TEST_VECTOR_RX
1169                 testDispPkts(hd);
1170                 #endif
1172                 /* Relay the packet to sa2ul */
1173                 sauRelayDmPkt(connIndex+1, hd);
1174                 /* Set the interrupt flag to false to indicate it is processed now */
1175                 gRxPktCntInRing = 0;
1176 #if defined (ACP_COHERENCY)
1177                 hd->nextDescPtr = CSL_pktdmaMakeAselAddr((uint64_t) 0ULL, \
1178                                     CSL_LCDMA_RINGACC_ASEL_ENDPOINT_ACP_WR_ALLOC);
1179                 hd->bufPtr      = CSL_pktdmaMakeAselAddr(hd->bufPtr, \
1180                                     CSL_LCDMA_RINGACC_ASEL_ENDPOINT_ACP_WR_ALLOC);
1181 #endif
1183 #if defined (SOC_AM64X)
1184 #else
1185                 /* Update the return ring for the descriptor to be Tx Complete
1186                    this gets set back during rx recycle
1187                  */
1188                 CSL_udmapCppi5SetReturnPolicy( hd,
1189                                                CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST,
1190                                                CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPOLICY_VAL_ENTIRE_PKT,
1191                                                CSL_UDMAP_CPPI5_PD_PKTINFO2_EARLYRET_VAL_NO,
1192                                                CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPUSHPOLICY_VAL_TO_TAIL,
1193                                                tFramework.txComplRingNum);
1194 #endif
1195                 pktLen = CSL_udmapCppi5GetPktLen((void *) hd);
1196                 RingPush(tFramework.gTxRingHandle, pktLen, (physptr_t) hd);
1197             }
1199               /* The packet should loop back into queue DEST_QUEUE_PKT_TX */    
1200             for (i = 0; i < 2000; i++)  {
1201                 utilCycleDelay (1000);
1202                 if (gRxPktCntInRing != 0)
1203                     break;
1204             }
1206             if (i >= 2000)  {
1207                 salld_sim_halt();
1208                 SALog ("%s (%s:%d): Did not find SA reply in rx ring  %d \n", pat->name, __FILE__, __LINE__, tFramework.rxComplRingNum);
1209                  saTestRecoverAndExit (tf, pat, SA_TEST_FAILED);  /* no return */
1210             }
1212             /* This descriptor has a buffer owned by the framework, so the common code can be used for recycle */
1213             if (gRxPktCntInRing != 0)
1214             {
1216                 FW_CPPI_DESC_T *pAppDesc;
1217                 pAppDesc = (FW_CPPI_DESC_T *) NULL;
1218                 hd = (CSL_UdmapCppi5HMPD *)(NULL);
1219                 RingPop(tFramework.gRxRingHandle, &pAppDesc);
1220                 if (pAppDesc != (FW_CPPI_DESC_T *) NULL)
1221                 {
1222                     hd = &pAppDesc->hostDesc;
1223                 }
1225                 /* Indicate the Rx pkt is serviced now */
1226                 gRxPktCntInRing = 0;
1228                 /* Check if the descriptor has some errors, if yes - halt the test for inspection */
1229                 psFlags = CSL_udmapCppi5GetPsFlags(hd);
1231                 if (psFlags)
1232                 {
1233                    SALog(" The SA2UL returned error code = %d \n", psFlags);
1234                    System_flush();
1235                    salld_sim_halt();
1236                 }
1237 #if defined (DMA_TYPE_LCDMA)
1238 #else
1239                 sauCheckDesc(hd, connIndex+1, pktNum, __LINE__);
1240 #endif
1241                 salld_sim_print("Conn %d: Receive Data Mode Pkt %d from SA\n", connIndex+1, pktNum); 
1242                 /* Extract PS Info if exists */
1243                 psDataAddr = CSL_udmapCppi5GetPsDataAddr((void*) hd, 0, 1);
1244                 infoLen1    = CSL_udmapCppi5GetPsDataLen((void *) hd);
1245                 if ((infoLen) || (infoLen1))
1246                 {
1247                     if(memcmp((void*) psDataAddr, authTag, infoLen))
1248                     {
1249                         SALog("Conn %d(Pkt %d): authentication tag does not match!\n", connIndex+1, pktNum);
1250                         System_flush();
1251                      }
1252                 }
1253                 
1254                 sauVerifyDmPkt(connIndex, hd);
1256                 /* Book keep the Rx */
1257                 sauBookKeepRx();
1258             }
1260         } /* Connection Loop */
1262     } /* Packet Loop */
1266 extern volatile sauTest_tputData_t gSauTputData[SAU_TPUT_NUM_PKTSIZES][SAU_TPUT_MAX_PROFILE_CHANNELS];
1268 #define SAU_TPUT_TEST_DESC_DUMP 0
1270 #if SAU_TPUT_TEST_DESC_DUMP
1271 volatile CSL_UdmapCppi5HMPD    gSauDescEncDumpMem[SAU_TPUT_NUM_PKTSIZES * SAU_TPUT_MAX_PROFILE_CHANNELS * SAU_TPUT_PKTBATCH_CNT];
1272 volatile uint32_t    gSauDescDumpEncIndex;
1273 volatile CSL_UdmapCppi5HMPD    gSauDescDecDumpMem[SAU_TPUT_NUM_PKTSIZES * SAU_TPUT_MAX_PROFILE_CHANNELS * SAU_TPUT_PKTBATCH_CNT];
1274 volatile uint32_t    gSauDescDumpDecIndex;
1275 #endif
1277 /*******************************************************************************
1278  *  Function: Througput Test Data collection and Verification
1279  *******************************************************************************
1280  *  DESCRIPTION:  This function performs throughput packet test/verification
1281  *      as specified below:
1282  *
1283  *   - For each pkt loop
1284  *     - Generate payload with specific data pattern and variable length
1285  *     - For each pair of connections
1286  *       - Format the raw packet with the connection header and payload
1287  *       - Perform the following protocol-specific operations
1288  *         - Invoke salld_sendData() API for Data Mode channel
1289  *       - Prepare and send packet to SA for Encryption (and Authentication)
1290  *       - Receive encrypted packet from SA sub-system
1291  *       - Perform the following protocol-specific operations
1292  *          - Invoke salld_sendData() API for the corresponding Data Mode channel
1293  *       - Forward the packet to SA for Decryption (and Authentication)
1294  *       - Preceive the decrypted packet from the SA sub-system
1295  *       - Perform payload verification
1296  *   - End of the test loop
1297  *
1298  ******************************************************************************/
1299 void sauConnTputDmPktTest(tFramework_t *tf, saTest_t *pat, uint16_t numPkts)
1301     CSL_UdmapCppi5HMPD *hd[SAU_TPUT_PKTBATCH_CNT+1];
1302     Int       connIndex, maxBatch;
1303 #if   SAU_TPUT_TEST_DESC_DUMP
1304     uint32_t  descType;
1305 #else
1306     Int       encFirstTime, decFirstTime;
1307     volatile uint64_t  encGtcCumSumVal = 0, decGtcCumSumVal = 0;
1308     volatile uint64_t  gtcTxStart, gtcTxEnd;
1309     volatile uint64_t  gtcRxStart, gtcRxEnd, overhead;
1310 #endif
1311     uint16_t  pktNum,  nPkts, payloadLen;
1312     uint32_t  infoLen, numPktsRx, pLen;
1313     uint32_t  authTag[SAU_TPUT_PKTBATCH_CNT][8];
1314     uintptr_t psDataAddr;
1315     Int       i;
1316     Int       pIdx;
1317     Int       pktLen[SAU_TPUT_NUM_PKTSIZES] = { 64, 512, 1024, 2048 };
1318     uint32_t  psFlags;
1320     /* Initialize the cycle counter */
1321     sau_cycle_cnt_init();
1322     gtcTxStart = sau_read_cycle_cnt();
1323     gtcTxEnd = sau_read_cycle_cnt();
1324     overhead = gtcTxEnd - gtcTxStart;
1325     gtcTxStart = sau_read_cycle_cnt();
1326     /* 32 cycle NOP instructions, which can be used to compute the overhead */
1327     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1328     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1329     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1330     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1331     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1332     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1333     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1334     asm (" NOP ");     asm (" NOP ");    asm (" NOP ");    asm (" NOP ");
1336     gtcTxEnd = sau_read_cycle_cnt();
1337     /* Total cycle should be 32 cycles + overhead */
1338     encGtcCumSumVal = gtcTxEnd - gtcTxStart - overhead;
1340 #if defined(BUILD_MCU)
1341     SALog("Captured cycle is = 0x%" PRIx64 " \n", encGtcCumSumVal);
1342     SALog("overhead cycle is = 0x%" PRIx64 " \n", overhead);
1343 #else
1344     SALog("Captured cycle is = 0x%" PRIx64 " \n", encGtcCumSumVal);
1345     SALog("overhead cycle is = 0x%" PRIx64 " \n", overhead);
1346 #endif
1349 #if SAU_TPUT_TEST_DESC_DUMP
1350     gSauDescDumpEncIndex =  gSauDescDumpDecIndex = 0;
1351 #endif
1353     numPkts = SAU_TPUT_PKTBATCH_CNT;
1355     SALog("Running the SA Throughput Test to collect data ... (Please don't halt)");
1357     for (pIdx=0; pIdx < SAU_TPUT_NUM_PKTSIZES; pIdx++)
1358     {
1359         SALog("\n    For Packet Size %d: \n       Ch IDs: ", pktLen[pIdx]);
1360         for (connIndex = 0; connIndex < numConnHandles; connIndex += 2)
1361         {
1362             payloadLen = pktLen[pIdx];
1363             SALog ("%d  ", connIndex);
1365             nPkts = numPkts;
1366             /* Generate the payload for sa2ul */
1367             sauGenPayload(SAU_PAYLOAD_INC8, 0,  payloadLen, sap_pkt_test_buf);
1369 #if   SAU_TPUT_TEST_DESC_DUMP
1370 #else
1371             gSauTputData[pIdx][connIndex].connId    = connIndex;
1372             gSauTputData[pIdx][connIndex].pktLen    = pktLen[pIdx];
1373             gSauTputData[pIdx][connIndex].numPkts   = numPkts;
1375             encFirstTime = TRUE;
1376             decFirstTime = TRUE;
1377 #endif
1379             pktNum = 0;
1380             while(pktNum < nPkts)
1381             {
1382                 if (nPkts >= SAU_TPUT_PKTBATCH_CNT)
1383                 {
1384                     maxBatch = SAU_TPUT_PKTBATCH_CNT;
1385                 }
1386                 else
1387                 {
1388                     maxBatch = nPkts;
1389                 }
1391                 /* Pause the Tx UDMAP channel to prevent sa2ul to consume it */
1392                 salld_test_controlTxDma(SA2UL_UDMAP_TX_PAUSE);
1394                 /* Push in one shot to encrypt the packets */
1395                 gRxPktCntInRing = 0;
1396                 for (i = 0; i < maxBatch; i++)
1397                 {
1398                     hd[i] = sauGenDmPkt(tf, connIndex, payloadLen, sap_pkt_test_buf);
1399                     if (hd[i] == NULL)
1400                     {
1401                         saTestRecoverAndExit (tf, pat, SA_TEST_FAILED);  /* no return */
1402                     }
1404 #if   SAU_TPUT_TEST_DESC_DUMP
1405                     /* Check if the descriptor is valid host desc */
1406                     descType = CSL_udmapCppi5GetDescType((void *)hd[i]);
1407                     if (descType != CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST)
1408                     {
1409                         salld_sim_halt();
1410                     }
1411                     memcpy((void *)&gSauDescEncDumpMem[gSauDescDumpEncIndex++], (void *) hd[i], sizeof(CSL_UdmapCppi5HMPD));
1412 #endif
1413                     pLen = CSL_udmapCppi5GetPktLen((void *) hd[i]);
1415                     /* Benchmarking Ring Push API */
1416                     if (i == 0)
1417                     {
1418                         gtcTxStart = sau_read_cycle_cnt();
1419                     }
1420                     RingPush(tFramework.gTxRingHandle, pLen, (physptr_t) hd[i]);
1421                     if (i == 0)
1422                     {
1423                         gtcTxEnd = sau_read_cycle_cnt();
1424                         gSauTputData[pIdx][connIndex].ringPushCycles = gtcTxEnd - gtcTxStart - overhead;
1425                     }
1426                 }
1428                 /*Make sure there is no packet in the Rx ring before enable of TX DMA */
1429                 do
1430                 {
1431                     utilCycleDelay(1000);
1432                 } while (gRxPktCntInRing);
1434                 /* Now start the profile */
1435                 gtcTxStart = sau_read_cycle_cnt();
1436                 /* The packets should loop back into queue TF_RING_RXQ after the
1437                  * udma is enabled
1438                  */
1439                  salld_test_controlTxDma(SA2UL_UDMAP_TX_UNPAUSE);
1440 #if defined(SOC_AM64X)
1441                 /* This descriptor has a buffer owned by the framework, so the common code can be used for recycle */
1442                 do
1443                 {
1444                    numPktsRx =  CSL_lcdma_ringaccGetReverseRingOcc(&tFramework.gDrvHandle->lcdmaRaRegs, \
1445                                  tFramework.rxComplRingNum, CSL_LCDMA_RINGACC_RING_MODE_RX_RING);
1446                 } while (numPktsRx < maxBatch);
1447 #else
1448                 /* This descriptor has a buffer owned by the framework, so the common code can be used for recycle */
1449                 do
1450                 {
1451                    numPktsRx =  CSL_ringaccGetRingOcc(&tFramework.gDrvHandle->raRegs, tFramework.rxComplRingNum);
1452                 } while (numPktsRx < maxBatch);
1453 #endif
1455 #if   SAU_TPUT_TEST_DESC_DUMP
1456 #else
1457                 /* Stop the profile */
1458                 gtcTxEnd = sau_read_cycle_cnt();
1460                 /* Book keep */
1461                 sauBookKeepTx(); 
1462                 encGtcCumSumVal = gtcTxEnd - gtcTxStart - overhead;
1464                 /* Check */
1465                 if (numPktsRx > maxBatch)
1466                 {
1467                     /* The ring can not get more than pushed for sa2ul operations */
1468                     SALog("expected %d packets in the ring, got %d packets \n", maxBatch, numPktsRx);
1469                     salld_sim_halt();
1470                 }
1472                 /* Get the recived packets out of SA2UL */
1473                 for (i = 0; i < numPktsRx; i++)
1474                 {
1475                     FW_CPPI_DESC_T *pAppDesc;
1476                     pAppDesc = (FW_CPPI_DESC_T *) NULL;
1477                     hd[i] = (CSL_UdmapCppi5HMPD *)(NULL);
1478                                         /* Benchmarking Ring Push API */
1479                     if (i == 0)
1480                     {
1481                         gtcTxStart = sau_read_cycle_cnt();
1482                     }
1483                     RingPop(tFramework.gRxRingHandle, &pAppDesc);
1484                     if (i == 0)
1485                     {
1486                         gtcTxEnd = sau_read_cycle_cnt();
1487                         gSauTputData[pIdx][connIndex].ringPopCycles = gtcTxEnd - gtcTxStart - overhead;
1488                     }
1490                     if (pAppDesc != (FW_CPPI_DESC_T *) NULL)
1491                     {
1492                         hd[i] = &pAppDesc->hostDesc;
1493                     }
1494                     /* Check if the descriptor has some errors, if yes - halt the test for inspection */
1495                     psFlags = CSL_udmapCppi5GetPsFlags(hd[i]);
1497                     if (psFlags)
1498                     {
1499                        SALog(" The SA2UL returned error code = %d \n", psFlags);
1500                        System_flush();
1501                        salld_sim_halt();
1502                     }
1503                 }
1505                 gSauTputData[pIdx][connIndex].cycles = (uint32_t)encGtcCumSumVal;
1507                 /* Collect the first batch encryption cycles */
1508                 if (encFirstTime == TRUE)
1509                 {
1510                     encFirstTime = FALSE;
1511                 }
1513                 gSauTputData[pIdx][connIndex + 1].connId    = connIndex+1;
1514                 gSauTputData[pIdx][connIndex + 1].pktLen    = pktLen[pIdx];
1515                 gSauTputData[pIdx][connIndex + 1].numPkts   = numPkts;
1516 #endif
1518                 /* Pause the DMA channels after all packets are sent to SA2UL */
1519                 salld_test_controlTxDma(SA2UL_UDMAP_TX_PAUSE);
1521                 /* Relay the packet to Decrypt the received packets */
1522                 gRxPktCntInRing  = 0;
1523                 for (i = 0; i < maxBatch; i++)
1524                 {
1525                     psDataAddr = CSL_udmapCppi5GetPsDataAddr((void *) hd[i],false,true);
1526                     infoLen    = CSL_udmapCppi5GetPsDataLen((void*) hd[i]);
1527                     if (infoLen != 0)
1528                     {
1529                         memcpy(&authTag[i][0], (void *) psDataAddr, infoLen);
1530                     }
1532                     /* Relay the packet */
1533                     sauRelayDmPkt(connIndex + 1,hd[i]);
1534 #if   SAU_TPUT_TEST_DESC_DUMP
1535                     /* Check if the descriptor is valid host desc */
1536                     descType = CSL_udmapCppi5GetDescType((void *)hd[i]);
1537                     if (descType != CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST)
1538                     {
1539                         salld_sim_halt();
1540                     }
1541                     memcpy((void *)&gSauDescDecDumpMem[gSauDescDumpDecIndex++], (void *) hd[i], sizeof(CSL_UdmapCppi5HMPD));
1542 #endif
1543 #if defined (SOC_AM64X)
1544 #else
1545                     /* Update the return ring for the descriptor to be Tx Complete
1546                        this gets set back during rx recycle
1547                      */
1548                     CSL_udmapCppi5SetReturnPolicy( hd[i],
1549                                                    CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_HOST,
1550                                                    CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPOLICY_VAL_ENTIRE_PKT,
1551                                                    CSL_UDMAP_CPPI5_PD_PKTINFO2_EARLYRET_VAL_NO,
1552                                                    CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPUSHPOLICY_VAL_TO_TAIL,
1553                                                    tFramework.txComplRingNum);
1554 #endif
1555                     pLen = CSL_udmapCppi5GetPktLen((void *) hd[i]);
1557                     /* Benchmarking Ring Push API */
1558                     if (i == 0)
1559                     {
1560                         gtcTxStart = sau_read_cycle_cnt();
1561                     }
1562                     RingPush(tFramework.gTxRingHandle, pLen, (physptr_t) hd[i]);
1564                     if (i == 0)
1565                     {
1566                         gtcTxEnd = sau_read_cycle_cnt();
1567                         gSauTputData[pIdx][connIndex+1].ringPushCycles = gtcTxEnd - gtcTxStart - overhead;
1568                     }
1569                 }
1571                 /* Make sre there are no Rx Pkts before enable of TX DMA */
1572                 do
1573                 {
1574                     utilCycleDelay(1000);
1575                 } while (gRxPktCntInRing);
1577                 /* The packets should loop back into queue TF_RING_RXQ after the 
1578                  * udma is unpaused
1579                  */
1581 #if   SAU_TPUT_TEST_DESC_DUMP
1582 #else
1583                  numPktsRx = 0;
1584 #endif
1586                 /* Now start the profile */
1587                  gtcRxStart = sau_read_cycle_cnt();
1588                  salld_test_controlTxDma(SA2UL_UDMAP_TX_UNPAUSE);
1590 #if defined(SOC_AM64X)
1591                  while (numPktsRx < maxBatch)
1592                  {
1593                      numPktsRx =  CSL_lcdma_ringaccGetReverseRingOcc(&tFramework.gDrvHandle->lcdmaRaRegs, \
1594                                      tFramework.rxComplRingNum, CSL_LCDMA_RINGACC_RING_MODE_RX_RING);
1595                  }
1597 #else
1598                  while (numPktsRx < maxBatch)
1599                  {
1600                      numPktsRx =  CSL_ringaccGetRingOcc(&tFramework.gDrvHandle->raRegs, tFramework.rxComplRingNum);
1601                  }
1602 #endif
1604 #if   SAU_TPUT_TEST_DESC_DUMP
1605 #else
1606                  /* Stop the profile */
1607                  gtcRxEnd = sau_read_cycle_cnt();
1608                  decGtcCumSumVal = gtcRxEnd - gtcRxStart - overhead;
1610                  /* Pause the Tx UDMAP channel to prevent sa2ul to consume further packets */
1611                   salld_test_controlTxDma(SA2UL_UDMAP_TX_PAUSE); 
1613                  /* Check */
1614                  if (numPktsRx > maxBatch)
1615                  {
1616                      /* The ring can not get more than pushed for sa2ul operations */
1617                      SALog("expected %d packets in the ring, got %d packets \n", maxBatch, numPktsRx);
1618                      salld_sim_halt();
1619                  }
1620  
1621                  /* Get the recived packets out of SA2UL */
1622                  for (i = 0; i < numPktsRx; i++)
1623                  {
1624                      FW_CPPI_DESC_T *pAppDesc;
1625                      pAppDesc = (FW_CPPI_DESC_T *) NULL;
1626                      hd[i] = (CSL_UdmapCppi5HMPD *)(NULL);
1627                      /* Benchmarking Ring Pop API */
1628                      if (i == 0)
1629                      {
1630                          gtcTxStart = sau_read_cycle_cnt();
1631                      }
1632                      RingPop(tFramework.gRxRingHandle, &pAppDesc);
1633                      if (i == 0)
1634                      {
1635                          gtcTxEnd = sau_read_cycle_cnt();
1636                          gSauTputData[pIdx][connIndex+1].ringPopCycles = gtcTxEnd - gtcTxStart - overhead;
1637                      }
1639                      if (pAppDesc != (FW_CPPI_DESC_T *) NULL)
1640                      {
1641                          hd[i] = &pAppDesc->hostDesc;
1642                      }
1643                      /* Check if the descriptor has some errors, if yes - halt the test for inspection */
1644                      psFlags = CSL_udmapCppi5GetPsFlags(hd[i]);
1646                      if (psFlags)
1647                      {
1648                         SALog(" The SA2UL returned error code = %d \n", psFlags);
1649                         System_flush();
1650                         salld_sim_halt();
1651                      }
1653                  }
1654                 gSauTputData[pIdx][connIndex+1].cycles = (uint32_t)decGtcCumSumVal;
1656 #endif /* SAU_TPUT_TEST_DESC_DUMP */
1658                 /* Book keep */
1659                 sauBookKeepRx();
1661                 /* compare the functionality */
1662                 for (i = 0 ; i < maxBatch; i++)
1663                 {
1664                     psDataAddr = CSL_udmapCppi5GetPsDataAddr((void *) hd[i],false,true);
1665                     infoLen    = CSL_udmapCppi5GetPsDataLen((void*) hd[i]);
1666                     if (infoLen != 0)
1667                     {
1668                         if (memcmp((void*) psDataAddr, &authTag[i][0],infoLen))
1669                         {
1670                             SALog("Conn %d(Pkt %d): authentication tag does not match!\n", connIndex+1, pktNum + i);
1671                             System_flush();
1672                         }
1673                     }
1674 #if       SAU_TPUT_TEST_DESC_DUMP
1675                     /* for descriptor dump, don't verify data packets */
1676                     /* free buffer */
1677                     testCommonRecycleLBDesc (&tFramework, hd[i]); /* No Error Check here */
1678 #else
1679                     /* verify */
1680                     sauVerifyDmPkt(connIndex, hd[i]);
1681 #endif
1682                 }
1684 #if   SAU_TPUT_TEST_DESC_DUMP
1685 #else
1686                 /* Collect the first batch decryption cycles */
1687                 if (decFirstTime == TRUE)
1688                 {
1689                     decFirstTime = FALSE;
1690                 }
1691 #endif
1692                 /* Indicate maxBatch number of packets are processed */
1693                 pktNum += maxBatch;
1694             }
1695         }
1696     }
1698     SALog("\nDone ...\n");
1700     /* Re-enable the TX DMA back to always enable state */
1701     salld_test_controlTxDma(SA2UL_UDMAP_TX_UNPAUSE);
1704 /* Nothing past this point */