summaryrefslogtreecommitdiffstats
blob: c28d36e8aef8605edb5e52f4c40fd19ec4a320a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
/******************************************************************************
 * FILE PURPOSE:  Compile time Tunable parameters for NWAL Module
 ******************************************************************************
 * FILE NAME:   nwal_util.h
 *
 * DESCRIPTION: Static inline NWAL utility functions. Can be used in the
 *              case  of Applications using low NWL overhead mode and being
 *              able to get access to low level hardware TX and RX
 *
 * REVISION HISTORY:
 *
 *  Copyright (c) Texas Instruments Incorporated 2012
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/* ============================================================= */
/**
 *   @file  nwal_util.h
 *
 *   path  ti/drv/nwal/nwal_util.h
 *
 *   @brief     File contains low level utility function and inline
 *              macros to enable hardware offload for keystone
 *              devices.
 *              Static inline NWAL utility functions. Can be used in the
 *              case of Applications using low NWL overhead mode and being
 *              able  to get access to low level hardware TX and RX
 *
 */

/**
 *
 *  \par
 *  NOTE:
 *      (C) Copyright 2012 Texas Instruments, Inc.
 *  \par
 */


#ifndef _NWAL_UTIL_H
#define _NWAL_UTIL_H

#ifdef __cplusplus
extern "C" {
#endif
#include "ti/drv/nwal/nwal.h"
#include "ti/drv/nwal/src/nwal_loc.h"

extern nssGlobalConfigParams_t nssGblCfgParams;
/**************** DEFINES USED BY INLINE MACROS BEGIN ****************/
#if defined(DEVICE_K2E) || defined(K2L) || defined(SOC_K2E) || defined(SOC_K2L)
#define NWAL_PAFRM_ETH_PS_FLAGS_PORT_SHIFT  0
#else
#define NWAL_PAFRM_ETH_PS_FLAGS_PORT_SHIFT  4
#endif
#define NWAL_PA_L4_CHKSUM_ERR               0x4
#define NWAL_PA_IPV4_HDR_CHKSUM_ERR         0x8


/**
 *  @ingroup nwal_api_structures
 *  @brief Cookie updated by NWAL for the packet flow
 *
 *  @details The parameters in this structure will be updated by NWAL during
 *           API call @see nwal_initPsCmdInfo(). Application to pass it back
 *           in @see nwalTxPktInfo_t during @see nwal_send API call for packet
 *           transmission.
 */
#define NWAL_MAX_PS_COMMAND_SIZE       96
typedef struct {
    uint32_t        psCmdLabel[NWAL_MAX_PS_COMMAND_SIZE/4];
                                        /**<  Command Label to be sent to
                                          *   NetCP for the packet flow
                                          *   with list of actions
                                          */
    uint32_t        psCmdLabelLen;      /**< Length of valid command label in
                                          *  bytes
                                          */
    uint8_t         udpChkOff;          /**< Offset for UDP checksum command
                                          *  in the command label
                                          */
    uint8_t         pa2saNextRoute;     /**< Offset for next route information
                                          *  to update SA Context details
                                          */
    uint8_t         saShortInfoOff;     /**< Offset for SA Short Info command
                                          *  in the command label
                                          */
    uint8_t         enetPortNextRoute;  /**< Offset for next route information
                                          *  to update SA Context details
                                          */
    uint8_t         ahPathCmdOff;       /**< Offset for updating ICV bytes in
                                          *  case of IPSec AH crypto offload
                                          */
    Qmss_QueueHnd   txQueue;            /**< Transmit Queue */
}nwalTxPSCmdInfo_t;

#ifdef NWAL_ENABLE_SA
/**
 *  @ingroup nwal_api_structures
 *  @brief Cookie updated by NWAL for the Data Mode SA Channel
 *
 *  @details The parameters in this structure will be updated by NWAL during
 *           API call @see nwal_initDMPSCmdInfo(). Application to pass it back
 *           in  @see nwal_mCmdDMUpdate API call before packet
 *           transmission.
 */
typedef struct {
    Sa_CmdLbUpdateInfo_t*   pUpdateInfo;
    uint32_t*               pCmdLb;/**<  Command Label to be sent to
                                   *   NetCP for the packet flow
                                   *   with list of actions
                                   */
    uint16_t               cmdLbLen;/**< Length of command Label */
    uint32_t*              pSwInfo; /**< Security Context info for the channel */
    Qmss_QueueHnd          rxSbSaQ;  /**< Default  Packet Queue to receive response
                                      * for all data mode SA related
                                      * responses
                                      */
    int16_t                rxPktFlowId; /**< Default Flow Handle for packets
                                           *  from NetCP to host
                                           */
    Qmss_QueueHnd          txQueue; /**< Transmit Queue */
}nwalTxDmPSCmdInfo_t;
#endif
/******************** DEFINES USED BY INLINE MACROS END ********************/

/**************** Low Level API Functions exposed by NWAL BEGIN ***************/
/**
 *  @ingroup nwal_api_functions
 *  @brief nwal_initPsCmdInfo  API for Initializing PS Command Info
 *
 *  @details The API can be called by application to initialize NetCP protocol
 *           specific command for any hardware offload functionality.
 *           The API should be called for similar packet format with protocol
 *           headers at fixed offsets. For transmitting packets out the helper
 *           functions included in nwal_util.h can be used.
 *
 *           The API call is not required for the application using
 *  @param[in]  nwalInst    NWAL Instance  identifier
 *  @param[in]  pPktInfo        Transmit packet information @see nwalTxPktInfo_t
 *  @param[in]  pTxPSCmdInfo    Protocol Specific command info initialized with
 *                              static values  during init.Dynamic field update
 *                              will be done during API call nwal_sendxxx
 *
 *  @retval      @see nwal_OK  on success. Error codes @see nwal_RetValue
 *  @pre         @see nwal_start
 */
nwal_RetValue nwal_initPSCmdInfo  (nwal_Inst            nwalInst,
                                   nwalTxPktInfo_t*     pPktInfo,
                                   nwalTxPSCmdInfo_t*   pTxPSCmdInfo);

#ifdef NWAL_ENABLE_SA
/**
 *  @ingroup nwal_api_functions
 *  @brief nwal_getDmCmdLb  Get the Data Mode Command Label created during
 *         channel create time
 *
 *  @details API returns static PS command label infrastructure created
 *           during nwal_setDMSecAssoc().
 *  @param[in]  nwalInst    NWAL Instance  identifier
 *  @param[in]  nwalDmSaHandle        Handle returned after
 *                                    @see nwal_setDMSecAssoc
 *  @param[in]  pTxDmPsCmdInfo       Command label Meta Data for Crypto SB Send
 *  @pre        @see nwal_setDMSecAssoc
 */
nwal_RetValue nwal_initDMPSCmdInfo(nwal_Inst              nwalInst,
                                   nwal_Handle            nwalDmSaHandle,
                                   nwalTxDmPSCmdInfo_t*   pTxDmPsCmdInfo);
#endif

/** @defgroup nwal_fastMacros NWAL Low Level APIs
 *  @{
 */
/** @} */

/** @defgroup nwal_fast_send_macros NWAL Transmit Low Level Helper API's
 *  @ingroup nwal_fastMacros
 */

/** @defgroup nwal_recv_macros NWAL Receive Low Level Helper API's
 *  @ingroup nwal_fastMacros
 */


/*********************** NWAL FAST SEND HELPER MACROS BEGIN ******************/

/********************************************************************
 * FUNCTION PURPOSE: Update the Enet Port in Next Route for PS command
 *                   to NetCP
 ********************************************************************
 * DESCRIPTION: Update the Enet Port in Next Route for PS command
 *              to NetCP
 ********************************************************************/
static inline void nwal_modNREnetPort(uint8_t*             pPsDataBuf,
                                      uint8_t              portNROffset,
                                      nwal_enetPort_t      enetPort)
{
    pasahoNextRoute_t*  nr;
    uint8_t             psFlags =0;

    nr = (pasahoNextRoute_t*)&pPsDataBuf[portNROffset];

    if(enetPort)
    {
        /* Send to explicit port. In the case of loopback mode
         * enetPort is expected to be set to NWAL_ENET_PORT_UNKNOWN
         */
         PASAHO_SET_E (nr, 1);
         psFlags = ((enetPort & pa_EMAC_CTRL_PORT_MASK) <<
                     NWAL_PAFRM_ETH_PS_FLAGS_PORT_SHIFT);
         PASAHO_SET_PKTTYPE  (nr, psFlags);
         PASAHO_SET_DEST  (nr, PASAHO_NR_DEST_ETH);
    }
    /* PS FLAG update not being done. Here assumption is that
     * application is not switching between loopback and
     * non loopback mode between creation of command label and
     * sending packet
     * In the case of non loopback case initial PS command label
     * will already have PS flag set to zero
     */
}

/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdUpdatePSData  Update NetCP command for any offload
 *         functionilty for TX packets.
 *
 *  @details Inline macro API can be used to update PS data.
 *           API to be called for updating PS data with no additional
 *           per packet modification compared to already available after
 *           @see nwal_initPSCmdInfo API call.
 *           In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush operation in
 *          the case of non cache coherent architecure. Refer @see nwal_send
 *          for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *  @param[in]  ppPktDesc       CPPI packet descriptor which could be used
 *   @param[in] ppPsDataBuf     Buffer containing PS Data
 *                              @see nwal_initPSCmdInfo
 *  @pre        @see nwal_initPSCmdInfo
 */
static inline
void nwal_mCmdUpdatePSData(Ti_Pkt*               pPkt,
                             nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                             Cppi_HostDesc**       ppPktDesc,
                             uint8_t**             ppPsDataBuf)
{
    *ppPktDesc = Pktlib_getDescFromPacket(pPkt);
    /* Attach the command label to the PS data in descriptor */
    *ppPsDataBuf = Cppi_setPSData (Cppi_DescType_HOST,
                                   (Cppi_Desc *)*ppPktDesc,
                                   (uint8_t *)pTxPSCmdInfo->psCmdLabel,
                                   pTxPSCmdInfo->psCmdLabelLen);
}

/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetPort  Minimal NetCP offload case. EMAC port information
 *         for outgoing packet will be updated.
 *
 *  @details Inline macro API can be used to transmit  packet
 *           out of specific EMAC Port without using any offload feature
 *           at NetCP. In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush
 *          operation in the case of non cache coherent architecure.
 *          Refer @see nwal_send() for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_initPSCmdInfo
 */
static inline void nwal_mCmdSetPort  (Ti_Pkt*               pPkt,
                                      nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                      nwal_enetPort_t       enetPort)
{
    Cppi_HostDesc*      pPktDesc;
    uint8_t*            pPsDataBuf;

    if((pTxPSCmdInfo) && (pTxPSCmdInfo->psCmdLabelLen))
    {
        nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);
        nwal_modNREnetPort(pPsDataBuf,
                           pTxPSCmdInfo->enetPortNextRoute,
                           enetPort);
        return;
    }
    pPktDesc = Pktlib_getDescFromPacket(pPkt);
    /* Redirect packet to port based on Application configuration.
     * Zero value will let switch route the packet to correct outgoing port
     */
    if (!nssGblCfgParams.layout.fNssGen2)
    {
        Cppi_setPSFlags(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc, enetPort);
    }
    else
    {
        Cppi_DescTag    tag;
        tag.srcTagHi  = 0;
        tag.srcTagLo  = 0;
        tag.destTagHi = 0;
        tag.destTagLo = enetPort;
        Cppi_setTag(Cppi_DescType_HOST,
                   (Cppi_Desc *)pPktDesc,
                   (Cppi_DescTag *)&tag);
    }
    /* Clear PS Data */
    Cppi_setPSLen (Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc, 0);
}

/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetL4CkSumPort  Update L4 checksum command and outgoing
 *         EMAC port to NetCP command.
 *
 *  @details Inline macro API can be used to do dynamic update for L4
 *           checksum offload command to NetCP before transmitting  packet
 *           out of specific EMAC Port. In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush operation in
 *          the case of non cache coherent architecure. Refer @see nwal_send()
 *          for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  l4OffBytes      Offset to Layer 4 header
 *  @param[in]  l4Len           Layer 4 payload length including header
 *                              + payload
 *  @param[in]  pseudoHdrChecksum   Pseudo Header checksum for L4
 *  @param[in]  enetPort            Transmit Enet Port
 *  @pre        @see nwal_initPSCmdInfo
 */
static inline
void nwal_mCmdSetL4CkSumPort(Ti_Pkt*               pPkt,
                             nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                             uint16_t              l4OffBytes,
                             uint16_t              l4Len,
                             uint16_t              pseudoHdrChecksum,
                             nwal_enetPort_t       enetPort)
{
    Cppi_HostDesc*      pPktDesc;
    pasahoComChkCrc_t*  ptx;
    uint8_t*            pPsDataBuf;

    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    /* L4 checksum command need to be updated with
     * Offset to the L4 header
     * new pseudo header checksum and
     * L4 length
     */
    ptx = (pasahoComChkCrc_t *)&pPsDataBuf[pTxPSCmdInfo->udpChkOff];

    /* Update Layer 4 Offset bytes */
    PASAHO_CHKCRC_SET_START      (ptx, l4OffBytes);

    /* Update Length */
    PASAHO_CHKCRC_SET_LEN (ptx,l4Len);

    /* Update Pseudo header checksum */
    PASAHO_CHKCRC_SET_INITVAL    (ptx, pseudoHdrChecksum);

    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);
}


/**
  *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetCrypPort  Update Crypto command and outgoing
 *         EMAC port to NetCP command.
 *
 *  @details Inline macro API can be used to do dynamic update of
 *           crypto command parameters to NetCP before transmitting  packet
 *           out of specific EMAC Port. In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
*            QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *           Application would also need to do required cache flush
 *           operation in the case of non cache coherent architecure.
 *           Refer nwal_send() for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  saOffBytes      Offset from base of the packet to the header
 *                              of protocol per the following list:
 *                                  - IPSEC ESP with AH: IP header
 *                                  - IPSEC ESP: ESP Header
 *  @param[in]  saPayloadLen    Length of the payload starting from
 *                              saOffBytes to the end of the protocol
 *  @param[in]  swInfo0         Sw Info with SA context related details
 *  @param[in]  swInfo1         Sw Info with SA context related details
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_getSecAssoc @see nwal_initPSCmdInfo
 */
static inline void nwal_mCmdSetCrypPort (Ti_Pkt*               pPkt,
                                         nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                         uint16_t              saOffBytes,
                                         uint16_t              saPayloadLen,
                                         uint32_t              swInfo0,
                                         uint32_t              swInfo1,
                                         nwal_enetPort_t       enetPort)
{
    Cppi_HostDesc*      pPktDesc;
    uint8_t*            pPsDataBuf;
    pasahoShortInfo_t*  sInfo;
    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    sInfo = (pasahoShortInfo_t *)&pPsDataBuf[pTxPSCmdInfo->saShortInfoOff];
    PASAHO_SINFO_SET_PAYLOAD_OFFSET(sInfo, saOffBytes);
    PASAHO_SINFO_SET_PAYLOAD_LENGTH(sInfo, saPayloadLen);

    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);

    /* Update the Software Info for Security context in the descriptor
     * itself as packet would be sent directly to SA directly
     */
    Cppi_setSoftwareInfo0(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo0);
    Cppi_setSoftwareInfo1(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo1);

}




/**
  *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetL3CkSumCrypPort  Update L3 checksum, Crypto command and outgoing
 *         EMAC port to NetCP command.
 *
 *  @details Inline macro API can be used to do dynamic update of
 *           crypto command parameters to NetCP before transmitting  packet
 *           out of specific EMAC Port. In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
*            QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *           Application would also need to do required cache flush
 *           operation in the case of non cache coherent architecure.
 *           Refer nwal_send() for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  saOffBytes      Offset from base of the packet to the header
 *                              of protocol per the following list:
 *                                  - IPSEC ESP with AH: IP header
 *                                  - IPSEC ESP: ESP Header
 *  @param[in]  saPayloadLen    Length of the payload starting from
 *                              saOffBytes to the end of the protocol
 *  @param[in]  swInfo0         Sw Info with SA context related details
 *  @param[in]  swInfo1         Sw Info with SA context related details
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_getSecAssoc @see nwal_initPSCmdInfo
 */
static inline void nwal_mCmdSetL3CkSumCrypPort (Ti_Pkt*               pPkt,
                                         nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                         uint16_t              saOffBytes,
                                         uint16_t              saPayloadLen,
                                         uint32_t              swInfo0,
                                         uint32_t              swInfo1,
                                         nwal_enetPort_t       enetPort)
{
    Cppi_HostDesc*      pPktDesc;
    uint8_t*            pPsDataBuf;
    pasahoShortInfo_t*  sInfo;
    pasahoNextRoute_t*  nr;
    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    sInfo = (pasahoShortInfo_t *)&pPsDataBuf[pTxPSCmdInfo->saShortInfoOff];
    PASAHO_SINFO_SET_PAYLOAD_OFFSET(sInfo, saOffBytes);
    PASAHO_SINFO_SET_PAYLOAD_LENGTH(sInfo, saPayloadLen);


    nr = (pasahoNextRoute_t *)&pPsDataBuf[pTxPSCmdInfo->pa2saNextRoute];
    nr->swInfo0 = swInfo0;
    nr->swInfo1 = swInfo1;


    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);

    /* Update the Software Info for Security context in the descriptor
     * itself as packet would be sent directly to SA directly
     */
    Cppi_setSoftwareInfo0(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo0);
    Cppi_setSoftwareInfo1(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo1);

}

/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetL4CkSumCrypPort  Update L4 checksum,Crypto and
 *         outgoing EMAC port to NetCP command
 *
 *  @details Inline macro API can be used to do dynamic update for Crypto
 *           and L4  checksum offload command to NetCP before transmitting
 *           packet out of specific EMAC Port. In this case application is
 *           expected to provide full packet including protocol headers and
 *           call Qmss_queuePushXX API to transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush operation in
 *          the case of non cache coherent architecure. Refer nwal_send()
 *          for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  l4OffBytes      Offset to L4 Header
 *  @param[in]  l4Len           Layer 4 payload length including header +
 *                              payload
 *  @param[in]  pseudoHdrChecksum   Pseudo Header checksum for L4
 *  @param[in]  saOffBytes      Offset from base of the packet to the header
 *                              of protocol per the following list:
 *                                  - IPSEC ESP with AH: IP header
 *                                  - IPSEC ESP: ESP Header
 *  @param[in]  saPayloadLen    Length of the payload starting from
 *                              saOffBytes to the end of the protocol
 *  @param[in]  swInfo0         Sw Info with SA context related details
 *  @param[in]  swInfo1         Sw Info with SA context related details
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_getSecAssoc @see nwal_initPSCmdInfo
 */
static inline void
            nwal_mCmdSetL4CkSumCrypPort (Ti_Pkt*               pPkt,
                                         nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                         uint16_t              l4OffBytes,
                                         uint16_t              l4Len,
                                         uint16_t              pseudoHdrChecksum,
                                         uint16_t              saOffBytes,
                                         uint16_t              saPayloadLen,
                                         uint32_t              swInfo0,
                                         uint32_t              swInfo1,
                                         nwal_enetPort_t       enetPort)
{

    pasahoComChkCrc_t   *ptx;
    Cppi_HostDesc*      pPktDesc;
    uint8_t*            pPsDataBuf;
    pasahoShortInfo_t*  sInfo;
    pasahoNextRoute_t*  nr;

    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    /* L4 checksum command need to be updated with
     * Offset to the L4 header
     * new pseudo header checksum and
     * L4 length
     */
    ptx = (pasahoComChkCrc_t *)&pPsDataBuf[pTxPSCmdInfo->udpChkOff];

    /* Update Layer 4 Offset bytes */
    PASAHO_CHKCRC_SET_START      (ptx, l4OffBytes);

    /* Update Length */
    PASAHO_CHKCRC_SET_LEN (ptx,l4Len);

    /* Update Pseudo header checksum */
    PASAHO_CHKCRC_SET_INITVAL    (ptx, pseudoHdrChecksum);

    sInfo = (pasahoShortInfo_t *)&pPsDataBuf[pTxPSCmdInfo->saShortInfoOff];
    PASAHO_SINFO_SET_PAYLOAD_OFFSET(sInfo, saOffBytes);
    PASAHO_SINFO_SET_PAYLOAD_LENGTH(sInfo, saPayloadLen);


    nr = (pasahoNextRoute_t *)&pPsDataBuf[pTxPSCmdInfo->pa2saNextRoute];
    nr->swInfo0 = swInfo0;
    nr->swInfo1 = swInfo1;
    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);

}

/**
  *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetAHCrypPort  Update Crypto command and outgoing
 *         EMAC port to NetCP command for IPSec AH mode.
 *
 *  @details Inline macro API can be used to do dynamic update of
 *           crypto command parameters to NetCP before transmitting  packet
 *           out of specific EMAC Port. In this case application is expected
 *           to provide full packet including protocol headers and call
 *           Qmss_queuePushXX API to transmit the packet out.
*            QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *           Application would also need to do required cache flush
 *           operation in the case of non cache coherent architecure.
 *           Refer nwal_send() for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  saOffBytes      Offset from base of the packet to the header
 *                              of protocol per the following list:
 *                                  - IPSEC ESP with AH: IP header
 *                                  - IPSEC ESP: ESP Header
 *  @param[in]  saPayloadLen    Length of the payload starting from
 *                              saOffBytes to the end of the protocol
 *  @param[in]  swInfo0         Sw Info with SA context related details
 *  @param[in]  swInfo1         Sw Info with SA context related details
 *  @param[in]  saAhIcvOffBytes Offset to the ICV field in the case of
 *                              IPSec AH mode for authentication tag insertion
 *                               by NETCP.
 *  @param[in]  saAhMacSize     Size of the authentication tag to be inserted by
 *                              NetCP in the case of IPSec AH mode. Reset to
 *                              zero in the case of ESP mode.
 *                              Application also need to make sure that size is
 *                              not more than max value
 *                              @ref NWAL_IPSEC_AH_MAX_AUTH_TAG_BYTES
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_getSecAssoc @see nwal_initPSCmdInfo
 */
static inline void nwal_mCmdSetAHCrypPort (Ti_Pkt*               pPkt,
                                         nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                         uint16_t              saOffBytes,
                                         uint16_t              saPayloadLen,
                                         uint32_t              swInfo0,
                                         uint32_t              swInfo1,
                                         uint16_t              saAhIcvOffBytes,
                                         uint16_t              saAhMacSize,
                                         nwal_enetPort_t       enetPort)
{
    Cppi_HostDesc*          pPktDesc;
    uint8_t*                pPsDataBuf;
    pasahoShortInfo_t*      pSInfo;
    pasahoComBlindPatch_t*  pBpCmd;

    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    pSInfo = (pasahoShortInfo_t *)&pPsDataBuf[pTxPSCmdInfo->saShortInfoOff];
    PASAHO_SINFO_SET_PAYLOAD_OFFSET(pSInfo, saOffBytes);
    PASAHO_SINFO_SET_PAYLOAD_LENGTH(pSInfo, saPayloadLen);

    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);
    pBpCmd = (pasahoComBlindPatch_t *)&pPsDataBuf[pTxPSCmdInfo->ahPathCmdOff];
    PASAHO_BPATCH_SET_PATCH_NBYTES  (pBpCmd, saAhMacSize);
    PASAHO_BPATCH_SET_OFFSET        (pBpCmd, saAhIcvOffBytes);

    /* Update the Software Info for Security context in the descriptor
     * itself as packet would be sent directly to SA directly
     */
    Cppi_setSoftwareInfo0(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo0);
    Cppi_setSoftwareInfo1(Cppi_DescType_HOST, (Cppi_Desc *)pPktDesc,swInfo1);

}


/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdSetL4CkSumAHCrypPort  Update L4 checksum,Crypto and
 *         outgoing EMAC port for IPSec AH packet to NetCP command.
 *
 *  @details Inline macro API can be used to do dynamic update for Crypto
 *           in IPSec AH mode and L4  checksum offload command to
 *           NetCP before transmitting packet out of specific EMAC Port.
 *           In this case application is  expected to provide full packet
 *           including protocol headers and  call Qmss_queuePushXX API
 *           to transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush operation in
 *          the case of non cache coherent architecure. Refer nwal_send()
 *          for sample implementation
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[in]  pTxPSCmdInfo    Static Command Label @see nwalTxPSCmdInfo_t
 *                              created during API call
 *                              @see nwal_initPSCmdInfo
 *  @param[in]  l4OffBytes      Offset to L4 Header
 *  @param[in]  l4Len           Layer 4 payload length including header +
 *                              payload
 *  @param[in]  pseudoHdrChecksum   Pseudo Header checksum for L4
 *  @param[in]  saOffBytes      Offset from base of the packet to the header
 *                              of protocol per the following list:
 *                                  - IPSEC ESP with AH: IP header
 *                                  - IPSEC ESP: ESP Header
 *  @param[in]  saPayloadLen    Length of the payload starting from
 *                              saOffBytes to the end of the protocol
 *  @param[in]  swInfo0         Sw Info with SA context related details
 *  @param[in]  swInfo1         Sw Info with SA context related details
 *  @param[in]  saAhIcvOffBytes Offset to the ICV field in the case of
 *                              IPSec AH mode for authentication tag insertion
 *                               by NETCP.
 *  @param[in]  saAhMacSize     Size of the authentication tag to be inserted by
 *                              NetCP in the case of IPSec AH mode. Reset to
 *                              zero in the case of ESP mode.
 *                              Application also need to make sure that size is
 *                              not more than max value
 *                              @ref NWAL_IPSEC_AH_MAX_AUTH_TAG_BYTES
 *  @param[in]  enetPort        Transmit Enet Port
 *  @pre        @see nwal_getSecAssoc @see nwal_initPSCmdInfo
 */
static inline void
            nwal_mCmdSetL4CkSumAHCrypPort(Ti_Pkt*               pPkt,
                                         nwalTxPSCmdInfo_t*    pTxPSCmdInfo,
                                         uint16_t              l4OffBytes,
                                         uint16_t              l4Len,
                                         uint16_t              pseudoHdrChecksum,
                                         uint16_t              saOffBytes,
                                         uint16_t              saPayloadLen,
                                         uint32_t              swInfo0,
                                         uint32_t              swInfo1,
                                         uint16_t              saAhIcvOffBytes,
                                         uint16_t              saAhMacSize,
                                         nwal_enetPort_t       enetPort)
{

    pasahoComChkCrc_t*      ptx;
    Cppi_HostDesc*          pPktDesc;
    uint8_t*                pPsDataBuf;
    pasahoShortInfo_t*      sInfo;
    pasahoNextRoute_t*      nr;
    pasahoComBlindPatch_t*  pBpCmd;

    nwal_mCmdUpdatePSData(pPkt,pTxPSCmdInfo,&pPktDesc,&pPsDataBuf);

    /* L4 checksum command need to be updated with
     * Offset to the L4 header
     * new pseudo header checksum and
     * L4 length
     */
    ptx = (pasahoComChkCrc_t *)&pPsDataBuf[pTxPSCmdInfo->udpChkOff];

    /* Update Layer 4 Offset bytes */
    PASAHO_CHKCRC_SET_START      (ptx, l4OffBytes);

    /* Update Length */
    PASAHO_CHKCRC_SET_LEN (ptx,l4Len);

    /* Update Pseudo header checksum */
    PASAHO_CHKCRC_SET_INITVAL    (ptx, pseudoHdrChecksum);

    sInfo = (pasahoShortInfo_t *)&pPsDataBuf[pTxPSCmdInfo->saShortInfoOff];
    PASAHO_SINFO_SET_PAYLOAD_OFFSET(sInfo, saOffBytes);
    PASAHO_SINFO_SET_PAYLOAD_LENGTH(sInfo, saPayloadLen);


    nr = (pasahoNextRoute_t *)&pPsDataBuf[pTxPSCmdInfo->pa2saNextRoute];
    nr->swInfo0 = swInfo0;
    nr->swInfo1 = swInfo1;

    pBpCmd = (pasahoComBlindPatch_t *)&pPsDataBuf[pTxPSCmdInfo->ahPathCmdOff];
    PASAHO_BPATCH_SET_PATCH_NBYTES  (pBpCmd, saAhMacSize);
    PASAHO_BPATCH_SET_OFFSET        (pBpCmd, saAhIcvOffBytes);

    nwal_modNREnetPort(pPsDataBuf,
                       pTxPSCmdInfo->enetPortNextRoute,
                       enetPort);

}

#ifdef NWAL_ENABLE_SA
/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mCmdDMUpdate  Update PS Command label for Side Band Data Mode
 *
 *  @details Inline macro API can be used to do dynamic update for Side Band
 *           Data Mode SA.
 *           In this case application is expected to provide full packet
 *           including protocol headers and call Qmss_queuePushXX API to
 *           transmit the packet out.
 *           QMSS push operation is being separated to:
 *              - give flexibility to application for TX time and packet
 *                preparation
 *              - Have control on either doing raw push w/o virtual to
 *                physical address translation
 *          Application would also need to do required cache flush operation in
 *          the case of non cache coherent architecure. Refer @see nwal_sendDM()
 *          for sample implementation
 *
 *  @param[in]  pPkt            Payload to be transmitted to SA
 *  @param[in]  pTxDmPSCmdInfo  Command Label Meta Data returned from
 *                              @see nwal_initDMPSCmdInfo
 *  @param[in]  appCtxId        Application context ID identifying
 *                              the data mode request. The 32 bit ID
 *                              will be received as echo back for the
 *                              response from NetCP through
 *                              @ref nwal_mmGetDmAppCtxId
 *  @param[in]  encOffset       Specify the offset to the encrypted/decrypted
 *                              data in the packet in bytes
 *  @param[in]  encSize         Specify the total number of bytes  to be
 *                              encrypted or decrypted
 *  @param[in]  pEncIV;         Contain the initialization vectors
 *                              used in certain encryption modes.
 *                              @note: IV should be specified here
 *                              in GCM/CCM mode
 *  @param[in]   authOffset;    Specify the offset to the
 *                              authenticated data in the packet
 *                              in bytes
 *  @param[in]  authSize;       Specify the total number of bytes
 *                              to be authenticated
 *  @param[in]   pAuthIV;       Contain the initialization vectors
 *                              used in certain authentication
 *                              modes.
 *                              @note: IV should be specified
 *                              here in GMAC mode
 *  @param[in]   aadSize;       Size of additional authenticated
                                data in bytes
 *  @param[in]   pAad;          Contain the additional
                                authenticated data in
                                GCM/CCM modes
 *  @param[in]
 *  @pre        @see nwal_setDMSecAssoc @see nwal_initDMPSCmdInfo
 */
static inline void  nwal_mCmdDMUpdate (Ti_Pkt*                  pPkt,
                                       nwalTxDmPSCmdInfo_t*     pTxDmPSCmdInfo,
                                       nwal_AppId               appCtxId,
                                       uint8_t                  encOffset,
                                       uint16_t                 encSize,
                                       uint8_t*                 pEncIV,
                                       uint8_t                  authOffset,
                                       uint16_t                 authSize,
                                       uint8_t*                 pAuthIV,
                                       uint16_t                 aadSize,
                                       uint8_t*                 pAad)
{
    uint8_t*                pDataBuf;
    uint32_t                dataLen;
    Cppi_HostDesc*          pPloadDesc;
    uint32_t*               pTmpCmdLb;

    pPloadDesc = Pktlib_getDescFromPacket(pPkt);

    /* Update the Static PS command to the descriptor */
    pTmpCmdLb = (uint32_t *)
                 Cppi_setPSData(Cppi_DescType_HOST,
                                (Cppi_Desc *)pPloadDesc,
                                (uint8_t *)pTxDmPSCmdInfo->pCmdLb,
                                pTxDmPSCmdInfo->cmdLbLen);

    /* Updated Dynamic per packet info in the PS command */
    Pktlib_getDataBuffer(pPkt,&pDataBuf,&dataLen);
    sa_mDmUpdateCmdLb(encOffset,
                      encSize,
                      pEncIV,
                      authOffset,
                      authSize,
                      pAuthIV,
                      aadSize,
                      pAad,
                      pDataBuf,
                      pTxDmPSCmdInfo->pUpdateInfo,
                      pTmpCmdLb);

    /* Configure return Queue and Flow ID for packet returned from SA */
    sa_SWINFO_UPDATE_DEST_INFO(pTxDmPSCmdInfo->pSwInfo,
                               (uint16_t)(pTxDmPSCmdInfo->rxSbSaQ),
                               pTxDmPSCmdInfo->rxPktFlowId);
    Cppi_setSoftwareInfo (Cppi_DescType_HOST,
                          (Cppi_Desc *)pPloadDesc,
                          (uint8_t *)pTxDmPSCmdInfo->pSwInfo);

    /* Store additional Application context
     * Timestamp field in descriptor is being overloaded for storing
     * additional Application context
     */
     Cppi_setTimeStamp(Cppi_DescType_HOST,
                       (Cppi_Desc *)pPloadDesc,
                       (uint32_t)appCtxId);
}
#endif
/*********************** NWAL FAST SEND HELPER MACROS END ******************/

/*********************** NWAL FAST RECEIVE HELPER MACROS BEGIN *************/
/******* NWAL FAST RECEIVE INLINE MACROS ***/
/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mmGetDmAuthTag  Get Authentication Tag for Data Mode SA packet
 *
 *  @details Inline macro API to retrieve the Authentication tag for Data Mode
 *           SA packet.
 *
 *  @param[in]  pPkt            Packet received after crypto action from NetCP
 *  @param[in]  ppAuthTag       Authentication Tag for the packet
 *  @param[in]  pAuthTagLen     Length of authentication tag
 *  @pre        @see nwal_setDMSecAssoc @see nwal_sendDM
 */
static inline void
            nwal_mmGetDmAuthTag (Ti_Pkt*               pPkt,
                                 uint8_t**             ppAuthTag,
                                 uint32_t*             pAuthTagLen)
{
    Cppi_getPSData (Cppi_DescType_HOST,
                    Cppi_PSLoc_PS_IN_DESC,
                    (Cppi_Desc *)pPkt,
                    ppAuthTag,
                    pAuthTagLen);
}

/**
 *  @ingroup nwal_fast_send_macros
 *  @brief nwal_mmGetDmAppCtxId  Get Application Context for Data Mode SA packet
 *
 *  @details Inline macro API to retrieve the Application Context for Data Mode
 *           SA packet.
 *
 *  @param[in]  pPkt            Packet received after crypto action from NetCP
 *  @param[in]  pAppCtxId       Application Context Id which was passed during
 *                              @see nwal_sendDM
 *  @pre        @see nwal_setDMSecAssoc @see nwal_sendDM
 */
static inline void
            nwal_mmGetDmAppCtxId (Ti_Pkt*               pPkt,
                                  uint32_t*             pAppCtxId)
{
    Cppi_getTimeStamp(Cppi_DescType_HOST,
                      (Cppi_Desc *)pPkt,
                      pAppCtxId);
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetAppidFmPkt Get App ID from an incoming packet from NetCP
 *
 *  @details Inline macro API to get AppID from the incoming packet from
 *           NetCP.
 *
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @param[out] pAppId          Application ID returned if found
 *  @retval     @see nwal_TRUE if found / @see nwal_FALSE if not found in packet
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_Bool_t nwal_mGetAppidFmPkt (Ti_Pkt*               pPkt,
                                               nwal_AppId*           pAppId)
{
    Cppi_HostDesc*      pPktDesc;
    uint32_t*           pSwInfo0;

    pPktDesc = Pktlib_getDescFromPacket(pPkt);
    if (Cppi_getSoftwareInfo(Cppi_DescType_HOST,
                              (Cppi_Desc *)pPktDesc,
                              (uint8_t **) &pSwInfo0) == CPPI_EPIB_NOT_PRESENT)
    {
        return nwal_FALSE;
    }

    *pAppId = (nwal_AppId)(*pSwInfo0);
    return nwal_TRUE;
}

static inline uint8_t * nwalCppi_getPSData (Cppi_DescType descType, Cppi_PSLoc location, Cppi_Desc *descAddr, uint32_t *dataLen)
{
    Cppi_HostDesc   *hostDescPtr = (Cppi_HostDesc *) descAddr;
    uint8_t         epibPresent;
    uint8_t         *pPSData;


    if ((*dataLen = CSL_FEXTR (hostDescPtr->packetInfo, 29, 24) * 4) == 0)
    {
        return NULL;
    }

    epibPresent = CSL_FEXTR (hostDescPtr->packetInfo, 31, 31);

    if (descType == Cppi_DescType_HOST)
    {
        if (location == Cppi_PSLoc_PS_IN_SOP)
            pPSData = (uint8_t *) hostDescPtr->buffPtr;
        else
            pPSData = (uint8_t *) (((uint8_t *) &hostDescPtr->psData) - (!epibPresent * CPPI_HOST_DESC_EPIB_SIZE));
    }
    else
    {
        Cppi_MonolithicDesc *monolithicDescPtr = (Cppi_MonolithicDesc *) descAddr;
        pPSData = (uint8_t *) (((uint8_t *) &monolithicDescPtr->psData) - (!epibPresent * CPPI_MONOLITHIC_DESC_EPIB_SIZE));
    }

    return(pPSData);
}


/* find pointer to proto info fields in descriptor */
/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetProtoInfo Get Protocol Info data from an incoming packet
 *         from NetCP
 *
 *  @details Inline macro API to get Protocol Info from the incoming packet
 *           from NetCP.
 *
 *  @param[in]  pPkt     Packet to be transmitted out of NetCP
 *  @retval     Pointer to protocol Info to be passed for other utilities.
 *              Since no error check is being done application would need
 *              to make sure that a valid non Null is being returned before
 *              accessing other RX utilities
 *  @pre        Application should have received the packet through poll
 */
static inline  pasahoLongInfo_t* nwal_mGetProtoInfo(Ti_Pkt *    pPkt)
{
    uint32_t            infoLen = 0;
    Cppi_HostDesc*      pHd = Pktlib_getDescFromPacket(pPkt);
    pasahoLongInfo_t*   pProtoInfo = NULL;

    pProtoInfo = (pasahoLongInfo_t*)nwalCppi_getPSData (Cppi_DescType_HOST,
                                                        Cppi_PSLoc_PS_IN_DESC,
                                                        (Cppi_Desc *)pHd,
                                                        &infoLen);
#if 0
    /* Debug Code for GCC arm-2009q1 Compiler optimization load before store problem */
    if((pProtoInfo) == NULL)
    {
        printf("Null PS Data, Length: %d \n",infoLen);
    }
#endif

    return(pProtoInfo);
}

/** "protoInfo" below is return of NWAL_GET_PROTO_INFO() above**/

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetL3OffBytes Get offset to the L3 header.
 *  This is valid if packet had gone through Layer 2 classification at 
 *  NetCP
 *
 *  @details Inline macro API to get offset to the payload.
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval     Offset to the layer 3 header in the packet
 *  @pre        Application should have received the packet through poll
 */
static inline uint16_t nwal_mGetL3OffBytes( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_L3_OFFSET(protoInfo));
}


/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetL4Offset Get Offset to L4 protocol
 *
 *  @details Inline macro API to get offset to L4 protocol
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval             L4 Offset Value
 *                       @see nwal_mGetProtoInfo
 *  @pre        Application should have received the packet through poll
 */
static inline uint16_t nwal_mGetL4Offset( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_L4_OFFSET(protoInfo));
}


/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetL4ProtoType Get L4 protocol type
 *
 *  @details Inline macro API to get L4 protocol type.
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval              L4 Protocol type
 *                       @see nwal_mGetProtoInfo
 *  @pre  @see nwal_mGetL4Offset Application should make sure that L4 offset is valid
 */
static inline uint16_t nwal_mGetL4ProtoType( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_NXT_HDR_TYPE(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetPloadOffBytes Get offset to the payload.
 *   This is valid if packet had gone through Layer 4 classification.
 *
 *  @details Inline macro API to get offset to the payload.
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval     Offset to the payload in the packet
 *  @pre        Application should have received the packet through poll
 */
static inline uint16_t nwal_mGetPloadOffBytes( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_L5_OFFSET(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetPloadLen Get length of the payload
 *   This is valid if packet had gone through Layer 4 classification at NetCP
 *
 *  @details Inline macro API to get offset to the payload
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval     Length of the payload in the packet
 *  @pre        Application should have received the packet through poll
 */
static inline uint16_t nwal_mGetPloadLen( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_END_OFFSET(protoInfo) -
           PASAHO_LINFO_READ_L5_OFFSET(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetCryptoStatus Get the status of crypto action by NetCP
 *         for incoming packet for 
 *
 *  @details Inline macro API to get crypto status of the packet 
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval     Flag with indication of IPSec Crypto status
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_rxFlag1_t
nwal_mGetCryptoStatus( pasahoLongInfo_t* protoInfo)
{
    nwal_rxFlag1_t rxFlag1=0;
    if((PASAHO_LINFO_IS_IPSEC_ESP(protoInfo)) ||
       (PASAHO_LINFO_IS_IPSEC_AH(protoInfo)))
    {
        rxFlag1 |= (NWAL_RX_IPSEC_CRYPTO_DONE_OK |
                    NWAL_RX_IPSEC_WINDOW_DONE_OK);
    }
    return(rxFlag1);
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mIsMacBroadcast Return nwal_TRUE for MAC broadcast packet
 *
 *  @details Inline macro API to check for MAC broadcast packet
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_Bool_t
nwal_mIsMacBroadcast( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_IS_MAC_BROADCAST(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mIsFragmentPkt Return nwal_TRUE for IP fragment packet received
 *
 *  @details Inline macro API to check for IP Fragment packet
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_Bool_t
nwal_mIsFragmentPkt( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_FLAG_FRAG(protoInfo));
}


/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mIsMacMulticast Return nwal_TRUE for MAC Multicast packet
 *
 *  @details Inline macro API to check for MAC multicast packet
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_Bool_t
nwal_mIsMacMulticast( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_IS_MAC_MULTICAST(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mGetRxEmacPort Get the incoming port id for the packet

 *
 *  @details Inline macro API to get incoming port id for the packet
 *
 *  @param[in] protoInfo Non Null Pointer to protocol Info returned from
 *                       @see nwal_mGetProtoInfo
 *  @retval     Emac port for incoming packet @see nwal_enetPort_t
 *  @pre        Application should have received the packet through poll
 */
static inline nwal_macPktType_t
nwal_mGetRxEmacPort( pasahoLongInfo_t* protoInfo)
{
    return(PASAHO_LINFO_READ_INPORT(protoInfo));
}

/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mIsL3CksumStatusPass Layer 3 Checksum result is PASS
 *
 *  @details Inline macro API to check if Layer3 Checksum result is PASS
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @retval     nwal_TRUE for successful checksum result, nwal_FALSE for failure
 *  @pre        Application should have received non zero L3 offset bytes
 *              @see nwal_mGetL3OffBytes
 */
static inline nwal_Bool_t nwal_mIsL3CksumStatusPass(Ti_Pkt*     pPkt)
{
    uint32_t            eflags = 0x0;
    eflags =
        (Cppi_getDescError (Cppi_DescType_HOST,
                            (Cppi_Desc *)Pktlib_getDescFromPacket(pPkt))) &
                            0xf;
    if(eflags & NWAL_PA_IPV4_HDR_CHKSUM_ERR)
    {
        return nwal_FALSE;
    }

    return nwal_TRUE;
}


/**
 *  @ingroup nwal_recv_macros
 *  @brief nwal_mIsL4CksumStatusPass Layer 4 Checksum result is PASS
 *
 *  @details Inline macro API to check if Layer4 Checksum result is PASS
 *  @param[in]  pPkt            Packet to be transmitted out of NetCP
 *  @retval     @see nwal_TRUE for successful checksum result,
 *              @see nwal_FALSE for failure
 *  @pre        Application should have received non zero L4 offset bytes
 *              @see nwal_mGetPloadOffBytes
 */
static inline nwal_Bool_t nwal_mIsL4CksumStatusPass(Ti_Pkt*     pPkt)
{
    uint32_t            eflags = 0x0;
    eflags =
        (Cppi_getDescError (Cppi_DescType_HOST,
                            (Cppi_Desc *)Pktlib_getDescFromPacket(pPkt))) &
                            0xf;
    if(eflags & NWAL_PA_L4_CHKSUM_ERR)
    {
        return nwal_FALSE;
    }
    return nwal_TRUE;
}
#ifdef __cplusplus
}
#endif


#endif  /* _NWAL_UTIL_H */