1a05c377jhibbits/*
2a05c377jhibbits * Copyright 2008-2015 Freescale Semiconductor Inc.
3a05c377jhibbits *
4a05c377jhibbits * Redistribution and use in source and binary forms, with or without
5a05c377jhibbits * modification, are permitted provided that the following conditions are met:
6a05c377jhibbits *     * Redistributions of source code must retain the above copyright
7a05c377jhibbits *       notice, this list of conditions and the following disclaimer.
8a05c377jhibbits *     * Redistributions in binary form must reproduce the above copyright
9a05c377jhibbits *       notice, this list of conditions and the following disclaimer in the
10a05c377jhibbits *       documentation and/or other materials provided with the distribution.
11a05c377jhibbits *     * Neither the name of Freescale Semiconductor nor the
12a05c377jhibbits *       names of its contributors may be used to endorse or promote products
13a05c377jhibbits *       derived from this software without specific prior written permission.
14a05c377jhibbits *
15a05c377jhibbits *
16a05c377jhibbits * ALTERNATIVELY, this software may be distributed under the terms of the
17a05c377jhibbits * GNU General Public License ("GPL") as published by the Free Software
18a05c377jhibbits * Foundation, either version 2 of that License or (at your option) any
19a05c377jhibbits * later version.
20a05c377jhibbits *
21a05c377jhibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22a05c377jhibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23a05c377jhibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24a05c377jhibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25a05c377jhibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26a05c377jhibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27a05c377jhibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28a05c377jhibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29a05c377jhibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30a05c377jhibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31a05c377jhibbits */
32a05c377jhibbits
33a05c377jhibbits/******************************************************************************
34a05c377jhibbits @File          fm_macsec.c
35a05c377jhibbits
36a05c377jhibbits @Description   FM MACSEC driver routines implementation.
37a05c377jhibbits*//***************************************************************************/
38a05c377jhibbits
39a05c377jhibbits#include "std_ext.h"
40a05c377jhibbits#include "error_ext.h"
41a05c377jhibbits#include "xx_ext.h"
42a05c377jhibbits#include "string_ext.h"
43a05c377jhibbits#include "sprint_ext.h"
44a05c377jhibbits#include "fm_mac_ext.h"
45a05c377jhibbits
46a05c377jhibbits#include "fm_macsec_master.h"
47a05c377jhibbits
48a05c377jhibbits
49a05c377jhibbitsextern uint16_t    FM_MAC_GetMaxFrameLength(t_Handle FmMac);
50a05c377jhibbits
51a05c377jhibbits
52a05c377jhibbits/****************************************/
53a05c377jhibbits/*       static functions               */
54a05c377jhibbits/****************************************/
55a05c377jhibbitsstatic t_Error CheckFmMacsecParameters(t_FmMacsec *p_FmMacsec)
56a05c377jhibbits{
57a05c377jhibbits    if (!p_FmMacsec->f_Exception)
58a05c377jhibbits        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided"));
59a05c377jhibbits
60a05c377jhibbits    return E_OK;
61a05c377jhibbits}
62a05c377jhibbits
63a05c377jhibbitsstatic void UnimplementedIsr(t_Handle h_Arg, uint32_t id)
64a05c377jhibbits{
65a05c377jhibbits    UNUSED(h_Arg); UNUSED(id);
66a05c377jhibbits
67a05c377jhibbits    REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("Unimplemented Isr!"));
68a05c377jhibbits}
69a05c377jhibbits
70a05c377jhibbitsstatic void MacsecEventIsr(t_Handle h_FmMacsec)
71a05c377jhibbits{
72a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
73a05c377jhibbits    uint32_t    events,event,i;
74a05c377jhibbits
75a05c377jhibbits    SANITY_CHECK_RETURN(p_FmMacsec, E_INVALID_HANDLE);
76a05c377jhibbits
77a05c377jhibbits    events = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->evr);
78a05c377jhibbits    events |= GET_UINT32(p_FmMacsec->p_FmMacsecRegs->ever);
79a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->evr,events);
80a05c377jhibbits
81a05c377jhibbits    for (i=0; i<NUM_OF_TX_SC; i++)
82a05c377jhibbits        if (events & FM_MACSEC_EV_TX_SC_NEXT_PN(i))
83a05c377jhibbits        {
84a05c377jhibbits            GET_MACSEC_MODULE_EVENT(e_FM_MACSEC_MOD_SC_TX, i, e_FM_INTR_TYPE_NORMAL, event);
85a05c377jhibbits            p_FmMacsec->intrMng[event].f_Isr(p_FmMacsec->intrMng[event].h_SrcHandle, i);
86a05c377jhibbits        }
87a05c377jhibbits}
88a05c377jhibbits
89a05c377jhibbitsstatic void MacsecErrorIsr(t_Handle h_FmMacsec)
90a05c377jhibbits{
91a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
92a05c377jhibbits    uint32_t    errors,error,i;
93a05c377jhibbits
94a05c377jhibbits    SANITY_CHECK_RETURN(p_FmMacsec, E_INVALID_HANDLE);
95a05c377jhibbits
96a05c377jhibbits    errors = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->err);
97a05c377jhibbits    errors |= GET_UINT32(p_FmMacsec->p_FmMacsecRegs->erer);
98a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->err,errors);
99a05c377jhibbits
100a05c377jhibbits    for (i=0; i<NUM_OF_TX_SC; i++)
101a05c377jhibbits        if (errors & FM_MACSEC_EX_TX_SC(i))
102a05c377jhibbits        {
103a05c377jhibbits            GET_MACSEC_MODULE_EVENT(e_FM_MACSEC_MOD_SC_TX, i, e_FM_INTR_TYPE_ERR, error);
104a05c377jhibbits            p_FmMacsec->intrMng[error].f_Isr(p_FmMacsec->intrMng[error].h_SrcHandle, i);
105a05c377jhibbits        }
106a05c377jhibbits
107a05c377jhibbits    if (errors & FM_MACSEC_EX_ECC)
108a05c377jhibbits    {
109a05c377jhibbits        uint8_t     eccType;
110a05c377jhibbits        uint32_t    tmpReg;
111a05c377jhibbits
112a05c377jhibbits        tmpReg = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->meec);
113a05c377jhibbits        ASSERT_COND(tmpReg & MECC_CAP);
114a05c377jhibbits        eccType = (uint8_t)((tmpReg & MECC_CET) >> MECC_CET_SHIFT);
115a05c377jhibbits
116a05c377jhibbits        if (!eccType && (p_FmMacsec->userExceptions & FM_MACSEC_USER_EX_SINGLE_BIT_ECC))
117a05c377jhibbits            p_FmMacsec->f_Exception(p_FmMacsec->h_App,e_FM_MACSEC_EX_SINGLE_BIT_ECC);
118a05c377jhibbits        else if (eccType && (p_FmMacsec->userExceptions & FM_MACSEC_USER_EX_MULTI_BIT_ECC))
119a05c377jhibbits            p_FmMacsec->f_Exception(p_FmMacsec->h_App,e_FM_MACSEC_EX_MULTI_BIT_ECC);
120a05c377jhibbits        else
121a05c377jhibbits            WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->meec,tmpReg);
122a05c377jhibbits    }
123a05c377jhibbits}
124a05c377jhibbits
125a05c377jhibbitsstatic t_Error MacsecInit(t_Handle h_FmMacsec)
126a05c377jhibbits{
127a05c377jhibbits    t_FmMacsec                  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
128a05c377jhibbits    t_FmMacsecDriverParam       *p_FmMacsecDriverParam = NULL;
129a05c377jhibbits    uint32_t                    tmpReg,i,macId;
130a05c377jhibbits
131a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
132a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
133a05c377jhibbits
134a05c377jhibbits    CHECK_INIT_PARAMETERS(p_FmMacsec, CheckFmMacsecParameters);
135a05c377jhibbits
136a05c377jhibbits    p_FmMacsecDriverParam = p_FmMacsec->p_FmMacsecDriverParam;
137a05c377jhibbits
138a05c377jhibbits    for (i=0;i<e_FM_MACSEC_EV_DUMMY_LAST;i++)
139a05c377jhibbits        p_FmMacsec->intrMng[i].f_Isr = UnimplementedIsr;
140a05c377jhibbits
141a05c377jhibbits    tmpReg = 0;
142a05c377jhibbits    tmpReg |= (p_FmMacsecDriverParam->changedTextWithNoEncryptDeliverUncontrolled << CFG_UECT_SHIFT)|
143a05c377jhibbits              (p_FmMacsecDriverParam->onlyScbIsSetDeliverUncontrolled << CFG_ESCBT_SHIFT)           |
144a05c377jhibbits              (p_FmMacsecDriverParam->unknownSciTreatMode << CFG_USFT_SHIFT)                        |
145a05c377jhibbits              (p_FmMacsecDriverParam->invalidTagsDeliverUncontrolled << CFG_ITT_SHIFT)              |
146a05c377jhibbits              (p_FmMacsecDriverParam->encryptWithNoChangedTextDiscardUncontrolled << CFG_KFT_SHIFT) |
147a05c377jhibbits              (p_FmMacsecDriverParam->untagTreatMode << CFG_UFT_SHIFT)                              |
148a05c377jhibbits              (p_FmMacsecDriverParam->keysUnreadable << CFG_KSS_SHIFT)                              |
149a05c377jhibbits              (p_FmMacsecDriverParam->reservedSc0 << CFG_S0I_SHIFT)                                 |
150a05c377jhibbits              (p_FmMacsecDriverParam->byPassMode << CFG_BYPN_SHIFT);
151a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg, tmpReg);
152a05c377jhibbits
153a05c377jhibbits    tmpReg = FM_MAC_GetMaxFrameLength(p_FmMacsec->h_FmMac);
154a05c377jhibbits    /* At least Ethernet FCS (4 bytes) overhead must be subtracted from MFL.
155a05c377jhibbits     * In addition, the SCI (8 bytes) overhead might be subtracted as well. */
156a05c377jhibbits    tmpReg -= p_FmMacsecDriverParam->mflSubtract;
157a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->mfl, tmpReg);
158a05c377jhibbits
159a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->tpnet, p_FmMacsecDriverParam->pnExhThr);
160a05c377jhibbits
161a05c377jhibbits    if (!p_FmMacsec->userExceptions)
162a05c377jhibbits        p_FmMacsec->exceptions &= ~FM_MACSEC_EX_ECC;
163a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->erer, p_FmMacsec->exceptions);
164a05c377jhibbits
165a05c377jhibbits    p_FmMacsec->numRxScAvailable = NUM_OF_RX_SC;
166a05c377jhibbits    if (p_FmMacsecDriverParam->reservedSc0)
167a05c377jhibbits        p_FmMacsec->numRxScAvailable --;
168a05c377jhibbits    p_FmMacsec->numTxScAvailable = NUM_OF_TX_SC;
169a05c377jhibbits
170a05c377jhibbits    XX_Free(p_FmMacsecDriverParam);
171a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam = NULL;
172a05c377jhibbits
173a05c377jhibbits    FM_MAC_GetId(p_FmMacsec->h_FmMac, &macId);
174a05c377jhibbits    FmRegisterIntr(p_FmMacsec->h_Fm,
175a05c377jhibbits                   e_FM_MOD_MACSEC,
176a05c377jhibbits                   (uint8_t)macId,
177a05c377jhibbits                   e_FM_INTR_TYPE_NORMAL,
178a05c377jhibbits                   MacsecEventIsr,
179a05c377jhibbits                   p_FmMacsec);
180a05c377jhibbits
181a05c377jhibbits    FmRegisterIntr(p_FmMacsec->h_Fm,
182a05c377jhibbits                   e_FM_MOD_MACSEC,
183a05c377jhibbits                   0,
184a05c377jhibbits                   e_FM_INTR_TYPE_ERR,
185a05c377jhibbits                   MacsecErrorIsr,
186a05c377jhibbits                   p_FmMacsec);
187a05c377jhibbits
188a05c377jhibbits    return E_OK;
189a05c377jhibbits}
190a05c377jhibbits
191a05c377jhibbitsstatic t_Error MacsecFree(t_Handle h_FmMacsec)
192a05c377jhibbits{
193a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
194a05c377jhibbits    uint32_t    macId;
195a05c377jhibbits
196a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
197a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(!p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
198a05c377jhibbits
199a05c377jhibbits    FM_MAC_GetId(p_FmMacsec->h_FmMac, &macId);
200a05c377jhibbits    FmUnregisterIntr(p_FmMacsec->h_Fm,
201a05c377jhibbits                   e_FM_MOD_MACSEC,
202a05c377jhibbits                   (uint8_t)macId,
203a05c377jhibbits                   e_FM_INTR_TYPE_NORMAL);
204a05c377jhibbits
205a05c377jhibbits    FmUnregisterIntr(p_FmMacsec->h_Fm,
206a05c377jhibbits                   e_FM_MOD_MACSEC,
207a05c377jhibbits                   0,
208a05c377jhibbits                   e_FM_INTR_TYPE_ERR);
209a05c377jhibbits
210a05c377jhibbits    if (p_FmMacsec->rxScSpinLock)
211a05c377jhibbits        XX_FreeSpinlock(p_FmMacsec->rxScSpinLock);
212a05c377jhibbits    if (p_FmMacsec->txScSpinLock)
213a05c377jhibbits        XX_FreeSpinlock(p_FmMacsec->txScSpinLock);
214a05c377jhibbits
215a05c377jhibbits    XX_Free(p_FmMacsec);
216a05c377jhibbits
217a05c377jhibbits    return E_OK;
218a05c377jhibbits}
219a05c377jhibbits
220a05c377jhibbitsstatic t_Error MacsecConfigUnknownSciFrameTreatment(t_Handle h_FmMacsec, e_FmMacsecUnknownSciFrameTreatment treatMode)
221a05c377jhibbits{
222a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
223a05c377jhibbits
224a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
225a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
226a05c377jhibbits
227a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->unknownSciTreatMode = treatMode;
228a05c377jhibbits
229a05c377jhibbits    return E_OK;
230a05c377jhibbits}
231a05c377jhibbits
232a05c377jhibbitsstatic t_Error MacsecConfigInvalidTagsFrameTreatment(t_Handle h_FmMacsec, bool deliverUncontrolled)
233a05c377jhibbits{
234a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
235a05c377jhibbits
236a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
237a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
238a05c377jhibbits
239a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->invalidTagsDeliverUncontrolled = deliverUncontrolled;
240a05c377jhibbits
241a05c377jhibbits    return E_OK;
242a05c377jhibbits}
243a05c377jhibbits
244a05c377jhibbitsstatic t_Error MacsecConfigChangedTextWithNoEncryptFrameTreatment(t_Handle h_FmMacsec, bool deliverUncontrolled)
245a05c377jhibbits{
246a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
247a05c377jhibbits
248a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
249a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
250a05c377jhibbits
251a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->changedTextWithNoEncryptDeliverUncontrolled = deliverUncontrolled;
252a05c377jhibbits
253a05c377jhibbits    return E_OK;
254a05c377jhibbits}
255a05c377jhibbits
256a05c377jhibbitsstatic t_Error MacsecConfigOnlyScbIsSetFrameTreatment(t_Handle h_FmMacsec, bool deliverUncontrolled)
257a05c377jhibbits{
258a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
259a05c377jhibbits
260a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
261a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
262a05c377jhibbits
263a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->onlyScbIsSetDeliverUncontrolled = deliverUncontrolled;
264a05c377jhibbits
265a05c377jhibbits    return E_OK;
266a05c377jhibbits}
267a05c377jhibbits
268a05c377jhibbitsstatic t_Error MacsecConfigEncryptWithNoChangedTextFrameTreatment(t_Handle h_FmMacsec, bool discardUncontrolled)
269a05c377jhibbits{
270a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
271a05c377jhibbits
272a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
273a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
274a05c377jhibbits
275a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->encryptWithNoChangedTextDiscardUncontrolled = discardUncontrolled;
276a05c377jhibbits
277a05c377jhibbits    return E_OK;
278a05c377jhibbits}
279a05c377jhibbits
280a05c377jhibbitsstatic t_Error MacsecConfigUntagFrameTreatment(t_Handle h_FmMacsec, e_FmMacsecUntagFrameTreatment treatMode)
281a05c377jhibbits{
282a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
283a05c377jhibbits
284a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
285a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
286a05c377jhibbits
287a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->untagTreatMode = treatMode;
288a05c377jhibbits
289a05c377jhibbits    return E_OK;
290a05c377jhibbits}
291a05c377jhibbits
292a05c377jhibbitsstatic t_Error MacsecConfigPnExhaustionThreshold(t_Handle h_FmMacsec, uint32_t pnExhThr)
293a05c377jhibbits{
294a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
295a05c377jhibbits
296a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
297a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
298a05c377jhibbits
299a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->pnExhThr = pnExhThr;
300a05c377jhibbits
301a05c377jhibbits    return E_OK;
302a05c377jhibbits}
303a05c377jhibbits
304a05c377jhibbitsstatic t_Error MacsecConfigKeysUnreadable(t_Handle h_FmMacsec)
305a05c377jhibbits{
306a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
307a05c377jhibbits
308a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
309a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
310a05c377jhibbits
311a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->keysUnreadable = TRUE;
312a05c377jhibbits
313a05c377jhibbits    return E_OK;
314a05c377jhibbits}
315a05c377jhibbits
316a05c377jhibbitsstatic t_Error MacsecConfigSectagWithoutSCI(t_Handle h_FmMacsec)
317a05c377jhibbits{
318a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
319a05c377jhibbits
320a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
321a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
322a05c377jhibbits
323a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->sectagOverhead -= MACSEC_SCI_SIZE;
324a05c377jhibbits    p_FmMacsec->p_FmMacsecDriverParam->mflSubtract += MACSEC_SCI_SIZE;
325a05c377jhibbits
326a05c377jhibbits    return E_OK;
327a05c377jhibbits}
328a05c377jhibbits
329a05c377jhibbitsstatic t_Error MacsecConfigException(t_Handle h_FmMacsec, e_FmMacsecExceptions exception, bool enable)
330a05c377jhibbits{
331a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
332a05c377jhibbits    uint32_t    bitMask = 0;
333a05c377jhibbits
334a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
335a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
336a05c377jhibbits
337a05c377jhibbits    GET_USER_EXCEPTION_FLAG(bitMask, exception);
338a05c377jhibbits    if (bitMask)
339a05c377jhibbits    {
340a05c377jhibbits        if (enable)
341a05c377jhibbits            p_FmMacsec->userExceptions |= bitMask;
342a05c377jhibbits        else
343a05c377jhibbits            p_FmMacsec->userExceptions &= ~bitMask;
344a05c377jhibbits    }
345a05c377jhibbits    else
346a05c377jhibbits        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
347a05c377jhibbits
348a05c377jhibbits    return E_OK;
349a05c377jhibbits}
350a05c377jhibbits
351a05c377jhibbitsstatic t_Error MacsecGetRevision(t_Handle h_FmMacsec, uint32_t *p_MacsecRevision)
352a05c377jhibbits{
353a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
354a05c377jhibbits
355a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
356a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(!p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
357a05c377jhibbits
358a05c377jhibbits    *p_MacsecRevision = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->ip_rev1);
359a05c377jhibbits
360a05c377jhibbits    return E_OK;
361a05c377jhibbits}
362a05c377jhibbits
363a05c377jhibbitsstatic t_Error MacsecEnable(t_Handle h_FmMacsec)
364a05c377jhibbits{
365a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
366a05c377jhibbits    uint32_t    tmpReg;
367a05c377jhibbits
368a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
369a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(!p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
370a05c377jhibbits
371a05c377jhibbits    tmpReg  = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg);
372a05c377jhibbits    tmpReg |= CFG_BYPN;
373a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg,tmpReg);
374a05c377jhibbits
375a05c377jhibbits    return E_OK;
376a05c377jhibbits}
377a05c377jhibbits
378a05c377jhibbitsstatic t_Error MacsecDisable(t_Handle h_FmMacsec)
379a05c377jhibbits{
380a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
381a05c377jhibbits    uint32_t    tmpReg;
382a05c377jhibbits
383a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
384a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(!p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
385a05c377jhibbits
386a05c377jhibbits    tmpReg  = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg);
387a05c377jhibbits    tmpReg &= ~CFG_BYPN;
388a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg,tmpReg);
389a05c377jhibbits
390a05c377jhibbits    return E_OK;
391a05c377jhibbits}
392a05c377jhibbits
393a05c377jhibbitsstatic t_Error MacsecSetException(t_Handle h_FmMacsec, e_FmMacsecExceptions exception, bool enable)
394a05c377jhibbits{
395a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
396a05c377jhibbits    uint32_t    bitMask;
397a05c377jhibbits
398a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
399a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(!p_FmMacsec->p_FmMacsecDriverParam, E_INVALID_HANDLE);
400a05c377jhibbits
401a05c377jhibbits    GET_USER_EXCEPTION_FLAG(bitMask, exception);
402a05c377jhibbits    if (bitMask)
403a05c377jhibbits    {
404a05c377jhibbits        if (enable)
405a05c377jhibbits            p_FmMacsec->userExceptions |= bitMask;
406a05c377jhibbits        else
407a05c377jhibbits            p_FmMacsec->userExceptions &= ~bitMask;
408a05c377jhibbits    }
409a05c377jhibbits    else
410a05c377jhibbits        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
411a05c377jhibbits
412a05c377jhibbits    if (!p_FmMacsec->userExceptions)
413a05c377jhibbits        p_FmMacsec->exceptions &= ~FM_MACSEC_EX_ECC;
414a05c377jhibbits    else
415a05c377jhibbits        p_FmMacsec->exceptions |= FM_MACSEC_EX_ECC;
416a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->erer, p_FmMacsec->exceptions);
417a05c377jhibbits
418a05c377jhibbits    return E_OK;
419a05c377jhibbits}
420a05c377jhibbits
421a05c377jhibbitsstatic void InitFmMacsecControllerDriver(t_FmMacsecControllerDriver *p_FmMacsecControllerDriver)
422a05c377jhibbits{
423a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_Init                                            = MacsecInit;
424a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_Free                                            = MacsecFree;
425a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUnknownSciFrameTreatment                  = MacsecConfigUnknownSciFrameTreatment;
426a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigInvalidTagsFrameTreatment                 = MacsecConfigInvalidTagsFrameTreatment;
427a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigEncryptWithNoChangedTextFrameTreatment    = MacsecConfigEncryptWithNoChangedTextFrameTreatment;
428a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUntagFrameTreatment                       = MacsecConfigUntagFrameTreatment;
429a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigChangedTextWithNoEncryptFrameTreatment    = MacsecConfigChangedTextWithNoEncryptFrameTreatment;
430a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigOnlyScbIsSetFrameTreatment                = MacsecConfigOnlyScbIsSetFrameTreatment;
431a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigPnExhaustionThreshold                     = MacsecConfigPnExhaustionThreshold;
432a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigKeysUnreadable                            = MacsecConfigKeysUnreadable;
433a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigSectagWithoutSCI                          = MacsecConfigSectagWithoutSCI;
434a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigException                                 = MacsecConfigException;
435a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_GetRevision                                     = MacsecGetRevision;
436a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_Enable                                          = MacsecEnable;
437a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_Disable                                         = MacsecDisable;
438a05c377jhibbits    p_FmMacsecControllerDriver->f_FM_MACSEC_SetException                                    = MacsecSetException;
439a05c377jhibbits}
440a05c377jhibbits
441a05c377jhibbits/****************************************/
442a05c377jhibbits/*       Inter-Module functions         */
443a05c377jhibbits/****************************************/
444a05c377jhibbits
445a05c377jhibbitsvoid FmMacsecRegisterIntr(t_Handle                h_FmMacsec,
446a05c377jhibbits                          e_FmMacsecEventModules  module,
447a05c377jhibbits                          uint8_t                 modId,
448a05c377jhibbits                          e_FmIntrType            intrType,
449a05c377jhibbits                          void (*f_Isr) (t_Handle h_Arg, uint32_t id),
450a05c377jhibbits                          t_Handle                h_Arg)
451a05c377jhibbits{
452a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
453a05c377jhibbits    uint8_t     event= 0;
454a05c377jhibbits
455a05c377jhibbits    SANITY_CHECK_RETURN(p_FmMacsec, E_INVALID_HANDLE);
456a05c377jhibbits
457a05c377jhibbits    GET_MACSEC_MODULE_EVENT(module, modId, intrType, event);
458a05c377jhibbits
459a05c377jhibbits    ASSERT_COND(event != e_FM_MACSEC_EV_DUMMY_LAST);
460a05c377jhibbits    p_FmMacsec->intrMng[event].f_Isr = f_Isr;
461a05c377jhibbits    p_FmMacsec->intrMng[event].h_SrcHandle = h_Arg;
462a05c377jhibbits}
463a05c377jhibbits
464a05c377jhibbitsvoid FmMacsecUnregisterIntr(t_Handle                h_FmMacsec,
465a05c377jhibbits                            e_FmMacsecEventModules  module,
466a05c377jhibbits                            uint8_t                 modId,
467a05c377jhibbits                            e_FmIntrType            intrType)
468a05c377jhibbits{
469a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
470a05c377jhibbits    uint8_t     event= 0;
471a05c377jhibbits
472a05c377jhibbits    SANITY_CHECK_RETURN(p_FmMacsec, E_INVALID_HANDLE);
473a05c377jhibbits
474a05c377jhibbits    GET_MACSEC_MODULE_EVENT(module, modId,intrType, event);
475a05c377jhibbits
476a05c377jhibbits    ASSERT_COND(event != e_FM_MACSEC_EV_DUMMY_LAST);
477a05c377jhibbits    p_FmMacsec->intrMng[event].f_Isr = NULL;
478a05c377jhibbits    p_FmMacsec->intrMng[event].h_SrcHandle = NULL;
479a05c377jhibbits}
480a05c377jhibbits
481a05c377jhibbitst_Error FmMacsecAllocScs(t_Handle h_FmMacsec, e_ScType type, bool isPtp, uint32_t numOfScs, uint32_t *p_ScIds)
482a05c377jhibbits{
483a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
484a05c377jhibbits    t_Error     err = E_OK;
485a05c377jhibbits    bool        *p_ScTable;
486a05c377jhibbits    uint32_t    *p_ScAvailable,i;
487a05c377jhibbits
488a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
489a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_ScIds, E_INVALID_HANDLE);
490a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(numOfScs, E_INVALID_HANDLE);
491a05c377jhibbits
492a05c377jhibbits    if (type == e_SC_RX)
493a05c377jhibbits    {
494a05c377jhibbits        p_ScTable       = (bool *)p_FmMacsec->rxScTable;
495a05c377jhibbits        p_ScAvailable   = &p_FmMacsec->numRxScAvailable;
496a05c377jhibbits        i               = (NUM_OF_RX_SC - 1);
497a05c377jhibbits    }
498a05c377jhibbits    else
499a05c377jhibbits    {
500a05c377jhibbits        p_ScTable       = (bool *)p_FmMacsec->txScTable;
501a05c377jhibbits        p_ScAvailable   = &p_FmMacsec->numTxScAvailable;
502a05c377jhibbits        i               = (NUM_OF_TX_SC - 1);
503a05c377jhibbits
504a05c377jhibbits    }
505a05c377jhibbits    if (*p_ScAvailable < numOfScs)
506a05c377jhibbits        RETURN_ERROR(MINOR, E_NOT_AVAILABLE, ("Not enough SCs available"));
507a05c377jhibbits
508a05c377jhibbits    if (isPtp)
509a05c377jhibbits    {
510a05c377jhibbits        i = 0;
511a05c377jhibbits        if (p_ScTable[i])
512a05c377jhibbits            RETURN_ERROR(MINOR, E_NOT_AVAILABLE, ("Sc 0 Not available"));
513a05c377jhibbits    }
514a05c377jhibbits
515a05c377jhibbits    for (;numOfScs;i--)
516a05c377jhibbits    {
517a05c377jhibbits        if (p_ScTable[i])
518a05c377jhibbits            continue;
519a05c377jhibbits        numOfScs --;
520a05c377jhibbits        (*p_ScAvailable)--;
521a05c377jhibbits        p_ScIds[numOfScs] = i;
522a05c377jhibbits        p_ScTable[i] = TRUE;
523a05c377jhibbits    }
524a05c377jhibbits
525a05c377jhibbits    return err;
526a05c377jhibbits}
527a05c377jhibbits
528a05c377jhibbitst_Error FmMacsecFreeScs(t_Handle h_FmMacsec, e_ScType type, uint32_t numOfScs, uint32_t *p_ScIds)
529a05c377jhibbits{
530a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
531a05c377jhibbits    t_Error     err = E_OK;
532a05c377jhibbits    bool        *p_ScTable;
533a05c377jhibbits    uint32_t    *p_ScAvailable,maxNumOfSc,i;
534a05c377jhibbits
535a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
536a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_ScIds, E_INVALID_HANDLE);
537a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(numOfScs, E_INVALID_HANDLE);
538a05c377jhibbits
539a05c377jhibbits    if (type == e_SC_RX)
540a05c377jhibbits    {
541a05c377jhibbits        p_ScTable       = (bool *)p_FmMacsec->rxScTable;
542a05c377jhibbits        p_ScAvailable   = &p_FmMacsec->numRxScAvailable;
543a05c377jhibbits        maxNumOfSc      = NUM_OF_RX_SC;
544a05c377jhibbits    }
545a05c377jhibbits    else
546a05c377jhibbits    {
547a05c377jhibbits        p_ScTable       = (bool *)p_FmMacsec->txScTable;
548a05c377jhibbits        p_ScAvailable   = &p_FmMacsec->numTxScAvailable;
549a05c377jhibbits        maxNumOfSc      = NUM_OF_TX_SC;
550a05c377jhibbits    }
551a05c377jhibbits
552a05c377jhibbits    if ((*p_ScAvailable + numOfScs) > maxNumOfSc)
553a05c377jhibbits        RETURN_ERROR(MINOR, E_FULL, ("Too much SCs"));
554a05c377jhibbits
555a05c377jhibbits    for (i=0;i<numOfScs;i++)
556a05c377jhibbits    {
557a05c377jhibbits        p_ScTable[p_ScIds[i]] = FALSE;
558a05c377jhibbits        (*p_ScAvailable)++;
559a05c377jhibbits    }
560a05c377jhibbits
561a05c377jhibbits    return err;
562a05c377jhibbits
563a05c377jhibbits}
564a05c377jhibbits
565a05c377jhibbitst_Error FmMacsecSetPTP(t_Handle h_FmMacsec, bool enable)
566a05c377jhibbits{
567a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
568a05c377jhibbits    uint32_t    tmpReg = 0;
569a05c377jhibbits
570a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
571a05c377jhibbits
572a05c377jhibbits    tmpReg = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg);
573a05c377jhibbits    if (enable && (tmpReg & CFG_S0I))
574a05c377jhibbits        RETURN_ERROR(MINOR, E_INVALID_STATE, ("MACSEC already in point-to-point mode"));
575a05c377jhibbits
576a05c377jhibbits    if (enable)
577a05c377jhibbits        tmpReg |= CFG_S0I;
578a05c377jhibbits    else
579a05c377jhibbits        tmpReg &= ~CFG_S0I;
580a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->cfg, tmpReg);
581a05c377jhibbits
582a05c377jhibbits    return E_OK;
583a05c377jhibbits}
584a05c377jhibbits
585a05c377jhibbitst_Error FmMacsecCreateRxSc(t_Handle h_FmMacsec, t_RxScParams *p_RxScParams)
586a05c377jhibbits{
587a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
588a05c377jhibbits    t_Error     err = E_OK;
589a05c377jhibbits    uint32_t    tmpReg = 0, intFlags;
590a05c377jhibbits
591a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
592a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_RxScParams, E_INVALID_HANDLE);
593a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_RxScParams->scId < NUM_OF_RX_SC, E_INVALID_HANDLE);
594a05c377jhibbits
595a05c377jhibbits    intFlags = XX_LockIntrSpinlock(p_FmMacsec->rxScSpinLock);
596a05c377jhibbits
597a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsca, p_RxScParams->scId);
598a05c377jhibbits    tmpReg = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsccfg);
599a05c377jhibbits    if (tmpReg & RX_SCCFG_SCI_EN_MASK)
600a05c377jhibbits    {
601a05c377jhibbits        XX_UnlockIntrSpinlock(p_FmMacsec->rxScSpinLock, intFlags);
602a05c377jhibbits        RETURN_ERROR(MINOR, E_INVALID_STATE, ("Rx Sc %d must be disable",p_RxScParams->scId));
603a05c377jhibbits    }
604a05c377jhibbits
605a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsci1h, GET_SCI_FIRST_HALF(p_RxScParams->sci));
606a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsci2h, GET_SCI_SECOND_HALF(p_RxScParams->sci));
607a05c377jhibbits    tmpReg |= ((p_RxScParams->replayProtect << RX_SCCFG_RP_SHIFT) & RX_SCCFG_RP_MASK);
608a05c377jhibbits    tmpReg |= ((p_RxScParams->validateFrames << RX_SCCFG_VF_SHIFT) & RX_SCCFG_VF_MASK);
609a05c377jhibbits    tmpReg |= ((p_RxScParams->confidentialityOffset << RX_SCCFG_CO_SHIFT) & RX_SCCFG_CO_MASK);
610a05c377jhibbits    tmpReg |= RX_SCCFG_SCI_EN_MASK;
611a05c377jhibbits    tmpReg |= (p_RxScParams->cipherSuite << RX_SCCFG_CS_SHIFT);
612a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsccfg, tmpReg);
613a05c377jhibbits
614a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rpw, p_RxScParams->replayWindow);
615a05c377jhibbits
616a05c377jhibbits    XX_UnlockIntrSpinlock(p_FmMacsec->rxScSpinLock, intFlags);
617a05c377jhibbits
618a05c377jhibbits    return err;
619a05c377jhibbits}
620a05c377jhibbits
621a05c377jhibbitst_Error FmMacsecDeleteRxSc(t_Handle h_FmMacsec, uint32_t scId)
622a05c377jhibbits{
623a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
624a05c377jhibbits    t_Error     err = E_OK;
625a05c377jhibbits    uint32_t    tmpReg = 0, intFlags;
626a05c377jhibbits
627a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
628a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(scId < NUM_OF_RX_SC, E_INVALID_HANDLE);
629a05c377jhibbits
630a05c377jhibbits    intFlags = XX_LockIntrSpinlock(p_FmMacsec->rxScSpinLock);
631a05c377jhibbits
632a05c377jhibbits    tmpReg &= ~RX_SCCFG_SCI_EN_MASK;
633a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsca, scId);
634a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->rxsccfg, tmpReg);
635a05c377jhibbits
636a05c377jhibbits    XX_UnlockIntrSpinlock(p_FmMacsec->rxScSpinLock, intFlags);
637a05c377jhibbits
638a05c377jhibbits    return err;
639a05c377jhibbits}
640a05c377jhibbits
641a05c377jhibbitst_Error FmMacsecCreateTxSc(t_Handle h_FmMacsec, t_TxScParams *p_TxScParams)
642a05c377jhibbits{
643a05c377jhibbits    t_FmMacsec  *p_FmMacsec = (t_FmMacsec*)h_FmMacsec;
644a05c377jhibbits    t_Error     err = E_OK;
645a05c377jhibbits    uint32_t    tmpReg = 0, intFlags;
646a05c377jhibbits    bool        alwaysIncludeSCI = FALSE, useES = FALSE, useSCB = FALSE;
647a05c377jhibbits
648a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_FmMacsec, E_INVALID_HANDLE);
649a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_TxScParams, E_INVALID_HANDLE);
650a05c377jhibbits    SANITY_CHECK_RETURN_ERROR(p_TxScParams->scId < NUM_OF_TX_SC, E_INVALID_HANDLE);
651a05c377jhibbits
652a05c377jhibbits    intFlags = XX_LockIntrSpinlock(p_FmMacsec->txScSpinLock);
653a05c377jhibbits
654a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->txsca, p_TxScParams->scId);
655a05c377jhibbits
656a05c377jhibbits    tmpReg = GET_UINT32(p_FmMacsec->p_FmMacsecRegs->txsccfg);
657a05c377jhibbits    if (tmpReg & TX_SCCFG_SCE_MASK)
658a05c377jhibbits    {
659a05c377jhibbits        XX_UnlockIntrSpinlock(p_FmMacsec->txScSpinLock, intFlags);
660a05c377jhibbits        RETURN_ERROR(MINOR, E_INVALID_STATE, ("Tx Sc %d must be disable",p_TxScParams->scId));
661a05c377jhibbits    }
662a05c377jhibbits
663a05c377jhibbits    WRITE_UINT32(p_FmMacsec->p_FmMacsecRegs->txsci1h, GET_SCI_FIRST_HALF(p_TxScParams->sci));
664a05c377