xref: /freebsd/sys/contrib/ncsw/Peripherals/FM/HC/hc.c (revision d9f0ce31900a48d1a2bfc1c8c86f79d1e831451a)
1 /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of Freescale Semiconductor nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "std_ext.h"
34 #include "error_ext.h"
35 #include "sprint_ext.h"
36 #include "string_ext.h"
37 
38 #include "fm_common.h"
39 #include "fm_hc.h"
40 
41 
42 #define HC_HCOR_OPCODE_PLCR_PRFL                                0x0
43 #define HC_HCOR_OPCODE_KG_SCM                                   0x1
44 #define HC_HCOR_OPCODE_SYNC                                     0x2
45 #define HC_HCOR_OPCODE_CC                                       0x3
46 #define HC_HCOR_OPCODE_CC_CAPWAP_REASSM_TIMEOUT                 0x5
47 
48 #define HC_HCOR_GBL                         0x20000000
49 
50 #define SIZE_OF_HC_FRAME_PORT_REGS          (sizeof(t_HcFrame)-sizeof(t_FmPcdKgInterModuleSchemeRegs)+sizeof(t_FmPcdKgPortRegs))
51 #define SIZE_OF_HC_FRAME_SCHEME_REGS        sizeof(t_HcFrame)
52 #define SIZE_OF_HC_FRAME_PROFILES_REGS      (sizeof(t_HcFrame)-sizeof(t_FmPcdKgInterModuleSchemeRegs)+sizeof(t_FmPcdPlcrInterModuleProfileRegs))
53 #define SIZE_OF_HC_FRAME_PROFILE_CNT        (sizeof(t_HcFrame)-sizeof(t_FmPcdPlcrInterModuleProfileRegs)+sizeof(uint32_t))
54 #define SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC 16
55 
56 #define BUILD_FD(len)                     \
57 do {                                      \
58     memset(&fmFd, 0, sizeof(t_DpaaFD));   \
59     DPAA_FD_SET_ADDR(&fmFd, p_HcFrame);    \
60     DPAA_FD_SET_OFFSET(&fmFd, 0);         \
61     DPAA_FD_SET_LENGTH(&fmFd, len);       \
62 } while (0)
63 
64 
65 #if defined(__MWERKS__) && !defined(__GNUC__)
66 #pragma pack(push,1)
67 #endif /* defined(__MWERKS__) && ... */
68 #define MEM_MAP_START
69 
70 /**************************************************************************//**
71  @Description   PCD KG scheme registers
72 *//***************************************************************************/
73 typedef _Packed struct t_FmPcdKgSchemeRegsWithoutCounter {
74     volatile uint32_t kgse_mode;    /**< MODE */
75     volatile uint32_t kgse_ekfc;    /**< Extract Known Fields Command */
76     volatile uint32_t kgse_ekdv;    /**< Extract Known Default Value */
77     volatile uint32_t kgse_bmch;    /**< Bit Mask Command High */
78     volatile uint32_t kgse_bmcl;    /**< Bit Mask Command Low */
79     volatile uint32_t kgse_fqb;     /**< Frame Queue Base */
80     volatile uint32_t kgse_hc;      /**< Hash Command */
81     volatile uint32_t kgse_ppc;     /**< Policer Profile Command */
82     volatile uint32_t kgse_gec[FM_PCD_KG_NUM_OF_GENERIC_REGS];
83                                     /**< Generic Extract Command */
84     volatile uint32_t kgse_dv0;     /**< KeyGen Scheme Entry Default Value 0 */
85     volatile uint32_t kgse_dv1;     /**< KeyGen Scheme Entry Default Value 1 */
86     volatile uint32_t kgse_ccbs;    /**< KeyGen Scheme Entry Coarse Classification Bit*/
87     volatile uint32_t kgse_mv;      /**< KeyGen Scheme Entry Match vector */
88 } _PackedType t_FmPcdKgSchemeRegsWithoutCounter;
89 
90 typedef _Packed struct t_FmPcdKgPortRegs {
91     volatile uint32_t                       spReg;
92     volatile uint32_t                       cppReg;
93 } _PackedType t_FmPcdKgPortRegs;
94 
95 typedef _Packed struct t_HcFrame {
96     volatile uint32_t                           opcode;
97     volatile uint32_t                           actionReg;
98     volatile uint32_t                           extraReg;
99     volatile uint32_t                           commandSequence;
100     union {
101         t_FmPcdKgInterModuleSchemeRegs          schemeRegs;
102         t_FmPcdKgInterModuleSchemeRegs          schemeRegsWithoutCounter;
103         t_FmPcdPlcrInterModuleProfileRegs       profileRegs;
104         volatile uint32_t                       singleRegForWrite;    /* for writing SP, CPP, profile counter */
105         t_FmPcdKgPortRegs                       portRegsForRead;
106         volatile uint32_t                       clsPlanEntries[CLS_PLAN_NUM_PER_GRP];
107         t_FmPcdCcCapwapReassmTimeoutParams      ccCapwapReassmTimeout;
108     } hcSpecificData;
109 } _PackedType t_HcFrame;
110 
111 #define MEM_MAP_END
112 #if defined(__MWERKS__) && !defined(__GNUC__)
113 #pragma pack(pop)
114 #endif /* defined(__MWERKS__) && ... */
115 
116 
117 typedef struct t_FmHc {
118     t_Handle                    h_FmPcd;
119     t_Handle                    h_HcPortDev;
120     t_FmPcdQmEnqueueCallback    *f_QmEnqueue;     /**< A callback for enqueuing frames to the QM */
121     t_Handle                    h_QmArg;          /**< A handle to the QM module */
122     uint8_t                     padTill16;
123 
124     uint32_t                    seqNum;
125     volatile bool               wait[32];
126 } t_FmHc;
127 
128 
129 static __inline__ t_Error EnQFrm(t_FmHc *p_FmHc, t_DpaaFD *p_FmFd, volatile uint32_t *p_SeqNum)
130 {
131     t_Error     err = E_OK;
132     uint32_t    savedSeqNum;
133     uint32_t    intFlags;
134     uint32_t    timeout=100;
135 
136     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
137     *p_SeqNum = p_FmHc->seqNum;
138     savedSeqNum = p_FmHc->seqNum;
139     p_FmHc->seqNum = (uint32_t)((p_FmHc->seqNum+1)%32);
140     ASSERT_COND(!p_FmHc->wait[savedSeqNum]);
141     p_FmHc->wait[savedSeqNum] = TRUE;
142     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
143     DBG(TRACE, ("Send Hc, SeqNum %d, FD@0x%x, fd offset 0x%x",
144                 savedSeqNum,DPAA_FD_GET_ADDR(p_FmFd),DPAA_FD_GET_OFFSET(p_FmFd)));
145     err = p_FmHc->f_QmEnqueue(p_FmHc->h_QmArg, (void *)p_FmFd);
146     if(err)
147         RETURN_ERROR(MINOR, err, ("HC enqueue failed"));
148 
149     while (p_FmHc->wait[savedSeqNum] && --timeout)
150         XX_UDelay(100);
151 
152     if (!timeout)
153         RETURN_ERROR(MINOR, E_TIMEOUT, ("HC Callback, timeout exceeded"));
154 
155     return err;
156 }
157 
158 static t_Error CcHcDoDynamicChange(t_FmHc *p_FmHc, t_Handle p_OldPointer, t_Handle p_NewPointer)
159 {
160     t_HcFrame               *p_HcFrame;
161     t_DpaaFD                fmFd;
162     t_Error                 err = E_OK;
163 
164     ASSERT_COND(p_FmHc);
165 
166     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
167     if (!p_HcFrame)
168         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
169 
170     memset(p_HcFrame, 0, sizeof(t_HcFrame));
171     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_CC);
172     p_HcFrame->actionReg  = FmPcdCcGetNodeAddrOffsetFromNodeInfo(p_FmHc->h_FmPcd, p_NewPointer);
173     if(p_HcFrame->actionReg == (uint32_t)ILLEGAL_BASE)
174     {
175         XX_FreeSmart(p_HcFrame);
176         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Something wrong with base address"));
177     }
178 
179     p_HcFrame->actionReg  |=  0xc0000000;
180         p_HcFrame->extraReg   = FmPcdCcGetNodeAddrOffsetFromNodeInfo(p_FmHc->h_FmPcd, p_OldPointer);
181     if(p_HcFrame->extraReg == (uint32_t)ILLEGAL_BASE)
182     {
183         XX_FreeSmart(p_HcFrame);
184         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Something wrong with base address"));
185     }
186 
187     BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
188 
189     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
190     {
191         XX_FreeSmart(p_HcFrame);
192         RETURN_ERROR(MINOR, err, NO_MSG);
193     }
194 
195     XX_FreeSmart(p_HcFrame);
196 
197     return E_OK;
198 }
199 
200 static t_Error HcDynamicChange(t_FmHc *p_FmHc,t_List *h_OldPointersLst, t_List *h_NewPointersLst, t_Handle *h_Params)
201 {
202 
203     t_List      *p_PosOld, *p_PosNew;
204     uint16_t    i = 0;
205     t_Error     err = E_OK;
206     uint8_t     numOfModifiedPtr;
207 
208     SANITY_CHECK_RETURN_ERROR((LIST_NumOfObjs(h_NewPointersLst) == LIST_NumOfObjs(h_OldPointersLst)),E_INVALID_STATE);
209 
210     numOfModifiedPtr = (uint8_t)LIST_NumOfObjs(h_NewPointersLst);
211     p_PosNew = NCSW_LIST_FIRST(h_NewPointersLst);
212     p_PosOld = NCSW_LIST_FIRST(h_OldPointersLst);
213     for(i = 0; i < numOfModifiedPtr; i++)
214     {
215         err = CcHcDoDynamicChange(p_FmHc, p_PosOld, p_PosNew);
216         if(err)
217         {
218             FmPcdCcReleaseModifiedDataStructure(p_FmHc->h_FmPcd, h_OldPointersLst, h_NewPointersLst, i, h_Params);
219             RETURN_ERROR(MAJOR, err, ("For part of nodes changes are done - situation is danger"));
220         }
221         p_PosNew = NCSW_LIST_NEXT(p_PosNew);
222         p_PosOld = NCSW_LIST_NEXT(p_PosOld);
223     }
224 
225     err = FmPcdCcReleaseModifiedDataStructure(p_FmHc->h_FmPcd, h_OldPointersLst, h_NewPointersLst, i, h_Params);
226     if(err)
227         RETURN_ERROR(MAJOR, err, NO_MSG);
228 
229     return E_OK;
230 }
231 
232 
233 t_Handle FmHcConfigAndInit(t_FmHcParams *p_FmHcParams)
234 {
235     t_FmHc          *p_FmHc;
236     t_FmPortParams  fmPortParam;
237     t_Error         err = E_OK;
238 
239     p_FmHc = (t_FmHc *)XX_Malloc(sizeof(t_FmHc));
240     if (!p_FmHc)
241     {
242         REPORT_ERROR(MINOR, E_NO_MEMORY, ("HC obj"));
243         return NULL;
244     }
245     memset(p_FmHc,0,sizeof(t_FmHc));
246 
247     p_FmHc->h_FmPcd             = p_FmHcParams->h_FmPcd;
248     p_FmHc->f_QmEnqueue         = p_FmHcParams->params.f_QmEnqueue;
249     p_FmHc->h_QmArg             = p_FmHcParams->params.h_QmArg;
250 
251     if (!FmIsMaster(p_FmHcParams->h_Fm))
252         return (t_Handle)p_FmHc;
253 
254 /*
255 TKT056919 - axi12axi0 can hang if read request follows the single byte write on the very next cycle
256 TKT038900 - FM dma lockup occur due to AXI slave protocol violation
257 */
258 #ifdef FM_LOCKUP_ALIGNMENT_ERRATA_FMAN_SW004
259     p_FmHc->padTill16 = 16 - (sizeof(t_FmHc) % 16);
260 #endif /* FM_LOCKUP_ALIGNMENT_ERRATA_FMAN_SW004 */
261     memset(&fmPortParam, 0, sizeof(fmPortParam));
262     fmPortParam.baseAddr    = p_FmHcParams->params.portBaseAddr;
263     fmPortParam.portType    = e_FM_PORT_TYPE_OH_HOST_COMMAND;
264     fmPortParam.portId      = p_FmHcParams->params.portId;
265     fmPortParam.liodnBase   = p_FmHcParams->params.liodnBase;
266     fmPortParam.h_Fm        = p_FmHcParams->h_Fm;
267 
268     fmPortParam.specificParams.nonRxParams.errFqid      = p_FmHcParams->params.errFqid;
269     fmPortParam.specificParams.nonRxParams.dfltFqid     = p_FmHcParams->params.confFqid;
270     fmPortParam.specificParams.nonRxParams.qmChannel    = p_FmHcParams->params.qmChannel;
271 
272     p_FmHc->h_HcPortDev = FM_PORT_Config(&fmPortParam);
273     if(!p_FmHc->h_HcPortDev)
274     {
275         REPORT_ERROR(MAJOR, E_INVALID_HANDLE, ("FM HC port!"));
276         XX_Free(p_FmHc);
277         return NULL;
278     }
279 
280     /* final init */
281     if ((err = FM_PORT_Init(p_FmHc->h_HcPortDev)) != E_OK)
282     {
283         REPORT_ERROR(MAJOR, err, ("FM HC port!"));
284         FmHcFree(p_FmHc);
285         return NULL;
286     }
287 
288     if ((err = FM_PORT_Enable(p_FmHc->h_HcPortDev)) != E_OK)
289     {
290         REPORT_ERROR(MAJOR, err, ("FM HC port!"));
291         FmHcFree(p_FmHc);
292         return NULL;
293     }
294 
295     return (t_Handle)p_FmHc;
296 }
297 
298 void FmHcFree(t_Handle h_FmHc)
299 {
300     t_FmHc  *p_FmHc = (t_FmHc*)h_FmHc;
301 
302     if (!p_FmHc)
303         return;
304 
305     if (p_FmHc->h_HcPortDev)
306         FM_PORT_Free(p_FmHc->h_HcPortDev);
307 
308     XX_Free(p_FmHc);
309 }
310 
311 #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0))
312 t_Error FmHcDumpRegs(t_Handle h_FmHc)
313 {
314     t_FmHc  *p_FmHc = (t_FmHc*)h_FmHc;
315 
316     SANITY_CHECK_RETURN_ERROR(p_FmHc, E_INVALID_HANDLE);
317     SANITY_CHECK_RETURN_ERROR(p_FmHc->h_HcPortDev, E_INVALID_HANDLE);
318 
319     return  FM_PORT_DumpRegs(p_FmHc->h_HcPortDev);
320 
321 }
322 #endif /* (defined(DEBUG_ERRORS) && ... */
323 
324 void FmHcTxConf(t_Handle h_FmHc, t_DpaaFD *p_Fd)
325 {
326     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
327     t_HcFrame   *p_HcFrame;
328     uint32_t    intFlags;
329 
330     ASSERT_COND(p_FmHc);
331 
332     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
333     p_HcFrame  = (t_HcFrame *)PTR_MOVE(DPAA_FD_GET_ADDR(p_Fd), DPAA_FD_GET_OFFSET(p_Fd));
334 
335     DBG(TRACE, ("Hc Conf, SeqNum %d, FD@0x%x, fd offset 0x%x",
336                 p_HcFrame->commandSequence, DPAA_FD_GET_ADDR(p_Fd), DPAA_FD_GET_OFFSET(p_Fd)));
337 
338     if (!(p_FmHc->wait[p_HcFrame->commandSequence]))
339         REPORT_ERROR(MINOR, E_INVALID_FRAME, ("Not an Host-Command frame received!"));
340     else
341         p_FmHc->wait[p_HcFrame->commandSequence] = FALSE;
342     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
343 }
344 
345 t_Handle FmHcPcdKgSetScheme(t_Handle h_FmHc, t_FmPcdKgSchemeParams *p_Scheme)
346 {
347     t_FmHc                              *p_FmHc = (t_FmHc*)h_FmHc;
348     t_Error                             err = E_OK;
349     t_FmPcdKgInterModuleSchemeRegs      schemeRegs;
350     t_HcFrame                           *p_HcFrame;
351     t_DpaaFD                            fmFd;
352     uint32_t                            intFlags;
353     uint8_t                             physicalSchemeId, relativeSchemeId;
354 
355     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
356     if (!p_HcFrame)
357     {
358         REPORT_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
359         return NULL;
360     }
361 
362     if(!p_Scheme->modify)
363     {
364         /* check that schemeId is in range */
365         if(p_Scheme->id.relativeSchemeId >= FmPcdKgGetNumOfPartitionSchemes(p_FmHc->h_FmPcd))
366         {
367             REPORT_ERROR(MAJOR, E_NOT_IN_RANGE, ("Scheme is out of range"));
368             XX_FreeSmart(p_HcFrame);
369             return NULL;
370         }
371 
372         relativeSchemeId = p_Scheme->id.relativeSchemeId;
373 
374         if (FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, FALSE))
375         {
376             XX_FreeSmart(p_HcFrame);
377             return NULL;
378         }
379 
380         physicalSchemeId = FmPcdKgGetPhysicalSchemeId(p_FmHc->h_FmPcd, relativeSchemeId);
381 
382         memset(p_HcFrame, 0, sizeof(t_HcFrame));
383         p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
384         p_HcFrame->actionReg  = FmPcdKgBuildReadSchemeActionReg(physicalSchemeId);
385         p_HcFrame->extraReg = 0xFFFFF800;
386 
387         BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
388 
389         if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
390         {
391             FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
392             REPORT_ERROR(MINOR, err, NO_MSG);
393             XX_FreeSmart(p_HcFrame);
394             return NULL;
395         }
396 
397         /* check if this scheme is already used */
398         if (FmPcdKgHwSchemeIsValid(p_HcFrame->hcSpecificData.schemeRegs.kgse_mode))
399         {
400             FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
401             REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, ("Scheme is already used"));
402             XX_FreeSmart(p_HcFrame);
403             return NULL;
404         }
405     }
406     else
407     {
408         intFlags = FmPcdLock(p_FmHc->h_FmPcd);
409         physicalSchemeId = (uint8_t)(PTR_TO_UINT(p_Scheme->id.h_Scheme)-1);
410         relativeSchemeId = FmPcdKgGetRelativeSchemeId(p_FmHc->h_FmPcd, physicalSchemeId);
411         if( relativeSchemeId == FM_PCD_KG_NUM_OF_SCHEMES)
412         {
413             FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
414             REPORT_ERROR(MAJOR, E_NOT_IN_RANGE, NO_MSG);
415             XX_FreeSmart(p_HcFrame);
416             return NULL;
417         }
418         err = FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, TRUE);
419         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
420         if (err)
421         {
422             XX_FreeSmart(p_HcFrame);
423             return NULL;
424         }
425     }
426 
427     err = FmPcdKgBuildScheme(p_FmHc->h_FmPcd, p_Scheme, &schemeRegs);
428     if(err)
429     {
430         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
431         REPORT_ERROR(MAJOR, err, NO_MSG);
432         XX_FreeSmart(p_HcFrame);
433         return NULL;
434     }
435 
436     memset(p_HcFrame, 0, sizeof(t_HcFrame));
437     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
438     p_HcFrame->actionReg  = FmPcdKgBuildWriteSchemeActionReg(physicalSchemeId, p_Scheme->schemeCounter.update);
439     p_HcFrame->extraReg = 0xFFFFF800;
440     memcpy(&p_HcFrame->hcSpecificData.schemeRegs, &schemeRegs, sizeof(t_FmPcdKgInterModuleSchemeRegs));
441     if(!p_Scheme->schemeCounter.update)
442     {
443         p_HcFrame->hcSpecificData.schemeRegs.kgse_dv0   = schemeRegs.kgse_dv0;
444         p_HcFrame->hcSpecificData.schemeRegs.kgse_dv1   = schemeRegs.kgse_dv1;
445         p_HcFrame->hcSpecificData.schemeRegs.kgse_ccbs  = schemeRegs.kgse_ccbs;
446         p_HcFrame->hcSpecificData.schemeRegs.kgse_mv    = schemeRegs.kgse_mv;
447     }
448 
449     BUILD_FD(sizeof(t_HcFrame));
450 
451     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
452     {
453         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
454         REPORT_ERROR(MINOR, err, NO_MSG);
455         XX_FreeSmart(p_HcFrame);
456         return NULL;
457     }
458 
459     FmPcdKgValidateSchemeSw(p_FmHc->h_FmPcd, relativeSchemeId);
460 
461     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
462 
463     XX_FreeSmart(p_HcFrame);
464 
465     return (t_Handle)(UINT_TO_PTR(physicalSchemeId + 1));
466 }
467 
468 t_Error FmHcPcdKgDeleteScheme(t_Handle h_FmHc, t_Handle h_Scheme)
469 {
470     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
471     t_Error     err = E_OK;
472     t_HcFrame   *p_HcFrame;
473     t_DpaaFD    fmFd;
474     uint8_t     relativeSchemeId;
475     uint8_t     physicalSchemeId = (uint8_t)(PTR_TO_UINT(h_Scheme)-1);
476 
477     relativeSchemeId = FmPcdKgGetRelativeSchemeId(p_FmHc->h_FmPcd, physicalSchemeId);
478 
479     if ((err = FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, FALSE)) != E_OK)
480         RETURN_ERROR(MAJOR, err, NO_MSG);
481 
482     if(relativeSchemeId == FM_PCD_KG_NUM_OF_SCHEMES)
483     {
484         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
485         RETURN_ERROR(MAJOR, E_NOT_IN_RANGE, NO_MSG);
486     }
487 
488     err = FmPcdKgCheckInvalidateSchemeSw(p_FmHc->h_FmPcd, relativeSchemeId);
489     if (err)
490     {
491         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
492         RETURN_ERROR(MAJOR, err, NO_MSG);
493     }
494 
495     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
496     if (!p_HcFrame)
497     {
498         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
499         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
500     }
501     memset(p_HcFrame, 0, sizeof(t_HcFrame));
502     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
503     p_HcFrame->actionReg  = FmPcdKgBuildWriteSchemeActionReg(physicalSchemeId, TRUE);
504     p_HcFrame->extraReg = 0xFFFFF800;
505     memset(&p_HcFrame->hcSpecificData.schemeRegs, 0, sizeof(t_FmPcdKgInterModuleSchemeRegs));
506 
507     BUILD_FD(sizeof(t_HcFrame));
508 
509     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
510     {
511         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
512         XX_FreeSmart(p_HcFrame);
513         RETURN_ERROR(MINOR, err, NO_MSG);
514     }
515 
516     FmPcdKgInvalidateSchemeSw(p_FmHc->h_FmPcd, relativeSchemeId);
517 
518     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
519 
520     XX_FreeSmart(p_HcFrame);
521 
522     return E_OK;
523 }
524 
525 t_Error FmHcPcdKgCcGetSetParams(t_Handle h_FmHc, t_Handle  h_Scheme, uint32_t requiredAction)
526 {
527     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
528     t_Error     err = E_OK;
529     t_HcFrame   *p_HcFrame;
530     t_DpaaFD    fmFd;
531     uint8_t     relativeSchemeId;
532     uint8_t     physicalSchemeId = (uint8_t)(PTR_TO_UINT(h_Scheme)-1);
533     uint32_t    tmpReg32 = 0;
534 
535     relativeSchemeId = FmPcdKgGetRelativeSchemeId(p_FmHc->h_FmPcd, physicalSchemeId);
536     if( relativeSchemeId == FM_PCD_KG_NUM_OF_SCHEMES)
537         RETURN_ERROR(MAJOR, E_NOT_IN_RANGE, NO_MSG);
538 
539     if (FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, FALSE))
540         RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Lock of the scheme FAILED"));
541 
542     if(!FmPcdKgGetPointedOwners(p_FmHc->h_FmPcd, relativeSchemeId) ||
543        !(FmPcdKgGetRequiredAction(p_FmHc->h_FmPcd, relativeSchemeId) & requiredAction))
544     {
545 
546         if(requiredAction & UPDATE_NIA_ENQ_WITHOUT_DMA)
547         {
548             if((FmPcdKgGetNextEngine(p_FmHc->h_FmPcd, relativeSchemeId) == e_FM_PCD_DONE) && (FmPcdKgGetDoneAction(p_FmHc->h_FmPcd, relativeSchemeId) ==  e_FM_PCD_ENQ_FRAME))
549 
550             {
551                 p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
552                 if (!p_HcFrame)
553                 {
554                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
555                     RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
556                 }
557                 memset(p_HcFrame, 0, sizeof(t_HcFrame));
558                 p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
559                 p_HcFrame->actionReg  = FmPcdKgBuildReadSchemeActionReg(physicalSchemeId);
560                 p_HcFrame->extraReg = 0xFFFFF800;
561                 BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
562                 if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
563                 {
564                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
565                     XX_FreeSmart(p_HcFrame);
566                     RETURN_ERROR(MINOR, err, NO_MSG);
567                 }
568 
569                 /* check if this scheme is already used */
570                 if (!FmPcdKgHwSchemeIsValid(p_HcFrame->hcSpecificData.schemeRegs.kgse_mode))
571                 {
572                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
573                     XX_FreeSmart(p_HcFrame);
574                     RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, ("Scheme is already used"));
575                 }
576                 tmpReg32 = p_HcFrame->hcSpecificData.schemeRegs.kgse_mode;
577 
578                 ASSERT_COND(tmpReg32 & (NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME));
579 
580                 p_HcFrame->hcSpecificData.schemeRegs.kgse_mode =  tmpReg32 | NIA_BMI_AC_ENQ_FRAME_WITHOUT_DMA;
581 
582                 p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
583                 p_HcFrame->actionReg  = FmPcdKgBuildWriteSchemeActionReg(physicalSchemeId, FALSE);
584                 p_HcFrame->extraReg = 0x80000000;
585 
586                 BUILD_FD(sizeof(t_HcFrame));
587 
588                 if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
589                 {
590                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
591                     XX_FreeSmart(p_HcFrame);
592                     RETURN_ERROR(MINOR, err, NO_MSG);
593                 }
594 
595                 XX_FreeSmart(p_HcFrame);
596             }
597             else if (FmPcdKgGetNextEngine(p_FmHc->h_FmPcd, relativeSchemeId) == e_FM_PCD_PLCR)
598             {
599 
600                 if((FmPcdKgIsDirectPlcr(p_FmHc->h_FmPcd, relativeSchemeId) == FALSE) ||
601                     (FmPcdKgIsDistrOnPlcrProfile(p_FmHc->h_FmPcd, relativeSchemeId) == TRUE))
602                  {
603                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
604                     RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("In this situation PP can not be with distribution and has to be shared"));
605                  }
606                 err = FmPcdPlcrCcGetSetParams(p_FmHc->h_FmPcd, FmPcdKgGetRelativeProfileId(p_FmHc->h_FmPcd, relativeSchemeId), requiredAction);
607                 if(err)
608                 {
609                     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
610                     RETURN_ERROR(MAJOR, err, NO_MSG);
611                 }
612         }
613       }
614     }
615 
616     FmPcdKgUpatePointedOwner(p_FmHc->h_FmPcd, relativeSchemeId,TRUE);
617     FmPcdKgUpdateRequiredAction(p_FmHc->h_FmPcd, relativeSchemeId,requiredAction);
618     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
619 
620     return E_OK;
621 }
622 
623 uint32_t  FmHcPcdKgGetSchemeCounter(t_Handle h_FmHc, t_Handle h_Scheme)
624 {
625     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
626     t_Error     err = E_OK;
627     t_HcFrame   *p_HcFrame;
628     t_DpaaFD    fmFd;
629     uint32_t    retVal;
630     uint8_t     relativeSchemeId;
631     uint8_t     physicalSchemeId = (uint8_t)(PTR_TO_UINT(h_Scheme)-1);
632 
633     relativeSchemeId = FmPcdKgGetRelativeSchemeId(p_FmHc->h_FmPcd, physicalSchemeId);
634     if( relativeSchemeId == FM_PCD_KG_NUM_OF_SCHEMES)
635     {
636         REPORT_ERROR(MAJOR, E_NOT_IN_RANGE, NO_MSG);
637         return 0;
638     }
639 
640     if ((err = FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, FALSE)) != E_OK)
641     {
642         REPORT_ERROR(MAJOR, err, ("Scheme lock"));
643         return 0;
644     }
645 
646     /* first read scheme and check that it is valid */
647     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
648     if (!p_HcFrame)
649     {
650         REPORT_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
651         return 0;
652     }
653     memset(p_HcFrame, 0, sizeof(t_HcFrame));
654     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
655     p_HcFrame->actionReg  = FmPcdKgBuildReadSchemeActionReg(physicalSchemeId);
656     p_HcFrame->extraReg = 0xFFFFF800;
657 
658     BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
659 
660     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
661     {
662         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
663         REPORT_ERROR(MINOR, err, NO_MSG);
664         XX_FreeSmart(p_HcFrame);
665         return 0;
666     }
667 
668     if (!FmPcdKgHwSchemeIsValid(p_HcFrame->hcSpecificData.schemeRegs.kgse_mode))
669     {
670         REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, ("Scheme is invalid"));
671         XX_FreeSmart(p_HcFrame);
672         return 0;
673     }
674 
675     retVal = p_HcFrame->hcSpecificData.schemeRegs.kgse_spc;
676 
677     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
678 
679     XX_FreeSmart(p_HcFrame);
680 
681     return retVal;
682 }
683 
684 t_Error  FmHcPcdKgSetSchemeCounter(t_Handle h_FmHc, t_Handle h_Scheme, uint32_t value)
685 {
686     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
687     t_Error     err = E_OK;
688     t_HcFrame   *p_HcFrame;
689     t_DpaaFD    fmFd;
690     uint8_t     relativeSchemeId, physicalSchemeId = (uint8_t)(PTR_TO_UINT(h_Scheme)-1);
691 
692     relativeSchemeId = FmPcdKgGetRelativeSchemeId(p_FmHc->h_FmPcd, physicalSchemeId);
693     if( relativeSchemeId == FM_PCD_KG_NUM_OF_SCHEMES)
694         RETURN_ERROR(MAJOR, E_NOT_IN_RANGE, NO_MSG);
695 
696     if ((err = FmPcdKgSchemeTryLock(p_FmHc->h_FmPcd, relativeSchemeId, FALSE)) != E_OK)
697         RETURN_ERROR(MAJOR, err, NO_MSG);
698 
699     /* first read scheme and check that it is valid */
700     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
701     if (!p_HcFrame)
702         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
703     memset(p_HcFrame, 0, sizeof(t_HcFrame));
704     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
705     p_HcFrame->actionReg  = FmPcdKgBuildReadSchemeActionReg(physicalSchemeId);
706     p_HcFrame->extraReg = 0xFFFFF800;
707 
708     BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
709 
710     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
711     {
712         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
713         XX_FreeSmart(p_HcFrame);
714         RETURN_ERROR(MINOR, err, NO_MSG);
715     }
716 
717     /* check that scheme is valid */
718     if (!FmPcdKgHwSchemeIsValid(p_HcFrame->hcSpecificData.schemeRegs.kgse_mode))
719     {
720         FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
721         XX_FreeSmart(p_HcFrame);
722         RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, ("Scheme is invalid"));
723     }
724 
725     /* Write scheme back, with modified counter */
726     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
727     p_HcFrame->actionReg  = FmPcdKgBuildWriteSchemeActionReg(physicalSchemeId, TRUE);
728     p_HcFrame->extraReg = 0xFFFFF800;
729     /* write counter */
730     p_HcFrame->hcSpecificData.schemeRegs.kgse_spc = value;
731 
732     BUILD_FD(sizeof(t_HcFrame));
733 
734     err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence);
735 
736     FmPcdKgReleaseSchemeLock(p_FmHc->h_FmPcd, relativeSchemeId);
737     XX_FreeSmart(p_HcFrame);
738 
739     return err;
740 }
741 
742 t_Error FmHcPcdKgSetClsPlan(t_Handle h_FmHc, t_FmPcdKgInterModuleClsPlanSet *p_Set)
743 {
744     t_FmHc                  *p_FmHc = (t_FmHc*)h_FmHc;
745     t_HcFrame               *p_HcFrame;
746     t_DpaaFD                fmFd;
747     uint32_t                i;
748     t_Error                 err = E_OK;
749 
750     ASSERT_COND(p_FmHc);
751 
752     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
753     if (!p_HcFrame)
754         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
755 
756     for(i=p_Set->baseEntry;i<p_Set->baseEntry+p_Set->numOfClsPlanEntries;i+=8)
757     {
758         memset(p_HcFrame, 0, sizeof(t_HcFrame));
759         p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
760         p_HcFrame->actionReg  = FmPcdKgBuildWriteClsPlanBlockActionReg((uint8_t)(i / CLS_PLAN_NUM_PER_GRP));
761         p_HcFrame->extraReg = 0xFFFFF800;
762         memcpy((void*)&p_HcFrame->hcSpecificData.clsPlanEntries, (void *)&p_Set->vectors[i-p_Set->baseEntry], CLS_PLAN_NUM_PER_GRP*sizeof(uint32_t));
763 
764         BUILD_FD(sizeof(t_HcFrame));
765 
766         if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
767         {
768             XX_FreeSmart(p_HcFrame);
769             RETURN_ERROR(MINOR, err, NO_MSG);
770         }
771     }
772     XX_FreeSmart(p_HcFrame);
773 
774     return err;
775 }
776 
777 t_Error FmHcPcdKgDeleteClsPlan(t_Handle h_FmHc, uint8_t  grpId)
778 {
779     t_FmHc                              *p_FmHc = (t_FmHc*)h_FmHc;
780     t_FmPcdKgInterModuleClsPlanSet      *p_ClsPlanSet;
781 
782     /* clear clsPlan entries in memory */
783     p_ClsPlanSet = (t_FmPcdKgInterModuleClsPlanSet *)XX_Malloc(sizeof(t_FmPcdKgInterModuleClsPlanSet));
784     if (!p_ClsPlanSet)
785         RETURN_ERROR(MAJOR, E_NO_MEMORY, ("memory allocation failed for p_ClsPlanSetd"));
786     memset(p_ClsPlanSet, 0, sizeof(t_FmPcdKgInterModuleClsPlanSet));
787 
788     p_ClsPlanSet->baseEntry = FmPcdKgGetClsPlanGrpBase(p_FmHc->h_FmPcd, grpId);
789     p_ClsPlanSet->numOfClsPlanEntries = FmPcdKgGetClsPlanGrpSize(p_FmHc->h_FmPcd, grpId);
790     ASSERT_COND(p_ClsPlanSet->numOfClsPlanEntries <= FM_PCD_MAX_NUM_OF_CLS_PLANS);
791 
792     if (FmHcPcdKgSetClsPlan(p_FmHc, p_ClsPlanSet) != E_OK)
793         RETURN_ERROR(MAJOR, E_INVALID_STATE, NO_MSG);
794     XX_Free(p_ClsPlanSet);
795 
796     FmPcdKgDestroyClsPlanGrp(p_FmHc->h_FmPcd, grpId);
797 
798     return E_OK;
799 }
800 
801 t_Error FmHcPcdCcCapwapTimeoutReassm(t_Handle h_FmHc, t_FmPcdCcCapwapReassmTimeoutParams *p_CcCapwapReassmTimeoutParams )
802 {
803     t_FmHc                              *p_FmHc = (t_FmHc*)h_FmHc;
804     t_HcFrame                           *p_HcFrame;
805     uint32_t                            intFlags;
806     t_DpaaFD                            fmFd;
807     t_Error                             err;
808 
809     SANITY_CHECK_RETURN_VALUE(h_FmHc, E_INVALID_HANDLE,0);
810 
811     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
812     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
813     if (!p_HcFrame)
814         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
815     memset(p_HcFrame, 0, sizeof(t_HcFrame));
816     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_CC_CAPWAP_REASSM_TIMEOUT);
817     memcpy(&p_HcFrame->hcSpecificData.ccCapwapReassmTimeout, p_CcCapwapReassmTimeoutParams, sizeof(t_FmPcdCcCapwapReassmTimeoutParams));
818     BUILD_FD(sizeof(t_HcFrame));
819 
820     err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence);
821 
822     XX_FreeSmart(p_HcFrame);
823     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
824     return err;
825 }
826 
827 
828 t_Error FmHcPcdPlcrCcGetSetParams(t_Handle h_FmHc,uint16_t absoluteProfileId, uint32_t requiredAction)
829 {
830     t_FmHc              *p_FmHc = (t_FmHc*)h_FmHc;
831     t_HcFrame           *p_HcFrame;
832     t_DpaaFD            fmFd;
833     t_Error             err;
834     uint32_t            tmpReg32 = 0;
835     uint32_t            requiredActionTmp, pointedOwnersTmp;
836 
837     SANITY_CHECK_RETURN_VALUE(h_FmHc, E_INVALID_HANDLE,0);
838 
839     if (absoluteProfileId >= FM_PCD_PLCR_NUM_ENTRIES)
840         RETURN_ERROR(MAJOR, E_INVALID_VALUE,("Policer profile out of range"));
841 
842     if (FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, absoluteProfileId, FALSE))
843         return ERROR_CODE(E_BUSY);
844 
845 
846     requiredActionTmp = FmPcdPlcrGetRequiredAction(p_FmHc->h_FmPcd, absoluteProfileId);
847     pointedOwnersTmp = FmPcdPlcrGetPointedOwners(p_FmHc->h_FmPcd, absoluteProfileId);
848 
849     if(!pointedOwnersTmp || !(requiredActionTmp & requiredAction))
850     {
851 
852         if(requiredAction & UPDATE_NIA_ENQ_WITHOUT_DMA)
853         {
854 
855             p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
856             if (!p_HcFrame)
857                 RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
858             /* first read scheme and check that it is valid */
859             memset(p_HcFrame, 0, sizeof(t_HcFrame));
860             p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
861             p_HcFrame->actionReg  = FmPcdPlcrBuildReadPlcrActionReg(absoluteProfileId);
862             p_HcFrame->extraReg = 0x00008000;
863 
864             BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
865 
866             if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
867             {
868                 FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
869                 XX_FreeSmart(p_HcFrame);
870                 RETURN_ERROR(MINOR, err, NO_MSG);
871             }
872 
873             /* check that profile is valid */
874             if (!FmPcdPlcrHwProfileIsValid(p_HcFrame->hcSpecificData.profileRegs.fmpl_pemode))
875             {
876                 FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
877                 XX_FreeSmart(p_HcFrame);
878                 RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, ("Policer is already used"));
879             }
880 
881             tmpReg32 = p_HcFrame->hcSpecificData.profileRegs.fmpl_pegnia;
882             if(!(tmpReg32 & (NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME)))
883             {
884                 XX_FreeSmart(p_HcFrame);
885                 RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Next engine of this policer profile has to be assigned to FM_PCD_DONE"));
886             }
887             tmpReg32 |= NIA_BMI_AC_ENQ_FRAME_WITHOUT_DMA;
888 
889             p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
890             p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionReg(absoluteProfileId);
891             p_HcFrame->actionReg |= FmPcdPlcrBuildNiaProfileReg(TRUE, FALSE, FALSE);
892             p_HcFrame->extraReg = 0x00008000;
893             p_HcFrame->hcSpecificData.singleRegForWrite = tmpReg32;
894 
895             BUILD_FD(SIZE_OF_HC_FRAME_PROFILE_CNT);
896 
897             if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
898             {
899                 FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
900                 XX_FreeSmart(p_HcFrame);
901                 RETURN_ERROR(MINOR, err, NO_MSG);
902             }
903 
904             tmpReg32 = p_HcFrame->hcSpecificData.profileRegs.fmpl_peynia;
905             if(!(tmpReg32 & (NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME)))
906             {
907                 XX_FreeSmart(p_HcFrame);
908                 RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Next engine of this policer profile has to be assigned to FM_PCD_DONE"));
909             }
910             tmpReg32 |= NIA_BMI_AC_ENQ_FRAME_WITHOUT_DMA;
911 
912             p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
913             p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionReg(absoluteProfileId);
914             p_HcFrame->actionReg |= FmPcdPlcrBuildNiaProfileReg(FALSE, TRUE, FALSE);
915             p_HcFrame->extraReg = 0x00008000;
916             p_HcFrame->hcSpecificData.singleRegForWrite = tmpReg32;
917 
918             BUILD_FD(SIZE_OF_HC_FRAME_PROFILE_CNT);
919 
920             if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
921             {
922                 FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
923                 XX_FreeSmart(p_HcFrame);
924                 RETURN_ERROR(MINOR, err, NO_MSG);
925             }
926 
927             tmpReg32 = p_HcFrame->hcSpecificData.profileRegs.fmpl_pernia;
928             if(!(tmpReg32 & (NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME)))
929             {
930                 XX_FreeSmart(p_HcFrame);
931                 RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Next engine of this policer profile has to be assigned to FM_PCD_DONE"));
932             }
933             tmpReg32 |= NIA_BMI_AC_ENQ_FRAME_WITHOUT_DMA;
934 
935             p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
936             p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionReg(absoluteProfileId);
937             p_HcFrame->actionReg |= FmPcdPlcrBuildNiaProfileReg(FALSE, FALSE, TRUE);
938             p_HcFrame->extraReg = 0x00008000;
939             p_HcFrame->hcSpecificData.singleRegForWrite = tmpReg32;
940 
941             BUILD_FD(SIZE_OF_HC_FRAME_PROFILE_CNT);
942 
943             if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
944             {
945                 FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
946                 XX_FreeSmart(p_HcFrame);
947                 RETURN_ERROR(MINOR, err, NO_MSG);
948             }
949             XX_FreeSmart(p_HcFrame);
950         }
951     }
952 
953     FmPcdPlcrUpatePointedOwner(p_FmHc->h_FmPcd, absoluteProfileId, TRUE);
954     FmPcdPlcrUpdateRequiredAction(p_FmHc->h_FmPcd, absoluteProfileId, requiredAction);
955 
956     FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
957 
958     return E_OK;
959 }
960 
961 t_Handle FmHcPcdPlcrSetProfile(t_Handle h_FmHc,t_FmPcdPlcrProfileParams *p_Profile)
962 {
963     t_FmHc                              *p_FmHc = (t_FmHc*)h_FmHc;
964     t_FmPcdPlcrInterModuleProfileRegs   profileRegs;
965     t_Error                             err = E_OK;
966     uint32_t                            intFlags;
967     uint16_t                            profileIndx;
968     t_HcFrame                           *p_HcFrame;
969     t_DpaaFD                            fmFd;
970 
971     if (p_Profile->modify)
972     {
973         profileIndx = (uint16_t)(PTR_TO_UINT(p_Profile->id.h_Profile)-1);
974         if (FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, profileIndx, FALSE))
975             return NULL;
976     }
977     else
978     {
979         intFlags = FmPcdLock(p_FmHc->h_FmPcd);
980         err = FmPcdPlcrGetAbsoluteProfileId(p_FmHc->h_FmPcd,
981                                             p_Profile->id.newParams.profileType,
982                                             p_Profile->id.newParams.h_FmPort,
983                                             p_Profile->id.newParams.relativeProfileId,
984                                             &profileIndx);
985         if (err)
986         {
987             REPORT_ERROR(MAJOR, err, NO_MSG);
988             return NULL;
989         }
990         err = FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, profileIndx, TRUE);
991         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
992         if (err)
993             return NULL;
994     }
995 
996     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
997     if (!p_HcFrame)
998     {
999         REPORT_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1000         return NULL;
1001     }
1002 
1003     if(!p_Profile->modify)
1004     {
1005         memset(p_HcFrame, 0, sizeof(t_HcFrame));
1006         p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1007         p_HcFrame->actionReg  = FmPcdPlcrBuildReadPlcrActionReg(profileIndx);
1008         p_HcFrame->extraReg = 0x00008000;
1009 
1010         BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
1011 
1012         if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1013         {
1014             FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, profileIndx);
1015             REPORT_ERROR(MINOR, err, NO_MSG);
1016             XX_FreeSmart(p_HcFrame);
1017             return NULL;
1018         }
1019 
1020         /* check if this scheme is already used */
1021         if (FmPcdPlcrHwProfileIsValid(p_HcFrame->hcSpecificData.profileRegs.fmpl_pemode))
1022         {
1023             FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, profileIndx);
1024             REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, ("Policer is already used"));
1025             XX_FreeSmart(p_HcFrame);
1026             return NULL;
1027         }
1028     }
1029 
1030     memset(&profileRegs, 0, sizeof(t_FmPcdPlcrInterModuleProfileRegs));
1031     err = FmPcdPlcrBuildProfile(p_FmHc->h_FmPcd, p_Profile, &profileRegs);
1032     if(err)
1033     {
1034         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, profileIndx);
1035         REPORT_ERROR(MAJOR, err, NO_MSG);
1036         XX_FreeSmart(p_HcFrame);
1037         return NULL;
1038     }
1039 
1040     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1041     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1042     p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionRegs(profileIndx);
1043     p_HcFrame->extraReg = 0x00008000;
1044     memcpy(&p_HcFrame->hcSpecificData.profileRegs, &profileRegs, sizeof(t_FmPcdPlcrInterModuleProfileRegs));
1045 
1046     BUILD_FD(sizeof(t_HcFrame));
1047 
1048     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1049     {
1050         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, profileIndx);
1051         REPORT_ERROR(MINOR, err, NO_MSG);
1052         XX_FreeSmart(p_HcFrame);
1053         return NULL;
1054     }
1055 
1056     FmPcdPlcrValidateProfileSw(p_FmHc->h_FmPcd, profileIndx);
1057 
1058     FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, profileIndx);
1059 
1060     XX_FreeSmart(p_HcFrame);
1061 
1062     return UINT_TO_PTR((uint64_t)profileIndx+1);
1063 }
1064 
1065 t_Error FmHcPcdPlcrDeleteProfile(t_Handle h_FmHc, t_Handle h_Profile)
1066 {
1067     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1068     uint16_t    absoluteProfileId = (uint16_t)(PTR_TO_UINT(h_Profile)-1);
1069     t_Error     err = E_OK;
1070     t_HcFrame   *p_HcFrame;
1071     t_DpaaFD    fmFd;
1072 
1073     if (FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, absoluteProfileId, FALSE))
1074         return ERROR_CODE(E_BUSY);
1075 
1076     FmPcdPlcrInvalidateProfileSw(p_FmHc->h_FmPcd, absoluteProfileId);
1077 
1078     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
1079     if (!p_HcFrame)
1080         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1081     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1082     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1083     p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionReg(absoluteProfileId);
1084     p_HcFrame->actionReg  |= 0x00008000;
1085     p_HcFrame->extraReg = 0x00008000;
1086     memset(&p_HcFrame->hcSpecificData.profileRegs, 0, sizeof(t_FmPcdPlcrInterModuleProfileRegs));
1087 
1088     BUILD_FD(sizeof(t_HcFrame));
1089 
1090     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1091     {
1092         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1093         XX_FreeSmart(p_HcFrame);
1094         RETURN_ERROR(MINOR, err, NO_MSG);
1095     }
1096 
1097     FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1098 
1099     XX_FreeSmart(p_HcFrame);
1100 
1101     return E_OK;
1102 }
1103 
1104 t_Error  FmHcPcdPlcrSetProfileCounter(t_Handle h_FmHc, t_Handle h_Profile, e_FmPcdPlcrProfileCounters counter, uint32_t value)
1105 {
1106 
1107     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1108     uint16_t    absoluteProfileId = (uint16_t)(PTR_TO_UINT(h_Profile)-1);
1109     t_Error     err = E_OK;
1110     t_HcFrame   *p_HcFrame;
1111     t_DpaaFD    fmFd;
1112 
1113     if (FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, absoluteProfileId, FALSE))
1114         return ERROR_CODE(E_BUSY);
1115 
1116     /* first read scheme and check that it is valid */
1117     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
1118     if (!p_HcFrame)
1119         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1120     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1121     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1122     p_HcFrame->actionReg  = FmPcdPlcrBuildReadPlcrActionReg(absoluteProfileId);
1123     p_HcFrame->extraReg = 0x00008000;
1124 
1125     BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
1126 
1127     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1128     {
1129         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1130         XX_FreeSmart(p_HcFrame);
1131         RETURN_ERROR(MINOR, err, NO_MSG);
1132     }
1133 
1134     /* check that profile is valid */
1135     if (!FmPcdPlcrHwProfileIsValid(p_HcFrame->hcSpecificData.profileRegs.fmpl_pemode))
1136     {
1137         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1138         XX_FreeSmart(p_HcFrame);
1139         RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, ("Policer is already used"));
1140     }
1141 
1142     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1143     p_HcFrame->actionReg  = FmPcdPlcrBuildWritePlcrActionReg(absoluteProfileId);
1144     p_HcFrame->actionReg |= FmPcdPlcrBuildCounterProfileReg(counter);
1145     p_HcFrame->extraReg = 0x00008000;
1146     p_HcFrame->hcSpecificData.singleRegForWrite = value;
1147 
1148     BUILD_FD(SIZE_OF_HC_FRAME_PROFILE_CNT);
1149 
1150     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1151     {
1152         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1153         XX_FreeSmart(p_HcFrame);
1154         RETURN_ERROR(MINOR, err, NO_MSG);
1155     }
1156 
1157     FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1158 
1159     XX_FreeSmart(p_HcFrame);
1160 
1161     return E_OK;
1162 }
1163 
1164 uint32_t FmHcPcdPlcrGetProfileCounter(t_Handle h_FmHc, t_Handle h_Profile, e_FmPcdPlcrProfileCounters counter)
1165 {
1166     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1167     uint16_t    absoluteProfileId = (uint16_t)(PTR_TO_UINT(h_Profile)-1);
1168     t_Error     err = E_OK;
1169     t_HcFrame   *p_HcFrame;
1170     t_DpaaFD    fmFd;
1171     uint32_t    retVal = 0;
1172 
1173     SANITY_CHECK_RETURN_VALUE(h_FmHc, E_INVALID_HANDLE,0);
1174 
1175     if (FmPcdPlcrProfileTryLock(p_FmHc->h_FmPcd, absoluteProfileId, FALSE))
1176         return 0;
1177 
1178     /* first read scheme and check that it is valid */
1179     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
1180     if (!p_HcFrame)
1181     {
1182         REPORT_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1183         return 0;
1184     }
1185     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1186     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_PLCR_PRFL);
1187     p_HcFrame->actionReg  = FmPcdPlcrBuildReadPlcrActionReg(absoluteProfileId);
1188     p_HcFrame->extraReg = 0x00008000;
1189 
1190     BUILD_FD(SIZE_OF_HC_FRAME_READ_OR_CC_DYNAMIC);
1191 
1192     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1193     {
1194         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1195         REPORT_ERROR(MINOR, err, NO_MSG);
1196         XX_FreeSmart(p_HcFrame);
1197         return 0;
1198     }
1199 
1200     /* check that profile is valid */
1201     if (!FmPcdPlcrHwProfileIsValid(p_HcFrame->hcSpecificData.profileRegs.fmpl_pemode))
1202     {
1203         FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1204         XX_FreeSmart(p_HcFrame);
1205         REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, ("invalid Policer profile"));
1206         return 0;
1207     }
1208 
1209     switch (counter)
1210     {
1211         case e_FM_PCD_PLCR_PROFILE_GREEN_PACKET_TOTAL_COUNTER:
1212             retVal = p_HcFrame->hcSpecificData.profileRegs.fmpl_pegpc;
1213             break;
1214         case e_FM_PCD_PLCR_PROFILE_YELLOW_PACKET_TOTAL_COUNTER:
1215             retVal = p_HcFrame->hcSpecificData.profileRegs.fmpl_peypc;
1216             break;
1217         case e_FM_PCD_PLCR_PROFILE_RED_PACKET_TOTAL_COUNTER:
1218             retVal = p_HcFrame->hcSpecificData.profileRegs.fmpl_perpc;
1219             break;
1220         case e_FM_PCD_PLCR_PROFILE_RECOLOURED_YELLOW_PACKET_TOTAL_COUNTER:
1221             retVal = p_HcFrame->hcSpecificData.profileRegs.fmpl_perypc;
1222             break;
1223         case e_FM_PCD_PLCR_PROFILE_RECOLOURED_RED_PACKET_TOTAL_COUNTER:
1224             retVal = p_HcFrame->hcSpecificData.profileRegs.fmpl_perrpc;
1225             break;
1226         default:
1227             REPORT_ERROR(MAJOR, E_INVALID_SELECTION, NO_MSG);
1228     }
1229 
1230     FmPcdPlcrReleaseProfileLock(p_FmHc->h_FmPcd, absoluteProfileId);
1231 
1232     XX_FreeSmart(p_HcFrame);
1233 
1234     return retVal;
1235 }
1236 
1237 t_Error FmHcPcdCcModifyTreeNextEngine(t_Handle h_FmHc, t_Handle h_CcTree, uint8_t grpId, uint8_t index, t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams)
1238 {
1239     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1240     t_Error     err = E_OK;
1241     uint32_t    intFlags;
1242     t_List      h_OldPointersLst, h_NewPointersLst;
1243     t_Handle    h_Params;
1244 
1245     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1246     err = FmPcdCcTreeTryLock(h_CcTree);
1247     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1248     if (err)
1249         return err;
1250 
1251     INIT_LIST(&h_OldPointersLst);
1252     INIT_LIST(&h_NewPointersLst);
1253 
1254     err = FmPcdCcModifyNextEngineParamTree(p_FmHc->h_FmPcd, h_CcTree, grpId, index, p_FmPcdCcNextEngineParams,
1255             &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1256     if(err)
1257     {
1258         FmPcdCcTreeReleaseLock(h_CcTree);
1259         RETURN_ERROR(MAJOR, err, NO_MSG);
1260     }
1261 
1262     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1263 
1264     FmPcdCcTreeReleaseLock(h_CcTree);
1265 
1266     return err;
1267 }
1268 
1269 
1270 t_Error FmHcPcdCcModifyNodeMissNextEngine(t_Handle h_FmHc, t_Handle h_CcNode, t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams)
1271 {
1272     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1273     t_Handle    h_Params;
1274     t_List      h_OldPointersLst, h_NewPointersLst;
1275     t_Error     err = E_OK;
1276     t_List      h_List;
1277     uint32_t    intFlags;
1278 
1279     INIT_LIST(&h_List);
1280 
1281     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1282 
1283     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1284     {
1285         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1286         return err;
1287     }
1288 
1289     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1290 
1291     INIT_LIST(&h_OldPointersLst);
1292     INIT_LIST(&h_NewPointersLst);
1293 
1294     err = FmPcdCcModifyMissNextEngineParamNode(p_FmHc->h_FmPcd, h_CcNode, p_FmPcdCcNextEngineParams, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1295     if(err)
1296     {
1297         FmPcdCcNodeTreeReleaseLock(&h_List);
1298         RETURN_ERROR(MAJOR, err, NO_MSG);
1299     }
1300 
1301     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1302 
1303     FmPcdCcNodeTreeReleaseLock(&h_List);
1304 
1305 
1306     return E_OK;
1307 }
1308 
1309 t_Error FmHcPcdCcRemoveKey(t_Handle h_FmHc, t_Handle h_CcNode, uint8_t keyIndex)
1310 {
1311     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1312     t_Handle    h_Params;
1313     t_List      h_OldPointersLst, h_NewPointersLst;
1314     t_Error     err = E_OK;
1315     t_List      h_List;
1316     uint32_t    intFlags;
1317 
1318     INIT_LIST(&h_List);
1319 
1320     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1321 
1322     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1323     {
1324         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1325         return err;
1326     }
1327 
1328     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1329 
1330     INIT_LIST(&h_OldPointersLst);
1331     INIT_LIST(&h_NewPointersLst);
1332 
1333 
1334     err = FmPcdCcRemoveKey(p_FmHc->h_FmPcd,h_CcNode,keyIndex, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1335     if(err)
1336     {
1337         FmPcdCcNodeTreeReleaseLock(&h_List);
1338         RETURN_ERROR(MAJOR, err, NO_MSG);
1339     }
1340 
1341     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1342 
1343     FmPcdCcNodeTreeReleaseLock(&h_List);
1344 
1345     return err;
1346 
1347 }
1348 
1349 t_Error FmHcPcdCcAddKey(t_Handle h_FmHc, t_Handle h_CcNode, uint8_t keyIndex, uint8_t keySize, t_FmPcdCcKeyParams  *p_KeyParams)
1350 {
1351     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1352     t_Handle    h_Params;
1353     t_List      h_OldPointersLst, h_NewPointersLst;
1354     t_Error     err = E_OK;
1355     t_List      h_List;
1356     uint32_t    intFlags;
1357 
1358     INIT_LIST(&h_List);
1359 
1360     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1361 
1362     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1363     {
1364         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1365         return err;
1366     }
1367 
1368     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1369 
1370     INIT_LIST(&h_OldPointersLst);
1371     INIT_LIST(&h_NewPointersLst);
1372 
1373 
1374     err = FmPcdCcAddKey(p_FmHc->h_FmPcd,h_CcNode,keyIndex,keySize, p_KeyParams, &h_OldPointersLst,&h_NewPointersLst, &h_Params);
1375     if(err)
1376     {
1377         FmPcdCcNodeTreeReleaseLock(&h_List);
1378         RETURN_ERROR(MAJOR, err, NO_MSG);
1379     }
1380 
1381     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1382 
1383     FmPcdCcNodeTreeReleaseLock(&h_List);
1384 
1385     return err;
1386 }
1387 
1388 
1389 t_Error FmHcPcdCcModifyKey(t_Handle h_FmHc, t_Handle h_CcNode, uint8_t keyIndex, uint8_t keySize, uint8_t  *p_Key, uint8_t *p_Mask)
1390 {
1391     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1392     t_List      h_OldPointersLst, h_NewPointersLst;
1393     t_Error     err = E_OK;
1394     t_List      h_List;
1395     uint32_t    intFlags;
1396     t_Handle    h_Params;
1397 
1398     UNUSED(keySize);
1399 
1400     INIT_LIST(&h_List);
1401 
1402     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1403 
1404     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1405     {
1406         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1407         return err;
1408     }
1409 
1410     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1411 
1412     INIT_LIST(&h_OldPointersLst);
1413     INIT_LIST(&h_NewPointersLst);
1414 
1415     err = FmPcdCcModifyKey(p_FmHc->h_FmPcd, h_CcNode, keyIndex, keySize, p_Key, p_Mask, &h_OldPointersLst,&h_NewPointersLst,  &h_Params);
1416     if(err)
1417     {
1418         FmPcdCcNodeTreeReleaseLock(&h_List);
1419         RETURN_ERROR(MAJOR, err, NO_MSG);
1420     }
1421 
1422     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1423 
1424     FmPcdCcNodeTreeReleaseLock(&h_List);
1425 
1426     return err;
1427 }
1428 
1429 t_Error FmHcPcdCcModifyNodeNextEngine(t_Handle h_FmHc, t_Handle h_CcNode, uint8_t keyIndex, t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams)
1430 {
1431     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1432     t_Error     err = E_OK;
1433     t_List      h_OldPointersLst, h_NewPointersLst;
1434     t_List      h_List;
1435     uint32_t    intFlags;
1436     t_Handle    h_Params;
1437 
1438     INIT_LIST(&h_List);
1439 
1440     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1441 
1442     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1443     {
1444         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1445         return err;
1446     }
1447 
1448     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1449 
1450     INIT_LIST(&h_OldPointersLst);
1451     INIT_LIST(&h_NewPointersLst);
1452 
1453     err = FmPcdCcModiyNextEngineParamNode(p_FmHc->h_FmPcd, h_CcNode, keyIndex, p_FmPcdCcNextEngineParams, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1454     if(err)
1455     {
1456         FmPcdCcNodeTreeReleaseLock(&h_List);
1457         RETURN_ERROR(MAJOR, err, NO_MSG);
1458     }
1459 
1460     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1461     FmPcdCcNodeTreeReleaseLock(&h_List);
1462     return err;
1463 }
1464 
1465 
1466 t_Error FmHcPcdCcModifyKeyAndNextEngine(t_Handle h_FmHc, t_Handle h_CcNode, uint8_t keyIndex, uint8_t keySize, t_FmPcdCcKeyParams  *p_KeyParams)
1467 {
1468     t_FmHc      *p_FmHc = (t_FmHc*)h_FmHc;
1469     t_List      h_OldPointersLst, h_NewPointersLst;
1470     t_Error     err = E_OK;
1471     t_List      h_List;
1472     uint32_t    intFlags;
1473     t_Handle    h_Params;
1474 
1475     INIT_LIST(&h_OldPointersLst);
1476     INIT_LIST(&h_NewPointersLst);
1477     INIT_LIST(&h_List);
1478 
1479     intFlags = FmPcdLock(p_FmHc->h_FmPcd);
1480 
1481     if ((err = FmPcdCcNodeTreeTryLock(p_FmHc->h_FmPcd, h_CcNode, &h_List)) != E_OK)
1482     {
1483         FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1484         return err;
1485     }
1486 
1487     FmPcdUnlock(p_FmHc->h_FmPcd, intFlags);
1488 
1489 
1490     err = FmPcdCcModifyKeyAndNextEngine(p_FmHc->h_FmPcd,h_CcNode,keyIndex,keySize, p_KeyParams, &h_OldPointersLst,&h_NewPointersLst, &h_Params);
1491     if(err)
1492     {
1493         FmPcdCcNodeTreeReleaseLock(&h_List);
1494         RETURN_ERROR(MAJOR, err, NO_MSG);
1495     }
1496 
1497     err =  HcDynamicChange(p_FmHc, &h_OldPointersLst, &h_NewPointersLst, &h_Params);
1498 
1499     FmPcdCcNodeTreeReleaseLock(&h_List);
1500 
1501 
1502     return err;
1503 }
1504 
1505 
1506 t_Error FmHcKgWriteSp(t_Handle h_FmHc, uint8_t hardwarePortId, uint32_t spReg, bool add)
1507 {
1508     t_FmHc                  *p_FmHc = (t_FmHc*)h_FmHc;
1509     t_HcFrame               *p_HcFrame;
1510     t_DpaaFD                fmFd;
1511     t_Error                 err = E_OK;
1512 
1513     ASSERT_COND(p_FmHc);
1514 
1515     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
1516     if (!p_HcFrame)
1517         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1518     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1519     /* first read SP register */
1520     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
1521     p_HcFrame->actionReg  = FmPcdKgBuildReadPortSchemeBindActionReg(hardwarePortId);
1522     p_HcFrame->extraReg = 0xFFFFF800;
1523 
1524     BUILD_FD(SIZE_OF_HC_FRAME_PORT_REGS);
1525 
1526     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1527     {
1528         XX_FreeSmart(p_HcFrame);
1529         RETURN_ERROR(MINOR, err, NO_MSG);
1530     }
1531 
1532     /* spReg is the first reg, so we can use it both for read and for write */
1533     if(add)
1534         p_HcFrame->hcSpecificData.portRegsForRead.spReg |= spReg;
1535     else
1536         p_HcFrame->hcSpecificData.portRegsForRead.spReg &= ~spReg;
1537 
1538     p_HcFrame->actionReg  = FmPcdKgBuildWritePortSchemeBindActionReg(hardwarePortId);
1539 
1540     BUILD_FD(sizeof(t_HcFrame));
1541 
1542     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1543     {
1544         XX_FreeSmart(p_HcFrame);
1545         RETURN_ERROR(MINOR, err, NO_MSG);
1546     }
1547 
1548     XX_FreeSmart(p_HcFrame);
1549 
1550     return E_OK;
1551 }
1552 
1553 t_Error FmHcKgWriteCpp(t_Handle h_FmHc, uint8_t hardwarePortId, uint32_t cppReg)
1554 {
1555     t_FmHc                  *p_FmHc = (t_FmHc*)h_FmHc;
1556     t_HcFrame               *p_HcFrame;
1557     t_DpaaFD                fmFd;
1558     t_Error                 err = E_OK;
1559 
1560     ASSERT_COND(p_FmHc);
1561 
1562     p_HcFrame = (t_HcFrame *)XX_MallocSmart((sizeof(t_HcFrame) + p_FmHc->padTill16), 0, 16);
1563     if (!p_HcFrame)
1564         RETURN_ERROR(MINOR, E_NO_MEMORY, ("HC Frame obj"));
1565     memset(p_HcFrame, 0, sizeof(t_HcFrame));
1566     /* first read SP register */
1567     p_HcFrame->opcode = (uint32_t)(HC_HCOR_GBL | HC_HCOR_OPCODE_KG_SCM);
1568     p_HcFrame->actionReg  = FmPcdKgBuildWritePortClsPlanBindActionReg(hardwarePortId);
1569     p_HcFrame->extraReg = 0xFFFFF800;
1570     p_HcFrame->hcSpecificData.singleRegForWrite = cppReg;
1571 
1572     BUILD_FD(sizeof(t_HcFrame));
1573 
1574     if ((err = EnQFrm(p_FmHc, &fmFd, &p_HcFrame->commandSequence)) != E_OK)
1575     {
1576         XX_FreeSmart(p_HcFrame);
1577         RETURN_ERROR(MINOR, err, NO_MSG);
1578     }
1579 
1580     XX_FreeSmart(p_HcFrame);
1581 
1582     return E_OK;
1583 }
1584 
1585