xref: /freebsd/sys/contrib/ncsw/Peripherals/FM/MACSEC/fm_macsec.c (revision c2c014f24c10f90d85126ac5fbd4d8524de32b1c)
1 /*
2  * Copyright 2008-2015 Freescale Semiconductor Inc.
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 
34  @File          fm_macsec.c
35 
36  @Description   FM MACSEC driver routines implementation.
37 *//***************************************************************************/
38 
39 #include "std_ext.h"
40 #include "error_ext.h"
41 #include "xx_ext.h"
42 #include "string_ext.h"
43 #include "sprint_ext.h"
44 #include "debug_ext.h"
45 
46 #include "fm_macsec.h"
47 
48 
49 /****************************************/
50 /*       API Init unit functions        */
51 /****************************************/
FM_MACSEC_Config(t_FmMacsecParams * p_FmMacsecParam)52 t_Handle FM_MACSEC_Config(t_FmMacsecParams *p_FmMacsecParam)
53 {
54     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver;
55 
56     SANITY_CHECK_RETURN_VALUE(p_FmMacsecParam, E_INVALID_HANDLE, NULL);
57 
58     if (p_FmMacsecParam->guestMode)
59         p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)FM_MACSEC_GUEST_Config(p_FmMacsecParam);
60     else
61         p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)FM_MACSEC_MASTER_Config(p_FmMacsecParam);
62 
63     if (!p_FmMacsecControllerDriver)
64         return NULL;
65 
66     return (t_Handle)p_FmMacsecControllerDriver;
67 }
68 
FM_MACSEC_Init(t_Handle h_FmMacsec)69 t_Error FM_MACSEC_Init(t_Handle h_FmMacsec)
70 {
71     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
72 
73     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
74 
75     if (p_FmMacsecControllerDriver->f_FM_MACSEC_Init)
76         return p_FmMacsecControllerDriver->f_FM_MACSEC_Init(h_FmMacsec);
77 
78     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
79 }
80 
FM_MACSEC_Free(t_Handle h_FmMacsec)81 t_Error FM_MACSEC_Free(t_Handle h_FmMacsec)
82 {
83     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
84 
85     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
86 
87     if (p_FmMacsecControllerDriver->f_FM_MACSEC_Free)
88         return p_FmMacsecControllerDriver->f_FM_MACSEC_Free(h_FmMacsec);
89 
90     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
91 }
92 
FM_MACSEC_ConfigUnknownSciFrameTreatment(t_Handle h_FmMacsec,e_FmMacsecUnknownSciFrameTreatment treatMode)93 t_Error FM_MACSEC_ConfigUnknownSciFrameTreatment(t_Handle h_FmMacsec, e_FmMacsecUnknownSciFrameTreatment treatMode)
94 {
95     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
96 
97     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
98 
99     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUnknownSciFrameTreatment)
100         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUnknownSciFrameTreatment(h_FmMacsec, treatMode);
101 
102     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
103 }
104 
FM_MACSEC_ConfigInvalidTagsFrameTreatment(t_Handle h_FmMacsec,bool deliverUncontrolled)105 t_Error FM_MACSEC_ConfigInvalidTagsFrameTreatment(t_Handle h_FmMacsec, bool deliverUncontrolled)
106 {
107     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
108 
109     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
110 
111     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigInvalidTagsFrameTreatment)
112         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigInvalidTagsFrameTreatment(h_FmMacsec, deliverUncontrolled);
113 
114     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
115 }
116 
FM_MACSEC_ConfigEncryptWithNoChangedTextFrameTreatment(t_Handle h_FmMacsec,bool discardUncontrolled)117 t_Error FM_MACSEC_ConfigEncryptWithNoChangedTextFrameTreatment(t_Handle h_FmMacsec, bool discardUncontrolled)
118 {
119     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
120 
121     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
122 
123     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigEncryptWithNoChangedTextFrameTreatment)
124         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigEncryptWithNoChangedTextFrameTreatment(h_FmMacsec, discardUncontrolled);
125 
126     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
127 }
128 
FM_MACSEC_ConfigUntagFrameTreatment(t_Handle h_FmMacsec,e_FmMacsecUntagFrameTreatment treatMode)129 t_Error FM_MACSEC_ConfigUntagFrameTreatment(t_Handle h_FmMacsec, e_FmMacsecUntagFrameTreatment treatMode)
130 {
131     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
132 
133     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
134 
135     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUntagFrameTreatment)
136         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigUntagFrameTreatment(h_FmMacsec, treatMode);
137 
138     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
139 }
140 
FM_MACSEC_ConfigPnExhaustionThreshold(t_Handle h_FmMacsec,uint32_t pnExhThr)141 t_Error FM_MACSEC_ConfigPnExhaustionThreshold(t_Handle h_FmMacsec, uint32_t pnExhThr)
142 {
143     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
144 
145     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
146 
147     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigPnExhaustionThreshold)
148         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigPnExhaustionThreshold(h_FmMacsec, pnExhThr);
149 
150     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
151 }
152 
FM_MACSEC_ConfigKeysUnreadable(t_Handle h_FmMacsec)153 t_Error FM_MACSEC_ConfigKeysUnreadable(t_Handle h_FmMacsec)
154 {
155     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
156 
157     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
158 
159     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigKeysUnreadable)
160         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigKeysUnreadable(h_FmMacsec);
161 
162     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
163 }
164 
FM_MACSEC_ConfigSectagWithoutSCI(t_Handle h_FmMacsec)165 t_Error FM_MACSEC_ConfigSectagWithoutSCI(t_Handle h_FmMacsec)
166 {
167     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
168 
169     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
170 
171     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigSectagWithoutSCI)
172         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigSectagWithoutSCI(h_FmMacsec);
173 
174     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
175 }
176 
FM_MACSEC_ConfigException(t_Handle h_FmMacsec,e_FmMacsecExceptions exception,bool enable)177 t_Error FM_MACSEC_ConfigException(t_Handle h_FmMacsec, e_FmMacsecExceptions exception, bool enable)
178 {
179     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
180 
181     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
182 
183     if (p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigException)
184         return p_FmMacsecControllerDriver->f_FM_MACSEC_ConfigException(h_FmMacsec, exception, enable);
185 
186     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
187 }
188 
FM_MACSEC_GetRevision(t_Handle h_FmMacsec,uint32_t * p_MacsecRevision)189 t_Error FM_MACSEC_GetRevision(t_Handle h_FmMacsec, uint32_t *p_MacsecRevision)
190 {
191     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
192 
193     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
194 
195     if (p_FmMacsecControllerDriver->f_FM_MACSEC_GetRevision)
196         return p_FmMacsecControllerDriver->f_FM_MACSEC_GetRevision(h_FmMacsec, p_MacsecRevision);
197 
198     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
199 }
200 
201 
FM_MACSEC_Enable(t_Handle h_FmMacsec)202 t_Error FM_MACSEC_Enable(t_Handle h_FmMacsec)
203 {
204     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
205 
206     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
207 
208     if (p_FmMacsecControllerDriver->f_FM_MACSEC_Enable)
209         return p_FmMacsecControllerDriver->f_FM_MACSEC_Enable(h_FmMacsec);
210 
211     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
212 }
213 
FM_MACSEC_Disable(t_Handle h_FmMacsec)214 t_Error FM_MACSEC_Disable(t_Handle h_FmMacsec)
215 {
216     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
217 
218     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
219 
220     if (p_FmMacsecControllerDriver->f_FM_MACSEC_Disable)
221         return p_FmMacsecControllerDriver->f_FM_MACSEC_Disable(h_FmMacsec);
222 
223     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
224 }
225 
FM_MACSEC_SetException(t_Handle h_FmMacsec,e_FmMacsecExceptions exception,bool enable)226 t_Error FM_MACSEC_SetException(t_Handle h_FmMacsec, e_FmMacsecExceptions exception, bool enable)
227 {
228     t_FmMacsecControllerDriver *p_FmMacsecControllerDriver = (t_FmMacsecControllerDriver *)h_FmMacsec;
229 
230     SANITY_CHECK_RETURN_ERROR(p_FmMacsecControllerDriver, E_INVALID_HANDLE);
231 
232     if (p_FmMacsecControllerDriver->f_FM_MACSEC_SetException)
233         return p_FmMacsecControllerDriver->f_FM_MACSEC_SetException(h_FmMacsec, exception, enable);
234 
235     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
236 }
237 
238